I have a simple project Spring boot project. It contains one Jersey based Controller: @Path("persons") @Produces(MediaType.APPLICATION_JSON) public class PersonsController {
@GET
public Person get() {
return new Person("James", 20);
}
}
It returns json response as expected (url: http://localhost:PORT/persons):
{
"name": "James",
"age": 20
}
My aim is to add Spring Cloud Contract tests for this controller. I have added all required mvn configurations, and test:
public class MvcTest {
@Before
public void setup() {
RestAssuredMockMvc.standaloneSetup(new PersonsController());
}
}
Here is contract (groovy file): import org.springframework.cloud.contract.spec.Contract
Contract.make {
request {
method 'GET'
url('persons')
}
response {
status 200
body(
"name": "James",
"age": 20
)
}
}
When I run mvn clean package
following error always is returned:
Failed tests:
ContractVerifierTest.validate_getTest:26 expected:<[200]> but was:<[404]>
I believe this should be related to the ServletDispatcher as it doesn't see Jersey's paths. The same project with replaced @Path to @RequestMapping works. However, I need to make it working with Jersey. Have I missed something?
Have you checked the section about jaxrs support? https://cloud.spring.io/spring-cloud-contract/1.0.x/spring-cloud-contract.html#_jax_rs_support. Here you have an example how you can use it https://github.com/spring-cloud/spring-cloud-contract/tree/1.0.x/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/test/resources/functionalTest/sampleJerseyProject