Arquillian与Payara Micro连接器1.1:NullPointer

时间:2019-07-09 13:06:05

标签: java-ee junit jboss-arquillian payara-micro

我无法获得与Arquillian和Payara一起使用的简单测试。

我有pyara博客(Blogpost)中的模板,我不知道出了什么问题。

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">
    <modelVersion>4.0.0</modelVersion>

    <groupId>de.example.arquillian</groupId>
    <artifactId>arquillianTest</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <payara.version>5.192</payara.version>
    </properties>

    <dependencyManagement>
                <dependencies>
            <dependency>
                <groupId>org.jboss.arquillian</groupId>
                <artifactId>arquillian-bom</artifactId>
                <version>1.4.1.Final</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <!-- Junit -->
    <dependency>
        <groupId>org.jboss.arquillian.junit</groupId>
        <artifactId>arquillian-junit-container</artifactId>
        <version>1.4.1.Final</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>fish.payara.arquillian</groupId>
        <artifactId>arquillian-payara-micro-managed</artifactId>
        <version>1.1</version>
        <scope>test</scope>
    </dependency>
    </dependencies>

    <build>
        <plugins>
            <!-- Download and copy Payara Micro artefact -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>3.1.1</version>
                <executions>
                    <execution>
                        <phase>process-test-classes</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>fish.payara.extras</groupId>
                                    <artifactId>payara-micro</artifactId>
                                    <version>${payara.version}</version>
                                    <overWrite>false</overWrite>
                                    <outputDirectory>${project.basedir}/target/</outputDirectory>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!-- Configure Payara Micro Runtime -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.2</version>
                <configuration>
                    <environmentVariables>
                        <MICRO_JAR>${project.basedir}/target/payara-micro-${payara.version}.jar</MICRO_JAR>
                    </environmentVariables>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

HelloWorld.java

public class HelloWorld {

    public String sayHello() {
        return "Hello World";
    }
}

HelloWorldTest

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.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;


@RunWith(Arquillian.class)
public class HelloWorldTest {


    @Deployment
    public static JavaArchive createDeployment() {
        return ShrinkWrap.create(JavaArchive.class)
                .addClass(HelloWorld.class);
    }


    @Test()
    public void sayHelloTest() {
        HelloWorld helloWorld = new HelloWorld();
        Assert.assertEquals(helloWorld.sayHello(), "Hello World");
    }
}

HelloworldTest应该通过,但是我得到了 HelloWorldTest.HelloWorldTest»NullPointer

我不知道如何进一步简化它,并认为存在配置错误?

2 个答案:

答案 0 :(得分:0)

您应该替换以下依赖项:

 <dependency>
   <groupId>fish.payara.arquillian</groupId>
   <artifactId>arquillian-payara-micro-managed</artifactId>
   <version>1.1</version>
   <scope>test</scope>
</dependency>

<groupId>fish.payara.arquillian</groupId>
     <artifactId>arquillian-payara-micro-5-managed</artifactId>
     <version>1.0.Beta3</version>
     <scope>test</scope>
</dependency>

如您所指的blog帖子中所述。

我有一个GitHub上的Payara Micro 5.192和JUnit 4.12和Arquillian的运行示例。您可以检出存储库,然后在mvn test文件夹中运行arquillian-payara-micro-example,一切正常。

答案 1 :(得分:0)

因此,问题是由payara arquillian连接器引起的。 1.1版和1.2版快照具有此错误。

您应该在他的答案秀中使用1.0Beta3作为rieckpil。

我在Github上发布了一个Issue,并且此错误已得到确认。 (PAYARA-3991) Gihub Issue

所以希望这个问题会尽快解决。