Jan 152016

Testing Liferay plugins is not an easy task. Nowadays, integration tests in Liferay are easier using Arquillian. Arquillian is an innovative and highly extensible testing platform for the JVM that enables developers to easily create automated integration, functional and acceptance tests for Java middleware. In this post we are going to write the steps you need to follow in order to Arquillian works and we will also describe some of the errors that you could find.

Basically, you have to take into account:

  1. Review your Tomcat
    1. Is JMX enabled on Tomcat?
    2. Is tomcat-users configured?
    3. Is tomcat’s manager installed?
  2. Review your plugin
    1. Does the arquillian.xml exist in the plugin’s test classpath?
    2. Does the arquillian.xml point to the tomcat (URL and port)?
    3. Is IVY resolving arquillian dependencies, and putting them into your classpath?
    4. Do you have “SDK/portlets/my-portlet/test/integration” as folder structure?
  3. Before testing your plugin, is Tomcat running?

Reviewing your Tomcat

Firstly, you have to configure our Tomcat. In theory, you can configure your Tomcat running ant setup-testable-tomcat on root folder of plugins SDK, only the first time you start with sdk. However, I have to say that it didn’t work for me, and it was difficult to find this ant task. I had to look for it on the Internet and when I run it I got several errors. In the end, I had to set up each file manually.

For enabling JMX on Tomcat, go to TOMCAT_HOME/bin directory and add this line after original CATALINA_OPTS definition:

If you prefer, you can also, change directly your setenv.sh (or setenv.bat) and add

However, because I work with Eclipse Liferay IDE, I put this line in the configuration of my Liferay Server (clicking on Open launch configuration).

Secondly, you need to configure tomcat’s manager users and roles. Modify your tomcat-users.xml with this

Thirdly, you have to install Tomcat’s manager as web application under webapps. You can download it from here.

Then you have to untar the file under webapps directory. The result is:

Arquillian communicates with this application to deploy your tests on the container.

Now check that manager application works. For that, go to http://localhost:8080/manager and use the credential tomcat/tomcat. If everything is ok, you will a list of yourt applications in your Tomcat.

If something is wrong with manager application, when you test your plugin, you can get an error similar to:

Reviewing your plugin

You have to configure your pluging to use arquillian, executing ant setup-arquillian on root folder of your plugin. I didn’t do that. You can configure your plugin manually or, better, you can create your plugin using Liferay IDE wizard. When you create a plugin with Liferay IDE (version 2.2.5-ga5), the wizard

  1. will create for you the archive arquillian.xml under /test/integration, to define the credentials to log in the tomcat’s manager
  2. and will add Arquillian dependencies in ivy.xml

The arquillian.xml should be similiar to:

Perhaps you need add host and httpPort properties if your tomcat is not at localhost:8080.

By default, your ivy.xml will have the following dependencies:

However, you must upgrade arquillian version to 1.0.1 or 1.0.2. For example, your ivy.xml should be

If you don’t upgrade arquillian version, you will get an error similar to:

Needless to say, you will need a JUnit dependency such as, for example,

Creating a test class under test/integration folder

A regular class to be tested with Arquillian could be

Notice you need @RunWith(Arquillian.class). You don’t need to use @Deployment annotation in any method.
Before testing your class, Tomcat must be running. Don’t deploy your plugin: Arquillian will deploy and undeploy it for you.

After starting up Tomcat, check that port JMX 8099 is open and listing

When you run your test from Eclipse

in Tomcat’s console the log is similar to

and the log in our JUnit console is

Testing on Windows

If you are testing your Liferay plugins on Windows you may get the following error

The method in WebArchiveBuilder class where the exception is thrown is

The error occurs because in Windows does not exist ant.exe executable file; there is only the ant.bat file. If you don’t specify a file extension, ProcessUtil.execute will only run archives with extension .exe. So you need to convert your ant.bat into ant.exe and, obviously, ant.exe must be in your path (environment variable). For this conversion, you can use several programs, such as http://www.battoexeconverter.com/

Files under a standard apache-ant-1.9.1/bin directory, with a new ant.exe file.

IMHO, I think that the method build() in WebArchiveBuilder class should check the current operating system. If the os is Windows, ProcessUtil.execute should run ant.exe instance of ant.

More information

You can get more information at the following links:








Sorry, the comment form is closed at this time.