Search in sources :

Example 6 with RedirectView

use of cn.taketoday.web.view.RedirectView in project today-framework by TAKETODAY.

the class ViewControllerRegistryTests method getRedirectView.

private RedirectView getRedirectView(String path) {
    ParameterizableViewController controller = getController(path);
    assertThat(controller.getViewName()).isNull();
    assertThat(controller.getView()).isNotNull();
    assertThat(controller.getView().getClass()).isEqualTo(RedirectView.class);
    return (RedirectView) controller.getView();
}
Also used : ParameterizableViewController(cn.taketoday.web.handler.mvc.ParameterizableViewController) RedirectView(cn.taketoday.web.view.RedirectView)

Example 7 with RedirectView

use of cn.taketoday.web.view.RedirectView in project today-infrastructure by TAKETODAY.

the class FreeMarkerViewTests method freeMarkerViewResolver.

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

Aggregations

RedirectView (cn.taketoday.web.view.RedirectView)7 Test (org.junit.jupiter.api.Test)6 StaticWebServletApplicationContext (cn.taketoday.web.context.support.StaticWebServletApplicationContext)2 ServletRequestContext (cn.taketoday.web.servlet.ServletRequestContext)2 InternalResourceView (cn.taketoday.web.servlet.view.InternalResourceView)2 AbstractView (cn.taketoday.web.view.AbstractView)2 ModelAndView (cn.taketoday.web.view.ModelAndView)2 View (cn.taketoday.web.view.View)2 ParameterizableViewController (cn.taketoday.web.handler.mvc.ParameterizableViewController)1 MockServletContext (cn.taketoday.web.mock.MockServletContext)1 MockServletContext (cn.taketoday.web.testfixture.servlet.MockServletContext)1