2 Replies Latest reply on Oct 3, 2012 2:58 AM by Charles Moulliard

    Place @Deployment in a different class

    Charles Moulliard Newbie

      Hi,

       

      I would like to know if it is possible to implement the following scenario. The @Deployment annotation is not added in the Junit Class containing CDI annotations and @Run(Arquillian.class) but in a subclass.

       

      Why : According to the container used to run the Unit Test, I would like to use a different archive (JAR, WAR, ....) with different librairies.

       

      Basically, we should have the parent class which will look like this :

       

      @RunWith(Arquillian.class)

      public class IntegrationTest {

       

          @Inject

          MyRoutes config;

       

          @Inject

          @Mock

          MockEndpoint result;

       

          @Test

          public void integrationTest() throws Exception {

           ...

          }

      }

       

      and the @Deployment will be added in a subclass

       

      To test with Weld, we could create a Configurator class in a package "weld"

       

      public class Configurator extends IntegrationTest {

       

          @Deployment(testable = false)

          @TargetsContainer("weld-ee-embedded-1.1")

          public static JavaArchive buildArchive() {

       

              JavaArchive jar =  ShrinkWrap.create(JavaArchive.class)

                      .addPackage(CdiCamelContext.class.getPackage())

                      .addPackage(CamelExtension.class.getPackage())

                      .addPackage(MyRoutes.class.getPackage())

                      .addPackage(Configurator.class.getPackage())

                      .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");

       

              return jar;

          }

       

      and to test with JBossAS :

       

      public class Configurator extends IntegrationTest {

       

          @Deployment

          @TargetsContainer("jbossas-managed")

          public static Archive<?> createTestArchive() {

       

              JavaArchive jarTest = ShrinkWrap.create(JavaArchive.class)

                      .addPackage(MyRoutes.class.getPackage())

                      .addPackage(IntegrationTest.class.getPackage())

                      .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");

       

              File[] libs = Maven.resolver()

                      .loadPomFromFile("pom.xml")

                      .resolve("org.apache.camel:camel-core","org.apache.camel:camel-cdi","org.apache.activemq:activemq-camel")

                      .withTransitivity()

                      .as(File.class);

       

       

              return ShrinkWrap

                      .create(WebArchive.class, "test.war")

                      .addAsLibrary(jarTest)

                      .addAsLibraries(libs);

          }

       

      Unfortunately, if I create the project like that, it does not work

       

      Any ideas are welcome ?

       

      Regards,

       

      Charles