我尝试使用带有TomEE Embedded容器的arquillian持久性扩展进行测试,但在我的测试用例中 - 提供的数据集似乎没有调用。
这是我的pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<groupId>com.mycompany.mvd</groupId>
<artifactId>hr-model</artifactId>
<dependencies>
<dependency>
<groupId>org.arquillian.universe</groupId>
<artifactId>arquillian-junit</artifactId>
<type>pom</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${version.junit}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.arquillian.universe</groupId>
<artifactId>arquillian-persistence</artifactId>
<scope>test</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.arquillian.universe</groupId>
<artifactId>arquillian-transaction-jta</artifactId>
<scope>test</scope>
<type>pom</type>
<exclusions>
<exclusion>
<groupId>org.jboss.arquillian.extension</groupId>
<artifactId>arquillian-transaction-jta</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.openejb</groupId>
<artifactId>arquillian-tomee-embedded</artifactId>
<version>1.7.4</version>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.arquillian</groupId>
<artifactId>arquillian-universe</artifactId>
<version>${version.arquillian_universe}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<properties>
<version.arquillian_universe>1.0.0.Alpha3</version.arquillian_universe>
<version.junit>4.12</version.junit>
</properties>
我有简单的实体类
@Entity
public class MyEntity {
@Id
private Long id;
private String value;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
arquillian.xml:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<arquillian xmlns="http://jboss.org/schema/arquillian" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
<container qualifier="server" default="true">
<configuration>
<property name="httpsPort">-1</property>
<property name="httpPort">-1</property>
<property name="stopPort">-1</property>
<property name="properties">
jdbc/TestDB = new://Resource?type=DataSource
jdbc/TestDB.JdbcDriver = org.hsqldb.jdbcDriver
jdbc/TestDB.JdbcUrl = jdbc:hsqldb:mem:arquillian
jdbc/TestDB.UserName = sa
jdbc/TestDB.Password =
jdbc/TestDB.JtaManaged = true
jdbc/TestDB.LogSql = true
</property>
</configuration>
</container>
<extension qualifier="persistence">
<property name="defaultDataSource">openejb:Resource/jdbc/TestDB</property>
</extension>
数据集文件:
<dataset>
<myentity id="1" value="Test"/>
<myentity id="2" value="Test2"/>
<myentity id="3" value="Test3"/>
</dataset>
测试用例,不起作用:
@Test
@Transactional(TransactionMode.COMMIT)
@UsingDataSet("datasets/myentity.xml")
@InSequence(5)
public void shouldFindInDataset() {
MyEntity entity = entityManager.find(MyEntity.class, 2L);
System.out.println(entity);
Assert.assertNotNull(entity);
Assert.assertEquals("Test2", entity.getValue());
}