我试图运行具有的Arquillian JUnit测试的注解@Stateless我的服务类,但它不工作...的Arquillian JUnit测试不起作用
的@Deployment通过测试,但@Test断言失败,出现空指针异常的注射服务:
@RunWith(Arquillian.class)
public class GenericDaoTest {
@Inject
private EmployeeService employeeService;
@Deployment
public static JavaArchive createTestableDeployment() {
final JavaArchive jar = ShrinkWrap
.create(JavaArchive.class)
.addPackage("it.smartit.application.timesheet.service")
.addPackage("it.smartit.application.timesheet.service.impl")
.addAsManifestResource("META-INF/persistence.xml",
"persistence.xml")
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
.addPackage("it.smartit.application.timesheet.entity");
return jar;
}
@Test
public void should_crud() {
assertNotNull(employeeService);
Employee initialSize = employeeService.findById(new Integer(1));
}
}
注入的服务是:“代理的视图类:EJB的的EmployeeService:mployeeServiceImpl”当我尝试调用它返回的方法:首先
我使用道,但我与jpa没有用,所以现在在servi CE我使用实体管理器,但仍然没有工作:(
@Local
public interface GenericService<T, PK extends Serializable>{
T findById(PK id);
}
@Stateless(name = "GenericServiceImpl", mappedName = "GenericServiceImpl")
public class GenericServiceImpl<T, PK extends Serializable> implements
GenericService<T, PK> {
@PersistenceContext(unitName = "timesheet")
protected EntityManager entityManager;
private Class<T> entityClass;
public GenericServiceImpl() {
}
public GenericServiceImpl(Class<T> entityClass) {
this.entityClass = entityClass;
}
@Override
public T findById(PK id) {
return entityManager.find(entityClass, id);
}
}
public interface EmployeeService extends
GenericService<Employee,Integer> {
}
@Stateless(name = "EmployeeServiceImpl", mappedName = "EmployeeServiceImpl")
public class EmployeeServiceImpl extends GenericServiceImpl<Employee,Integer> implements EmployeeService{
public EmployeeServiceImpl() {
super(Employee.class);
}
}
用这个资产就返回此错误:
javax.ejb.EJBException: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not prepare statement
at org.jboss.as.ejb3.tx.CMTTxInterceptor.handleExceptionInOurTx(CMTTxInterceptor.java:190)
....
Caused by: org.jboss.arquillian.test.spi.ArquillianProxyException: org.h2.jdbc.JdbcSQLException : Table "EMPLOYEES" not found; SQL statement:
选择employee0_.employeed_id为employee1_3_0_,employee0_.address作为....
我在Wildfly8和MySQL
你能分享你的依赖吗? –
发布更新谢谢@ bartosz.majsak – antonio