Search in sources :

Example 56 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 57 with AnnotationConfigWebApplicationContext

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();
}
Also used : EntityLinks(org.springframework.hateoas.EntityLinks) AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) MockServletContext(org.springframework.mock.web.MockServletContext) Test(org.junit.Test)

Example 58 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 59 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 60 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)192 Test (org.junit.Test)129 MockServletContext (org.springframework.mock.web.MockServletContext)80 MockMvc (org.springframework.test.web.servlet.MockMvc)25 URI (java.net.URI)23 HashMap (java.util.HashMap)23 MapPropertySource (org.springframework.core.env.MapPropertySource)23 StandardEnvironment (org.springframework.core.env.StandardEnvironment)23 MessageSerDe (com.kixeye.chassis.transport.serde.MessageSerDe)21 DispatcherServlet (org.springframework.web.servlet.DispatcherServlet)16 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 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)13 QueuingWebSocketListener (com.kixeye.chassis.transport.websocket.QueuingWebSocketListener)9 WebSocketMessageRegistry (com.kixeye.chassis.transport.websocket.WebSocketMessageRegistry)9