use of org.springframework.ui.ModelMap in project spring-framework by spring-projects.
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);
assertEquals("redirect:testView", this.mavContainer.getViewName());
assertSame(redirectModel, this.mavContainer.getModel());
}
use of org.springframework.ui.ModelMap in project spring-framework by spring-projects.
the class RedirectViewTests method updateTargetUrl.
@Test
public void updateTargetUrl() throws Exception {
StaticWebApplicationContext wac = new StaticWebApplicationContext();
wac.registerSingleton("requestDataValueProcessor", RequestDataValueProcessorWrapper.class);
wac.setServletContext(new MockServletContext());
wac.refresh();
RequestDataValueProcessor mockProcessor = mock(RequestDataValueProcessor.class);
wac.getBean(RequestDataValueProcessorWrapper.class).setRequestDataValueProcessor(mockProcessor);
RedirectView rv = new RedirectView();
// Init RedirectView with WebAppCxt
rv.setApplicationContext(wac);
rv.setUrl("/path");
request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
given(mockProcessor.processUrl(request, "/path")).willReturn("/path?key=123");
rv.render(new ModelMap(), request, response);
verify(mockProcessor).processUrl(request, "/path");
}
use of org.springframework.ui.ModelMap in project spring-framework by spring-projects.
the class RedirectViewTests method updateTargetUrlWithContextLoader.
@Test
public void updateTargetUrlWithContextLoader() throws Exception {
StaticWebApplicationContext wac = new StaticWebApplicationContext();
wac.registerSingleton("requestDataValueProcessor", RequestDataValueProcessorWrapper.class);
MockServletContext servletContext = new MockServletContext();
ContextLoader contextLoader = new ContextLoader(wac);
contextLoader.initWebApplicationContext(servletContext);
try {
RequestDataValueProcessor mockProcessor = mock(RequestDataValueProcessor.class);
wac.getBean(RequestDataValueProcessorWrapper.class).setRequestDataValueProcessor(mockProcessor);
RedirectView rv = new RedirectView();
rv.setUrl("/path");
given(mockProcessor.processUrl(request, "/path")).willReturn("/path?key=123");
rv.render(new ModelMap(), request, response);
verify(mockProcessor).processUrl(request, "/path");
} finally {
contextLoader.closeWebApplicationContext(servletContext);
}
}
use of org.springframework.ui.ModelMap in project spring-framework by spring-projects.
the class RedirectViewUriTemplateTests method dontApplyUriVariables.
// SPR-9016
@Test
public void dontApplyUriVariables() throws Exception {
String url = "/test#{'one','abc'}";
RedirectView redirectView = new RedirectView(url, true);
redirectView.setExpandUriTemplateVariables(false);
redirectView.renderMergedOutputModel(new ModelMap(), this.request, this.response);
assertEquals(url, this.response.getRedirectedUrl());
}
use of org.springframework.ui.ModelMap in project spring-framework by spring-projects.
the class MappingJackson2JsonViewTests method renderWithPrettyPrint.
@Test
public void renderWithPrettyPrint() throws Exception {
ModelMap model = new ModelMap("foo", new TestBeanSimple());
view.setPrettyPrint(true);
view.render(model, request, response);
String result = response.getContentAsString().replace("\r\n", "\n");
assertTrue("Pretty printing not applied:\n" + result, result.startsWith("{\n \"foo\" : {\n "));
validateResult();
}
Aggregations