Saturday, May 30, 2009

Maven integration test

I m currently doing some functional tests using a great build tool Maven (this also has been used much by Atlassian developer) on my Confluence plugin. Yep, as usualy, i got a problem on my test :P. I found there is a "Class not found exception" on the log file. The class that could not be found is JSONObject which is from json-lib. I was wondering how could this be happening. Then, I checked the classpath of my integrationt test. Forgot to mention that I use cargo to startup Tomcat for my functional test.


Checking on the classpath, i could not find any json-lib library. I thought that it is added automatically as I have specified the dependency of my plugin, but in fact it is not. Thus, what I did is to copy the dependency so that the error does not reoccur anymore. Maven defines 3 phases on integration test, they are pre integration test, integration test and post integration test. I didnt choose one of them but I choose phase package. 
This phase will be executed before pre integration test. The first time I was trying pre-integration phase, it does not work. Thus, I pick the phase before executing integration phase and the result it works like a charm.

The following is the code that I have:

There is a few ways to copy any data to any directory using maven. A few plugins available to do that. You can use maven-antrun-plugin, you can reference to maven documentation about plugins availabe.

TargetClassLoaderTransactionProxyFactoryBean vs TransactionProxyFactoryBean

I had an experience on some error which tells me that the Confluence cannot find the interface that I use for TransactionProxyFactoryBean, interface is needed by this class to perform transaction. I checked on my code and directory where my code is compiled, to see whether the interface that Confluence complains to, does actually exist or not.


Checking those things, I was sure that all the things are there, but Confluence keeps complaining about the error. Then, I asked uncle google and found a jira issue saying about Confluence's bug regarding this matter. It also says about the replacement class of TransactionProxyFactoryBean which is TargetClassLoaderTransactionProxyFactoryBean. After changing this class, all the things are working fine. It seems that there is a classloader problem (it is definitely as Confluence cannot find the class file :P )