Search in sources :

Example 21 with MvcResult

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

the class RequestResultMatchers method asyncNotStarted.

/**
	 * Assert that asynchronous processing was not started.
	 * @see #asyncStarted()
	 */
public ResultMatcher asyncNotStarted() {
    return new ResultMatcher() {

        @Override
        public void match(MvcResult result) {
            HttpServletRequest request = result.getRequest();
            assertEquals("Async started", false, request.isAsyncStarted());
        }
    };
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ResultMatcher(org.springframework.test.web.servlet.ResultMatcher) MvcResult(org.springframework.test.web.servlet.MvcResult)

Example 22 with MvcResult

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

the class RequestResultMatchers method asyncResult.

/**
	 * Assert the result from asynchronous processing with the given matcher.
	 * <p>This method can be used when a controller method returns {@link Callable}
	 * or {@link WebAsyncTask}.
	 */
public <T> ResultMatcher asyncResult(final Matcher<T> matcher) {
    return new ResultMatcher() {

        @Override
        @SuppressWarnings("unchecked")
        public void match(MvcResult result) {
            HttpServletRequest request = result.getRequest();
            assertAsyncStarted(request);
            assertThat("Async result", (T) result.getAsyncResult(), matcher);
        }
    };
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ResultMatcher(org.springframework.test.web.servlet.ResultMatcher) MvcResult(org.springframework.test.web.servlet.MvcResult)

Example 23 with MvcResult

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

the class ViewResultMatchers method name.

/**
	 * Assert the selected view name.
	 */
public ResultMatcher name(final String expectedViewName) {
    return new ResultMatcher() {

        @Override
        public void match(MvcResult result) throws Exception {
            ModelAndView mav = result.getModelAndView();
            assertTrue("No ModelAndView found", mav != null);
            assertEquals("View name", expectedViewName, mav.getViewName());
        }
    };
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) ResultMatcher(org.springframework.test.web.servlet.ResultMatcher) MvcResult(org.springframework.test.web.servlet.MvcResult)

Example 24 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 with the
	 * given Hamcrest {@link Matcher}.
	 */
public ResultMatcher number(final Matcher<? super Double> matcher) {
    return new ResultMatcher() {

        @Override
        public void match(MvcResult result) throws Exception {
            MockHttpServletResponse response = result.getResponse();
            xpathHelper.assertNumber(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 25 with MvcResult

use of org.springframework.test.web.servlet.MvcResult 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)

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