Is it possible to run some controllers and routes only in test mode?
I need to mock some response when clicking by link. I would create controller and routs that would be available only when I run play test.
Is it possible?
As Mike has indicated, the code from my Blog indeed shows you how to configure your route file, so that only certain routes are available in Dev or Prod mode. So...
%{ if (play.mode.isDev()) { }%
GET /route4 Application.noProd
GET /route5 Application.noProd
GET /route6 Application.noProd
%{ } }%
However, this will indeed prevent these routes from working in Prod mode, but they will not exclude the controller from being accessed. The reason for this, is that more than likely you will have the following at the bottom of your routes file
* /{controller}/{action} {controller}.{action}
This means that I can access the Application.noProd
action using the catch all route, which would be the following URL
/application/noprod
So. If you want to hide your routes and your controllers, you have a few options.
You could remove the catch-all route, so that there is no entry other than the specific routes you have set up. This does mean that you need to specify all your routes for all actions in your routes file.
Secondly, you could check for play.mode.isDev()
in your actions, and call badRequest()
to prevent access. This would make this much more visible, but may be an unacceptable overhead in coding.
Yes it possible. You can add code to your route file like:
%{ if (play.mode.isDev()) { }%
GET /route4 Application.noProd
GET /route5 Application.noProd
GET /route6 Application.noProd
%{ } }%
Everything is explained on this website: http://playframework.wordpress.com/2011/07/15/hidden-features-of-the-play-framework-routes-file/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With