Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

For manipulating the various type of application containers (Java EE and others), Cargo has two types of containers:

  • An installed container means you have the container available as an installation (either locally on the machine or "locally" to the Cargo Daemon). In this case, the typical build / test cycle would be:
    1. Perform any preparations you need to in order to create your deployables
    2. Use Cargo to start the container (which will actually configure, start and deploy your deployable(s))
    3. Perform any actions you want to do on the container
    4. Use Cargo to stop the container
  • A remote container means you have the container running (usually, on another machine). In this case, the typical build / test cycle would be:
    1. Perform any preparations you need to in order to create your deployables
    2. Use Cargo to perform a remote deployment to the container
    3. Perform any actions you want to do on the container
    4. Use Cargo to undeploy your deployables

Of course, Cargo is not limited to testing - You can also use it to configure, package or remotely handle many containers.

The following examples demonstrate how to configure Resin 3.0.15 to start in target/resin3x and deploy a WAR located in path/to/simple.war using the Java API. The default port is 8080. Please note that the container.start() and container.stop() methods wait until the container is fully started and fully stopped before continuing. Thus, for any action you are executing after, you are assured the container is completely operational.

...

Static deployment means that the Deployable is deployed before the container is started. Here's an example using the strongly typed Java API: Wiki Markup{snippet:lang=java|id=qs-typed|url=https://raw.githubusercontent.com/codehaus-cargo/cargo/master/core/documentation/src/main/java/org/codehaus/cargo/documentation/Snippets.java}

Code Block
languagejava
Deployable war = new WAR("path/to/simple.war");

// START SNIPPET: configuration-typed-resin3x
LocalConfiguration configuration =
    new Resin3xStandaloneLocalConfiguration("target/myresin3x");
// END SNIPPET: configuration-typed-resin3x
configuration.addDeployable(war);

InstalledLocalContainer container =
    new Resin3xInstalledLocalContainer(configuration);
container.setHome("c:/apps/resin-3.0.18");

container.start();
// Here you are assured the container is started.

container.stop();
// Here you are assured the container is stopped.

Here's the same example using the generic untyped API (which we recommend as it leads to more generic code): Wiki Markup{snippet:lang=java|id=qs-untyped|url=https://raw.githubusercontent.com/codehaus-cargo/cargo/master/core/documentation/src/main/java/org/codehaus/cargo/documentation/Snippets.java}

Code Block
languagejava
Deployable war = new DefaultDeployableFactory().createDeployable(
    "resin3x", "path/to/simple.war", DeployableType.WAR);

ConfigurationFactory configurationFactory =
    new DefaultConfigurationFactory();
LocalConfiguration configuration =
    (LocalConfiguration) configurationFactory.createConfiguration(
"resin3x", ContainerType.INSTALLED, ConfigurationType.STANDALONE);
configuration.addDeployable(war);

InstalledLocalContainer container =
    (InstalledLocalContainer) new DefaultContainerFactory().createContainer(
"resin3x", ContainerType.INSTALLED, configuration);
container.setHome("c:/apps/resin-3.0.18");

container.start();
// Here you are assured the container is started.

container.stop();
// Here you are assured the container is stopped.


Hot deployment

Hot deployment means that the Deployable is deployed after the container is started. Wiki Markup{snippet:lang=java|id=qs-deploy|url=https://raw.githubusercontent.com/codehaus-cargo/cargo/master/core/documentation/src/main/java/org/codehaus/cargo/documentation/Snippets.java}

Code Block
languagejava
InstalledLocalContainer container = new Resin3xInstalledLocalContainer(
    new Resin3xStandaloneLocalConfiguration("target/myresin3x"));
container.setHome("c:/apps/resin-3.0.18");

container.start();

// Here you are assured the container is started.

Deployable war = new WAR("path/to/simple.war");
Deployer deployer = new ResinInstalledLocalDeployer(container);
deployer.deploy(war);

// Here you are NOT sure the WAR has finished deploying. To be sure you
// need to use a DeployableMonitor to monitor the deployment. For example
// the following code deploys the WAR and wait until it is available to
// serve requests (the URL should point to a resource inside your WAR):
deployer.deploy(war, new URLDeployableMonitor(
    new URL("http://server:port/some/url")));

container.stop();

// Here you are assured the container is stopped.


Functional tests

For a detailed documentation on how to use Cargo for executing functional tests on a container, directly from your Java unit test classes (JUnit, TestNG, etc), read our Functional testing page.