Search in sources :

Example 26 with FlashMap

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

the class FlashMapManagerTests method flashAttributesWithQueryParamsWithSpace.

// SPR-12569
@Test
public void flashAttributesWithQueryParamsWithSpace() throws Exception {
    String encodedValue = URLEncoder.encode("1 2", StandardCharsets.UTF_8);
    FlashMap flashMap = new FlashMap();
    flashMap.put("key", "value");
    flashMap.setTargetRequestPath("/path");
    flashMap.addTargetRequestParam("param", encodedValue);
    this.request.setCharacterEncoding("UTF-8");
    this.flashMapManager.saveOutputFlashMap(flashMap, this.request, this.response);
    MockHttpServletRequest requestAfterRedirect = new MockHttpServletRequest("GET", "/path");
    requestAfterRedirect.setQueryString("param=" + encodedValue);
    requestAfterRedirect.addParameter("param", "1 2");
    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 27 with FlashMap

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

the class FlashMapManagerTests method saveOutputFlashMapEmpty.

@Test
public void saveOutputFlashMapEmpty() {
    FlashMap flashMap = new FlashMap();
    this.flashMapManager.saveOutputFlashMap(flashMap, this.request, this.response);
    List<FlashMap> allMaps = this.flashMapManager.getFlashMaps();
    assertThat(allMaps).isNull();
}
Also used : FlashMap(org.springframework.web.servlet.FlashMap) Test(org.junit.jupiter.api.Test)

Example 28 with FlashMap

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

the class FlashMapManagerTests method saveOutputFlashMap.

@Test
public void saveOutputFlashMap() {
    FlashMap flashMap = new FlashMap();
    flashMap.put("name", "value");
    // expire immediately so we can check expiration started
    this.flashMapManager.setFlashMapTimeout(-1);
    this.flashMapManager.saveOutputFlashMap(flashMap, this.request, this.response);
    List<FlashMap> allMaps = this.flashMapManager.getFlashMaps();
    assertThat(allMaps).isNotNull();
    assertThatFlashMap(allMaps.get(0)).isSameAs(flashMap);
    assertThat(flashMap.isExpired()).isTrue();
}
Also used : FlashMap(org.springframework.web.servlet.FlashMap) Test(org.junit.jupiter.api.Test)

Example 29 with FlashMap

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

the class FlashMapManagerTests method retrieveAndUpdateMatchWithTrailingSlash.

@Test
public void retrieveAndUpdateMatchWithTrailingSlash() {
    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);
    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)

Example 30 with FlashMap

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

the class FlashMapManagerTests method saveOutputFlashMapDecodeTargetPath.

@Test
public void saveOutputFlashMapDecodeTargetPath() {
    FlashMap flashMap = new FlashMap();
    flashMap.put("key", "value");
    flashMap.setTargetRequestPath("/once%20upon%20a%20time");
    this.flashMapManager.saveOutputFlashMap(flashMap, this.request, this.response);
    assertThat(flashMap.getTargetRequestPath()).isEqualTo("/once upon a time");
}
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