use of org.springframework.mock.web.MockServletContext in project spring-boot by spring-projects.
the class HypermediaAutoConfigurationTests method entityLinksCreated.
@Test
public void entityLinksCreated() throws Exception {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
this.context.register(BaseConfig.class);
this.context.refresh();
EntityLinks discoverers = this.context.getBean(EntityLinks.class);
assertThat(discoverers).isNotNull();
}
use of org.springframework.mock.web.MockServletContext in project spring-boot by spring-projects.
the class HypermediaAutoConfigurationTests method jacksonConfigurationIsAppliedToTheHalObjectMapper.
@Test
public void jacksonConfigurationIsAppliedToTheHalObjectMapper() {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
this.context.register(BaseConfig.class);
EnvironmentTestUtils.addEnvironment(this.context, "spring.jackson.serialization.INDENT_OUTPUT:true");
this.context.refresh();
ObjectMapper objectMapper = this.context.getBean("_halObjectMapper", ObjectMapper.class);
assertThat(objectMapper.getSerializationConfig().isEnabled(SerializationFeature.INDENT_OUTPUT)).isTrue();
}
use of org.springframework.mock.web.MockServletContext in project spring-boot by spring-projects.
the class ThymeleafAutoConfigurationTests method createLayoutFromConfigClass.
@Test
public void createLayoutFromConfigClass() throws Exception {
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
context.register(ThymeleafAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
MockServletContext servletContext = new MockServletContext();
context.setServletContext(servletContext);
context.refresh();
ThymeleafView view = (ThymeleafView) context.getBean(ThymeleafViewResolver.class).resolveViewName("view", Locale.UK);
MockHttpServletResponse response = new MockHttpServletResponse();
MockHttpServletRequest request = new MockHttpServletRequest();
request.setAttribute(RequestContext.WEB_APPLICATION_CONTEXT_ATTRIBUTE, context);
view.render(Collections.singletonMap("foo", "bar"), request, response);
String result = response.getContentAsString();
assertThat(result).contains("<title>Content</title>");
assertThat(result).contains("<span>bar</span>");
context.close();
}
use of org.springframework.mock.web.MockServletContext 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.mock.web.MockServletContext 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