如何使用Maven运行标准的Arquillian EJB会话测试?

时间:2013-09-09 00:10:51

标签: eclipse maven ejb jboss-arquillian

我是Arquillian和Maven的新手,本周刚刚开始,所以我为这个简单的问题道歉。毋庸置疑,我已经花了一些时间学习绳索。对于我的最新技巧,我正在尝试设置标准EJB会话Bean。我的大部分知识来自Arquillian入门指南:

http://arquillian.org/guides/getting_started/
http://arquillian.org/guides/getting_started_rinse_and_repeat/
http://docs.jboss.org/arquillian/reference/1.0.0.Alpha1/en-US/html_single/#d0e395

要获取错误,我在Eclipse中右键单击我的Model项目并选择Run As->在服务器上运行。我收到以下错误:

Caused by: java.lang.ClassNotFoundException: org.jboss.shrinkwrap.api.asset.Asset from [Module "deployment.Model.jar:main" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:196) [jboss-modules.jar:1.2.0.Final-redhat-1]
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:444) [jboss-modules.jar:1.2.0.Final-redhat-1]
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:432) [jboss-modules.jar:1.2.0.Final-redhat-1]
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:399) [jboss-modules.jar:1.2.0.Final-redhat-1]
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:374) [jboss-modules.jar:1.2.0.Final-redhat-1]
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:119) [jboss-modules.jar:1.2.0.Final-redhat-1]
... 29 more

这是完整的服务器日志:

http://www.williverstravels.com/JDev/Forums/StackOverflow/arquillianEJB/log.txt

这是我的测试类

 package model.session;

 import static org.junit.Assert.*;

 import javax.ejb.EJB;

 import model.entity.Project;

 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.asset.EmptyAsset;
 import org.jboss.shrinkwrap.api.spec.JavaArchive;
 import org.junit.Test;
 import org.junit.runner.RunWith;

 @RunWith(Arquillian.class)
 public class SessionTest {

     @EJB
     private MyManagerLocal service;

     @Deployment
     public static JavaArchive createTestableDeployment() {
         final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "example.jar")
                 .addClasses(MyManagerLocal.class, MyManager.class)
                 .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
         return jar;
     }

     @Test
     public void assertEqualsProject() {
         Project project = (Project)service.getEntityByPrimaryKey(Project.class, 1L);
         assertEquals(project.getProjectId().longValue(), 1L);
     }
 }

这是我的pom.xml

<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">
<modelVersion>4.0.0</modelVersion>
<groupId>Model</groupId>
<artifactId>Model</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.jboss.arquillian</groupId>
            <artifactId>arquillian-bom</artifactId>
            <version>1.1.1.Final</version>
            <scope>import</scope>
            <type>pom</type>
        </dependency>
    </dependencies>
</dependencyManagement>
<build>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.12</version>
        </plugin>
    </plugins>
</build>
<dependencies>
    <dependency>
        <groupId>org.jboss.arquillian.junit</groupId>
        <artifactId>arquillian-junit-container</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.8.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.jboss.spec</groupId>
        <artifactId>jboss-javaee-6.0</artifactId>
        <version>1.0.0.Final</version>
        <type>pom</type>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>commons-lang</groupId>
        <artifactId>commons-lang</artifactId>
        <version>2.3</version>
    </dependency>
    <dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>eclipselink</artifactId>
        <version>2.5.1-RC1</version>
        <scope>provided</scope>
    </dependency>
</dependencies>
<profiles>
    <profile>
        <id>jboss-embedded</id>
        <dependencies>
            <dependency>
                <groupId>org.jboss.arquillian.container</groupId>
                <artifactId>arquillian-weld-ee-embedded-1.1</artifactId>
                <version>1.0.0.CR3</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.jboss.weld</groupId>
                <artifactId>weld-core</artifactId>
                <version>1.1.5.Final</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-simple</artifactId>
                <version>1.6.4</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
    </profile>
    <profile>
        <id>arquillian-jbossas-managed</id>
        <dependencies>
            <dependency>
                <groupId>org.jboss.as</groupId>
                <artifactId>jboss-as-arquillian-container-managed</artifactId>
                <version>7.1.1.Final</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.jboss.arquillian.protocol</groupId>
                <artifactId>arquillian-protocol-servlet</artifactId>
                <scope>test</scope>
            </dependency>
        </dependencies>
    </profile>
</profiles>

我还有一个arquillian.xml文件

<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">
<defaultProtocol type="Servlet 3.0"></defaultProtocol>
<container qualifier="arquillian-jbossas-managed" default="true">
    <configuration>
        <property name="jbossHome">C:\Dev\eap</property>
        <property name="allowConnectingToRunningServer">true</property>
    </configuration>
</container>

使用过JBoss AS 7.2 / EAP 6.1后,看起来有些罐子丢失了,但我原本以为Maven pom.xml会处理这个问题。 任何帮助,将不胜感激。我此刻有点失落。

**更新** 我已经尝试了一些其他pom.xml配置,例如将所有arquillian范围更改为运行时或只是完全删除标记。仍然得到相同的错误。我也尝试添加以下内容无效:

<dependency>
    <groupId>org.jboss.shrinkwrap.resolver</groupId>
    <artifactId>shrinkwrap-resolver-bom</artifactId>
    <version>2.1.0-alpha-1</version>
    <scope>runtime</scope>
    <type>pom</type>
</dependency>

**更新**

据我所知,问题在于我的pom.xml中的jar行。需要库,但它们不与jar一起打包。所以我回到绘图板上,了解如何让我的测试工作。我应该将它们打包到另一个项目吗?因为我的测试无法“看到”正在测试的Model.jar,所以当我运行它时也会给我带来错误。这变成了一个加剧的陷阱-22。

0 个答案:

没有答案