(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
ます。これをテストする@ApplicationScoped
と動作しますが、それは私が望むものではありません。また、テストし@Named
たり、動作したりする@LocalBean
と動作します。しかし、これらは非 EJB 仕様です。
更新 2:これに対する回避策を見つけました。WELD SE に変更しear.merge(ejbJar)
てテストに追加すると、溶接プロファイルとWildfly 管理プロファイルで機能します。
それでも私はこれを解決策とは考えていません。WELD-EE でサポートされるべきだと思うからです。