junit - DBUnit dataset not accesible in test methods -



junit - DBUnit dataset not accesible in test methods -

i have test following

@runwith(springjunit4classrunner.class) @contextconfiguration(locations = { "classpath:meta-inf/spring/testdataspringcontext.xml" }) @transactional @transactionconfiguration(transactionmanager = "transactionmanager", defaultrollback = true) @testexecutionlisteners({ dependencyinjectiontestexecutionlistener.class, dirtiescontexttestexecutionlistener.class, transactiondbunittestexecutionlistener.class }) public class agencedaotest { @autowired private agencedao magencedao; @test @databasesetup(value = "/meta-inf/db-test/sampledata.xml", type = databaseoperation.refresh) public void listagences() { list<agencevo> vlisteagences = magencedao.getagences(); assert.notnull(vlisteagences); assert.notempty(vlisteagences); list<agencevo> vlisteagencestrouvees = listutils.select(vlisteagences, new predicate<agencevo>() { public boolean evaluate(agencevo pagencevo) { homecoming pagencevo.getlibelle().startswith("test_"); } }); assert.notnull(vlisteagencestrouvees); assert.notempty(vlisteagencestrouvees); assert.istrue(vlisteagencestrouvees.size() == 1); } }

everything seems ok because in log see following:

[transactionaltestexecutionlistener: startnewtransaction];began transaction (1): transaction manager [org.springframework.jdbc.datasource.datasourcetransactionmanager@39d325]; rollback [true] [dbunittestexecutionlistener: setuporteardown];executing setup of @databasetest using refresh on /meta-inf/db-test/sampledata.xml [abstracttablemetadata: getdatatypefactory];potential problem found: configured info type mill 'class org.dbunit.dataset.datatype.defaultdatatypefactory' might cause problems current database 'oracle' (e.g. datatypes may not supported properly). in rare cases might see message because list of supported database products incomplete (list=[derby]). if please request java-class update via forums.if using own idatatypefactory extending defaultdatatypefactory, ensure override getvaliddbproducts() specify supported database products. [sql: logstatement];select this_.agc_id agc1_0_0_, this_.agc_cp agc2_0_0_, this_.agc_adr1 agc3_0_0_, this_.agc_commune agc4_0_0_, this_.agc_adr2 agc5_0_0_, this_.agc_libelle agc6_0_0_, this_.agc_mail agc7_0_0_, this_.agc_nom agc8_0_0_, this_.agc_tel agc9_0_0_ ftn_agence_agc this_ [dbunittestexecutionlistener: verifyexpected];skipping @databasetest expectation due test exception class java.lang.illegalargumentexception [transactionaltestexecutionlistener: endtransaction];rolled transaction after test execution test context [[testcontext@cdd54e testclass = agencedaotest, locations = array<string>['classpath:meta-inf/spring/testdataspringcontext.xml'], testinstance = com.edf.ftn.data.admin.agencedaotest@16f2067, testmethod = listagences@agencedaotest, testexception = java.lang.illegalargumentexception: [assertion failed] - collection must not empty: must contain @ to the lowest degree 1 element]]

the dbunit dataset loaded after transaction created, dataset info should visible in select, not visible. when select executed records in dataset not retrieved.

to verify if dataset beingness loaded i've tried insert duplicate key , exception launched, supose de dataset loaded correctly.

the datasource , transactionmanager configuration is:

<bean id="datasource" class="org.apache.commons.dbcp.basicdatasource" destroy-method="close"> <property name="driverclassname" value="oracle.jdbc.driver.oracledriver" /> <property name="url" value="jdbc:oracle:thin:@${ip}:${port}:${schema}" /> <property name="username" value="${user}" /> <property name="password" value="${pass}" /> <property name="defaultautocommit" value="false" /> </bean> <bean id="transactionmanager" class="org.springframework.jdbc.datasource.datasourcetransactionmanager"> <property name="datasource" ref="datasource"/> </bean>

the dao not configured transactional, because in application isn't. have tried create transactional, , result same.

i not understand why in line:

list<agencevo> vlisteagences = magencedao.getagences();

the dataset not visible.

any help/hint appreciated. thanks!

solution found

i fixed problem using transactionawaredatasourceproxy

finally i've got next configuration datasource:

<bean id="dbcpdatasource" class="org.apache.commons.dbcp.basicdatasource" destroy-method="close"> <property name="driverclassname" value="oracle.jdbc.driver.oracledriver" /> <property name="url" value="jdbc:oracle:thin:@${ip}:${port}:${schema}" /> <property name="username" value="${user}" /> <property name="password" value="${pass}" /> <property name="defaultautocommit" value="false" /> </bean> <bean id="datasource" class="org.springframework.jdbc.datasource.transactionawaredatasourceproxy"> <constructor-arg ref="dbcpdatasource" /> </bean> <bean id="futunoatransactionmanager" class="org.springframework.jdbc.datasource.datasourcetransactionmanager"> <property name="datasource" ref="datasource"/> </bean>

junit dbunit spring-test-dbunit

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -