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 the 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:
- You need to repeat all these lines in every build script you want to useArquillian and Wildfly.
- 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.
- If you want to test your code against several application servers you have the problem number 2 plus start dealing with profiles.
<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.
- 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)
Reference: | Arquillian Chameleon for the sake of simplicity from our JCG partner Alex Soto at the One Jar To Rule Them All blog. |