org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap Java Examples

The following examples show how to use org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ModelAndViewMethodReturnValueHandlerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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();
	assertEquals("redirect:viewName", mavContainer.getViewName());
	assertEquals("attrValue", model.get("attrName"));
	assertSame(redirectAttributes, model);
}
 
Example #2
Source File: ViewMethodReturnValueHandlerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #3
Source File: ModelAndViewMethodReturnValueHandlerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #4
Source File: ModelAndViewMethodReturnValueHandlerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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();
	assertEquals("myRedirect:viewName", mavContainer.getViewName());
	assertEquals("attrValue", model.get("attrName"));
	assertSame(redirectAttributes, model);
}
 
Example #5
Source File: ModelAndViewMethodReturnValueHandlerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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();
	assertEquals("redirect:viewName", mavContainer.getViewName());
	assertEquals("attrValue", model.get("attrName"));
	assertSame(redirectAttributes, model);
}
 
Example #6
Source File: ModelAndViewMethodReturnValueHandlerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #7
Source File: ViewNameMethodReturnValueHandlerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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);
	assertEquals("redirect:testView", this.mavContainer.getViewName());
	assertSame(redirectModel, this.mavContainer.getModel());
}
 
Example #8
Source File: ViewNameMethodReturnValueHandlerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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);
	assertEquals("myRedirect:testView", this.mavContainer.getViewName());
	assertSame(redirectModel, this.mavContainer.getModel());
}
 
Example #9
Source File: ViewNameMethodReturnValueHandlerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #10
Source File: RedirectAttributesMethodArgumentResolver.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
		NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {

	DataBinder dataBinder = binderFactory.createBinder(webRequest, null, null);
	ModelMap redirectAttributes  = new RedirectAttributesModelMap(dataBinder);
	mavContainer.setRedirectModel(redirectAttributes);
	return redirectAttributes;
}
 
Example #11
Source File: ViewMethodReturnValueHandlerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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());
}
 
Example #12
Source File: ModelAndViewMethodReturnValueHandlerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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);
}
 
Example #13
Source File: ModelAndViewMethodReturnValueHandlerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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();
	assertEquals("myRedirect:viewName", mavContainer.getViewName());
	assertEquals("attrValue", model.get("attrName"));
	assertSame(redirectAttributes, model);
}
 
Example #14
Source File: ViewNameMethodReturnValueHandlerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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());
}
 
Example #15
Source File: ModelAndViewMethodReturnValueHandlerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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());
}
 
Example #16
Source File: ViewNameMethodReturnValueHandlerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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);
	assertEquals("redirect:testView", this.mavContainer.getViewName());
	assertSame(redirectModel, this.mavContainer.getModel());
}
 
Example #17
Source File: ViewNameMethodReturnValueHandlerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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);
	assertEquals("myRedirect:testView", this.mavContainer.getViewName());
	assertSame(redirectModel, this.mavContainer.getModel());
}
 
Example #18
Source File: ViewNameMethodReturnValueHandlerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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());
}
 
Example #19
Source File: ViewMethodReturnValueHandlerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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());
}
 
Example #20
Source File: ModelAndViewMethodReturnValueHandlerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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);
}
 
Example #21
Source File: ModelAndViewMethodReturnValueHandlerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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();
	assertEquals("myRedirect:viewName", mavContainer.getViewName());
	assertEquals("attrValue", model.get("attrName"));
	assertSame(redirectAttributes, model);
}
 
Example #22
Source File: ModelAndViewMethodReturnValueHandlerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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();
	assertEquals("redirect:viewName", mavContainer.getViewName());
	assertEquals("attrValue", model.get("attrName"));
	assertSame(redirectAttributes, model);
}
 
Example #23
Source File: ModelAndViewMethodReturnValueHandlerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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());
}
 
Example #24
Source File: ViewNameMethodReturnValueHandlerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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);
	assertEquals("redirect:testView", this.mavContainer.getViewName());
	assertSame(redirectModel, this.mavContainer.getModel());
}
 
Example #25
Source File: ViewNameMethodReturnValueHandlerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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);
	assertEquals("myRedirect:testView", this.mavContainer.getViewName());
	assertSame(redirectModel, this.mavContainer.getModel());
}