Search in sources :

Example 11 with ClassPathResource

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

the class ClassUtilsSmallTest method setUp.

@BeforeClass
public static void setUp() throws IOException {
    oldClassLoader = getClassLoader();
    String jar = new ClassPathResource("no-directory-entries.jar", getClassLoader()).getLocationOnDisk();
    assertTrue(new File(jar).isFile());
    ClassUtils.addJarOrDirectoryToClasspath(jar);
}
Also used : File(java.io.File) ClassPathResource(org.flywaydb.core.internal.util.scanner.classpath.ClassPathResource) BeforeClass(org.junit.BeforeClass)

Example 12 with ClassPathResource

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

the class ClassUtilsSmallTest method addDirectoryToClasspath.

/**
     * Tests dynamically adding a directory to the classpath.
     */
@Test
public void addDirectoryToClasspath() throws Exception {
    assertFalse(new ClassPathResource("pkg/runtime.conf", getClassLoader()).exists());
    String folder = new ClassPathResource("dynamic", getClassLoader()).getLocationOnDisk();
    ClassUtils.addJarOrDirectoryToClasspath(folder);
    assertTrue(new ClassPathResource("pkg/runtime.conf", getClassLoader()).exists());
    Resource[] resources = new ClassPathScanner(getClassLoader()).scanForResources(new Location("classpath:pkg"), "run", ".conf");
    assertEquals("pkg/runtime.conf", resources[0].getLocation());
}
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) ClassPathResource(org.flywaydb.core.internal.util.scanner.classpath.ClassPathResource) Test(org.junit.Test)

Example 13 with ClassPathResource

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

the class ClassUtilsSmallTest method addJarToClasspath.

/**
     * Tests dynamically adding a jar file to the classpath.
     */
@Test
public void addJarToClasspath() throws Exception {
    assertFalse(new ClassPathResource("db/migration/V1__Initial_structure.sql.sql", getClassLoader()).exists());
    assertFalse(ClassUtils.isPresent("org.flywaydb.sample.migration.V1_2__Another_user", getClassLoader()));
    String jar = new ClassPathResource("flyway-sample.jar", getClassLoader()).getLocationOnDisk();
    assertTrue(new File(jar).isFile());
    ClassUtils.addJarOrDirectoryToClasspath(jar);
    assertTrue(new ClassPathResource("db/migration/V1__Initial_structure.sql", getClassLoader()).exists());
    assertTrue(ClassUtils.isPresent("org.flywaydb.sample.migration.V1_2__Another_user", getClassLoader()));
    Resource[] resources = new ClassPathScanner(getClassLoader()).scanForResources(new Location("classpath:db/migration"), "V1__", ".sql");
    assertEquals("db/migration/V1__Initial_structure.sql", resources[0].getLocation());
    Class<?>[] classes = new ClassPathScanner(getClassLoader()).scanForClasses(new Location("classpath:org/flywaydb/sample/migration"), SpringJdbcMigration.class);
    assertEquals("org.flywaydb.sample.migration.V1_2__Another_user", classes[0].getName());
}
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) File(java.io.File) ClassPathResource(org.flywaydb.core.internal.util.scanner.classpath.ClassPathResource) Test(org.junit.Test)

Example 14 with ClassPathResource

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

the class ClassUtilsSmallTest method addDirectoryToClasspathDefaultPackage.

/**
     * Tests dynamically adding a directory to the default package of classpath.
     */
@Test
public void addDirectoryToClasspathDefaultPackage() throws Exception {
    assertFalse(new ClassPathResource("runtime.conf", getClassLoader()).exists());
    String folder = new ClassPathResource("dynamic/pkg2", getClassLoader()).getLocationOnDisk();
    ClassUtils.addJarOrDirectoryToClasspath(folder);
    assertTrue(new ClassPathResource("funtime.properties", getClassLoader()).exists());
    Resource[] resources = new ClassPathScanner(getClassLoader()).scanForResources(new Location("classpath:"), "fun", ".properties");
    assertEquals("funtime.properties", resources[1].getLocation());
}
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) ClassPathResource(org.flywaydb.core.internal.util.scanner.classpath.ClassPathResource) Test(org.junit.Test)

Example 15 with ClassPathResource

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

the class OracleSqlScriptSmallTest method parseSqlStatementsWithInlineCommentsInsidePlSqlBlocks.

@Test
public void parseSqlStatementsWithInlineCommentsInsidePlSqlBlocks() throws Exception {
    String source = new ClassPathResource("migration/dbsupport/oracle/sql/function/V2__FunctionWithConditionals.sql", Thread.currentThread().getContextClassLoader()).loadAsString("UTF-8");
    SqlScript sqlScript = new SqlScript(source, new OracleDbSupport(null));
    List<SqlStatement> sqlStatements = sqlScript.getSqlStatements();
    assertEquals(1, sqlStatements.size());
    assertEquals(18, sqlStatements.get(0).getLineNumber());
    assertTrue(sqlStatements.get(0).getSql().contains("/* for the rich */"));
}
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