Search in sources :

Example 16 with AnnotationConfigWebApplicationContext

use of org.springframework.web.context.support.AnnotationConfigWebApplicationContext in project spring-boot by spring-projects.

the class Neo4jDataAutoConfigurationTests method load.

private void load(Class<?> config, String... environment) {
    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    EnvironmentTestUtils.addEnvironment(ctx, environment);
    if (config != null) {
        ctx.register(config);
    }
    ctx.register(PropertyPlaceholderAutoConfiguration.class, TransactionAutoConfiguration.class, Neo4jDataAutoConfiguration.class);
    ctx.refresh();
    this.context = ctx;
}
Also used : AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext)

Example 17 with AnnotationConfigWebApplicationContext

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);
        }
    }
}
Also used : TypeConstrainedMappingJackson2HttpMessageConverter(org.springframework.hateoas.mvc.TypeConstrainedMappingJackson2HttpMessageConverter) AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) RequestMappingHandlerAdapter(org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter) MockServletContext(org.springframework.mock.web.MockServletContext) Test(org.junit.Test)

Example 18 with AnnotationConfigWebApplicationContext

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();
}
Also used : AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) MockServletContext(org.springframework.mock.web.MockServletContext) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 19 with AnnotationConfigWebApplicationContext

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;
}
Also used : AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext)

Example 20 with AnnotationConfigWebApplicationContext

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();
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ThymeleafView(org.thymeleaf.spring5.view.ThymeleafView) Matchers.containsString(org.hamcrest.Matchers.containsString) AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Aggregations

AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)244 Test (org.junit.Test)116 MockServletContext (org.springframework.mock.web.MockServletContext)75 DispatcherServlet (org.springframework.web.servlet.DispatcherServlet)42 ContextLoaderListener (org.springframework.web.context.ContextLoaderListener)30 MockMvc (org.springframework.test.web.servlet.MockMvc)26 ServletRegistration (javax.servlet.ServletRegistration)25 HashMap (java.util.HashMap)24 URI (java.net.URI)23 MapPropertySource (org.springframework.core.env.MapPropertySource)23 StandardEnvironment (org.springframework.core.env.StandardEnvironment)23 MessageSerDe (com.kixeye.chassis.transport.serde.MessageSerDe)21 Test (org.junit.jupiter.api.Test)17 ProtobufMessageSerDe (com.kixeye.chassis.transport.serde.converter.ProtobufMessageSerDe)15 RestTemplate (org.springframework.web.client.RestTemplate)15 ServiceError (com.kixeye.chassis.transport.dto.ServiceError)14 JsonJacksonMessageSerDe (com.kixeye.chassis.transport.serde.converter.JsonJacksonMessageSerDe)14 XmlMessageSerDe (com.kixeye.chassis.transport.serde.converter.XmlMessageSerDe)14 YamlJacksonMessageSerDe (com.kixeye.chassis.transport.serde.converter.YamlJacksonMessageSerDe)14 SerDeHttpMessageConverter (com.kixeye.chassis.transport.http.SerDeHttpMessageConverter)13