Search in sources :

Example 26 with MvcResult

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);
        }
    };
}
Also used : ResultMatcher(org.springframework.test.web.servlet.ResultMatcher) MvcResult(org.springframework.test.web.servlet.MvcResult) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse)

Example 27 with MvcResult

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));
        }
    };
}
Also used : ResultMatcher(org.springframework.test.web.servlet.ResultMatcher) MvcResult(org.springframework.test.web.servlet.MvcResult) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse)

Example 28 with MvcResult

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);
        }
    };
}
Also used : ResultMatcher(org.springframework.test.web.servlet.ResultMatcher) MvcResult(org.springframework.test.web.servlet.MvcResult) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse)

Example 29 with MvcResult

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);
        }
    };
}
Also used : ResultMatcher(org.springframework.test.web.servlet.ResultMatcher) MvcResult(org.springframework.test.web.servlet.MvcResult) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse)

Example 30 with MvcResult

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();
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CountDownLatch(java.util.concurrent.CountDownLatch) MvcResult(org.springframework.test.web.servlet.MvcResult) MockMvc(org.springframework.test.web.servlet.MockMvc) Test(org.junit.Test)

Aggregations

MvcResult (org.springframework.test.web.servlet.MvcResult)628 Test (org.junit.Test)365 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)178 Test (org.junit.jupiter.api.Test)163 ResultMatcher (org.springframework.test.web.servlet.ResultMatcher)69 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)39 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)38 WebMvcTest (org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)36 MockHttpSession (org.springframework.mock.web.MockHttpSession)35 ResultActions (org.springframework.test.web.servlet.ResultActions)27 DatabaseSetup (com.github.springtestdbunit.annotation.DatabaseSetup)26 ExpectedDatabase (com.github.springtestdbunit.annotation.ExpectedDatabase)26 Map (java.util.Map)24 RequestBuilder (org.springframework.test.web.servlet.RequestBuilder)24 WithMockUser (org.springframework.security.test.context.support.WithMockUser)23 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)22 AbstractSaturnConsoleTest (com.vip.saturn.job.console.AbstractSaturnConsoleTest)20 Cookie (javax.servlet.http.Cookie)18 MockMvc (org.springframework.test.web.servlet.MockMvc)17 HttpSession (jakarta.servlet.http.HttpSession)16