WSO2 ESB Unit Test Suite - problem with artifact from registry - unit-testing

WSO2: 7.0.0
WSO2 MI: 1.1.0
I have defined Unit Test Suite for sequence with Validation Mediator. Validator mediator uses json schema from Registry (conf:schema/PostQuestionsJSONSchema.json):
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="ValidateUpdateQuestion" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<validate cache-schema="true">
<schema key="conf:schema/PostQuestionsJSONSchema.json"/>
<on-fail>
<propertyGroup description="Set Error Info">
<property name="httpErrorCode" scope="default" type="STRING" value="400"/>
<property name="httpErrorMessage" scope="default" type="STRING" value="Bad Request"/>
</propertyGroup>
<sequence key="DefaultFaultHandler"/>
</on-fail>
</validate>
</sequence>
In my Unit Test Suite, I have defined registry-resource (PostQuestionsJSONSchema.json):
<unit-test>
<artifacts>
<test-artifact>
<artifact>/TestProject/src/main/synapse-config/sequences/ValidateUpdateQuestion.xml</artifact>
</test-artifact>
<supportive-artifacts>
<artifact>/TestProject/src/main/synapse-config/sequences/DefaultFaultHandler.xml</artifact>
</supportive-artifacts>
<registry-resources>
<registry-resource>
<file-name>PostQuestionsJSONSchema.json</file-name>
<artifact>\TestProjectRegistry\PostQuestionsJSONSchema.json</artifact>
<registry-path>/_system/config/schema</registry-path>
<media-type>application/json</media-type>
</registry-resource>
</registry-resources>
<connector-resources/>
</artifacts>
<test-cases>
<test-case name="valid">
<input>
<payload><![CDATA[<body></body>]]></payload>
<properties>
<property name="Content-Type" scope="transport" value="application/json"/>
</properties>
</input>
<assertions>
<assertNotNull>
<actual>$body</actual>
<message>Body is NULL</message>
</assertNotNull>
</assertions>
</test-case>
</test-cases>
<mock-services/>
</unit-test>
But when I start that test, I have:
[INFO] +-------------------+----------------+---------------+---------------+
[INFO] | TEST CASE | DEPLOYMENT | MEDIATION | ASSERTION |
[INFO] +===================+================+===============+===============+
[INFO] | Test Case - Suite | PASSED | FAILED | SKIPPED |
[INFO] +-------------------+----------------+---------------+---------------+
[INFO]
[INFO] Failed Test Case(s):
[INFO] +-------------------+-------------------+-------------------------------------------------------------------------------------------+
[INFO] | TEST CASE | FAILURE STATE | EXCEPTION / ERROR MESSAGE |
[INFO] +===================+===================+===========================================================================================+
[INFO] | Test Case - valid | MEDIATION | No Schema is available with the key : conf:schema/PostQuestionsJSONSchema.json |
[INFO] | | | org.apache.synapse.mediators.builtin.ValidateMediator.mediate(ValidateMediator.java:413) |
How to define correclty registry resources for Unit Test Suite?

Did you try this in the latest WSO2 MI 1.2.0 runtime? They have done a couple of fixes for the unit testing framework. It worked for me the unit test suite with both registry and connector resources.

Related

How to increase the server startup timeout in WSO2 Integration Studio?

I want to make an oracle database connection by opening a dataservice project with WSO2 Integration studio application. I can connect to the Oracle database. But when I run the dataservice project, the WSO2 Integration Studio application goes into time out and asks us to increase the time out time. How and where should we increase this time?
Integration Studio Dataservice project Xml :
<data transports="http https" serviceGroup="" serviceNamespace="" name="demoDataService">
<description />
<resource method="GET" path="GetGenders">
<call-query href="GetGenders" />
</resource>
<config id="OracleDataSourceIdenfierName" enableOData="true">
<property name="driverClassName">oracle.jdbc.driver.OracleDriver</property>
<property name="url">jdbc:oracle:thin:#host:port/schema_name</property>
<property name="username">username</property>
<property name="password">password</property>
</config>
<query id="GetGenders" useConfig="OracleDataSourceIdenfierName">
<sql>SELECT column1,column2 FROM schema_name.table_name</sql>
<result outputType="json">{
"Genders": {
"Gender": [
{
"column1": "$column1",
"column2": "$column2"
}
]
}
}</result>
<properties>
<property name="fetchDirection">forward</property>
</properties>
</query>
</data>
WSO2 Integration Studio Timeout Error:
Go to Window -> Show View -> Other Then search for Servers. Select Servers and click on Open.
Then Double Click on the "Micro Integrator Server 4.1" Then look for the timeout settings.

ESB WSO2 | Trying to send an email through email connector and getting "org.wso2.carbon.connector.email.send cannot be found" error

I'm trying to send an email using email connector from esb wso2 but I'm getting this error:
Invoking Target EIP Sequence org.wso2.carbon.connector.email.send paramNames : [from, to, subject, content, contentType]
[2022-07-22 10:52:14,113] ERROR {org.apache.synapse.mediators.template.InvokeMediator} - Sequence template org.wso2.carbon.connector.email.send cannot be found
[2022-07-22 10:52:14,121] DEBUG {org.apache.synapse.debug.SynapseDebugManager} - Mediation flow terminated for id urn:uuid:3f3f9864-bbc1-4e95-a4bf-1574196dfb8c
[2022-07-22 10:52:14,121] WARN {org.apache.synapse.core.axis2.SynapseMessageReceiver} - Executing fault handler due to exception encountered
[2022-07-22 10:52:14,121] WARN {org.apache.synapse.FaultHandler} - ERROR_CODE : 0
[2022-07-22 10:52:14,121] WARN {org.apache.synapse.FaultHandler} - ERROR_MESSAGE : Sequence template org.wso2.carbon.connector.email.send cannot be found
[2022-07-22 10:52:14,122] WARN {org.apache.synapse.FaultHandler} - ERROR_DETAIL : org.apache.synapse.SynapseException: Sequence template org.wso2.carbon.connector.email.send cannot be found
This is my api which I use:
<?xml version="1.0" encoding="UTF-8"?>
<api context="/api/send/email" name="api.send.email" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST">
<inSequence>
<property expression="json-eval($.from)" name="from" scope="default" type="STRING"/>
<property expression="json-eval($.to)" name="to" scope="default" type="STRING"/>
<property expression="json-eval($.subject)" name="subject" scope="default" type="STRING"/>
<property expression="json-eval($.content)" name="content" scope="default" type="STRING"/>
<property expression="json-eval($.contentType)" name="contentType" scope="default" type="STRING"/>
<log level="custom">
<property expression="$ctx:from" name="Log_from:"/>
<property expression="$ctx:to" name="Log_to:"/>
<property expression="$ctx:subject" name="Log_subject:"/>
<property expression="$ctx:content" name="Log_content:"/>
<property expression="$ctx:contentType" name="Log_contentType:"/>
</log>
<email.send configKey="TEST_SMTP_CONNECTION">
<from>{json-eval($.from)}</from>
<to>{json-eval($.to)}</to>
<subject>{json-eval($.subject)}</subject>
<content>{json-eval($.content)}</content>
<contentType>{json-eval($.contentType)}</contentType>
</email.send>
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
</api>
I think the problem is based on the fact that I don't think I added the connector on my project in the correct way.
So, first of all I added a connector on my main project (where I have APIs, endpoints etc) - Right Click - Add or Remove Connector/Module - then I added the email connector)
Then I created a new Connector Exporter on my project (Right Click on an empty space on my Project Explorer - I named the exporter 'test' - and I think here is the problem:
What Group ID, Parent Group ID and Parent Artifact ID I should choose? (same question when I'm making Composite Application for connector)
LATER EDIT*:
When I'm deploying de car. app for the email connector I'm getting these errors:
Error in instantiating class : org.wso2.carbon.connector.operations.list.EmailGetAttachment java.lang.NoClassDefFoundError: org/wso2/carbon/connector/core/exception/ContentBuilderException
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671)
at java.lang.Class.getConstructor0(Class.java:3075)
at java.lang.Class.newInstance(Class.java:412)
Unable to update status for : {org.wso2.carbon.connector}email :: Template configuration : null cannot be builtfor Synapse Library artifact : getEmailAttachment org.apache.synapse.deployers.SynapseArtifactDeploymentException: Template configuration : null cannot be builtfor Synapse Library artifact : getEmailAttachment
To answer your questions, if you have a Maven MultiModule Project you can get the details of the parent project from the pom.xml of the parent project.(This is the root pom.xml typically)
The easiest way to resolve your problem is to create your project from an existing template which will make sure projects are created correctly. Inorder to do that, follow the steps below.
Open Integration Studio and Go to Help -> Getting Started.
Then select the Email Service sample project, give it a name and create the project.
Now you should have a full working project with a Connector Exported.
In the future for creating new projects, you can refer to this document.

WSO2 ESB FileConnector MergeFiles does not produce expected results

I am working with the WSO2 ESB 6.5.0 and am using the fileconnector-2.0.21 version for file operations. The proxy service that I'm building is intended to read the files from a certain source path and merge the contents into a file at the destination path.
The content of the proxy service artifact is below
<?xml version="1.0" encoding="UTF-8"?>
<proxy name="FileMergeProxy" startOnLoad="true" transports="http https" xmlns="http://ws.apache.org/ns/synapse">
<target>
<inSequence>
<log description="Combine files" level="custom" separator="| ">
<property name="statusMessage" value="Processing complete"/>
<property name="fileCreation" value="Initiating file merge"/>
<property expression="$ctx:mergeDirPath" name="sourceDir"/>
<property expression="$ctx:finalDirPath" name="destDir"/>
<property expression="$ctx:outputFilePattern" name="pattern"/>
<property expression="fn:concat('file:///', $ctx:mergeDirPath)" name="sourceDir1" scope="default" type="STRING"/>
property expression="fn:concat('file:///', $ctx:finalDirPath)" name="destDir1" scope="default" type="STRING"/>
</log>
<fileconnector.mergeFiles>
<source>{$ctx:mergeDirPath}</source>
<destination>{$ctx:finalDirPath}</destination>
<filePattern>{$ctx:outputFilePattern}</filePattern>
</fileconnector.mergeFiles>
<log description="Processing complete" level="custom" separator="| ">
<property name="doneMessage" value="File merge processing complete"/>
</log>
</inSequence>
<outSequence/>
<faultSequence>
<log level="custom">
<property name="text" value="An unexpected error occured"/>
<property expression="get-property('ERROR_MESSAGE')" name="message"/>
<property expression="get-property('ERROR_DETAIL')" name="errordetail"/>
</log>
<send description="Send Error Information"/>
</faultSequence>
</target>
</proxy>
I'm invoking the service with the following parameters as a JSON file
{
"mergeDirPath": "C://temp//merge//",
"finalDirPath": "C://temp//final//finalcontent.txt",
"outputFilePattern": "\\*txt"
}
When I call the service after deploying the artifacts to the ESB engine, it creates an empty file in the destination path without merging the contents of the files in the source directory. This is the extract from the WSO2 logs.
[2020-03-23 12:48:36,683] [] INFO - LogMediator To: /services/FileMergeProxy,MessageID: urn:uuid:b569ec6a-d4fe-4763-a0ca-fb2eb868a31e correlation_id : a1c542bb-7fac-4e0b-9582-8cb1a605f618,Direction: request,Payload: { "mergeDirPath": "C://temp//merge//", "finalDirPath": "C://temp//final//finalcontent.txt", "outputFilePattern": "\\*txt" }
[2020-03-23 12:49:00,422] [] INFO - LogMediator statusMessage = Combine files| fileCreation = Initiating file merge| sourceDir = C://temp//merge//| destDir = C://temp//final//finalcontent.txt| pattern = \*txt| sourceDir1 = file:///C://temp//merge//| destDir1 = file:///C://temp//final//finalcontent.txt
[2020-03-23 12:49:02,943] [] INFO - LogMediator doneMessage = File merge processing complete
Unless I'm missing something here, shouldn't the mergeFiles be doing exactly that - merge the contents of files in a specified directory ? Any helpful suggestions or pointers are welcome. Thanks in advance.
According to the proxy you have shared, you have defined properties inside the log mediator. Define the properties outside the log mediator.

In WSO2 ESB, how to pass parameter to sequence from scheduler task

I configured a scheduler task to invoke a sequence; and I need to pass a parameter to this sequence per requirement. How to accomplish this in WSO2 ESB? I had attempting to pass in the value through the message property in the scheduler task and read the value off the message in the sequence. But failed to obtain the value in the sequence. My codes and output shown below. Please let me know what I should do to make it work. Thank you for your time in advance.
<task class="org.apache.synapse.startup.tasks.MessageInjector" group="synapse.simple.quartz" name="UploadFile2Vendor1" xmlns="http://ws.apache.org/ns/synapse">
<trigger interval="15"/>
<property name="message" xmlns:task="http://www.wso2.org/products/wso2commons/tasks">
<request>
<vendorId>1</vendorId>
</request>
</property>
<property name="sequenceName" value="SendFile2VendorSeq" xmlns:task="http://www.wso2.org/products/wso2commons/tasks"/>
<property name="injectTo" value="sequence" xmlns:task="http://www.wso2.org/products/wso2commons/tasks"/>
</task>
<sequence name="SendFile2VendorSeq" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<log>
<property xmlns:m0="http://services.samples"
expression="$body/m0:request/m0:vendorId" name="vendorId"/>
</log>
<dblookup description="get vendor">
<connection>
<pool>
<dsName>jdbc/DBDS</dsName>
</pool>
</connection>
<statement>
<sql>SELECT code, name FROM vendor WHERE id = ?</sql>
<parameter expression="get-property('vendorId')" type="INTEGER"/>
<result column="code" name="code"/>
<result column="name" name="name"/>
</statement>
</dblookup>
</sequence>
Output in log file
[2016-07-27 09:25:36,446] DEBUG - StartUpController Synapse server name : localhost
[2016-07-27 09:25:36,446] DEBUG - StartUpController loaded task property : <property xmlns="http://ws.apache.org/ns/synapse" xmlns:task="http://www.wso2.org/products/wso2commons/tasks" name="injectTo" value="sequence"/>
[2016-07-27 09:25:36,446] DEBUG - StartUpController loaded task property : <property xmlns="http://ws.apache.org/ns/synapse" xmlns:task="http://www.wso2.org/products/wso2commons/tasks" name="sequenceName" value="SendFile2VendorSeq"/>
[2016-07-27 09:25:36,446] DEBUG - StartUpController loaded task property : <property xmlns="http://ws.apache.org/ns/synapse" xmlns:task="http://www.wso2.org/products/wso2commons/tasks" name="message">
<request>
<vendorId>1</vendorId>
</request>
</property>
[2016-07-27 09:25:36,446] DEBUG - PropertyHelper Setting property :: invoking method setMessage(<request xmlns="http://ws.apache.org/ns/synapse">
<vendorId>1</vendorId>
</request>)
[2016-07-27 09:25:36,446] DEBUG - MessageInjector set message <request xmlns="http://ws.apache.org/ns/synapse">
<vendorId>1</vendorId>
</request>
[2016-07-27 09:25:36,446] DEBUG - TaskScheduler TaskScheduler already initialized.
[2016-07-27 09:25:36,532] INFO - AbstractQuartzTaskManager Task scheduled: [-1234][ESB_TASK][Upload2Vendor]
[2016-07-27 09:25:36,532] INFO - NTaskTaskManager Scheduled task [NTask::-1234::Upload2Vendor]
[2016-07-27 09:25:36,532] DEBUG - StartUpController Submitted task [Upload2Vendor] to Synapse task scheduler.
[2016-07-27 09:25:36,532] DEBUG - TaskDeployer Initialized the StartupTask : Upload2Vendor
[2016-07-27 09:25:36,532] DEBUG - TaskDeployer StartupTask Deployment from file : C:\MyApps\wso2esb-4.9.0\tmp\carbonapps\-1234\1469629535899ESBCDRCApp_1.0.0.car\UploadCDR2CDG_1.0.0\Upload2Vendor-1.0.0.xml : Completed
[2016-07-27 09:25:36,532] INFO - TaskDeployer StartupTask named 'Upload2Vendor' has been deployed from file : C:\MyApps\wso2esb-4.9.0\tmp\carbonapps\-1234\1469629535899ESBCDRCApp_1.0.0.car\UploadCDR2CDG_1.0.0\Upload2Vendor-1.0.0.xml
[2016-07-27 09:25:36,532] DEBUG - SynapseArtifactDeploymentStore Added deployment artifact with file : C:\MyApps\wso2esb-4.9.0\tmp\carbonapps\-1234\1469629535899ESBCDRCApp_1.0.0.car\UploadCDR2CDG_1.0.0\Upload2Vendor-1.0.0.xml
[2016-07-27 09:25:36,532] DEBUG - AbstractSynapseArtifactDeployer Deployment of the synapse artifact from file : C:\MyApps\wso2esb-4.9.0\tmp\carbonapps\-1234\1469629535899ESBCDRCApp_1.0.0.car\UploadCDR2CDG_1.0.0\Upload2Vendor-1.0.0.xml : COMPLETED
[2016-07-27 09:25:36,532] INFO - ApplicationManager Successfully Deployed Carbon Application : ESBCDRCApp_1.0.0 {super-tenant}
[2016-07-27 09:25:36,532] DEBUG - MessageInjector execute
[2016-07-27 09:25:36,532] DEBUG - Axis2SynapseEnvironment Creating Message Context
[2016-07-27 09:25:36,542] DEBUG - MessageInjector injecting message to sequence : SendFile2VendorSeq
[2016-07-27 09:25:36,542] DEBUG - Axis2SynapseEnvironment Injecting MessageContext for asynchronous mediation using the : SendFile2VendorSeq Sequence
[2016-07-27 09:25:36,552] DEBUG - SequenceMediator Start : Sequence <SendFile2VendorSeq>
[2016-07-27 09:25:36,552] DEBUG - SequenceMediator Sequence <SequenceMediator> :: mediate()
[2016-07-27 09:25:36,552] DEBUG - SequenceMediator Mediation started from mediator position : 0
[2016-07-27 09:25:36,552] DEBUG - SequenceMediator Building message. Sequence <SequenceMediator> is content aware
[2016-07-27 09:25:36,552] DEBUG - LogMediator Start : Log mediator
[2016-07-27 09:25:36,552] INFO - LogMediator To: , MessageID: urn:uuid:c620513a-5b90-452e-8133-d5fd23e2cce0, Direction: request, vendorId =
[2016-07-27 09:25:36,552] DEBUG - LogMediator End : Log mediator
[2016-07-27 09:25:36,552] DEBUG - DBLookupMediator Start : DBLookup mediator
[2016-07-27 09:25:36,582] DEBUG - DBLookupMediator Getting a connection from DataSource jdbc/CallOneCDRDB and preparing statement :
SELECT SELECT code, name FROM vendor WHERE id = ?
[2016-07-27 09:25:36,662] DEBUG - DBLookupMediator Setting as parameter : 1 value : null as JDBC Type : 4(see java.sql.Types for valid types)
[2016-07-27 09:25:36,662] DEBUG - DBLookupMediator Successfully prepared statement :
SELECT code, name FROM vendor WHERE id = ?
One option you can try is use org.apache.synapse.startup.tasks.TemplateMessageExecutor
as the task class. This class exposes two parameters :
1. templateParams
You can set the parameters here in an XML in some root element.
Example :
<root>
<user>John</user>
<age>10</age>
</root>
2. templateKey
You can set the key of sequence template that uses the above parameters here.
Example : gov:/sequenceTemplates/getUserSequenceTemplate
Sample Sequence Template
<template name="getUserSequenceTemplate" xmlns="http://ws.apache.org/ns/synapse">
<parameter name="user"/>
<parameter name="age"/>
<sequence>
<log level = "full">
<property name="User name is" expression={$func:user} />
<property name="User age is" expression={$func:age} />
</log>
</sequence>
</template>
There seems to be issue with namespace. I have updated the task and sequence as follow. This worked for me.
Task
<task class="org.apache.synapse.startup.tasks.MessageInjector" group="synapse.simple.quartz" name="UploadFile2Vendor1" xmlns="http://ws.apache.org/ns/synapse">
<trigger interval="15"/>
<property name="message" xmlns:task="http://www.wso2.org/products/wso2commons/tasks">
<request xmlns="" xmlns:m0="http://services.samples">
<vendorId>1</vendorId>
</request>
</property>
<property name="sequenceName" value="SendFile2VendorSeq" xmlns:task="http://www.wso2.org/products/wso2commons/tasks"/>
<property name="injectTo" value="sequence" xmlns:task="http://www.wso2.org/products/wso2commons/tasks"/>
</task>
Sequence
<?xml version="1.0" encoding="UTF-8"?>
<sequence xmlns="http://ws.apache.org/ns/synapse"
name="SendFile2VendorSeq"
trace="disable">
<log level="full"/>
<log>
<property xmlns:m0="http://services.samples"
name="vendorId"
expression="//vendorId"/>
</log>
</sequence>

Playframework 2.2.x + Java +JPA - Separate Database for Unit Testing and Production

I am using Java + Playframework + JPA using PlayFramework 2.3-M1 for developing application.
I want to use MySQL database when I run the aplication, but when I run test using
activator test
I want to use in memory database H2.
How can this be done ?
Below is my
conf/META-INF/persistence.xml
<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 name="prod" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<non-jta-data-source>prodDS</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 name="test" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<non-jta-data-source>TestDS</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="true"></property>
<property name="hibernate.format_sql" value="true"></property>
</properties>
</persistence-unit>
</persistence>
conf/application.conf
# Database configuration
# ~~~~~
# You can declare as many datasources as you want.
# By convention, the default datasource is named `default`
#
db.test.driver=org.h2.Driver
db.test.url="jdbc:h2:mem:play"
db.test.user=sa
db.test.password=""
db.test.jndiName=TestDS
jpa.test=testPersistenceUnit
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
# Ebean configuration
# ~~~~~
# You can declare as many Ebean servers as you want.
# By convention, the default server is named `default`
#
ebean.default="models.*"
Is this the best approach to get it done?
Thanks
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.