在嵌入式Tomee中使用Arquillian进行测试:如何删除HSQL数据源?

时间:2017-12-05 19:04:33

标签: java jboss-arquillian tomee

我正在尝试使用嵌入式Tomee测试具有Arquillian持久性的会话bean。但是Tomee尝试连接到其默认的HSQLDB数据源。

AFAIK,我应该指示Tomee使用tomee.xml来评论HSQLDB数据源。

如何使用arquillian.xml执行此操作?还是有另一种方式?

我的部署方法:

    @Deployment
public static WebArchive createTestArchive() {
    MavenResolverSystem resolver = Maven.resolver();  
    File[] files = resolver.loadPomFromFile("pom.xml").importRuntimeDependencies().resolve().withTransitivity().asFile();  

    for (File f : files) {
        System.out.println(f.getPath());
    }

    return ShrinkWrap.create(WebArchive.class)
            .addClasses(MyBean.class)
            .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
            .addAsManifestResource("persistence.xml", "persistence.xml")
            .addAsLibraries(files);
}

我的persistence.xml:

    <persistence-unit name="oracle">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <properties>
        <property name="hibernate.archive.autodetection" value="class" />
        <property name="hibernate.dialect"
            value="org.hibernate.dialect.OracleDialect"/>
        <property name="hibernate.connection.driver_class" value="oracle.jdbc.driver.OracleDriver" />
        <property name="hibernate.connection.url" value="jdbc:oracle:thin:@localhost:1521:ORADB" />
        <property name="hibernate.connection.username" value="gk2" />
        <property name="hibernate.connection.password" value="qwerty" />
        <!-- <property name="hibernate.show_sql" value="true"/> -->
        <property name="hibernate.flushMode" value="FLUSH_AUTO" />
        <property name="hibernate.hbm2ddl.auto" value="validate" />
    </properties>
</persistence-unit>

我的arquillian.xml:

<container qualifier="tomee" default="true">
    <configuration>
        <property name="httpPort">-1</property>
        <property name="stopPort">-1</property>
        <!--Optional Container Properties -->
        <property name="properties">
        </property>
    </configuration>
</container>

1 个答案:

答案 0 :(得分:0)

我找到了问题。

应在arquillian.xml中配置数据源:

        <property name="properties">
            oracle = new://Resource?type=DataSource
            oracle.JdbcUrl = jdbc:oracle:thin:@localhost:1521:ORADB
            oracle.JdbcDriver = oracle.jdbc.driver.OracleDriver
            oracle.UserName = username
            oracle.Password = password              
            ...
        </property>