DeploymentScenario scenario = deploymentScenario.get();
if(scenario == null)
{
throw new IllegalArgumentException("No deployment scenario in context");
}
ContainerRegistry registry = containerRegistry.get();
if(registry == null)
{
throw new IllegalArgumentException("No container registry in context");
}
Deployment deployment = scenario.deployment(new DeploymentTargetDescription(name));
if(deployment == null)
{
throw new IllegalArgumentException("No deployment in context found with name " + name);
}
if (deployment.getDescription().managed())
{
throw new IllegalArgumentException("Could not deploy " + name + " deployment. The deployment is controlled by Arquillian");
}
Container container = registry.getContainer(deployment.getDescription().getTarget());
if (!container.getState().equals(State.STARTED))
{
throw new IllegalArgumentException("Deployment with name " + name + " could not be undeployed. Container " +
container.getName() + " must be still running.");