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);
}
use of org.springframework.web.servlet.DispatcherServlet in project spring-boot by spring-projects.
the class ServletWebServerFactoryAutoConfigurationTests method verifyContext.
private void verifyContext() {
MockServletWebServerFactory factory = getWebServerFactory();
Servlet servlet = this.context.getBean(DispatcherServletAutoConfiguration.DEFAULT_DISPATCHER_SERVLET_BEAN_NAME, Servlet.class);
verify(factory.getServletContext()).addServlet("dispatcherServlet", servlet);
}
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());
}
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);
}
use of org.springframework.web.servlet.DispatcherServlet in project spring-boot by spring-projects.
the class DispatcherServletAutoConfigurationTests method registrationOverrideWithDispatcherServletWrongName.
// If a DispatcherServlet instance is registered with a name different
// from the default one, we're registering one anyway
@Test
public void registrationOverrideWithDispatcherServletWrongName() throws Exception {
this.context = new AnnotationConfigWebApplicationContext();
this.context.register(CustomDispatcherServletWrongName.class, DispatcherServletAutoConfiguration.class);
this.context.setServletContext(new MockServletContext());
this.context.refresh();
ServletRegistrationBean<?> registration = this.context.getBean(ServletRegistrationBean.class);
assertThat(registration.getUrlMappings().toString()).isEqualTo("[/]");
assertThat(registration.getServletName()).isEqualTo("dispatcherServlet");
assertThat(this.context.getBeanNamesForType(DispatcherServlet.class).length).isEqualTo(2);
}
Aggregations