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);
}
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();
}
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();
}
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);
}
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");
}
Aggregations