简体   繁体   English

与arquillian的EAR集成测试

[英]EAR integration test with arquillian

I have the following real project structure: 我有以下真实的项目结构:

EAR
 - lib/commons.jar
 - lib/another dependencies
 - ejb.jar

I want to test it with arquillian but I always get an exception. 我想用arquillian测试它,但我总是得到一个例外。

This is my java method where the EAR is built: 这是构建EAR的java方法:

@Deployment
public static Archive<?> createTestArchive() {
    //create ear
    EnterpriseArchive ear = ShrinkWrap
            .create(EnterpriseArchive.class, "test-app.ear");

    // create ejb-jar
    JavaArchive ejb = ShrinkWrap
            .create(JavaArchive.class, "test-ejb.jar")
            .addPackage("a.b.ejb")
            .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");

    // resolve ejb dependencies
    File[] dependencies = Maven.resolver()
            .loadPomFromFile("pom.xml")
            .importDependencies(ScopeType.COMPILE, ScopeType.TEST)
            .resolve()
            .withTransitivity()
            .asFile();

    ear.addAsModule(ejb);
    ear.addAsLibraries(dependencies);
    ear.setApplicationXML("glassfish-resources.xml");

    LOGGER.debug("content: " + ear.toString(true));
    return ear;
}

The content looks fine but something is not okay because I get this exception: 内容看起来很好,但有些东西不合适,因为我得到了这个例外:

ArquillianServletRunner not found.
Could not determine ContextRoot from ProtocolMetadata, please contact DeployableContainer developer.

JAR content: JAR内容:

/a/
/a/b/
/a/b/ejb/
/a/b/ejb/MyEjb.class
...
/META-INF/
/META-INF/beans.xml

EAR content EAR内容

/test-ejb.jar
/lib/
/lib/commons-444750341265461918.jar
/lib/slf4j-api-1.7.21.jar
/lib/slf4j-log4j12-1.7.21.jar
/lib/guava-21.0.jar
...
/lib/arquillian-testenricher-initialcontext-1.1.13.Final.jar
/lib/payara-embedded-all-4.1.1.171.0.1.jar
/lib/postgresql-42.0.0.jar
/META-INF/
/META-INF/application.xml

The reason why I got " ArquillianServletRunner not found " error was because there was an error on EJB level. 我得到“ ArquillianServletRunner not found ”错误的原因是因为EJB级别存在错误。

The following test code works properly: 以下测试代码正常工作:

@RunWith(Arquillian.class)
public class EchoServiceBeanTest {

    @EJB
    private EchoService echoService;

    @Deployment
    public static Archive<?> createDeployment() {
        // create ear
        EnterpriseArchive ear = ShrinkWrap
                .create(EnterpriseArchive.class, "test-app.ear");

        // create ejb.jar
        JavaArchive ejb = ShrinkWrap
                .create(JavaArchive.class, "test-ejb.jar")
                .addPackages(true, "a.b.ejb")
                .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
        LOGGER.debug("EJB content: " + ejb.toString(true));

        // build ear
        ear.addAsModule(ejb);

        LOGGER.debug("EAR deployment content: " + ear.toString(true));
        return ear;
    }

    @Test
    public void echo() throws Exception {
        Assert.assertNotNull(echoService);
        String expected = "hello";
        String returned = echoService.echo(expected);
        Assert.assertEquals(expected, returned);
    }
}

used maven dependencies: 使用maven依赖项:

<dependencies>
    <!-- provided jars -->
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-api</artifactId>
        <version>7.0</version>
        <scope>provided</scope>
    </dependency>
    <!-- junit -->
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>
    <!-- log4j -->
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
    </dependency>
    <!-- arquillian -->
    <dependency>
        <groupId>org.jboss.arquillian.junit</groupId>
        <artifactId>arquillian-junit-container</artifactId>
        <version>1.1.13.Final</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.jboss.arquillian.container</groupId>
        <artifactId>arquillian-glassfish-embedded-3.1</artifactId>
        <version>1.0.0.Final</version>
        <scope>test</scope>
    </dependency>
    <!-- embedded EE container -->
    <dependency>
        <groupId>fish.payara.extras</groupId>
        <artifactId>payara-embedded-all</artifactId>
        <version>4.1.1.171.1</version>
        <scope>test</scope>
    </dependency>
</dependencies>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM