samedi 25 juin 2016

Rest Assured + Mock MVC @ControllerAdvice

In my project I am using ,Rest Assured MockMVC with the following dependency. <dependency> <groupId>com.jayway.restassured</groupId> <artifactId>spring-mock-mvc</artifactId> <version>2.9.0</version> </dependency>

And my test class looks like -

TestController testController = new TestController();
@Before
public void configureRestAssuredForController() {
    RestAssuredMockMvc.standaloneSetup(testController);
}

I have a couple of ExceptionHandlers defined in the controller class. In my JUnit tests I could verify the request paths and the handlers when defined in the controller class.

However - When I moved the handlers to a separate class with @ControllerAdvice ,handlers are not being invoked from the tests.

I understood that it is because of the standalone set up for the controller,which probably could not load handlers defined in another class.

But I couldn't figure out how do I add the exception handlers to the RestAssuredMockMvc,in standalone mode to make this work.

enter code here

I am struggling and Any help is much appreciated please.

Aucun commentaire:

Enregistrer un commentaire