Search in sources :

Example 16 with FlashMap

use of org.springframework.web.servlet.FlashMap in project spring-framework by spring-projects.

the class RedirectViewUriTemplateTests method setUp.

@BeforeEach
public void setUp() {
    this.request = new MockHttpServletRequest();
    this.response = new MockHttpServletResponse();
    this.request.setAttribute(DispatcherServlet.OUTPUT_FLASH_MAP_ATTRIBUTE, new FlashMap());
    this.request.setAttribute(DispatcherServlet.FLASH_MAP_MANAGER_ATTRIBUTE, new SessionFlashMapManager());
}
Also used : FlashMap(org.springframework.web.servlet.FlashMap) MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) SessionFlashMapManager(org.springframework.web.servlet.support.SessionFlashMapManager) MockHttpServletResponse(org.springframework.web.testfixture.servlet.MockHttpServletResponse) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 17 with FlashMap

use of org.springframework.web.servlet.FlashMap in project spring-framework by spring-projects.

the class RedirectViewTests method setUp.

@BeforeEach
public void setUp() throws Exception {
    this.request = new MockHttpServletRequest();
    this.request.setContextPath("/context");
    this.request.setCharacterEncoding(WebUtils.DEFAULT_CHARACTER_ENCODING);
    this.request.setAttribute(DispatcherServlet.OUTPUT_FLASH_MAP_ATTRIBUTE, new FlashMap());
    this.request.setAttribute(DispatcherServlet.FLASH_MAP_MANAGER_ATTRIBUTE, new SessionFlashMapManager());
    this.response = new MockHttpServletResponse();
}
Also used : FlashMap(org.springframework.web.servlet.FlashMap) MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) SessionFlashMapManager(org.springframework.web.servlet.support.SessionFlashMapManager) MockHttpServletResponse(org.springframework.web.testfixture.servlet.MockHttpServletResponse) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 18 with FlashMap

use of org.springframework.web.servlet.FlashMap in project spring-framework by spring-projects.

the class RequestMappingHandlerAdapterTests method setAlwaysUseRedirectAttributes.

@Test
public void setAlwaysUseRedirectAttributes() throws Exception {
    HandlerMethodArgumentResolver redirectAttributesResolver = new RedirectAttributesMethodArgumentResolver();
    HandlerMethodArgumentResolver modelResolver = new ModelMethodProcessor();
    HandlerMethodReturnValueHandler viewHandler = new ViewNameMethodReturnValueHandler();
    this.handlerAdapter.setArgumentResolvers(Arrays.asList(redirectAttributesResolver, modelResolver));
    this.handlerAdapter.setReturnValueHandlers(Collections.singletonList(viewHandler));
    this.handlerAdapter.setIgnoreDefaultModelOnRedirect(true);
    this.handlerAdapter.afterPropertiesSet();
    this.request.setAttribute(DispatcherServlet.OUTPUT_FLASH_MAP_ATTRIBUTE, new FlashMap());
    HandlerMethod handlerMethod = handlerMethod(new RedirectAttributeController(), "handle", Model.class);
    ModelAndView mav = this.handlerAdapter.handle(request, response, handlerMethod);
    assertThat(mav.getModel().isEmpty()).as("Without RedirectAttributes arg, model should be empty").isTrue();
}
Also used : HandlerMethodReturnValueHandler(org.springframework.web.method.support.HandlerMethodReturnValueHandler) FlashMap(org.springframework.web.servlet.FlashMap) ModelMethodProcessor(org.springframework.web.method.annotation.ModelMethodProcessor) ModelAndView(org.springframework.web.servlet.ModelAndView) HandlerMethodArgumentResolver(org.springframework.web.method.support.HandlerMethodArgumentResolver) InvocableHandlerMethod(org.springframework.web.method.support.InvocableHandlerMethod) HandlerMethod(org.springframework.web.method.HandlerMethod) Test(org.junit.jupiter.api.Test)

Example 19 with FlashMap

use of org.springframework.web.servlet.FlashMap in project spring-framework by spring-projects.

the class FlashAttributeResultMatchersTests method getStubMvcResult.

private StubMvcResult getStubMvcResult() {
    FlashMap flashMap = new FlashMap();
    flashMap.put("good", "good");
    StubMvcResult mvcResult = new StubMvcResult(null, null, null, null, null, flashMap, null);
    return mvcResult;
}
Also used : StubMvcResult(org.springframework.test.web.servlet.StubMvcResult) FlashMap(org.springframework.web.servlet.FlashMap)

Example 20 with FlashMap

use of org.springframework.web.servlet.FlashMap in project spring-framework by spring-projects.

the class MockHttpServletRequestBuilderTests method flashAttribute.

@Test
void flashAttribute() {
    this.builder.flashAttr("foo", "bar");
    MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
    FlashMap flashMap = new SessionFlashMapManager().retrieveAndUpdate(request, null);
    assertThat((Object) flashMap).isNotNull();
    assertThat(flashMap.get("foo")).isEqualTo("bar");
}
Also used : FlashMap(org.springframework.web.servlet.FlashMap) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) SessionFlashMapManager(org.springframework.web.servlet.support.SessionFlashMapManager) Test(org.junit.jupiter.api.Test)

Aggregations

FlashMap (org.springframework.web.servlet.FlashMap)30 Test (org.junit.jupiter.api.Test)20 SessionFlashMapManager (org.springframework.web.servlet.support.SessionFlashMapManager)5 MockHttpServletRequest (org.springframework.web.testfixture.servlet.MockHttpServletRequest)5 MockHttpServletResponse (org.springframework.web.testfixture.servlet.MockHttpServletResponse)5 BeforeEach (org.junit.jupiter.api.BeforeEach)3 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)2 HandlerMethod (org.springframework.web.method.HandlerMethod)2 FlashMapManager (org.springframework.web.servlet.FlashMapManager)2 ModelAndView (org.springframework.web.servlet.ModelAndView)2 ArrayList (java.util.ArrayList)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 Cookie (javax.servlet.http.Cookie)1 JsonResponse (org.broadleafcommerce.common.web.JsonResponse)1 ClassMetadata (org.broadleafcommerce.openadmin.dto.ClassMetadata)1 DynamicResultSet (org.broadleafcommerce.openadmin.dto.DynamicResultSet)1 Entity (org.broadleafcommerce.openadmin.dto.Entity)1 SectionCrumb (org.broadleafcommerce.openadmin.dto.SectionCrumb)1 PersistencePackageRequest (org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest)1 Test (org.junit.Test)1