Java Integration testing with Arquillian, database cleanup -
i making integration tests, , need clean database between tests can make correct asserts, , tests wont result in errors failed while seeding database
or unable 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 tests work }
strict cleanup strategy should clear database fails because of foreign-keys. tried disabling referential integrity
adding property arquillian.xml
<property name="initstatement">set referential_integrity false</property>
how can achieve want? ideas?
you can set database mode in persistence.xml drop-create. force database rebuild scratch each redeploy (it's something!)
Comments
Post a Comment