Search in sources :

Example 11 with ModelMap

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());
}
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)

Example 12 with ModelMap

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");
}
Also used : RequestDataValueProcessor(org.springframework.web.servlet.support.RequestDataValueProcessor) RequestDataValueProcessorWrapper(org.springframework.web.servlet.support.RequestDataValueProcessorWrapper) ModelMap(org.springframework.ui.ModelMap) StaticWebApplicationContext(org.springframework.web.context.support.StaticWebApplicationContext) MockServletContext(org.springframework.mock.web.test.MockServletContext) Test(org.junit.Test)

Example 13 with ModelMap

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);
    }
}
Also used : ContextLoader(org.springframework.web.context.ContextLoader) RequestDataValueProcessor(org.springframework.web.servlet.support.RequestDataValueProcessor) RequestDataValueProcessorWrapper(org.springframework.web.servlet.support.RequestDataValueProcessorWrapper) ModelMap(org.springframework.ui.ModelMap) StaticWebApplicationContext(org.springframework.web.context.support.StaticWebApplicationContext) MockServletContext(org.springframework.mock.web.test.MockServletContext) Test(org.junit.Test)

Example 14 with ModelMap

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());
}
Also used : ModelMap(org.springframework.ui.ModelMap) Test(org.junit.Test)

Example 15 with ModelMap

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();
}
Also used : ModelMap(org.springframework.ui.ModelMap) Test(org.junit.Test)

Aggregations

ModelMap (org.springframework.ui.ModelMap)48 Test (org.junit.Test)23 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)18 ModelAndView (org.springframework.web.servlet.ModelAndView)11 RedirectAttributesModelMap (org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap)9 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)5 Map (java.util.Map)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 IOException (java.io.IOException)3 Date (java.util.Date)3 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)3 HttpSessionRequiredException (org.springframework.web.HttpSessionRequiredException)3 RedirectAttributes (org.springframework.web.servlet.mvc.support.RedirectAttributes)3 NimbusClient (backtype.storm.utils.NimbusClient)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ParseException (java.text.ParseException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 HttpSession (javax.servlet.http.HttpSession)2