Search in sources :

Example 1 with RedirectView

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

the class ParameterizableViewControllerTests method redirectView.

@Test
public void redirectView() throws Exception {
    RedirectView view = new RedirectView("/foo");
    this.controller.setView(view);
    ModelAndView modelAndView = this.controller.handleRequest(this.context);
    assertThat(modelAndView.getView()).isSameAs(view);
}
Also used : RedirectView(cn.taketoday.web.view.RedirectView) ModelAndView(cn.taketoday.web.view.ModelAndView) Test(org.junit.jupiter.api.Test)

Example 2 with RedirectView

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

the class ViewControllerRegistryTests method addRedirectViewControllerWithCustomSettings.

@Test
public void addRedirectViewControllerWithCustomSettings() throws Exception {
    this.registry.addRedirectViewController("/path", "/redirectTo").setContextRelative(false).setKeepQueryParams(true).setStatusCode(HttpStatus.PERMANENT_REDIRECT);
    RedirectView redirectView = getRedirectView("/path");
    this.request.setQueryString("a=b");
    this.request.setContextPath("/context");
    redirectView.render(Collections.emptyMap(), new ServletRequestContext(null, this.request, this.response));
    assertThat(this.response.getStatus()).isEqualTo(308);
    assertThat(response.getRedirectedUrl()).isEqualTo("/redirectTo?a=b");
    assertThat(redirectView.getApplicationContext()).isNotNull();
}
Also used : RedirectView(cn.taketoday.web.view.RedirectView) ServletRequestContext(cn.taketoday.web.servlet.ServletRequestContext) Test(org.junit.jupiter.api.Test)

Example 3 with RedirectView

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

the class ViewControllerRegistryTests method addRedirectViewController.

@Test
public void addRedirectViewController() throws Exception {
    this.registry.addRedirectViewController("/path", "/redirectTo");
    RedirectView redirectView = getRedirectView("/path");
    this.request.setQueryString("a=b");
    this.request.setContextPath("/context");
    redirectView.render(Collections.emptyMap(), new ServletRequestContext(null, this.request, this.response));
    assertThat(this.response.getStatus()).isEqualTo(302);
    assertThat(this.response.getRedirectedUrl()).isEqualTo("/context/redirectTo");
    assertThat(redirectView.getApplicationContext()).isNotNull();
}
Also used : RedirectView(cn.taketoday.web.view.RedirectView) ServletRequestContext(cn.taketoday.web.servlet.ServletRequestContext) Test(org.junit.jupiter.api.Test)

Example 4 with RedirectView

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

the class ParameterizableViewControllerTests method redirectView.

@Test
public void redirectView() throws Exception {
    RedirectView view = new RedirectView("/foo");
    this.controller.setView(view);
    ModelAndView modelAndView = this.controller.handleRequest(this.context);
    assertThat(modelAndView.getView()).isSameAs(view);
}
Also used : RedirectView(cn.taketoday.web.view.RedirectView) ModelAndView(cn.taketoday.web.view.ModelAndView) Test(org.junit.jupiter.api.Test)

Example 5 with RedirectView

use of cn.taketoday.web.view.RedirectView in project today-framework 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.testfixture.servlet.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