Search in sources :

Example 16 with ModelAndView

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

the class UrlFilenameViewControllerTests method multiLevelMappingWithFallback.

@PathPatternsParameterizedTest
void multiLevelMappingWithFallback(Function<String, RequestContext> requestFactory) throws Exception {
    UrlFilenameViewController controller = new UrlFilenameViewController();
    RequestContext request = requestFactory.apply("/docs/cvs/commit.html");
    exposePathInMapping(request, "/docs/cvs/commit.html");
    ModelAndView mv = controller.handleRequest(request);
    assertThat(mv.getViewName()).isEqualTo("docs/cvs/commit");
    assertThat(mv.getModel().isEmpty()).isTrue();
}
Also used : ModelAndView(cn.taketoday.web.view.ModelAndView) RequestContext(cn.taketoday.web.RequestContext) ServletRequestContext(cn.taketoday.web.servlet.ServletRequestContext) MockServletRequestContext(cn.taketoday.web.servlet.MockServletRequestContext) PathPatternsParameterizedTest(cn.taketoday.web.view.PathPatternsParameterizedTest)

Example 17 with ModelAndView

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

the class ParameterizableViewControllerTests method handleRequestWithFlashAttributes.

@Test
public void handleRequestWithFlashAttributes() throws Exception {
    this.request.setAttribute(RedirectModel.INPUT_ATTRIBUTE, new RedirectModel("name", "value"));
    ModelAndView mav = this.controller.handleRequest(this.context);
    assertThat(mav.getModel().size()).isEqualTo(1);
    assertThat(mav.getModel().get("name")).isEqualTo("value");
}
Also used : RedirectModel(cn.taketoday.web.view.RedirectModel) ModelAndView(cn.taketoday.web.view.ModelAndView) Test(org.junit.jupiter.api.Test)

Example 18 with ModelAndView

use of cn.taketoday.web.view.ModelAndView 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 19 with ModelAndView

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

the class ParameterizableViewControllerTests method redirectStatusWithRedirectPrefix.

@Test
public void redirectStatusWithRedirectPrefix() throws Exception {
    this.controller.setStatusCode(HttpStatus.PERMANENT_REDIRECT);
    this.controller.setViewName("redirect:/foo");
    ModelAndView modelAndView = this.controller.handleRequest(this.context);
    assertThat(modelAndView.getViewName()).isEqualTo("redirect:/foo");
    assertThat(this.response.getStatus()).as("3xx status should be left to RedirectView to set").isEqualTo(200);
    assertThat(this.request.getAttribute(View.RESPONSE_STATUS_ATTRIBUTE)).isEqualTo(HttpStatus.PERMANENT_REDIRECT);
}
Also used : ModelAndView(cn.taketoday.web.view.ModelAndView) Test(org.junit.jupiter.api.Test)

Example 20 with ModelAndView

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

the class UrlFilenameViewControllerTests method withSuffix.

@PathPatternsParameterizedTest
void withSuffix(Function<String, RequestContext> requestFactory) throws Exception {
    UrlFilenameViewController controller = new UrlFilenameViewController();
    controller.setSuffix("_mysuf");
    RequestContext request = requestFactory.apply("/index.html");
    ModelAndView mv = controller.handleRequest(request);
    assertThat(mv.getViewName()).isEqualTo("index_mysuf");
    assertThat(mv.getModel().isEmpty()).isTrue();
}
Also used : ModelAndView(cn.taketoday.web.view.ModelAndView) RequestContext(cn.taketoday.web.RequestContext) ServletRequestContext(cn.taketoday.web.servlet.ServletRequestContext) MockServletRequestContext(cn.taketoday.web.servlet.MockServletRequestContext) PathPatternsParameterizedTest(cn.taketoday.web.view.PathPatternsParameterizedTest)

Aggregations

ModelAndView (cn.taketoday.web.view.ModelAndView)56 Test (org.junit.jupiter.api.Test)28 ServletRequestContext (cn.taketoday.web.servlet.ServletRequestContext)26 MockServletRequestContext (cn.taketoday.web.servlet.MockServletRequestContext)24 PathPatternsParameterizedTest (cn.taketoday.web.view.PathPatternsParameterizedTest)24 RequestContext (cn.taketoday.web.RequestContext)22 RedirectModel (cn.taketoday.web.view.RedirectModel)6 BindingContext (cn.taketoday.web.BindingContext)4 StaticWebApplicationContext (cn.taketoday.web.context.support.StaticWebApplicationContext)4 MockHttpServletRequest (cn.taketoday.web.mock.MockHttpServletRequest)2 MockHttpServletResponse (cn.taketoday.web.mock.MockHttpServletResponse)2 MockHttpServletRequest (cn.taketoday.web.testfixture.servlet.MockHttpServletRequest)2 MockHttpServletResponse (cn.taketoday.web.testfixture.servlet.MockHttpServletResponse)2 RedirectView (cn.taketoday.web.view.RedirectView)2 View (cn.taketoday.web.view.View)2