views:

536

answers:

1

I have a collection of integration tests that have been generated by Spring Roo for my domain objects (and DAO ITDs).

They appear to be fixed to use the "production" applicationContext.xml, which reads the database.properties and connects to the MySQL database schema I have set up for experimenting with the project:

privileged aspect AdvertIntegrationTest_Roo_IntegrationTest {

    declare @type: AdvertIntegrationTest: @RunWith
        (SpringJUnit4ClassRunner.class);    

    declare @type: AdvertIntegrationTest: @ContextConfiguration
        (locations = "classpath:/META-INF/spring/applicationContext.xml");   

The outcome of this is that my demo database is frequently populated with garbage by these tests.

I'd like to change the configuration so that the integration tests use an in-mem database, and leave the MySQL database well alone. At the moment, the only option that I can see is to remove the Roo annotations and manage these tests myself from now on, but I'd rather keep Roo in the loop at the moment.

Is it possible to configure my project, so the "mvn tomcat" and "mvn test" commands use separate databases, without breaking the Spring Roo set-up? Or perhaps there is a better approach for what I want to do?

+2  A: 

Sean,

I have struggled with the same thing. I ended up putting a copy of applicationContext.xml in test/resources/META-INF/spring and modifying the line below:

<context:property-placeholder location="classpath*:META-INF/spring/test/*.properties"/>

In that 'test' directory the property place holder points to, i have put another database.properties which configures hsqldb.

Finally, I had to have a different copy of persistence.xml which configures the SQL Dialect (also in applicationContext.xml)

<bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="entityManagerFactory">
    <property name="persistenceXmlLocation" value="classpath:META-INF/persistence-for-tests.xml"/>
    <property name="dataSource" ref="dataSource"/>
</bean>

I suppose that a more elegant solution through use of pom.xml magic is possible, but for now this seemed like an acceptable solution to me.

Hans

Hans Westerbeek
i voted for the jira issue as well :)
Hans Westerbeek
This is very useful, thanks! how did you instruct the Roo tests to use the "test" applicationContext.xml? Did you modify the generated AJ files?
seanhodges
no i did not modify any aj files, this is not required and also not recommended since they are created/managed exclusively by roo.Roo defers test execution to maven. maven will simply pick up the configuration files that live in test/resources and thus are on the classpath.
Hans Westerbeek