我能够成功创建Arquillian + Glassfish嵌入式和Arquillian + websphere嵌入式POC项目。现在我试图将Arquillian与我的实际开发项目集成在一起。以下是关于我的项目的breif信息。
IDE: IBM RAD 8.5.X
Server: IBM Websphere 8.5.X
Development: EJB3.1 complaint code (lot of EJBS)
UNIT Testing: JUnit4.11, Mockito etc.,
EJB Unit (or Integration) Testing: None, trying to use Arquillian 1.1.4
Deployment: using IDE RAD deployment
目前我的项目既没有ant也没有maven脚本来创建ear并在服务器上部署。我们非常依赖IBM RAD来在开发模式下部署我们的应用程序。因此,该项目使用的是Websphere JDK和Websphere运行时环境(在.classpath中)。
我正在尝试使用Arquillian + Glassfish嵌入式容器为EJB开发单元测试用例。我无法使用websphere嵌入式容器,因为我们有许多@Remote ejb和websphere嵌入式容器不支持@Remote支持。此时我不想从类路径中删除websphere运行时依赖项,因为我需要分析影响并说服我的内部架构。
是否可以将Arquillian + Glassfish嵌入式容器与Websphere运行时一起使用。我尝试传递JVM属性以查找glassfish嵌入式EJB Provider但它仍在尝试加载websphere容器。当然,这是因为Websphere运行时库可以通过.claspath。
获得任何评论或帮助都非常明显。
测试用例
@RunWith(Arquillian.class)
public class CalculatorBeanTest {
@Deployment
public static JavaArchive createDeployment() {
return ShrinkWrap.create(JavaArchive.class, "test.jar")
.addPackage(CalculatorBean.class.getPackage())
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
}
@EJB
private Calculator calc;
@Test
public void testAddition() {
assertThat(calc, notNullValue());
double result = calc.plus(10d, 5d);
assertThat(result, equalTo(15d));
}
}
arquillian.xml
<arquillian xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://jboss.org/schema/arquillian"
xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd"
xmlns:gfembed="urn:arq:org.jboss.arquillian.container.glassfish.embedded_3">
<container qualifier="glassfish-embedded" default="true">
<configuration>
<property name="resourcesXml">test-resources/glassfish-resources.xml</property>
</configuration>
</container>
</arquillian>
的glassfish-resources.xml中
<!DOCTYPE resources PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 Resource Definitions //EN"
"http://www.sun.com/software/appserver/dtds/sun-resources_1_4.dtd">
<resources>
RAD classpath
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/com.ibm.ws.ast.st.runtime.runtimeTarget.v85/WebSphere Application Server v8.5">
<attributes>
<attribute name="owner.project.facets" value="wcg"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/WebSphere Application Server V8.5 JRE">
<attributes>
<attribute name="owner.project.facets" value="java"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="lib/test-scope/glassfish-embedded-all-3.1.2.2.jar"/>
<classpathentry kind="lib" path="lib/test-scope/arquillian-config-api-1.1.4.Final.jar"/>
<classpathentry kind="lib" path="lib/test-scope/arquillian-config-impl-base-1.1.4.Final.jar"/>
<classpathentry kind="lib" path="lib/test-scope/arquillian-container-impl-base-1.1.4.Final.jar"/>
<classpathentry kind="lib" path="lib/test-scope/arquillian-container-spi-1.1.4.Final.jar"/>
<classpathentry kind="lib" path="lib/test-scope/arquillian-container-test-api-1.1.4.Final.jar"/>
<classpathentry kind="lib" path="lib/test-scope/arquillian-container-test-impl-base-1.1.4.Final.jar"/>
<classpathentry kind="lib" path="lib/test-scope/arquillian-container-test-spi-1.1.4.Final.jar"/>
<classpathentry kind="lib" path="lib/test-scope/arquillian-core-api-1.1.4.Final.jar"/>
<classpathentry kind="lib" path="lib/test-scope/arquillian-core-impl-base-1.1.4.Final.jar"/>
<classpathentry kind="lib" path="lib/test-scope/arquillian-core-spi-1.1.4.Final.jar"/>
<classpathentry kind="lib" path="lib/test-scope/arquillian-glassfish-embedded-3.1-1.0.0.CR4.jar"/>
<classpathentry kind="lib" path="lib/test-scope/arquillian-junit-container-1.1.4.Final.jar"/>
<classpathentry kind="lib" path="lib/test-scope/arquillian-junit-core-1.1.4.Final.jar"/>
<classpathentry kind="lib" path="lib/test-scope/arquillian-persistence-api-1.0.0.Alpha7.jar"/>
<classpathentry kind="lib" path="lib/test-scope/arquillian-persistence-core-1.0.0.Alpha7.jar"/>
<classpathentry kind="lib" path="lib/test-scope/arquillian-persistence-dbunit-1.0.0.Alpha7.jar"/>
<classpathentry kind="lib" path="lib/test-scope/arquillian-persistence-spi-1.0.0.Alpha7.jar"/>
<classpathentry kind="lib" path="lib/test-scope/arquillian-protocol-servlet-1.1.4.Final.jar"/>
<classpathentry kind="lib" path="lib/test-scope/arquillian-test-api-1.1.4.Final.jar"/>
<classpathentry kind="lib" path="lib/test-scope/arquillian-test-impl-base-1.1.4.Final.jar"/>
<classpathentry kind="lib" path="lib/test-scope/arquillian-test-spi-1.1.4.Final.jar"/>
<classpathentry kind="lib" path="lib/test-scope/arquillian-testenricher-cdi-1.1.4.Final.jar"/>
<classpathentry kind="lib" path="lib/test-scope/arquillian-testenricher-ejb-1.1.4.Final.jar"/>
<classpathentry kind="lib" path="lib/test-scope/arquillian-testenricher-initialcontext-1.1.4.Final.jar"/>
<classpathentry kind="lib" path="lib/test-scope/arquillian-testenricher-resource-1.1.4.Final.jar"/>
<classpathentry kind="lib" path="lib/test-scope/arquillian-transaction-api-1.0.1.Final.jar"/>
<classpathentry kind="lib" path="lib/test-scope/arquillian-transaction-impl-base-1.0.1.Final.jar"/>
<classpathentry kind="lib" path="lib/test-scope/arquillian-transaction-jta-1.0.1.Final.jar"/>
<classpathentry kind="lib" path="lib/test-scope/arquillian-transaction-spi-1.0.1.Final.jar"/>
<classpathentry kind="lib" path="lib/test-scope/commons-collections-3.2.1.jar"/>
<classpathentry kind="lib" path="lib/test-scope/commons-logging-1.1.jar"/>
<classpathentry kind="lib" path="lib/test-scope/dbunit-2.5.0.jar"/>
<classpathentry kind="lib" path="lib/test-scope/fest-assert-1.4.jar"/>
<classpathentry kind="lib" path="lib/test-scope/fest-util-1.1.6.jar"/>
<classpathentry kind="lib" path="lib/test-scope/hamcrest-core-1.3.jar"/>
<classpathentry kind="lib" path="lib/test-scope/hamcrest-library-1.3.jar"/>
<classpathentry kind="lib" path="lib/test-scope/jackson-core-asl-1.9.2.jar"/>
<classpathentry kind="lib" path="lib/test-scope/jackson-mapper-asl-1.9.2.jar"/>
<classpathentry kind="lib" path="lib/test-scope/junit-4.11.jar"/>
<classpathentry kind="lib" path="lib/test-scope/log4j-1.2.13.jar"/>
<classpathentry kind="lib" path="lib/test-scope/mockito-all-1.9.5.jar"/>
<classpathentry kind="lib" path="lib/test-scope/poi-3.2-FINAL.jar"/>
<classpathentry kind="lib" path="lib/test-scope/shrinkwrap-api-1.2.2.jar"/>
<classpathentry kind="lib" path="lib/test-scope/shrinkwrap-descriptors-api-base-2.0.0-alpha-5.jar"/>
<classpathentry kind="lib" path="lib/test-scope/shrinkwrap-descriptors-spi-2.0.0-alpha-5.jar"/>
<classpathentry kind="lib" path="lib/test-scope/shrinkwrap-impl-base-1.2.2.jar"/>
<classpathentry kind="lib" path="lib/test-scope/shrinkwrap-spi-1.2.2.jar"/>
<classpathentry kind="lib" path="lib/test-scope/slf4j-api-1.7.2.jar"/>
<classpathentry kind="lib" path="lib/test-scope/snakeyaml-1.10.jar"/>
异常
2015年4月3日下午6:50:49 com.sun.enterprise.v3.server.CommonClassLoaderServiceImpl findDerbyClient 信息:找不到javadb客户端jar文件,默认情况下derby jdbc驱动程序不可用。
java.lang.NoClassDefFoundError: com.ibm.ejs.ras.hpel.HpelHelper
at com.ibm.ejs.ras.RasHelper.getThreadId(RasHelper.java:1764)
at com.ibm.ejs.ras.RasEvent6$1.initialValue(RasEvent6.java:101)
at java.lang.ThreadLocal.setInitialValue(ThreadLocal.java:152)
at java.lang.ThreadLocal.get(ThreadLocal.java:142)
at com.ibm.ejs.ras.RasEvent6.<init>(RasEvent6.java:292)
at com.ibm.ejs.ras.MessageEvent6.<init>(MessageEvent6.java:203)
at com.ibm.ejs.ras.Tr.fireMessageEvent(Tr.java:1562)
at com.ibm.ejs.ras.Tr.error(Tr.java:730)
at com.ibm.ws.naming.java.javaURLContextFactory.isNameSpaceAccessable(javaURLContextFactory.java:108)
at com.ibm.ws.naming.urlbase.UrlContextFactory.getObjectInstance(UrlContextFactory.java:85)
at javax.naming.spi.NamingManager.getURLContext(NamingManager.java:706)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:422)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:376)
at javax.naming.InitialContext.rebind(InitialContext.java:448)
at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.publishObject(GlassfishNamingManagerImpl.java:206)
at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.publishObject(GlassfishNamingManagerImpl.java:189)
at org.glassfish.kernel.javaee.MEJBService.postConstruct(MEJBService.java:81)
at com.sun.hk2.component.AbstractCreatorImpl.inject(AbstractCreatorImpl.java:131)
at com.sun.hk2.component.ConstructorCreator.initialize(ConstructorCreator.java:91)
at com.sun.hk2.component.AbstractCreatorImpl.get(AbstractCreatorImpl.java:82)
at com.sun.hk2.component.SingletonInhabitant.get(SingletonInhabitant.java:67)
at com.sun.hk2.component.EventPublishingInhabitant.get(EventPublishingInhabitant.java:139)
at com.sun.hk2.component.AbstractInhabitantImpl.get(AbstractInhabitantImpl.java:78)
at com.sun.enterprise.v3.server.AppServerStartup.run(AppServerStartup.java:229)
at com.sun.enterprise.v3.server.AppServerStartup.doStart(AppServerStartup.java:145)
at com.sun.enterprise.v3.server.AppServerStartup.start(AppServerStartup.java:136)
at com.sun.enterprise.glassfish.bootstrap.GlassFishImpl.start(GlassFishImpl.java:79)
at org.jboss.arquillian.container.glassfish.embedded_3_1.GlassFishContainer.start(GlassFishContainer.java:174)
at org.jboss.arquillian.container.impl.ContainerImpl.start(ContainerImpl.java:199)
at org.jboss.arquillian.container.impl.client.container.ContainerLifecycleController$8.perform(ContainerLifecycleController.java:163)
at org.jboss.arquillian.container.impl.client.container.ContainerLifecycleController$8.perform(ContainerLifecycleController.java:157)
at org.jboss.arquillian.container.impl.client.container.ContainerLifecycleController.forContainer(ContainerLifecycleController.java:255)
at org.jboss.arquillian.container.impl.client.container.ContainerLifecycleController.startContainer(ContainerLifecycleController.java:156)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:611)
at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)
at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)
at org.jboss.arquillian.container.impl.client.ContainerDeploymentContextHandler.createContainerContext(ContainerDeploymentContextHandler.java:57)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:611)
at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:145)
at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:116)
at org.jboss.arquillian.core.impl.EventImpl.fire(EventImpl.java:67)
at org.jboss.arquillian.container.impl.client.container.ContainerLifecycleController$2.perform(ContainerLifecycleController.java:77)
at org.jboss.arquillian.container.impl.client.container.ContainerLifecycleController$2.perform(ContainerLifecycleController.java:70)
at org.jboss.arquillian.container.impl.client.container.ContainerLifecycleController.forEachSuiteContainer(ContainerLifecycleController.java:221)
at org.jboss.arquillian.container.impl.client.container.ContainerLifecycleController.startSuiteContainers(ContainerLifecycleController.java:69)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:611)
at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)
at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)
at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:145)
at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:116)
at org.jboss.arquillian.core.impl.EventImpl.fire(EventImpl.java:67)
at org.jboss.arquillian.container.test.impl.client.ContainerEventController.execute(ContainerEventController.java:86)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:611)
at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)
at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)
at org.jboss.arquillian.test.impl.TestContextHandler.createSuiteContext(TestContextHandler.java:65)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:611)
at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:145)
at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:116)
at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.beforeSuite(EventTestRunnerAdaptor.java:68)
at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:99)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.ClassNotFoundException: com.ibm.ejs.ras.hpel.HpelHelper
at java.net.URLClassLoader.findClass(URLClassLoader.java:434)
at java.lang.ClassLoader.loadClassHelper(ClassLoader.java:688)
at java.lang.ClassLoader.loadClass(ClassLoader.java:667)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:358)
at java.lang.ClassLoader.loadClass(ClassLoader.java:650)
... 89 more