javajboss-arquillianshrinkwrap

Multiple deployment methods in one test class


I'm trying to test a legacy application using TestNG and Arquillian. There is a constrain due to which I need to have two different methods annotated with @Deployment.

Method 1 (For deploying only the test code and run it against the application, already deployed and running in WildFly 10)

    @Deployment
    public static WebArchive createDeployment() {
        WebArchive war = ShrinkWrap.create(WebArchive.class).addClass(Test.class)
                .addAsManifestResource(new File("jboss-deployment-structure.xml"))
                .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
        return war;
    }

Method 2 (For deploying the whole application along with the test code to a remote WildFly 10 server)

    @Deployment
    public static EnterpriseArchive createEARDeployment(){
        EnterpriseArchive ear = ShrinkWrap.createFromZipFile(EnterpriseArchive.class, new File("some_archive.ear"))
                .addAsModule(Testable.archiveToTest(ShrinkWrap.create(WebArchive.class, "test.war")
                            .addClass(SoftCountFacadeTest.class)
                            .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")));
        return ear;
    }

My requirement is that Arquillian should be able to choose either of these deployment methods based on some configuration. For time being I'm commenting out the deployment method that need not to be run. The @Deployment.order, given here, is of no use as all the deployments will still run only their order of execution can be controlled.

Any help is highly appreciated.


Solution

  • may be you can try (you need to fill in ear condition by yourself):

    @Deployment
    public static Archive<?> createDynamicDeployment() {
      if(<ear condition>) {
        EnterpriseArchive ear = ShrinkWrap.createFromZipFile(EnterpriseArchive.class, new File("some_archive.ear"))
                .addAsModule(Testable.archiveToTest(ShrinkWrap.create(WebArchive.class, "test.war")
                            .addClass(SoftCountFacadeTest.class)
                            .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")));
        return ear;
      } else {
        WebArchive war = ShrinkWrap.create(WebArchive.class).addClass(Test.class)
                .addAsManifestResource(new File("jboss-deployment-structure.xml"))
                .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
        return war;
      }
    }