Arquillian Weld EE NullPointerException(调用方法)EAR

时间:2016-04-21 08:28:25

标签: jboss-arquillian jboss-weld weld shrinkwrap

我正在尝试使用(ShrinkWrap)EnterpriseArchive中的Arquillian + WELD EE进行测试。 但是当我开始调用该方法时,我得到一个NullPointerException。

我的pom.xml

        <profile>
            <id>arquillian-weld-ee-embedded</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <dependencies>
                <dependency>
                    <groupId>org.jboss.spec</groupId>
                    <artifactId>jboss-javaee-7.0</artifactId>
                    <version>1.0.3.Final</version>
                    <type>pom</type>
                    <scope>provided</scope>
                </dependency>
                <dependency>
                    <groupId>org.jboss.arquillian.container</groupId>
                    <artifactId>arquillian-weld-ee-embedded-1.1</artifactId>
                    <version>1.0.0.CR9</version>
                    <scope>test</scope>
                </dependency>
                <dependency>
                    <groupId>org.jboss.weld</groupId>
                    <artifactId>weld-core</artifactId>
                    <scope>test</scope>
                </dependency>
                <dependency>
                    <groupId>org.jboss.weld</groupId>
                    <artifactId>weld-api</artifactId>
                    <scope>test</scope>
                </dependency>
                <dependency>
                    <groupId>org.jboss.weld</groupId>
                    <artifactId>weld-spi</artifactId>
                    <scope>test</scope>
                </dependency>
                <dependency>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-simple</artifactId>
                    <version>1.6.4</version>
                    <scope>test</scope>
                </dependency>
            </dependencies>
            <dependencyManagement>
                <dependencies>
                    <dependency>
                        <groupId>org.jboss.weld</groupId>
                        <artifactId>weld-core-bom</artifactId>
                        <version>2.3.3.Final</version>
                        <type>pom</type>
                        <scope>import</scope>
                    </dependency>
                </dependencies>
            </dependencyManagement>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-surefire-plugin</artifactId>
                    </plugin>
                </plugins>
            </build>
        </profile>

我的测试类

@RunWith(Arquillian.class)
public class NewSessionBeanTest {

    public NewSessionBeanTest() {
    }

    @Deployment
    public static Archive<?> createDeployment() {
        final JavaArchive ejbJar = ShrinkWrap
                .create(JavaArchive.class, "ejb-jar.jar")
                .addClass(NewSessionBean.class)
                .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");

        final WebArchive testWar = ShrinkWrap.create(WebArchive.class, "test.war")
                .addClass(NewSessionBeanTest.class)
                .addAsManifestResource("META-INF/test-web-beans.xml", "beans.xml")
                ;
        final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class)
                .setApplicationXML("META-INF/test-application.xml")
                .addAsModule(ejbJar)
                .addAsModule(testWar);

        return ear;
    }

    @Inject
    NewSessionBean sessionBean;

    @Test
    public void testBusinessMethod() throws Exception {
        assertNotNull(sessionBean);

        // With Weld-EE it gives NullPointerException here
        sessionBean.businessMethod();
    }
}

它在sessionBean.businessMethod();处失败,插入了代理,因此assertNotNull通过。当我使用arquillian-weld-se-embedded-1.1(SE)时,我收到错误could not inject members

当我使用wildfly嵌入式容器测试时,这非常有效。

更新:我的NewSessionBean课程为@Stateless + @LocalBean(也是在没有@LocalBean的情况下进行测试。当我使用{{1}进行测试时它有效,但它不是我想要的。 此外,如果我测试它@ApplicationScoped@Named它也可以。但这些都是非EJB规范。

http://www.programcreek.com/java-api-examples/index.php?source_dir=arquillian-container-weld-master/weld-ee-embedded-1.1/src/test/java/org/jboss/arquillian/container/weld/ee/embedded_1_1/WeldEmbeddedIntegrationEARTestCase.java

上找到测试

更新2:我找到了解决方法。更改为WELD SE并将@LocalBean添加到测试适用于焊接配置文件 Wildfly托管配置文件。

我仍然不认为这是一个解决方案,因为我认为它应该得到WELD-EE的支持。

0 个答案:

没有答案