use of org.springframework.web.context.support.AnnotationConfigWebApplicationContext in project spring-boot by spring-projects.
the class HypermediaAutoConfigurationTests method customizationOfSupportedMediaTypesCanBeDisabled.
@Test
public void customizationOfSupportedMediaTypesCanBeDisabled() {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
this.context.register(BaseConfig.class);
EnvironmentTestUtils.addEnvironment(this.context, "spring.hateoas.use-hal-as-default-json-media-type:false");
this.context.refresh();
RequestMappingHandlerAdapter handlerAdapter = this.context.getBean(RequestMappingHandlerAdapter.class);
for (HttpMessageConverter<?> converter : handlerAdapter.getMessageConverters()) {
if (converter instanceof TypeConstrainedMappingJackson2HttpMessageConverter) {
assertThat(converter.getSupportedMediaTypes()).containsExactly(MediaTypes.HAL_JSON);
}
}
}
use of org.springframework.web.context.support.AnnotationConfigWebApplicationContext 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.web.context.support.AnnotationConfigWebApplicationContext 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.web.context.support.AnnotationConfigWebApplicationContext in project spring-boot by spring-projects.
the class AbstractSessionAutoConfigurationTests method load.
protected void load(Collection<Class<?>> configs, String... environment) {
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
EnvironmentTestUtils.addEnvironment(ctx, environment);
if (configs != null) {
ctx.register(configs.toArray(new Class<?>[configs.size()]));
}
ctx.register(ServerProperties.class, SessionAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
ctx.refresh();
this.context = ctx;
}
use of org.springframework.web.context.support.AnnotationConfigWebApplicationContext 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();
}
Aggregations