Package org.flywaydb.test
Class FlywayTestExecutionListener
java.lang.Object
org.springframework.test.context.support.AbstractTestExecutionListener
org.flywaydb.test.FlywayTestExecutionListener
- All Implemented Interfaces:
org.springframework.core.Ordered,org.springframework.test.context.TestExecutionListener
- Direct Known Subclasses:
FlywayTestExecutionListener
public class FlywayTestExecutionListener
extends org.springframework.test.context.support.AbstractTestExecutionListener
implements org.springframework.test.context.TestExecutionListener
Spring test execution listener to get annotation
FlywayTest up and
running
If the annotation FlywayTest used on class level a clean , init ,
migrate cycle is done during class load.
If the annotation FlywayTest used on test method level a clean , init
, migrate cycle is done before test execution.
Important if the annotation FlywayTest are used the system properties
for jdbc.url, jdbc.driver,
jdbc.username, and jdbc.password should be set.
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="dbc.properties"/>
<property name="ignoreResourceNotFound" value="true"/>
</bean>
<bean id="flyway" class="org.flywaydb.core.Flyway" depends-on="data.source.id">
<property name="dataSource" ref="data.source.id"/>
<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
-->
<bean id="dataSourceRef" 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 test class
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"/context/simple_applicationContext.xml"})
@TestExecutionListeners({DependencyInjectionTestExecutionListener.class,
FlywayTestExecutionListener.class})
@FlywayTest
public class SimpleLoadTest
Notes:
- If you using spring framework version lower than 3.x the annotation
FlywayTestwont work at class level. - For spring framework version 2.5.6 use simple_applicationContext_spring256.xml as application context example
- If you using the annotation
FlywayTestmore than one time in test classes than do not use parallel execution in surefire plugin. With this option you will setup your database in more than one thread parallel!
- Version:
- 2011-12-10, 1.7
- Author:
- Florian, EddĂș MelĂ©ndez
-
Field Summary
Fields 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) no implementation for annotationFlywayTestneeded.voidafterTestMethod(org.springframework.test.context.TestContext testContext) no implementation for annotationFlywayTestneeded.voidbeforeTestClass(org.springframework.test.context.TestContext testContext) Invoke this method before test class will be created.voidbeforeTestExecution(org.springframework.test.context.TestContext testContext) implementation for annotationFlywayTestfor handling withorg.testng.annotations.BeforeMethodannotation.voidbeforeTestMethod(org.springframework.test.context.TestContext testContext) Called from spring before a test method will be invoked.protected org.apache.commons.logging.LogintgetOrder()voidprepareTestInstance(org.springframework.test.context.TestContext testContext) implementation for annotationFlywayTestfor handling withorg.junit.BeforeorBeforeEachannotation.voidsetOrder(int order) change the default order value;Methods inherited from class org.springframework.test.context.support.AbstractTestExecutionListener
afterTestExecutionMethods 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
-
Constructor Details
-
FlywayTestExecutionListener
public FlywayTestExecutionListener()Allocates newAbstractDbSpringContextTestsinstance.
-
-
Method Details
-
getLogger
protected org.apache.commons.logging.Log getLogger()- Returns:
- the instance of logger.
-
beforeTestClass
public void beforeTestClass(org.springframework.test.context.TestContext testContext) throws Exception Invoke this method before test class will be created. Attention: This will be only invoked if spring version >= 3.x are used.- Specified by:
beforeTestClassin interfaceorg.springframework.test.context.TestExecutionListener- Overrides:
beforeTestClassin classorg.springframework.test.context.support.AbstractTestExecutionListener- Parameters:
testContext- default test context filled from spring- Throws:
Exception- if any error occurred
-
beforeTestExecution
public void beforeTestExecution(org.springframework.test.context.TestContext testContext) throws Exception implementation for annotationFlywayTestfor handling withorg.testng.annotations.BeforeMethodannotation.- Specified by:
beforeTestExecutionin interfaceorg.springframework.test.context.TestExecutionListener- Overrides:
beforeTestExecutionin classorg.springframework.test.context.support.AbstractTestExecutionListener- Parameters:
testContext- default test context filled from spring- Throws:
Exception- if any error occurred
-
prepareTestInstance
public void prepareTestInstance(org.springframework.test.context.TestContext testContext) throws Exception implementation for annotationFlywayTestfor handling withorg.junit.BeforeorBeforeEachannotation.- Specified by:
prepareTestInstancein interfaceorg.springframework.test.context.TestExecutionListener- Overrides:
prepareTestInstancein classorg.springframework.test.context.support.AbstractTestExecutionListener- Parameters:
testContext- default test context filled from spring- Throws:
Exception- if any error occurred
-
beforeTestMethod
public void beforeTestMethod(org.springframework.test.context.TestContext testContext) throws Exception Called from spring before a test method will be invoked.- Specified by:
beforeTestMethodin interfaceorg.springframework.test.context.TestExecutionListener- Overrides:
beforeTestMethodin classorg.springframework.test.context.support.AbstractTestExecutionListener- Parameters:
testContext- default test context filled from spring- Throws:
Exception- if any error occurred
-
afterTestMethod
public void afterTestMethod(org.springframework.test.context.TestContext testContext) throws Exception no implementation for annotationFlywayTestneeded.- Specified by:
afterTestMethodin interfaceorg.springframework.test.context.TestExecutionListener- Overrides:
afterTestMethodin classorg.springframework.test.context.support.AbstractTestExecutionListener- Parameters:
testContext- default test context filled from spring- Throws:
Exception- if any error occurred
-
afterTestClass
public void afterTestClass(org.springframework.test.context.TestContext testContext) throws Exception no implementation for annotationFlywayTestneeded.- Specified by:
afterTestClassin interfaceorg.springframework.test.context.TestExecutionListener- Overrides:
afterTestClassin classorg.springframework.test.context.support.AbstractTestExecutionListener- Parameters:
testContext- default test context filled from spring- Throws:
Exception- if any error occurred
-
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 4500
- Since:
- 3.2.1.1
-