This page explains how to run Cactus tests with the Jetty servlet container. You will need the single Jetty jar, and if you are using JSPs you will also need the Jasper jars.
The idea is to use the
org.apache.cactus.extension.jetty.JettyTestSetup
JUnit
TestSetup class provided by Cactus so that Jetty is started before the
tests are run.
In order to use the TestSetup, you need to wrap your test suite in
JettyTestSetup
:
public class TestJettyAll extends TestCase { public static Test suite() { TestSuite suite = new TestSuite(); suite.addTestSuite(MyTestClass1.class); [...] suite.addTestSuite(MyTestClassN.class); return new JettyTestSetup(suite); }
You can configure the Jetty TestSetup either programatically or with system properties:
setConfigFile(File)
or the system property
cactus.jetty.config
sets the location of an optional
jetty.xml file (see Jetty's documentation for details).
setResourceDir(File)
or the system property
cactus.jetty.resourceDir
sets the directory containing
the web-application resources (expanded WAR). If you omit this step,
you'll only be able to use the Servlet Redirector.
JettyTestSetup
behavior. For example:
<junit> [...] <jvmarg value="-Dcactus.contextURL=http://localhost:${test.port}/test"/> <jvmarg value="-Dcactus.jetty.resourceDir=${src.webapp.dir}"/> <jvmarg value="-Dcactus.jetty.config=${src.webapp.dir}/test/jetty.xml"/> <classpath> [...] <!-- Include Jetty jar and optionally Jasper jars in the classpath --> <pathelement location="${jetty.jar}"/> <pathelement location="${jasper-compiler.jar}"/> <pathelement location="${jasper-runtime.jar}"/> </classpath> <test name="org.apache.cactus.sample.TestJettyAll"/> </junit>
Again all you have to do is add the correct VM arguments, and the Jetty and Jasper jars, to the JUnit launch.
For example in Eclipse you would add the jars, and create a JUnit launch configuration as below: