Search in sources :

Example 1 with TypeConstrainedMappingJackson2HttpMessageConverter

use of org.springframework.hateoas.mvc.TypeConstrainedMappingJackson2HttpMessageConverter 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 2 with TypeConstrainedMappingJackson2HttpMessageConverter

use of org.springframework.hateoas.mvc.TypeConstrainedMappingJackson2HttpMessageConverter in project spring-boot by spring-projects.

the class HypermediaAutoConfigurationTests method supportedMediaTypesOfTypeConstrainedConvertersIsCustomized.

@Test
public void supportedMediaTypesOfTypeConstrainedConvertersIsCustomized() {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());
    this.context.register(BaseConfig.class);
    this.context.refresh();
    RequestMappingHandlerAdapter handlerAdapter = this.context.getBean(RequestMappingHandlerAdapter.class);
    for (HttpMessageConverter<?> converter : handlerAdapter.getMessageConverters()) {
        if (converter instanceof TypeConstrainedMappingJackson2HttpMessageConverter) {
            assertThat(converter.getSupportedMediaTypes()).contains(MediaType.APPLICATION_JSON, 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)

Aggregations

Test (org.junit.Test)2 TypeConstrainedMappingJackson2HttpMessageConverter (org.springframework.hateoas.mvc.TypeConstrainedMappingJackson2HttpMessageConverter)2 MockServletContext (org.springframework.mock.web.MockServletContext)2 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)2 RequestMappingHandlerAdapter (org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter)2