I'm developing an application with JPA 2, Spring and JSF 2 running in WildFly 8.0.0. I have already developed some previous applications following the same specification but never tested properly using jUnit. Now, I would like to change that and test more.
As I am very early in development and already want to test the application, came the first problem. How do I test my application with it running out of a container ? I say this because the datasource of my application is managed by the container. So, being outside of it I do not have a datasource .
I thought of assigning the responsibility of managing the datasource for Spring when I'm running the tests, but that implies new configuration files when I'm running the tests. More configuration files means more future maintenance. I would like to avoid this scenario, but if there is no other way ...
Concluding and leaving the question, is there any way to unitarily test the application outside of a container with respect to datasource access?
EDIT: Adding some information that may be needed for the response:
My datasource ( minhaapp-ds.xml
):
<?xml version="1.0" encoding="UTF-8"?>
<datasources xmlns="http://www.jboss.org/ironjacamar/schema">
<datasource jta="false" jndi-name="java:/datasource/minhaappds" pool-name="minhaAppDS" enabled="true" use-ccm="false">
<connection-url>jdbc:oracle:thin:@etc:0000</connection-url>
<driver-class>oracle.jdbc.OracleDriver</driver-class>
<driver>ojdbc6.jar</driver>
<pool>
<min-pool-size>1</min-pool-size>
<max-pool-size>15</max-pool-size>
</pool>
<security>
<user-name>minha_app</user-name>
<password>minha_app</password>
</security>
<validation>
<validate-on-match>false</validate-on-match>
<background-validation>false</background-validation>
</validation>
<timeout>
<idle-timeout-minutes>5</idle-timeout-minutes>
</timeout>
<statement>
<share-prepared-statements>false</share-prepared-statements>
</statement>
</datasource>
</datasources>
My persistence.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="minhaAppPU" transaction-type="JTA">
<jta-data-source>java:/datasource/minhaappds</jta-data-source>
<class>br.com.cpy.model.Classe1</class>
<class>br.com.cpy.model.Classe2</class>
<class>br.com.cpy.model.Classe3</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
<property name="hibernate.show_sql" value="false"/>
<property name="jboss.entity.manager.factory.jndi.name" value="java:jboss/minhaappEMF" />
</properties>
</persistence-unit>
</persistence>
And finally, spring-persistence-context.xml
<jee:jndi-lookup jndi-name="java:jboss/minhaappEMF" id="entityManagerFactory" expected-type="javax.persistence.EntityManagerFactory" />
<tx:jta-transaction-manager />
<tx:annotation-driven />