Spring Fest 2018 - Spring Data REST and Spring Cloud Contract
Demonstration execution procedure (5 steps)
Consumer is Frontend application that built by Angular.
Producer is Backend application that built by Spring Data REST.
1. Checkout sources
git clone firstname.lastname@example.org:tagbangers/sf-2018-spring-cloud-contract-demo.git
2. Run Pact Broker (Docker)
cd sf-2018-spring-cloud-contract-demo/ docker-compose up -d
You can check the UI of Pact Broker by access to the following URL.
3. Run frontend (Consumer) tests
cd sf-2018-spring-cloud-contract-demo/frontend/ npm install npm test
You can see that a Pact file is generated in the following path.
4. Publish Pacts to Pact Broker
npm run publish-pacts
You can see that the Pact file generated in Step 4 was published to Pact Broker.
5. Verify contract by backend (Producer)
cd sf-2018-spring-cloud-contract-demo/backend/ ./mvnw clean install
At this time, Spring Cloud Contract will automatically fetch the Pact file from Pact Broker and convert it to Contract.
Next, Generates unit test code automatically from Contract and execute it.
We will verify that Contract is being protected by making all those tests successful.
You can check the automatically generated unit test code in the following pass.