Search in sources :

Example 46 with ResultMatcher

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

the class CookieResultMatchers method version.

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

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

Example 47 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 48 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 49 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 50 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)

Aggregations

ResultMatcher (org.springframework.test.web.servlet.ResultMatcher)74 MvcResult (org.springframework.test.web.servlet.MvcResult)69 Test (org.junit.jupiter.api.Test)22 Cookie (javax.servlet.http.Cookie)15 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)13 ModelAndView (org.springframework.web.servlet.ModelAndView)11 Test (org.junit.Test)5 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)5 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 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