use of org.springframework.test.web.servlet.MvcResult 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);
}
};
}
use of org.springframework.test.web.servlet.MvcResult 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));
}
};
}
use of org.springframework.test.web.servlet.MvcResult 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);
}
};
}
use of org.springframework.test.web.servlet.MvcResult 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);
}
};
}
use of org.springframework.test.web.servlet.MvcResult in project spring-boot by spring-projects.
the class MetricFilterAutoConfigurationTests method correctlyRecordsMetricsForDeferredResultResponse.
@Test
public void correctlyRecordsMetricsForDeferredResultResponse() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class, MetricFilterAutoConfiguration.class);
MetricsFilter filter = context.getBean(MetricsFilter.class);
CountDownLatch latch = new CountDownLatch(1);
MockMvc mvc = MockMvcBuilders.standaloneSetup(new MetricFilterTestController(latch)).addFilter(filter).build();
String attributeName = MetricsFilter.class.getName() + ".StopWatch";
MvcResult result = mvc.perform(post("/create")).andExpect(status().isOk()).andExpect(request().asyncStarted()).andExpect(request().attribute(attributeName, is(notNullValue()))).andReturn();
latch.countDown();
mvc.perform(asyncDispatch(result)).andExpect(status().isCreated()).andExpect(request().attribute(attributeName, is(nullValue())));
verify(context.getBean(CounterService.class)).increment("status.201.create");
context.close();
}
Aggregations