@Test(expected = SoyTofuException.class)
 public void shouldThrowExceptionIfTemplateDoesntExist() throws Exception {
   View view =
       cachingClosureTemplateViewResolver.resolveViewName(
           "com.tomakehurst.doesntexist", Locale.UK);
   view.render(model, request, response);
 }
コード例 #2
0
  @Test
  public void resolveViewNoMatchUseUnacceptableStatus() throws Exception {
    viewResolver.setUseNotAcceptableStatusCode(true);
    request.addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9");

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

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

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

    expect(viewResolverMock.resolveViewName(viewName, locale)).andReturn(viewMock);
    expect(viewMock.getContentType()).andReturn("application/pdf").anyTimes();

    replay(viewResolverMock, viewMock);

    View result = viewResolver.resolveViewName(viewName, locale);
    assertNotNull("Invalid view", result);
    MockHttpServletResponse response = new MockHttpServletResponse();
    result.render(null, request, response);
    assertEquals("Invalid status code set", 406, response.getStatus());

    verify(viewResolverMock, viewMock);
  }
コード例 #3
0
 private MockHttpServletResponse render(String viewName, Locale locale) throws Exception {
   GroovyTemplateViewResolver resolver = this.context.getBean(GroovyTemplateViewResolver.class);
   View view = resolver.resolveViewName(viewName, locale);
   assertThat(view, notNullValue());
   HttpServletRequest request = new MockHttpServletRequest();
   request.setAttribute(RequestContext.WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.context);
   MockHttpServletResponse response = new MockHttpServletResponse();
   view.render(null, request, response);
   return response;
 }
 private String render(View view) throws Exception {
   response = new MockHttpServletResponse();
   view.render(model, request, response);
   return response.getContentAsString();
 }