I configured my test environment via java config. At my test I need some data upfront to run it, but when i run the test with the @DatabaseSetup
annotation I always get the error
Unable to load dataset from "personTestData.xml" using class com.github.springtestdbunit.dataset.FlatXmlDataSetLoader
The file is located at src/test/resources/personTestData.xml
. Out of curiosity I moved the file into the same package where the test itself is located, still the same error.
I have spent countless hours searching the web for the error, no solution till now.
UPDATE
Components and version I use:
junit: 4.12
hamcrest: 1.3
springtestdbunit: 1.2.1
dbunit: 2.5.0
bonecp: 0.8.0
hsqldb: 1.8.0.10
my xml
<?xml version="1.0" encoding="UTF-8"?>
<dataset>
<person id="uuid'da578845-356c-4c99-9bda-c288c88e7b55"
dateCreated="2015-03-24 10:54:00"
isEnabled="1"
city="Graz"
displayName="42"
email="[email protected]"
firstname="Arthur"
lastname="Dent"
phone="01123456"
street="Waßkannergasse 16"
web="www.vdsoft.at"
zip="1010"/>
<person id="uuid'5aaae7dd-b84f-463e-a534-e7b2bc54752a"
dateCreated="2015-03-24 10:54:10"
isEnabled="1"
city="Graz"
displayName="Towel"
email="[email protected]"
firstname="Ford"
lastname="Prefect"
phone="01123856"
street="Waßkannergasse 45"
web="www.vdsoft.at"
zip="1010"/>
<person id="uuid'b770b982-3a59-4292-9fd8-715afa2c1bef"
dateCreated="2015-03-24 10:54:20"
isEnabled="1"
city="Graz"
displayName="Lemon"
email="[email protected]"
firstname="Zaphod"
lastname="Beeblebrox"
phone="01125456"
street="Waßkannergasse 20"
web="www.vdsoft.at"
zip="1010"/>
</dataset>
my testcase
@Test
@DatabaseSetup(type = DatabaseOperation.CLEAN_INSERT,
value = "personTestData.xml")
public void AddPersonAdditionsSuccessfull() {
PersonAdditionsDbo data = new PersonAdditionsDbo();
data.setCompany("VDsoft");
data.setCompetences("Developer");
data.setDistributor(true);
data.setFunction("Teamleader");
data.setHolisIsTopBecause("Payes rent...");
data.setIamHolisBecauseNote("Work");
data.setInvestment(10000f);
data.setInvitedById(this.zaphodBeeblebrox.getId());
data.setNotes("Something to say...");
data.setPerson(this.athurDent);
data.setReceiveNewsletter(true);
data.setReceivePressMessages(true);
data.setType("Developer");
assertNull(data.getId());
this.repo.save(data);
assertNotNull(data.getId());
}
stack trace, snipped for the init of the db
WARN [main] (EntityManagerFactoryRegistry.java:80) - HHH000436: Entity manager factory name (TESTHolisEMF) is already registered. If entity manager will be clustered or passivated, specify a unique value for property 'hibernate.ejb.entitymanager_factory_name'
WARN [main] (TestContextManager.java:252) - Caught exception while allowing TestExecutionListener [com.github.springtestdbunit.DbUnitTestExecutionListener@23cd5d42] to process 'before' execution of test method [public void holis.backend.webapi.repository.PersonAdditionTest.AddPersonAdditionsSuccessfull()] for test instance [holis.backend.webapi.repository.PersonAdditionTest@2b44d6d0]
java.lang.IllegalArgumentException: Unable to load dataset from "personTestData.xml" using class com.github.springtestdbunit.dataset.FlatXmlDataSetLoader
at org.springframework.util.Assert.notNull(Assert.java:112)
at com.github.springtestdbunit.DbUnitRunner.loadDataset(DbUnitRunner.java:214)
at com.github.springtestdbunit.DbUnitRunner.loadDataSets(DbUnitRunner.java:203)
at com.github.springtestdbunit.DbUnitRunner.setupOrTeardown(DbUnitRunner.java:184)
at com.github.springtestdbunit.DbUnitRunner.beforeTestMethod(DbUnitRunner.java:66)
at com.github.springtestdbunit.DbUnitTestExecutionListener.beforeTestMethod(DbUnitTestExecutionListener.java:186)
at org.springframework.test.context.TestContextManager.beforeTestMethod(TestContextManager.java:249)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:72)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:73)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:217)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:83)
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.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:68)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:163)
at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:45)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)
@DatabaseSetup
? – Signorino