Search in sources :

Example 1 with DispatcherServlet

use of org.springframework.web.servlet.DispatcherServlet in project pinpoint by naver.

the class SpringWebMvcIT method testRequest.

@Test
public void testRequest() throws Exception {
    MockServletConfig config = new MockServletConfig();
    MockHttpServletRequest req = new MockHttpServletRequest();
    MockHttpServletResponse res = new MockHttpServletResponse();
    config.addInitParameter("contextConfigLocation", "classpath:spring-web-test.xml");
    req.setMethod("GET");
    req.setRequestURI("/");
    req.setRemoteAddr("1.2.3.4");
    DispatcherServlet servlet = new DispatcherServlet();
    servlet.init(config);
    servlet.service(req, res);
    Method method = FrameworkServlet.class.getDeclaredMethod("doGet", HttpServletRequest.class, HttpServletResponse.class);
    PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
    verifier.printCache();
    verifier.verifyTrace(Expectations.event(SPRING_MVC, method));
    verifier.verifyTraceCount(0);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) DispatcherServlet(org.springframework.web.servlet.DispatcherServlet) MockServletConfig(org.springframework.mock.web.MockServletConfig) Method(java.lang.reflect.Method) PluginTestVerifier(com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 2 with DispatcherServlet

use of org.springframework.web.servlet.DispatcherServlet in project spring-boot by spring-projects.

the class MultipartAutoConfigurationTests method webServerWithNothing.

@Test
public void webServerWithNothing() throws Exception {
    this.context = new AnnotationConfigServletWebServerApplicationContext(WebServerWithNothing.class, BaseConfiguration.class);
    DispatcherServlet servlet = this.context.getBean(DispatcherServlet.class);
    verify404();
    assertThat(servlet.getMultipartResolver()).isNotNull();
    assertThat(this.context.getBeansOfType(StandardServletMultipartResolver.class)).hasSize(1);
    assertThat(this.context.getBeansOfType(MultipartResolver.class)).hasSize(1);
}
Also used : AnnotationConfigServletWebServerApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext) DispatcherServlet(org.springframework.web.servlet.DispatcherServlet) Test(org.junit.Test)

Example 3 with DispatcherServlet

use of org.springframework.web.servlet.DispatcherServlet in project spring-framework by spring-projects.

the class DefaultMockMvcBuilderTests method dispatcherServletCustomizer.

/**
	 * See /SPR-14277
	 */
@Test
public void dispatcherServletCustomizer() {
    StubWebApplicationContext root = new StubWebApplicationContext(this.servletContext);
    DefaultMockMvcBuilder builder = webAppContextSetup(root);
    builder.addDispatcherServletCustomizer(ds -> ds.setContextId("test-id"));
    builder.dispatchOptions(true);
    MockMvc mvc = builder.build();
    DispatcherServlet ds = (DispatcherServlet) new DirectFieldAccessor(mvc).getPropertyValue("servlet");
    assertEquals("test-id", ds.getContextId());
}
Also used : DispatcherServlet(org.springframework.web.servlet.DispatcherServlet) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) MockMvc(org.springframework.test.web.servlet.MockMvc) Test(org.junit.Test)

Example 4 with DispatcherServlet

use of org.springframework.web.servlet.DispatcherServlet in project spring-boot by spring-projects.

the class EndpointWebMvcChildContextConfiguration method dispatcherServlet.

@Bean(name = DispatcherServletAutoConfiguration.DEFAULT_DISPATCHER_SERVLET_BEAN_NAME)
public DispatcherServlet dispatcherServlet() {
    DispatcherServlet dispatcherServlet = new DispatcherServlet();
    // Ensure the parent configuration does not leak down to us
    dispatcherServlet.setDetectAllHandlerAdapters(false);
    dispatcherServlet.setDetectAllHandlerExceptionResolvers(false);
    dispatcherServlet.setDetectAllHandlerMappings(false);
    dispatcherServlet.setDetectAllViewResolvers(false);
    return dispatcherServlet;
}
Also used : DispatcherServlet(org.springframework.web.servlet.DispatcherServlet) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) Bean(org.springframework.context.annotation.Bean)

Example 5 with DispatcherServlet

use of org.springframework.web.servlet.DispatcherServlet in project spring-boot by spring-projects.

the class DispatcherServletAutoConfigurationTests method renamesMultipartResolver.

@Test
public void renamesMultipartResolver() throws Exception {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());
    this.context.register(MultipartResolverConfiguration.class, DispatcherServletAutoConfiguration.class);
    this.context.refresh();
    DispatcherServlet dispatcherServlet = this.context.getBean(DispatcherServlet.class);
    dispatcherServlet.onApplicationEvent(new ContextRefreshedEvent(this.context));
    assertThat(dispatcherServlet.getMultipartResolver()).isInstanceOf(MockMultipartResolver.class);
}
Also used : DispatcherServlet(org.springframework.web.servlet.DispatcherServlet) AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) MockServletContext(org.springframework.mock.web.MockServletContext) ContextRefreshedEvent(org.springframework.context.event.ContextRefreshedEvent) Test(org.junit.Test)

Aggregations

DispatcherServlet (org.springframework.web.servlet.DispatcherServlet)33 Test (org.junit.Test)16 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)14 MockServletConfig (org.springframework.mock.web.test.MockServletConfig)7 WebApplicationContext (org.springframework.web.context.WebApplicationContext)6 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)5 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)5 ServletRegistration (javax.servlet.ServletRegistration)4 Server (org.eclipse.jetty.server.Server)4 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)4 AnnotationConfigServletWebServerApplicationContext (org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext)4 Bean (org.springframework.context.annotation.Bean)4 MockServletContext (org.springframework.mock.web.MockServletContext)4 InetSocketAddress (java.net.InetSocketAddress)3 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)3 Order (org.springframework.core.annotation.Order)3 MockServletContext (org.springframework.mock.web.test.MockServletContext)3 GenericWebApplicationContext (org.springframework.web.context.support.GenericWebApplicationContext)3 Filter (javax.servlet.Filter)2 ServerConnector (org.eclipse.jetty.server.ServerConnector)2