Search code examples
mongodbplayframeworkmorphia

Play framework testing and access to session object when using MongoDB


In play framework application.conf there are lines:

%test.db.url=jdbc:h2:mem:play;MODE=MYSQL;LOCK_MODE=0
%test.jpa.ddl=create

But I am using MongoDB with Morphia. How do I change above settings for testing? Note that I am not using play framework morphia module.

From technical point of view, each unit test would have its own in memory instance of mongodb test database. How to make that happen?

Also when I use session object in test code both in functional and unit tests, I get compile error value session not found. How to access session in test code?


Solution

  • There isn't a way to modify those settings to create an "in memory instance of mongodb". If you want each unit test to have a clean copy of the database, you'll have to setup & teardown a new copy of your database in mongodb for each test.

    You can grab the session cookie directly in your functional tests using Scope.Session.current().