Search in sources :

Example 26 with ClassPathResource

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

the class ClassUtilsSmallTest method addJarToClasspathNoDirectoryEntries.

/**
     * Tests dynamically adding a jar file to the classpath.
     */
@Test
public void addJarToClasspathNoDirectoryEntries() throws Exception {
    assertTrue(new ClassPathResource("db/migration/V1_11__Create_tbl_bob.sql", getClassLoader()).exists());
    Resource[] resources = new ClassPathScanner(getClassLoader()).scanForResources(new Location("classpath:db/migration"), "V1_11", ".sql");
    Class[] classes = new ClassPathScanner(getClassLoader()).scanForClasses(new Location("classpath:db/migration"), JdbcMigration.class);
    assertEquals("db/migration/V1_11__Create_tbl_bob.sql", resources[0].getLocation());
    assertEquals(0, classes.length);
}
Also used : Resource(org.flywaydb.core.internal.util.scanner.Resource) ClassPathResource(org.flywaydb.core.internal.util.scanner.classpath.ClassPathResource) ClassPathScanner(org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner) AfterClass(org.junit.AfterClass) BeforeClass(org.junit.BeforeClass) ClassPathResource(org.flywaydb.core.internal.util.scanner.classpath.ClassPathResource) Test(org.junit.Test)

Example 27 with ClassPathResource

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

the class SapHanaSqlStatementBuilderSmallTest method parseProcedureWithEmbeddedSemicola.

private void parseProcedureWithEmbeddedSemicola(String resourceName, int numStatements) {
    final String sqlScriptSource = new ClassPathResource(resourceName, SapHanaSqlStatementBuilderSmallTest.class.getClassLoader()).loadAsString("UTF-8");
    SapHanaSqlStatementBuilder statementBuilder = new SapHanaSqlStatementBuilder();
    String[] lines = StringUtils.tokenizeToStringArray(sqlScriptSource, "\n");
    final List<String> statements = new ArrayList<String>();
    for (String line : lines) {
        statementBuilder.addLine(line);
        if (statementBuilder.isTerminated()) {
            statements.add(statementBuilder.getSqlStatement().getSql());
            statementBuilder = new SapHanaSqlStatementBuilder();
        }
    }
    assertEquals("Number of recognized statements", numStatements, statements.size());
}
Also used : ArrayList(java.util.ArrayList) ClassPathResource(org.flywaydb.core.internal.util.scanner.classpath.ClassPathResource)

Example 28 with ClassPathResource

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

the class SQLServerMigrationTestCase method msDBToolsNotCleared.

@Test
public void msDBToolsNotCleared() 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 {
        final String queryObjectCount = "SELECT COUNT(*) from sys.all_objects";
        int initialObjectsCount = jdbcTemplate.queryForInt(queryObjectCount);
        schema.clean();
        int finalObjectCount = jdbcTemplate.queryForInt(queryObjectCount);
        assertEquals("Cleaning the schema must not delete MS DB Tools objects.", initialObjectsCount, finalObjectCount);
    } 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 29 with ClassPathResource

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

the class OracleSqlScriptSmallTest method parseFunctionsAndProcedures.

@Test
public void parseFunctionsAndProcedures() throws Exception {
    String source = new ClassPathResource("migration/dbsupport/oracle/sql/function/V1__Function.sql", Thread.currentThread().getContextClassLoader()).loadAsString("UTF-8");
    SqlScript sqlScript = new SqlScript(source, new OracleDbSupport(null));
    List<SqlStatement> sqlStatements = sqlScript.getSqlStatements();
    assertEquals(5, sqlStatements.size());
    assertEquals(17, sqlStatements.get(0).getLineNumber());
    assertEquals(26, sqlStatements.get(1).getLineNumber());
    assertEquals(34, sqlStatements.get(2).getLineNumber());
    assertEquals(36, sqlStatements.get(3).getLineNumber());
    assertEquals(44, sqlStatements.get(4).getLineNumber());
    assertEquals("COMMIT", sqlStatements.get(4).getSql());
}
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 30 with ClassPathResource

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

the class OracleSqlScriptSmallTest method parseQQuotes.

@Test
public void parseQQuotes() throws Exception {
    String source = new ClassPathResource("migration/dbsupport/oracle/sql/qquote/V1__Q_Quote.sql", Thread.currentThread().getContextClassLoader()).loadAsString("UTF-8");
    SqlScript sqlScript = new SqlScript(source, new OracleDbSupport(null));
    List<SqlStatement> sqlStatements = sqlScript.getSqlStatements();
    assertEquals(12, sqlStatements.size());
}
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)

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