org.apache.derbyTesting.functionTests.tests.lang
Class DatabaseClassLoadingTest

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.apache.derbyTesting.junit.BaseTestCase
              extended by org.apache.derbyTesting.junit.BaseJDBCTestCase
                  extended by org.apache.derbyTesting.functionTests.tests.lang.DatabaseClassLoadingTest
All Implemented Interfaces:
junit.framework.Test

public class DatabaseClassLoadingTest
extends BaseJDBCTestCase

Test database class loading, executing routines from the installed jars including accessing resources. Replacing jars and handling signed jars is also tested.


Field Summary
 
Fields inherited from class org.apache.derbyTesting.junit.BaseTestCase
DEFAULT_DB_DIR, DERBY_LOG, ERRORSTACKTRACEFILE
 
Constructor Summary
DatabaseClassLoadingTest(java.lang.String name)
           
 
Method Summary
(package private) static void addEntries(java.util.zip.ZipOutputStream zos, java.io.File dir, java.lang.String dbName, int old)
           
private static void addFile(java.util.zip.ZipOutputStream zos, java.io.File f, java.lang.String dbName, int old)
           
private  void checkCorrectLoader(java.lang.String className, java.sql.PreparedStatement ps1, java.sql.PreparedStatement ps2, java.sql.PreparedStatement ps3)
           
private  void checkLoading(java.lang.String order)
          Run a number of tests to ensure classes are loaded from the correct class loader.
private static void createArchive(java.lang.String jarName, java.io.File dbDir, java.lang.String dbName)
          jarname - jarname to use path - path to database dbname - database name in archive
private  void derby2035Workaround()
           
private static void getResourceTests(java.sql.Connection conn)
           
private  void installJar(java.lang.String resource, java.lang.String jarName)
           
private  void loadJavaClass(java.lang.String method, java.lang.String expectedSQLState)
          Test loading classes in the java. and javax. namespaces from a jar, it should be disallowed or be ignored.
private static void readOnlyTest(javax.sql.DataSource ds)
          Run an number of statements against a jar'ed database to ensure it is read-only and that class loading works from jar files embedded in jar'ed up databases.
private  void removeJar(java.lang.String jarName)
           
private  void replaceJar(java.lang.String resource, java.lang.String jarName)
           
private static void setContextClassLoader(java.net.URL url)
           
private  void setDBClasspath(java.lang.String cp)
           
private static void signersTests(java.sql.Connection conn)
           
static junit.framework.Test suite()
          Run the tests only in embedded since this is testing server side behaviour.
 void testAddContact()
          Test that a new connection successfully sees the changes.
 void testAlterTable()
          Alter the table to add a column, the add contact procedure should still work.
 void testClassLoadOrdering()
          Test ordering of class loading.
 void testClassPathRollback()
          check the roll back of class loading.
 void testCreateDatabaseJar()
          Create a Jar of the current database.
 void testDatabaseInClasspath()
           
 void testDatabaseInJar()
          Test the jar'ed up database created by testCreateDatabaseJar accessing the database using the jar(path to archive)db form of database name.
 void testGetResource()
           
 void testHackedJarReplacedClass()
          Replace the signed jar with a hacked jar. emc.class modified to diable valid e-mail address check but using same signatures within jar.
 void testIndirectLoading()
          Test that loading of Derby's internal classes from an installed jar file is disallowed.
 void testInvalidJar()
          replace with a hacked jar file, emc.class modified to be an invalid class (no signing on this jar).
 void testJarHandling()
          Test the sqlj procedures without setting any database classpath.
 void testLoadDerbyClassIndirectly()
          Load a org.apache.derby class directly (ie. through a direct procedure call) from the jar file.
 void testLoadJavaClassDirectly()
          Load a java.sql class directly (ie. through a direct procedure call) from the jar file.
 void testLoadJavaClassDirectly2()
          Load a java.derby99 class directly (ie. through a direct procedure call) from the jar file.
 void testLoadJavaClassDirectly3()
          Load a javax.derby99 class directly (ie. through a direct procedure call) from the jar file.
 void testLoadJavaClassIndirectly()
          Load a java.sql class indirectly (ie. through a valid class in the installed jar file) from the jar file.
 void testRemoveJar()
           
 void testReplacedClass()
          Change of class due to testReplaceJar that changes the application to run checks on the e-mail to ensure it is valid (in this case by seeing if it simply includes 'spam' in the title).
 void testReplaceJar()
          Replace the jar to later test the prepare from a different connection picks up the new version.
 void testSecondJar()
          now add another jar in to test two jars and a quoted identifer for the jar names.
 void testSetClasspath()
          Set the classpath to include the MAIL_APP jar.
 void testSignedJar()
          Test to see if the jar signatures can be obtained from the jar file.
 void testTableFunctionInJar()
          Test that table functions can be invoked from inside jar files stored in the database.
 void testWithNoClasspath()
          Install the jar, but don't set the classpath.
 void testWithNoInstalledJars()
          Test the routines fail before the jars that contain their code have been installed and/or set in the classpath.
 
Methods inherited from class org.apache.derbyTesting.junit.BaseJDBCTestCase
assertCallError, assertCheckTable, assertCompileError, assertEquals, assertEquals, assertEquals, assertEquivalentDataType, assertGetIntError, assertNextError, assertPreparedStatementError, assertSQLExceptionEquals, assertSQLState, assertSQLState, assertStatementError, assertStatementError, assertStatementError, assertStatementError, assertTableRowCount, assertUpdateCount, assertUpdateCount, checkAllConsistency, checkEstimatedRowCount, commit, createStatement, createStatement, createStatement, dropTable, dropTable, getConnection, getDatabaseProperty, getLastSQLException, initializeConnection, openConnection, openDefaultConnection, openDefaultConnection, openUserConnection, prepareCall, prepareCall, prepareCall, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, rollback, runScript, runScript, runSQLCommands, setAutoCommit, tearDown, usingDB2Client, usingDerbyNetClient, usingEmbedded
 
Methods inherited from class org.apache.derbyTesting.junit.BaseTestCase
alarm, assertEquals, assertEquals, assertEquals, assertExecJavaCmdAsExpected, assertSecurityManager, assertThrowableEquals, execJavaCmd, fail, getFailureFolder, getJavaExecutableName, getSystemProperty, getTestConfiguration, getTestResource, openTestResource, println, printStackTrace, readProcessOutput, removeDirectory, removeDirectory, removeSystemProperty, runBare, setSystemProperty, traceit
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runTest, setName, setUp, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DatabaseClassLoadingTest

public DatabaseClassLoadingTest(java.lang.String name)
Method Detail

suite

public static junit.framework.Test 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.


testWithNoInstalledJars

public void testWithNoInstalledJars()
                             throws java.sql.SQLException
Test the routines fail before the jars that contain their code have been installed and/or set in the classpath.

Throws:
java.sql.SQLException

testJarHandling

public void testJarHandling()
                     throws java.sql.SQLException,
                            java.net.MalformedURLException
Test the sqlj procedures without setting any database classpath. This allows testing with the security manager without hitting the bugs that exist when the database class path is set with the security manager.

Throws:
java.sql.SQLException
java.net.MalformedURLException

testWithNoClasspath

public void testWithNoClasspath()
                         throws java.sql.SQLException,
                                java.net.MalformedURLException
Install the jar, but don't set the classpath.

Throws:
java.sql.SQLException
java.net.MalformedURLException

testSetClasspath

public void testSetClasspath()
                      throws java.sql.SQLException
Set the classpath to include the MAIL_APP jar.

Throws:
java.sql.SQLException

testAddContact

public void testAddContact()
                    throws java.sql.SQLException
Test that a new connection successfully sees the changes.

Throws:
java.sql.SQLException

testGetResource

public void testGetResource()
                     throws java.sql.SQLException
Throws:
java.sql.SQLException

getResourceTests

private static void getResourceTests(java.sql.Connection conn)
                              throws java.sql.SQLException
Throws:
java.sql.SQLException

testAlterTable

public void testAlterTable()
                    throws java.sql.SQLException
Alter the table to add a column, the add contact procedure should still work.

Throws:
java.sql.SQLException

testClassPathRollback

public void testClassPathRollback()
                           throws java.sql.SQLException,
                                  java.net.MalformedURLException
check the roll back of class loading. install a new jar in a transaction, see that the new class is used and then rollback the old class should be used after the rollback.

Throws:
java.sql.SQLException
java.net.MalformedURLException

testReplaceJar

public void testReplaceJar()
                    throws java.sql.SQLException,
                           java.net.MalformedURLException
Replace the jar to later test the prepare from a different connection picks up the new version.

Throws:
java.sql.SQLException
java.net.MalformedURLException

testReplacedClass

public void testReplacedClass()
                       throws java.sql.SQLException
Change of class due to testReplaceJar that changes the application to run checks on the e-mail to ensure it is valid (in this case by seeing if it simply includes 'spam' in the title).

Throws:
java.sql.SQLException

testSecondJar

public void testSecondJar()
                   throws java.sql.SQLException,
                          java.net.MalformedURLException
now add another jar in to test two jars and a quoted identifer for the jar names.

Throws:
java.net.MalformedURLException
java.sql.SQLException

testSignedJar

public void testSignedJar()
                   throws java.sql.SQLException,
                          java.net.MalformedURLException
Test to see if the jar signatures can be obtained from the jar file. The jar was signed with a self signed certificate keytool -delete -alias emccto -keystore emcks -storepass ab987c keytool -genkey -dname "cn=EMC CTO, ou=EMC APP, o=Easy Mail Company, c=US" -alias emccto -keypass kpi135 -keystore emcks -storepass ab987c keytool -selfcert -alias emccto -keypass kpi135 -validity 36500 -keystore emcks -storepass ab987c keytool -keystore emcks -storepass ab987c -list -v jarsigner -keystore emcks -storepass ab987c -keypass kpi135 -signedjar dcl_emc2s.jar dcl_emc2.jar emccto keytool -delete -alias emccto -keystore emcks -storepass ab987c

Throws:
java.sql.SQLException
java.net.MalformedURLException

signersTests

private static void signersTests(java.sql.Connection conn)
                          throws java.sql.SQLException
Throws:
java.sql.SQLException

testHackedJarReplacedClass

public void testHackedJarReplacedClass()
                                throws java.sql.SQLException,
                                       java.net.MalformedURLException
Replace the signed jar with a hacked jar. emc.class modified to diable valid e-mail address check but using same signatures within jar. Class loader should reject. rejects it.

Throws:
java.sql.SQLException
java.net.MalformedURLException

testInvalidJar

public void testInvalidJar()
                    throws java.sql.SQLException,
                           java.net.MalformedURLException
replace with a hacked jar file, emc.class modified to be an invalid class (no signing on this jar).

Throws:
java.net.MalformedURLException
java.sql.SQLException

testRemoveJar

public void testRemoveJar()
                   throws java.sql.SQLException
Throws:
java.sql.SQLException

testCreateDatabaseJar

public void testCreateDatabaseJar()
                           throws java.lang.Exception
Create a Jar of the current database.

Throws:
java.lang.Exception

testDatabaseInJar

public void testDatabaseInJar()
                       throws java.sql.SQLException
Test the jar'ed up database created by testCreateDatabaseJar accessing the database using the jar(path to archive)db form of database name.

Throws:
java.sql.SQLException

testDatabaseInClasspath

public void testDatabaseInClasspath()
                             throws java.sql.SQLException,
                                    java.net.MalformedURLException
Throws:
java.sql.SQLException
java.net.MalformedURLException

testLoadJavaClassIndirectly

public void testLoadJavaClassIndirectly()
                                 throws java.sql.SQLException,
                                        java.net.MalformedURLException
Load a java.sql class indirectly (ie. through a valid class in the installed jar file) from the jar file.

Throws:
java.sql.SQLException
java.net.MalformedURLException

testLoadJavaClassDirectly

public void testLoadJavaClassDirectly()
                               throws java.sql.SQLException,
                                      java.net.MalformedURLException
Load a java.sql class directly (ie. through a direct procedure call) from the jar file.

Throws:
java.sql.SQLException
java.net.MalformedURLException

testLoadJavaClassDirectly2

public void testLoadJavaClassDirectly2()
                                throws java.sql.SQLException,
                                       java.net.MalformedURLException
Load a java.derby99 class directly (ie. through a direct procedure call) from the jar file. This is to see if additional non-standard java.* packages can be added into the JVM

Throws:
java.sql.SQLException
java.net.MalformedURLException

testLoadJavaClassDirectly3

public void testLoadJavaClassDirectly3()
                                throws java.sql.SQLException,
                                       java.net.MalformedURLException
Load a javax.derby99 class directly (ie. through a direct procedure call) from the jar file. This is to see if additional non-standard javax.* packages can be added into the JVM. As an implementation note this is blocked by Derby's class loader, not the JVM's security mechanism.

Throws:
java.sql.SQLException
java.net.MalformedURLException

testLoadDerbyClassIndirectly

public void testLoadDerbyClassIndirectly()
                                  throws java.sql.SQLException,
                                         java.net.MalformedURLException
Load a org.apache.derby class directly (ie. through a direct procedure call) from the jar file. As an implementation note this is blocked by Derby's class loader, not the JVM's security mechanism.

Throws:
java.sql.SQLException
java.net.MalformedURLException

loadJavaClass

private void loadJavaClass(java.lang.String method,
                           java.lang.String expectedSQLState)
                    throws java.sql.SQLException,
                           java.net.MalformedURLException
Test loading classes in the java. and javax. namespaces from a jar, it should be disallowed or be ignored. These tests are run as separate fixtures to ensure the failed loading does not affect subsequent attempts to load.

Throws:
java.net.MalformedURLException
java.sql.SQLException

readOnlyTest

private static void readOnlyTest(javax.sql.DataSource ds)
                          throws java.sql.SQLException
Run an number of statements against a jar'ed database to ensure it is read-only and that class loading works from jar files embedded in jar'ed up databases.

Throws:
java.sql.SQLException

testClassLoadOrdering

public void testClassLoadOrdering()
                           throws java.sql.SQLException,
                                  java.net.MalformedURLException
Test ordering of class loading.

Throws:
java.net.MalformedURLException
java.sql.SQLException

checkLoading

private void checkLoading(java.lang.String order)
                   throws java.sql.SQLException
Run a number of tests to ensure classes are loaded from the correct class loader. The order of loading the entry point classes is set by order. 123 will load the entry point classes in order OrderTest1, OrderTest2, OrderTest3. Since loading these entry point classes and the order of execution will determine the loading order of the other classes, we change the order to ensure that classes are loaded from the correct jar regardless of which class loaded it. Ie. Loading OrderTest2 first, which loads indirectly OrderObject1,2,3 ensures that even though OrderTest2 is loaded from OT2 that the others are loaded from their correct jar.

Parameters:
order - Order the entry point classes will be loaded.
Throws:
java.sql.SQLException

checkCorrectLoader

private void checkCorrectLoader(java.lang.String className,
                                java.sql.PreparedStatement ps1,
                                java.sql.PreparedStatement ps2,
                                java.sql.PreparedStatement ps3)
                         throws java.sql.SQLException
Throws:
java.sql.SQLException

testIndirectLoading

public void testIndirectLoading()
                         throws java.sql.SQLException,
                                java.net.MalformedURLException
Test that loading of Derby's internal classes from an installed jar file is disallowed.

Throws:
java.sql.SQLException
java.net.MalformedURLException

testTableFunctionInJar

public void testTableFunctionInJar()
                            throws java.sql.SQLException,
                                   java.net.MalformedURLException
Test that table functions can be invoked from inside jar files stored in the database.

Throws:
java.sql.SQLException
java.net.MalformedURLException

installJar

private void installJar(java.lang.String resource,
                        java.lang.String jarName)
                 throws java.sql.SQLException,
                        java.net.MalformedURLException
Throws:
java.sql.SQLException
java.net.MalformedURLException

replaceJar

private void replaceJar(java.lang.String resource,
                        java.lang.String jarName)
                 throws java.sql.SQLException,
                        java.net.MalformedURLException
Throws:
java.sql.SQLException
java.net.MalformedURLException

removeJar

private void removeJar(java.lang.String jarName)
                throws java.sql.SQLException
Throws:
java.sql.SQLException

setDBClasspath

private void setDBClasspath(java.lang.String cp)
                     throws java.sql.SQLException
Throws:
java.sql.SQLException

derby2035Workaround

private void derby2035Workaround()
                          throws java.sql.SQLException
Throws:
java.sql.SQLException

createArchive

private static void createArchive(java.lang.String jarName,
                                  java.io.File dbDir,
                                  java.lang.String dbName)
                           throws java.lang.Exception
jarname - jarname to use path - path to database dbname - database name in archive

Throws:
java.lang.Exception

addEntries

static void addEntries(java.util.zip.ZipOutputStream zos,
                       java.io.File dir,
                       java.lang.String dbName,
                       int old)
                throws java.lang.Exception
Throws:
java.lang.Exception

addFile

private static void addFile(java.util.zip.ZipOutputStream zos,
                            java.io.File f,
                            java.lang.String dbName,
                            int old)
                     throws java.io.IOException
Throws:
java.io.IOException

setContextClassLoader

private static void setContextClassLoader(java.net.URL url)

Built on Sat 2009-11-28 18:44:18-0800, from revision 885187

Apache Derby V10.6 Internals - Copyright © 2004,2008 The Apache Software Foundation. All Rights Reserved.