java – 如何正确配置嵌入式OpenEJB容器以进行测试?
作者:互联网
这是我的SLSB:
@Stateless
public class MyService {
PersistenceContext(unitName = "abc")
EntityManager em;
public boolean exists(int id) {
return this.em.find(Employee.class, id) != null;
}
}
这是我的persistence.xml(我正在使用Glassfish v3):
<persistence>
<persistence-unit name="abc">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:/MyDS</jta-data-source>
<properties>
<property name="hibernate.archive.autodetection" value="class" />
<property name="hibernate.dialect"
value="org.hibernate.dialect.MySQLInnoDBDialect" />
</properties>
</persistence-unit>
</persistence>
现在我正在尝试使用OpenEJB嵌入式容器创建测试.这是我的测试类:
class MyServiceText {
@Test
public void testChecksExistence() throws Exception {
Properties properties = new Properties();
properties.setProperty(
javax.naming.Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.client.LocalInitialContextFactory"
);
InitialContext ic = new InitialContext(properties);
// actual testing skipped
}
}
我想用HSQL进行测试.如何指示OpenEJB我的持久性单元“abc”在测试期间必须指向HSQL?我要创建一个新版本的persistence.xml吗?我要用openejb.xml吗?我迷失了他们的examples and documentation ..
标签:java,maven-2,maven-3,ejb-3-0,openejb 来源: https://codeday.me/bug/20190518/1129377.html