我有一个抽象类的人,并继承了所使用的类。我正在使用json文件进行单元测试但是当我运行测试时,我得到以下错误org.jboss.arquillian.persistence.dbunit.exception.DBUnitInitializationException:无法从给定文件加载数据集:employ.json我在做什么错?
班级人员
import java.io.Serializable;
import java.lang.Long;
import java.lang.String;
import javax.persistence.*;
@Entity
@Inheritance(strategy=InheritanceType.JOINED)
public abstract class Person implements Serializable {
@Id
@Column(name = "id", unique = true, nullable = false, updatable = false,
length = 11)
private Long id;
@Column(name = "name", nullable = false, updatable = true, length = 50)
private String name;
@Column(name = "email", nullable = false, updatable = true, length = 30)
private String email;
@Column(name = "phone", nullable = false, updatable = true, length = 16)
private String phone;
@Column(name = "password", unique = false, nullable = false, updatable = true, length = 20)
private String password;
private static final long serialVersionUID = 1L;
public Person() {
super();
}
}
受雇班级
import java.io.Serializable;
import javax.persistence.*;
public class Employed extends Person implements Serializable {
private static final long serialVersionUID = 1L;
public Employed() {
super();
}
}
测试
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.jboss.arquillian.transaction.api.annotation.TransactionMode;
import org.jboss.arquillian.transaction.api.annotation.Transactional;
import org.jboss.arquillian.persistence.UsingDataSet;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(Arquillian.class)
public class EmployedTest {
@PersistenceContext
private EntityManager entityManager;
@Deployment
public static Archive<?> createTestArchive() {
return ShrinkWrap.create(WebArchive.class,
"test.war").addPackage(Employed.class.getPackage())
.addAsResource("persistenceForTest.xml", "META-INF/persistence.xml")
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
}
@Test
@Transactional(value=TransactionMode.ROLLBACK)
@UsingDataSet({"employed.json"})
public void findTest() {
Employed employed = entityManager.find(Employed.class,123456L);
Assert.assertEquals("pete",employed.getName());
}
}
和JSON文件
{
"employed":
[
{
"id":123456,
"name":"pete",
"email":"pete@gmail.com",
"phone":"3233934933",
"password":"123456"
}
]
}