1

我尝试在已安装的 JBoss 上使用 arquillian 做一个简单的测试示例,其版本为 4.2.2GA。花了很多时间在这个社区和堆栈流中做了很多阅读,但就是不知道如何让它工作。

现在的测试是这样的:

package com.ultramain.system.view.test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import javax.ejb.EJB;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.EnterpriseArchive;
import org.jboss.shrinkwrap.descriptor.api.Descriptors;

import org.junit.Test;
import org.junit.runner.RunWith;

import com.ultramain.system.view.test.IShrinkWrapBasicTest;
import com.ultramain.system.view.test.ShrinkWrapBasicTest;

@RunWith(Arquillian.class)
public class QuerySimulationContainer {

@EJB
private IShrinkWrapBasicTest testObject;

@Deployment
public static JavaArchive createDeployment() {
JavaArchive jar = ShrinkWrap.create(JavaArchive.class)
    .addClasses(QuerySimulationContainer.class,IShrinkWrapBasicTest.class,ShrinkWrapBasicTest.class);
System.out.println(jar.toString(true));
//System.out.println(jar.getContent());    
return jar; 
}

@Test 
public void testShrinkWrapWorks(){
    testObject = new ShrinkWrapBasicTest();
    assertEquals(testObject.getTestText(), "Test for ShrinkWrap");
}

}

测试单元需要的接口和类如下:

IShrinkWrapBasicTest.java:

package com.ultramain.system.view.test;

import javax.ejb.Remote;

@Remote
public interface IShrinkWrapBasicTest
{
    public String getTestText();

    public void testMethod();
}

ShrinkWrapBasicTest.java:

package com.ultramain.system.view.test;

import javax.ejb.Stateless;
import javax.ejb.Local;

@Stateless
public class ShrinkWrapBasicTest implements IShrinkWrapBasicTest
{ 
    public String getTestText()
    {
        return "Test for ShrinkWrap";
    }

    public void testMethod(){
    }
}

我的 pom.XML 中更改的部分在并列出如下: pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                      http://maven.apache.org/xsd/maven-4.0.0.xsd">

<!-- other parts in pom.XML which haven't been changed -->

    <dependencies>
        <!-- other dependency parts in original pom.XML, which haven't been changed after using arquillian -->

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-annotations</artifactId>
            <version>3.2.1.ga</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-math</artifactId>
            <version>2.0</version>
        </dependency>
        <dependency>
            <groupId>javax.jee</groupId>
            <artifactId>jee</artifactId>
            <version>5.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>jboss</groupId>
            <artifactId>jboss-annotations-ejb3</artifactId>
            <version>4.2.0.GA</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.arquillian</groupId>
            <artifactId>arquillian-bom</artifactId>
            <version>1.0.3.Final</version>
            <scope>import</scope>
            <type>pom</type>
        </dependency>            
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.arquillian.junit</groupId>
            <artifactId>arquillian-junit-container</artifactId>
            <version>1.0.3.Final</version>            
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>javax.ejb</groupId>
            <artifactId>ejb-api</artifactId>
            <version>3.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>dom4j</groupId>
            <artifactId>dom4j</artifactId>
            <version>1.6.1-jboss</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.spec</groupId>
            <artifactId>jboss-javaee-5.0</artifactId>
            <version>1.0.0.GA</version>
            <type>pom</type>
            <scope>provided</scope>
        </dependency>    
        <dependency>
            <groupId>org.jboss.client</groupId>
             <artifactId>jmx-invoker-adaptor-client</artifactId>
              <version>4.2.2.GA</version>
              <scope>test</scope>
        </dependency>    
        <dependency>
            <groupId>org.jboss.arquillian.container</groupId>
            <artifactId>arquillian-jbossas-remote-4.2</artifactId>
            <version>1.0.0.Final-SNAPSHOT</version>
            <scope>test</scope>
        </dependency>
        <dependency>
          <groupId>org.jboss.arquillian.container</groupId>
          <artifactId>arquillian-container-spi</artifactId>
          <version>1.0.3.Final</version>
          <scope>test</scope>
        </dependency>
        <dependency>
          <groupId>org.jboss.arquillian.container</groupId>
          <artifactId>arquillian-container-test-spi</artifactId>
          <version>1.0.3.Final</version>
          <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.arquillian.protocol</groupId>
            <artifactId>arquillian-protocol-servlet</artifactId>
            <version>1.0.3.Final</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>jboss</groupId>
            <artifactId>jbossall-client</artifactId>
            <version>4.2.2.GA</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.deployers</groupId>
            <artifactId>jboss-deployers-client-spi</artifactId>
            <version>2.2.2.GA</version>
            <scope>test</scope>
        </dependency>
        <dependency>
          <groupId>org.jboss.deployers</groupId>
          <artifactId>jboss-deployers-core-spi</artifactId>
          <version>2.2.2.GA</version>
              <scope>test</scope>
        </dependency>         
        <dependency>
            <groupId>org.jboss.shrinkwrap.descriptors</groupId>
            <artifactId>shrinkwrap-descriptors-impl-javaee</artifactId>
            <version>2.0.0-alpha-4</version>
            <scope>test</scope>
        </dependency>
        <dependency>
          <groupId>org.jboss.shrinkwrap</groupId>
          <artifactId>shrinkwrap-api</artifactId>
          <version>1.1.1-alpha-2</version>
          <scope>test</scope>
        </dependency>
        <dependency>
          <groupId>org.jboss.shrinkwrap.resolver</groupId>
          <artifactId>shrinkwrap-resolver-bom</artifactId>
          <version>2.0.0-alpha-6</version>
          <type>pom</type>
          <scope>test</scope>
        </dependency>
        <dependency>
          <groupId>org.jboss.shrinkwrap.resolver</groupId>
          <artifactId>shrinkwrap-resolver-depchain</artifactId>
          <version>2.0.0-alpha-6</version>
          <type>pom</type>
          <scope>test</scope>
        </dependency>    

       <!-- other dependency parts in original pom.XML, which haven't been changed after using arquillian -->
    </dependencies>
<!-- other parts in original pom.XML, which haven't been changed after using arquillian -->
</project>

我正在使用 jndi.properties 文件、aquillian.launch 文件和下面列出的另一个 arquillian.xml:

jndi.properties(这里的 URL 是我们用来启动 JBOSS 服务器的 ip 地址):

java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming\:org.jnp.interfaces 
java.naming.provider.url=jnp://URL:1099

arquilllian.launch:

local

arquillian.xml(这里的URL是我们用来启动JBOSS服务器的ip地址):

<?xml version="1.0"?>
<arquillian xmlns="http://jboss.org/schema/arquillian"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
        http://jboss.org/schema/arquillian
        http://jboss.org/schema/arquillian/arquillian_1_0.xsd">        
    <container qualifier="local" default="true">
        <configuration>
            <property name="profileName">local</property>
            <property name="providerUrl">jnp://URL:1099</property>      
            <property name="contextFactory">org.jnp.interfaces.NamingContextFactory</property>
            <property name="urlPkgPrefix">org.jboss.naming:org.jnp.interfaces</property>
        </configuration>   
        <protocol type="Servlet 2.5">
                <property name="host">URL</property>
                <property name="port">8080</property>
        </protocol>          
    </container>
</arquillian>

故障跟踪是:

org.jboss.arquillian.container.spi.client.container.LifecycleException: Could not connect to container
    at org.jboss.arquillian.container.jbossas.remote_4_2.JBossASRemoteContainer.start(JBossASRemoteContainer.java:97)
    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:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    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:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    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:135)
    at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:115)
    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:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    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:135)
    at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:115)
    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:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    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:60)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    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:135)
    at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:115)
    at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.beforeSuite(EventTestRunnerAdaptor.java:68)
    at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:97)
    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: javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException: Could not get DeploymentManager
    at javax.enterprise.deploy.shared.factories.DeploymentFactoryManager.getDeploymentManager(DeploymentFactoryManager.java:138)
    at org.jboss.arquillian.container.jbossas.remote_4_2.JBossASRemoteContainer.createDeploymentManager(JBossASRemoteContainer.java:117)
    at org.jboss.arquillian.container.jbossas.remote_4_2.JBossASRemoteContainer.start(JBossASRemoteContainer.java:93)
    ... 61 more

我在这里被困了几天,并尝试了我从这里的其他帖子以及 Github 的 arquillian.container.jboss 中的示例中学到的所有内容。现在有点绝望......谁能看到我的错误是什么?我错过了 pom 文件中的任何内容吗?

在此先感谢您的任何建议!

4

0 回答 0