6 Replies Latest reply on Apr 11, 2013 12:12 PM by Steve Friesen

    Persistence cleanup issue

    Steve Friesen Newbie

      Hi,

       

      I have a simple test class that has two tests. Before the first test I use a dataset to seed the database table. I was trying to see whether I could set up the tests so that I didn't need to keep seeding the table for every test if the data that I am using is the same. So on the first test I set the cleanup phase to TestExecutionPhase.NONE. The second test has no dataset, but tests against the same table and data. The test succeeds, but the cleanup fails. I get a NullPointerException. If I run this with only a single test and cleanup afterwards it runs successfully (and cleans up the table). Am I supposed to re-seed the database with every test?

      Here's the exception. The arquillian.xml and test class are below.

       

      Thanks,

       

      Steve

      org.jboss.arquillian.persistence.dbunit.exception.DBUnitDataSetHandlingException: Unable to clean database.

      at org.jboss.arquillian.persistence.dbunit.cleanup.UsedTablesOnlyCleanupStrategyExecutor.cleanupDatabase(UsedTablesOnlyCleanupStrategyExecutor.java:54)

      at org.jboss.arquillian.persistence.dbunit.DBUnitDataHandler.cleanDatabase(DBUnitDataHandler.java:174)

      at org.jboss.arquillian.persistence.dbunit.DBUnitDataHandler.cleanup(DBUnitDataHandler.java:115)

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

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

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

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

      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.persistence.dbunit.DBUnitDataStateLogger.aroundCleanup(DBUnitDataStateLogger.java:121)

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

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

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

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

      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:89)

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

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

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

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

      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:75)

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

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

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

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

      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:60)

      at sun.reflect.GeneratedMethodAccessor433.invoke(Unknown Source)

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

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

      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:135)

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

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

      at org.jboss.arquillian.persistence.core.lifecycle.DataCleanupHandler.verifyDatabase(DataCleanupHandler.java:71)

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

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

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

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

      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.test.impl.TestContextHandler.createTestContext(TestContextHandler.java:89)

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

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

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

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

      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:75)

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

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

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

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

      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:60)

      at sun.reflect.GeneratedMethodAccessor433.invoke(Unknown Source)

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

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

      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.persistence.core.lifecycle.ErrorCollectorHandler.collectErrors(ErrorCollectorHandler.java:46)

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

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

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

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

      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.persistence.dbunit.DBUnitPersistenceTestLifecycleHandler.provideDatabaseConnection(DBUnitPersistenceTestLifecycleHandler.java:118)

      at org.jboss.arquillian.persistence.dbunit.DBUnitPersistenceTestLifecycleHandler.provideDatabaseConnectionAroundAfterPersistenceTest(DBUnitPersistenceTestLifecycleHandler.java:89)

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

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

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

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

      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:135)

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

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

      at org.jboss.arquillian.persistence.core.lifecycle.PersistenceTestTrigger.afterTest(PersistenceTestTrigger.java:122)

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

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

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

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

      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.testenricher.cdi.CreationalContextDestroyer.destory(CreationalContextDestroyer.java:44)

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

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

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

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

      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:89)

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

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

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

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

      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:75)

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

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

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

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

      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:60)

      at sun.reflect.GeneratedMethodAccessor433.invoke(Unknown Source)

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

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

      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:135)

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

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

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

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

      at org.jboss.arquillian.junit.Arquillian.access$100(Arquillian.java:46)

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

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

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

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

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

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

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

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

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

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

      at org.jboss.arquillian.junit.Arquillian.access$100(Arquillian.java:46)

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

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

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

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

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

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

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

      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:668)

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

      at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)

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

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

      at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)

      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)

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

      at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)

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

      at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)

      at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)

      at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)

      at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)

      at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)

      at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)

      at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)

      at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)

      at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)

      at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)

      at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)

      at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)

      at com.sun.grizzly.ContextTask.run(ContextTask.java:71)

      at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)

      at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)

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

      Caused by: java.lang.NullPointerException

      at org.jboss.arquillian.persistence.dbunit.cleanup.UsedTablesOnlyCleanupStrategyExecutor.cleanupDatabase(UsedTablesOnlyCleanupStrategyExecutor.java:47)

      ... 172 more

       

      Here are my persistence extensions in arquillian.xml

       

      <extension qualifier="persistence">
        <property name="defaultDataSource">jdbc/FisTestDbDs</property>
        <property name="defaultCleanupPhase">AFTER</property>
        <property name="defaultCleanupStrategy">USED_TABLES_ONLY</property>
       </extension>
       <extension qualifier="persistence-dbunit">
        <property name="defaultDataSetFormat">YAML</property>
        <property name="schema">fistest</property>
       </extension>
       <extension qualifier="persistence-script">
        <property name="sqlStatementDelimiter">NEW_LINE</property>
       </extension>
      
      

       

      Here is my test class:

       

      @RunWith(Arquillian.class)
      public class SteveBeanTest {
          public SteveBeanTest() {
          }
          
          @Deployment
          public static JavaArchive createDeployment() {
              JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class)
                  .addClasses(AbstractFacade.class,AppUserFacade.class,AppUser.class,UserRole.class)
                  .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
                  .addAsManifestResource("test-persistence.xml", ArchivePaths.create("persistence.xml"));
              System.out.println(javaArchive.toString(true));
              return javaArchive;
          }
          
          @EJB
          AppUserFacade appUserFacade;
          @Test @InSequence(1)
          @UsingDataSet("datasets/appusers.yml")
          @Cleanup(phase = TestExecutionPhase.NONE)
          public void should_get_3_users_from_findAll() {
              System.out.println("should_get_3_users_from_findAll");
              List<AppUser> appUsers = appUserFacade.findAll();
              Assert.assertEquals(appUsers.size(), 2);
          }
          
          @Test @InSequence(2)
          @Cleanup(phase = TestExecutionPhase.AFTER)
          public void should_get_user_2_from_findUserByUserName() {
              System.out.println("should_get_user_2_from_findUserByUserName");
              AppUser appUser = appUserFacade.findUserByName("testuser2");
              Assert.assertNotNull(appUser);
              
          }