use of org.springframework.web.testfixture.servlet.MockHttpServletRequest in project spring-framework by spring-projects.
the class ViewMethodReturnValueHandlerTests method setup.
@BeforeEach
public void setup() {
this.handler = new ViewMethodReturnValueHandler();
this.mavContainer = new ModelAndViewContainer();
this.webRequest = new ServletWebRequest(new MockHttpServletRequest());
}
use of org.springframework.web.testfixture.servlet.MockHttpServletRequest in project spring-framework by spring-projects.
the class DefaultHandlerExceptionResolverTests method handleNoHandlerFoundException.
@Test
public void handleNoHandlerFoundException() throws Exception {
ServletServerHttpRequest req = new ServletServerHttpRequest(new MockHttpServletRequest("GET", "/resource"));
NoHandlerFoundException ex = new NoHandlerFoundException(req.getMethod().name(), req.getServletRequest().getRequestURI(), req.getHeaders());
ModelAndView mav = exceptionResolver.resolveException(request, response, null, ex);
assertThat(mav).as("No ModelAndView returned").isNotNull();
assertThat(mav.isEmpty()).as("No Empty ModelAndView returned").isTrue();
assertThat(response.getStatus()).as("Invalid status code").isEqualTo(404);
}
use of org.springframework.web.testfixture.servlet.MockHttpServletRequest in project spring-framework by spring-projects.
the class FlashMapManagerTests method saveOutputFlashMapDecodeParameters.
// SPR-9657, SPR-11504
@Test
public void saveOutputFlashMapDecodeParameters() throws Exception {
FlashMap flashMap = new FlashMap();
flashMap.put("key", "value");
flashMap.setTargetRequestPath("/path");
flashMap.addTargetRequestParam("param", "%D0%90%D0%90");
flashMap.addTargetRequestParam("param", "%D0%91%D0%91");
flashMap.addTargetRequestParam("param", "%D0%92%D0%92");
flashMap.addTargetRequestParam("%3A%2F%3F%23%5B%5D%40", "value");
this.request.setCharacterEncoding("UTF-8");
this.flashMapManager.saveOutputFlashMap(flashMap, this.request, this.response);
MockHttpServletRequest requestAfterRedirect = new MockHttpServletRequest("GET", "/path");
requestAfterRedirect.setQueryString("param=%D0%90%D0%90¶m=%D0%91%D0%91¶m=%D0%92%D0%92&%3A%2F%3F%23%5B%5D%40=value");
requestAfterRedirect.addParameter("param", "\u0410\u0410");
requestAfterRedirect.addParameter("param", "\u0411\u0411");
requestAfterRedirect.addParameter("param", "\u0412\u0412");
requestAfterRedirect.addParameter(":/?#[]@", "value");
flashMap = this.flashMapManager.retrieveAndUpdate(requestAfterRedirect, new MockHttpServletResponse());
assertThatFlashMap(flashMap).isNotNull();
assertThat(flashMap.size()).isEqualTo(1);
assertThat(flashMap.get("key")).isEqualTo("value");
}
use of org.springframework.web.testfixture.servlet.MockHttpServletRequest in project spring-framework by spring-projects.
the class CachingResourceResolverTests method resolveResourceAcceptEncodingInCacheKey.
@Test
public void resolveResourceAcceptEncodingInCacheKey(GzippedFiles gzippedFiles) throws IOException {
String file = "bar.css";
gzippedFiles.create(file);
// 1. Resolve plain resource
MockHttpServletRequest request = new MockHttpServletRequest("GET", file);
Resource expected = this.chain.resolveResource(request, file, this.locations);
String cacheKey = resourceKey(file);
assertThat(this.cache.get(cacheKey).get()).isSameAs(expected);
// 2. Resolve with Accept-Encoding
request = new MockHttpServletRequest("GET", file);
request.addHeader("Accept-Encoding", "gzip ; a=b , deflate , br ; c=d ");
expected = this.chain.resolveResource(request, file, this.locations);
cacheKey = resourceKey(file + "+encoding=br,gzip");
assertThat(this.cache.get(cacheKey).get()).isSameAs(expected);
// 3. Resolve with Accept-Encoding but no matching codings
request = new MockHttpServletRequest("GET", file);
request.addHeader("Accept-Encoding", "deflate");
expected = this.chain.resolveResource(request, file, this.locations);
cacheKey = resourceKey(file);
assertThat(this.cache.get(cacheKey).get()).isSameAs(expected);
}
use of org.springframework.web.testfixture.servlet.MockHttpServletRequest in project spring-framework by spring-projects.
the class CachingResourceResolverTests method resolveResourceMatchingEncoding.
@Test
public void resolveResourceMatchingEncoding() {
Resource resource = Mockito.mock(Resource.class);
Resource gzipped = Mockito.mock(Resource.class);
this.cache.put(resourceKey("bar.css"), resource);
this.cache.put(resourceKey("bar.css+encoding=gzip"), gzipped);
MockHttpServletRequest request = new MockHttpServletRequest("GET", "bar.css");
assertThat(this.chain.resolveResource(request, "bar.css", this.locations)).isSameAs(resource);
request = new MockHttpServletRequest("GET", "bar.css");
request.addHeader("Accept-Encoding", "gzip");
assertThat(this.chain.resolveResource(request, "bar.css", this.locations)).isSameAs(gzipped);
}
Aggregations