Class OfficeFrameTestCase
- java.lang.Object
-
- junit.framework.Assert
-
- junit.framework.TestCase
-
- net.officefloor.frame.test.OfficeFrameTestCase
-
- All Implemented Interfaces:
junit.framework.Test
- Direct Known Subclasses:
AbstractChangesTestCase
,AbstractOfficeConstructTestCase
,AbstractPolyglotObjectTest
,AbstractPolyglotProcedureTest
public abstract class OfficeFrameTestCase extends junit.framework.TestCase
TestCase
providing additional helper functions.- Author:
- Daniel Sagenschneider
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static interface
OfficeFrameTestCase.FailOperation
Operation forassertFail(net.officefloor.frame.test.OfficeFrameTestCase.FailOperation, java.lang.Class<F>)
that should fail.protected static interface
OfficeFrameTestCase.GuiTest
protected static interface
OfficeFrameTestCase.MultithreadedTestLogic<T extends java.lang.Throwable>
Multi-threaded test logic interface.protected static interface
OfficeFrameTestCase.StressTest
protected static interface
OfficeFrameTestCase.TestCapture<T extends java.lang.Throwable>
Test capture interface.protected static interface
OfficeFrameTestCase.TestLogic<R,T extends java.lang.Throwable>
Test logic interface.protected static interface
OfficeFrameTestCase.UsesDockerTest
protected static interface
OfficeFrameTestCase.UsesGCloudTest
static interface
OfficeFrameTestCase.WaitForTruePredicate<T extends java.lang.Throwable>
Predicate to check for is true.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
CLASS_LOADER_EXTRA_CLASS_NAME
Class
name of the extra class for the newClassLoader
.static java.lang.String
CLASS_LOADER_EXTRA_PACKAGE_NAME
Package
name of the extra class for the newClassLoader
.ClassLoaderTestSupport
classLoaderTestSupport
protected static java.lang.String
END_OF_LINE
End line.FileTestSupport
fileTestSupport
LogTestSupport
logTestSupport
MockTestSupport
mockTestSupport
ThreadedTestSupport
threadedTestSupport
-
Constructor Summary
Constructors Constructor Description OfficeFrameTestCase()
Default constructor, so will usesetName(String)
.OfficeFrameTestCase(java.lang.String name)
Initiate allowing specifying name of test.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
assertContents(java.io.File expected, java.io.File actual)
Asserts the contents of the inputFile
instances are the same.static void
assertContents(java.io.Reader expected, java.io.Reader actual)
Asserts the contents of the inputReader
instances are the same.static <F extends java.lang.Throwable>
FassertFail(java.lang.Class<F> expectedFailureType, java.lang.Object object, java.lang.reflect.Method method, java.lang.Object... parameters)
Provides simplified facade to verifyMethod
will fail.static <F extends java.lang.Throwable>
FassertFail(java.lang.Class<F> expectedFailureType, java.lang.Object object, java.lang.String methodName, java.lang.Object... parameters)
Provides simplified facade to verifyMethod
will fail.static <F extends java.lang.Throwable>
FassertFail(OfficeFrameTestCase.FailOperation operation, java.lang.Class<F> expectedFailureType)
Asserts the failure.static <O> void
assertGraph(O expectedRoot, O actualRoot, java.lang.String... ignoreMethodNames)
Assets that the input graph is as expected.static <O> void
assertList(java.lang.String[] methods, java.util.List<O> list, O... expectedItems)
Asserts that properties on items within list match.static <O> void
assertList(java.lang.String[] methods, O[] array, O... expectedItems)
Asserts that properties on items within the array match.static <O> void
assertList(java.lang.String sortMethod, java.lang.String[] methods, java.util.List<O> list, O... expectedItems)
Asserts that properties on items within list match after the list is sorted.static <O> void
assertList(java.util.List<O> list, O... expectedItems)
Asserts that the input list equals the expected.static <O> void
assertList(ListItemMatcher<O> matcher, java.util.List<O> list, O... expectedItems)
Asserts that the input list is as expected.static <O> void
assertProperties(O expected, O actual, java.lang.String... methods)
Asserts that properties on the input objects match for the specified methods.static void
assertTextEquals(java.lang.String message, java.lang.String expected, java.lang.String actual)
Asserts the input texts match taking into account platform differences.static void
assertXmlEquals(java.lang.String message, java.lang.String expected, java.lang.String actual)
Asserts the input XML's match with white spacing removed.protected <T extends java.lang.Throwable>
java.lang.StringcaptureLoggerOutput(OfficeFrameTestCase.TestCapture<T> test)
Capturestd err
of test logic.void
clearDirectory(java.io.File directory)
Creates the input directory.void
copyDirectory(java.io.File source, java.io.File target)
Copies the contents of thesource
directory to thetarget
directory.void
createFile(java.io.File target, java.io.InputStream content)
Creates the target file with the content.<M> M
createMock(java.lang.Class<M> classToMock)
Creates a mock object registering the mock object with registry for management.java.lang.ClassLoader
createNewClassLoader()
Creates a newClassLoader
from current process's java class path.static java.lang.String
createPlatformIndependentText(java.lang.String rawText)
Creates the platform independent text for comparing.<M> M
createSynchronizedMock(java.lang.Class<M> interfaceToMock)
Creates a thread safe mock object.void
deleteDirectory(java.io.File directory)
Deletes the input directory.void
displayGraph(java.lang.Object root)
Displays the graph of objects starting at root.void
displayGraph(java.lang.Object root, java.lang.String... ignoreMethodNames)
Displays the graph of objects starting at root ignoring following verticies by the input method names.protected <T extends java.lang.Throwable>
voiddoMultiThreadedTest(int threadCount, int iterationCount, int timeout, OfficeFrameTestCase.MultithreadedTestLogic<T> test)
Undertakes multi-threaded testing ofOfficeFrameTestCase.TestLogic
.protected <T extends java.lang.Throwable>
voiddoMultiThreadedTest(int threadCount, int iterationCount, OfficeFrameTestCase.MultithreadedTestLogic<T> test)
Undertakes multi-threaded testing ofOfficeFrameTestCase.TestLogic
.protected <R,T extends java.lang.Throwable>
RdoTest(OfficeFrameTestCase.TestLogic<R,T> test)
Undertakes test wrapping with mock object replay and verify.static java.lang.RuntimeException
fail(java.lang.Throwable ex)
Triggers failure due to exception.java.io.File
findFile(java.lang.Class<?> packageClass, java.lang.String fileName)
Obtains the file by the input file name located in the package of the input class.java.io.File
findFile(java.lang.String relativePath)
Obtains the file at the relative path.java.io.InputStream
findInputStream(java.lang.Class<?> packageClass, java.lang.String fileName)
Obtains the input stream to the file by the input file name located in the package of the input class.java.lang.String
getDisplayRunTime(long startTime)
Obtains run time in human readable form.java.lang.String
getDisplayRunTime(long startTime, long endTime)
Obtains run time in human readable form.java.lang.String
getFileContents(java.io.File file)
Obtains the contents of the output file.java.lang.String
getFileLocation(java.lang.Class<?> packageClass, java.lang.String fileName)
Obtains the file location of the input file located in the package of the input class.static <T> T
getItem(java.util.Collection<T> items, java.lang.String methodName, java.lang.Object value)
Obtains the item within the items whose property by methodName matches the input value.java.lang.String
getPackageRelativePath(java.lang.Class<?> packageClass)
Obtains the relative path of the package of the class.static java.lang.Object
getProperty(java.lang.Object object, java.lang.String methodName)
Obtains the property on the Object.protected boolean
isGuiAvailable()
Indicates if the GUI is available.protected boolean
isPrintMessages()
Determines if printing messages.static boolean
isSkipStressTests()
Indicates if not to run stress tests.static boolean
isSkipTestsUsingDocker()
Indicates if not to run tests using docker.static boolean
isSkipTestsUsingGCloud()
Indicates if not to run tests using GCloud (Google Cloud).<T> T
param(T value)
Wraps a parameter value when attempting to capture.<T> T
paramType(java.lang.Class<T> type)
Wraps a parameter type expected.void
printHeapMemoryDiagnostics()
Prints heap memory details.void
printMessage(java.io.InputStream message)
Prints a message regarding the test.void
printMessage(java.io.Reader message)
Prints a message regarding the test.void
printMessage(java.lang.String message)
Prints a message regarding the test.<T> void
recordReturn(java.lang.Object mockObject, T ignore, T recordedReturn)
Convenience method to record a method and its return on a mock object.<T> void
recordReturn(java.lang.Object mockObject, T ignore, T recordedReturn, ArgumentsMatcher matcher)
Convenience method to record a method, anArgumentsMatcher
and return value.<T> void
recordThrows(java.lang.Object mockObject, T ignore, java.lang.Throwable exception)
Convenience method to record anException
.void
recordVoid(java.lang.Object mockObject, ArgumentsMatcher matcher)
Convenience method to record void method.static java.lang.String
removeXmlWhiteSpacing(java.lang.String xml)
Removes the white spacing from the XML.protected void
replayMockObjects()
Flags all the mock objects to replay.void
runBare()
void
setDebugVerbose()
Specifies to provide debug verbose output to aid in debugging.void
setLogGC()
Turns on logging of GC as part of test.void
setName(java.lang.String name)
void
setVerbose(boolean isVerbose)
Specifies to provide verbose output to aid in debugging.void
sleep(int time)
Facade helper function for invokingThread.sleep(long)
.static void
throwException(java.lang.Throwable ex)
Propagates theThrowable
as either: downcastException
downcastError
Throwable
wrapped with anException
void
timeout(long startTime)
Facade method to timeout operations after 3 seconds.void
timeout(long startTime, int secondsToRun)
Facade method to timeout operations after a second.protected void
verifyMockObjects()
Verifies all mock objects.<T extends java.lang.Throwable>
voidwaitForTrue(OfficeFrameTestCase.WaitForTruePredicate<T> check)
Waits for the check to betrue
.<T extends java.lang.Throwable>
voidwaitForTrue(OfficeFrameTestCase.WaitForTruePredicate<T> check, int secondsToRun)
Waits for the check to betrue
.-
Methods inherited from class junit.framework.TestCase
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, setUp, tearDown, toString
-
-
-
-
Field Detail
-
END_OF_LINE
protected static java.lang.String END_OF_LINE
End line.
-
CLASS_LOADER_EXTRA_PACKAGE_NAME
public static final java.lang.String CLASS_LOADER_EXTRA_PACKAGE_NAME
Package
name of the extra class for the newClassLoader
.- See Also:
- Constant Field Values
-
CLASS_LOADER_EXTRA_CLASS_NAME
public static final java.lang.String CLASS_LOADER_EXTRA_CLASS_NAME
Class
name of the extra class for the newClassLoader
.- See Also:
- Constant Field Values
-
threadedTestSupport
public final ThreadedTestSupport threadedTestSupport
-
fileTestSupport
public final FileTestSupport fileTestSupport
-
classLoaderTestSupport
public final ClassLoaderTestSupport classLoaderTestSupport
-
logTestSupport
public final LogTestSupport logTestSupport
-
mockTestSupport
public final MockTestSupport mockTestSupport
-
-
Constructor Detail
-
OfficeFrameTestCase
public OfficeFrameTestCase()
Default constructor, so will usesetName(String)
.
-
OfficeFrameTestCase
public OfficeFrameTestCase(java.lang.String name)
Initiate allowing specifying name of test.- Parameters:
name
- Test name.
-
-
Method Detail
-
runBare
public void runBare() throws java.lang.Throwable
- Overrides:
runBare
in classjunit.framework.TestCase
- Throws:
java.lang.Throwable
-
isSkipStressTests
public static boolean isSkipStressTests()
Indicates if not to run stress tests.
Stress tests should normally be run, but in cases of quick unit testing running for functionality the stress tests can reduce turn around time and subsequently the effectiveness of the tests. This is therefore provided to maintain effectiveness of unit tests.
Furthermore, builds time out on Travis so avoid running.
- Returns:
true
to ignore doing a stress test.
-
isSkipTestsUsingDocker
public static boolean isSkipTestsUsingDocker()
Indicates if not to run tests using docker.
Some environments do not support docker, so this enables disabling these tests.
- Returns:
true
to ignore doing a docker test.
-
isSkipTestsUsingGCloud
public static boolean isSkipTestsUsingGCloud()
Indicates if not to run tests using GCloud (Google Cloud).
Some environments do not have GCloud available, so this enables disabling these tests.
- Returns:
true
to ignore doing a GCloud test.
-
fail
public static java.lang.RuntimeException fail(java.lang.Throwable ex)
Triggers failure due to exception.
This is useful to not have to provide throws clauses on tests.
- Parameters:
ex
- Failure.- Returns:
RuntimeException
to allowthrow fail(ex);
for compilation. Note this is never returned as always throws exception.- Throws:
TestFail
- Handled byrunBare()
.
-
throwException
public static void throwException(java.lang.Throwable ex) throws java.lang.Exception
Propagates the
Throwable
as either:- downcast
Exception
- downcast
Error
Throwable
wrapped with anException
This is useful for such methods as
TestCase.tearDown()
that do not allow throwingThrowable
.- Parameters:
ex
-Throwable
to propagate as anException
.- Throws:
java.lang.Exception
- The failure.
- downcast
-
assertFail
public static <F extends java.lang.Throwable> F assertFail(OfficeFrameTestCase.FailOperation operation, java.lang.Class<F> expectedFailureType)
Asserts the failure.- Type Parameters:
F
- Failure type.- Parameters:
operation
-OfficeFrameTestCase.FailOperation
that is expected fail.expectedFailureType
- Expect type of failure.- Returns:
- Actual failure for further assertions.
-
assertFail
public static <F extends java.lang.Throwable> F assertFail(java.lang.Class<F> expectedFailureType, java.lang.Object object, java.lang.String methodName, java.lang.Object... parameters)
Provides simplified facade to verifyMethod
will fail.- Type Parameters:
F
- Failure type.- Parameters:
expectedFailureType
- Expected failure of method.object
- Object to invokeMethod
on.methodName
- Name of theMethod
.parameters
- Parameters for theMethod
.- Returns:
- Actual failure for further assertions.
-
assertFail
public static <F extends java.lang.Throwable> F assertFail(java.lang.Class<F> expectedFailureType, java.lang.Object object, java.lang.reflect.Method method, java.lang.Object... parameters)
Provides simplified facade to verifyMethod
will fail.- Type Parameters:
F
- Failure type.- Parameters:
expectedFailureType
- Expected failure of method.object
- Object to invokeMethod
on.method
-Method
.parameters
- Parameters for theMethod
.- Returns:
- Actual failure for further assertions.
-
assertTextEquals
public static void assertTextEquals(java.lang.String message, java.lang.String expected, java.lang.String actual)
Asserts the input texts match taking into account platform differences.- Parameters:
message
- Message.expected
- Raw expected text.actual
- Raw actual text.
-
createPlatformIndependentText
public static java.lang.String createPlatformIndependentText(java.lang.String rawText)
Creates the platform independent text for comparing.- Parameters:
rawText
- Raw text.- Returns:
- Platform independent text.
-
assertXmlEquals
public static void assertXmlEquals(java.lang.String message, java.lang.String expected, java.lang.String actual)
Asserts the input XML's match with white spacing removed.- Parameters:
message
- Message.expected
- Raw expected text.actual
- Raw actual text.
-
removeXmlWhiteSpacing
public static java.lang.String removeXmlWhiteSpacing(java.lang.String xml)
Removes the white spacing from the XML.- Parameters:
xml
- XML.- Returns:
- XML with white spacing removed.
-
assertGraph
public static <O> void assertGraph(O expectedRoot, O actualRoot, java.lang.String... ignoreMethodNames) throws java.lang.Exception
Assets that the input graph is as expected.- Type Parameters:
O
- Type.- Parameters:
expectedRoot
- Expected root.actualRoot
- Actual root.ignoreMethodNames
- Listing of methods to be ignored in checking.- Throws:
java.lang.Exception
- If fails.
-
assertContents
public static void assertContents(java.io.File expected, java.io.File actual) throws java.io.IOException
Asserts the contents of the inputFile
instances are the same.- Parameters:
expected
- Expected file.actual
- Actual file.- Throws:
java.io.IOException
- If fails to read contents.
-
assertContents
public static void assertContents(java.io.Reader expected, java.io.Reader actual)
Asserts the contents of the inputReader
instances are the same.- Parameters:
expected
- Expected content.actual
- Actual content.
-
assertList
@SafeVarargs public static <O> void assertList(ListItemMatcher<O> matcher, java.util.List<O> list, O... expectedItems)
Asserts that the input list is as expected.- Type Parameters:
O
- Type.- Parameters:
matcher
- Matches the items of the list.list
- List to be checked.expectedItems
- Items expected to be in the list.
-
assertList
@SafeVarargs public static <O> void assertList(java.util.List<O> list, O... expectedItems)
Asserts that the input list equals the expected.- Type Parameters:
O
- Type.- Parameters:
list
- List to be checked.expectedItems
- Items expected in the list.
-
assertList
@SafeVarargs public static <O> void assertList(java.lang.String[] methods, java.util.List<O> list, O... expectedItems)
Asserts that properties on items within list match.- Type Parameters:
O
- Type.- Parameters:
methods
- Method names to specify the properties on the items to match.list
- List to be checked.expectedItems
- Items expected in the list.
-
assertList
@SafeVarargs public static <O> void assertList(java.lang.String[] methods, O[] array, O... expectedItems)
Asserts that properties on items within the array match.- Type Parameters:
O
- Type.- Parameters:
methods
- Method names to specify the properties on the items to match.array
- Array to be checked.expectedItems
- Items expected in the array.
-
assertList
@SafeVarargs public static <O> void assertList(java.lang.String sortMethod, java.lang.String[] methods, java.util.List<O> list, O... expectedItems)
Asserts that properties on items within list match after the list is sorted.- Type Parameters:
O
- Type.- Parameters:
sortMethod
- Name of method on the items to sort the list by to ensure match in order.methods
- Method names to specify the properties on the items to match.list
- List to be checked.expectedItems
- Items expected in the list.
-
assertProperties
public static <O> void assertProperties(O expected, O actual, java.lang.String... methods)
Asserts that properties on the input objects match for the specified methods.- Type Parameters:
O
- Type.- Parameters:
expected
- Expected item.actual
- Actual item.methods
- Method names to specify the properties on the item to match.
-
getProperty
public static java.lang.Object getProperty(java.lang.Object object, java.lang.String methodName)
Obtains the property on the Object.- Parameters:
object
- Object.methodName
- Method name to obtain property value.- Returns:
- Value of property.
-
getItem
public static <T> T getItem(java.util.Collection<T> items, java.lang.String methodName, java.lang.Object value)
Obtains the item within the items whose property by methodName matches the input value.- Type Parameters:
T
- Item type.- Parameters:
items
- Items to search.methodName
- Property on the item.value
- Value of property the item should match.- Returns:
- Item with the matching property.
-
setName
public void setName(java.lang.String name)
- Overrides:
setName
in classjunit.framework.TestCase
-
isGuiAvailable
protected boolean isGuiAvailable()
Indicates if the GUI is available.- Returns:
true
if the GUI is available.
-
setVerbose
public void setVerbose(boolean isVerbose)
Specifies to provide verbose output to aid in debugging.- Parameters:
isVerbose
-true
to turn on verbose output.
-
setDebugVerbose
public void setDebugVerbose()
Specifies to provide debug verbose output to aid in debugging.
-
setLogGC
public void setLogGC()
Turns on logging of GC as part of test.
-
createNewClassLoader
public java.lang.ClassLoader createNewClassLoader()
Creates a new
ClassLoader
from current process's java class path.Class
instances loaded via thisClassLoader
will be different to the currentClassLoader
. This is to allow testing multipleClassLoader
environments (such as Eclipse plug-ins).- Returns:
- New
ClassLoader
.
-
displayGraph
public void displayGraph(java.lang.Object root) throws java.lang.Exception
Displays the graph of objects starting at root.- Parameters:
root
- Root of graph to display.- Throws:
java.lang.Exception
- If fails.
-
displayGraph
public void displayGraph(java.lang.Object root, java.lang.String... ignoreMethodNames) throws java.lang.Exception
Displays the graph of objects starting at root ignoring following verticies by the input method names.- Parameters:
root
- Root of graph to display.ignoreMethodNames
- Method names to ignore.- Throws:
java.lang.Exception
- If fails.
-
createMock
public final <M> M createMock(java.lang.Class<M> classToMock)
Creates a mock object registering the mock object with registry for management.- Type Parameters:
M
- Interface type.- Parameters:
classToMock
-Class
to be mocked.- Returns:
- Mock object.
-
createSynchronizedMock
public final <M> M createSynchronizedMock(java.lang.Class<M> interfaceToMock)
Creates a thread safe mock object.- Type Parameters:
M
- Interface type.- Parameters:
interfaceToMock
-Class
to mock.- Returns:
- Mock object.
-
param
public <T> T param(T value)
Wraps a parameter value when attempting to capture.- Type Parameters:
T
- Value type.- Parameters:
value
- Value.- Returns:
- Value for parameter.
-
paramType
public <T> T paramType(java.lang.Class<T> type)
Wraps a parameter type expected.- Type Parameters:
T
- Value type.- Parameters:
type
- Expected type.- Returns:
- Value for parameter.
-
recordReturn
public final <T> void recordReturn(java.lang.Object mockObject, T ignore, T recordedReturn)
Convenience method to record a method and its return on a mock object.- Type Parameters:
T
- Expected result type.- Parameters:
mockObject
- Mock object.ignore
- Result of operation on the mock object. This is only provided to obtain correct return type for recording return.recordedReturn
- Value that is recorded to be returned from the mock object.
-
recordReturn
public final <T> void recordReturn(java.lang.Object mockObject, T ignore, T recordedReturn, ArgumentsMatcher matcher)
Convenience method to record a method, anArgumentsMatcher
and return value.- Type Parameters:
T
- Expected result type.- Parameters:
mockObject
- Mock object.ignore
- Result of operation on the mock object. This is only provided to obtain correct return type for recording return.recordedReturn
- Value that is recorded to be returned from the mock object.matcher
-ArgumentsMatcher
.
-
recordVoid
public final void recordVoid(java.lang.Object mockObject, ArgumentsMatcher matcher)
Convenience method to record void method.- Parameters:
mockObject
- Mock object.matcher
-ArgumentsMatcher
.
-
recordThrows
public final <T> void recordThrows(java.lang.Object mockObject, T ignore, java.lang.Throwable exception)
Convenience method to record anException
.- Type Parameters:
T
- Expected result type.- Parameters:
mockObject
- Mock object.ignore
- Result of operation on the mock object. This is only provided to obtain correct return type for recording return.exception
-Throwable
.
-
replayMockObjects
protected final void replayMockObjects()
Flags all the mock objects to replay.
-
verifyMockObjects
protected final void verifyMockObjects()
Verifies all mock objects.
-
doTest
protected final <R,T extends java.lang.Throwable> R doTest(OfficeFrameTestCase.TestLogic<R,T> test) throws T extends java.lang.Throwable
Undertakes test wrapping with mock object replay and verify.- Type Parameters:
R
- Return type of test logic.T
- PossibleThrowable
.- Parameters:
test
- Test logic to wrap in replay/verify.- Returns:
- Result of test logic.
- Throws:
T
- If logic throwsException
.T extends java.lang.Throwable
-
doMultiThreadedTest
protected final <T extends java.lang.Throwable> void doMultiThreadedTest(int threadCount, int iterationCount, OfficeFrameTestCase.MultithreadedTestLogic<T> test) throws T extends java.lang.Throwable
Undertakes multi-threaded testing ofOfficeFrameTestCase.TestLogic
.- Parameters:
threadCount
- Number ofThread
instances to run in parallel.iterationCount
- Number of iterations ofOfficeFrameTestCase.TestLogic
perThread
.test
-OfficeFrameTestCase.TestLogic
.- Throws:
T
- Possible failure from failingOfficeFrameTestCase.TestLogic
.T extends java.lang.Throwable
-
doMultiThreadedTest
protected final <T extends java.lang.Throwable> void doMultiThreadedTest(int threadCount, int iterationCount, int timeout, OfficeFrameTestCase.MultithreadedTestLogic<T> test) throws T extends java.lang.Throwable
Undertakes multi-threaded testing ofOfficeFrameTestCase.TestLogic
.- Parameters:
threadCount
- Number ofThread
instances to run in parallel.iterationCount
- Number of iterations ofOfficeFrameTestCase.TestLogic
perThread
.timeout
- Timeout.test
-OfficeFrameTestCase.TestLogic
.- Throws:
T
- Possible failure from failingOfficeFrameTestCase.TestLogic
.T extends java.lang.Throwable
-
captureLoggerOutput
protected final <T extends java.lang.Throwable> java.lang.String captureLoggerOutput(OfficeFrameTestCase.TestCapture<T> test) throws T extends java.lang.Throwable
Capturestd err
of test logic.- Type Parameters:
T
- PossibleException
type.- Parameters:
test
- Test logic to capturestd err
.- Returns:
std err
output.- Throws:
T
- PossibleThrowable
.T extends java.lang.Throwable
-
findFile
public java.io.File findFile(java.lang.String relativePath) throws java.io.FileNotFoundException
Obtains the file at the relative path.- Parameters:
relativePath
- Relative path to the file.- Returns:
File
.- Throws:
java.io.FileNotFoundException
- If file could not be found.
-
findFile
public java.io.File findFile(java.lang.Class<?> packageClass, java.lang.String fileName) throws java.io.FileNotFoundException
Obtains the file by the input file name located in the package of the input class.- Parameters:
packageClass
- Class to obtain the relative path from for its package.fileName
- Name of file within the package directory.- Returns:
- File within the package directory.
- Throws:
java.io.FileNotFoundException
- Should the file not be found.
-
getFileLocation
public java.lang.String getFileLocation(java.lang.Class<?> packageClass, java.lang.String fileName)
Obtains the file location of the input file located in the package of the input class.- Parameters:
packageClass
- Class to obtain the relative path from for its package.fileName
- Name of the file within the package directory.- Returns:
- Path to the file.
-
clearDirectory
public void clearDirectory(java.io.File directory)
Creates the input directory.- Parameters:
directory
- Directory to be cleared.
-
deleteDirectory
public void deleteDirectory(java.io.File directory)
Deletes the input directory.- Parameters:
directory
- Directory to be deleted.
-
copyDirectory
public void copyDirectory(java.io.File source, java.io.File target) throws java.io.IOException
Copies the contents of thesource
directory to thetarget
directory.- Parameters:
source
- Source directory.target
- Target directory.- Throws:
java.io.IOException
- If fails to copy the directory.
-
findInputStream
public java.io.InputStream findInputStream(java.lang.Class<?> packageClass, java.lang.String fileName) throws java.io.FileNotFoundException
Obtains the input stream to the file by the input file name located in the package of the input class.
Note: this also searches the class path for the file.
- Parameters:
packageClass
- Class to obtain the relative path from for its package.fileName
- Name of file within the package directory.- Returns:
- File within the package directory.
- Throws:
java.io.FileNotFoundException
- Should the file not be found.
-
getPackageRelativePath
public java.lang.String getPackageRelativePath(java.lang.Class<?> packageClass)
Obtains the relative path of the package of the class.- Parameters:
packageClass
- Class to obtain the relative path from for its package.- Returns:
- Relative path of class's package.
-
getFileContents
public java.lang.String getFileContents(java.io.File file) throws java.io.FileNotFoundException, java.io.IOException
Obtains the contents of the output file.- Parameters:
file
- File to obtain contents from.- Returns:
- Contents of the output file.
- Throws:
java.io.FileNotFoundException
- Should output file not yet be created.java.io.IOException
- Should fail to read from output file.
-
createFile
public void createFile(java.io.File target, java.io.InputStream content) throws java.io.IOException
Creates the target file with the content.- Parameters:
content
- Content for the file.target
- Target file.- Throws:
java.io.IOException
- If fails to create.
-
sleep
public void sleep(int time)
Facade helper function for invokingThread.sleep(long)
.- Parameters:
time
- Sleep time in seconds.
-
timeout
public void timeout(long startTime)
Facade method to timeout operations after 3 seconds.- Parameters:
startTime
- Start time fromSystem.currentTimeMillis()
.
-
timeout
public void timeout(long startTime, int secondsToRun)
Facade method to timeout operations after a second.- Parameters:
startTime
- Start time fromSystem.currentTimeMillis()
.secondsToRun
- Seconds to run before timeout.
-
waitForTrue
public <T extends java.lang.Throwable> void waitForTrue(OfficeFrameTestCase.WaitForTruePredicate<T> check) throws T extends java.lang.Throwable
Waits for the check to betrue
.- Type Parameters:
T
- Possible failure type.- Parameters:
check
- Check.- Throws:
T
- Possible failure.T extends java.lang.Throwable
-
waitForTrue
public <T extends java.lang.Throwable> void waitForTrue(OfficeFrameTestCase.WaitForTruePredicate<T> check, int secondsToRun) throws T extends java.lang.Throwable
Waits for the check to betrue
.- Type Parameters:
T
- Possible failure type.- Parameters:
check
- Check.secondsToRun
- Seconds to wait before timing out.- Throws:
T
- Possible failure.T extends java.lang.Throwable
-
isPrintMessages
protected boolean isPrintMessages()
Determines if printing messages.- Returns:
true
to print messages.
-
printHeapMemoryDiagnostics
public void printHeapMemoryDiagnostics()
Prints heap memory details.
-
getDisplayRunTime
public java.lang.String getDisplayRunTime(long startTime)
Obtains run time in human readable form.- Parameters:
startTime
- Start time of running.- Returns:
- Run time in human readable form.
-
getDisplayRunTime
public java.lang.String getDisplayRunTime(long startTime, long endTime)
Obtains run time in human readable form.- Parameters:
startTime
- Start time of running.endTime
- End time of running.- Returns:
- Run time in human readable form.
-
printMessage
public void printMessage(java.lang.String message)
Prints a message regarding the test.- Parameters:
message
- Message to be printed.
-
printMessage
public void printMessage(java.io.InputStream message) throws java.io.IOException
Prints a message regarding the test.- Parameters:
message
- Message to be printed.- Throws:
java.io.IOException
- If fails to print message.
-
printMessage
public void printMessage(java.io.Reader message) throws java.io.IOException
Prints a message regarding the test.- Parameters:
message
- Message to be printed.- Throws:
java.io.IOException
- If fails to print message.
-
-