首页 > 解决方案 > 如何使用 OpenJPA Maven 插件进行测试

问题描述

我需要进行集成测试以检查多线程持久性到 Oracle。我们在应用程序中使用 openjpa,所以我决定使用openjpa-maven-plugin进行测试。

我试图准备一些配置文件来测试

<profiles>
    <profile>
        <id>integration-test</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.openjpa</groupId>
                    <artifactId>openjpa-maven-plugin</artifactId>
                    <version>${openjpa.version}</version>
                    <configuration>
                        <sqlAction>build</sqlAction>
                        <sqlFile>/src/test/resources/sql/insert.sql</sqlFile>
                        <connectionDriverName>org.apache.commons.dbcp.BasicDataSource</connectionDriverName>
                        <connectionProperties>
                            driverClass=oracle.jdbc.OracleDriver,
                            jdbc.url=jdbc:oracle:thin:@server-test-ora:1521/bacl,
                            user=user,
                            password=root,
                            minPoolSize=5,
                            acquireRetryAttempts=3,
                            maxPoolSize=20
                        </connectionProperties>
                        <includes>**/entities/*.class</includes>
                        <addDefaultConstructor>true</addDefaultConstructor>
                       <enforcePropertyRestrictions>true</enforcePropertyRestrictions>
                    </configuration>
                    <executions>
                        <execution>
                            <id>test enhancer</id>
                            <phase>process-test-classes</phase>
                            <goals>
                                <goal>test-enhance</goal>
                            </goals>
                        </execution>
                    </executions>

                    <dependencies>
                        <dependency>
                            <groupId>org.apache.openjpa</groupId>
                            <artifactId>openjpa</artifactId>
                            <version>${openjpa.version}</version>
                        </dependency>
                    </dependencies>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

但实际上,我不明白我需要做什么以及如何进行该测试。如何让 EntityManager 尝试执行我的 insert.sql

INSERT INTO USER (NAME,SURNAME,DATE) VALUES ('NAME','SURNAME',to_date('2018-12-08 17:21:03', 'yyyy-mm-dd hh24:mi:ss'));

我需要什么它正在尝试进行一些并发测试。我有很多,但没有任何数据库,现在我需要测试连接或 inMemoryOracle。

所以我的问题是如何从插件中获取 EntityManager (是否需要创建任何 context.xml 其他?)

标签: javaspringmavenintegration-testingopenjpa

解决方案


推荐阅读