import junit.extensions.TestSetup;
import junit.framework.Test;
[...]
public class CargoTestSetup extends TestSetup
{
InstalledLocalContainer container;
public CargoTestSetup(Test test)
{
super(test);
}
protected void setUp() throws Exception
{
// (1) Optional step to install the container from a URL pointing to its distribution
Installer installer = new ZipURLInstaller(
new URL("http://archive.apache.org/dist/tomcat/tomcat-6/v6.0.32/bin/apache-tomcat-6.0.32.zip"));
installer.install();
// (2) Create the Cargo Container instance wrapping our physical container
LocalConfiguration configuration = (LocalConfiguration) new DefaultConfigurationFactory().createConfiguration(
"tomcat6x", ContainerType.INSTALLED, ConfigurationType.STANDALONE);
InstalledLocalContainer container =
(InstalledLocalContainer) new DefaultContainerFactory().createContainer(
"tomcat6x", ContainerType.INSTALLED, configuration);
container.setHome(installer.getHome());
// (3) Statically deploy some WAR (optional)
configuration.addDeployable(new WAR("cargo.war"));
// (4) Start the container
container.start();
}
protected void tearDown() throws Exception
{
// (6) Stop the container
container.stop();
}
}