Search in sources :

Example 11 with FlashMap

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

the class FlashMapManagerTests method retrieveAndUpdateRemoveExpired.

@Test
public void retrieveAndUpdateRemoveExpired() {
    List<FlashMap> flashMaps = new ArrayList<>();
    for (int i = 0; i < 5; i++) {
        FlashMap expiredFlashMap = new FlashMap();
        expiredFlashMap.startExpirationPeriod(-1);
        flashMaps.add(expiredFlashMap);
    }
    this.flashMapManager.setFlashMaps(flashMaps);
    this.flashMapManager.retrieveAndUpdate(this.request, this.response);
    assertThat(this.flashMapManager.getFlashMaps().size()).as("Expired instances should be removed even if the saved FlashMap is empty").isEqualTo(0);
}
Also used : FlashMap(org.springframework.web.servlet.FlashMap) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Test(org.junit.jupiter.api.Test)

Example 12 with FlashMap

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

the class FlashMapManagerTests method saveOutputFlashMapDecodeParameters.

// SPR-9657, SPR-11504
@Test
public void saveOutputFlashMapDecodeParameters() throws Exception {
    FlashMap flashMap = new FlashMap();
    flashMap.put("key", "value");
    flashMap.setTargetRequestPath("/path");
    flashMap.addTargetRequestParam("param", "%D0%90%D0%90");
    flashMap.addTargetRequestParam("param", "%D0%91%D0%91");
    flashMap.addTargetRequestParam("param", "%D0%92%D0%92");
    flashMap.addTargetRequestParam("%3A%2F%3F%23%5B%5D%40", "value");
    this.request.setCharacterEncoding("UTF-8");
    this.flashMapManager.saveOutputFlashMap(flashMap, this.request, this.response);
    MockHttpServletRequest requestAfterRedirect = new MockHttpServletRequest("GET", "/path");
    requestAfterRedirect.setQueryString("param=%D0%90%D0%90&param=%D0%91%D0%91&param=%D0%92%D0%92&%3A%2F%3F%23%5B%5D%40=value");
    requestAfterRedirect.addParameter("param", "\u0410\u0410");
    requestAfterRedirect.addParameter("param", "\u0411\u0411");
    requestAfterRedirect.addParameter("param", "\u0412\u0412");
    requestAfterRedirect.addParameter(":/?#[]@", "value");
    flashMap = this.flashMapManager.retrieveAndUpdate(requestAfterRedirect, new MockHttpServletResponse());
    assertThatFlashMap(flashMap).isNotNull();
    assertThat(flashMap.size()).isEqualTo(1);
    assertThat(flashMap.get("key")).isEqualTo("value");
}
Also used : FlashMap(org.springframework.web.servlet.FlashMap) MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) MockHttpServletResponse(org.springframework.web.testfixture.servlet.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 13 with FlashMap

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

the class FlashMapManagerTests method retrieveAndUpdateMatchByPath.

@Test
public void retrieveAndUpdateMatchByPath() {
    FlashMap flashMap = new FlashMap();
    flashMap.put("key", "value");
    flashMap.setTargetRequestPath("/path");
    this.flashMapManager.setFlashMaps(Arrays.asList(flashMap));
    this.request.setRequestURI("/path");
    FlashMap inputFlashMap = this.flashMapManager.retrieveAndUpdate(this.request, this.response);
    assertThatFlashMap(inputFlashMap).isEqualTo(flashMap);
}
Also used : FlashMap(org.springframework.web.servlet.FlashMap) Test(org.junit.jupiter.api.Test)

Example 14 with FlashMap

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

the class FlashMapManagerTests method saveOutputFlashMapAndNormalizeEmptyTargetPath.

// gh-23240
@Test
public void saveOutputFlashMapAndNormalizeEmptyTargetPath() {
    FlashMap flashMap = new FlashMap();
    flashMap.put("key", "value");
    flashMap.setTargetRequestPath("");
    this.flashMapManager.saveOutputFlashMap(flashMap, this.request, this.response);
    assertThat(flashMap.getTargetRequestPath()).isEqualTo("");
}
Also used : FlashMap(org.springframework.web.servlet.FlashMap) Test(org.junit.jupiter.api.Test)

Example 15 with FlashMap

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

the class FlashMapManagerTests method retrieveAndUpdateMatchByOriginatingPathAndQueryString.

// SPR-15505
@Test
public void retrieveAndUpdateMatchByOriginatingPathAndQueryString() {
    FlashMap flashMap = new FlashMap();
    flashMap.put("key", "value");
    flashMap.setTargetRequestPath("/accounts");
    flashMap.addTargetRequestParam("a", "b");
    this.flashMapManager.setFlashMaps(Collections.singletonList(flashMap));
    this.request.setAttribute(WebUtils.FORWARD_REQUEST_URI_ATTRIBUTE, "/accounts");
    this.request.setAttribute(WebUtils.FORWARD_QUERY_STRING_ATTRIBUTE, "a=b");
    this.request.setRequestURI("/mvc/accounts");
    this.request.setQueryString("x=y");
    FlashMap inputFlashMap = this.flashMapManager.retrieveAndUpdate(this.request, this.response);
    assertThatFlashMap(inputFlashMap).isEqualTo(flashMap);
    assertThat(this.flashMapManager.getFlashMaps().size()).as("Input FlashMap should have been removed").isEqualTo(0);
}
Also used : FlashMap(org.springframework.web.servlet.FlashMap) 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