3 Replies Latest reply on Dec 17, 2016 8:06 PM by Otávio Augusto Junior

    ClassNotFoundException for the test class in arquillian ServletTestRunner

    Abhishek Shukla Newbie

      I am trying to execute a JUnit testcase with Arquillian in Eclipse Indigo on JBoss 5.1 EAP.

       

      The test EAR deploys perfectly on JBoss via Arquillian, but the Arquillian ServletTestRunner throw ClassNotFoundException while trying to execute test cases.

       

      Here's the stack trace that I see on JUnit Console:

      java.lang.ClassNotFoundException: com.espn.authorizationmgr.ejb.ArquillianADManagerTest

          at java.net.URLClassLoader$1.run(URLClassLoader.java:202)

          at java.security.AccessController.doPrivileged(Native Method)

          at java.net.URLClassLoader.findClass(URLClassLoader.java:190)

          at java.lang.ClassLoader.loadClass(ClassLoader.java:307)

          at java.lang.ClassLoader.loadClass(ClassLoader.java:248)

          at org.jboss.arquillian.protocol.servlet.runner.ServletTestRunner.executeTest(ServletTestRunner.java:158)

          at org.jboss.arquillian.protocol.servlet.runner.ServletTestRunner.execute(ServletTestRunner.java:126)

          at org.jboss.arquillian.protocol.servlet.runner.ServletTestRunner.doGet(ServletTestRunner.java:90)

          at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)

          at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)

          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

          at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)

          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)

          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

          at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)

          at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)

          at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:183)

          at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:95)

          at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)

          at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)

          at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)

          at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)

          at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)

          at org.apache.catalina.authenticator.SingleSignOn.invoke(SingleSignOn.java:383)

          at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)

          at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)

          at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)

          at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)

          at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:451)

          at java.lang.Thread.run(Thread.java:662)

       

      My TestClass is:

      /**

      *

      */

      package com.espn.authorizationmgr.ejb;

       

      import static org.junit.Assert.assertNotNull;

       

      import javax.ejb.EJB;

       

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

      import org.jboss.arquillian.junit.Arquillian;

      import org.jboss.shrinkwrap.api.ShrinkWrap;

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

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

      import org.junit.BeforeClass;

      import org.junit.Test;

      import org.junit.runner.RunWith;

       

      import com.espn.activedirectory.MemberNotInGroupException;

      import com.espn.authorizationmgr.ejb.impl.ActiveDirectoryDelegateBean;

       

      /**

      * @author shuklaa

      *

      */

      @RunWith(Arquillian.class)

      public class ArquillianADManagerTest {

       

          private static ActiveDirectoryDelegate.Remote activeDirectoryDelegate = null;

       

          private static final String TEST_ADD_USERID = "xxxx";

          private static final String TEST_REMOVE_USERID = "xxxx";

          private static final String TEST_GROUP = "xxxxxxx";

       

          @EJB

          ActiveDirectoryDelegate.Local activeDirecotryDelegate;

       

          @Deployment

          public static EnterpriseArchive createTestArchive() {

              JavaArchive ejb = ShrinkWrap

                      .create(JavaArchive.class, "authorizationmgr-test-ejb.jar")

                      .addClasses(ActiveDirectoryDelegate.class, ActiveDirectoryDelegate.Local.class, ActiveDirectoryDelegate.Remote.class,

                              ActiveDirectoryDelegateBean.class).addPackages(true, "com.espn.authorizationmgr.entity")

                      .addPackages(true, "com.espn.authorizationmgr.exception").addPackages(true, "com.espn.authorizationmgr.message")

                      .addAsManifestResource("test-persistence.xml", "META-INF/persistence.xml");

       

              EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, "authorizationmgr-test.ear").addAsModule(ejb);

       

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

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

       

              return ear;

       

          }

       

          @BeforeClass

          public static void setUpClass() throws Exception {

              System.out.println("Set Up.");

          }

       

          public void cleanUpTestData() throws Exception {

              System.out.println("cleanUpTestData");

              try {

                  activeDirectoryDelegate.removeFromGroup("XXXX", TEST_ADD_USERID, TEST_GROUP);

                  System.out.println("cleanUpTestData removed successfully");

       

              } catch (MemberNotInGroupException e) {

                  // Ignore

                  System.out.println("MemberNotInGroupException cleaning up test data: " + e.getMessage());

              } catch (Exception e) {

                  // Ignore

                  System.out.println("exception cleaning up test data: " + e.getMessage());

              }

              // try {

              // activeDirectoryDelegate.addToGroup(TEST_REMOVE_USERID, TEST_GROUP);

              // } catch (MemberAlreadyInGroupException e) {

              // // Ignore

              // System.out.println("MembeAlreadyInGroupException cleaning up test data: "+e.getMessage());

              // }catch (Exception e) {

              // // Ignore

              // System.out.println("exception cleaning up test data: "+e.getMessage());

              // }

          }

       

          @Test

          public void testAddingSomeoneToGroup() {

              System.out.println("testAddingSomeoneToGroup");

       

              try {

                  addToGroup();

                  cleanUpTestData();

              } catch (Exception e) {

                  // TODO Auto-generated catch block

                  e.printStackTrace();

              }

          }

       

          public void addToGroup() throws Exception {

              System.out.println("adding to group");

              activeDirectoryDelegate.addToGroup("XXXX", TEST_ADD_USERID, TEST_GROUP);

              System.out.println("add successful");

       

          }

       

          public void removeFromGroup() throws Exception {

              System.out.println("removing from group");

              activeDirectoryDelegate.removeFromGroup("XXXX", TEST_REMOVE_USERID, TEST_GROUP);

              System.out.println("remove successful");

       

          }

       

      }

       

      Wondering if someone can help...

        • 1. Re: ClassNotFoundException for the test class in arquillian ServletTestRunner
          Aslak Knutsen Master

          You'll have to add the TestClass manually when you create a EnterpriseArchive. The Servlet Protocol does not currently default any of the modules and don't know where to add it.

          • 3. Re: ClassNotFoundException for the test class in arquillian ServletTestRunner
            Otávio Augusto Junior Newbie

            Hello all, i need some help here too

             

            I know that the topic is old, but i'm getting the same error here with a little diferent cenario. In my case, i'm not trying to generate a EAR archive, it is a simplest WAR file, but on the other hand i'm using de annotation @ArquillianSuiteDeployment to generate a separated deployment file for a remote container (wildfly-10).

             

            My @ArquillianSuiteDeployment

            package com.sgasys;
            
            @ArquillianSuiteDeployment
            public class Deployments {
            
              @Deployment
              public static WebArchive generateAutogeneratedDeployment() {
              WebArchive war = createDefautDeploy("sgasys-test.war");
            
            
              addAllResourcesFrom(war, "./target/classes", "/WEB-INF/classes");
              addAllResourcesFrom(war, "./src/main/webapp", "/");
              replacePersistenceUnit(war);
            
              return war;
              }
            
             //omited methods
            }
            

             

            My test class

            @RunWith(Arquillian.class)
            public class Amb92PersistenceTest {
            
            
              @Inject
              Amb92Facade repository;
            
              @Test
              @Transactional(TransactionMode.ROLLBACK)
              public void novoAmb92(@ArquillianResource URL deploymentUrl) {
              repository.save(new Amb92("56.01.001-0", "CISTOMETRIA SIMPLES"));
              }
            }
            

             

            Part of my dependencies from pom.xml, (only tests)

              <dependency>
              <groupId>junit</groupId>
              <artifactId>junit</artifactId>
              <scope>test</scope>
              </dependency>
            
              <dependency>
              <groupId>org.wildfly.bom</groupId>
              <artifactId>wildfly-javaee7-with-tools</artifactId>
              <version>10.1.0.Final</version>
              <scope>import</scope>
              <type>pom</type>
              </dependency>
              <dependency>
              <groupId>org.jboss.arquillian.junit</groupId>
              <artifactId>arquillian-junit-container</artifactId>
              <scope>test</scope>
              </dependency>
              <dependency>
              <groupId>org.jboss.shrinkwrap.resolver</groupId>
              <artifactId>shrinkwrap-resolver-impl-maven</artifactId>
              <scope>test</scope>
              </dependency>
              <dependency>
              <groupId>org.wildfly.arquillian</groupId>
              <artifactId>wildfly-arquillian-container-remote</artifactId>
              <version>2.0.0.Final</version>
              <scope>test</scope>
              </dependency>
              <dependency>
              <groupId>org.eu.ingwar.tools</groupId>
              <artifactId>arquillian-suite-extension</artifactId>
              <version>1.1.2</version>
              <scope>test</scope>
              </dependency>
              <dependency>
                        <groupId>org.jboss.arquillian.extension</groupId>
                        <artifactId>arquillian-persistence-api</artifactId>
                        <version>1.0.0.Alpha6
                        </version>
                        <scope>test</scope>
                    </dependency>
                    <dependency>
                        <groupId>org.jboss.arquillian.extension</groupId>
                        <artifactId>arquillian-persistence-impl</artifactId>
                        <version>1.0.0.Alpha6</version>
                        <scope>test</scope>
                    </dependency>
            

             

             

            The exception

            java.lang.ClassNotFoundException: com.sgasys.auxiliar.Amb92PersistenceTest from [Module "deployment.sgasys-test.war:main" from Service Module Loader]
              at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:198)
              at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:363)
              at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:351)
              at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:93)
              at org.jboss.arquillian.protocol.servlet.runner.ServletTestRunner.executeTest(ServletTestRunner.java:168)
              at org.jboss.arquillian.protocol.servlet.runner.ServletTestRunner.execute(ServletTestRunner.java:135)
              at org.jboss.arquillian.protocol.servlet.runner.ServletTestRunner.doGet(ServletTestRunner.java:98)
              at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
              at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
              at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
              at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129)
              at org.ocpsoft.rewrite.servlet.RewriteFilter.doFilter(RewriteFilter.java:226)
              at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
              at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
              at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)
              at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
              at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
              at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
              at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
              at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
              at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
              at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
              at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
              at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
              at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
              at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
              at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
              at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
              at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
              at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
              at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
              at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
              at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292)
              at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81)
              at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138)
              at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)
              at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
              at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
              at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
              at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
              at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
              at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
              at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
              at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
              at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)
              at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
              at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104)
              at io.undertow.server.Connectors.executeRootHandler(Connectors.java:202)
              at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:805)
              at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
              at java.lang.Thread.run(Thread.java:745)
            

             

            i would be glad for any help.