Search in sources :

Example 6 with ContentNegotiationManager

use of cn.taketoday.web.accept.ContentNegotiationManager in project today-infrastructure by TAKETODAY.

the class ReactiveTypeHandlerTests method setup.

@BeforeEach
public void setup() throws Exception {
    ContentNegotiationManagerFactoryBean factoryBean = new ContentNegotiationManagerFactoryBean();
    factoryBean.afterPropertiesSet();
    ContentNegotiationManager manager = factoryBean.getObject();
    ReactiveAdapterRegistry adapterRegistry = ReactiveAdapterRegistry.getSharedInstance();
    this.handler = new ReactiveTypeHandler(adapterRegistry, new SyncTaskExecutor(), manager);
    resetRequest();
}
Also used : ContentNegotiationManagerFactoryBean(cn.taketoday.web.accept.ContentNegotiationManagerFactoryBean) SyncTaskExecutor(cn.taketoday.core.task.SyncTaskExecutor) ContentNegotiationManager(cn.taketoday.web.accept.ContentNegotiationManager) ReactiveAdapterRegistry(cn.taketoday.core.ReactiveAdapterRegistry) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 7 with ContentNegotiationManager

use of cn.taketoday.web.accept.ContentNegotiationManager in project today-infrastructure by TAKETODAY.

the class ReturnValueHandlerManagerTests method contentNegotiationManager.

@Test
void contentNegotiationManager() {
    ReturnValueHandlerManager manager = new ReturnValueHandlerManager();
    ContentNegotiationManager contentNegotiationManager = new ContentNegotiationManager();
    manager.setContentNegotiationManager(contentNegotiationManager);
}
Also used : ContentNegotiationManager(cn.taketoday.web.accept.ContentNegotiationManager) Test(org.junit.jupiter.api.Test)

Example 8 with ContentNegotiationManager

use of cn.taketoday.web.accept.ContentNegotiationManager in project today-infrastructure by TAKETODAY.

the class ContentNegotiationConfigurerTests method ignoreAcceptHeader.

@Test
public void ignoreAcceptHeader() throws Exception {
    this.configurer.ignoreAcceptHeader(true);
    this.configurer.favorParameter(true);
    ContentNegotiationManager manager = this.configurer.buildContentNegotiationManager();
    this.servletRequest.setRequestURI("/flower");
    this.servletRequest.addHeader("Accept", MediaType.IMAGE_GIF_VALUE);
    assertThat(manager.resolveMediaTypes(this.webRequest)).isEqualTo(ContentNegotiationStrategy.MEDIA_TYPE_ALL_LIST);
}
Also used : ContentNegotiationManager(cn.taketoday.web.accept.ContentNegotiationManager) Test(org.junit.jupiter.api.Test)

Example 9 with ContentNegotiationManager

use of cn.taketoday.web.accept.ContentNegotiationManager in project today-infrastructure by TAKETODAY.

the class ContentNegotiationConfigurerTests method favorParameter.

@Test
public void favorParameter() throws Exception {
    this.configurer.favorParameter(true);
    this.configurer.parameterName("f");
    this.configurer.mediaTypes(Collections.singletonMap("json", MediaType.APPLICATION_JSON));
    ContentNegotiationManager manager = this.configurer.buildContentNegotiationManager();
    this.servletRequest.setRequestURI("/flower");
    this.servletRequest.addParameter("f", "json");
    assertThat(manager.resolveMediaTypes(this.webRequest).get(0)).isEqualTo(MediaType.APPLICATION_JSON);
}
Also used : ContentNegotiationManager(cn.taketoday.web.accept.ContentNegotiationManager) Test(org.junit.jupiter.api.Test)

Example 10 with ContentNegotiationManager

use of cn.taketoday.web.accept.ContentNegotiationManager in project today-infrastructure by TAKETODAY.

the class ContentNegotiationConfigurerTests method setDefaultContentType.

@Test
public void setDefaultContentType() throws Exception {
    this.configurer.defaultContentType(MediaType.APPLICATION_JSON);
    ContentNegotiationManager manager = this.configurer.buildContentNegotiationManager();
    assertThat(manager.resolveMediaTypes(this.webRequest).get(0)).isEqualTo(MediaType.APPLICATION_JSON);
}
Also used : ContentNegotiationManager(cn.taketoday.web.accept.ContentNegotiationManager) Test(org.junit.jupiter.api.Test)

Aggregations

ContentNegotiationManager (cn.taketoday.web.accept.ContentNegotiationManager)43 Test (org.junit.jupiter.api.Test)38 InternalResourceView (cn.taketoday.web.servlet.view.InternalResourceView)16 InternalResourceViewResolver (cn.taketoday.web.servlet.view.InternalResourceViewResolver)16 Locale (java.util.Locale)16 MediaType (cn.taketoday.http.MediaType)10 FixedContentNegotiationStrategy (cn.taketoday.web.accept.FixedContentNegotiationStrategy)8 ContentNegotiationManagerFactoryBean (cn.taketoday.web.accept.ContentNegotiationManagerFactoryBean)6 HeaderContentNegotiationStrategy (cn.taketoday.web.accept.HeaderContentNegotiationStrategy)6 BeforeEach (org.junit.jupiter.api.BeforeEach)5 ClassPathResource (cn.taketoday.core.io.ClassPathResource)4 FileSystemResource (cn.taketoday.core.io.FileSystemResource)4 Resource (cn.taketoday.core.io.Resource)4 UrlBasedResource (cn.taketoday.core.io.UrlBasedResource)4 ParameterContentNegotiationStrategy (cn.taketoday.web.accept.ParameterContentNegotiationStrategy)4 PathExtensionContentNegotiationStrategy (cn.taketoday.web.accept.PathExtensionContentNegotiationStrategy)4 ReactiveAdapterRegistry (cn.taketoday.core.ReactiveAdapterRegistry)2 SyncTaskExecutor (cn.taketoday.core.task.SyncTaskExecutor)2 MappingMediaTypeFileExtensionResolver (cn.taketoday.web.accept.MappingMediaTypeFileExtensionResolver)2 StaticWebApplicationContext (cn.taketoday.web.context.support.StaticWebApplicationContext)2