Arquillian OpenEJB: deploy and forget archives


Arquillian is great but when testing always on the same app, in a single thread in embedded mode it is a pain to deploy the app for each class.

You can create your own extension as shown by Aslask (https://gist.github.com/3975179) but you need to code it.

If you need the arquillian features that’s probably the best way to go but if you just want to deploy the app OpenEJB has a hack too (probably easier).

This one is mainly intended to deploy an Archive<?> (potentially created by ShrinkWrap) when the container starts. Then you can use it as a client (that’s really great for REST or SOAP testing) and with some server features (basically cdi injection in the context of a single deployment application).

You simply have to define the property openejb.arquillian.predeploy-archives in “properties” attribute of openejb container in arquillian.xml. The value is a comma separated list of qualified name. Then the class is parsed to find all public static methods annotated @Deployment then the archive is deployed.

Here an example:

<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="openejb" default="true">
    <configuration>
      <property name="properties">
        openejb.arquillian.predeploy-archives = org.superbiz.archives.[SimpleArchive|SimpleArchive2]
      </property>
    </configuration>
  </container>
</arquillian>

The SimpleArchive simply contains the method:

@Deployment
public static WebArchive simple() {
    return ShrinkWrap.create(WebArchive.class, "simple.war")
            .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
            .addClass(SimpleBean.class);
}
Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s