Search in sources :

Example 21 with TestConfiguration

use of org.apache.derbyTesting.junit.TestConfiguration in project derby by apache.

the class PhaseChanger method setUp.

/**
 * Set the phase and boot the database, creating it
 * or upgrading it as required. The thread context
 * class loader is changed to point to the old
 * jar files if required for the phase.
 */
protected void setUp() throws SQLException {
    UpgradeChange.phase.set(phase);
    UpgradeChange.oldVersion.set(version);
    TestConfiguration config = TestConfiguration.getCurrent();
    trace = config.doTrace();
    if (trace) {
        String versStr = ((int[]) UpgradeChange.oldVersion.get())[0] + "." + ((int[]) UpgradeChange.oldVersion.get())[1] + "." + ((int[]) UpgradeChange.oldVersion.get())[2] + "." + ((int[]) UpgradeChange.oldVersion.get())[3];
        BaseTestCase.traceit("Test upgrade from: " + versStr + ", phase: " + UpgradeChange.PHASES[phase]);
        if (UpgradeChange.PHASES[phase].equals("UPGRADE")) {
            BaseTestCase.traceit("Upgrade attributes = " + upgradeAttributes);
        }
    }
    if (loader != null) {
        previousLoader = Thread.currentThread().getContextClassLoader();
        ClassLoaderTestSetup.setThreadLoader(loader);
    }
    DataSource ds = JDBCDataSource.getDataSource();
    switch(phase) {
        case UpgradeChange.PH_POST_HARD_UPGRADE:
            // in a setup method.
            return;
        case UpgradeChange.PH_CREATE:
            JDBCDataSource.setBeanProperty(ds, "createDatabase", "create");
            break;
        case UpgradeChange.PH_HARD_UPGRADE:
            JDBCDataSource.setBeanProperty(ds, "connectionAttributes", upgradeAttributes);
            break;
        default:
            break;
    }
    // Ensure the database exists or upgrade it.
    ds.getConnection().close();
}
Also used : TestConfiguration(org.apache.derbyTesting.junit.TestConfiguration) DataSource(javax.sql.DataSource) JDBCDataSource(org.apache.derbyTesting.junit.JDBCDataSource)

Aggregations

TestConfiguration (org.apache.derbyTesting.junit.TestConfiguration)21 File (java.io.File)7 Connection (java.sql.Connection)5 IOException (java.io.IOException)2 SQLException (java.sql.SQLException)2 Properties (java.util.Properties)2 DataSource (javax.sql.DataSource)2 JDBCDataSource (org.apache.derbyTesting.junit.JDBCDataSource)2 PrintStream (java.io.PrintStream)1 PrintWriter (java.io.PrintWriter)1 Socket (java.net.Socket)1 UnknownHostException (java.net.UnknownHostException)1 PrivilegedActionException (java.security.PrivilegedActionException)1 DatabaseMetaData (java.sql.DatabaseMetaData)1 Driver (java.sql.Driver)1 PreparedStatement (java.sql.PreparedStatement)1 Statement (java.sql.Statement)1 HashSet (java.util.HashSet)1 Test (junit.framework.Test)1 org.apache.derby.tools.dblook (org.apache.derby.tools.dblook)1