Skip to content
This repository was archived by the owner on Apr 4, 2026. It is now read-only.

Commit a861c90

Browse files
committed
Add integration test to check flash cookie removal (close #139)
1 parent 66ba610 commit a861c90

4 files changed

Lines changed: 41 additions & 3 deletions

File tree

project-code/integration-tests/src/test/scala/AllTests.scala

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,33 @@ abstract class AbstractPlay2WarTests extends FeatureSpec with GivenWhenThen with
285285
fail("Page not found")
286286
}
287287
}
288+
289+
scenario("Container set and remove flash cookie") {
290+
291+
// no flash cookie before test :)
292+
var maybeFlashCookie = Option(webClient.getCookieManager.getCookie("PLAY_FLASH"))
293+
maybeFlashCookie should be (None)
294+
295+
// still no flash cookie after this request
296+
webClient.getPage(rootUrl + "/redirectLanding")
297+
maybeFlashCookie = Option(webClient.getCookieManager.getCookie("PLAY_FLASH"))
298+
maybeFlashCookie should be (None)
299+
300+
// Call page which sets Flash cookie, then redirect to redirectLanding page which removes cookie
301+
val page = givenWhenGet("a page", "/flashing", "load a page which sets flash cookie")
302+
303+
Then("page body should contain 'Flash cookie: found'")
304+
page.map { p =>
305+
p.getWebResponse.getContentAsString should include("Flash cookie: found")
306+
}.getOrElse {
307+
fail("Page not found")
308+
}
309+
310+
// no flash cookie after redirecting
311+
maybeFlashCookie = Option(webClient.getCookieManager.getCookie("PLAY_FLASH"))
312+
maybeFlashCookie should be (None)
313+
314+
}
288315
}
289316

290317
/*

sample/common/app/controllers/Application.scala

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ object Application extends Controller {
4646
Ok(views.html.getCookies(mapCookies))
4747
}
4848

49-
def redirectLanding = Action {
50-
Ok(views.html.redirectLanding())
49+
def redirectLanding = Action { implicit request =>
50+
val flashResult = flash.get("success").getOrElse("not found")
51+
Ok(views.html.redirectLanding(flashResult))
5152
}
5253

5354
def redirect = Action {
@@ -181,4 +182,11 @@ object Application extends Controller {
181182
Thread.sleep(java.util.concurrent.TimeUnit.SECONDS.toMillis(duration))
182183
Ok("")
183184
}
185+
186+
def flashing = Action {
187+
Redirect(routes.Application.redirectLanding).flashing(
188+
"success" -> "found"
189+
)
190+
}
191+
184192
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
@()
1+
@(flashResult: String)
22

33
@main("Redirect landing") {
44
<p>redirect landing</p>
5+
<p>Flash cookie: @flashResult</p>
56
}

sample/common/conf/routes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,7 @@ GET /clock controllers.Application.liveClock
3434
GET /longRequest/:duration controllers.JavaApplication.longRequest(duration: Long)
3535
GET /slongRequest/:duration controllers.Application.longRequest(duration: Long)
3636

37+
GET /flashing controllers.Application.flashing
38+
3739
# Map static resources from the /public folder to the /assets URL path
3840
GET /assets/*file controllers.Assets.at(path="/public", file)

0 commit comments

Comments
 (0)