0 Replies Latest reply on Jan 20, 2013 10:42 AM by milaw

    Arquillian and Maven 3, OSGi (equinox), blueprint, WAS 8...

    milaw

      I lost myself in the space of Arquillian...

       

      Hi All,

      I'm new with arquillian and trying to make a test (for test ) with OSGi bundle...

      After few days, I got lost between dependencies, profile, container.... I need help.

      Someone can provide me a guideline to use arquillian with osgi?

       

      At the end, part of my project require to test bundles in websphere.

      I choose at first option to use arquillian...

       

      You can see below sample code that i used:

       

      TEST CLASS

      @RunWith(Arquillian.class)

      public class SimpleServiceTest {

                @Deployment

          public static Archive<?> createdeployment() {

                          final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "deployment-arquillian")

                                                   .addClass(SimpleService.class);

                          archive.setManifest(new Asset() {

                                    public InputStream openStream(){

                                              OSGiManifestBuilder builder = OSGiManifestBuilder.newInstance();

                                              builder.addBundleSymbolicName(archive.getName());

                                              builder.addBundleManifestVersion(1);

                                              return builder.openStream();

                                    }

                          });

                          System.out.println(archive.toString(true));

                          return archive;

                }

                @Inject

          public Bundle bundle;

       

       

          @Test

          public void testClassTest() throws Exception {

              // Assert that the bundle is injected

              assertNotNull("Bundle injected", bundle);

             

              // Assert that the bundle is in state RESOLVED

              // Note when the test bundle contains the test case it

              // must be resolved already when this test method is called

              assertEquals("Bundle RESOLVED", Bundle.RESOLVED, bundle.getState());

       

       

              // Start the bundle

              bundle.start();

              assertEquals("Bundle ACTIVE", Bundle.ACTIVE, bundle.getState());

       

           [...]

             

              // Stop the bundle

              bundle.stop();

              assertEquals("Bundle RESOLVED", Bundle.RESOLVED, bundle.getState());

          }

      }

       

       

      with below dependencies:

       

      <!--  Arquillian  -->

                          <dependency>

                  <groupId>org.jboss.arquillian.junit</groupId>

                  <artifactId>arquillian-junit-container</artifactId>

                  <version>1.0.3.Final</version>

                  <scope>test</scope>

              </dependency>

       

       

              <dependency>

                  <groupId>org.jboss.arquillian.protocol</groupId>

                  <artifactId>arquillian-protocol-servlet</artifactId>

                  <version>1.0.3.Final</version>

                  <scope>test</scope>

              </dependency>

             

              <!-- JUnit  -->

              <dependency>

                     <groupId>junit</groupId>

                     <artifactId>junit</artifactId>

                     <version>4.8.1</version>

                     <scope>test</scope>

                   </dependency>

       

              <!-- OSGi -->

                          <dependency>

                                    <groupId>org.jboss.arquillian.osgi</groupId>

                                    <artifactId>arquillian-osgi-bundle</artifactId>

                                    <version>2.0.0.Alpha2</version>

                                    <type>bundle</type>

                                    <scope>test</scope>

                          </dependency>

                          <!-- OSGiManifestBuilder  -->

                          <dependency>

                                    <groupId>org.jboss.arquillian.container</groupId>

                                    <artifactId>arquillian-container-osgi</artifactId>

                                    <version>2.0.0.Alpha2</version>

                                    <scope>test</scope>

                          </dependency>

       

                          <dependency>

                                    <groupId>org.jboss.weld</groupId>

                                    <artifactId>weld-core</artifactId>

                                    <version>2.0.0.Beta1</version>

                                    <scope>test</scope>

                          </dependency>

                          <dependency>

                                    <groupId>org.slf4j</groupId>

                                    <artifactId>slf4j-simple</artifactId>

                                    <version>1.7.2</version>

                                    <scope>test</scope>

                          </dependency>

                </dependencies>

       

      profile:

          

      <profile>

                              <id>weld-ee-embedded-1.1</id>

                              <dependencies>

                                  <dependency>

                                      <groupId>org.jboss.arquillian.container</groupId>

                                      <artifactId>arquillian-weld-ee-embedded-1.1</artifactId>

                                      <version>1.0.0-SNAPSHOT</version>

                                  </dependency>

                                  <dependency>

                                      <groupId>org.jboss.weld</groupId>

                                      <artifactId>weld-core</artifactId>

                                  </dependency>

                                  <dependency>

                                      <groupId>org.jboss.weld</groupId>

                                      <artifactId>weld-api</artifactId>

                                  </dependency>

                                  <dependency>

                                      <groupId>org.slf4j</groupId>

                                      <artifactId>slf4j-simple</artifactId>

                                  </dependency>

                              </dependencies>

                              <dependencyManagement>

                                  <dependencies>

                                      <dependency>

                                          <groupId>org.jboss.weld</groupId>

                                          <artifactId>weld-core-bom</artifactId>

                                          <version>1.1.0.Final</version>

                                          <type>pom</type>

                                          <scope>import</scope>

                                      </dependency>

                                  </dependencies>

                              </dependencyManagement>

                          </profile>

       

      and the xml :

       

      <?xml version="1.0" encoding="UTF-8"?>

      <arquillian xmlns="http://jboss.org/schema/arquillian"

         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

         xsi:schemaLocation="http://jboss.org/schema/arquillian

              http://jboss.org/schema/arquillian/arquillian_1_0.xsd">

             

              <engine>

                        <property name="deploymentExportPath">target/</property>

                    </engine>

                          <container qualifier="weld" default="true" />

      </arquillian>

       

       

      Thanks for your help!

      M.