use of org.apache.derbyTesting.junit.ClasspathSetup in project derby by apache.
the class DatabaseClassLoadingTest method suite.
/**
* Run the tests only in embedded since this is testing
* server side behaviour. Due to DERBY-537 and DERBY-2040
* most of the tests are run without a security manager.
* Ordering is important here so the fixtures are added
* explicitly.
*/
public static Test suite() throws Exception {
final BaseTestSuite suite = new BaseTestSuite("DatabaseClassLoadingTest");
// Need DriverManager to execute the add contact procedure
// as it uses server side jdbc.
Test test = suite;
if (JDBC.vmSupportsJDBC3()) {
String[] orderedTests = { "testJarHandling", "testWithNoInstalledJars", "testWithNoClasspath", "testSetClasspath", "testAddContact", "testGetResource", "testAlterTable", "testClassPathRollback", "testReplaceJar", "testReplacedClass", "testSecondJar", "testSignedJar", "testCreateDatabaseJar", "testHackedJarReplacedClass", "testInvalidJar", "testRemoveJar", "testLoadJavaClassIndirectly", "testLoadJavaClassDirectly", "testLoadJavaClassDirectly2", "testLoadJavaClassDirectly3", "testLoadDerbyClassIndirectly", "testIndirectLoading", "testTableFunctionInJar", "testUDAInJar", "test_5352" };
for (int i = 0; i < orderedTests.length; i++) {
suite.addTest(new DatabaseClassLoadingTest(orderedTests[i]));
}
suite.addTest(new DatabaseClassLoadingTest("testDatabaseInJar"));
// to delete the jar file afterwards.
if (ClasspathSetup.supportsClose()) {
suite.addTest(new ClasspathSetup(new DatabaseClassLoadingTest("testDatabaseInClasspath"), SupportFilesSetup.getReadOnlyURL("dclt.jar")));
}
// No security manager because the test uses getClass().getClassLoader()
// in an installed jar to ensure that the class loader for
// specific classes is correct. This operation is not allowed in general.
suite.addTest(SecurityManagerSetup.noSecurityManager(new DatabaseClassLoadingTest("testClassLoadOrdering")));
// Add test cases accessing a classpath database when a login
// timeout has been specified.
suite.addTest(loginTimeoutSuite());
test = new SupportFilesSetup(suite, new String[] { "functionTests/tests/lang/dcl_emc1.jar", "functionTests/tests/lang/dcl_emcaddon.jar", "functionTests/tests/lang/dcl_emc2.jar", "functionTests/tests/lang/dcl_emc2s.jar", "functionTests/tests/lang/dcl_emc2sm.jar", "functionTests/tests/lang/dcl_emc2l.jar", "functionTests/tests/lang/dcl_java.jar", "functionTests/tests/lang/dcl_ot1.jar", "functionTests/tests/lang/dcl_ot2.jar", "functionTests/tests/lang/dcl_ot3.jar", "functionTests/tests/lang/dcl_id.jar", "functionTests/tests/lang/dummy_vti.jar", "functionTests/tests/lang/median_uda.jar" });
}
return new CleanDatabaseTestSetup(test) {
protected void decorateSQL(Statement s) throws SQLException {
s.executeUpdate("create schema emc");
s.executeUpdate("create schema \"emcAddOn\"");
s.executeUpdate("create table emc.contacts " + "(id int primary key, e_mail varchar(30))");
s.executeUpdate("create procedure EMC.ADDCONTACT(id INT, e_mail VARCHAR(30)) " + "MODIFIES SQL DATA " + "external name 'org.apache.derbyTesting.databaseclassloader.emc.addContact' " + "language java parameter style java");
s.executeUpdate("create function EMC.GETARTICLE(path VARCHAR(60)) " + "RETURNS VARCHAR(256) " + "NO SQL " + "external name 'org.apache.derbyTesting.databaseclassloader.emc.getArticle' " + "language java parameter style java");
// function that gets the signers of the class (loaded from the jar)
s.executeUpdate("CREATE FUNCTION EMC.GETSIGNERS(" + "CLASS_NAME VARCHAR(256)) RETURNS VARCHAR(60) " + "NO SQL LANGUAGE JAVA PARAMETER STYLE JAVA " + "EXTERNAL NAME 'org.apache.derbyTesting.databaseclassloader.emc.getSigners'");
s.executeUpdate("CREATE FUNCTION \"emcAddOn\".VALIDCONTACT(E_MAIL VARCHAR(30)) " + "RETURNS SMALLINT " + "READS SQL DATA LANGUAGE JAVA PARAMETER STYLE JAVA " + "EXTERNAL NAME 'org.apache.derbyTesting.databaseclassloader.addon.vendor.util.valid'");
}
};
}
use of org.apache.derbyTesting.junit.ClasspathSetup in project derby by apache.
the class DatabaseClassLoadingTest method loginTimeoutSuite.
/**
* Create a test suite that verifies the fix for DERBY-6107. Connection
* attempts used to fail when trying to access a classpath database that
* lived in the context class loader, if a login timeout was used and a
* previous connection attempt had been made from a thread that did not
* have the database in its context class loader.
*/
private static Test loginTimeoutSuite() throws Exception {
BaseTestSuite suite = new BaseTestSuite("Class loading with login timeout");
// First run a test when the database is not in the classpath.
// Expect the connection attempt to fail.
suite.addTest(new DatabaseClassLoadingTest("testLoginTimeoutNotInClasspath"));
// afterwards. (DERBY-2162)
if (ClasspathSetup.supportsClose()) {
suite.addTest(new ClasspathSetup(new DatabaseClassLoadingTest("testLoginTimeoutInClasspath"), SupportFilesSetup.getReadOnlyURL("dclt.jar")));
}
// Finally, check that the database cannot be found anymore after
// it has been removed from the classpath.
suite.addTest(new DatabaseClassLoadingTest("testLoginTimeoutNotInClasspath"));
// time out.
return new LoginTimeoutTestSetup(suite, 100);
}
use of org.apache.derbyTesting.junit.ClasspathSetup in project derby by apache.
the class NativeAuthenticationServiceTest method decorate.
/**
* <p>
* Wrap base test with standard decorators in order to setup system
* properties and allow for the creation of multiple databases with
* stored properties that can't be removed at tearDown time.
* </p>
*/
private Test decorate(boolean clientServer) throws Exception {
String credentialsDBPhysicalName = TestConfiguration.generateUniqueDatabaseName();
Test result = this;
//
if (clientServer) {
result = TestConfiguration.clientServerDecorator(result);
}
//
// Turn on the property which enables NATIVE authentication. This will trigger
// an engine shutdown at the end of the test. We want to shutdown the engine
// before deleting the physical databases. This is because we need one of the
// databases (the credentials db) in order to authenticate engine shutdown.
//
Properties systemProperties = null;
try {
systemProperties = systemProperties(credentialsDBPhysicalName);
} catch (Exception e) {
printStackTrace(e);
}
println(nameOfTest());
println(" NativeAuthenticationServiceTest.decorate() systemProperties = " + systemProperties);
result = new SystemPropertyTestSetup(result, systemProperties, true);
//
if (enableSubprotocolTests()) {
// Add a jar file to the classpath so that we can test the classpath subprotocol.
URL nast2Jar = SupportFilesSetup.getReadOnlyURL(NAST2_JAR_FILE);
result = new ClasspathSetup(result, nast2Jar);
// Add the jar files needed for testing jar and classpath subprotocols.
result = new SupportFilesSetup(result, SUPPORT_FILES_SOURCE, null, SUPPORT_FILES_TARGET, null);
}
//
// Register temporary databases, where the test will do its work.
// We can't use the default, re-usable database because NATIVE authentication stores
// persistent properties which cannot be turned off.
//
result = TestConfiguration.additionalDatabaseDecoratorNoShutdown(result, CREDENTIALS_DB, credentialsDBPhysicalName);
result = TestConfiguration.additionalDatabaseDecoratorNoShutdown(result, SECOND_DB);
result = TestConfiguration.additionalDatabaseDecoratorNoShutdown(result, THIRD_DB);
result = _fourthDBSetup = TestConfiguration.additionalDatabaseDecoratorNoShutdown(result, FOURTH_DB, true);
result = _fifthDBSetup = TestConfiguration.additionalDatabaseDecoratorNoShutdown(result, FIFTH_DB, true);
result = _sixthDBSetup = TestConfiguration.additionalDatabaseDecoratorNoShutdown(result, SIXTH_DB, true);
result = _seventhDBSetup = TestConfiguration.additionalDatabaseDecoratorNoShutdown(result, SEVENTH_DB, true);
result = _eighthDBSetup = TestConfiguration.additionalDatabaseDecoratorNoShutdown(result, EIGHTH_DB, true);
result = _ninthDBSetup = TestConfiguration.additionalDatabaseDecoratorNoShutdown(result, NINTH_DB, true);
result = TestConfiguration.additionalDatabaseDecoratorNoShutdown(result, TENTH_DB);
result = TestConfiguration.additionalDatabaseDecoratorNoShutdown(result, ELEVENTH_DB);
result = TestConfiguration.additionalDatabaseDecoratorNoShutdown(result, TWELTH_DB);
result = TestConfiguration.additionalDatabaseDecoratorNoShutdown(result, THIRTEENTH_DB);
result = TestConfiguration.additionalDatabaseDecoratorNoShutdown(result, FOURTEENTH_DB);
result = _fifteenthDBSetup = TestConfiguration.additionalDatabaseDecoratorNoShutdown(result, FIFTEENTH_DB, true);
result = TestConfiguration.changeUserDecorator(result, DBO, getPassword(DBO));
return result;
}
Aggregations