Search in sources :

Example 21 with ResultMatcher

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

the class XpathResultMatchers method doesNotExist.

/**
	 * Evaluate the XPath and assert that content doesn't exist.
	 */
public ResultMatcher doesNotExist() {
    return new ResultMatcher() {

        @Override
        public void match(MvcResult result) throws Exception {
            MockHttpServletResponse response = result.getResponse();
            xpathHelper.doesNotExist(response.getContentAsByteArray(), getDefinedEncoding(response));
        }
    };
}
Also used : ResultMatcher(org.springframework.test.web.servlet.ResultMatcher) MvcResult(org.springframework.test.web.servlet.MvcResult) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse)

Example 22 with ResultMatcher

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

the class XpathResultMatchers method booleanValue.

/**
	 * Evaluate the XPath and assert the {@link Boolean} value found.
	 */
public ResultMatcher booleanValue(final Boolean value) {
    return new ResultMatcher() {

        @Override
        public void match(MvcResult result) throws Exception {
            MockHttpServletResponse response = result.getResponse();
            xpathHelper.assertBoolean(response.getContentAsByteArray(), getDefinedEncoding(response), value);
        }
    };
}
Also used : ResultMatcher(org.springframework.test.web.servlet.ResultMatcher) MvcResult(org.springframework.test.web.servlet.MvcResult) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse)

Example 23 with ResultMatcher

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

the class XpathResultMatchers method exists.

/**
	 * Evaluate the XPath and assert that content exists.
	 */
public ResultMatcher exists() {
    return new ResultMatcher() {

        @Override
        public void match(MvcResult result) throws Exception {
            MockHttpServletResponse response = result.getResponse();
            xpathHelper.exists(response.getContentAsByteArray(), getDefinedEncoding(response));
        }
    };
}
Also used : ResultMatcher(org.springframework.test.web.servlet.ResultMatcher) MvcResult(org.springframework.test.web.servlet.MvcResult) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse)

Example 24 with ResultMatcher

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

the class XpathResultMatchers method number.

/**
	 * Evaluate the XPath and assert the {@link Double} value found.
	 */
public ResultMatcher number(final Double expectedValue) {
    return new ResultMatcher() {

        @Override
        public void match(MvcResult result) throws Exception {
            MockHttpServletResponse response = result.getResponse();
            xpathHelper.assertNumber(response.getContentAsByteArray(), getDefinedEncoding(response), expectedValue);
        }
    };
}
Also used : ResultMatcher(org.springframework.test.web.servlet.ResultMatcher) MvcResult(org.springframework.test.web.servlet.MvcResult) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse)

Example 25 with ResultMatcher

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

the class XpathResultMatchers method nodeCount.

/**
	 * Evaluate the XPath and assert the number of nodes found with the given
	 * Hamcrest {@link Matcher}.
	 */
public ResultMatcher nodeCount(final Matcher<Integer> matcher) {
    return new ResultMatcher() {

        @Override
        public void match(MvcResult result) throws Exception {
            MockHttpServletResponse response = result.getResponse();
            xpathHelper.assertNodeCount(response.getContentAsByteArray(), getDefinedEncoding(response), matcher);
        }
    };
}
Also used : ResultMatcher(org.springframework.test.web.servlet.ResultMatcher) MvcResult(org.springframework.test.web.servlet.MvcResult) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse)

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