Search in sources :

Example 21 with MockHttpServletResponse

use of org.springframework.mock.web.MockHttpServletResponse 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 22 with MockHttpServletResponse

use of org.springframework.mock.web.MockHttpServletResponse 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 23 with MockHttpServletResponse

use of org.springframework.mock.web.MockHttpServletResponse 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 24 with MockHttpServletResponse

use of org.springframework.mock.web.MockHttpServletResponse in project spring-boot by spring-projects.

the class FreeMarkerAutoConfigurationTests method customSuffix.

@Test
public void customSuffix() throws Exception {
    registerAndRefreshContext("spring.freemarker.suffix:.freemarker");
    MockHttpServletResponse response = render("suffixed");
    String result = response.getContentAsString();
    assertThat(result).contains("suffixed");
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 25 with MockHttpServletResponse

use of org.springframework.mock.web.MockHttpServletResponse in project spring-boot by spring-projects.

the class FreeMarkerAutoConfigurationTests method defaultViewResolution.

@Test
public void defaultViewResolution() throws Exception {
    registerAndRefreshContext();
    MockHttpServletResponse response = render("home");
    String result = response.getContentAsString();
    assertThat(result).contains("home");
    assertThat(response.getContentType()).isEqualTo("text/html;charset=UTF-8");
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Aggregations

MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)2376 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)2002 Test (org.junit.jupiter.api.Test)1416 lombok.val (lombok.val)946 Test (org.junit.Test)582 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)484 MockServletContext (org.springframework.mock.web.MockServletContext)462 MockRequestContext (org.springframework.webflow.test.MockRequestContext)460 MockFilterChain (org.springframework.mock.web.MockFilterChain)240 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)185 JEEContext (org.pac4j.core.context.JEEContext)159 FilterChain (jakarta.servlet.FilterChain)117 Authentication (org.springframework.security.core.Authentication)116 BeforeEach (org.junit.jupiter.api.BeforeEach)107 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)97 HashMap (java.util.HashMap)84 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)83 WebMvcTest (org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)74 HttpServletResponse (jakarta.servlet.http.HttpServletResponse)67 MockHttpSession (org.springframework.mock.web.MockHttpSession)67