Java Code Examples for org.flywaydb.test.annotation.FlywayTest

The following examples show how to use org.flywaydb.test.annotation.FlywayTest. These examples are extracted from open source projects. 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
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 2
/**
 * 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 3
@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 4
/**
 * 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 5
Source Project: phoebus   Source File: DAOTest.java    License: 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 6
Source Project: flyway-test-extensions   Source File: Spring5JUnitTest.java    License: 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 7
Source Project: flyway-test-extensions   Source File: Spring3JUnitTest.java    License: 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
public void dummyTestMethodLoad() throws Exception {
	int res = countCustomer();

	assertEquals("Count of customer", 0, res);
}
 
Example 8
Source Project: flyway-test-extensions   Source File: Spring3JUnitTest.java    License: 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();

	assertEquals("Count of customer", 2, res);
}
 
Example 9
@FlywayTest(locationsForMigrate = "loadmsql")
@Sql(scripts = "/testSqlFiles/loadSqlScriptExecutionsTest.sql")
@Test
public void loadSqlScriptExecutionsWithFlywayTestInsertTest() throws Exception {
    int countCustomer = countCustomer();

    assertThat("All customer (Flyway and Sql script) should be loaded.", countCustomer, is(3));
}
 
Example 10
/**
 * 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 11
/**
 * Made a clean init migrate usage before execution of test methods
 */
@Test
@FlywayTests(value = {
        @FlywayTest(locationsForMigrate = {"loadMultibleSQLs"}, flywayName = "flyway"),
        @FlywayTest(locationsForMigrate = {"loadMultipleSQLs2"}, flywayName = "flyway2")
})
public void loadMultipleSQLsLocations() throws Exception {
    int res = countCustomer();
    int res2 = countCustomer2();

    assertEquals("Count of customer", 2, res);
    assertEquals("Count of customer2", 2, res2);
}
 
Example 12
@Test
@FlywayTest
public void loadDefaultMigrations() {
    assertThat(dataSource).isNotNull();

    List<Map<String, Object>> persons = jdbcTemplate.queryForList(SQL_SELECT_PERSONS);
    assertThat(persons).isNotNull().hasSize(1);

    Map<String, Object> person = persons.get(0);
    assertThat(person).containsExactly(
            entry("id", 1L),
            entry("first_name", "Dave"),
            entry("last_name", "Syer"));
}
 
Example 13
@Test
@FlywayTest(locationsForMigrate = "db/test_migration/appendable")
public void loadAppendableTestMigrations() {
    assertThat(dataSource).isNotNull();

    List<Map<String, Object>> persons = jdbcTemplate.queryForList(SQL_SELECT_PERSONS);
    assertThat(persons).isNotNull().hasSize(2);

    assertThat(persons).extracting("id", "first_name", "last_name").containsExactlyInAnyOrder(
            tuple(1L, "Dave", "Syer"),
            tuple(2L, "Tom", "Hanks"));
}
 
Example 14
@Test
@FlywayTest(locationsForMigrate = "db/test_migration/dependent")
public void loadDependentTestMigrations() {
    assertThat(dataSource).isNotNull();

    List<Map<String, Object>> persons = jdbcTemplate.queryForList(SQL_SELECT_PERSONS);
    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"));
}
 
Example 15
Source Project: flyway-test-extensions   Source File: SpringConfigTest.java    License: 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, flywayName = "flywayOne")
public void useFlywayOne_testMethodLoadWithBaseline() throws Exception {
    int res = countCustomer();

    assertThat("Count of customer", res, is(0));
}
 
Example 16
@Test
@FlywayTest(flywayName = "flyway1")
@FlywayTest(flywayName = "flyway2", invokeCleanDB = true, invokeMigrateDB = false)
public void databaseShouldBeLoadedByFlyway1() {
    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"));

    assertThat(jdbcTemplate.queryForObject("select to_regclass('next.person')", String.class)).isNull();
}
 
Example 17
@Test
@FlywayTest(flywayName = "flyway1", invokeCleanDB = true, invokeMigrateDB = false)
@FlywayTest(flywayName = "flyway2")
public void databaseShouldBeLoadedByFlyway2() {
    assertThat(dataSource).isNotNull();

    assertThat(jdbcTemplate.queryForObject("select to_regclass('test.person')", String.class)).isNull();

    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 18
/**
 * 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 19
@BeforeClass
@FlywayTests(value = {
        @FlywayTest(flywayName = "flyway"),
        @FlywayTest(locationsForMigrate = {"basetest2", "loadMultipleSQLs2"}, overrideLocations = true, flywayName = "flyway2")
})
public static void beforeClass() {
}
 
Example 20
@Test
@FlywayTest
public void isolatedTest2() {
    assertThat(dataSource).isNotNull();

    List<Map<String, Object>> persons = jdbcTemplate.queryForList(SQL_SELECT_PERSONS);
    assertThat(persons).isNotNull().hasSize(1);

    jdbcTemplate.update(SQL_INSERT_PERSON, 2, "Will", "Smith");
}
 
Example 21
@Test
@Repeat(30)
@Timed(millis = 30000)
@FlywayTest(locationsForMigrate = "db/test_migration/appendable")
public void testEmbeddedDatabase() {
    List<Map<String, Object>> persons = jdbcTemplate.queryForList(SQL_SELECT_PERSONS);
    assertThat(persons).isNotNull().hasSize(2);
}
 
Example 22
Source Project: flyway-test-extensions   Source File: SpringConfigTest.java    License: 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();

    assertThat("Count of customer", res, is(2));
}
 
Example 23
/**
 * Made a clean init migrate usage before execution of test methods
 */
@Test
@FlywayTests(value = {
        @FlywayTest(flywayName = "flyway"),
        @FlywayTest(flywayName = "flyway2")
})
public void dummyTestMethodLoad() throws Exception {
    int res = countCustomer();
    int res2 = countCustomer2();

    assertEquals("Count of customer", 0, res);
    assertEquals("Count of customer2", 0, res2);
}
 
Example 24
Source Project: phoebus   Source File: DAOTest.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
@FlywayTest(invokeCleanDB = true)
public void testCreateConfigNoParentFound() {

	Node config = Node.builder().nodeType(NodeType.CONFIGURATION).build();

	// The parent node does not exist in the database, so this throws an exception
	nodeDAO.createNode(UUID.randomUUID().toString(), config);
}
 
Example 25
Source Project: flyway-test-extensions   Source File: Spring3DBunitTest.java    License: 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 26
@FlywayTest(locationsForMigrate = "loadmsql")
@Sql(scripts = "/testSqlFiles/loadSqlScriptExecutionsTest.sql")
@Test
public void loadSqlScriptExecutionsWithFlywayTestInsertTest() throws Exception {
    int countCustomer = countCustomer();

    assertEquals("All customer (Flyway and Sql script) should be loaded.", 3, countCustomer);
}
 
Example 27
Source Project: flyway-test-extensions   Source File: SpringConfigTest.java    License: 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(flywayName = "flywayOne")
public void useFlywayOne_noCustomer() throws Exception {
    int res = countCustomer();

    assertEquals("Count of customer", 0, res);
}
 
Example 28
/**
 * 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 29
Source Project: flyway-test-extensions   Source File: BaseJUnitTest.java    License: 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 30
Source Project: flyway-test-extensions   Source File: Spring4DBunitTest.java    License: 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);
}