Search in sources :

Example 36 with ResultMatcher

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

the class CookieResultMatchers method path.

public ResultMatcher path(final String name, final String path) {
    return new ResultMatcher() {

        @Override
        public void match(MvcResult result) throws Exception {
            Cookie cookie = result.getResponse().getCookie(name);
            assertEquals("Response cookie path", path, cookie.getPath());
        }
    };
}
Also used : Cookie(javax.servlet.http.Cookie) ResultMatcher(org.springframework.test.web.servlet.ResultMatcher) MvcResult(org.springframework.test.web.servlet.MvcResult)

Example 37 with ResultMatcher

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

the class CookieResultMatchers method path.

/**
	 * Assert a cookie path with a Hamcrest {@link Matcher}.
	 */
public ResultMatcher path(final String name, final Matcher<? super String> matcher) {
    return new ResultMatcher() {

        @Override
        public void match(MvcResult result) throws Exception {
            Cookie cookie = result.getResponse().getCookie(name);
            assertThat("Response cookie path", cookie.getPath(), matcher);
        }
    };
}
Also used : Cookie(javax.servlet.http.Cookie) ResultMatcher(org.springframework.test.web.servlet.ResultMatcher) MvcResult(org.springframework.test.web.servlet.MvcResult)

Example 38 with ResultMatcher

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

the class CookieResultMatchers method domain.

/**
	 * Assert a cookie's domain with a Hamcrest {@link Matcher}.
	 */
public ResultMatcher domain(final String name, final Matcher<? super String> matcher) {
    return new ResultMatcher() {

        @Override
        public void match(MvcResult result) throws Exception {
            Cookie cookie = result.getResponse().getCookie(name);
            assertThat("Response cookie domain", cookie.getDomain(), matcher);
        }
    };
}
Also used : Cookie(javax.servlet.http.Cookie) ResultMatcher(org.springframework.test.web.servlet.ResultMatcher) MvcResult(org.springframework.test.web.servlet.MvcResult)

Example 39 with ResultMatcher

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

the class CookieResultMatchers method comment.

/**
	 * Assert a cookie's comment with a Hamcrest {@link Matcher}.
	 */
public ResultMatcher comment(final String name, final Matcher<? super String> matcher) {
    return new ResultMatcher() {

        @Override
        public void match(MvcResult result) throws Exception {
            Cookie cookie = result.getResponse().getCookie(name);
            assertThat("Response cookie comment", cookie.getComment(), matcher);
        }
    };
}
Also used : Cookie(javax.servlet.http.Cookie) ResultMatcher(org.springframework.test.web.servlet.ResultMatcher) MvcResult(org.springframework.test.web.servlet.MvcResult)

Example 40 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.
	 */
public ResultMatcher methodName(final String name) {
    return new ResultMatcher() {

        @Override
        public void match(MvcResult result) throws Exception {
            HandlerMethod handlerMethod = getHandlerMethod(result);
            assertEquals("Handler method", name, handlerMethod.getMethod().getName());
        }
    };
}
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