I am succesfully running EJB tests with Arquillian against an (older) Glassfish 3.1 embedded.
When trying to @Inject weld beans, I get a NPE when I want to address a method in a transitively injected Weld bean.
So, I am testing EJB A. EJB A has a ref to EJB B. EJB B has a ref to a Weld bean.
This is the Jar init.
@Deployment
public static Archive<?> createDeployment() {
return ShrinkWrap.create(JavaArchive.class, "itscool.jar")
.addClasses(DashboardService.class, PropertyService.class, StorageService.class, EPSRepository.class,
EmailService.class, NotificationRepository.class, EmailRepository.class, Configuration.class,
MailingList.class, BogusBean.class, Bogus.class)
.addAsManifestResource("META-INF/persistence.xml", "persistence.xml")
.addAsManifestResource(EmptyAsset.INSTANCE, "META-INF/beans.xml")
.addAsResource(new File("src/test/resources/csman.properties"), "csman.properties");
}
So, the injected bean is the Configuration.class. First, I thought there was some initialization error in the Configuration impl class, so I created the @Bogus and BogusBean to only test the injection. I get the same errors.
@Bogus
public class BogusBean {
public void setIt(){
}
}
And the Qualifier
@Documented
@Target({ ElementType.METHOD, ElementType.FIELD, ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
@Qualifier
public @interface Bogus {
}
And the injection in the EmailService (a @stateless session bean).
@Inject
@Bogus
private BogusBean bogus;
@EJB
private EmailRepository emailRepos;
@PostConstruct
public void init() {
bogus.setIt();
}
The NPE happens on the bogus.setIt() line. as bogus == null.
This is the maven config
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<version>1.1.11.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.core</groupId>
<artifactId>arquillian-core-api</artifactId>
<version>1.1.11.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.weld.arquillian.container</groupId>
<artifactId>arquillian-weld-ee-embedded-1.1</artifactId>
<version>1.1.2.Final</version>
</dependency>
I added a Profile for the glassfish embedded
<profile>
<id>arquillian-glassfish-embedded</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-glassfish-embedded-3.1</artifactId>
<version>1.0.0.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.main.extras</groupId>
<artifactId>glassfish-embedded-all</artifactId>
<version>3.1.2.2</version>
<!-- was 4.0 -->
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.23.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.23.2</version>
<scope>provided</scope>
</dependency>
</dependencies>
</profile>
I also tried to change from weld-ee to weld-se but then the container doesn't even start. (as stated here) : how-to-test-ejb-method-call-with-arquillian-weld-ee-embedded