Search in sources :

Example 6 with RedirectAttributesModelMap

use of org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap in project spring-framework by spring-projects.

the class ModelAndViewMethodReturnValueHandlerTests method handleRedirectAttributesWithoutRedirect.

@Test
public void handleRedirectAttributesWithoutRedirect() throws Exception {
    RedirectAttributesModelMap redirectAttributes = new RedirectAttributesModelMap();
    mavContainer.setRedirectModel(redirectAttributes);
    ModelAndView mav = new ModelAndView();
    handler.handleReturnValue(mav, returnParamModelAndView, mavContainer, webRequest);
    ModelMap model = mavContainer.getModel();
    assertEquals(null, mavContainer.getView());
    assertTrue(mavContainer.getModel().isEmpty());
    assertNotSame("RedirectAttributes should not be used if controller doesn't redirect", redirectAttributes, model);
}
Also used : RedirectAttributesModelMap(org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap) ModelMap(org.springframework.ui.ModelMap) ModelAndView(org.springframework.web.servlet.ModelAndView) RedirectAttributesModelMap(org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap) Test(org.junit.Test)

Example 7 with RedirectAttributesModelMap

use of org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap in project spring-framework by spring-projects.

the class ModelAndViewMethodReturnValueHandlerTests method handleRedirectAttributesWithViewReference.

@Test
public void handleRedirectAttributesWithViewReference() throws Exception {
    RedirectAttributesModelMap redirectAttributes = new RedirectAttributesModelMap();
    mavContainer.setRedirectModel(redirectAttributes);
    ModelAndView mav = new ModelAndView(new RedirectView(), "attrName", "attrValue");
    handler.handleReturnValue(mav, returnParamModelAndView, mavContainer, webRequest);
    assertEquals(RedirectView.class, mavContainer.getView().getClass());
    assertEquals("attrValue", mavContainer.getModel().get("attrName"));
    assertSame("RedirectAttributes should be used if controller redirects", redirectAttributes, mavContainer.getModel());
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) RedirectView(org.springframework.web.servlet.view.RedirectView) RedirectAttributesModelMap(org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap) Test(org.junit.Test)

Example 8 with RedirectAttributesModelMap

use of org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap in project spring-framework by spring-projects.

the class ViewMethodReturnValueHandlerTests method returnViewRedirect.

@Test
public void returnViewRedirect() throws Exception {
    RedirectView redirectView = new RedirectView("testView");
    ModelMap redirectModel = new RedirectAttributesModelMap();
    this.mavContainer.setRedirectModel(redirectModel);
    MethodParameter param = createReturnValueParam("view");
    this.handler.handleReturnValue(redirectView, param, this.mavContainer, this.webRequest);
    assertSame(redirectView, this.mavContainer.getView());
    assertSame("Should have switched to the RedirectModel", redirectModel, this.mavContainer.getModel());
}
Also used : ModelMap(org.springframework.ui.ModelMap) RedirectAttributesModelMap(org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap) RedirectView(org.springframework.web.servlet.view.RedirectView) RedirectAttributesModelMap(org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap) MethodParameter(org.springframework.core.MethodParameter) Test(org.junit.Test)

Example 9 with RedirectAttributesModelMap

use of org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap in project spring-framework by spring-projects.

the class ViewNameMethodReturnValueHandlerTests method returnViewNameRedirect.

@Test
public void returnViewNameRedirect() throws Exception {
    ModelMap redirectModel = new RedirectAttributesModelMap();
    this.mavContainer.setRedirectModel(redirectModel);
    this.handler.handleReturnValue("redirect:testView", this.param, this.mavContainer, this.webRequest);
    assertEquals("redirect:testView", this.mavContainer.getViewName());
    assertSame(redirectModel, this.mavContainer.getModel());
}
Also used : RedirectAttributesModelMap(org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap) ModelMap(org.springframework.ui.ModelMap) RedirectAttributesModelMap(org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap) Test(org.junit.Test)

Aggregations

RedirectAttributesModelMap (org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap)9 Test (org.junit.Test)8 ModelMap (org.springframework.ui.ModelMap)8 ModelAndView (org.springframework.web.servlet.ModelAndView)4 RedirectView (org.springframework.web.servlet.view.RedirectView)2 MethodParameter (org.springframework.core.MethodParameter)1 DataBinder (org.springframework.validation.DataBinder)1