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

    Fields
    Modifier and Type
    Field
    Description
    protected final org.flywaydb.test.FlywayTestExecutionListener
     
     
    protected final org.apache.commons.logging.Log
     

    Fields inherited from interface org.springframework.core.Ordered

    HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
  • Constructor Summary

    Constructors
    Constructor
    Description
    Allocates new AbstractDbSpringContextTests instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    afterTestClass(org.springframework.test.context.TestContext testContext)
     
    void
    afterTestMethod(org.springframework.test.context.TestContext testContext)
     
    void
    beforeTestClass(org.springframework.test.context.TestContext testContext)
     
    void
    beforeTestMethod(org.springframework.test.context.TestContext testContext)
     
    int
     
    void
    prepareTestInstance(org.springframework.test.context.TestContext testContext)
     
    void
    setOrder(int order)
    change the default order value;

    Methods inherited from class org.springframework.test.context.support.AbstractTestExecutionListener

    afterTestExecution, beforeTestExecution

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.springframework.test.context.TestExecutionListener

    afterTestExecution, beforeTestExecution
  • Field Details

    • logger

      protected final org.apache.commons.logging.Log logger
    • dbUnit

      protected final DBUnitTestExecutionListener dbUnit
    • dbReset

      protected final org.flywaydb.test.FlywayTestExecutionListener dbReset
  • Constructor Details

    • FlywayDBUnitTestExecutionListener

      public FlywayDBUnitTestExecutionListener()
      Allocates new AbstractDbSpringContextTests instance.
  • Method Details

    • beforeTestClass

      public void beforeTestClass(org.springframework.test.context.TestContext testContext) throws Exception
      Specified by:
      beforeTestClass in interface org.springframework.test.context.TestExecutionListener
      Overrides:
      beforeTestClass in class org.springframework.test.context.support.AbstractTestExecutionListener
      Throws:
      Exception
    • prepareTestInstance

      public void prepareTestInstance(org.springframework.test.context.TestContext testContext) throws Exception
      Specified by:
      prepareTestInstance in interface org.springframework.test.context.TestExecutionListener
      Overrides:
      prepareTestInstance in class org.springframework.test.context.support.AbstractTestExecutionListener
      Throws:
      Exception
    • beforeTestMethod

      public void beforeTestMethod(org.springframework.test.context.TestContext testContext) throws Exception
      Specified by:
      beforeTestMethod in interface org.springframework.test.context.TestExecutionListener
      Overrides:
      beforeTestMethod in class org.springframework.test.context.support.AbstractTestExecutionListener
      Throws:
      Exception
    • afterTestMethod

      public void afterTestMethod(org.springframework.test.context.TestContext testContext) throws Exception
      Specified by:
      afterTestMethod in interface org.springframework.test.context.TestExecutionListener
      Overrides:
      afterTestMethod in class org.springframework.test.context.support.AbstractTestExecutionListener
      Throws:
      Exception
    • afterTestClass

      public void afterTestClass(org.springframework.test.context.TestContext testContext) throws Exception
      Specified by:
      afterTestClass in interface org.springframework.test.context.TestExecutionListener
      Overrides:
      afterTestClass in class org.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:
      getOrder in interface org.springframework.core.Ordered
      Overrides:
      getOrder in class org.springframework.test.context.support.AbstractTestExecutionListener
      Returns:
      order default 4000
      Since:
      3.2.1.1