spring - How to clean two databases after running JUnit test method using Flyway -
i have junit test method makes call 2 different services , both services running different data sources , of course in 2 transaction managers.
so have configured flyway use h2 data base , implemented junit test method below.
@runwith(springjunit4classrunner.class) @transactional public class datacontrollertest extends baseintegrationtest { @test public void testdatasave() throws exception { // test code call controller internally calls 2 services. assertequals(1, jdbctestutils.countrowsintable(this.jdbctemplate, "database1table1")); assertequals(1, jdbctestutils.countrowsintable(this.anotherjdbctemplate, "database2table1")); } }
so question test method creating records in h2 database , want clear data after running test.
<bean id="txmanager" class="org.springframework.jdbc.datasource.datasourcetransactionmanager"> <property name="datasource" ref="datasource1" /> </bean> <tx:advice id="txadvice" transaction-manager="txmanager"> <tx:attributes> <tx:method name="*" /> </tx:attributes> </tx:advice>
and other transaction manager work on different data source configured below.
<bean id="txmanager2" class="org.springframework.jdbc.datasource.datasourcetransactionmanager"> <property name="datasource" ref="anotherdatasource" /> </bean> <tx:advice id="txadvice" transaction-manager="txmanager"> <tx:attributes> <tx:method name="*" /> </tx:attributes> </tx:advice>
since gave test class transactional clean database after each test method run. clearning 1 database. want clean database part of anotherdatasource.
how need proceed that..? if possible , how mention these 2 transaction managers in @transactional annotation.
Comments
Post a Comment