Search in sources :

Example 11 with ModelAndView

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

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

the class ParameterizableViewControllerTests method defaultViewName.

// 
@Test
public void defaultViewName() throws Exception {
    ModelAndView modelAndView = this.controller.handleRequest(this.context);
    assertThat(modelAndView.getViewName()).isNull();
}
Also used : ModelAndView(cn.taketoday.web.view.ModelAndView) Test(org.junit.jupiter.api.Test)

Example 13 with ModelAndView

use of cn.taketoday.web.view.ModelAndView in project today-infrastructure 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 14 with ModelAndView

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

the class ModelAndViewReturnValueHandler method handleModelAndView.

/**
 * Resolve {@link ModelAndView} return type
 *
 * @since 2.3.3
 */
public final void handleModelAndView(RequestContext context, Object handler, @Nullable ModelAndView modelAndView) throws Exception {
    if (modelAndView != null) {
        View view = modelAndView.getView();
        String viewName = modelAndView.getViewName();
        BindingContext bindingContext = context.getBindingContext();
        bindingContext.addAllAttributes(modelAndView.getModel());
        if (viewName != null) {
            delegate.renderView(context, viewName);
        } else if (view != null) {
            delegate.renderView(context, view);
        }
    }
}
Also used : BindingContext(cn.taketoday.web.BindingContext) View(cn.taketoday.web.view.View) ModelAndView(cn.taketoday.web.view.ModelAndView)

Example 15 with ModelAndView

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

the class UrlFilenameViewControllerTests method nestedPathisUsedAsViewName_InBreakingChangeFromSpring12Line.

/**
 * This is the expected behavior, and it now has a test to prove it.
 * https://opensource.atlassian.com/projects/spring/browse/SPR-2789
 */
@PathPatternsParameterizedTest
void nestedPathisUsedAsViewName_InBreakingChangeFromSpring12Line(Function<String, RequestContext> requestFactory) throws Exception {
    UrlFilenameViewController controller = new UrlFilenameViewController();
    RequestContext request = requestFactory.apply("/products/view.html");
    ModelAndView mv = controller.handleRequest(request);
    assertThat(mv.getViewName()).isEqualTo("products/view");
    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