Skip to content

NDViet/aut-api-testing

Repository files navigation

API Testing Demo Backend

This repository contains a Java 21 multi-module Spring Boot backend designed to support API functional testing, GraphQL validation, black-box smoke tests, coverage collection with JaCoCo, and selective test execution based on changed modules.

Modules

  • shared-kernel: shared exceptions, enums, and API error handling.
  • catalog-service: product catalog domain, REST endpoints, and GraphQL queries and mutations.
  • ordering-service: customer and order workflows, REST endpoints, and GraphQL queries and mutations.
  • backend-app: runnable Spring Boot application, Flyway migrations, demo seed data, JaCoCo agent packaging, and container assets.
  • api-smoke-tests: black-box API tests intended to run against a live stack started with Docker Compose.

Exposed APIs

REST

  • GET /api/v1/products
  • GET /api/v1/products/{sku}
  • POST /api/v1/products
  • PATCH /api/v1/products/{sku}/inventory
  • GET /api/v1/customers
  • POST /api/v1/customers
  • GET /api/v1/orders
  • GET /api/v1/orders/{orderNumber}
  • POST /api/v1/orders
  • GET /actuator/health

GraphQL

GraphQL is exposed at POST /graphql.

  • Queries: products, productBySku, customers, orders, orderByNumber
  • Mutations: createProduct, adjustInventory, createCustomer, placeOrder

Local workflow

Build the application artifacts:

./gradlew clean build :backend-app:copyJacocoAgent

Start the stack:

./gradlew clean build :backend-app:copyJacocoAgent
docker compose up --build

Run smoke tests against the live stack:

./gradlew :api-smoke-tests:test -PbaseUrl=http://localhost:8180 -PbearerToken=local-api-token

The application container mounts .coverage/ and writes JaCoCo execution data to .coverage/jacoco.exec.

The packaged JaCoCo agent file is produced at backend-app/build/jacoco-agent/jacocoagent.jar.

Authentication

All application REST and GraphQL endpoints require Authorization: Bearer <token>.

  • Default local token: local-api-token
  • Override token with APP_BEARER_TOKEN
  • Public endpoint kept open for health checks: GET /actuator/health

Example REST request:

curl http://localhost:8180/api/v1/products \
  -H 'Authorization: Bearer local-api-token'

Example GraphQL request:

curl http://localhost:8180/graphql \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer local-api-token' \
  --data '{"query":"{ products { sku name } }"}'

Change-based testing

Use the helper script to determine impacted Gradle test tasks from git changes:

scripts/resolve-impacted-tasks.sh origin/main HEAD

The GitHub workflow uses this script to run targeted unit tests before running the live-stack smoke suite and publishing an image to GHCR.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors