Search in sources :

Example 6 with ResultMatcher

use of org.springframework.test.web.servlet.ResultMatcher in project spring-framework by spring-projects.

the class CookieResultMatchers method doesNotExist.

/**
	 * Assert a cookie does not exist. Note that the existence check is
	 * irrespective of whether max age is 0, i.e. expired.
	 */
public ResultMatcher doesNotExist(final String name) {
    return new ResultMatcher() {

        @Override
        public void match(MvcResult result) {
            Cookie cookie = result.getResponse().getCookie(name);
            assertTrue("Unexpected cookie with name " + name, cookie == null);
        }
    };
}
Also used : Cookie(javax.servlet.http.Cookie) ResultMatcher(org.springframework.test.web.servlet.ResultMatcher) MvcResult(org.springframework.test.web.servlet.MvcResult)

Example 7 with ResultMatcher

use of org.springframework.test.web.servlet.ResultMatcher in project spring-framework by spring-projects.

the class CookieResultMatchers method value.

/**
	 * Assert a cookie value.
	 */
public ResultMatcher value(final String name, final String expectedValue) {
    return new ResultMatcher() {

        @Override
        public void match(MvcResult result) {
            Cookie cookie = result.getResponse().getCookie(name);
            assertTrue("Response cookie not found: " + name, cookie != null);
            assertEquals("Response cookie", expectedValue, cookie.getValue());
        }
    };
}
Also used : Cookie(javax.servlet.http.Cookie) ResultMatcher(org.springframework.test.web.servlet.ResultMatcher) MvcResult(org.springframework.test.web.servlet.MvcResult)

Example 8 with ResultMatcher

use of org.springframework.test.web.servlet.ResultMatcher in project spring-framework by spring-projects.

the class CookieResultMatchers method maxAge.

/**
	 * Assert a cookie's maxAge value.
	 */
public ResultMatcher maxAge(final String name, final int maxAge) {
    return new ResultMatcher() {

        @Override
        public void match(MvcResult result) {
            Cookie cookie = result.getResponse().getCookie(name);
            assertTrue("No cookie with name: " + name, cookie != null);
            assertEquals("Response cookie maxAge", maxAge, cookie.getMaxAge());
        }
    };
}
Also used : Cookie(javax.servlet.http.Cookie) ResultMatcher(org.springframework.test.web.servlet.ResultMatcher) MvcResult(org.springframework.test.web.servlet.MvcResult)

Example 9 with ResultMatcher

use of org.springframework.test.web.servlet.ResultMatcher in project spring-framework by spring-projects.

the class HandlerResultMatchers method method.

/**
	 * Assert the controller method used to process the request.
	 */
public ResultMatcher method(final Method method) {
    return new ResultMatcher() {

        @Override
        public void match(MvcResult result) throws Exception {
            HandlerMethod handlerMethod = getHandlerMethod(result);
            assertEquals("Handler method", method, handlerMethod.getMethod());
        }
    };
}
Also used : ResultMatcher(org.springframework.test.web.servlet.ResultMatcher) MvcResult(org.springframework.test.web.servlet.MvcResult) HandlerMethod(org.springframework.web.method.HandlerMethod)

Example 10 with ResultMatcher

use of org.springframework.test.web.servlet.ResultMatcher in project spring-framework by spring-projects.

the class HandlerResultMatchers method methodName.

/**
	 * Assert the name of the controller method used to process the request
	 * using the given Hamcrest {@link Matcher}.
	 */
public ResultMatcher methodName(final Matcher<? super String> matcher) {
    return new ResultMatcher() {

        @Override
        public void match(MvcResult result) throws Exception {
            HandlerMethod handlerMethod = getHandlerMethod(result);
            assertThat("Handler method", handlerMethod.getMethod().getName(), matcher);
        }
    };
}
Also used : ResultMatcher(org.springframework.test.web.servlet.ResultMatcher) MvcResult(org.springframework.test.web.servlet.MvcResult) HandlerMethod(org.springframework.web.method.HandlerMethod)

Aggregations

MvcResult (org.springframework.test.web.servlet.MvcResult)48 ResultMatcher (org.springframework.test.web.servlet.ResultMatcher)48 Cookie (javax.servlet.http.Cookie)15 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)13 ModelAndView (org.springframework.web.servlet.ModelAndView)11 BindingResult (org.springframework.validation.BindingResult)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)4 HandlerMethod (org.springframework.web.method.HandlerMethod)4 Method (java.lang.reflect.Method)2 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Test (org.junit.Test)1 HttpStatus (org.springframework.http.HttpStatus)1 MediaType (org.springframework.http.MediaType)1 AssertionErrors (org.springframework.test.util.AssertionErrors)1 StubMvcResult (org.springframework.test.web.servlet.StubMvcResult)1 Errors (org.springframework.validation.Errors)1 MethodInvocationInfo (org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder.MethodInvocationInfo)1