Package org.flywaydb.test.dbunit
Class FlywayDBUnitTestExecutionListener
java.lang.Object
org.springframework.test.context.support.AbstractTestExecutionListener
org.flywaydb.test.dbunit.FlywayDBUnitTestExecutionListener
- All Implemented Interfaces:
org.springframework.core.Ordered,org.springframework.test.context.TestExecutionListener
public class FlywayDBUnitTestExecutionListener
extends org.springframework.test.context.support.AbstractTestExecutionListener
implements org.springframework.test.context.TestExecutionListener
A
TestExecutionListeners to get both annotation FlywayTest and DBUnitSupport work in the correct order.
It make the delegation in the natural order to the both database TestExecutionListener
for db reset FlywayTestExecutionListener and DBunit
DBUnitTestExecutionListener.
If only on of them is needed it can be addressed directly.
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location"><value>jdbc.properties</value></property>
<property name="ignoreResourceNotFound" value="true"/>
</bean>
<!-- flyway part -->
<bean id="flyway" class="org.flywaydb.core.Flyway" depends-on="dataSourceId">
<property name="dataSource" ref="dataSourceId"/>
<property name="locations" value="oracle"/>
</bean>
<!-- H2 Setup
-Djdbc.driver=org.h2.Driver
-Djdbc.url=jdbc:h2:./db/testCaseDb
-Djdbc.username=OC_MORE_TEST
-Djdbc.password=OC_MORE_TEST
Oracle Setup
-Djdbc.driver=oracle.jdbc.driver.OracleDriver
-Djdbc.url=jdbc:oracle:thin:<oracle.host>:<oracle.port>:<oracle.sid>
-Djdbc.username=OC_MORE_TEST
-Djdbc.password=OC_MORE_TEST
-->
<bean id="dataSourceId" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName"><value>$jdbc.driver</value></property>
<property name="url"><value>$jdbc.url</value></property>
<property name="username"><value>$jdbc.username</value></property>
<property name="password"><value>$jdbc.password</value></property>
</bean>
If this setup is used exist the possibility to run test again different database such as
H2 or Oracle.
Usage inside the Testclass
- Version:
- 1.0
- Author:
- florian
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final org.flywaydb.test.FlywayTestExecutionListenerprotected final DBUnitTestExecutionListenerprotected final org.apache.commons.logging.LogFields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
ConstructorsConstructorDescriptionAllocates newAbstractDbSpringContextTestsinstance. -
Method Summary
Modifier and TypeMethodDescriptionvoidafterTestClass(org.springframework.test.context.TestContext testContext) voidafterTestMethod(org.springframework.test.context.TestContext testContext) voidbeforeTestClass(org.springframework.test.context.TestContext testContext) voidbeforeTestMethod(org.springframework.test.context.TestContext testContext) intgetOrder()voidprepareTestInstance(org.springframework.test.context.TestContext testContext) voidsetOrder(int order) change the default order value;Methods inherited from class org.springframework.test.context.support.AbstractTestExecutionListener
afterTestExecution, beforeTestExecutionMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.test.context.TestExecutionListener
afterTestExecution, beforeTestExecution
-
Field Details
-
logger
protected final org.apache.commons.logging.Log logger -
dbUnit
-
dbReset
protected final org.flywaydb.test.FlywayTestExecutionListener dbReset
-
-
Constructor Details
-
FlywayDBUnitTestExecutionListener
public FlywayDBUnitTestExecutionListener()Allocates newAbstractDbSpringContextTestsinstance.
-
-
Method Details
-
beforeTestClass
public void beforeTestClass(org.springframework.test.context.TestContext testContext) throws Exception - Specified by:
beforeTestClassin interfaceorg.springframework.test.context.TestExecutionListener- Overrides:
beforeTestClassin classorg.springframework.test.context.support.AbstractTestExecutionListener- Throws:
Exception
-
prepareTestInstance
public void prepareTestInstance(org.springframework.test.context.TestContext testContext) throws Exception - Specified by:
prepareTestInstancein interfaceorg.springframework.test.context.TestExecutionListener- Overrides:
prepareTestInstancein classorg.springframework.test.context.support.AbstractTestExecutionListener- Throws:
Exception
-
beforeTestMethod
public void beforeTestMethod(org.springframework.test.context.TestContext testContext) throws Exception - Specified by:
beforeTestMethodin interfaceorg.springframework.test.context.TestExecutionListener- Overrides:
beforeTestMethodin classorg.springframework.test.context.support.AbstractTestExecutionListener- Throws:
Exception
-
afterTestMethod
public void afterTestMethod(org.springframework.test.context.TestContext testContext) throws Exception - Specified by:
afterTestMethodin interfaceorg.springframework.test.context.TestExecutionListener- Overrides:
afterTestMethodin classorg.springframework.test.context.support.AbstractTestExecutionListener- Throws:
Exception
-
afterTestClass
public void afterTestClass(org.springframework.test.context.TestContext testContext) throws Exception - Specified by:
afterTestClassin interfaceorg.springframework.test.context.TestExecutionListener- Overrides:
afterTestClassin classorg.springframework.test.context.support.AbstractTestExecutionListener- Throws:
Exception
-
setOrder
public void setOrder(int order) change the default order value;- Since:
- 3.2.1.1
-
getOrder
public int getOrder()- Specified by:
getOrderin interfaceorg.springframework.core.Ordered- Overrides:
getOrderin classorg.springframework.test.context.support.AbstractTestExecutionListener- Returns:
- order default 4000
- Since:
- 3.2.1.1
-