Package org.springframework.web.servlet

Examples of org.springframework.web.servlet.ViewResolver


        OrderComparator.sort(this.viewResolvers);
      }
    }
    else {
      try {
        ViewResolver vr = context.getBean(VIEW_RESOLVER_BEAN_NAME, ViewResolver.class);
        this.viewResolvers = Collections.singletonList(vr);
      }
      catch (NoSuchBeanDefinitionException ex) {
        // Ignore, we'll add a default ViewResolver later.
      }
View Full Code Here


    assertEquals(Ordered.LOWEST_PRECEDENCE, compositeResolver.getOrder());

    List<ViewResolver> resolvers = compositeResolver.getViewResolvers();
    assertEquals(BeanNameViewResolver.class, resolvers.get(0).getClass());

    ViewResolver resolver = resolvers.get(1);
    assertEquals(InternalResourceViewResolver.class, resolver.getClass());
    DirectFieldAccessor accessor = new DirectFieldAccessor(resolver);
    assertEquals(InternalResourceView.class, accessor.getPropertyValue("viewClass"));

    assertEquals(TilesViewResolver.class, resolvers.get(2).getClass());
View Full Code Here

  @Test
  public void resolveViewNameWithPathExtension() throws Exception {
    request.setRequestURI("/test.xls");

    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);
    assertSame("Invalid view", viewMock, result);
  }
View Full Code Here

    MappingMediaTypeFileExtensionResolver extensionsResolver = new MappingMediaTypeFileExtensionResolver(mapping);
    ContentNegotiationManager manager = new ContentNegotiationManager(new HeaderContentNegotiationStrategy());
    manager.addFileExtensionResolvers(extensionsResolver);
    viewResolver.setContentNegotiationManager(manager);

    ViewResolver viewResolverMock = mock(ViewResolver.class);
    viewResolver.setViewResolvers(Collections.singletonList(viewResolverMock));

    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);
    assertSame("Invalid view", viewMock, result);
  }
View Full Code Here

    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);
    assertSame("Invalid view", viewMock, result);
  }
View Full Code Here

    MediaType mediaType = new MediaType("application", "xml");
    FixedContentNegotiationStrategy fixedStrategy = new FixedContentNegotiationStrategy(mediaType);
    viewResolver.setContentNegotiationManager(new ContentNegotiationManager(fixedStrategy));

    ViewResolver viewResolverMock1 = mock(ViewResolver.class, "viewResolver1");
    ViewResolver viewResolverMock2 = mock(ViewResolver.class, "viewResolver2");
    viewResolver.setViewResolvers(Arrays.asList(viewResolverMock1, viewResolverMock2));
    viewResolver.afterPropertiesSet();

    View viewMock1 = mock(View.class, "application_xml");
    View viewMock2 = mock(View.class, "text_html");

    String viewName = "view";
    Locale locale = Locale.ENGLISH;

    given(viewResolverMock1.resolveViewName(viewName, locale)).willReturn(viewMock1);
    given(viewResolverMock2.resolveViewName(viewName, locale)).willReturn(viewMock2);
    given(viewMock1.getContentType()).willReturn("application/xml");
    given(viewMock2.getContentType()).willReturn("text/html;charset=ISO-8859-1");

    View result = viewResolver.resolveViewName(viewName, locale);
    assertSame("Invalid view", viewMock1, result);
View Full Code Here

  @Test
  public void resolveViewNameAcceptHeader() throws Exception {
    request.addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");

    ViewResolver viewResolverMock1 = mock(ViewResolver.class);
    ViewResolver viewResolverMock2 = mock(ViewResolver.class);
    viewResolver.setViewResolvers(Arrays.asList(viewResolverMock1, viewResolverMock2));

    viewResolver.afterPropertiesSet();

    View viewMock1 = mock(View.class, "application_xml");
    View viewMock2 = mock(View.class, "text_html");

    String viewName = "view";
    Locale locale = Locale.ENGLISH;

    given(viewResolverMock1.resolveViewName(viewName, locale)).willReturn(viewMock1);
    given(viewResolverMock2.resolveViewName(viewName, locale)).willReturn(viewMock2);
    given(viewMock1.getContentType()).willReturn("application/xml");
    given(viewMock2.getContentType()).willReturn("text/html;charset=ISO-8859-1");

    View result = viewResolver.resolveViewName(viewName, locale);
    assertSame("Invalid view", viewMock2, result);
View Full Code Here

  public void resolveViewNameAcceptHeaderSortByQuality() throws Exception {
    request.addHeader("Accept", "text/plain;q=0.5, application/json");

    viewResolver.setContentNegotiationManager(new ContentNegotiationManager(new HeaderContentNegotiationStrategy()));

    ViewResolver htmlViewResolver = mock(ViewResolver.class);
    ViewResolver jsonViewResolver = mock(ViewResolver.class);
    viewResolver.setViewResolvers(Arrays.asList(htmlViewResolver, jsonViewResolver));

    View htmlView = mock(View.class, "text_html");
    View jsonViewMock = mock(View.class, "application_json");

    String viewName = "view";
    Locale locale = Locale.ENGLISH;

    given(htmlViewResolver.resolveViewName(viewName, locale)).willReturn(htmlView);
    given(jsonViewResolver.resolveViewName(viewName, locale)).willReturn(jsonViewMock);
    given(htmlView.getContentType()).willReturn("text/html");
    given(jsonViewMock.getContentType()).willReturn("application/json");

    View result = viewResolver.resolveViewName(viewName, locale);
    assertSame("Invalid view", jsonViewMock, result);
View Full Code Here

  @Test
  public void resolveViewNameAcceptHeaderWithSuffix() throws Exception {
    request.addHeader("Accept", "application/vnd.example-v2+xml");

    ViewResolver viewResolverMock = mock(ViewResolver.class);
    viewResolver.setViewResolvers(Arrays.asList(viewResolverMock));

    viewResolver.afterPropertiesSet();

    View viewMock = mock(View.class, "application_xml");

    String viewName = "view";
    Locale locale = Locale.ENGLISH;

    given(viewResolverMock.resolveViewName(viewName, locale)).willReturn(viewMock);
    given(viewMock.getContentType()).willReturn("application/*+xml");

    View result = viewResolver.resolveViewName(viewName, locale);

    assertSame("Invalid view", viewMock, result);
View Full Code Here

  @Test
  public void resolveViewNameAcceptHeaderDefaultView() throws Exception {
    request.addHeader("Accept", "application/json");

    ViewResolver viewResolverMock1 = mock(ViewResolver.class);
    ViewResolver viewResolverMock2 = mock(ViewResolver.class);
    viewResolver.setViewResolvers(Arrays.asList(viewResolverMock1, viewResolverMock2));

    View viewMock1 = mock(View.class, "application_xml");
    View viewMock2 = mock(View.class, "text_html");
    View viewMock3 = mock(View.class, "application_json");

    List<View> defaultViews = new ArrayList<View>();
    defaultViews.add(viewMock3);
    viewResolver.setDefaultViews(defaultViews);

    viewResolver.afterPropertiesSet();

    String viewName = "view";
    Locale locale = Locale.ENGLISH;

    given(viewResolverMock1.resolveViewName(viewName, locale)).willReturn(viewMock1);
    given(viewResolverMock2.resolveViewName(viewName, locale)).willReturn(viewMock2);
    given(viewMock1.getContentType()).willReturn("application/xml");
    given(viewMock2.getContentType()).willReturn("text/html;charset=ISO-8859-1");
    given(viewMock3.getContentType()).willReturn("application/json");

    View result = viewResolver.resolveViewName(viewName, locale);
View Full Code Here

TOP

Related Classes of org.springframework.web.servlet.ViewResolver

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.