简体   繁体   中英

Spring Cloud Contract with Jersey

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM