Integration testing database cleanup resulting in `Failed while seeding database` or `Unable to clean database.`
logofat Apr 24, 2015 4:35 AMI 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..