use of org.springframework.web.testfixture.servlet.MockHttpServletRequest in project spring-framework by spring-projects.
the class CssLinkResourceTransformerTests method transform.
@Test
public void transform() throws Exception {
this.request = new MockHttpServletRequest("GET", "/static/main.css");
Resource css = getResource("main.css");
String expected = "\n" + "@import url(\"/static/bar-11e16cf79faee7ac698c805cf28248d2.css?#iefix\");\n" + "@import url('/static/bar-11e16cf79faee7ac698c805cf28248d2.css#bla-normal');\n" + "@import url(/static/bar-11e16cf79faee7ac698c805cf28248d2.css);\n\n" + "@import \"/static/foo-e36d2e05253c6c7085a91522ce43a0b4.css\";\n" + "@import '/static/foo-e36d2e05253c6c7085a91522ce43a0b4.css';\n\n" + "body { background: url(\"/static/images/image-f448cd1d5dba82b774f3202c878230b3.png?#iefix\") }\n";
TransformedResource actual = (TransformedResource) this.transformerChain.transform(this.request, css);
String result = new String(actual.getByteArray(), StandardCharsets.UTF_8);
result = StringUtils.deleteAny(result, "\r");
assertThat(result).isEqualTo(expected);
}
use of org.springframework.web.testfixture.servlet.MockHttpServletRequest in project spring-framework by spring-projects.
the class ServletRequestMethodArgumentResolverTests method pushBuilder.
@Test
public void pushBuilder() throws Exception {
final PushBuilder pushBuilder = Mockito.mock(PushBuilder.class);
servletRequest = new MockHttpServletRequest("GET", "") {
@Override
public PushBuilder newPushBuilder() {
return pushBuilder;
}
};
ServletWebRequest webRequest = new ServletWebRequest(servletRequest, new MockHttpServletResponse());
MethodParameter pushBuilderParameter = new MethodParameter(method, 11);
assertThat(resolver.supportsParameter(pushBuilderParameter)).as("PushBuilder not supported").isTrue();
Object result = resolver.resolveArgument(pushBuilderParameter, null, webRequest, null);
assertThat(result).as("Invalid result").isSameAs(pushBuilder);
}
use of org.springframework.web.testfixture.servlet.MockHttpServletRequest in project spring-framework by spring-projects.
the class UriTemplateServletAnnotationControllerHandlerMethodTests method extension.
@PathPatternsParameterizedTest
void extension(boolean usePathPatterns) throws Exception {
initDispatcherServlet(SimpleUriTemplateController.class, usePathPatterns, wac -> {
if (!usePathPatterns) {
RootBeanDefinition mappingDef = new RootBeanDefinition(RequestMappingHandlerMapping.class);
mappingDef.getPropertyValues().add("useSuffixPatternMatch", true);
mappingDef.getPropertyValues().add("removeSemicolonContent", "false");
wac.registerBeanDefinition("handlerMapping", mappingDef);
}
});
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/42;jsessionid=c0o7fszeb1;q=24.xml");
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getContentAsString()).isEqualTo(!usePathPatterns ? "test-42-24" : "test-42-24.xml");
}
use of org.springframework.web.testfixture.servlet.MockHttpServletRequest in project spring-framework by spring-projects.
the class UriTemplateServletAnnotationControllerHandlerMethodTests method menuTree.
// gh-11306
@PathPatternsParameterizedTest
void menuTree(boolean usePathPatterns) throws Exception {
initDispatcherServlet(MenuTreeController.class, usePathPatterns);
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/book/menu/type/M5");
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getContentAsString()).isEqualTo("M5");
}
use of org.springframework.web.testfixture.servlet.MockHttpServletRequest in project spring-framework by spring-projects.
the class UriTemplateServletAnnotationControllerHandlerMethodTests method customRegex.
@PathPatternsParameterizedTest
void customRegex(boolean usePathPatterns) throws Exception {
initDispatcherServlet(CustomRegexController.class, usePathPatterns);
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/42;q=1;q=2");
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getStatus()).isEqualTo(200);
assertThat(response.getContentAsString()).isEqualTo(!usePathPatterns ? "test-42-;q=1;q=2-[1, 2]" : "test-42--[1, 2]");
}
Aggregations