Spring Cloud Contract with Jersey

553 views Asked by At

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?

1

There are 1 answers