Arquillian Faqs

In this article I'm including a list of common questions related to Arquillian integration testing framework

How to create a WAR deployment with Arquillian

In the following example you can see how to create a War deployment which includes a custom Manifest file (with Dependencies), plus a file into the WEB-INF folder and the Web classes:

@Deployment
public static WebArchive createWarDeployment() {
      WebArchive archive = ShrinkWrap.create(WebArchive.class, "web.war");
         archive
               .setManifest(new StringAsset("Manifest-Version: 1.0\n"
                     + "Dependencies: org.apache.activemq.artemis")
               .addAsWebInfResource(new File(JBossWSTestHelper.getTestResourcesDir() + "/jaxws/cxf/jms/META-INF/wsdl/HelloWorldService.wsdl"), "classes/META-INF/wsdl/HelloWorldService.wsdl")
               .addClass(org.jboss.test.ws.jaxws.cxf.jms.DeploymentTestServlet.class)
               .addClass(org.jboss.test.ws.jaxws.cxf.jms.HelloWorld.class);
      return archive;
 }

How to create a JAR deployment with Arquillian

In the following example you can check how to create a JAR deployment which includes as well a custom Manifest file:

@Deployment
public static JavaArchive createJarDeployment() {
      JavaArchive archive = ShrinkWrap.create(JavaArchive.class,"ejb.jar");
         archive
               .setManifest(new StringAsset("Manifest-Version: 1.0\n"
                     + "Dependencies: org.apache.activemq.artemis")
               .addClass(org.jboss.test.ws.jaxws.cxf.jms.HelloWorld.class)
               .addClass(org.jboss.test.ws.jaxws.cxf.jms.HelloWorldImpl.class);
      return archive;
}

How to determine the order of deployments with Arquillian

In case you have multiple deployment to be used with Arquillian, you can specify the deployment order with the parameter "order" of the @Deployment annotation:

@Deployment(name="ejb-deployment", order=1)
public static JavaArchive createJarDeployment() {
      JavaArchive archive = ShrinkWrap.create(JavaArchive.class,"ejb.jar");
         archive
               .setManifest(new StringAsset("Manifest-Version: 1.0\n"
                     + "Dependencies: org.apache.activemq.artemis")
               .addClass(org.jboss.test.ws.jaxws.cxf.jms.HelloWorld.class)
               .addClass(org.jboss.test.ws.jaxws.cxf.jms.HelloWorldImpl.class);
      return archive;
}

How does Arquillain find an embedded WildFly ?

You have two options: one is setting the environment variable JBOSS_HOME to path to jBoss installation. Otherwise, a tag property should be added to arquillian.xml inside a container tag:

<arquillian xmlns="http://jboss.org/schema/arquillian"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://jboss.org/schema/arquillian
    http://jboss.org/schema/arquillian/arquillian_1_0.xsd">

<container qualifier="jboss" default="true">
    <configuration>
        <property name="jbossHome">/path/to/jboss</property>
    </configuration>
</container>

How do you configure the JVM Parameters of the application server with Arquillian ?

In your arquillian.xml you can add the configuration it tell Wildfly or other application server which xml config to use:

<container qualifier="jboss" default="true">
    <configuration>
        <property name="jbossHome">${jboss.home}</property>
        <property name="serverConfig">standalone-full.xml</property>
       
        <property name="javaVmArguments">-Xmx512m -XX:MaxPermSize=128m -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8787</property 
    </configuration>
</container>

How to perform deploy/undeploy of Arquillian archives programmatically ?

This can be done using the Deployer service which can be in turn injected as @ArquillianResource. See the following example:

@Deployment(name = "App-1", managed = false)
public static WebArchive create() {
  return ShrinkWrap.create(JavaArchive.class);
}

@ArquillianResource
private Deployer deployer;

@Test
public void should_work() {
  deployer.deploy("App-1");
   
  deployer.undeploy("App-1");
}

 

Follow us on Twitter