use of org.springframework.test.web.servlet.ResultMatcher in project spring-framework by spring-projects.
the class XpathResultMatchers method string.
/**
* Apply the XPath and assert the {@link String} value found with the given
* Hamcrest {@link Matcher}.
*/
public ResultMatcher string(final Matcher<? super String> matcher) {
return new ResultMatcher() {
@Override
public void match(MvcResult result) throws Exception {
MockHttpServletResponse response = result.getResponse();
xpathHelper.assertString(response.getContentAsByteArray(), getDefinedEncoding(response), matcher);
}
};
}
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.
*/
public ResultMatcher nodeCount(final int expectedCount) {
return new ResultMatcher() {
@Override
public void match(MvcResult result) throws Exception {
MockHttpServletResponse response = result.getResponse();
xpathHelper.assertNodeCount(response.getContentAsByteArray(), getDefinedEncoding(response), expectedCount);
}
};
}
use of org.springframework.test.web.servlet.ResultMatcher in project spring-framework by spring-projects.
the class XpathResultMatchers method node.
/**
* Evaluate the XPath and assert the {@link Node} content found with the
* given Hamcrest {@link Matcher}.
*/
public ResultMatcher node(final Matcher<? super Node> matcher) {
return new ResultMatcher() {
@Override
public void match(MvcResult result) throws Exception {
MockHttpServletResponse response = result.getResponse();
xpathHelper.assertNode(response.getContentAsByteArray(), getDefinedEncoding(response), matcher);
}
};
}
use of org.springframework.test.web.servlet.ResultMatcher in project spring-framework by spring-projects.
the class XpathResultMatchers method string.
/**
* Apply the XPath and assert the {@link String} value found.
*/
public ResultMatcher string(final String expectedValue) {
return new ResultMatcher() {
@Override
public void match(MvcResult result) throws Exception {
MockHttpServletResponse response = result.getResponse();
xpathHelper.assertString(response.getContentAsByteArray(), getDefinedEncoding(response), expectedValue);
}
};
}
use of org.springframework.test.web.servlet.ResultMatcher in project tutorials by eugenp.
the class RequestMapingShortcutsIntegrationTest method giventUrl_whenPatchRequest_thenFindPatchResponse.
@Test
public void giventUrl_whenPatchRequest_thenFindPatchResponse() throws Exception {
MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.patch("/patch");
ResultMatcher contentMatcher = MockMvcResultMatchers.content().string("PATCH Response");
this.mockMvc.perform(builder).andExpect(contentMatcher).andExpect(MockMvcResultMatchers.status().isOk());
}
Aggregations