9 Replies Latest reply on Nov 8, 2012 6:22 AM by David Bertini

    Add personal JAR to test

    David Bertini Newbie

      Hi,

         I'm new in Arquillian test, please help me

       

      I've to add my personal jar to an Arquillian test. I've search in the internet but I can't find a solution.

       

      I've made a test class file that use Axis, Axione and other my personal class present in a jar, but when the test run the error is "java.lang.NoClassDefFoundError: org/apache/axis/AxisFault"

       

      Someone can Help me?

       

      Thanks a lot!!!!

        • 1. Re: Add personal JAR to test
          Bartosz Majsak Master

          Hi David,

           

          if you are using maven repository you can use the solution suggested in this guide:

          https://community.jboss.org/wiki/HowToIAddMavenArtifactsToMyShrinkWrapArchives

           

          if it's arbitrary file sitting already in your classpath the mechanism is pretty much similar, you just need to create proper File object.

           

          HTH

           

          Cheers,

          Bartosz

          • 2. Re: Add personal JAR to test
            David Bertini Newbie

            Yes I have to add my personal jar present on filesystem, axis.jar. I can't add thi to my test and when i run it the errore is the precedent

            • 3. Re: Add personal JAR to test
              Bartosz Majsak Master

              Can you share your test code? Is this jar not declared as dependency using maven/ivy/gradle etc? How are you building your project?

              • 4. Re: Add personal JAR to test
                David Bertini Newbie

                The code of my class is

                 

                package it.bcc.sinergia.wstest;

                 

                 

                import it.bcc.sinergia.wisehub.anagraficainfopubbliche.client.AnagraficaInfoPubblicheClient;

                import it.bcc.sinergia.wisehub.anagraficainfopubbliche.client.AnagraficaInfoPubblicheInputParameter;

                import it.bcc.sinergia.wisehub.anagraficainfopubbliche.client.AnagraficaInfoPubblicheOutputParameter;

                 

                 

                import org.jboss.arquillian.container.test.api.Deployment;

                import org.jboss.arquillian.junit.Arquillian;

                import org.jboss.shrinkwrap.api.Archive;

                import org.jboss.shrinkwrap.api.ShrinkWrap;

                import org.jboss.shrinkwrap.api.asset.EmptyAsset;

                import org.jboss.shrinkwrap.api.spec.WebArchive;

                import org.junit.Assert;

                import org.junit.Test;

                import org.junit.runner.RunWith;

                 

                 

                @RunWith(Arquillian.class)

                public class GreeterTest {

                 

                 

                          @Deployment

                          public static Archive<?> createDeployment() {

                                    return ShrinkWrap.create(WebArchive .class).addClass(GreeterTest.class)

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

                          }

                 

                 

                          @Test

                          public void anagrafiche_pubbliche_test() {

                                    // Assert.assertEquals("Hello, Earthling!","");

                                    try {

                 

                                              AnagraficaInfoPubblicheInputParameter lPar = new AnagraficaInfoPubblicheInputParameter();

                 

                                              AnagraficaInfoPubblicheOutputParameter outputParameter = AnagraficaInfoPubblicheClient

                                                                  .getAnagrafichePubbliche(lPar);

                 

                 

                                              Assert.assertNotNull(outputParameter);

                                    } catch (Exception a) {

                                              Assert.fail(a.getMessage());

                                    }

                 

                 

                          }

                }

                 

                and my pom.xml is:

                 

                <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

                          <modelVersion>4.0.0</modelVersion>

                          <groupId>it.bcc.sinergia</groupId>

                          <artifactId>WebServiceTest</artifactId>

                          <version>0.0.1-SNAPSHOT</version>

                          <name>WebServiceTest</name>

                 

                          <properties>

                        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

                    </properties>

                   

                          <dependencyManagement>

                              <dependencies>

                                  <dependency>

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

                                      <artifactId>arquillian-bom</artifactId>

                                      <version>1.0.3.Final</version>

                                      <scope>import</scope>

                                      <type>pom</type>

                                  </dependency>

                              </dependencies>

                          </dependencyManagement>

                 

                 

                          <build>

                        <plugins>

                            <plugin>

                                <artifactId>maven-compiler-plugin</artifactId>

                                <version>2.3.2</version>

                                <configuration>

                                    <source>1.6</source>

                                    <target>1.6</target>

                                </configuration>

                            </plugin>

                           

                            <plugin>

                                                  <artifactId>maven-surefire-plugin</artifactId>

                                                  <version>2.12</version>

                                              </plugin>

                 

                        </plugins>

                    </build>

                   

                    <dependencies>

                 

                                    <!-- dependency per le librerie di javaee -->

                        <dependency>

                                  <groupId>org.jboss.spec</groupId>

                                  <artifactId>jboss-javaee-6.0</artifactId>

                                  <version>1.0.0.Final</version>

                                  <type>pom</type>

                                  <scope>provided</scope>

                              </dependency>

                 

                                    <!-- dependency per le librerie di junit -->

                        <dependency>

                            <groupId>junit</groupId>

                            <artifactId>junit</artifactId>

                            <version>4.8.1</version>

                            <scope>test</scope>

                        </dependency>

                       

                        <!-- dependency per le librerie di arquillian -->

                        <dependency>

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

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

                                        <scope>test</scope>

                                    </dependency>

                 

                 

                        <!-- dependencies del container per lanciare il test di arquillian -->

                        <dependency>

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

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

                                        <version>1.0.0.CR5</version>

                                        <scope>test</scope>

                                    </dependency>

                                    <dependency>

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

                                        <artifactId>weld-core</artifactId>

                                        <version>1.1.5.Final</version>

                                        <scope>test</scope>

                                    </dependency>

                                    <dependency>

                                        <groupId>org.slf4j</groupId>

                                        <artifactId>slf4j-simple</artifactId>

                                        <version>1.6.4</version>

                                        <scope>test</scope>

                                    </dependency>

                 

                                    <!-- Dependencies per le librerie dei webservice -->

                                    <dependency>

                                              <groupId>org.apache.axis2</groupId>

                                              <artifactId>axis2</artifactId>

                                              <version>1.4</version>

                                    </dependency>

                                    <dependency>

                                              <groupId>axis</groupId>

                                              <artifactId>axis-wsdl4j</artifactId>

                                              <version>1.5.1</version>

                                    </dependency>

                                    <dependency>

                                              <groupId>org.apache.ws.commons</groupId>

                                              <artifactId>XmlSchema</artifactId>

                                              <version>1.1</version>

                                    </dependency>

                                    <dependency>

                                              <groupId>commons-logging</groupId>

                                              <artifactId>commons-logging-api</artifactId>

                                              <version>1.1</version>

                                    </dependency>

                                    <dependency>

                                              <groupId>backport-util-concurrent</groupId>

                                              <artifactId>backport-util-concurrent</artifactId>

                                              <version>1.1_01</version>

                                    </dependency>

                                    <dependency>

                                              <groupId>org.apache.neethi</groupId>

                                              <artifactId>neethi</artifactId>

                                              <version>3.0.1</version>

                                    </dependency>

                                    <dependency>

                                              <groupId>commons-httpclient</groupId>

                                              <artifactId>commons-httpclient</artifactId>

                                              <version>3.1</version>

                                    </dependency>

                                    <dependency>

                                              <groupId>org.apache.tuscany.sca.shades</groupId>

                                              <artifactId>tuscany-webservices-nodep</artifactId>

                                              <version>2.0-M5.1</version>

                                    </dependency>

                 

                 

                                    <dependency>

                                              <groupId>org.jboss.shrinkwrap.resolver</groupId>

                                              <artifactId>shrinkwrap-resolver-impl-maven</artifactId>

                                    </dependency>

                 

                 

                          </dependencies>

                   

                </project>

                 

                 

                in addition to this i've to add other 3 jar present on my classpath

                 

                THANK FOR THE HELP!!!!!!!

                • 5. Re: Add personal JAR to test
                  Bartosz Majsak Master

                  If you want to test your service from the outside of the application (as client) I would suggest to use @Deployment(testable=false). Another important thing is that you need to create your deployment package properly - so add all the services you interact with and libraries needed (as described in the guide I linked above). You don't need to add test class at all. It will be either added automatically (if you deploy and run tests in the container), or not if you run as client.

                  • 6. Re: Add personal JAR to test
                    Bartosz Majsak Master

                    Another option would be to build your webservice project through maven and deploy this WAR file as part of the test, for example:

                    ShrinkWrap.create(ZipImporter.class, "foo.war").importFrom(new File("target/foo.war"))

                    • 7. Re: Add personal JAR to test
                      David Bertini Newbie

                      So I can do this?

                       

                      ShrinkWrap.create(ZipImporter.class, "foo.war").importFrom(new File("lib/mylib.jar"))


                      • 8. Re: Add personal JAR to test
                        Bartosz Majsak Master

                        You theoretically can, but this won't bring any value for your tests if it's only the library. You need to add all services/classes you are interacting with in this test.

                        I think this can help you getting started with the ShrinkWrap deployment http://arquillian.org/guides/shrinkwrap_introduction/

                        • 9. Re: Add personal JAR to test
                          David Bertini Newbie

                          Thank you very much! I've test my client!!!!