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);
}
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());
}
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.
}
}
}
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());
}
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());
}
Aggregations