Search in sources :

Example 16 with ClassPathResource

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

the class OracleSqlScriptSmallTest method parseSqlStatements.

@Test
public void parseSqlStatements() throws Exception {
    String source = new ClassPathResource("migration/dbsupport/oracle/sql/placeholders/V1__Placeholders.sql", Thread.currentThread().getContextClassLoader()).loadAsString("UTF-8");
    SqlScript sqlScript = new SqlScript(source, new OracleDbSupport(null));
    List<SqlStatement> sqlStatements = sqlScript.getSqlStatements();
    assertEquals(3, sqlStatements.size());
    assertEquals(18, sqlStatements.get(0).getLineNumber());
    assertEquals(27, sqlStatements.get(1).getLineNumber());
    assertEquals(32, sqlStatements.get(2).getLineNumber());
    assertEquals("COMMIT", sqlStatements.get(2).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 17 with ClassPathResource

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

the class PostgreSQLSqlScriptSmallTest method parseSqlStatementsDo.

@Test
public void parseSqlStatementsDo() throws Exception {
    String source = new ClassPathResource("migration/dbsupport/postgresql/sql/dollar/V2__Even_more_dollars.sql", Thread.currentThread().getContextClassLoader()).loadAsString("UTF-8");
    SqlScript sqlScript = new SqlScript(source, new PostgreSQLDbSupport(null));
    List<SqlStatement> sqlStatements = sqlScript.getSqlStatements();
    assertEquals(3, sqlStatements.size());
    assertEquals(17, sqlStatements.get(0).getLineNumber());
    assertEquals(23, sqlStatements.get(1).getLineNumber());
    assertEquals(28, 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 18 with ClassPathResource

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

the class OracleSqlScriptSmallTest method parsePackages.

@Test
public void parsePackages() throws Exception {
    String source = new ClassPathResource("migration/dbsupport/oracle/sql/package/V1__Package.sql", Thread.currentThread().getContextClassLoader()).loadAsString("UTF-8");
    SqlScript sqlScript = new SqlScript(source, new OracleDbSupport(null));
    List<SqlStatement> sqlStatements = sqlScript.getSqlStatements();
    assertEquals(2, sqlStatements.size());
    assertEquals(17, sqlStatements.get(0).getLineNumber());
    assertEquals(33, 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 19 with ClassPathResource

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

the class MainClassLoaderSmallTest method loadConfigurationFileBackslash.

@Test
public void loadConfigurationFileBackslash() throws Exception {
    Properties properties = new Properties();
    String filename = new ClassPathResource("dynamic/pkg/runtime.conf", getClassLoader()).getLocationOnDisk();
    String[] args = new String[] { "-configFile=" + filename, "-configFileEncoding=UTF-8" };
    Main.loadConfiguration(properties, args);
    assertEquals(1, properties.size());
    assertEquals("at\\runtime", properties.getProperty("loaded"));
}
Also used : Properties(java.util.Properties) ClassPathResource(org.flywaydb.core.internal.util.scanner.classpath.ClassPathResource) Test(org.junit.Test)

Example 20 with ClassPathResource

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

the class CommandLineLargeTest method runFlywayCommandLine.

/**
     * Runs the Flyway Command Line tool.
     *
     * @param expectedReturnCode The expected return code for this invocation.
     * @param configFileName     The config file name. {@code null} for default.
     * @param operation          The operation {@code null} for none.
     * @param extraArgs          The extra arguments to pass to the tool.
     * @return The standard output produced by the tool.
     * @throws Exception thrown when the invocation failed.
     */
protected String runFlywayCommandLine(int expectedReturnCode, String configFileName, String operation, String... extraArgs) throws Exception {
    List<String> args = new ArrayList<String>();
    String installDir = new File(getInstallDir()).getAbsolutePath();
    args.add(installDir + "/flyway" + flywayCmdLineExtensionForCurrentSystem());
    if (operation != null) {
        args.add(operation);
    }
    if (configFileName != null) {
        String configFile = new ClassPathResource(configFileName, Thread.currentThread().getContextClassLoader()).getLocationOnDisk();
        args.add("-configFile=" + configFile);
    }
    args.addAll(Arrays.asList(extraArgs));
    //Debug mode
    args.add("-X");
    ProcessBuilder builder = new ProcessBuilder(args);
    builder.directory(new File(installDir));
    builder.redirectErrorStream(true);
    Process process = builder.start();
    String stdOut = FileCopyUtils.copyToString(new InputStreamReader(process.getInputStream(), "UTF-8"));
    int returnCode = process.waitFor();
    System.out.print(stdOut);
    assertEquals("Unexpected return code", expectedReturnCode, returnCode);
    // Normalize line endings across platforms
    return stdOut.replace("\r", "");
}
Also used : InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) File(java.io.File) ClassPathResource(org.flywaydb.core.internal.util.scanner.classpath.ClassPathResource)

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