Search in sources :

Example 16 with TestConfiguration

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

the class ProtocolTest method createSocket.

/**
 * Initializes a socket to the server.
 *
 * @return A socket connected to the server.
 * @throws IOException if reading/writing to the socket fails
 * @throws UnknownHostException if the server host cannot be resolved
 */
private static Socket createSocket() throws IOException, UnknownHostException {
    Socket socket = null;
    final TestConfiguration cfg = TestConfiguration.getCurrent();
    try {
        socket = AccessController.doPrivileged(new java.security.PrivilegedExceptionAction<Socket>() {

            public Socket run() throws IOException, UnknownHostException {
                return new Socket(cfg.getHostName(), cfg.getPort());
            }
        });
    } catch (PrivilegedActionException pae) {
        if (pae.getCause() instanceof IOException) {
            throw (IOException) pae.getCause();
        } else if (pae.getCause() instanceof UnknownHostException) {
            throw (UnknownHostException) pae.getCause();
        }
        fail("Unhandled exception", pae);
    }
    return socket;
}
Also used : UnknownHostException(java.net.UnknownHostException) PrivilegedActionException(java.security.PrivilegedActionException) TestConfiguration(org.apache.derbyTesting.junit.TestConfiguration) IOException(java.io.IOException) Socket(java.net.Socket)

Example 17 with TestConfiguration

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

the class SecureServerTest method connectToServer.

private void connectToServer() throws Exception {
    final TestConfiguration config = getTestConfiguration();
    String url = ("jdbc:derby://localhost:" + config.getPort() + "/" + "wombat;create=true" + ";user=" + config.getUserName() + ";password=" + config.getUserPassword());
    println("XXX in connectToServer(). url = " + url);
    // just try to get a connection
    Class.forName("org.apache.derby.jdbc.ClientDriver");
    Connection conn = DriverManager.getConnection(url);
    assertNotNull("Connection should not be null...", conn);
    conn.close();
}
Also used : TestConfiguration(org.apache.derbyTesting.junit.TestConfiguration) Connection(java.sql.Connection)

Example 18 with TestConfiguration

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

the class _Suite method suite.

/**
 * Returns the default set of compatibility tests, intended to be run
 * as part of suites.All.
 *
 * @return A default suite of compatibility tests.
 */
public static Test suite() {
    // run off of UNC paths (network drives).
    if (suffersFromDerby5889()) {
        String msg = ("tests.compatibility disabled on Windows " + "with UNC paths, see DERBY-5889");
        println(msg);
        return new BaseTestSuite(msg);
    }
    // from VersionCombinationConfigurator.getJarDirectoryOf
    if (!TestConfiguration.loadingFromJars())
        return new BaseTestSuite("Compatibility tests skipped becasue " + "they need to run from jars");
    if (!Derby.hasClient() || !Derby.hasServer()) {
        return new BaseTestSuite("Compatibility tests skipped because " + "client or server is missing");
    }
    BaseTestSuite suite = new BaseTestSuite();
    addVersionCombinations(suite);
    TestConfiguration config = TestConfiguration.getCurrent();
    return new SecurityManagerSetup(new ServerSetup(suite, "localhost", config.getPort()), // to put on the classpath for the spawned process(es).
    VersionCombinationConfigurator.class.getName().replaceAll("\\.", "/") + ".policy", true);
}
Also used : TestConfiguration(org.apache.derbyTesting.junit.TestConfiguration) ServerSetup(org.apache.derbyTesting.junit.ServerSetup) BaseTestSuite(org.apache.derbyTesting.junit.BaseTestSuite) SecurityManagerSetup(org.apache.derbyTesting.junit.SecurityManagerSetup)

Example 19 with TestConfiguration

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

the class ReadMeFilesTest method testReadMeFilesExist.

public void testReadMeFilesExist() throws IOException, SQLException {
    getConnection();
    TestConfiguration currentConfig = TestConfiguration.getCurrent();
    String dbPath = currentConfig.getDatabasePath(currentConfig.getDefaultDatabaseName());
    lookForReadmeFile(dbPath);
    lookForReadmeFile(dbPath + File.separator + "seg0");
    String logDevice = currentConfig.getConnectionAttributes().getProperty("logDevice");
    if (logDevice != null) {
        lookForReadmeFile(logDir + File.separator + "log");
    } else {
        lookForReadmeFile(dbPath + File.separator + "log");
    }
}
Also used : TestConfiguration(org.apache.derbyTesting.junit.TestConfiguration)

Example 20 with TestConfiguration

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

the class DecryptDatabaseTest method setUp.

/**
 * Makes sure that the database is encrypted.
 */
public void setUp() throws Exception {
    super.setUp();
    // Connect.
    try {
        connect(false, BOOTPW, null).close();
    } catch (SQLException sqle) {
        assertSQLState("Did you change the boot password?", "XJ004", sqle);
        // Create the database and save the encryption algorithm.
        getConnection();
        saveEncryptionAlgorithm();
    }
    // Make sure the database is (still) encrypted.
    TestConfiguration tc = getTestConfiguration();
    tc.shutdownDatabase();
    try {
        connect(false, null, null);
        tc.shutdownDatabase();
        // Database has been decrypted. Encrypt it again.
        println("encrypting database (" + encryptionAlgorithm + ")");
        connect(false, BOOTPW, "dataEncryption=true;encryptionAlgorithm=" + encryptionAlgorithm);
        tc.shutdownDatabase();
        connect(false, null, null);
        fail("database encryption failed");
    } catch (SQLException sqle) {
        assertSQLState("XBM06", sqle);
    }
}
Also used : SQLException(java.sql.SQLException) TestConfiguration(org.apache.derbyTesting.junit.TestConfiguration)

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