angryip
angryip

Reputation: 2300

Conditional Deployment in Arquillian

Looking at the Arquillian documentation, I am aware that I can use the @ArquillianSuiteDeployment and @Deployment annotations to deploy my desired jars/wars to the container. Example:

@ArquillianSuiteDeployment
public class MyDeployer {

    @Deployment(name = "myapp", order = 1, testable = false)
    public static Archive<?> myDeploymentJar() {
        final File file = Maven.configureResolver().fromFile(System.getProperty("settings.xml"))
            .loadPomFromFile("pom.xml").resolve("com.myapp:test-app").withoutTransitivity()
            .asSingleFile();
        final JavaArchive jar = ShrinkWrap.createFromZipFile(JavaArchive.class, file);
        final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "test-app.jar").merge(jar);
        return archive;
    }
}

Let's infer that I have two more jars that I would like to deploy, but never together during the same test, JAR-A and JAR-C.

@Test
@RunAsClient
public void testOne() {
    // deploy JAR-A before all others, but do not deploy JAR-C
}

@Test
@RunAsClient
public void testTwo() {
    // deploy JAR-C before all others, but do not deploy JAR-A
}

Is it possible to introduce a conditional @Deployment that would go along with my tests?

Upvotes: 3

Views: 785

Answers (1)

bartosz.majsak
bartosz.majsak

Reputation: 1064

That's an interesting usecase.

Deployments happen before execution of the tests so it's not possible at the moment to achieve it just by using annotations.

You can, however, programmatically control deployments using Deployer service.

@Deployment(name = "JAR-C", managed = false)
public static WebArchive create() {
  return ShrinkWrap.create(JavaArchive.class);
}

@ArquillianResource
private Deployer deployer;

@Test
public void should_work() {
  deployer.deploy("JAR-C");
  // test
  deploy.undeploy("JAR-C");
}

Important fact is that you have to instruct Arquillian to not manage this deployment for you, that's what managed = false flag is for in @Deployment(name = "X", managed = false).

Hope that helps.

Upvotes: 2

Related Questions