Skip to content

specmatic/specmatic-order-api-java

Repository files navigation

Specmatic Sample: Spring Boot Order API

Table of Contents

Background

This sample project demonstrates how Specmatic can be used to contract test an API in isolation before integrating with consumers.

The interaction between Order API in this project and it's consumers is governed by this OpenAPI specification..

Tech

  1. Spring Boot service written in Java
  2. Specmatic
  3. Docker Desktop (for running contract tests with containers)

Run Contract Tests

Specmatic contract tests use the specmatic.yaml configuration file to start the required Specmatic stub before verifying the Order API.

1. Using Maven

For Unix based systems and Windows PowerShell:

./mvnw test -Dtest=ContractTest

For Windows Command Prompt:

mvnw.cmd test -Dtest=ContractTest

After the tests complete, view the report at build/reports/specmatic/html/index.html.

Contract Tests Using TestContainers

For Unix based systems and Windows PowerShell:

./mvnw test -Dtest=ContractTestUsingTestContainerTest

For Windows Command Prompt:

mvnw.cmd test -Dtest=ContractTestUsingTestContainerTest

3. Using Docker Desktop

For Unix based systems and Windows PowerShell:

# Start the service
./mvnw spring-boot:run
# Run the contract tests
docker run --rm --network host -v "$(pwd)/specmatic.yaml:/usr/src/app/specmatic.yaml" -v "$(pwd)/build/reports/specmatic:/usr/src/app/build/reports/specmatic" specmatic/specmatic test --port=8090

For Windows Command Prompt:

# Start the service
mvnw.cmd spring-boot:run
# Run the contract tests
docker run --rm --network host -v "%cd%/specmatic.yaml:/usr/src/app/specmatic.yaml" -v "%cd%/build/reports/specmatic:/usr/src/app/build/reports/specmatic" specmatic/specmatic test --port=8090

For More Info

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 14