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);
}
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¶m=%D0%91%D0%91¶m=%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");
}
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);
}
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("");
}
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);
}
Aggregations