views:

1298

answers:

4

For now I have a web java project which builds automatically and deployed to the JBoss by just copying ear archive to server dir (all using Ant).

What I need is a mechanism how to no only automatically deploy application, but also to verify if application deployed successfully and run HttpUnit tests on it.

The problem is how to automatically monitor deployment process to wait for the moment when deployment is finished and only after that run tests. So I want to build, deploy, run tests in "one click" (i use Cruise Control for that).

I would be appreciate for any suggestion about resolving the problem.

+1  A: 

Create a base test class from which all other tests derive. It has to be abstract so the automatic unit test collector doesn't try to run it.

In that class, add this code to setUp():

if (checkIsDeployed) {
    ... run code to verify your app is ready for testing and wait until it is ...
    checkIsDeployed = true;
}

checkIsDeployed must be static.

Aaron Digulla
So the only way to verify deployment status is to "ping" my app, if no answer then wait and ping again for a some time?
andrey
Yes; there is no way to make your container send an event that the webapp is ready. Actually, you app is never "ready" since the container will try to defer loading as much as possible. That's why I never deploy and run all my tests inline using mockrunner.
Aaron Digulla
You can let a tool do it for you and run your tests once it has been done. See my answer on Cargo.
Pascal Thivent
A: 

Hi,

You could consider using hudson build engine: https://hudson.dev.java.net/ to help you fire off events at specific times.

I know hudson can be used to run unit tests and automatic deployment could be achived by calling ant.

Karl

Karl
+4  A: 

The need here is to start a container and to deploy an application from a build script before to run tests depending on the deployed application. This is a typical need for integration tests, end-to-end / functional tests, ui tests.

The problem is that we can't just "fire and forget" the launch of a container and run the test task/goal. We need to wait for the application to be deployed before to run the tests and this takes some time. To be sure we can run tests when things are ready, the build has to start the container and deploy the application in a blocking way.

This is exactly what Cargo is about. Cargo is a Java API to start/stop your container and deploy your application. It provides the logic described above and can be used from Java, Ant or Maven.

If you are using Maven, the build life cycle already includes something for you with the "integration-test" phase. This phase is typically used for... integration tests and is wrapped by the "pre-integration-test" and "post-integration-test" phases. This is where you would plug Cargo start/stop goals. If you are using Ant, you can use cargo's ant task.

Another option based on the maven is described in the Mavan Jetty Plugin Configuration Guide. The idea is exactly the same as above except that you use the jetty plugin instead of cargo to start jetty during the "pre-integration-test" and stop it during the "post-integration-test".

Pascal Thivent
Cargo 0.9 has problems to determine reliably whether Tomcat is running and the app is correctly deployed. I reverted to use my own script which could kill Tomcat, clean the webapps directory of any leftovers, etc.
Aaron Digulla
Really? Is it a known issue? This might of course be a bug but I never faced this problem with Cargo and Tomcat. Anyway, a bug wouldn't change Cargo's goal.
Pascal Thivent
Unfortunately Cargo doesn't support hot deployment over ant task for now, but that is the reason to add this support by myself.
andrey
I'm not sure what you mean by *hot deployment over ant task*. According to http://cargo.codehaus.org/Ant+support, you can deploy with Cargo's Ant task.
Pascal Thivent
+1  A: 

Another option is to use the JBoss Server Ant Tasks.

The nice thing about these tasks is that they will block until JBoss is fully started, so there is no polling required. They will also fail if JBoss fails to start in the required timeout, and will attempt to shut JBoss down at the JVM shutdown if you are unable to because of some error. I believe these tasks are used for the JBoss testsuite.

I've also heard good things about Cargo. The benefit of it is that your build scripts are not JBoss specific. I think the JBoss Cargo plugin is maintained by some JBoss guys, as far as I know.

recampbell