cancel
Showing results for 
Search instead for 
Did you mean: 

How to deploy JNDI references programmatically?

kaihuener
Champ in-the-making
Champ in-the-making
Hey all,

I recently changed from Tomcat to JBoss application server (version 7.1.1).
According to several documentation (e.g. http://www.mastertheboss.com/activiti-bpmn/activiti-bpmn-on-jboss-as-7) I adapted
activiti.cfg.xml
in order to use CDI and JNDI references:
<bean id="transactionManager" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="java:jboss/TransactionManager"></property>
    <property name="resourceRef" value="true" />
</bean>
<bean id="processEngineConfiguration" class="org.activiti.cdi.CdiJtaProcessEngineConfiguration">
    <property name="dataSourceJndiName" value="java:/jboss/datasources/activiti" />
    <property name="databaseType" value="mysql" />
    <property name="transactionManager" ref="transactionManager" />
    <property name="transactionsExternallyManaged" value="true" />
    <property name="databaseSchemaUpdate" value="true" />
</bean>


When I try to deploy the bar archive including the new configuration, I get an exception regarding missing initial context:
Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial

I try to deploy by maven (see e.g. http://forums.activiti.org/content/create-and-deploy-par-using-maven-only) using class
DeployBarTask
from old
org.activiti.engine.impl.ant
namespace (activiti 5.10). Beside for deployment, I use new (5.14) activiti libs.

I fully understand the exception because outside the JBoss container, there is no initial context with JNDI resources. For example, for unit testing, I use mocked databases in a manually created context to simulate JNDI references. But I have absolutely no idea how to simulate or somehow mock the activiti database and JBoss transaction manager during bar deployment …

Sorry for this lengthy opening– my question: How to programmatically (best case: maven) deploy a bar archive including JNDI references? Is there a way or "good practice" to somehow add a database mock class to the bar archive that is only used during deployment? And how to deal with the JNDI reference for the transaction manager?

Thanks in advance for any ideas,
best regards,
kai
3 REPLIES 3

frederikherema1
Star Contributor
Star Contributor
Is it possible to use an alternative acitviti-context for testing? Try separating the process-engine only configuration out and keeping the shared (eg. beans, customisations, services, …) separate. This way, you can test using a standalone H2 DB, out of the container, but still exposing all bits needed in order to make the process work.

kaihuener
Champ in-the-making
Champ in-the-making
Frederik, thank you for this simple but effective hint!
Just putting a simplified copy into maven's test/resources folder works, of course.
Thank you and best regards,
kai

frederikherema1
Star Contributor
Star Contributor
This also allows you to mock out (or replace) any beans you use in the processes for easy testing of the process itself…