Search in sources :

Example 1 with InternalResourceView

use of org.springframework.web.servlet.view.InternalResourceView in project spring-framework by spring-projects.

the class ViewMethodReturnValueHandlerTests method returnView.

@Test
public void returnView() throws Exception {
    InternalResourceView view = new InternalResourceView("testView");
    this.handler.handleReturnValue(view, createReturnValueParam("view"), this.mavContainer, this.webRequest);
    assertSame(view, this.mavContainer.getView());
}
Also used : InternalResourceView(org.springframework.web.servlet.view.InternalResourceView) Test(org.junit.Test)

Example 2 with InternalResourceView

use of org.springframework.web.servlet.view.InternalResourceView in project spring-framework by spring-projects.

the class FreeMarkerViewTests method freeMarkerViewResolver.

@Test
public void freeMarkerViewResolver() throws Exception {
    FreeMarkerConfigurer configurer = new FreeMarkerConfigurer();
    configurer.setConfiguration(new TestConfiguration());
    StaticWebApplicationContext wac = new StaticWebApplicationContext();
    wac.setServletContext(new MockServletContext());
    wac.getBeanFactory().registerSingleton("configurer", configurer);
    wac.refresh();
    FreeMarkerViewResolver vr = new FreeMarkerViewResolver("prefix_", "_suffix");
    vr.setApplicationContext(wac);
    View view = vr.resolveViewName("test", Locale.CANADA);
    assertEquals("Correct view class", FreeMarkerView.class, view.getClass());
    assertEquals("Correct URL", "prefix_test_suffix", ((FreeMarkerView) view).getUrl());
    view = vr.resolveViewName("non-existing", Locale.CANADA);
    assertNull(view);
    view = vr.resolveViewName("redirect:myUrl", Locale.getDefault());
    assertEquals("Correct view class", RedirectView.class, view.getClass());
    assertEquals("Correct URL", "myUrl", ((RedirectView) view).getUrl());
    view = vr.resolveViewName("forward:myUrl", Locale.getDefault());
    assertEquals("Correct view class", InternalResourceView.class, view.getClass());
    assertEquals("Correct URL", "myUrl", ((InternalResourceView) view).getUrl());
}
Also used : StaticWebApplicationContext(org.springframework.web.context.support.StaticWebApplicationContext) AbstractView(org.springframework.web.servlet.view.AbstractView) InternalResourceView(org.springframework.web.servlet.view.InternalResourceView) RedirectView(org.springframework.web.servlet.view.RedirectView) View(org.springframework.web.servlet.View) MockServletContext(org.springframework.mock.web.test.MockServletContext) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 InternalResourceView (org.springframework.web.servlet.view.InternalResourceView)2 MockServletContext (org.springframework.mock.web.test.MockServletContext)1 StaticWebApplicationContext (org.springframework.web.context.support.StaticWebApplicationContext)1 View (org.springframework.web.servlet.View)1 AbstractView (org.springframework.web.servlet.view.AbstractView)1 RedirectView (org.springframework.web.servlet.view.RedirectView)1