public abstract class BaseTestCase
extends junit.framework.TestCase
Modifier and Type | Field and Description |
---|---|
protected static java.lang.String |
DEFAULT_DB_DIR |
protected static java.lang.String |
DERBY_LOG |
protected static java.lang.String |
ERRORSTACKTRACEFILE |
Constructor and Description |
---|
BaseTestCase(java.lang.String name)
Create a test case with the given name.
|
Modifier and Type | Method and Description |
---|---|
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.
|
static 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 |
assertLaunchedJUnitTestMethod(java.lang.String testLaunchMethod)
assert a method from an executing test
|
static void |
assertLaunchedJUnitTestMethod(java.lang.String testLaunchMethod,
java.lang.String databaseName)
assert a method from an executing test
|
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.
|
static java.io.File |
currentDirectory()
Return the current directory.
|
static 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.Throwable t)
Fail; attaching an exception for more detail on cause.
|
static int |
getClassVersionMajor()
Returns the major version of the class specification version supported
by the running JVM.
|
java.io.File |
getFailureFolder()
Get the folder where a test leaves any information
about its failure.
|
protected static java.lang.String[] |
getFilesWith(java.io.File dir,
java.lang.String prefix)
Get files in a directory which contain certain prefix
|
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.
|
static boolean |
hasInterruptibleIO()
Check if we have old style (before Sun Java 1.7) Solaris interruptible
IO.
|
static boolean |
isCVM()
Check if this is a CVM-based VM (like phoneME or Oracle Java ME
Embedded Client).
|
static boolean |
isIBMJVM() |
static boolean |
isJ9Platform() |
static boolean |
isJava5()
Check if this is java 5
|
static boolean |
isJava7() |
static boolean |
isPhoneME()
Check if the VM is phoneME.
|
static boolean |
isPlatform(java.lang.String osName)
Determine if there is a platform match with os.name.
|
static boolean |
isSunJVM() |
static boolean |
isWindowsPlatform()
Determine if platform is a Windows variant.
|
protected static java.io.InputStream |
openTestResource(java.net.URL url)
Open the URL for a a test resource, e.g.
|
static void |
println(java.lang.String text)
Print debug string.
|
static void |
printStackTrace(java.lang.Throwable t)
Print debug string.
|
static 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.
|
static void |
removeFiles(java.lang.String[] list)
Remove all the files in the list
|
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.
|
static boolean |
runsWithEmma() |
protected static void |
setSystemProperty(java.lang.String name,
java.lang.String value)
Set system property
|
static void |
sleep(long ms)
Makes the current thread sleep up to
ms milliseconds. |
static void |
sleepAtLeastOneTick()
Returns once the system timer has advanced at least one tick.
|
static void |
traceit(java.lang.String text)
Print trace string.
|
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, countTestCases, createResult, fail, fail, failNotEquals, failNotSame, failSame, format, getName, run, run, runTest, setName, setUp, tearDown, toString
protected static final java.lang.String ERRORSTACKTRACEFILE
protected static final java.lang.String DEFAULT_DB_DIR
protected static final java.lang.String DERBY_LOG
public BaseTestCase(java.lang.String name)
name
- name of the test case.public void runBare() throws java.lang.Throwable
runBare
in class junit.framework.TestCase
java.lang.Throwable
public final TestConfiguration getTestConfiguration()
public final java.io.File getFailureFolder()
TestConfiguration.getFailureFolder(TestCase)
public static void alarm(java.lang.String text)
text
- String to printpublic static void println(java.lang.String text)
text
- String to printpublic static void traceit(java.lang.String text)
text
- String to printpublic static void printStackTrace(java.lang.Throwable t)
t
- Throwable object to print stack trace fromprotected static void setSystemProperty(java.lang.String name, java.lang.String value)
name
- name of the propertyvalue
- value of the propertypublic static void removeSystemProperty(java.lang.String name)
name
- name of the propertyprotected static java.lang.String getSystemProperty(java.lang.String name)
name
- name of the propertyprotected static java.lang.String[] getFilesWith(java.io.File dir, java.lang.String prefix)
dir
- The directory we are checking for files with certain prefixprefix
- The prefix pattern we are interested.protected static java.net.URL getTestResource(java.lang.String name)
name
- Resource name, typically - org.apache.derbyTesing.somethingprotected static java.io.InputStream openTestResource(java.net.URL url) throws java.security.PrivilegedActionException
url
- URL obtained from getTestResourcejava.security.PrivilegedActionException
public static void assertSecurityManager()
public static void assertEquals(java.io.InputStream is1, java.io.InputStream is2) throws java.io.IOException
is1
- the first streamis2
- the second streamjava.io.IOException
- if reading from the streams failjunit.framework.AssertionFailedError
- if the stream contents are not equalpublic static void assertEquals(java.io.Reader r1, java.io.Reader r2) throws java.io.IOException
r1
- the first readerr2
- the second readerjava.io.IOException
- if reading from the streams failjunit.framework.AssertionFailedError
- if the reader contents are not equalpublic static void assertThrowableEquals(java.lang.Throwable t1, java.lang.Throwable t2)
t1
- first throwable to comparet2
- second throwable to comparepublic static void assertEquals(java.io.File file1, java.io.File file2)
file1
- the first file to comparefile2
- the second file to comparepublic static void assertExecJavaCmdAsExpected(java.lang.String[] expectedString, java.lang.String[] cmd, int expectedExitValue) throws java.lang.InterruptedException, java.io.IOException
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 commandexpectedExitValue
- expected return value from the commandjava.lang.InterruptedException
java.io.IOException
public static java.lang.Process execJavaCmd(java.lang.String[] cmd) throws java.io.IOException
cmd
- array of java arguments for commandjava.io.IOException
public static final java.lang.String getJavaExecutableName()
public static java.io.File currentDirectory()
Return the current directory.
public static final boolean isJ9Platform()
public static final boolean isSunJVM()
public static boolean isCVM()
public static boolean isPhoneME()
public static final boolean isPlatform(java.lang.String osName)
osName
- value we want to check against the system property
os.namepublic static final boolean isWindowsPlatform()
Return true if platform is a windows platform. Just looks for os.name starting with "Windows". The os.name property can have at least the following values (there are probably more): AIX Digital Unix FreeBSD HP UX Irix Linux Mac OS Mac OS X MPE/iX Netware 4.11 OS/2 SunOS Windows 2000 Windows 95 Windows 98 Windows NT Windows Vista Windows XP
public static final boolean isJava5()
public static final boolean isJava7()
public static final boolean runsWithEmma()
public static int getClassVersionMajor()
public static final boolean hasInterruptibleIO()
-XX:-UseVMInterruptibleIO
. On Sun Java 1.7 it
is by default disabled.public static final boolean isIBMJVM()
public static java.lang.String readProcessOutput(java.lang.Process pr) throws java.lang.InterruptedException
This will block until the process terminates.
pr
- a running processjava.lang.InterruptedException
- if interrupted while waiting for the
subprocess or one of the output collector threads to terminatepublic static void removeDirectory(java.lang.String path)
path
- Path of the directorypublic static void removeDirectory(java.io.File dir)
dir
- File of the directorypublic static void removeFiles(java.lang.String[] list)
list
- the list contains all the filespublic static void fail(java.lang.String msg, java.lang.Throwable t) throws junit.framework.AssertionFailedError
msg
- message explaining the failuret
- the cause of the failurejunit.framework.AssertionFailedError
public static void assertLaunchedJUnitTestMethod(java.lang.String testLaunchMethod) throws java.lang.Exception
testLaunchMethod
- complete pathname of the method to be executedjava.lang.Exception
public static void assertLaunchedJUnitTestMethod(java.lang.String testLaunchMethod, java.lang.String databaseName) throws java.lang.Exception
testLaunchMethod
- complete pathname of the method to be executeddatabaseName
- name of the database to be usedjava.lang.Exception
public static void sleepAtLeastOneTick()
public static void sleep(long ms)
ms
milliseconds.