Search in sources :

Example 11 with RedirectAttributesModelMap

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

the class ModelAndViewMethodReturnValueHandlerTests method handleRedirectAttributesWithViewName.

@Test
public void handleRedirectAttributesWithViewName() throws Exception {
    RedirectAttributesModelMap redirectAttributes = new RedirectAttributesModelMap();
    mavContainer.setRedirectModel(redirectAttributes);
    ModelAndView mav = new ModelAndView("redirect:viewName", "attrName", "attrValue");
    handler.handleReturnValue(mav, returnParamModelAndView, mavContainer, webRequest);
    ModelMap model = mavContainer.getModel();
    assertThat(mavContainer.getViewName()).isEqualTo("redirect:viewName");
    assertThat(model.get("attrName")).isEqualTo("attrValue");
    assertThat(model).isSameAs(redirectAttributes);
}
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.jupiter.api.Test)

Example 12 with RedirectAttributesModelMap

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

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);
    assertThat(this.mavContainer.getViewName()).isEqualTo("redirect:testView");
    assertThat(this.mavContainer.getModel()).isSameAs(redirectModel);
}
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.jupiter.api.Test)

Example 13 with RedirectAttributesModelMap

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

the class ViewNameMethodReturnValueHandlerTests method returnViewRedirectWithCustomRedirectPattern.

@Test
public void returnViewRedirectWithCustomRedirectPattern() throws Exception {
    ModelMap redirectModel = new RedirectAttributesModelMap();
    this.mavContainer.setRedirectModel(redirectModel);
    this.handler.setRedirectPatterns("myRedirect:*");
    this.handler.handleReturnValue("redirect:testView", this.param, this.mavContainer, this.webRequest);
    assertThat(this.mavContainer.getViewName()).isEqualTo("redirect:testView");
    assertThat(this.mavContainer.getModel()).isSameAs(redirectModel);
}
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.jupiter.api.Test)

Example 14 with RedirectAttributesModelMap

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

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);
    assertThat(this.mavContainer.getView()).isSameAs(redirectView);
    assertThat(this.mavContainer.getModel()).as("Should have switched to the RedirectModel").isSameAs(redirectModel);
}
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.jupiter.api.Test)

Example 15 with RedirectAttributesModelMap

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

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);
    assertThat(this.mavContainer.getView()).isSameAs(redirectView);
    assertThat(this.mavContainer.getModel()).as("Should have switched to the RedirectModel").isSameAs(redirectModel);
}
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.jupiter.api.Test)

Aggregations

RedirectAttributesModelMap (org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap)40 ModelMap (org.springframework.ui.ModelMap)28 Test (org.junit.jupiter.api.Test)24 ModelAndView (org.springframework.web.servlet.ModelAndView)17 Test (org.junit.Test)11 RedirectView (org.springframework.web.servlet.view.RedirectView)6 DBUnitTest (org.orcid.test.DBUnitTest)5 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)5 AbstractNGrinderTransactionalTest (org.ngrinder.AbstractNGrinderTransactionalTest)4 FileEntry (org.ngrinder.script.model.FileEntry)3 MethodParameter (org.springframework.core.MethodParameter)3 DataBinder (org.springframework.validation.DataBinder)3 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)2 List (java.util.List)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)2 Model (org.springframework.ui.Model)2 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)2 BindingResult (org.springframework.validation.BindingResult)2 BindingAwareModelMap (org.springframework.validation.support.BindingAwareModelMap)2