in play functional tests I am executing a request to some of my controllers method.
And in controller I am using flash scope to get some parameter and do work with it.
However in test I cannot setup this flash parameter, I tried:
Flash.current().put("key","value");
but that gives NullPointerException in test.
and in controller flash scope is empty:
flash.get("key")
How to setup flash scope? I don’t want to test whole workflow of setting this flash value, and reading it, I want to concentrate just on this one request.
Functional test execution is in a different thread than test setup with functional tests, so setting the Flash.current() won’t work.
Though, the
FunctionalTestclass stores cookies between calls.So one possibility to test requests which use the flash scope is to first call the request which, in your application, indeed sets the flash scope — though according to your description, you don’t want to that.
Another possibility is to manually put the Flash-Scoped variables into the cookies in the
Request— you would need to consultplay.mvc.Scope.Flash.save()for the format.