Search in sources :

Example 26 with RedirectAttributesModelMap

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

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 27 with RedirectAttributesModelMap

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

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 28 with RedirectAttributesModelMap

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

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 29 with RedirectAttributesModelMap

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

the class ModelAndViewMethodReturnValueHandlerTests method handleRedirectAttributesWithCustomPrefix.

@Test
public void handleRedirectAttributesWithCustomPrefix() throws Exception {
    RedirectAttributesModelMap redirectAttributes = new RedirectAttributesModelMap();
    mavContainer.setRedirectModel(redirectAttributes);
    ModelAndView mav = new ModelAndView("myRedirect:viewName", "attrName", "attrValue");
    handler.setRedirectPatterns("myRedirect:*");
    handler.handleReturnValue(mav, returnParamModelAndView, mavContainer, webRequest);
    ModelMap model = mavContainer.getModel();
    assertThat(mavContainer.getViewName()).isEqualTo("myRedirect: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 30 with RedirectAttributesModelMap

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

the class ViewNameMethodReturnValueHandlerTests method returnViewCustomRedirect.

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

Aggregations

RedirectAttributesModelMap (org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap)64 ModelMap (org.springframework.ui.ModelMap)44 Test (org.junit.jupiter.api.Test)33 ModelAndView (org.springframework.web.servlet.ModelAndView)25 Test (org.junit.Test)24 RedirectView (org.springframework.web.servlet.view.RedirectView)10 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)9 BindingResult (org.springframework.validation.BindingResult)6 DBUnitTest (org.orcid.test.DBUnitTest)5 MethodParameter (org.springframework.core.MethodParameter)5 DataBinder (org.springframework.validation.DataBinder)5 TodoDTO (net.petrikainulainen.spring.testmvc.todo.dto.TodoDTO)4 AbstractNGrinderTransactionalTest (org.ngrinder.AbstractNGrinderTransactionalTest)4 FileEntry (org.ngrinder.script.model.FileEntry)3 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)2 List (java.util.List)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 TodoNotFoundException (net.petrikainulainen.spring.testmvc.todo.exception.TodoNotFoundException)2 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)2 Model (org.springframework.ui.Model)2