0
votes

I've been trying to execute an Arquillian Integration test on my "remote" localhost JBoss server (not embedded/managed), but my local EJB is not being injected.

pom.xml

<profile>
    <!-- An optional Arquillian testing profile that executes tests in a remote JBoss AS instance -->
    <!-- Run with: mvn clean test -Parq-jbossas-remote -->
    <id>arq-jbossas-remote</id>
    <dependencies>
        <dependency>
            <groupId>org.jboss.as</groupId>
            <artifactId>jboss-as-arquillian-container-remote</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
</profile>

ProductService.java:

@Stateless
@Local(IProductService.class)
public class ProductService implements IProductService {

ProductServiceIntegrationTest.java

@RunWith(Arquillian.class)
public class ProductServiceIntegrationTest {

    protected static final Logger logger = LoggerFactory.getLogger(ProductServiceIntegrationTest.class);

    @Rule
    public TestName testMethod = new TestName();

    @EJB
    public IProductService productService;

    //    @Deployment(order = 1, name = "keystone-ear", testable = false)
    //    public static Archive<?> createKeystoneServicesArchive() {
    //        return ShrinkWrap
    //                .create(ZipImporter.class, "keystone-ear.ear")
    //                .importFrom(new File("target/dependency/keystone-ear.ear"))
    //                .as(EnterpriseArchive.class);
    //    }
    //    
    //    @Deployment(order = 2, name = "stock-wiz-ear", testable = false)
    //    public static Archive<?> createStockWizEjbArchive() {
    //        return ShrinkWrap
    //                .create(ZipImporter.class, "stock-wiz-ear.ear")
    //                .importFrom(new File("target/dependency/stock-wiz-ear.ear"))
    //                .as(EnterpriseArchive.class);
    //    }

    @Deployment
    public static Archive<?> createConductorEjbArchive() {

        JavaArchive ejbModule = ShrinkWrap
                .create(ZipImporter.class, "conductor-ejb.jar")
                .importFrom(new File("target/dependency/conductor-ejb.jar"))
                .as(JavaArchive.class);

        ejbModule.deletePackage("za.co.fnb.cbs.conductor.component.camel");

        EnterpriseArchive ear = ShrinkWrap
                .create(ZipImporter.class, "conductor-ear.ear")
                .importFrom(new File("target/dependency/conductor-ear.ear"))
                .as(EnterpriseArchive.class);
        ear.delete("/conductor-ejb.jar");
        ear.delete("/controller-web.war");
        ear.addAsModule(ejbModule);
        System.out.println(ear.toString(true));
        return ear;
    }

    @Test
    public void shouldBeInjected() throws Exception {
        Assert.assertNotNull(productService);
    }

}

I've commented out the two additional deployments which are dependencies for my integration test. I manually deployed the dependencies to the server prior to executing the test. Irrespective, I can't seem to get it working.

I've also tried specifying the JNDI mapped name as follows:

@EJB(mappedName = "java:global/conductor/conductor-ejb/ProductService!za.co.fnb.cbs.conductor.api.smartdevices.services.IProductService")
public IProductService productService;

I've also tried looking up the EJB via context...

@Before
public void before() throws Exception {
    Properties jndiProps = new Properties();
    jndiProps.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
//            env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.as.naming.InitialContextFactory");
    jndiProps.put(Context.PROVIDER_URL, "remote://localhost:4447");
    initialContext = new InitialContext(jndiProps);
    productService = (IProductService)initialContext.lookup("java:module/ProductService!za.co.fnb.cbs.conductor.api.smartdevices.services.IProductService");
}

I've also tried CDI injection, and placed beans.xml on test resource classpath, as well as main classpath. No luck.

Is Arquillian capable of running integration tests on EnterpriseArchive's? From my experience, this doesn't seem to be the case.

All the examples I've come across involve creating a small JavaArchive with one or two classes. This doesn't work for me. I have to deploy an EAR because of all the dependencies required.

1
I gave up on Arquillian, and eventually was able to test my EJB via remote invocation, following this article: blog.jonasbandi.net/2013/08/… - Enrico Goosen

1 Answers

0
votes

An EJB is a managed bean. If its null that means its not injected, a possible cause of that could be a JMX timeout, meaning the MBean server didn't response in time to the request, All I'm saying is increase the JMX time out and give it a bash xxxxxxx .