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.initialJUnit 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.