5 Replies Latest reply on Oct 31, 2010 9:47 PM by Mark Wen

    JPA TestCase Triggered ClassNotFoundException: org.jboss.weld.resources.spi.ResourceLoadingException

    Mark Wen Newbie

      Hi,

       

      I was trying to test my JPA DAO classes, and I referred to the following resources:

      1. http://community.jboss.org/en/arquillian/blog/2010/10/04/the-perfect-recipe-for-testing-jpa-2-revisited

      2. http://docs.jboss.org/arquillian/reference

       

      My JPA test case is more complicated than the examples. Since my JPA DAO classes are not configured as EJB, I cannot use @EJB annotation in the test class, so @Inject is used. Below is some code snippets:

       

      @RunWith(Arquillian.class)
      public class GenericDaoTestCase

      {

       

         @Deployment
         public static Archive<?> createDeployment()
         {
            return ShrinkWrap.create(WebArchive.class, "test.war")
                  .addClasses(Role.class)
                  .addClasses(GenericDao.class)
                  .addClasses(GenericDaoHibernate.class)
                  .addManifestResource("test-persistence.xml", "persistence.xml")
                  .addWebResource(EmptyAsset.INSTANCE, "beans.xml");
          }

         private static final Object log = System.out;
        
         @Inject
         UserTransaction utx;
        
         @Inject
         private GenericDaoHibernate genericDao;
         
          @Test
          public void testSave() throws Exception {
         
              utx.begin();

       

              Role role = new Role();
              role.setName("Test Role");
             
              role = genericDao.save(role);
             
              assertNotNull(role.getId());
             
              utx.commit();
          }

       

      }

       

      When I run the test case with "mvn clean test -Parq-jbossas-managed" in the command line, the test case was deployed to JBoss AS 6 sucessfully, but surefire reported the following exception:

       

      org.jboss.arquillian.impl.event.FiredEventException: java.lang.IllegalStateException: Error launching test com.app.domain.GenericDaoTestCase public void com.app.domain.GenericDaoTestCase.testSave() throws java.lang.Exception
          at org.jboss.arquillian.impl.event.MapEventManager.fire(MapEventManager.java:68)
          at org.jboss.arquillian.impl.context.AbstractEventContext.fire(AbstractEventContext.java:115)
          at org.jboss.arquillian.impl.EventTestRunnerAdaptor.test(EventTestRunnerAdaptor.java:157)
          at org.jboss.arquillian.junit.Arquillian$6.evaluate(Arquillian.java:244)
          at org.jboss.arquillian.junit.Arquillian$4.evaluate(Arquillian.java:207)
          at org.jboss.arquillian.junit.Arquillian$5$1.evaluate(Arquillian.java:225)
          at org.jboss.arquillian.junit.Arquillian$MultiStatementExecutor.execute(Arquillian.java:297)
          at org.jboss.arquillian.junit.Arquillian$5.evaluate(Arquillian.java:221)
      ...
      Caused by: java.lang.IllegalStateException: Error launching test com.app.domain.GenericDaoTestCase public void com.app.domain.GenericDaoTestCase.testSave() throws java.lang.Exception
          at org.jboss.arquillian.protocol.servlet_3.ServletMethodExecutor.invoke(ServletMethodExecutor.java:61)
          at org.jboss.arquillian.impl.handler.ContainerTestExecuter.callback(ContainerTestExecuter.java:50)
          at org.jboss.arquillian.impl.handler.ContainerTestExecuter.callback(ContainerTestExecuter.java:40)
          at org.jboss.arquillian.impl.event.MapEventManager.fire(MapEventManager.java:63)
          ... 30 more
      Caused by: java.lang.ClassNotFoundException: org.jboss.weld.resources.spi.ResourceLoadingException
          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 sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
          at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
          at java.lang.Class.forName0(Native Method)
          at java.lang.Class.forName(Class.java:247)
          ... 33 more

       

      Is there anything missing from my project, or something else was happening?

       

      Thanks.