Arquillian is a really good framework for integration tests and it eases a lot the testing of your application. But what can it do when you need several containers (let say you have 2 different containers)?
Aslak Knutsen pointed me out arquillian was already supported it! It was so good i had to test.
The result is a very simple sample which shows how to make it work with TomEE: multiple-tomee-arquillian
The idea is to define a group of tomees (let’s say a cluster ;)). Then to add in your test class the name of the container to use to deploy the application defined by the archive the method returns (the next sample will make everything clear).
Then the question is how to get the url of the application (for a webapp)? Here again arquillian manages it: @ArquillianResource can inject the url corresponding to the webapp. There are two ways: either injecting it as a field, here it needs the container qualifier (a bit complicated for nothing) or to inject it as a method parameter (easy since it needs nothing more).
So let’s see a sample. Here web archives are really simple since they only contain an index.html (but it proves it works ;)):
In the java test class important points are:
- don’t forget the (now classical) Arquillian runner
- give a name to your deployment (@Deployment)
- if you want to inject the url add testable=false to deployment annotation
- specify the container where to deploy the archive using @TargetsContainer
- on test method specify which deployment it targets with @OperateOnDeployment
@RunWith(Arquillian.class) public class MultipleTomEETest { @Deployment(name = "war1", testable = false) @TargetsContainer("tomee-1") public static WebArchive createDep1() { return ShrinkWrap.create(WebArchive.class, "application1.war") .addAsWebResource(new StringAsset("Hello from TomEE 1"), "index.html"); } @Deployment(name = "war2", testable = false) @TargetsContainer("tomee-2") public static WebArchive createDep2() { return ShrinkWrap.create(WebArchive.class, "application2.war") .addAsWebResource(new StringAsset("Hello from TomEE 2"), "index.html"); } @Test @OperateOnDeployment("war1") public void testRunningInDep1(@ArquillianResource final URL url) throws IOException { final String content = IO.slurp(url); assertEquals("Hello from TomEE 1", content); } @Test @OperateOnDeployment("war2") public void testRunningInDep2(@ArquillianResource final URL url) throws IOException { final String content = IO.slurp(url); assertEquals("Hello from TomEE 2", content); } }
In arquillian.xml simply define a group of classical container configurations.
<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"> <group qualifier="tomee-cluster"> <container qualifier="tomee-1"> <configuration> <property name="httpPort">-1</property> <property name="stopPort">-1</property> <property name="ajpPort">-1</property> <property name="version">1.0.0-beta-3-SNAPSHOT</property> <property name="dir">target/apache-tomee-remote-1</property> <property name="appWorkingDir">target/arquillian-test-working-dir-1</property> </configuration> </container> <container qualifier="tomee-2"> <configuration> <property name="httpPort">-1</property> <property name="stopPort">-1</property> <property name="ajpPort">-1</property> <property name="version">1.0.0-beta-3-SNAPSHOT</property> <property name="dir">target/apache-tomee-remote-2</property> <property name="appWorkingDir">target/arquillian-test-working-dir-2</property> </configuration> </container> </group> </arquillian>
So now you can test in TomEE your application even if it needs several instances :).
To conclude i would like to thank Aslask Knutsen for his help regarding this topic.
Excellent items from you, man. I’ve keep in mind your stuff prior to and you are just too excellent. I really like what you’ve received here, really like what you’re saying and the way in which by which you assert it. You make it enjoyable and you still care for to keep it wise. I cant wait to learn far more from you. This is actually a wonderful site.