Search in sources :

Example 36 with DriverDataSource

use of org.flywaydb.core.internal.util.jdbc.DriverDataSource in project flyway by flyway.

the class OracleDbSupportMediumTest method checkCurrentSchema.

/**
     * Checks the result of the getCurrentSchemaName call.
     *
     * @param useProxy Flag indicating whether to check it using a proxy user or not.
     */
private void checkCurrentSchema(boolean useProxy) throws Exception {
    Properties customProperties = getConnectionProperties();
    String user = customProperties.getProperty("oracle.user");
    String password = customProperties.getProperty("oracle.password");
    String url = customProperties.getProperty("oracle.url");
    String dataSourceUser = useProxy ? "\"flyway_proxy\"[" + user + "]" : user;
    DataSource dataSource = new DriverDataSource(Thread.currentThread().getContextClassLoader(), null, url, dataSourceUser, password, null);
    Connection connection = dataSource.getConnection();
    OracleDbSupport dbSupport = new OracleDbSupport(connection);
    String currentSchema = dbSupport.getCurrentSchemaName();
    connection.close();
    assertEquals(user.toUpperCase(), currentSchema);
}
Also used : DriverDataSource(org.flywaydb.core.internal.util.jdbc.DriverDataSource) Connection(java.sql.Connection) Properties(java.util.Properties) DataSource(javax.sql.DataSource) DriverDataSource(org.flywaydb.core.internal.util.jdbc.DriverDataSource)

Example 37 with DriverDataSource

use of org.flywaydb.core.internal.util.jdbc.DriverDataSource in project flyway by flyway.

the class SQLiteMigrationMediumTest method createDataSource.

@Override
protected DataSource createDataSource(Properties customProperties) {
    SQLiteConfig config = new SQLiteConfig();
    config.setOpenMode(SQLiteOpenMode.CREATE);
    config.setOpenMode(SQLiteOpenMode.DELETEONCLOSE);
    config.setOpenMode(SQLiteOpenMode.READWRITE);
    config.setOpenMode(SQLiteOpenMode.TRANSIENT_DB);
    config.enforceForeignKeys(true);
    return new DriverDataSource(Thread.currentThread().getContextClassLoader(), null, "jdbc:sqlite:target/sqlite-" + testName.getMethodName(), "", "", config.toProperties());
}
Also used : DriverDataSource(org.flywaydb.core.internal.util.jdbc.DriverDataSource) SQLiteConfig(org.sqlite.SQLiteConfig)

Example 38 with DriverDataSource

use of org.flywaydb.core.internal.util.jdbc.DriverDataSource in project flyway by flyway.

the class EnterpriseDBSuperUserMigrationMediumTest method setUp.

@Before
public void setUp() throws Exception {
    File customPropertiesFile = new File(System.getProperty("user.home") + "/flyway-mediumtests.properties");
    Properties customProperties = new Properties();
    if (customPropertiesFile.canRead()) {
        customProperties.load(new FileInputStream(customPropertiesFile));
    }
    String password = customProperties.getProperty("enterprisedb.password", "flyway");
    String url = customProperties.getProperty("enterprisedb.url", "jdbc:edb://localhost/flyway_db");
    flyway = new Flyway();
    flyway.setSchemas("super_user_test");
    flyway.setDataSource(new DriverDataSource(Thread.currentThread().getContextClassLoader(), null, url, "flyway", password, new Properties()));
    flyway.setValidateOnMigrate(true);
    flyway.clean();
}
Also used : Flyway(org.flywaydb.core.Flyway) DriverDataSource(org.flywaydb.core.internal.util.jdbc.DriverDataSource) Properties(java.util.Properties) File(java.io.File) FileInputStream(java.io.FileInputStream) Before(org.junit.Before)

Example 39 with DriverDataSource

use of org.flywaydb.core.internal.util.jdbc.DriverDataSource in project flyway by flyway.

the class EnterpriseDBDbSupportMediumTest method createDataSource.

/**
     * Creates a datasource for use in tests.
     *
     * @return The new datasource.
     */
private DataSource createDataSource() throws Exception {
    File customPropertiesFile = new File(System.getProperty("user.home") + "/flyway-mediumtests.properties");
    Properties customProperties = new Properties();
    if (customPropertiesFile.canRead()) {
        customProperties.load(new FileInputStream(customPropertiesFile));
    }
    String user = customProperties.getProperty("enterprisedb.user", "flyway");
    String password = customProperties.getProperty("enterprisedb.password", "flyway");
    String url = customProperties.getProperty("enterprisedb.url", "jdbc:edb://localhost/flyway_db");
    return new DriverDataSource(Thread.currentThread().getContextClassLoader(), null, url, user, password, new Properties());
}
Also used : DriverDataSource(org.flywaydb.core.internal.util.jdbc.DriverDataSource) Properties(java.util.Properties) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 40 with DriverDataSource

use of org.flywaydb.core.internal.util.jdbc.DriverDataSource in project flyway by flyway.

the class EnterpriseDBMigrationMediumTest method emptySearchPath.

@Test
public void emptySearchPath() {
    Flyway flyway1 = new Flyway();
    DriverDataSource driverDataSource = (DriverDataSource) dataSource;
    flyway1.setDataSource(new DriverDataSource(Thread.currentThread().getContextClassLoader(), null, driverDataSource.getUrl(), driverDataSource.getUser(), driverDataSource.getPassword(), new Properties()) {

        @Override
        public Connection getConnection() throws SQLException {
            Connection connection = super.getConnection();
            Statement statement = null;
            try {
                statement = connection.createStatement();
                statement.execute("SELECT set_config('search_path', '', false)");
            } finally {
                JdbcUtils.closeStatement(statement);
            }
            return connection;
        }
    });
    flyway1.setLocations(getBasedir());
    flyway1.setSchemas("public");
    flyway1.migrate();
}
Also used : Flyway(org.flywaydb.core.Flyway) DriverDataSource(org.flywaydb.core.internal.util.jdbc.DriverDataSource) SQLException(java.sql.SQLException) Statement(java.sql.Statement) Connection(java.sql.Connection) Test(org.junit.Test)

Aggregations

DriverDataSource (org.flywaydb.core.internal.util.jdbc.DriverDataSource)45 Test (org.junit.Test)29 Properties (java.util.Properties)11 File (java.io.File)6 FileInputStream (java.io.FileInputStream)6 Connection (java.sql.Connection)6 Flyway (org.flywaydb.core.Flyway)6 MigrationInfo (org.flywaydb.core.api.MigrationInfo)5 SQLException (java.sql.SQLException)4 Statement (java.sql.Statement)4 FlywayException (org.flywaydb.core.api.FlywayException)4 DataSource (javax.sql.DataSource)3 HashMap (java.util.HashMap)2 JdbcTemplate (org.flywaydb.core.internal.dbsupport.JdbcTemplate)2 Before (org.junit.Before)2 LocalRdbmsServiceTestConfig (com.google.appengine.tools.development.testing.LocalRdbmsServiceTestConfig)1 LocalServiceTestHelper (com.google.appengine.tools.development.testing.LocalServiceTestHelper)1 PrintWriter (java.io.PrintWriter)1 Map (java.util.Map)1 HBaseTestingUtility (org.apache.hadoop.hbase.HBaseTestingUtility)1