use of org.springframework.web.testfixture.servlet.MockHttpServletRequest in project spring-framework by spring-projects.
the class UriTemplateServletAnnotationControllerHandlerMethodTests method variableNamesWithUrlExtension.
// gh-13187
@PathPatternsParameterizedTest
void variableNamesWithUrlExtension(boolean usePathPatterns) throws Exception {
initDispatcherServlet(VariableNamesController.class, usePathPatterns, wac -> {
if (!usePathPatterns) {
RootBeanDefinition mappingDef = new RootBeanDefinition(RequestMappingHandlerMapping.class);
mappingDef.getPropertyValues().add("useSuffixPatternMatch", true);
wac.registerBeanDefinition("handlerMapping", mappingDef);
}
});
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/test/foo.json");
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getContentAsString()).isEqualTo(!usePathPatterns ? "foo-foo" : "foo-foo.json");
}
use of org.springframework.web.testfixture.servlet.MockHttpServletRequest in project spring-framework by spring-projects.
the class EncodedResourceResolverTests method resolveGzippedWithVersion.
@Test
public void resolveGzippedWithVersion(GzippedFiles gzippedFiles) {
gzippedFiles.create("foo.css");
String file = "foo-e36d2e05253c6c7085a91522ce43a0b4.css";
MockHttpServletRequest request = new MockHttpServletRequest();
request.addHeader("Accept-Encoding", "gzip");
Resource resolved = this.resolver.resolveResource(request, file, this.locations);
assertThat(resolved.getDescription()).isEqualTo(getResource("foo.css.gz").getDescription());
assertThat(resolved.getFilename()).isEqualTo(getResource("foo.css").getFilename());
boolean condition = resolved instanceof HttpResource;
assertThat(condition).isTrue();
}
use of org.springframework.web.testfixture.servlet.MockHttpServletRequest in project spring-framework by spring-projects.
the class EncodedResourceResolverTests method resolveGzipped.
@Test
public void resolveGzipped(GzippedFiles gzippedFiles) {
String file = "js/foo.js";
gzippedFiles.create(file);
MockHttpServletRequest request = new MockHttpServletRequest();
request.addHeader("Accept-Encoding", "gzip");
Resource actual = this.resolver.resolveResource(request, file, this.locations);
assertThat(actual.getDescription()).isEqualTo(getResource(file + ".gz").getDescription());
assertThat(actual.getFilename()).isEqualTo(getResource(file).getFilename());
boolean condition = actual instanceof HttpResource;
assertThat(condition).isTrue();
HttpHeaders headers = ((HttpResource) actual).getResponseHeaders();
assertThat(headers.getFirst(HttpHeaders.CONTENT_ENCODING)).isEqualTo("gzip");
assertThat(headers.getFirst(HttpHeaders.VARY)).isEqualTo("Accept-Encoding");
}
use of org.springframework.web.testfixture.servlet.MockHttpServletRequest in project spring-framework by spring-projects.
the class EncodedResourceResolverTests method resolveFromCacheWithEncodingVariants.
@Test
public void resolveFromCacheWithEncodingVariants(GzippedFiles gzippedFiles) {
// 1. Resolve, and cache .gz variant
String file = "js/foo.js";
gzippedFiles.create(file);
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/js/foo.js");
request.addHeader("Accept-Encoding", "gzip");
Resource resolved = this.resolver.resolveResource(request, file, this.locations);
assertThat(resolved.getDescription()).isEqualTo(getResource(file + ".gz").getDescription());
assertThat(resolved.getFilename()).isEqualTo(getResource(file).getFilename());
boolean condition = resolved instanceof HttpResource;
assertThat(condition).isTrue();
// 2. Resolve unencoded resource
request = new MockHttpServletRequest("GET", "/js/foo.js");
resolved = this.resolver.resolveResource(request, file, this.locations);
assertThat(resolved.getDescription()).isEqualTo(getResource(file).getDescription());
assertThat(resolved.getFilename()).isEqualTo(getResource(file).getFilename());
boolean condition1 = resolved instanceof HttpResource;
assertThat(condition1).isFalse();
}
use of org.springframework.web.testfixture.servlet.MockHttpServletRequest in project spring-framework by spring-projects.
the class ResourceHttpRequestHandlerIntegrationTests method initRequest.
private MockHttpServletRequest initRequest(String path) {
path = UriUtils.encodePath(path, StandardCharsets.UTF_8);
MockHttpServletRequest request = new MockHttpServletRequest("GET", path);
request.setCharacterEncoding(StandardCharsets.UTF_8.name());
return request;
}
Aggregations