Search in sources :

Example 6 with ClassPathResource

use of org.flywaydb.core.internal.util.scanner.classpath.ClassPathResource in project flyway by flyway.

the class EnterpriseDBSqlScriptSmallTest method parsePackages.

@Test
public void parsePackages() throws Exception {
    String source = new ClassPathResource("migration/dbsupport/enterprisedb/sql/package/V1__Package.sql", Thread.currentThread().getContextClassLoader()).loadAsString("UTF-8");
    SqlScript sqlScript = new SqlScript(source, new EnterpriseDBDbSupport(null));
    List<SqlStatement> sqlStatements = sqlScript.getSqlStatements();
    assertEquals(2, sqlStatements.size());
    assertEquals(17, sqlStatements.get(0).getLineNumber());
    assertEquals(30, sqlStatements.get(1).getLineNumber());
}
Also used : SqlStatement(org.flywaydb.core.internal.dbsupport.SqlStatement) SqlScript(org.flywaydb.core.internal.dbsupport.SqlScript) ClassPathResource(org.flywaydb.core.internal.util.scanner.classpath.ClassPathResource) Test(org.junit.Test)

Example 7 with ClassPathResource

use of org.flywaydb.core.internal.util.scanner.classpath.ClassPathResource in project flyway by flyway.

the class SQLServerMigrationTestCase method msDBToolsIgnoredForEmpty.

@Test
public void msDBToolsIgnoredForEmpty() throws Exception {
    Schema schema = dbSupport.getOriginalSchema();
    new SqlScript(new ClassPathResource("migration/dbsupport/sqlserver/createMSDBTools.sql", Thread.currentThread().getContextClassLoader()).loadAsString("UTF-8"), dbSupport).execute(jdbcTemplate);
    try {
        assertTrue("MS DB tools must be ignored in empty check.", schema.empty());
    } finally {
        try {
            new SqlScript(new ClassPathResource("migration/dbsupport/sqlserver/dropMSDBTools.sql", Thread.currentThread().getContextClassLoader()).loadAsString("UTF-8"), dbSupport).execute(jdbcTemplate);
        } catch (Exception e) {
        // Swallow to prevent override of test raised exception.
        }
    }
}
Also used : Schema(org.flywaydb.core.internal.dbsupport.Schema) SqlScript(org.flywaydb.core.internal.dbsupport.SqlScript) ClassPathResource(org.flywaydb.core.internal.util.scanner.classpath.ClassPathResource) FlywayException(org.flywaydb.core.api.FlywayException) SQLException(java.sql.SQLException) FlywaySqlScriptException(org.flywaydb.core.internal.dbsupport.FlywaySqlScriptException) Test(org.junit.Test)

Example 8 with ClassPathResource

use of org.flywaydb.core.internal.util.scanner.classpath.ClassPathResource in project flyway by flyway.

the class VerticaSqlScriptSmallTest method parseSqlStatementsDo.

@Test
public void parseSqlStatementsDo() throws Exception {
    String source = new ClassPathResource("migration/dbsupport/vertica/sql/dollar/V1__Dollar.sql", Thread.currentThread().getContextClassLoader()).loadAsString("UTF-8");
    SqlScript sqlScript = new SqlScript(source, new VerticaDbSupport(null));
    List<SqlStatement> sqlStatements = sqlScript.getSqlStatements();
    assertEquals(10, sqlStatements.size());
    assertEquals(17, sqlStatements.get(0).getLineNumber());
    assertEquals(19, sqlStatements.get(1).getLineNumber());
    assertEquals(20, sqlStatements.get(2).getLineNumber());
}
Also used : SqlStatement(org.flywaydb.core.internal.dbsupport.SqlStatement) SqlScript(org.flywaydb.core.internal.dbsupport.SqlScript) ClassPathResource(org.flywaydb.core.internal.util.scanner.classpath.ClassPathResource) Test(org.junit.Test)

Example 9 with ClassPathResource

use of org.flywaydb.core.internal.util.scanner.classpath.ClassPathResource in project flyway by flyway.

the class SqlMigrationResolverSmallTest method extractScriptName.

@Test
public void extractScriptName() {
    SqlMigrationResolver sqlMigrationResolver = new SqlMigrationResolver(null, scanner, new Location("db/migration"), PlaceholderReplacer.NO_PLACEHOLDERS, FlywayConfigurationForTests.createWithPrefix("db_"));
    assertEquals("db_0__init.sql", sqlMigrationResolver.extractScriptName(new ClassPathResource("db/migration/db_0__init.sql", Thread.currentThread().getContextClassLoader())));
}
Also used : ClassPathResource(org.flywaydb.core.internal.util.scanner.classpath.ClassPathResource) Location(org.flywaydb.core.internal.util.Location) Test(org.junit.Test)

Example 10 with ClassPathResource

use of org.flywaydb.core.internal.util.scanner.classpath.ClassPathResource in project flyway by flyway.

the class SqlMigrationResolverSmallTest method extractScriptNameRootLocation.

@Test
public void extractScriptNameRootLocation() {
    SqlMigrationResolver sqlMigrationResolver = new SqlMigrationResolver(null, scanner, new Location(""), PlaceholderReplacer.NO_PLACEHOLDERS, FlywayConfigurationForTests.createWithPrefix("db_"));
    assertEquals("db_0__init.sql", sqlMigrationResolver.extractScriptName(new ClassPathResource("db_0__init.sql", Thread.currentThread().getContextClassLoader())));
}
Also used : ClassPathResource(org.flywaydb.core.internal.util.scanner.classpath.ClassPathResource) Location(org.flywaydb.core.internal.util.Location) Test(org.junit.Test)

Aggregations

ClassPathResource (org.flywaydb.core.internal.util.scanner.classpath.ClassPathResource)31 Test (org.junit.Test)21 SqlScript (org.flywaydb.core.internal.dbsupport.SqlScript)17 SqlStatement (org.flywaydb.core.internal.dbsupport.SqlStatement)11 File (java.io.File)4 SQLException (java.sql.SQLException)4 HashMap (java.util.HashMap)4 PlaceholderReplacer (org.flywaydb.core.internal.util.PlaceholderReplacer)4 Resource (org.flywaydb.core.internal.util.scanner.Resource)4 ClassPathScanner (org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner)4 BeforeClass (org.junit.BeforeClass)4 FlywayException (org.flywaydb.core.api.FlywayException)3 ArrayList (java.util.ArrayList)2 Properties (java.util.Properties)2 FlywaySqlException (org.flywaydb.core.internal.dbsupport.FlywaySqlException)2 FlywaySqlScriptException (org.flywaydb.core.internal.dbsupport.FlywaySqlScriptException)2 Schema (org.flywaydb.core.internal.dbsupport.Schema)2 Location (org.flywaydb.core.internal.util.Location)2 AfterClass (org.junit.AfterClass)2 InputStreamReader (java.io.InputStreamReader)1