5 Replies Latest reply on Jan 28, 2015 12:10 PM by alice azevedo

    Arquillian Persistence Extension - NPE

    alice azevedo Newbie

      Hi everyone,

       

      I am starting with Arquillian and I have a few test cases working.

      Now I wanted to try Persistence Extension and I can't manage to get it working.

       

      Maybe someone could help me.

       

      Here's my test code:

       

      @RunWith(Arquillian.class)

      public class SimpleItemTest {

       

        @PersistenceContext

          private EntityManager em;

       

       

        @Deployment

          public static Archive<?> createDeployment() {

      final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "market-ejb.jar")

        .addPackage(Item.class.getPackage())

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

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

             return archive;

          }

       

        @Test

        @ApplyScriptBefore("populateCategory.sql")

        public void listItems() {

        List<Category> list = em.createQuery("select c from Category c", Category.class).getResultList();

        Assert.assertNotNull(list);

        Assert.assertTrue(list.isEmpty());

        }

      }

       

      The script populateCategory.sql is located in the folder src/test/resources/scripts and contains just one insert statement:

      insert into Category (name, id) values ('Vegetais', 1);

       

      My arquillian.xml

      <?xml version="1.0"?>

      <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">

         

          <container qualifier="jbossas-managed-7" default="true">

          <configuration>

          </configuration>

          </container>

        <extension qualifier="persistence">

           <property name="defaultDataSource">java:jboss/datasources/ExampleDS</property>

           <property name="dumpData">true</property>

        </extension>

         

        <extension qualifier="persistence-dbunit">

             <property name="datatypeFactory">org.dbunit.ext.h2.H2DataTypeFactory</property>

        </extension>

      </arquillian>

       

      When I remove the @ApplyScriptBefore annotation, no exception is thrown. But when I rung this simple test, I get the following stacktrace.

      I appreciate any help.

       

      java.lang.NullPointerException

        at org.jboss.arquillian.transaction.impl.lifecycle.TransactionHandler.testRequiresRollbackDueToFailure(TransactionHandler.java:170)

        at org.jboss.arquillian.transaction.impl.lifecycle.TransactionHandler.rollbackRequired(TransactionHandler.java:159)

        at org.jboss.arquillian.transaction.impl.lifecycle.TransactionHandler.endTransaction(TransactionHandler.java:123)

        at org.jboss.arquillian.transaction.impl.lifecycle.TransactionHandler.endTransactionAfterTest(TransactionHandler.java:102)

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

        at java.lang.reflect.Method.invoke(Method.java:597)

        at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)

        at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)

        at org.jboss.arquillian.testenricher.cdi.CreationalContextDestroyer.destory(CreationalContextDestroyer.java:44)

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

        at java.lang.reflect.Method.invoke(Method.java:597)

        at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)

        at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)

        at org.jboss.arquillian.test.impl.TestContextHandler.createTestContext(TestContextHandler.java:102)

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

        at java.lang.reflect.Method.invoke(Method.java:597)

        at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)

        at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)

        at org.jboss.arquillian.test.impl.TestContextHandler.createClassContext(TestContextHandler.java:84)

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

        at java.lang.reflect.Method.invoke(Method.java:597)

        at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)

        at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)

        at org.jboss.arquillian.test.impl.TestContextHandler.createSuiteContext(TestContextHandler.java:65)

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

        at java.lang.reflect.Method.invoke(Method.java:597)

        at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)

        at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)

        at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:145)

        at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:116)

        at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.after(EventTestRunnerAdaptor.java:103)

        at org.jboss.arquillian.junit.Arquillian$5.evaluate(Arquillian.java:277)

        at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)

        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)

        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)

        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)

        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)

        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)

        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)

        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)

        at org.jboss.arquillian.junit.Arquillian$2.evaluate(Arquillian.java:193)

        at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:345)

        at org.jboss.arquillian.junit.Arquillian.access$200(Arquillian.java:49)

        at org.jboss.arquillian.junit.Arquillian$3.evaluate(Arquillian.java:207)

        at org.junit.runners.ParentRunner.run(ParentRunner.java:363)

        at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:155)

        at org.junit.runner.JUnitCore.run(JUnitCore.java:137)

        at org.junit.runner.JUnitCore.run(JUnitCore.java:115)

        at org.jboss.arquillian.junit.container.JUnitTestRunner.execute(JUnitTestRunner.java:66)

        at org.jboss.arquillian.protocol.jmx.JMXTestRunner.runTestMethodInternal(JMXTestRunner.java:129)

        at org.jboss.arquillian.protocol.jmx.JMXTestRunner.runTestMethod(JMXTestRunner.java:108)

        at org.jboss.as.arquillian.service.ArquillianService$ExtendedJMXTestRunner.runTestMethod(ArquillianService.java:226)

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

        at java.lang.reflect.Method.invoke(Method.java:597)

        at com.sun.jmx.mbeanserver.StandardMBeanIntrospector.invokeM2(StandardMBeanIntrospector.java:93)

        at com.sun.jmx.mbeanserver.StandardMBeanIntrospector.invokeM2(StandardMBeanIntrospector.java:27)

        at com.sun.jmx.mbeanserver.MBeanIntrospector.invokeM(MBeanIntrospector.java:208)

        at com.sun.jmx.mbeanserver.PerInterface.invoke(PerInterface.java:120)

        at com.sun.jmx.mbeanserver.MBeanSupport.invoke(MBeanSupport.java:262)

        at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:836)

        at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:761)

        at org.jboss.as.jmx.PluggableMBeanServerImpl$TcclMBeanServer.invoke(PluggableMBeanServerImpl.java:498)

        at org.jboss.as.jmx.PluggableMBeanServerImpl.invoke(PluggableMBeanServerImpl.java:246)

        at org.jboss.remotingjmx.protocol.v1.ServerProxy$InvokeHandler.handle(ServerProxy.java:1034)

        at org.jboss.remotingjmx.protocol.v1.ServerProxy$MessageReciever$1.run(ServerProxy.java:215)

        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)

        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)

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

        • 1. Re: Arquillian Persistence Extension - NPE
          Rafael Pestano Novice

          Hi there,

           

          could you try to disable transaction on that test? this will show the real cause of the issue with your test ( i hope):

           

              @Test

              @Transactional(TransactionMode.DISABLED)

              @ApplyScriptBefore("populateCategory.sql")

              public void listItems() {

                  List<Category> list = em.createQuery("select c from Category c", Category.class).getResultList();

                  Assert.assertNotNull(list);

                  Assert.assertTrue(list.isEmpty());

              }

           

          or use @ApplyScriptAfter("populateCategory.sql") just to see the error.

           

          I hope it helps

          1 of 1 people found this helpful
          • 2. Re: Arquillian Persistence Extension - NPE
            alice azevedo Newbie

            Hi Rafael,

             

            I tried your suggestions and this is the error I got in all cases.

            GRAVE: Failed: br.com.ava.market.service.SimpleItemTest.listItems

            java.lang.IllegalStateException: Unresolvable implementation of org.jboss.arquillian.persistence.spi.script.StatementSplitter for specified dialect default

              at org.jboss.arquillian.persistence.script.splitter.StatementSplitterResolver.resolve(StatementSplitterResolver.java:57)

              at org.jboss.arquillian.persistence.dbunit.DBUnitDataHandler.executeScript(DBUnitDataHandler.java:147)

              at org.jboss.arquillian.persistence.dbunit.DBUnitDataHandler.executeScripts(DBUnitDataHandler.java:137)

              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

              at java.lang.reflect.Method.invoke(Method.java:597)

              at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)

              at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)

              at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)

              at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:145)

              at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:116)

              at org.jboss.arquillian.core.impl.EventImpl.fire(EventImpl.java:67)

              at org.jboss.arquillian.persistence.core.lifecycle.DataScriptsHandler.executeCustomScriptsBefore(DataScriptsHandler.java:66)

              at org.jboss.arquillian.persistence.core.lifecycle.DataScriptsHandler.executeBeforeTest(DataScriptsHandler.java:47)

            Here's my test-persistence.xml, as you can see I'm using Hypersonic for tests, as I've read it's supported by jBoss 7.1.

            <persistence version="2.1"

              xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

              xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">

                <persistence-unit name="market">

                    <!-- <jta-data-source>jdbc/market_test</jta-data-source> -->

                    <jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source>

                    <properties>

                    <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>

                        <property name="hibernate.hbm2ddl.auto" value="create-drop" />

                        <property name="hibernate.show_sql" value="true" />

                    </properties>

                </persistence-unit>

            </persistence>

            Any guess?

             

            Thank you for your help.

            • 3. Re: Arquillian Persistence Extension - NPE
              Rafael Pestano Novice

              are you using arquillian persisntence Alpha7?

               

              try using double quotes on your sql script:

               

              insert into Category (name, id) values ("Vegetais", 1);

               

              also try specifing the delimite to ';' in arquillian.xml (I think it's the default):

               

                <extension qualifier="persistence-script">

                      <property name="sqlStatementDelimiter">;</property>

                  </extension>

               

              also i would try to comment the "datatypeFactory" property.

               

              i hope it helps

              • 4. Re: Arquillian Persistence Extension - NPE
                alice azevedo Newbie

                Yes,

                I am using alpha 7:

                 

                        <dependency>

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

                            <artifactId>arquillian-persistence-dbunit</artifactId>

                            <version>1.0.0.Alpha7</version>

                            <scope>test</scope>

                       </dependency>

                I had tried setting sqlStatementDelimiter before even ';', NEW_LINE, but it didn't work as well.

                I tried double quotes but I got the same exception. By the stacktrace, it seems the script isn't even executed, the exception is thrown before it.

                 

                I looked the source code where the exception is thrown:

                public StatementSplitter resolve()

                {

                      final String sqlDialect = scriptingConfiguration.getSqlDialect();

                      StatementSplitter resolved = null;

                      final Collection<StatementSplitter> statementSplitters = new JavaSPIExtensionLoader().all(Thread.currentThread().getContextClassLoader(), StatementSplitter.class);

                      for (StatementSplitter statementSplitter : statementSplitters)

                      {

                         if (statementSplitter.supports().equalsIgnoreCase(sqlDialect))

                         {

                            if (resolved != null)

                            {

                               throw new IllegalStateException("Found multiple implementations of " + StatementSplitter.class.getName()

                                     + " for specified dialect " + sqlDialect);

                            }

                            resolved = statementSplitter;

                            resolved.setStatementDelimiter(scriptingConfiguration.getSqlStatementDelimiter());

                         }

                      }

                 

                 

                      if (resolved == null)

                      {

                         throw new IllegalStateException("Unresolvable implementation of " + StatementSplitter.class.getName() + " for specified dialect " + sqlDialect);

                      }

                 

                 

                      return resolved;

                   }

                It looks like no StatementSplitter implementation is found, but I haven't realized yet how to set it.

                Thank you,

                • 5. Re: Arquillian Persistence Extension - NPE
                  alice azevedo Newbie

                  Just for the record, I changed to arquillian-persistence-impl version 1.0.0.Alpha6 and it worked without any other change.