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