2 Replies Latest reply on Apr 24, 2015 4:35 AM by logofat

    Integration testing database cleanup resulting in `Failed while seeding database` or `Unable to clean database.`

    logofat

      I am making some integration tests, and I would need to clean up the database between tests so i can make correct asserts, and also that the tests wont result in errors like `Failed while seeding database` or `Unable to clean database.`.

       

      pom:

          <dependencyManagement>

            <dependencies>

             <dependency>

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

              <artifactId>arquillian-bom</artifactId>

              <version>1.1.2.Final</version>

              <scope>import</scope>

              <type>pom</type>

             </dependency>

            </dependencies>

          </dependencyManagement>

       

          <dependency>

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

            <artifactId>arquillian-bom</artifactId>

            <version>1.1.2.Final</version>

            <type>pom</type>

          </dependency>

          <dependency>

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

             <artifactId>arquillian-glassfish-embedded-3.1</artifactId>

             <version>1.0.0.CR4</version>

             <scope>test</scope>

          </dependency>

          <dependency>

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

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

             <scope>test</scope>

          </dependency>

          <dependency>

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

             <artifactId>arquillian-persistence-api</artifactId>

             <version>1.0.0.Alpha5</version>

             <scope>test</scope>

          </dependency>

          <dependency>

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

             <artifactId>arquillian-persistence-impl</artifactId>

             <version>1.0.0.Alpha5</version>

             <scope>test</scope>

          </dependency>

       

      Some test class:

       

          @RunWith(Arquillian.class)

          @UsingDataSet("datasets/empty.yml")

          public class SomeServiceCase {

       

           @EJB

           SomeService someService;

       

           @Deployment

           public static JavaArchive createDeployment() {

               return ShrinkWrap.create(JavaArchive.class)

                       .addPackages(true, "vo")

                       .addPackages(true, "service")

                       .addPackages(true, "domain")

                       .addAsManifestResource("test-persistence.xml", ArchivePaths.create("persistence.xml"));

           }

       

           @Test

           @UsingDataSet("datasets/someModel/someModels.yml")

           @Cleanup(phase = TestExecutionPhase.AFTER, strategy = CleanupStrategy.STRICT)

           public void teastSomething() {

              //modifies database content here

           }

       

       

           @Test

           @UsingDataSet("datasets/someModel/someModels.yml")

           @Cleanup(phase = TestExecutionPhase.AFTER, strategy = CleanupStrategy.STRICT)

           public void testSomethingElse() {

              //needs initial database content for tests to work

           }

       

      Strict cleanup strategy should clear the database but it fails because of foreign-keys. So i tried disabling `Referential Integrity` by adding a property to `arquillian.xml`

       

          <property name="initStatement">SET REFERENTIAL_INTEGRITY FALSE</property>

       

      I also tried Using CLEAN_INSERT in `arquillian.xml` but whit no luck..

        • 1. Re: Integration testing database cleanup resulting in `Failed while seeding database` or `Unable to clean database.`
          mrazjava

          I just resolved this exact issue today. Try to configure your test method like this:

           

          @Test @Ignore
          @usingDataSet("datasets/whatever.yml")
          @Cleanup(phase = TestExecutionPhase.NONE)
          @CleanupUsingScript("scripts/yourcleanupscript.sql")
          @Transactional(TransactionMode.DISABLED)
          public void yourTest() throws Exception {}
          

           

          Couple points on what I found out. DBUnit is buggy on cleanup especially when it comes to foreign keys. So tell it to forget cleanup and clean up yourself with @CleanupUsingScript. Also, I have an open issue but @Transactional in Arquillian seems bit off (buggy?) so at minimum, it's best to disable it during any troubleshooting.

           

          Also, I noticed you're on Alpha5 - which given the alpha stage is rather outdated. Is there a reason you're not on latest Alpha7 ? Quite few fixes since Alpha5, just an FYI.

           

          Cheers

          • 2. Re: Integration testing database cleanup resulting in `Failed while seeding database` or `Unable to clean database.`
            logofat

            This is an older project and when I updated to Alpha7 i started giving other errors like not finding 'org/jboss/arquillian/persistence/TransactionMode' maybe i missed some other dependencies or something

            Also,  how would a cleanupscript look like?