So I used some mix/match approach for faster testing
- I used separate configuration files for testing and production
- I used two different JPA Persistence Units for Prod and Testing
- Added overrode the config file for test execution in build.sbt
- Utilized to generate test schema
- Utilized evolution to load test data fixtures into test data
Below are my files:
conf/test.conf
db.default.driver=org.h2.Driver
db.default.url="jdbc:h2:mem:lb"
db.default.user=lb
db.default.password=""
#
# You can expose this datasource via JNDI if needed (Useful for JPA)
db.default.jndiName=DefaultDS
jpa.default=testPersistenceUnit
# Evolutions
# ~~~~~
# You can disable evolutions if needed
#evolutionplugin=disabled
conf/application.conf
db.default.driver=com.mysql.jdbc.Driver
db.default.url="jdbc:mysql://X.X.X.X/lb"
db.default.user=lb
db.default.password="lb"
#
# You can expose this datasource via JNDI if needed (Useful for JPA)
db.default.jndiName=DefaultDS
jpa.default=defaultPersistenceUnit
# Evolutions
# ~~~~~
# You can disable evolutions if needed
evolutionplugin=disabled
Then added following option to build.sbt file
build.sbt
javaOptions in Test += "-Dconfig.file=conf/test.conf"
Finally the persistence.xml file
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<!--Persistence Unit for Production-->
<persistence-unit name="defaultPersistenceUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<non-jta-data-source>DefaultDS</non-jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.show_sql" value="true"></property>
<property name="hibernate.format_sql" value="true"></property>
</properties>
</persistence-unit>
<!--Persistence Unit for Testing-->
<persistence-unit name="testPersistenceUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<non-jta-data-source>DefaultDS</non-jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.show_sql" value="false"></property>
<property name="hibernate.format_sql" value="true"></property>
</properties>
</persistence-unit>
</persistence>
Finally I test it using
activator test
Thanks to users at play-framework google group for leads into achieving this.