Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[#276] Ok.sendFile() with onClose integration test.

An integration test based on FunctionalSpec. It creates a file, calls
the action (by url) with the canonical path of the file as parameter and
expects it to be deleted once the request is done.
  • Loading branch information...
commit cfb9a50a303f95c36d6d6e6fdf494d62543d69d6 1 parent cc3bcd7
@arnihermann authored
View
5 framework/test/integrationtest/app/controllers/Application.scala
@@ -111,4 +111,9 @@ object Application extends Controller {
}
}
+ def onCloseSendFile(filepath: String) = Action {
+ import java.io.File
+ val file = new File(filepath)
+ Ok.sendFile(file, onClose = () => { file.delete() })
+ }
}
View
2  framework/test/integrationtest/conf/routes
@@ -41,6 +41,8 @@ GET /javascript-test controllers.Application.javascriptTest(name)
GET /accept controllers.Application.accept()
GET /accept-java controllers.JavaApi.accept()
+GET /onCloseSendFile/*fp controllers.Application.onCloseSendFile(fp)
+
# Map static resources from the /public folder to the /public path
GET /public/*file controllers.Assets.at(path="/public", file)
View
12 framework/test/integrationtest/test/FunctionalSpec.scala
@@ -12,6 +12,18 @@ import org.openqa.selenium.htmlunit.HtmlUnitDriver
class FunctionalSpec extends Specification {
"an Application" should {
+ "call onClose for Ok.sendFile responses" in {
+ import java.io.File
+ running(TestServer(9003), HTMLUNIT) { browser =>
+ def file = new File("onClose.tmp")
+ file.createNewFile()
+ file.exists() must equalTo(true)
+
+ browser.goTo("http://localhost:9003/onCloseSendFile/" + file.getCanonicalPath)
+ file.exists() must equalTo(false)
+ }
+ }
+
"pass functional test with two browsers" in {
running(TestServer(9002), HTMLUNIT) { browser =>
browser.goTo("http://localhost:9002")
Please sign in to comment.
Something went wrong with that request. Please try again.