EJB3Unit testing no-tx-datasource
- by justastefan
Hello, I am doing tests on an ejb3-project using ejb3unit http://ejb3unit.sourceforge.net/Session-Bean.html for testing. All my Services long for @PersistenceContext (UnitName=bla). I set up the ejb3unit.properties like this:
ejb3unit_jndi.1.isSessionBean=true
ejb3unit_jndi.1.jndiName=ejb/MyServiceBean
ejb3unit_jndi.1.className=com.company.project.MyServiceBean
everything works with the in-memory-database.
So now i want additionally test another servicebean with @PersistenceContext (UnitName=noTxDatasource) that goes for a defined in my datasources.xml:
<datasources>
<local-tx-datasource>
...
</local-tx-datasource>
<no-tx-datasource>
<jndi-name>noTxDatasource</jndi-name>
<connection-url>...</connection-url>
<driver-class>oracle.jdbc.OracleDriver</driver-class>
<user-name>bla</user-name>
<password>bla</password>
</no-tx-datasource>
</datasources>
How do I tell ejb3unit to make this work:
Object object = InitialContext.doLookup("java:/noTxDatasource");
if (object instanceof DataSource) {
return ((DataSource) object).getConnection();
} else {
return null;
}
Currently it fails saying: javax.NamingException: Cannot find the name (noTxDataSource) in the JNDI tree Current bindings: (ejb/MyServiceBean=com.company.project.MyServiceBean)
How can I add this no-tx-datasource to the jndi bindings?