org.apache.derbyTesting.junit
Class BaseTestCase

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.apache.derbyTesting.junit.BaseTestCase
All Implemented Interfaces:
junit.framework.Test
Direct Known Subclasses:
_Suite, _Suite, _Suite, _Suite, _Suite, _Suite, _Suite, _Suite, _Suite, _Suite, _Suite, _Suite, _Suite, _Suite, _Suite, _Suite, _Suite, _Suite, All, AllPackages, ArrayInputStreamTest, AssertFailureTest, BaseJDBCTestCase, BlockedByteArrayTest, ByteArrayCombinerStreamTest, CharacterStreamDescriptorTest, CompatibilityCombinations, FormatableBitSetTest, IjSecurityManagerTest, InputStreamUtilTest, JDBC40TranslationTest, PackagePrivateTestSuite, PathUtilTest, PositionedStoreStreamTest, ProtocolTest, ReaderToUTF8StreamTest, ReplicationRun, ReplicationSuite, StatementKeyFactoryTest, SysinfoLocaleTest, SystemPrivilegesPermissionTest, UTF8UtilTest, VerifySignatures, VirtualFileTest, XMLSuite

public abstract class BaseTestCase
extends junit.framework.TestCase

Base class for JUnit tests.


Field Summary
protected static java.lang.String DEFAULT_DB_DIR
           
protected static java.lang.String DERBY_LOG
           
protected static java.lang.String ERRORSTACKTRACEFILE
           
private static java.io.PrintStream out
           
 
Constructor Summary
private BaseTestCase()
          No argument constructor made private to enforce naming of test cases.
  BaseTestCase(java.lang.String name)
          Create a test case with the given name.
 
Method Summary
static void alarm(java.lang.String text)
          Print alarm string
static void assertEquals(java.io.File file1, java.io.File file2)
          Assert that two files in the filesystem are identical.
static void assertEquals(java.io.InputStream is1, java.io.InputStream is2)
          Compare the contents of two streams.
static void assertEquals(java.io.Reader r1, java.io.Reader r2)
          Compare the contents of two readers.
 void assertExecJavaCmdAsExpected(java.lang.String[] expectedString, java.lang.String[] cmd, int expectedExitValue)
          Execute command using 'java' executable and verify that it completes with expected results
static void assertSecurityManager()
          Assert a security manager is installed.
static void assertThrowableEquals(java.lang.Throwable t1, java.lang.Throwable t2)
          Assert that the detailed messages of the 2 passed-in Throwable's are equal (rather than '=='), as well as their class types.
 java.lang.Process execJavaCmd(java.lang.String[] cmd)
          Execute a java command and return the process.
static void fail(java.lang.String msg, java.lang.Exception e)
          Fail; attaching an exception for more detail on cause.
 java.io.File getFailureFolder()
          Get the folder where a test leaves any information about its failure.
static java.lang.String getJavaExecutableName()
          Return the executable name for spawning java commands.
protected static java.lang.String getSystemProperty(java.lang.String name)
          Get system property.
 TestConfiguration getTestConfiguration()
          Return the current configuration for the test.
protected static java.net.URL getTestResource(java.lang.String name)
          Obtain the URL for a test resource, e.g. a policy file or a SQL script.
protected static java.io.InputStream openTestResource(java.net.URL url)
          Open the URL for a a test resource, e.g. a policy file or a SQL script.
static void println(java.lang.String text)
          Print debug string.
static void printStackTrace(java.lang.Throwable t)
          Print debug string.
 java.lang.String readProcessOutput(java.lang.Process pr)
          Reads output from a process and returns it as a string.
static void removeDirectory(java.io.File dir)
          Remove the directory and its contents.
static void removeDirectory(java.lang.String path)
          Remove the directory and its contents.
protected static void removeSystemProperty(java.lang.String name)
          Remove system property
 void runBare()
          Run the test and force installation of a security manager with the default test policy file.
protected static void setSystemProperty(java.lang.String name, java.lang.String value)
          Set system property
static void traceit(java.lang.String text)
          Print trace string.
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runTest, setName, setUp, tearDown, 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
 

Field Detail

ERRORSTACKTRACEFILE

protected static final java.lang.String ERRORSTACKTRACEFILE
See Also:
Constant Field Values

DEFAULT_DB_DIR

protected static final java.lang.String DEFAULT_DB_DIR
See Also:
Constant Field Values

DERBY_LOG

protected static final java.lang.String DERBY_LOG
See Also:
Constant Field Values

out

private static final java.io.PrintStream out
Constructor Detail

BaseTestCase

private BaseTestCase()
No argument constructor made private to enforce naming of test cases. According to JUnit documentation, this constructor is provided for serialization, which we don't currently use.

See Also:
BaseTestCase(String)

BaseTestCase

public BaseTestCase(java.lang.String name)
Create a test case with the given name.

Parameters:
name - name of the test case.
Method Detail

runBare

public void runBare()
             throws java.lang.Throwable
Run the test and force installation of a security manager with the default test policy file. Individual tests can run without a security manager or with a different policy file using the decorators obtained from SecurityManagerSetup.
Method is final to ensure security manager is enabled by default. Tests should not need to override runTest, instead use test methods setUp, tearDown methods and decorators.

Overrides:
runBare in class junit.framework.TestCase
Throws:
java.lang.Throwable

getTestConfiguration

public final TestConfiguration getTestConfiguration()
Return the current configuration for the test.


getFailureFolder

public final java.io.File getFailureFolder()
Get the folder where a test leaves any information about its failure.

Returns:
Folder to use.
See Also:
TestConfiguration.getFailureFolder(TestCase)

alarm

public static void alarm(java.lang.String text)
Print alarm string

Parameters:
text - String to print

println

public static void println(java.lang.String text)
Print debug string.

Parameters:
text - String to print

traceit

public static void traceit(java.lang.String text)
Print trace string.

Parameters:
text - String to print

printStackTrace

public static void printStackTrace(java.lang.Throwable t)
Print debug string.

Parameters:
t - Throwable object to print stack trace from

setSystemProperty

protected static void setSystemProperty(java.lang.String name,
                                        java.lang.String value)
Set system property

Parameters:
name - name of the property
value - value of the property

removeSystemProperty

protected static void removeSystemProperty(java.lang.String name)
Remove system property

Parameters:
name - name of the property

getSystemProperty

protected static java.lang.String getSystemProperty(java.lang.String name)
Get system property.

Parameters:
name - name of the property

getTestResource

protected static java.net.URL getTestResource(java.lang.String name)
Obtain the URL for a test resource, e.g. a policy file or a SQL script.

Parameters:
name - Resource name, typically - org.apache.derbyTesing.something
Returns:
URL to the resource, null if it does not exist.

openTestResource

protected static java.io.InputStream openTestResource(java.net.URL url)
                                               throws java.security.PrivilegedActionException
Open the URL for a a test resource, e.g. a policy file or a SQL script.

Parameters:
url - URL obtained from getTestResource
Returns:
An open stream
Throws:
java.security.PrivilegedActionException

assertSecurityManager

public static void assertSecurityManager()
Assert a security manager is installed.


assertEquals

public static void assertEquals(java.io.InputStream is1,
                                java.io.InputStream is2)
                         throws java.io.IOException
Compare the contents of two streams. The streams are closed after they are exhausted.

Parameters:
is1 - the first stream
is2 - the second stream
Throws:
java.io.IOException - if reading from the streams fail
junit.framework.AssertionFailedError - if the stream contents are not equal

assertEquals

public static void assertEquals(java.io.Reader r1,
                                java.io.Reader r2)
                         throws java.io.IOException
Compare the contents of two readers. The readers are closed after they are exhausted.

Parameters:
r1 - the first reader
r2 - the second reader
Throws:
java.io.IOException - if reading from the streams fail
junit.framework.AssertionFailedError - if the reader contents are not equal

assertThrowableEquals

public static void assertThrowableEquals(java.lang.Throwable t1,
                                         java.lang.Throwable t2)
Assert that the detailed messages of the 2 passed-in Throwable's are equal (rather than '=='), as well as their class types.

Parameters:
t1 - first throwable to compare
t2 - second throwable to compare

assertEquals

public static void assertEquals(java.io.File file1,
                                java.io.File file2)
Assert that two files in the filesystem are identical.

Parameters:
file1 - the first file to compare
file2 - the second file to compare

assertExecJavaCmdAsExpected

public void assertExecJavaCmdAsExpected(java.lang.String[] expectedString,
                                        java.lang.String[] cmd,
                                        int expectedExitValue)
                                 throws java.lang.InterruptedException,
                                        java.io.IOException
Execute command using 'java' executable and verify that it completes with expected results

Parameters:
expectedString - String to compare the resulting output with. May be null if the output is not expected to be of interest.
cmd - array of java arguments for command
expectedExitValue - expected return value from the command
Throws:
java.lang.InterruptedException
java.io.IOException

execJavaCmd

public java.lang.Process execJavaCmd(java.lang.String[] cmd)
                              throws java.io.IOException
Execute a java command and return the process. The caller should decide what to do with the process, if anything, typical activities would be to do a pr.waitFor, or to get a getInputStream or getErrorStream Note, that for verifying the output of a Java process, there is assertExecJavaCmdAsExpected

Parameters:
cmd - array of java arguments for command
Returns:
the process that was started
Throws:
java.io.IOException

getJavaExecutableName

public static final java.lang.String getJavaExecutableName()
Return the executable name for spawning java commands. This will be /j9 for j9 jvms.

Returns:
full path to java executable.

readProcessOutput

public java.lang.String readProcessOutput(java.lang.Process pr)
                                   throws java.lang.InterruptedException
Reads output from a process and returns it as a string. This will block until the process terminates.

Parameters:
pr - a running process
Returns:
output of the process
Throws:
java.lang.InterruptedException

removeDirectory

public static void removeDirectory(java.lang.String path)
Remove the directory and its contents.

Parameters:
path - Path of the directory

removeDirectory

public static void removeDirectory(java.io.File dir)
Remove the directory and its contents.

Parameters:
dir - File of the directory

fail

public static void fail(java.lang.String msg,
                        java.lang.Exception e)
                 throws junit.framework.AssertionFailedError
Fail; attaching an exception for more detail on cause.

Parameters:
msg - message explaining the failure
e - exception related to the cause
Throws:
junit.framework.AssertionFailedError

Built on Wed 2009-11-25 18:43:31-0800, from revision 884373

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