如何针对不同的数据库运行Spring Roo生成的测试到Tomcat?

sea*_*ges 6 spring integration-testing hibernate spring-roo

我有一组由Spring Roo为我的域对象(和DAO ITD)生成的集成测试.

它们似乎已被修复以使用"production"applicationContext.xml,它读取database.properties并连接到我为实验项目设置的MySQL数据库模式:

privileged aspect AdvertIntegrationTest_Roo_IntegrationTest {

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

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

结果是我的演示数据库经常被这些测试填充垃圾.

我想更改配置,以便集成测试使用内存数据库,并使MySQL数据库保持独立.目前,我能看到的唯一选择是从现在开始删除Roo注释并自行管理这些测试,但我现在宁愿让Roo保持在循环中.

是否可以配置我的项目,因此"mvn tomcat"和"mvn test"命令使用单独的数据库,而不会破坏Spring Roo设置?或许对我想做的事情有更好的方法?

Han*_*eek 6

肖恩,

我一直在努力做同样的事情.我最终在test/resources/META-INF/spring中添加了applicationContext.xml的副本并修改了以下行:

<context:property-placeholder location="classpath*:META-INF/spring/test/*.properties"/>
Run Code Online (Sandbox Code Playgroud)

在属性占位符指向的'test'目录中,我已经放置了另一个配置hsqldb的database.properties.

最后,我必须有一个不同的persistence.xml副本来配置SQL Dialect(也在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>
Run Code Online (Sandbox Code Playgroud)

我想通过使用pom.xml魔法可以实现更优雅的解决方案,但是现在这对我来说似乎是一个可以接受的解决方案.

汉斯