cancel
Showing results for 
Search instead for 
Did you mean: 

PropertyPlaceholderConfigurer properties not being substituted in unit test

osganian
Champ in-the-making
Champ in-the-making
I'm new to Activiti and I have a simple unit test that is something like:

<java>
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:activiti-context.xml", "classpath:test-spring.xml" })
public class SimpleTest {
    /** JUnit test rule to give us access to Activiti services. */
    @Rule
    public ActivitiRule activitiRule = new ActivitiRule("activiti-context.xml");

    @Test
    @Deployment(resources = {"test-process.bpmn20.xml"})
    public void testIt() {
         …
    }
}
<java>

My activiti-context.xml looks like this:


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context-3.0.xsd
            http://www.springframework.org/schema/tx
            http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
    <!– Activates various annotations to be detected in bean classes –>
    <context:annotation-config />

    <!– Loads properties as spring based properties, things like database
         urls, etc. –>
    <bean id="dbProperties"
          class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="ignoreUnresolvablePlaceholders" value="true"/>
        <property name="location" value="classpath:activiti-context.properties" />
    </bean>

    <!–
         DataSource and EntityManager configurations
      –>
    <bean id="activitiDataSource"
          class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="${database.activiti.driverClassName}"/>
        <property name="url" value="${database.activiti.url}"/>
        <property name="username" value="${database.activiti.username}"/>
        <property name="password" value="${database.activiti.password}"/>
        <property name="validationQuery" value="${database.activiti.validation-query}"/>
        <!– check for idle connections every 10 mins –>
        <property name="timeBetweenEvictionRunsMillis" value="60000" />
        <!– setting -1 will make it check all idle connections–>
        <property name="numTestsPerEvictionRun" value="-1" />
        <!– close connections if they are idle for 10 mins –>
        <property name="minEvictableIdleTimeMillis" value="60000" />
    </bean>

    <!–
         Start of Activiti configurations
      –>

    <bean id="transactionManager"
          class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="activitiDataSource" />
    </bean>

    <bean id="processEngineConfiguration"
          class="org.activiti.spring..SpringProcessEngineConfiguration">
        <!– Common configuration properties –>
        <property name="history" value="audit" />
        <property name="jobExecutorActivate" value="true" />

        <!– Database configuration properties –>
        <!– Will create the Activiti tables if they are not present or if they
             are present will update them accordingly. –>
        <property name="dataSource" ref="activitiDataSource" />
        <property name="databaseSchemaUpdate" value="true" />

        <!– –>
        <property name="transactionManager" ref="transactionManager" />

        <!– JPA configuration properties –>
        <property name="jpaHandleTransaction" value="true" />
        <property name="jpaCloseEntityManager" value="true" />
    </bean>

    <!– –>
    <bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
        <property name="processEngineConfiguration" ref="processEngineConfiguration" />
    </bean>

    <!– The Activiti suite of services used within the processing engine. –>
    <bean id="repositoryService" factory-bean="processEngine"
          factory-method="getRepositoryService" />
    <bean id="runtimeService" factory-bean="processEngine"
          factory-method="getRuntimeService" />
    <bean id="taskService" factory-bean="processEngine"
          factory-method="getTaskService" />
    <bean id="historyService" factory-bean="processEngine"
          factory-method="getHistoryService" />
    <bean id="managementService" factory-bean="processEngine"
          factory-method="getManagementService" />
</beans>


And my activiti-context.properties where I put my database properties are:


database.activiti.url=jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000
database.activiti.driverClassName=org.h2.Driver
database.activiti.username=sa
database.activiti.password=
database.activiti.validation-query=SELECT 1 FROM DUAL


But when I run my unit test it looks like my database properties are not being evaluated:


12:03:56,801 [main] DEBUG org.springframework.jdbc.datasource.DataSourceUtils  - Fetching JDBC Connection from DataSourc
e
12:03:56,802 [main] ERROR org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl  - Exception while initializing Da
tabase connection
org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class '${database.activiti.driverClassName}'
        at org.apache.commons.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1429)
        at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
        at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
        at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
        at org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy$TransactionAwareInvocationHandler.invoke(
TransactionAwareDataSourceProxy.java:224)
        at $Proxy10.getMetaData(Unknown Source)
        at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.initDatabaseType(ProcessEngineConfigurationImpl.j
ava:654)
        at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.initDataSource(ProcessEngineConfigurationImpl.jav
a:607)
        at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.init(ProcessEngineConfigurationImpl.java:440)
        at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.buildProcessEngine(ProcessEngineConfigurationImpl
.java:412)
        at org.activiti.spring.SpringProcessEngineConfiguration.buildProcessEngine(SpringProcessEngineConfiguration.java
:65)
        at org.activiti.engine.impl.test.TestHelper.getProcessEngine(TestHelper.java:227)
        at org.activiti.engine.test.ActivitiRule.initializeProcessEngine(ActivitiRule.java:237)
        at org.activiti.engine.test.ActivitiRule.starting(ActivitiRule.java:205)
        at org.activiti.engine.test.ActivitiRule.startingQuietly(ActivitiRule.java:171)
        at org.activiti.engine.test.ActivitiRule.access$000(ActivitiRule.java:86)
        at org.activiti.engine.test.ActivitiRule$1.evaluate(ActivitiRule.java:124)
        at org.junit.rules.RunRules.evaluate(RunRules.java:20)
        at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodC
allbacks.java:74)
        at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCal
lbacks.java:82)
        at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
        at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCal
lbacks.java:61)
        at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallb
acks.java:70)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)
        at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
        at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
        at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
        at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
        at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
        at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
        at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
Caused by: java.lang.ClassNotFoundException: ${database.activiti.driverClassName}
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
        at org.apache.commons.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1420)
        … 43 more

Anybody have any idea what I might be doing wrong?

Thanks for any help,
Mike
3 REPLIES 3

jbarrez
Star Contributor
Star Contributor
Can you share your test project in a zip?

The config looks ok from a quick look.
Where is the properties file located?

osganian
Champ in-the-making
Champ in-the-making
Thanks for the reply.  So I have gotten a little further.  Seems I have 2 PropertyPlaceholderConfigurer beans defined in my spring xml.  I have 1 spring xml that defines one and another that gets included that defines another one.  So I had to specify a placeholderPrefix & placeholderSuffix for one of them so they don't conflict.  The reason I have 2 is because one is a test spring xml that defines some test properties.  However I am still getting a similar error that is occurring in my test case's use of ActivitiTestCase.

I tried to attach my entire maven test case as a zip but I get this error uploading it on this forum:

"The selected file activiti-test.zip cannot be uploaded. Only files with the following extensions are allowed: txt."

So I have uploaded them separately with a .txt extension.

Below is the stack trace when I run my simple junit test:

<code>
[INFO] Scanning for projects…
[INFO]
[INFO] ————————————————————————
[INFO] Building activiti 1.0.0
[INFO] ————————————————————————
[INFO]
[INFO] — maven-clean-plugin:2.4.1:clean (default-clean) @ activiti —
[INFO] Deleting C:\code\Temp\test2\activiti\target
[INFO]
[INFO] — maven-resources-plugin:2.5:resources (default-resources) @ activiti —
[debug] execute contextualize
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 3 resources
[INFO]
[INFO] — maven-compiler-plugin:2.3.2:compile (default-compile) @ activiti —
[INFO] No sources to compile
[INFO]
[INFO] — maven-resources-plugin:2.5:testResources (default-testResources) @ activiti —
[debug] execute contextualize
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 3 resources
[INFO]
[INFO] — maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ activiti —
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 2 source files to C:\code\Temp\test2\activiti\target\test-classes
[INFO]
[INFO] — maven-surefire-plugin:2.10:test (default-test) @ activiti —
[INFO] Surefire report directory: C:\code\Temp\test2\activiti\target\surefire-reports

——————————————————-
T E S T S
——————————————————-
Running com.test.activiti.SimpleTest
07:29:29,878 [main] INFO  org.springframework.test.context.TestContextManager  - @TestExecutionListeners is not present
for class [class com.test.activiti.SimpleTest]: using defaults.
07:29:29,947 [main] INFO  org.springframework.beans.factory.xml.XmlBeanDefinitionReader  - Loading XML bean definitions
from class path resource [test-spring.xml]
07:29:30,045 [main] INFO  org.springframework.beans.factory.xml.XmlBeanDefinitionReader  - Loading XML bean definitions
from class path resource [activiti-spring.xml]
07:29:30,146 [main] INFO  org.springframework.context.support.GenericApplicationContext  - Refreshing org.springframewor
k.context.support.GenericApplicationContext@175093f1: startup date [Wed Apr 29 07:29:30 EDT 2015]; root of context hiera
rchy
07:29:30,223 [main] INFO  org.springframework.beans.factory.config.PropertyPlaceholderConfigurer  - Loading properties f
ile from URL [file:target/test-classes/test.properties]
07:29:30,226 [main] INFO  org.springframework.beans.factory.config.PropertyPlaceholderConfigurer  - Loading properties f
ile from class path resource [activiti-spring.properties]
07:29:30,241 [main] INFO  org.springframework.beans.factory.support.DefaultListableBeanFactory  - Pre-instantiating sing
letons in org.springframework.beans.factory.support.DefaultListableBeanFactory@bb273cc: defining beans [activitiSpringTe
stProperties,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context
.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProces
sor,org.springframework.context.annotation.internalCommonAnnotationProcessor,activitiSpringProperties,activitiDataSource
,activitiTransactionManager,processEngineConfiguration,processEngine,repositoryService,runtimeService,taskService,histor
yService,managementService]; root of factory hierarchy
07:29:31,608 [main] INFO  org.activiti.engine.impl.db.DbSqlSession  - performing create on engine with resource org/acti
viti/db/create/activiti.h2.create.engine.sql
07:29:31,649 [main] INFO  org.activiti.engine.impl.db.DbSqlSession  - performing create on history with resource org/act
iviti/db/create/activiti.h2.create.history.sql
07:29:31,657 [main] INFO  org.activiti.engine.impl.db.DbSqlSession  - performing create on identity with resource org/ac
tiviti/db/create/activiti.h2.create.identity.sql
07:29:31,660 [main] INFO  org.activiti.engine.impl.ProcessEngineImpl  - ProcessEngine default created
07:29:31,661 [main] INFO  org.activiti.engine.impl.jobexecutor.JobExecutor  - Starting up the JobExecutor[org.activiti.e
ngine.impl.jobexecutor.DefaultJobExecutor].
07:29:31,664 [Thread-4] INFO  org.activiti.engine.impl.jobexecutor.AcquireJobsRunnableImpl  - JobExecutor[org.activiti.e
ngine.impl.jobexecutor.DefaultJobExecutor] starting to acquire jobs
07:29:31,697 [main] INFO  org.springframework.beans.factory.xml.XmlBeanDefinitionReader  - Loading XML bean definitions
from class path resource [activiti-spring.xml]
07:29:31,729 [main] ERROR org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl  - Exception while initializing Da
tabase connection
org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class '!abc{database.activiti.driverClassName}'
        at org.apache.commons.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1429)
        at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
        at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
        at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
        at org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy$TransactionAwareInvocationHandler.invoke(
TransactionAwareDataSourceProxy.java:224)
        at $Proxy12.getMetaData(Unknown Source)
        at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.initDatabaseType(ProcessEngineConfigurationImpl.j
ava:654)
        at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.initDataSource(ProcessEngineConfigurationImpl.jav
a:607)
        at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.init(ProcessEngineConfigurationImpl.java:440)
        at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.buildProcessEngine(ProcessEngineConfigurationImpl
.java:412)
        at org.activiti.spring.SpringProcessEngineConfiguration.buildProcessEngine(SpringProcessEngineConfiguration.java
:65)
        at org.activiti.engine.impl.test.TestHelper.getProcessEngine(TestHelper.java:227)
        at org.activiti.engine.test.ActivitiTestCase.initializeProcessEngine(ActivitiTestCase.java:112)
        at org.activiti.engine.test.ActivitiTestCase.setUp(ActivitiTestCase.java:84)
        at com.test.activiti.BaseTestCase.setUp(BaseTestCase.java:30)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
        at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
        at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodC
allbacks.java:74)
        at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
        at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCal
lbacks.java:82)
        at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
        at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCal
lbacks.java:61)
        at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallb
acks.java:70)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)
        at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
        at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
        at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
        at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
        at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
        at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
        at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)
Caused by: java.lang.ClassNotFoundException: !abc{database.activiti.driverClassName}
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
        at org.apache.commons.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1420)
        … 49 more
Cannot load JDBC driver class '!abc{database.activiti.driverClassName}'
java.lang.ClassNotFoundException: !abc{database.activiti.driverClassName}
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
        at org.apache.commons.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1420)
        at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
        at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
        at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
        at org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy$TransactionAwareInvocationHandler.invoke(
TransactionAwareDataSourceProxy.java:224)
        at $Proxy12.getMetaData(Unknown Source)
        at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.initDatabaseType(ProcessEngineConfigurationImpl.j
ava:654)
        at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.initDataSource(ProcessEngineConfigurationImpl.jav
a:607)
        at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.init(ProcessEngineConfigurationImpl.java:440)
        at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.buildProcessEngine(ProcessEngineConfigurationImpl
.java:412)
        at org.activiti.spring.SpringProcessEngineConfiguration.buildProcessEngine(SpringProcessEngineConfiguration.java
:65)
        at org.activiti.engine.impl.test.TestHelper.getProcessEngine(TestHelper.java:227)
        at org.activiti.engine.test.ActivitiTestCase.initializeProcessEngine(ActivitiTestCase.java:112)
        at org.activiti.engine.test.ActivitiTestCase.setUp(ActivitiTestCase.java:84)
        at com.test.activiti.BaseTestCase.setUp(BaseTestCase.java:30)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
        at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
        at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodC
allbacks.java:74)
        at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
        at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCal
lbacks.java:82)
        at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
        at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCal
lbacks.java:61)
        at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallb
acks.java:70)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)
        at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
        at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
        at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
        at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
        at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
        at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
        at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)
Cannot load JDBC driver class '!abc{database.activiti.driverClassName}'
java.lang.ClassNotFoundException: !abc{database.activiti.driverClassName}
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
        at org.apache.commons.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1420)
        at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
        at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
        at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
        at org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy$TransactionAwareInvocationHandler.invoke(
TransactionAwareDataSourceProxy.java:224)
        at $Proxy12.getMetaData(Unknown Source)
        at org.activiti.engine.impl.db.DbSqlSession.isTablePresent(DbSqlSession.java:1076)
        at org.activiti.engine.impl.db.DbSqlSession.isEngineTablePresent(DbSqlSession.java:1057)
        at org.activiti.engine.impl.db.DbSqlSession.dbSchemaUpdate(DbSqlSession.java:990)
        at org.activiti.engine.impl.db.DbSqlSession.performSchemaOperationsProcessEngineBuild(DbSqlSession.java:1385)
        at org.activiti.engine.impl.SchemaOperationsProcessEngineBuild.execute(SchemaOperationsProcessEngineBuild.java:2
5)
        at org.activiti.engine.impl.interceptor.CommandInvoker.execute(CommandInvoker.java:24)
        at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:57)
        at org.activiti.spring.SpringTransactionInterceptor$1.doInTransaction(SpringTransactionInterceptor.java:47)
        at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:130)
        at org.activiti.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:45)
        at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:31)
        at org.activiti.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:40)
        at org.activiti.engine.impl.ProcessEngineImpl.<init>(ProcessEngineImpl.java:77)
        at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.buildProcessEngine(ProcessEngineConfigurationImpl
.java:413)
        at org.activiti.spring.SpringProcessEngineConfiguration.buildProcessEngine(SpringProcessEngineConfiguration.java
:65)
        at org.activiti.engine.impl.test.TestHelper.getProcessEngine(TestHelper.java:227)
        at org.activiti.engine.test.ActivitiTestCase.initializeProcessEngine(ActivitiTestCase.java:112)
        at org.activiti.engine.test.ActivitiTestCase.setUp(ActivitiTestCase.java:84)
        at com.test.activiti.BaseTestCase.setUp(BaseTestCase.java:30)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect07:29:32,232 [main] ERROR org.activiti.engine.impl.interceptor.CommandContext  - masked exception
in command context. for root cause, see below as it will be rethrown later.
org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested
exception is org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class '!abc{database.activiti.driverCl
assName}'
        at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:24
0)
        at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTra
nsactionManager.java:371)
        at org.activiti.spring.SpringTransactionContext.rollback(SpringTransactionContext.java:60)
        at org.activiti.engine.impl.interceptor.CommandContext.close(CommandContext.java:173)
        at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:66)
        at org.activiti.spring.SpringTransactionInterceptor$1.doInTransaction(SpringTransactionInterceptor.java:47)
        at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:130)
        at org.activiti.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:45)
        at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:31)
        at org.activiti.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:40)
        at org.activiti.engine.impl.ProcessEngineImpl.<init>(ProcessEngineImpl.java:77)
        at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.buildProcessEngine(ProcessEngineConfigurationImpl
.java:413)
        at org.activiti.spring.SpringProcessEngineConfiguration.buildProcessEngine(SpringProcessEngineConfiguration.java
:65)
        at org.activiti.engine.impl.test.TestHelper.getProcessEngine(TestHelper.java:227)
        at org.activiti.engine.test.ActivitiTestCase.initializeProcessEngine(ActivitiTestCase.java:112)
        at org.activiti.engine.test.ActivitiTestCase.setUp(ActivitiTestCase.java:84)
        at com.test.activiti.BaseTestCase.setUp(BaseTestCase.java:30)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
        at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
        at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodC
allbacks.java:74)
        at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
        at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCal
lbacks.java:82)
        at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
        at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCal
lbacks.java:61)
        at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallb
acks.java:70)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)
        at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
        at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
        at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
        at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
        at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
        at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
        at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)
Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class '!abc{database.activiti.driverClass
Name}'
        at org.apache.commons.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1429)
        at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
        at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
        at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:20
2)
        … 51 more
Caused by: java.lang.ClassNotFoundException: !abc{database.activiti.driverClassName}
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
        at org.apache.commons.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1420)
        … 54 more
Tests run: 2, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 2.575 sec <<< FAILURE!
07:29:32,241 [Thread-5] INFO  org.springframework.context.support.GenericApplicationContext  - Closing org.springframewo
rk.context.support.GenericApplicationContext@175093f1: startup date [Wed Apr 29 07:29:30 EDT 2015]; root of context hier
archy
07:29:32,242 [Thread-5] INFO  org.springframework.beans.factory.support.DefaultListableBeanFactory  - Destroying singlet
ons in org.springframework.beans.factory.support.DefaultListableBeanFactory@bb273cc: defining beans [activitiSpringTestP
roperties,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.an
notation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor
,org.springframework.context.annotation.internalCommonAnnotationProcessor,activitiSpringProperties,activitiDataSource,ac
tivitiTransactionManager,processEngineConfiguration,processEngine,repositoryService,runtimeService,taskService,historySe
rvice,managementService]; root of factory hierarchy
07:29:32,243 [Thread-5] INFO  org.activiti.engine.impl.jobexecutor.JobExecutor  - Shutting down the JobExecutor[org.acti
viti.engine.impl.jobexecutor.DefaultJobExecutor].
07:29:32,243 [Thread-4] INFO  org.activiti.engine.impl.jobexecutor.AcquireJobsRunnableImpl  - JobExecutor[org.activiti.e
ngine.impl.jobexecutor.DefaultJobExecutor] stopped job acquisition

Results :

Tests in error:
  testIt(com.test.activiti.SimpleTest): couldn't check if tables are already present using metadata: Cannot load JDBC dr
iver class '!abc{database.activiti.driverClassName}'
  testIt(com.test.activiti.SimpleTest)

Tests run: 2, Failures: 0, Errors: 2, Skipped: 0

[INFO] ————————————————————————
[INFO] BUILD FAILURE
[INFO] ————————————————————————
[INFO] Total time: 5.103s
[INFO] Finished at: Wed Apr 29 07:29:32 EDT 2015
[INFO] Final Memory: 14M/220M
[INFO] ————————————————————————
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.10:test (default-test) on project activi
ti: There are test failures.
[ERROR]
[ERROR] Please refer to C:\code\Temp\test2\activiti\target\surefire-reports for the individual test results.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
</code>

As you can see the @ContextConfiguration annotation on the junit  test case doesn't have a beef with my spring xml but it seems the ActivitiTestCase does and cannot locate those properties.

jbarrez
Star Contributor
Star Contributor
Okay, so  first of all Spring expressions should be of the form ${} not {}.

Secondly, you are mixing two things: you are referencing the spring xml file in the ActivitiRule and again in the annotation at the top of your test class. This won't work.

You need to remove the ActivitiRule and Inject (@AutoWired) the ProcessEngine in the test class.