如何为Glassfish可嵌入EJBContainer + EclipseLink JPA设置JUnit测试?
|
我试图在Glassfish 3.1上使用EJB 3.1可嵌入EJBContainer进行集成
测试我的EJB。我不知道存在类加载问题。
我的ejb已内置到dum-ejb.jar中。他们使用EclipseLink JPA。我还创建EJB客户端jar dum-ejb-client.jar,同时尝试解决类加载问题。客户端jar包含EJB接口和Entity类(通常是参数或返回值)。客户端jar还包含许多不需要的类,可以将其删除(但我不知道它如何解决该问题)。
问题在于,由于EclipseLink确实将字节码编织到Entity类,所以在运行junit测试时Entity类一定不能位于类路径中:http://www.java.net/forum/topic/glassfish/glassfish/embedded-玻璃鱼和编织
我可以这样做并配置classpath,以便不包含dum-ejb.jar。如果我使用EJBContainer以便将我的服务作为java.lang.Object查找并通过反射调用它的方法,则该测试有效。但是,当然,这不是我要编写测试的方式。
典型的测试如下:
@Test
public void testInEJBContainer() throws Exception {
File ejbJarFile = new File(\"target/dum/dum-ejb.jar\");
Map props = new HashMap();
props.put(\"org.glassfish.ejb.embedded.glassfish.instance.root\",
\"target/classes/instance-root\");
props.put(EJBContainer.MODULES, new File[]{ejbJarFile});
EJBContainer container = EJBContainer.createEJBContainer(props);
CompanyService = (CompanyService)
container.getContext().lookup(\"java:global/dum/CompanyServiceImpl\");
log.info(\"result of findAll() \" + service.findAll(false));
}
如果CompanyService接口和返回的Company Entity类不能位于类路径中,如何运行测试?
即使dum-ejb.jar不在类路径上,而dum-ejb-client.jar不在类路径上,EclipseLink的编织也会被破坏。
这不是EJBContainer的典型用例,是否应该有一个简单的解决方案呢?
没有找到相关结果
已邀请:
1 个回复
骨乏唯瓜