Liferay 6.2 Integration Tests with Arquillian and maven

Posted on 06/06/2016 by Charalampos Chrysikopoulos

At last, after almost two years, I managed finally to make the integration tests work. And it is not so complicated as it seems to be. So straight to the point. I needed to enabled integration tests in Liferay 6.2EE SP14, but, I think, the steps are the same for all the 6.2 versions (also the CE). Arquillian is a framework that help us to run our test in the liferay portal, so we don't need to mock it. So, we need to configure our installation to work with arguillian. I suppose we have a tomcat installed on our system. We need to make some configurations to that tomcat, so arquillian can communicate with it and deploy its stuff.

Configure Tomcat

Installing Manager If you look at the webapps directory of your tomcat, per default, the manager web application is missing. You can add it, simple, by downloading the same tomcat version and from its webapps directory you can copy the manager folder back to you tomcats webapps directory. Setting users Having the manager web application installed, we need to define a user, that arquillian will be use, to deploy its plugins, by using the manager. To achieve this, we need to define a user with the appropriate roles. So, we need to edit the file tomcat-users.xml in TOMCAT_DIR/conf directory. In there we need to insert the following xml:

[cc lang="xml"] <!--?xml version="1.0"?--> <tomcat-users> <role rolename="tomcat"> <role rolename="manager-gui"> <role rolename="manager-script"> <role rolename="manager-jmx"> <role rolename="manager-status"> <user password="tomcat" roles="tomcat,manager-gui,manager-script,manager-jmx,manager-status" username="tomcat"> </user></role></role></role></role></role></tomcat-users> [/cc]

Enabling JMX Now, we need to enable JMX in tomcat. We edit the (or setenv.bat for windows) file in TOMCAT_DIR/bin directory. I replaced the content with the following:  CATALINA_OPTS="$CATALINA_OPTS -Dfile.encoding=UTF8 -Dorg.apache.catalina.loader.WebappClassLoader.ENABLE_CLEAR_REFERENCES=false -Duser.timezone=GMT -Xmx1024m -XX:MaxPermSize=256m" Now, the tomcat configuration has been set.

Configure Maven

In our plugin we need to add some dependencies. We will use the arquillian-liferay-maven-extension. In the plugins pom.xml file I added the following:  ... <dependencymanagement> <dependencies> <dependency> <groupid>org.jboss.arquillian</groupid> <artifactid>arquillian-bom</artifactid> <version>1.1.5.Final</version> <scope>test</scope> <type>pom</type> </dependency> </dependencies> </dependencymanagement> <dependencies> <dependency> <groupid>org.arquillian.liferay.maven</groupid> <artifactid>arquillian-liferay-maven-extension</artifactid> <version>1.0.0.Alpha2</version> <scope>test</scope> </dependency> <dependency> <groupid>org.jboss.arquillian.junit</groupid> <artifactid>arquillian-junit-container</artifactid> <version>1.1.5.Final</version> <scope>test</scope> </dependency> <dependency> <groupid>org.jboss.arquillian.container</groupid> <artifactid>arquillian-tomcat-remote-7</artifactid> <version>1.0.0.CR7</version> <scope>test</scope> </dependency> .... <dependencies> ...

Configure Arquillian

We need to give arquillian the information, where it can run the tests. So, we add the file arquillian.xml in the folder src/test/java/integration. In the file we add following XML:  <arquillian xmlns="" xmlns:xsi="" xsi:schemalocation=""> <container default="true" qualifier="tomcat"> <configuration> <property name="jmxPort">8099</property> <property name="host">localhost</property> <property name="httpPort">8080</property> <property name="user">tomcat</property> <property name="pass">tomcat</property> </configuration> </container> </arquillian> Here we are using all the previous things we configured.

The integration test

Now, we are ready to write our integration test. Lets assume, we have a custom Entity with the name SomeEntity. Lets try the following in our plugin project. We create a new class SomeEntityLocalServiceUtilTest in src/test/java/somewhere/service/impl.  import somewhere.service.model.SomeEntity; import somewhere.service.service.SomeEntityLocalServiceUtil; import org.junit.After; import org.junit.Assert; import org.junit.Before; @RunWith(Arquillian.class) public class SomeEntityLocalServiceUtilTest { @Test public void test() { int count = SomeEntityLocalServiceUtil.getSomeEntitiesCount(); Assert.assertTrue(count == 0); } }

Run the test

At last, we can now see, if our test works. Don't forget, the tomcat should be running. Let's run the test: [cc] mvn test [/cc] We should see how arquillian builds the plugin, deploys it on the portal, run the test and undeploys it again.


  • It seems to be correct to have a test server to run your tests. Not only for the db data, but arquillian deploys and then undeploys the plugins you want to test. So, while developing, perhaps you make also your own deployments in the portal, and this could create unwanted conflicts.
  • Sometimes I get java.lang.OutOfMemoryError: PermGen space. I didn't solve it yet. It seems, that arquillian starts a jvm (with surefire), and I couldn't find a way to define memory parameters there.
  • Running the tests from jenkins, there was a problem with a library, so I needed to add the following dependency in the pom.xml file:  <dependency> <groupid>biz.aQute.bnd</groupid> <artifactid>bnd</artifactid> <version>2.4.0</version> </dependency>


This entry was posted in Liferay and tagged arguillian, integration-test, liferay 6.2, test by Charalampos Chrysikopoulos

Add new comment