Search in sources :

Example 6 with DispatcherServlet

use of cn.taketoday.web.servlet.DispatcherServlet in project today-framework by TAKETODAY.

the class ResourceHttpRequestHandlerIntegrationTests method initDispatcherServlet.

private DispatcherServlet initDispatcherServlet(Class<?>... configClasses) throws ServletException {
    AnnotationConfigServletWebApplicationContext context = new AnnotationConfigServletWebApplicationContext();
    context.setServletContext(this.servletContext);
    context.register(configClasses);
    context.refresh();
    DispatcherServlet servlet = new DispatcherServlet(context);
    // servlet.setApplicationContext(context);
    servlet.init(this.servletConfig);
    return servlet;
}
Also used : AnnotationConfigServletWebApplicationContext(cn.taketoday.framework.web.servlet.context.AnnotationConfigServletWebApplicationContext) DispatcherServlet(cn.taketoday.web.servlet.DispatcherServlet)

Example 7 with DispatcherServlet

use of cn.taketoday.web.servlet.DispatcherServlet in project today-framework by TAKETODAY.

the class ResourceHttpRequestHandlerIntegrationTests method classpathLocationWithEncodedPath.

@ParameterizedTest
@MethodSource("argumentSource")
void classpathLocationWithEncodedPath(boolean usePathPatterns, String pathPrefix) throws Exception {
    MockHttpServletRequest request = initRequest(pathPrefix + "/test/foo with spaces.css");
    MockHttpServletResponse response = new MockHttpServletResponse();
    DispatcherServlet servlet = initDispatcherServlet(WebConfig.class);
    servlet.service(request, response);
    String description = "usePathPattern=" + usePathPatterns + ", prefix=" + pathPrefix;
    assertThat(response.getStatus()).as(description).isEqualTo(200);
    assertThat(response.getContentType()).as(description).isEqualTo("text/css");
    assertThat(response.getContentAsString()).as(description).isEqualTo("h1 { color:red; }");
}
Also used : MockHttpServletRequest(cn.taketoday.web.testfixture.servlet.MockHttpServletRequest) DispatcherServlet(cn.taketoday.web.servlet.DispatcherServlet) MockHttpServletResponse(cn.taketoday.web.testfixture.servlet.MockHttpServletResponse) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 8 with DispatcherServlet

use of cn.taketoday.web.servlet.DispatcherServlet in project today-infrastructure by TAKETODAY.

the class ResourceHttpRequestHandlerIntegrationTests method initDispatcherServlet.

private DispatcherServlet initDispatcherServlet(Class<?>... configClasses) throws ServletException {
    AnnotationConfigServletWebApplicationContext context = new AnnotationConfigServletWebApplicationContext();
    context.setServletContext(this.servletContext);
    context.register(configClasses);
    context.refresh();
    DispatcherServlet servlet = new DispatcherServlet(context);
    // servlet.setApplicationContext(context);
    servlet.init(this.servletConfig);
    return servlet;
}
Also used : AnnotationConfigServletWebApplicationContext(cn.taketoday.framework.web.servlet.context.AnnotationConfigServletWebApplicationContext) DispatcherServlet(cn.taketoday.web.servlet.DispatcherServlet)

Example 9 with DispatcherServlet

use of cn.taketoday.web.servlet.DispatcherServlet in project today-infrastructure by TAKETODAY.

the class ResourceHttpRequestHandlerIntegrationTests method cssFile.

@ParameterizedTest
@MethodSource("argumentSource")
void cssFile(boolean usePathPatterns, String pathPrefix) throws Exception {
    MockHttpServletRequest request = initRequest(pathPrefix + "/test/foo.css");
    MockHttpServletResponse response = new MockHttpServletResponse();
    DispatcherServlet servlet = initDispatcherServlet(WebConfig.class);
    servlet.service(request, response);
    String description = "usePathPattern=" + usePathPatterns + ", prefix=" + pathPrefix;
    assertThat(response.getStatus()).as(description).isEqualTo(200);
    assertThat(response.getContentType()).as(description).isEqualTo("text/css");
    assertThat(response.getContentAsString()).as(description).isEqualTo("h1 { color:red; }");
}
Also used : MockHttpServletRequest(cn.taketoday.web.mock.MockHttpServletRequest) DispatcherServlet(cn.taketoday.web.servlet.DispatcherServlet) MockHttpServletResponse(cn.taketoday.web.mock.MockHttpServletResponse) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

DispatcherServlet (cn.taketoday.web.servlet.DispatcherServlet)9 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 MethodSource (org.junit.jupiter.params.provider.MethodSource)4 AnnotationConfigServletWebApplicationContext (cn.taketoday.framework.web.servlet.context.AnnotationConfigServletWebApplicationContext)2 StaticWebApplicationContext (cn.taketoday.web.context.support.StaticWebApplicationContext)2 MockHttpServletRequest (cn.taketoday.web.mock.MockHttpServletRequest)2 MockHttpServletResponse (cn.taketoday.web.mock.MockHttpServletResponse)2 MockHttpServletRequest (cn.taketoday.web.testfixture.servlet.MockHttpServletRequest)2 MockHttpServletResponse (cn.taketoday.web.testfixture.servlet.MockHttpServletResponse)2 MockServletConfig (cn.taketoday.web.testfixture.servlet.MockServletConfig)2 Test (org.junit.jupiter.api.Test)2 BeanDefinitionRegistry (cn.taketoday.beans.factory.support.BeanDefinitionRegistry)1 AnnotatedBeanDefinitionReader (cn.taketoday.context.annotation.AnnotatedBeanDefinitionReader)1 RequestBindingException (cn.taketoday.web.bind.RequestBindingException)1 WebServletApplicationContext (cn.taketoday.web.servlet.WebServletApplicationContext)1 ServletException (jakarta.servlet.ServletException)1