0

I am trying to test with Arquillian + WELD EE in an (ShrinkWrap)EnterpriseArchive. But I am getting a NullPointerException when I start invoking the method.

My 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>

My testclass

@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();
    }
}

It fails at sessionBean.businessMethod();, there is an proxy inserted so assertNotNull passes. When I use arquillian-weld-se-embedded-1.1 (SE), then I get an error could not inject members.

This works perfectly when I test this with a wildfly-embedded container.

UPDATE: My NewSessionBean class is @Stateless + @LocalBean (also tested without @LocalBean. When I test this with @ApplicationScoped it works, but it's not what I want. Also if I test it @Named or with @LocalBean it works. But these are non-EJB specifications.

Found test on: 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

UPDATE 2: I have found a workaround for this. Changing to WELD SE and adding ear.merge(ejbJar) to the Test works for the weld profile and Wildfly Managed profile.

Still I don't consider this as a solution, because I think it should be supported by WELD-EE.

Albert Bos
  • 2,012
  • 1
  • 15
  • 26
  • Just out of curiosity, why using mocked EE environment instead of something closer to your prod? – bartosz.majsak Apr 22 '16 at 06:45
  • @bartosz.majsak The thing is I want to use both. I have 2 profiles in maven Weld-EE-Embedded and wildfly-managed. The code is already working in wildfly-managed. I want to use weld-ee-embedded as "fast" testing and want to re-use the exact some code for the wildfly-managed. I can get my code working when I only use JavaArchive instead of EnterpriseArchive. But the EnterpriseArchive is the closest I get to a real deployment. – Albert Bos Apr 22 '16 at 06:51
  • Got it. Might be a bug in weld-ee-embedded then. Is there a huge difference in build time between the two? I will have a look at it over the weekend. Maybe I will be able to help you. – bartosz.majsak Apr 22 '16 at 09:08
  • @bartosz.majsak There is quite some performance difference. I have found a hack/workaround, I updated my post. Still it isn't a clean solution. – Albert Bos Apr 24 '16 at 19:52

0 Answers0