public class FlywayTestExecutionListener extends Object implements org.springframework.test.context.TestExecutionListener
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:
FlywayTest wont work at class level.FlywayTest more 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!| Constructor and Description |
|---|
FlywayTestExecutionListener()
Allocates new
AbstractDbSpringContextTests instance. |
| Modifier and Type | Method and Description |
|---|---|
void |
afterTestClass(org.springframework.test.context.TestContext testContext)
no implementation for annotation
FlywayTest needed. |
void |
afterTestMethod(org.springframework.test.context.TestContext testContext)
no implementation for annotation
FlywayTest needed. |
void |
beforeTestClass(org.springframework.test.context.TestContext testContext)
Invoke this method before test class will be created.
|
void |
beforeTestMethod(org.springframework.test.context.TestContext testContext)
Called from spring before a test method will be invoked.
|
protected org.apache.commons.logging.Log |
getLogger() |
void |
prepareTestInstance(org.springframework.test.context.TestContext testContext)
no implementation for annotation
FlywayTest needed. |
public FlywayTestExecutionListener()
AbstractDbSpringContextTests instance.protected org.apache.commons.logging.Log getLogger()
public void beforeTestClass(org.springframework.test.context.TestContext testContext)
throws Exception
beforeTestClass in interface org.springframework.test.context.TestExecutionListenertestContext - default test context filled from springException - if any error occurredpublic void prepareTestInstance(org.springframework.test.context.TestContext testContext)
throws Exception
FlywayTest needed.prepareTestInstance in interface org.springframework.test.context.TestExecutionListenertestContext - default test context filled from springException - if any error occurredpublic void beforeTestMethod(org.springframework.test.context.TestContext testContext)
throws Exception
beforeTestMethod in interface org.springframework.test.context.TestExecutionListenertestContext - default test context filled from springException - if any error occurredpublic void afterTestMethod(org.springframework.test.context.TestContext testContext)
throws Exception
FlywayTest needed.afterTestMethod in interface org.springframework.test.context.TestExecutionListenertestContext - default test context filled from springException - if any error occurredpublic void afterTestClass(org.springframework.test.context.TestContext testContext)
throws Exception
FlywayTest needed.afterTestClass in interface org.springframework.test.context.TestExecutionListenertestContext - default test context filled from springException - if any error occurredCopyright © 2014. All rights reserved.