org.flywaydb.test.annotation.FlywayTest Java Examples

The following examples show how to use org.flywaydb.test.annotation.FlywayTest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MultipleFlywayBeansMethodLevelIntegrationTest.java    From embedded-database-spring-test with Apache License 2.0 6 votes vote down vote up
@Test
@FlywayTest(flywayName = "flyway1")
@FlywayTest(flywayName = "flyway2")
public void databaseShouldBeOverriddenByFlyway2() {
    assertThat(dataSource).isNotNull();

    List<Map<String, Object>> persons = jdbcTemplate.queryForList("select * from test.person");
    assertThat(persons).isNotNull().hasSize(2);

    assertThat(persons).extracting("id", "first_name", "last_name", "full_name").containsExactlyInAnyOrder(
            tuple(1L, "Dave", "Syer", "Dave Syer"),
            tuple(3L, "Will", "Smith", "Will Smith"));

    List<Map<String, Object>> nextPersons = jdbcTemplate.queryForList("select * from next.person");
    assertThat(nextPersons).isNotNull().hasSize(1);

    assertThat(nextPersons).extracting("id", "first_name", "surname").containsExactlyInAnyOrder(
            tuple(1L, "Dave", "Syer"));
}
 
Example #2
Source File: DAOTest.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
@Test
@FlywayTest(invokeCleanDB = true)
public void testGetChildNodes() throws Exception {
	Node rootNode = nodeDAO.getRootNode();

	Map<String, String> props = new HashMap<>();
	props.put("a", "b");

	Node folder1 = Node.builder().name("SomeFolder").properties(props).build();

	// Create folder1 in the root folder
	folder1 = nodeDAO.createNode(rootNode.getUniqueId(), folder1);

	List<Node> childNodes = nodeDAO.getChildNodes(rootNode.getUniqueId());

	assertEquals("b", childNodes.get(0).getProperty("a"));
	assertTrue(nodeDAO.getChildNodes(folder1.getUniqueId()).isEmpty());
}
 
Example #3
Source File: OptimizedFlywayTestExecutionListener.java    From embedded-database-spring-test with Apache License 2.0 6 votes vote down vote up
protected static DataSource reloadDataSource(FlywayDataSourceContext dataSourceContext, Flyway flywayBean, FlywayTest annotation) throws Exception {
    if (isAppendable(flywayBean, annotation)) {
        return dataSourceContext.reload(flywayBean).get();
    } else {
        String[] oldLocations = getFlywayLocations(flywayBean);
        try {
            if (annotation.overrideLocations()) {
                setFlywayLocations(flywayBean, annotation.locationsForMigrate());
            } else {
                setFlywayLocations(flywayBean, ObjectArrays.concat(oldLocations, annotation.locationsForMigrate(), String.class));
            }
            return dataSourceContext.reload(flywayBean).get();
        } finally {
            setFlywayLocations(flywayBean, oldLocations);
        }
    }
}
 
Example #4
Source File: OptimizedFlywayTestExecutionListener.java    From embedded-database-spring-test with Apache License 2.0 6 votes vote down vote up
/**
 * Checks if test migrations are appendable to core migrations.
 */
protected static boolean isAppendable(Flyway flyway, FlywayTest annotation) throws ClassNotFoundException {
    if (annotation.overrideLocations()) {
        return false;
    }

    if (ArrayUtils.isEmpty(annotation.locationsForMigrate())) {
        return true;
    }

    MigrationVersion testVersion = findFirstVersion(flyway, annotation.locationsForMigrate());
    if (testVersion == MigrationVersion.EMPTY) {
        return true;
    }

    MigrationVersion coreVersion = findLastVersion(flyway, getFlywayLocations(flyway));
    return coreVersion.compareTo(testVersion) < 0;
}
 
Example #5
Source File: FlywayTestExecutionListener.java    From flyway-test-extensions with Apache License 2.0 6 votes vote down vote up
/**
 * Search the class hierachie if a {@link FlywayTest} or {@link FlywayTests} annotation is used
 * together with a one of the Test annotations.
 *
 * @param testContext  current test spring context
 * @param testClass  current test class
 * @param junit4TestAnnotationClass  junit4 test annotation class
 * @param junit5TestAnnotationClass junit5 test annotation class
 */
private void handleFlywayTestWithTestAnnotation(TestContext testContext, Class testClass, Class junit4TestAnnotationClass, Class junit5TestAnnotationClass, Class testNgAnnotationClass) {
    Class currentTestClass = testClass;

    // search the first class with Before and FlywayTest annotation
    while (currentTestClass != Object.class) {
        final List<Method> allMethods = new ArrayList<Method>(Arrays.asList(currentTestClass.getDeclaredMethods()));
        for (final Method method : allMethods) {
            if (isMethodAnnotatedWithAtLeastOne(method, junit4TestAnnotationClass, junit5TestAnnotationClass, testNgAnnotationClass)
                    && isMethodAnnotatedWithAtLeastOne(method, FlywayTest.class, FlywayTests.class, null)) {
                // we have a method here that have both annotations
                getLogger().debug("Method " + method.getName() + " using flyway annotation.");
                if (handleFlywayTestAnnotationForMethod(testContext, method)) {
                    // finished handling
                    return;
                }
            }
        }

        // move to the upper class in the hierarchy in search for more methods
        currentTestClass = currentTestClass.getSuperclass();
    }
}
 
Example #6
Source File: BaseDBunitTest.java    From flyway-test-extensions with Apache License 2.0 5 votes vote down vote up
/**
 * Made a clean init migrate usage before execution of test methodes
 */
@Test
@FlywayTest
public void dummyTestMethodLoad() throws Exception {
	int res = countCustomer();

	Assert.assertEquals("Count of customer", 0, res);
}
 
Example #7
Source File: DAOTest.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
@Test
@FlywayTest(invokeCleanDB = true)
public void testNoNameClash() {

	Node rootNode = nodeDAO.getRootNode();

	Node n1 = Node.builder().id(1).name("n1").build();
	n1 = nodeDAO.createNode(rootNode.getUniqueId(), n1);
	Node n2 = Node.builder().id(2).name("n2").build();
	n2 = nodeDAO.createNode(rootNode.getUniqueId(), n2);
}
 
Example #8
Source File: BaseConnectionFactoryDBunitTest.java    From flyway-test-extensions with Apache License 2.0 5 votes vote down vote up
/**
 * Made a clean init migrate and insert sql with dbunit
 */
@Test
@FlywayTest
@DBUnitSupport(loadFilesForRun = { "INSERT", "/dbunit/dbunit.cus1.xml" })
public void loadDBUnitSQLs() throws Exception {
	int res = countCustomer();

	Assert.assertEquals("Count of customer", 2, res);
}
 
Example #9
Source File: FlywayTestApplicationTest.java    From flyway-test-extensions with Apache License 2.0 5 votes vote down vote up
@FlywayTest(invokeCleanDB = true)
@Test
public void singleLocation() throws Exception {
    assertThat(template.queryForObject(
            "SELECT COUNT(*) from PERSON", Integer.class),
            is(3));
}
 
Example #10
Source File: BaseDBunitTest.java    From flyway-test-extensions with Apache License 2.0 5 votes vote down vote up
/**
 * Made a clean init migrate with inserts from flyway and store it
 * afterwards
 */
@Test
@FlywayTest(locationsForMigrate = { "loadMultibleSQLs" })
@DBUnitSupport(saveTableAfterRun = { "CUSTOMER", "select * from CUSTOMER" }, saveFileAfterRun = "target/dbunitresult/customer1.xml")
public void storeDBUnitSQLs() throws Exception {
	int res = countCustomer();

	Assert.assertEquals("Count of customer", 2, res);
}
 
Example #11
Source File: BaseDBunitTest.java    From flyway-test-extensions with Apache License 2.0 5 votes vote down vote up
/**
 * Made a clean init migrate and insert sql with dbunit
 */
@Test
@FlywayTest
@DBUnitSupport(loadFilesForRun = { "INSERT", "/dbunit/dbunit.cus1.xml" })
public void loadDBUnitSQLs() throws Exception {
	int res = countCustomer();

	Assert.assertEquals("Count of customer", 2, res);
}
 
Example #12
Source File: SpringDBunitConnectionFactoryTest.java    From flyway-test-extensions with Apache License 2.0 5 votes vote down vote up
/**
 * Made a clean init migrate usage before execution of test methods
 */
@Test
@FlywayTest
public void dummyTestMethodLoad() throws Exception {
	int res = countCustomer();

	assertEquals("Count of customer", 0, res);
}
 
Example #13
Source File: Junit5WithSqlScriptsTestExecutionListenerTest.java    From flyway-test-extensions with Apache License 2.0 5 votes vote down vote up
@FlywayTest(locationsForMigrate = "loadmsql")
@Test
public void laodFlywayTestInsertWithoutSqlScriptExecutionTest() throws Exception {
    int countCustomer = countCustomer();

    assertThat("Only Flyway customer should be loaded.", countCustomer, is(2));
}
 
Example #14
Source File: BaseJUnitFlywayContextTest.java    From flyway-test-extensions with Apache License 2.0 5 votes vote down vote up
/**
 * Made a clean init migrate usage before execution of test methods
 */
@Test
@FlywayTest(locationsForMigrate = {"loadMultibleSQLs"})
public void loadMultibleSQLsLocations() throws Exception {
    int res = countCustomer();

    assertEquals("Count of customer", 2, res);
}
 
Example #15
Source File: BaseConnectionFactoryDBunitTest.java    From flyway-test-extensions with Apache License 2.0 5 votes vote down vote up
/**
 * Made a clean init migrate with inserts from flyway and store it
 * afterwards
 */
@Test
@FlywayTest(locationsForMigrate = { "loadMultibleSQLs" })
@DBUnitSupport(saveTableAfterRun = { "CUSTOMER", "select * from CUSTOMER" }, saveFileAfterRun = "target/dbunitresult/customer1.xml")
public void storeDBUnitSQLs() throws Exception {
	int res = countCustomer();

	Assert.assertEquals("Count of customer", 2, res);
}
 
Example #16
Source File: Junit5SpringTest.java    From flyway-test-extensions with Apache License 2.0 5 votes vote down vote up
/**
 * Made a clean init migrate usage before execution of test method and
 * load SQL statements from two directories.
 */
@Test
@FlywayTest(locationsForMigrate = {"loadmsql"})
public void loadMultibleSQLs() throws Exception {
	int res = countCustomer();

	assertThat("Count of customer", res, is(2));
}
 
Example #17
Source File: FlywayTestWithSqlScriptsTestExecutionListenerTest.java    From flyway-test-extensions with Apache License 2.0 5 votes vote down vote up
@FlywayTest(locationsForMigrate = "loadmsql")
@Test
public void laodFlywayTestInsertWithoutSqlScriptExecutionTest() throws Exception {
    int countCustomer = countCustomer();

    assertEquals("Only Flyway customer should be loaded.", 2, countCustomer);
}
 
Example #18
Source File: BaseJUnitFlywaysBeforeTest.java    From flyway-test-extensions with Apache License 2.0 5 votes vote down vote up
/**
 * Made a clean init migrate usage before execution of test methods
 */
@Test
@FlywayTest(locationsForMigrate = {"loadMultibleSQLs"}, flywayName = "flyway")
public void loadMultipleSQLsLocations() throws Exception {
    int res = countCustomer();
    int res2 = countCustomer2();

    assertEquals("Count of customer", 2, res);
    assertEquals("Count of customer2", 2, res2);
}
 
Example #19
Source File: FlywayTestExtensionTest.java    From flyway-test-extensions with Apache License 2.0 5 votes vote down vote up
/**
 * Made a clean init migrate usage before execution of test methods
 */
@Test
@FlywayTest(locationsForMigrate = { "basetest", "loadMultibleSQLs" }, overrideLocations = true)
public void loadMultibleSQLsOverrideLocations() throws Exception {
    int res = countCustomer();

    assertEquals("Count of customer", 2, res);
}
 
Example #20
Source File: BaseJUnitFlywaysBeforeTest.java    From flyway-test-extensions with Apache License 2.0 5 votes vote down vote up
@Before
@FlywayTests(value = {
        @FlywayTest(flywayName = "flyway"),
        @FlywayTest(locationsForMigrate = {"basetest2", "loadMultipleSQLs2"}, overrideLocations = true, flywayName = "flyway2")
})
public void before() {
}
 
Example #21
Source File: FlywayTestExtensionTest.java    From flyway-test-extensions with Apache License 2.0 5 votes vote down vote up
/**
 * Made a clean init migrate usage before execution of test methods
 */
@Test
@FlywayTest
void dummyTestMethodLoad() throws Exception {
    int res = countCustomer();

    assertThat("Count of customer", res, is(0));
}
 
Example #22
Source File: FlywayTestExtensionAnnotationTest.java    From flyway-test-extensions with Apache License 2.0 5 votes vote down vote up
/**
 * Made a clean init migrate usage before execution of test methods
 */
@Test
@FlywayTest(locationsForMigrate = { "sampletest5", "loadmsqlbefore" }, overrideLocations = true)
public void loadMultibleSQLsOverrideLocations() throws Exception {
    int res = countCustomer();

    assertThat("Count of customer", res, is(3));
}
 
Example #23
Source File: DAOTest.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
@Test
@FlywayTest(invokeCleanDB = true)
public void testGetRootsParent() {
	Node rootNode = nodeDAO.getRootNode();
	Node parent = nodeDAO.getParentNode(rootNode.getUniqueId());

	assertEquals(rootNode.getUniqueId(), parent.getUniqueId());
}
 
Example #24
Source File: Spring3DBunitConnectionFactoryTest.java    From flyway-test-extensions with Apache License 2.0 5 votes vote down vote up
/**
 * Made a clean init migrate with inserts from flyway and store it
 * afterwards
 */
@Test
@FlywayTest(locationsForMigrate = {"loadmsql"})
@DBUnitSupport(saveTableAfterRun = { "CUSTOMER", "select * from CUSTOMER" }, saveFileAfterRun = "target/dbunitresult/customer1.xml")
public void storeDBUnitSQLs() throws Exception {
	int res = countCustomer();

	assertEquals("Count of customer", 2, res);
}
 
Example #25
Source File: Spring4DBunitConnectionFactoryTest.java    From flyway-test-extensions with Apache License 2.0 5 votes vote down vote up
/**
 * Made a clean init migrate and insert sql with dbunit
 */
@Test
@FlywayTest
@DBUnitSupport(loadFilesForRun = { "INSERT", "/dbunit3/dbunit.cus1.xml"})
public void loadDBUnitSQLs() throws Exception {
	int res = countCustomer();

	assertEquals("Count of customer", 2, res);
}
 
Example #26
Source File: Spring5JUnitTest.java    From flyway-test-extensions with Apache License 2.0 5 votes vote down vote up
/**
 * Made a clean init migrate usage before execution of test method.
 * SQL statements will be loaded from the default location.
 */
@Test
@FlywayTest(invokeBaselineDB = true)
public void testMethodLoadWithBaseline() throws Exception {
    int res = countCustomer();

    assertThat("Count of customer", res, is(0));
}
 
Example #27
Source File: SpringDBunitTest.java    From flyway-test-extensions with Apache License 2.0 5 votes vote down vote up
/**
 * Made a clean init migrate with inserts from flyway and store it
 * afterwards
 */
@Test
@FlywayTest(locationsForMigrate = {"loadmsql"})
@DBUnitSupport(saveTableAfterRun = { "CUSTOMER", "select * from CUSTOMER" }, saveFileAfterRun = "target/dbunitresult/customer1.xml")
public void storeDBUnitSQLs() throws Exception {
	int res = countCustomer();

	assertEquals("Count of customer", 2, res);
}
 
Example #28
Source File: SpringConfigTest.java    From flyway-test-extensions with Apache License 2.0 5 votes vote down vote up
/**
 * Made a clean init migrate usage before execution of test method and
 * load SQL statements from two directories.
 */
@Test
@FlywayTest(locationsForMigrate = {"loadmsql"}, flywayName = "flywaySecond")
public void useFlywaySecond_loadMultibleSQLs() throws Exception {
    int res = countCustomer();

    assertThat("Count of customer", res, is(6));
}
 
Example #29
Source File: Spring4JUnitTest.java    From flyway-test-extensions with Apache License 2.0 5 votes vote down vote up
/**
 * Made a clean init migrate usage before execution of test method.
 * SQL statements will be loaded from the default location.
 */
@Test
@FlywayTest(invokeBaselineDB=true)
public void testMethodLoadWithBaseline() throws Exception {
    int res = countCustomer();

    assertEquals("Count of customer", 0, res);
}
 
Example #30
Source File: SpringConfigTest.java    From flyway-test-extensions with Apache License 2.0 5 votes vote down vote up
/**
 * Made a clean init migrate usage before execution of test method and
 * load SQL statements from two directories.
 */
@Test
@FlywayTest(locationsForMigrate = {"loadmsql"}, flywayName = "flywayOne")
public void useFlywayOne_loadMultibleSQLs() throws Exception {
    int res = countCustomer();

    assertEquals("Count of customer", 2, res);
}