use of cn.taketoday.web.mock.MockHttpServletRequest in project today-infrastructure by TAKETODAY.
the class ResourceHttpRequestHandlerTests method resourceNotFound.
@Test
public void resourceNotFound() throws Exception {
for (HttpMethod method : HttpMethod.values()) {
this.request = new MockHttpServletRequest("GET", "");
this.response = new MockHttpServletResponse();
resourceNotFound(method);
}
}
use of cn.taketoday.web.mock.MockHttpServletRequest in project today-infrastructure by TAKETODAY.
the class ResourceHttpRequestHandlerTests method getResourceWithMediaTypeResolvedThroughServletContext.
// SPR-14368
@Test
public void getResourceWithMediaTypeResolvedThroughServletContext() throws Exception {
MockServletContext servletContext = new MockServletContext() {
@Override
public String getMimeType(String filePath) {
return "foo/bar";
}
};
List<Resource> paths = Collections.singletonList(new ClassPathResource("test/", getClass()));
ResourceHttpRequestHandler handler = new ResourceHttpRequestHandler();
handler.setLocations(paths);
handler.afterPropertiesSet();
MockHttpServletRequest request = new MockHttpServletRequest(servletContext, "GET", "");
request.setRequestURI("foo.css");
handler.handleRequest(new ServletRequestContext(null, request, response));
assertThat(this.response.getContentType()).isEqualTo("foo/bar");
assertThat(this.response.getContentAsString()).isEqualTo("h1 { color:red; }");
}
use of cn.taketoday.web.mock.MockHttpServletRequest in project today-infrastructure by TAKETODAY.
the class ResourceHttpRequestHandlerTests method setup.
@BeforeEach
public void setup() throws Exception {
List<Resource> paths = new ArrayList<>(2);
paths.add(new ClassPathResource("test/", getClass()));
paths.add(new ClassPathResource("testalternatepath/", getClass()));
paths.add(new ClassPathResource("META-INF/resources/webjars/"));
TestServletContext servletContext = new TestServletContext();
this.handler = new ResourceHttpRequestHandler();
this.handler.setLocations(paths);
this.handler.setCacheSeconds(3600);
this.handler.afterPropertiesSet();
this.request = new MockHttpServletRequest(servletContext, "GET", "");
this.response = new MockHttpServletResponse();
requestContext = new ServletRequestContext(null, request, response);
}
use of cn.taketoday.web.mock.MockHttpServletRequest in project today-infrastructure by TAKETODAY.
the class ResourceHttpRequestHandlerTests method resolvePathWithTraversal.
@Test
@DisabledOnOs(OS.WINDOWS)
public void resolvePathWithTraversal() throws Exception {
for (HttpMethod method : HttpMethod.values()) {
this.request = new MockHttpServletRequest("GET", "");
this.response = new MockHttpServletResponse();
requestContext = new ServletRequestContext(null, request, response);
testResolvePathWithTraversal(method);
}
}
use of cn.taketoday.web.mock.MockHttpServletRequest in project today-infrastructure by TAKETODAY.
the class ResourceUrlProviderJavaConfigTests method setup.
@BeforeEach
@SuppressWarnings("resource")
public void setup() throws Exception {
AnnotationConfigServletWebApplicationContext context = new AnnotationConfigServletWebApplicationContext();
context.setServletContext(new MockServletContext());
context.register(WebConfig.class);
context.refresh();
this.request = new MockHttpServletRequest("GET", "/");
this.request.setContextPath("/myapp");
this.response = new MockHttpServletResponse();
this.filterChain = new MockFilterChain(this.servlet);
}
Aggregations