Skip to content

Add spring-boot-product-catalog sample (Spring Boot + PostgreSQL) - #149

Open
dhananjay6561 wants to merge 4 commits into
mainfrom
spring-boot-product-catalog
Open

Add spring-boot-product-catalog sample (Spring Boot + PostgreSQL)#149
dhananjay6561 wants to merge 4 commits into
mainfrom
spring-boot-product-catalog

Conversation

@dhananjay6561

Copy link
Copy Markdown
Member

Description

Adds a new Java sample — spring-boot-product-catalog, a Spring Boot + PostgreSQL product-catalog REST API used to demonstrate Keploy replacing hand-written API tests. Instead of JUnit fixtures and mocks, Keploy records real traffic once (capturing every downstream Postgres call as a mock) and replays it as a regression suite that needs no database at all.

The sample ships a committed test set under keploy/products-crud/:

  • 57 test cases covering the full CRUD lifecycle, category filtering, and 404/400 edge cases
  • 190 Postgres mocks (+2 DNS), so the database is stubbed on replay
  • docker-compose.keploy.yml — an app-only Compose file with no postgres service at all; the suite still passes green because every DB call is served from the recorded mocks

Also adds a paths-scoped CI workflow (.github/workflows/spring-boot-product-catalog.yml) and lists the sample as #11 in the root README.

Issues are disabled on this repo; no linked keploy/keploy issue.

Type of change

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

How Has This Been Tested?

The stack runs entirely in Docker (no local Java/Maven needed).

Record (brings the stack up in record mode, then drive traffic with ./seed.sh):

keploy record -c "docker compose up" \
  --cmd-type docker-compose --container-name catalog-app \
  -n product-catalog_default \
  --metadata "name=products-crud,description=full CRUD + filters + 404 + 400"

Replay against the recorded mocks:

keploy test -c "docker compose up" \
  --cmd-type docker-compose --container-name catalog-app \
  -n product-catalog_default --mappings --delay 20

Result:

  "products-crud"   Total: 57   Passed: 57   Failed: 0

Dependency-free replay — same green result with no database service present:

keploy test -c "docker compose -f docker-compose.keploy.yml up" \
  --cmd-type docker-compose --container-name catalog-app \
  -n product-catalog_default --mappings --delay 20

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have checked my code and corrected any misspellings
  • I have signed the commit message to agree to Developer Certificate of Origin (DCO)

A product-catalog REST API demonstrating Keploy replacing hand-written
API tests. Ships a committed test set of 57 cases and 190 Postgres mocks
under keploy/products-crud/, plus an app-only docker-compose.keploy.yml
that replays the full suite green with no database present.

- Full CRUD, category filters, inventory summary, stock adjustment
- Multi-stage Dockerfile (Temurin 21), docker-compose for record/replay
- Paths-scoped CI workflow: Maven build + end-to-end smoke test
- Listed as sample #11 in the root README

Signed-off-by: dhananjay6561 <dhananjayaggarwal6561@gmail.com>
Copilot AI lite review requested due to automatic review settings August 10, 2026 11:50

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new spring-boot-product-catalog sample module: a Spring Boot + PostgreSQL product-catalog REST API intended to demonstrate Keploy record/replay testing with a committed test-set and DB mocks.

Changes:

  • Introduces a CRUD + inventory summary REST API (controller/service/repository/model + DTOs + error handling).
  • Adds Docker-based local run + seed traffic generator + Keploy configuration and a committed Keploy test-set (tests + mocks + mappings).
  • Adds documentation and a paths-scoped GitHub Actions workflow for module CI.

Reviewed changes

Copilot reviewed 89 out of 90 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
spring-boot-product-catalog/src/test/java/io/keploy/productcatalog/ProductCatalogApplicationTests.java Adds a basic Spring context smoke test for the new sample.
spring-boot-product-catalog/src/main/resources/application.properties Configures app name, server port, lazy init, datasource, JPA, and actuator health exposure.
spring-boot-product-catalog/src/main/java/io/keploy/productcatalog/web/ProductController.java Defines the REST API endpoints for product CRUD, stock adjustment, and inventory summary.
spring-boot-product-catalog/src/main/java/io/keploy/productcatalog/web/error/ResourceNotFoundException.java Adds a domain-specific exception for 404 cases.
spring-boot-product-catalog/src/main/java/io/keploy/productcatalog/web/error/InsufficientStockException.java Adds a domain-specific exception for 409 stock conflicts.
spring-boot-product-catalog/src/main/java/io/keploy/productcatalog/web/error/GlobalExceptionHandler.java Provides stable, structured JSON error responses for deterministic Keploy replays.
spring-boot-product-catalog/src/main/java/io/keploy/productcatalog/web/dto/StockAdjustmentRequest.java Adds the PATCH stock-adjust request payload with validation.
spring-boot-product-catalog/src/main/java/io/keploy/productcatalog/web/dto/ProductResponse.java Adds the API response DTO and mapping from the JPA entity.
spring-boot-product-catalog/src/main/java/io/keploy/productcatalog/web/dto/ProductRequest.java Adds create/update request DTO with validation constraints.
spring-boot-product-catalog/src/main/java/io/keploy/productcatalog/web/dto/InventorySummaryResponse.java Adds the response model for aggregated inventory summary endpoint.
spring-boot-product-catalog/src/main/java/io/keploy/productcatalog/service/ProductService.java Implements CRUD logic, stock adjustment, and inventory aggregation.
spring-boot-product-catalog/src/main/java/io/keploy/productcatalog/repository/ProductRepository.java Adds the Spring Data JPA repository with category filtering query.
spring-boot-product-catalog/src/main/java/io/keploy/productcatalog/ProductCatalogApplication.java Adds the Spring Boot application entry point.
spring-boot-product-catalog/src/main/java/io/keploy/productcatalog/model/Product.java Adds the Product JPA entity schema and creation timestamp behavior.
spring-boot-product-catalog/seed.sh Adds a curl-based traffic generator used for Keploy recording and CI smoke testing.
spring-boot-product-catalog/README.md Documents sample purpose, architecture, API, Keploy record/replay steps, and troubleshooting.
spring-boot-product-catalog/pom.xml Defines the module’s Spring Boot, JPA, validation, web, and test dependencies.
spring-boot-product-catalog/mvnw.cmd Adds Maven Wrapper script for Windows.
spring-boot-product-catalog/mvnw Adds Maven Wrapper script for Unix-like systems.
spring-boot-product-catalog/keploy/products-crud/tests/put-api-products-by-id-5.yaml Adds a recorded Keploy test case for PUT validation failure behavior.
spring-boot-product-catalog/keploy/products-crud/tests/put-api-products-by-id-4.yaml Adds a recorded Keploy test case for PUT 404 behavior.
spring-boot-product-catalog/keploy/products-crud/tests/put-api-products-by-id-3.yaml Adds a recorded Keploy test case for PUT update behavior.
spring-boot-product-catalog/keploy/products-crud/tests/put-api-products-by-id-2.yaml Adds a recorded Keploy test case for PUT update behavior.
spring-boot-product-catalog/keploy/products-crud/tests/put-api-products-by-id-1.yaml Adds a recorded Keploy test case for PUT update behavior.
spring-boot-product-catalog/keploy/products-crud/tests/post-api-products-9.yaml Adds a recorded Keploy test case for POST create behavior.
spring-boot-product-catalog/keploy/products-crud/tests/post-api-products-8.yaml Adds a recorded Keploy test case for POST create behavior.
spring-boot-product-catalog/keploy/products-crud/tests/post-api-products-7.yaml Adds a recorded Keploy test case for POST create behavior.
spring-boot-product-catalog/keploy/products-crud/tests/post-api-products-6.yaml Adds a recorded Keploy test case for POST create behavior.
spring-boot-product-catalog/keploy/products-crud/tests/post-api-products-5.yaml Adds a recorded Keploy test case for POST create behavior.
spring-boot-product-catalog/keploy/products-crud/tests/post-api-products-4.yaml Adds a recorded Keploy test case for POST create behavior.
spring-boot-product-catalog/keploy/products-crud/tests/post-api-products-3.yaml Adds a recorded Keploy test case for POST create behavior.
spring-boot-product-catalog/keploy/products-crud/tests/post-api-products-20.yaml Adds a recorded Keploy test case for POST multi-field validation failure behavior.
spring-boot-product-catalog/keploy/products-crud/tests/post-api-products-2.yaml Adds a recorded Keploy test case for POST create behavior.
spring-boot-product-catalog/keploy/products-crud/tests/post-api-products-19.yaml Adds a recorded Keploy test case for POST validation failure behavior.
spring-boot-product-catalog/keploy/products-crud/tests/post-api-products-18.yaml Adds a recorded Keploy test case for POST validation failure behavior.
spring-boot-product-catalog/keploy/products-crud/tests/post-api-products-17.yaml Adds a recorded Keploy test case for POST validation failure behavior.
spring-boot-product-catalog/keploy/products-crud/tests/post-api-products-16.yaml Adds a recorded Keploy test case for POST validation failure behavior.
spring-boot-product-catalog/keploy/products-crud/tests/post-api-products-15.yaml Adds a recorded Keploy test case for POST validation failure behavior.
spring-boot-product-catalog/keploy/products-crud/tests/post-api-products-14.yaml Adds a recorded Keploy test case for POST validation failure behavior.
spring-boot-product-catalog/keploy/products-crud/tests/post-api-products-13.yaml Adds a recorded Keploy test case for POST validation failure behavior.
spring-boot-product-catalog/keploy/products-crud/tests/post-api-products-12.yaml Adds a recorded Keploy test case for POST create behavior.
spring-boot-product-catalog/keploy/products-crud/tests/post-api-products-11.yaml Adds a recorded Keploy test case for POST create behavior.
spring-boot-product-catalog/keploy/products-crud/tests/post-api-products-10.yaml Adds a recorded Keploy test case for POST create behavior.
spring-boot-product-catalog/keploy/products-crud/tests/post-api-products-1.yaml Adds a recorded Keploy test case for POST create behavior.
spring-boot-product-catalog/keploy/products-crud/tests/get-api-products-by-id-9.yaml Adds a recorded Keploy test case for GET-by-id behavior.
spring-boot-product-catalog/keploy/products-crud/tests/get-api-products-by-id-8.yaml Adds a recorded Keploy test case for GET-by-id behavior.
spring-boot-product-catalog/keploy/products-crud/tests/get-api-products-by-id-7.yaml Adds a recorded Keploy test case for GET-by-id behavior.
spring-boot-product-catalog/keploy/products-crud/tests/get-api-products-by-id-6.yaml Adds a recorded Keploy test case for GET-by-id behavior.
spring-boot-product-catalog/keploy/products-crud/tests/get-api-products-by-id-5.yaml Adds a recorded Keploy test case for GET-by-id behavior.
spring-boot-product-catalog/keploy/products-crud/tests/get-api-products-by-id-4.yaml Adds a recorded Keploy test case for GET-by-id behavior.
spring-boot-product-catalog/keploy/products-crud/tests/get-api-products-by-id-3.yaml Adds a recorded Keploy test case for GET-by-id behavior.
spring-boot-product-catalog/keploy/products-crud/tests/get-api-products-by-id-2.yaml Adds a recorded Keploy test case for GET-by-id behavior.
spring-boot-product-catalog/keploy/products-crud/tests/get-api-products-by-id-17.yaml Adds a recorded Keploy test case for GET-by-id 404 behavior after delete.
spring-boot-product-catalog/keploy/products-crud/tests/get-api-products-by-id-16.yaml Adds a recorded Keploy test case for GET-by-id 404 behavior.
spring-boot-product-catalog/keploy/products-crud/tests/get-api-products-by-id-15.yaml Adds a recorded Keploy test case for GET-by-id behavior after update.
spring-boot-product-catalog/keploy/products-crud/tests/get-api-products-by-id-14.yaml Adds a recorded Keploy test case for GET-by-id behavior after update.
spring-boot-product-catalog/keploy/products-crud/tests/get-api-products-by-id-13.yaml Adds a recorded Keploy test case for GET-by-id behavior after update.
spring-boot-product-catalog/keploy/products-crud/tests/get-api-products-by-id-12.yaml Adds a recorded Keploy test case for GET-by-id behavior.
spring-boot-product-catalog/keploy/products-crud/tests/get-api-products-by-id-11.yaml Adds a recorded Keploy test case for GET-by-id behavior.
spring-boot-product-catalog/keploy/products-crud/tests/get-api-products-by-id-10.yaml Adds a recorded Keploy test case for GET-by-id behavior.
spring-boot-product-catalog/keploy/products-crud/tests/get-api-products-by-id-1.yaml Adds a recorded Keploy test case for GET-by-id behavior.
spring-boot-product-catalog/keploy/products-crud/tests/get-api-products-9.yaml Adds a recorded Keploy test case for list-by-category behavior.
spring-boot-product-catalog/keploy/products-crud/tests/get-api-products-8.yaml Adds a recorded Keploy test case for list-by-category behavior.
spring-boot-product-catalog/keploy/products-crud/tests/get-api-products-7.yaml Adds a recorded Keploy test case for list-by-category behavior.
spring-boot-product-catalog/keploy/products-crud/tests/get-api-products-6.yaml Adds a recorded Keploy test case for list-by-category behavior.
spring-boot-product-catalog/keploy/products-crud/tests/get-api-products-5.yaml Adds a recorded Keploy test case for list-by-category behavior.
spring-boot-product-catalog/keploy/products-crud/tests/get-api-products-4.yaml Adds a recorded Keploy test case for list-by-category behavior.
spring-boot-product-catalog/keploy/products-crud/tests/get-api-products-3.yaml Adds a recorded Keploy test case for list-all behavior.
spring-boot-product-catalog/keploy/products-crud/tests/get-api-products-2.yaml Adds a recorded Keploy test case for list-all empty behavior.
spring-boot-product-catalog/keploy/products-crud/tests/get-api-products-12.yaml Adds a recorded Keploy test case for list-by-category behavior after updates/deletes.
spring-boot-product-catalog/keploy/products-crud/tests/get-api-products-11.yaml Adds a recorded Keploy test case for list-all behavior after updates/deletes.
spring-boot-product-catalog/keploy/products-crud/tests/get-api-products-10.yaml Adds a recorded Keploy test case for list-by-category empty behavior.
spring-boot-product-catalog/keploy/products-crud/tests/get-api-products-1.yaml Adds a recorded Keploy test case for list-all empty behavior (early).
spring-boot-product-catalog/keploy/products-crud/tests/delete-api-products-by-id-3.yaml Adds a recorded Keploy test case for DELETE 404 behavior.
spring-boot-product-catalog/keploy/products-crud/tests/delete-api-products-by-id-2.yaml Adds a recorded Keploy test case for DELETE success behavior.
spring-boot-product-catalog/keploy/products-crud/tests/delete-api-products-by-id-1.yaml Adds a recorded Keploy test case for DELETE success behavior.
spring-boot-product-catalog/keploy/products-crud/mappings.yaml Adds test-to-mocks mapping so stateful reads replay against the correct mocks.
spring-boot-product-catalog/keploy/products-crud/config.yaml Adds Keploy test-set metadata configuration.
spring-boot-product-catalog/keploy/.gitignore Ignores Keploy runtime artifacts (reports/logs) within the module.
spring-boot-product-catalog/keploy.yml Adds Keploy configuration for record/replay (compose command, ports, noise rules, mappings, delays).
spring-boot-product-catalog/Dockerfile Adds a multi-stage container build for the sample (Temurin 21 build + slim runtime).
spring-boot-product-catalog/docker-compose.yml Adds app + Postgres compose stack with healthchecks for local run/recording.
spring-boot-product-catalog/docker-compose.keploy.yml Adds an app-only compose stack for dependency-free Keploy replay.
spring-boot-product-catalog/.mvn/wrapper/maven-wrapper.properties Adds Maven Wrapper configuration for reproducible builds.
spring-boot-product-catalog/.gitignore Adds module-specific ignores (target/, IDE files, Keploy artifacts).
spring-boot-product-catalog/.gitattributes Normalizes line endings for mvnw and .cmd scripts.
spring-boot-product-catalog/.dockerignore Excludes build outputs and keploy/ fixtures from Docker build context.
README.md Registers the new sample as entry #11 in the repository root README.
.github/workflows/spring-boot-product-catalog.yml Adds a paths-scoped CI workflow to build and smoke-test the new sample.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread spring-boot-product-catalog/pom.xml
@dhananjay6561 dhananjay6561 self-assigned this Aug 10, 2026
The not-found message was 'Product not found with id: <id>', but the
committed GET/PUT/DELETE 404 tests assert body.message as 'Product <id>
not found' (only header.Date is noise). Restore the recorded wording so
the suite replays green as the README states, and add a guard comment so
the contract-sensitive string isn't reworded again.

Signed-off-by: dhananjay6561 <dhananjayaggarwal6561@gmail.com>
Comment thread spring-boot-product-catalog/README.md
Comment thread spring-boot-product-catalog/Dockerfile
Comment thread spring-boot-product-catalog/seed.sh
…ic stock

- docker-compose.yml: add an app healthcheck (Actuator /health via curl) so
  'docker compose up --wait' blocks until the app is actually ready. Left the
  DB-absent docker-compose.keploy.yml alone, where a db health check would fail.
- seed.sh: exercise GET /summary and PATCH /{id}/stock (409 + 404) so the README's
  're-record picks them up' claim holds; fail loudly if the app never becomes ready
  instead of silently proceeding and exiting 0.
- ProductService/ProductRepository: make adjustStock an atomic guarded UPDATE so
  concurrent PATCHes can't lose an update or bypass the >= 0 guard. Scoped to the
  (un-recorded) stock path via a @Modifying query rather than @Version, which would
  change every INSERT/UPDATE and break the committed Postgres mocks.

Signed-off-by: dhananjay6561 <dhananjayaggarwal6561@gmail.com>
Comment thread spring-boot-product-catalog/docker-compose.yml Outdated
The aggregate /actuator/health endpoint runs the JDBC db indicator on every
poll (interval: 5s), which Keploy captures as extra Postgres mocks during
keploy record and bloats mocks.yaml. The readiness group (already enabled via
management.endpoint.health.probes.enabled) doesn't touch the DB, so it still
gives 'docker compose up --wait' a real ready-to-serve signal without polluting
the recorded capture.

Signed-off-by: dhananjay6561 <dhananjayaggarwal6561@gmail.com>
@dhananjay6561

Copy link
Copy Markdown
Member Author

LGTM ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants