cancel
Showing results for 
Search instead for 
Did you mean: 

Integration Test: Standalone & App Server Datasource conflict -help

rangoo
Champ in-the-making
Champ in-the-making
Using JUnit for Integration testing I am trying to kick-off workflows which are already deployed on the application server. I have a HumanTask with a custom ExecutionListener. ExecutionListener loads SpringApplicationContext to make a JDBC call (using JdbcDaoSupport)  via ActivitDS datasource like this:

<jee:jndi-lookup id="dataSource" jndi-name="jdbc/ActivitiDS" expected-type="org.activiti.spring.SpringProcessEngineConfiguration" />




In my Integ test I am using a standalone datasource, which points to the same database as the server's datasource.

  <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
       <property name="driverClassName" value="${jdbc.driver}" />
       <property name="url" value="${jdbc.url}" />
       <property name="username" value="${jdbc.username}" />
       <property name="password" value="${jdbc.password}" />
       <property name="defaultAutoCommit" value="true" />
     </bean>


Unit Test

public class WorkflowTest {

   
    @Rule
     public ActivitiRule activitiRule = new ActivitiRule();

     @Test
   public void test() {
   // Start
      RuntimeService runtimeService = activitiRule.getRuntimeService();
      Map<String, Object> variableMap = new HashMap<String, Object>();
………………………
      ProcessInstance processInstance = runtimeService
            .startProcessInstanceByKey("MyProcess", variableMap);




After starting the Test, when the execution comes to ExecutionListener - I get a datasource init exception :

Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Invocation of init method failed; nested exception is 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

JUnit test uses the same Spring Context (incl datasource) thro its lifecycle, it perhaps is not able to create another datasource at ExecutionListner? I know I can mock the behaviour of the ExecutionListener, but since this being an Integ Test I have to get actual data in my ExecutionListener .
Any ideas are welcome.
2 REPLIES 2

rangoo
Champ in-the-making
Champ in-the-making
Looks like JNDI look up is the issue.

To give a little more perspective - I am using Custom Jars(for ExecutionListeners) and  I am placing them inside activiti-explorer lib. Now  for some reason JNDI look-up for Datasource from Custom jar is failing .  I have the same datasource working perfectly in a Webapp .

Is it because Look-up is from a JAR inside another webapp(explorer)? If so can I somehow re-use the Datasource of  activiti-explorer ?

trademak
Star Contributor
Star Contributor
It's definitely a JNDI lookup exception. Are you sure you have all necessary dependencies on the classpath to do a JNDI lookup and don't you need more configuration like server + port for the JNDI lookup?