I have this in my pom.xml:
<build>
<finalName>${project.artifactId}</finalName>
<filters>
<filter>${project.basedir}/src/main/resources/filters/${env}.properties</filter>
</filters>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<testResources>
<testResource>
<directory>${project.basedir}/src/test/resources</directory>
<filtering>true</filtering>
</testResource>
</testResources>
</build>
...
<profiles>
<profile>
<id>dev</id>
<properties>
<env>dev</env>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>qa</id>
<properties>
<env>qa</env>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<env>prod</env>
</properties>
</profile>
</profiles>
and I have these files in src/main/resources/filters: dev.properties, qa.properties and prod.properties.
But my spring config test-db-config.xml in src/test/resource is not picking up the values I have in the properties file:
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName">
<value>${db.driver}</value>
</property>
<property name="url">
<value>${db.url}</value>
</property>
<property name="username">
<value>${db.usename}</value>
</property>
<property name="password">
<value>${db.password}</value>
</property>
</bean>
Could someone point me in the right direction? Thanks
This is the error I am getting:
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 2.185 sec <<< FAILURE!
testCustomerExists(com.xxxx.hcs.persistence.repository.CustomerRepositoryTest) Time elapsed: 1.973 sec <<< ERROR!
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:99)
at org.springframework.test.context.DefaultTestContext.getApplicationContext(DefaultTestContext.java:101)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
...
In dev.properties I have:
db.driver=oracle.jdbc.OracleDriver
db.url=jdbc:oracle:thin:@hrsdev.xxxx.net:1548:yyyy
db.usedb.passwordrname=xxxx
db.password=yyyy
When I put these values in test-db-config.xml, the test cases run fine. So I know it is caused by the variable substitution.