use of cn.taketoday.web.accept.ParameterContentNegotiationStrategy in project today-infrastructure by TAKETODAY.
the class ContentNegotiatingViewResolverTests method resolveViewNameWithPathExtension.
@Test
public void resolveViewNameWithPathExtension() throws Exception {
request.setRequestURI("/test");
request.setParameter("format", "xls");
String mediaType = "application/vnd.ms-excel";
ContentNegotiationManager manager = new ContentNegotiationManager(new ParameterContentNegotiationStrategy(Collections.singletonMap("xls", MediaType.parseMediaType(mediaType))));
ViewResolver viewResolverMock = mock(ViewResolver.class);
viewResolver.setContentNegotiationManager(manager);
viewResolver.setViewResolvers(Collections.singletonList(viewResolverMock));
viewResolver.afterPropertiesSet();
View viewMock = mock(View.class, "application_xls");
String viewName = "view";
Locale locale = Locale.ENGLISH;
given(viewResolverMock.resolveViewName(viewName, locale)).willReturn(null);
given(viewResolverMock.resolveViewName(viewName + ".xls", locale)).willReturn(viewMock);
given(viewMock.getContentType()).willReturn(mediaType);
View result = viewResolver.resolveViewName(viewName, locale);
assertThat(result).as("Invalid view").isSameAs(viewMock);
}
use of cn.taketoday.web.accept.ParameterContentNegotiationStrategy in project today-framework by TAKETODAY.
the class ContentNegotiatingViewResolverTests method resolveViewNameWithRequestParameter.
@Test
public void resolveViewNameWithRequestParameter() throws Exception {
request.addParameter("format", "xls");
Map<String, MediaType> mapping = Collections.singletonMap("xls", MediaType.valueOf("application/vnd.ms-excel"));
ParameterContentNegotiationStrategy paramStrategy = new ParameterContentNegotiationStrategy(mapping);
viewResolver.setContentNegotiationManager(new ContentNegotiationManager(paramStrategy));
ViewResolver viewResolverMock = mock(ViewResolver.class);
viewResolver.setViewResolvers(Collections.singletonList(viewResolverMock));
viewResolver.afterPropertiesSet();
View viewMock = mock(View.class, "application_xls");
String viewName = "view";
Locale locale = Locale.ENGLISH;
given(viewResolverMock.resolveViewName(viewName, locale)).willReturn(null);
given(viewResolverMock.resolveViewName(viewName + ".xls", locale)).willReturn(viewMock);
given(viewMock.getContentType()).willReturn("application/vnd.ms-excel");
View result = viewResolver.resolveViewName(viewName, locale);
assertThat(result).as("Invalid view").isSameAs(viewMock);
}
use of cn.taketoday.web.accept.ParameterContentNegotiationStrategy in project today-framework by TAKETODAY.
the class ContentNegotiatingViewResolverTests method resolveViewNameWithPathExtension.
@Test
public void resolveViewNameWithPathExtension() throws Exception {
request.setRequestURI("/test");
request.setParameter("format", "xls");
String mediaType = "application/vnd.ms-excel";
ContentNegotiationManager manager = new ContentNegotiationManager(new ParameterContentNegotiationStrategy(Collections.singletonMap("xls", MediaType.parseMediaType(mediaType))));
ViewResolver viewResolverMock = mock(ViewResolver.class);
viewResolver.setContentNegotiationManager(manager);
viewResolver.setViewResolvers(Collections.singletonList(viewResolverMock));
viewResolver.afterPropertiesSet();
View viewMock = mock(View.class, "application_xls");
String viewName = "view";
Locale locale = Locale.ENGLISH;
given(viewResolverMock.resolveViewName(viewName, locale)).willReturn(null);
given(viewResolverMock.resolveViewName(viewName + ".xls", locale)).willReturn(viewMock);
given(viewMock.getContentType()).willReturn(mediaType);
View result = viewResolver.resolveViewName(viewName, locale);
assertThat(result).as("Invalid view").isSameAs(viewMock);
}
use of cn.taketoday.web.accept.ParameterContentNegotiationStrategy in project today-infrastructure by TAKETODAY.
the class ContentNegotiatingViewResolverTests method resolveViewNameWithRequestParameter.
@Test
public void resolveViewNameWithRequestParameter() throws Exception {
request.addParameter("format", "xls");
Map<String, MediaType> mapping = Collections.singletonMap("xls", MediaType.valueOf("application/vnd.ms-excel"));
ParameterContentNegotiationStrategy paramStrategy = new ParameterContentNegotiationStrategy(mapping);
viewResolver.setContentNegotiationManager(new ContentNegotiationManager(paramStrategy));
ViewResolver viewResolverMock = mock(ViewResolver.class);
viewResolver.setViewResolvers(Collections.singletonList(viewResolverMock));
viewResolver.afterPropertiesSet();
View viewMock = mock(View.class, "application_xls");
String viewName = "view";
Locale locale = Locale.ENGLISH;
given(viewResolverMock.resolveViewName(viewName, locale)).willReturn(null);
given(viewResolverMock.resolveViewName(viewName + ".xls", locale)).willReturn(viewMock);
given(viewMock.getContentType()).willReturn("application/vnd.ms-excel");
View result = viewResolver.resolveViewName(viewName, locale);
assertThat(result).as("Invalid view").isSameAs(viewMock);
}
Aggregations