Arquillian has support for multiple injection points like @EJB, @Resources and @Inject, but there are also non standard component model objects available within the Arquillian runtime that can be of useful during testing. In this tutorial we will learn how to expose these objects to the test case using the @ArquillianResource injection annotation.

By using the @ArquillianResource injection you can expose multiple internal objects such as Containers or Deployments which will be handled programmatically by your Test case.

Let's see an example of it:

package com.itbuzzpress.chapter8.test;

import java.util.List;

import org.jboss.arquillian.container.test.api.*;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.junit.Before;
import org.junit.Test;

import javax.inject.Inject;

import static org.junit.Assert.*;

import org.jboss.arquillian.junit.Arquillian;

import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;

import org.junit.runner.RunWith;

import com.itbuzzpress.chapter8.ejb.ManagerEJB;
import com.itbuzzpress.chapter8.entity.Customer;
import com.itbuzzpress.chapter8.entity.Request;
import org.jboss.arquillian.junit.InSequence;

public class TestJPA {

 @Inject ManagerEJB ejb;

 private ContainerController controller;

 private Deployer deployer;

 public void before() throws Throwable {
  System.out.println("Before Test");
 @Deployment(name = "deploy-0", managed = false)

 public static Archive < ? > createTestArchive() {
  return ShrinkWrap.create(WebArchive.class, "testjpa.war")
   .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");


 public void startServer() {

 public void stopServer() {


 public void test() {
  try {

   ejb.createCustomer("john", "park avenue 125", "", "+3955555");
   Customer customer = ejb.findCustomerByName("john");
   List < Customer > cc = ejb.findAllCustomers();
   ejb.createRequest("john", 100);

   List < Customer > customerList = ejb.findAllCustomers();

   log("=======> Customer List ");
   for (Customer c: customerList) {
    log("Customer found: " + c);
    log("============> Request Accociated:");
    List < Request > requestList = ejb.findAllRequestsByCustomer(c.getName());
    for (Request r: requestList) {
     log("Request found: " + r);

  } catch (Exception e) {
   // TODO Auto-generated catch block

 private void log(String string) {



This Test class is derived from the TestJPA class contained in the Practical Java EE Development with WildFly. Compared with the source code available on github ( we have changed a couple of things:

First of all, the application server is not started/stopped automatically by Arquillian but you can control it by injecting the Application server as an @ArquillianResource:

private ContainerController controller;

Next, also the Deployment of applications is managed programmatically by injecting another @ArquillianResouce:

private Deployer deployer;

Finally, notice that in order to guarantee that the @Test are run in the proper order (at first the application server is started, then the application is deployed and finally the test() method is executed), we have decorated our @Test with @Insequence annotation:


As you can see, we have referenced our Container by using the node-0 alias. This needs to be defined in arquillian.xml where you specify the Container type and configuration:

<arquillian xmlns=""

	<defaultProtocol type="Servlet 3.0" />

	<container qualifier="node-0" mode="manual" default="true"  >

			<property name="jbossHome">/home/jboss/wildfly-12.0.0.Final</property>
			<property name="managementPort">9990</property>
			<property name="managementAddress">localhost</property>