public abstract class BaseTestCase
extends junit.framework.TestCase
Modifier and Type | Field and Description |
---|---|
private static int |
debugPort |
protected static java.lang.String |
DEFAULT_DB_DIR |
protected static java.lang.String |
DERBY_LOG |
protected static java.lang.String |
ERRORSTACKTRACEFILE |
private static java.lang.String |
JACOCO_AGENT_PROP |
private static java.io.PrintStream |
out |
private static int |
spawnedCount
Counter used to produce unique file names based on process count.
|
Modifier | Constructor and Description |
---|---|
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.
|
Modifier and Type | Method and Description |
---|---|
static void |
alarm(java.lang.String text)
Print alarm string
|
static void |
assertDirectoryDeleted(java.io.File dir)
Deletes the specified directory and all its files and subdirectories.
|
static void |
assertEquals(byte[] expected,
byte[] actual)
Assert the equivalence of two byte arrays.
|
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(int[] expected,
int[] actual)
Assert the equivalence of two int arrays.
|
static void |
assertEquals(long[] expected,
long[] actual)
Assert the equivalence of two long arrays.
|
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 boolean |
assertSameNullness(java.lang.Object expected,
java.lang.Object actual)
Assert that two objects are either both null or neither null.
|
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 java.lang.Process |
execJavaCmd(java.lang.String jvm,
java.lang.String cp,
java.lang.String[] cmd,
java.io.File dir)
Same as
execJavaCmd( String, String, String[], File, boolean )
but with addClassPath == true . |
static java.lang.Process |
execJavaCmd(java.lang.String jvm,
java.lang.String cp,
java.lang.String[] cmd,
java.io.File dir,
boolean addClassPath)
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.
|
static java.net.URL |
getEmmaJar()
Get a URL pointing to
emma.jar , if the tests are running
with EMMA code coverage. |
private static java.io.File |
getEmmaOutFile()
Get a unique file object that can be used by sub-processes to store
EMMA code coverage data.
|
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
|
private static java.io.File |
getJaCoCoOutFile()
Get a unique file object that can be used by sub-processes to store
JaCoCo code coverage data.
|
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.
|
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.
|
static junit.framework.AssertionFailedError |
newAssertionFailedError(java.lang.String message,
java.lang.Throwable cause)
Create a new AssertionFailedError linked to another Throwable.
|
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.
|
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() |
static boolean |
runsWithJaCoCo() |
protected static void |
setSystemErr(java.io.PrintStream err)
Change the value of
System.err . |
protected static void |
setSystemOut(java.io.PrintStream out)
Change the value of
System.out . |
protected static void |
setSystemProperty(java.lang.String name,
java.lang.String value)
Set system property
|
private static void |
setupForDebuggerAttach(java.util.ArrayList<java.lang.String> cmdlist) |
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.
|
private static java.lang.String |
traceClientType() |
static void |
traceit(java.lang.String text)
Print trace string.
|
static boolean |
vmAtLeast(int major,
int minor)
Return true if the JVM is at least at the indicated rev level
|
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
private static final java.lang.String JACOCO_AGENT_PROP
protected static final java.lang.String ERRORSTACKTRACEFILE
protected static final java.lang.String DEFAULT_DB_DIR
protected static final java.lang.String DERBY_LOG
private static int debugPort
private static final java.io.PrintStream out
private static int spawnedCount
getEmmaOutFile()
,
getJaCoCoOutFile()
private BaseTestCase()
BaseTestCase(String)
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 setSystemOut(java.io.PrintStream out)
System.out
.out
- the new streamprotected static void setSystemErr(java.io.PrintStream err)
System.err
.err
- the new streamprotected 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(byte[] expected, byte[] actual)
Assert the equivalence of two byte arrays.
public static boolean assertSameNullness(java.lang.Object expected, java.lang.Object actual)
public static void assertEquals(int[] expected, int[] actual)
Assert the equivalence of two int arrays.
public static void assertEquals(long[] expected, long[] actual)
Assert the equivalence of two long arrays.
public 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 jvm, java.lang.String cp, java.lang.String[] cmd, java.io.File dir) throws java.io.IOException
execJavaCmd( String, String, String[], File, boolean )
but with addClassPath == true
.java.io.IOException
public static java.lang.Process execJavaCmd(java.lang.String jvm, java.lang.String cp, java.lang.String[] cmd, java.io.File dir, boolean addClassPath) throws java.io.IOException
jvm
- the path to the java executable, or null
to use
the default executable returned by
getJavaExecutableName()
cp
- the classpath for the spawned process, or null
to
inherit the classpath from the parent processcmd
- array of java arguments for commanddir
- working directory for the sub-process, or null
to
run in the same directory as the main test processaddClassPath
- if true
,add classpathjava.io.IOException
public static java.lang.Process execJavaCmd(java.lang.String[] cmd) throws java.io.IOException
execJavaCmd(null, null, cmd, null)
.java.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 boolean runsWithJaCoCo()
private static java.io.File getJaCoCoOutFile()
private static java.io.File getEmmaOutFile()
public static java.net.URL getEmmaJar()
emma.jar
, if the tests are running
with EMMA code coverage. The method returns null
if the
tests are not running with EMMA.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 assertDirectoryDeleted(java.io.File dir)
This method will attempt to delete all the files inside the root directory, even if one of the delete operations fails.
After having tried to delete all files once, any remaining files will be attempted deleted again after a pause. This is repeated, resulting in multiple failed delete attempts for any single file before the method gives up and raises a failure.
The approach above will mask any slowness involved in releasing file handles, but should fail if a file handle actually isn't released on a system that doesn't allow deletes on files with open handles (i.e. Windows). It will also mask slowness caused by the JVM, the file system, or the operation system.
dir
- the root to start deleting from (root will also be deleted)public 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 junit.framework.AssertionFailedError newAssertionFailedError(java.lang.String message, java.lang.Throwable cause)
message
- message explaining the failurecause
- the cause of the failurepublic 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 boolean vmAtLeast(int major, int minor)
public static void sleep(long ms)
ms
milliseconds.private static java.lang.String traceClientType()
private static void setupForDebuggerAttach(java.util.ArrayList<java.lang.String> cmdlist)
Apache Derby V10.13 Internals - Copyright © 2004,2016 The Apache Software Foundation. All Rights Reserved.