Enterprise Java

Arquillian Chameleon for the sake of simplicity

When using Arquillian, one of the things you need to do is defining under which container you want to execute all your tests.

And this is done by adding a dependency in the classpath for the adapter and depending on the mode used (embedded, managed or remote) having to download tchameleon-sleepy-jpg-adapt-945-1he application server manually. For example this happens when Wildfly is used in embedded or managed mode.

 

An example of a pom.xml using Wildfly could be:

<dependencies>
  <dependency>
    <groupId>org.wildfly</groupId>
      <artifactId>wildfly-arquillian-container-managed</artifactId>
      <version>${version.org.wildfly}</version>
      <scope>test</scope>
  </dependency>
</dependencies>

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-dependency-plugin</artifactId>
      <executions>
        <execution>
          <id>unpack</id>
          <phase>process-test-classes</phase>
          <goals>
            <goal>unpack</goal>
          </goals>
          <configuration>
            <artifactItems>
              <artifactItem>
                <groupId>org.wildfly</groupId>
                <artifactId>wildfly-dist</artifactId>
                <version>${version.org.wildfly}</version>
                <type>zip</type>
                <overWrite>false</overWrite>
                <outputDirectory>${project.build.directory}</outputDirectory>
             </artifactItem>
            </artifactItems>
          </configuration>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

Notice that in previous script, you need to define the Arquillian adapter, in this case the managed one, and use maven-dependency-plugin to download Wildfly distribution file used by Arquillian.

This approach is good and it works, but it has three drawbacks:

  1. You need to repeat all these lines in every build script you want to useArquillian and Wildfly.
  2. In case you need to use another application server in another project, you need to know which adapter artifact is required and if it is necessary to download  the artifacts or not. For example in case of Jetty embedded it is not necessary to download any distribution, you only need set the embedded dependency.
  3. If you want to test your code against several application servers you have the problem number 2 plus start dealing with profiles.
But all these problems can be fixed using Arquillian Chameleon. Arquillian Chameleon is a generic container which reads from arquillian.xml which container, which version and which mode you want to use in your tests, and he will take care of adding required adapter into classpath, download any required distribution and configure the protocol (this is something that as a user you should not touch).
How to use Arquillian Chameleon is pretty easy. Do whatever you would do normally such as adding Arquillian bom and add Chameleon Container instead of any application-server specific artifact:
<dependency>
  <groupId>org.arquillian.container</groupId>
  <artifactId>arquillian-container-chameleon</artifactId>
  <version>1.0.0.Alpha7</version>
  <scope>test</scope>
</dependency>

Then create in src/test/resources the Arquillian configuration file calledarquillian.xml with next configuration:

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

    <container qualifier="chameleon" default="true">
        <configuration>
            <property name="chameleonTarget">wildfly:9.0.0.Final:managed</property>
        </configuration>
    </container>

</arquillian>

Notice that now you only need to use a friendly property called chameleonTarget to define which container, version and mode you want to use. In previous exampleWildfly 9.0.0.Final with managed adapter.

When running any test with this configuration, Chameleon will check if Wildfly 9.0.0.Final distribution is downloaded, and if not download it, then will add to classpath the managed adapter for Wildfly 9.0.0 and finally execute the test as any other Arquillian test.

What’s happening if you want to use Payara instead of Wildfly? You only need to change chameleonTarget property to payara:4.1.1.163:managed, to for example run tests against Payara 4.1.1 in managed mode.

TIP: You can set this property using a Java system property (-Darq.container.chameleon.chameleonTarget = payara:4.1.1.163:managed)Currently next containers are supported by Chameleon:

  • JBoss EAP 6.x, 7.x
  • WildFly 10.x, 9.x, 8.x
  • JBoss AS 7.x
  • GlassFish 3.1.2, 4.x
  • Payara 4.x

We keep learning,
Alex.

I can see you, Your brown skin shining in the sun, I see you walking real slow(The boys of summer – The Ataris)

Music: https://www.youtube.com/watch?v=Qt6Lkgs0kiU

Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Back to top button