Java Code Examples for org.springframework.test.web.servlet.MvcResult#getHandler()

The following examples show how to use org.springframework.test.web.servlet.MvcResult#getHandler() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HandlerResultMatchers.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private static HandlerMethod getHandlerMethod(MvcResult result) {
	Object handler = result.getHandler();
	assertTrue("No handler", handler != null);
	if (!(handler instanceof HandlerMethod)) {
		fail("Not a HandlerMethod: " + handler);
	}
	return (HandlerMethod) handler;
}
 
Example 2
Source File: HandlerResultMatchers.java    From java-technology-stack with MIT License 5 votes vote down vote up
private static HandlerMethod getHandlerMethod(MvcResult result) {
	Object handler = result.getHandler();
	assertTrue("No handler", handler != null);
	if (!(handler instanceof HandlerMethod)) {
		fail("Not a HandlerMethod: " + handler);
	}
	return (HandlerMethod) handler;
}
 
Example 3
Source File: HandlerResultMatchers.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Assert the type of the handler that processed the request.
 */
public ResultMatcher handlerType(final Class<?> type) {
	return new ResultMatcher() {
		@Override
		public void match(MvcResult result) throws Exception {
			Object handler = result.getHandler();
			assertTrue("No handler: ", handler != null);
			Class<?> actual = handler.getClass();
			if (HandlerMethod.class.isInstance(handler)) {
				actual = ((HandlerMethod) handler).getBeanType();
			}
			assertEquals("Handler type", type, ClassUtils.getUserClass(actual));
		}
	};
}
 
Example 4
Source File: JacksonResultHandlers.java    From spring-auto-restdocs with Apache License 2.0 5 votes vote down vote up
@Override
public void handle(MvcResult result) throws Exception {
    // HandlerMethod is not present in case of invalid endpoint
    // or in case of static resource url
    if (result.getHandler() instanceof HandlerMethod) {
        setHandlerMethod(result.getRequest(), (HandlerMethod) result.getHandler());
    }
    setObjectMapper(result.getRequest(), objectMapper);
    initRequestPattern(result.getRequest());
    setJavadocReader(result.getRequest(), JavadocReaderImpl.createWithSystemProperty());
    setConstraintReader(result.getRequest(),
            ConstraintReaderImpl.create(objectMapper, translationResolver, constraintDescriptionResolver));
    setTypeMapping(result.getRequest(), typeMapping);
}
 
Example 5
Source File: HandlerResultMatchers.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
private static Object assertHandlerMethod(MvcResult result) {
	Object handler = result.getHandler();
	assertTrue("No handler: ", handler != null);
	assertTrue("Not a HandlerMethod: " + handler, HandlerMethod.class.isInstance(handler));
	return handler;
}