Ratpacked: Using Spring Cloud Contract As Client
In a previous post we learned about Spring Cloud Contract. We saw how we can use contracts to implement the server side of the contract. But Spring Cloud Contract also creates a stub based on the contract. The stub server is implemented with Wiremock and Spring Boot. The server can match incoming requests with the contracts and send back the response as defined in the contract. Let’s write an application that is invoking HTTP requests on the server application we wrote before. In the tests that we write for this client application we use the stub that is generated by Spring Cloud Contract. We know the stub is following the contract of the actual server.
First we create the stub in our server project with the Gradle task verifierStubsJar
.
The tests in the client application need these stub and will fetch it as dependency from a Maven repository or the local Maven repository.
For our example we use the local Maven repository.
We add the maven-publish
plugin to the server project and run the task publishToMavenLocal
.