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,AbstractHttpServerImplementationTest,AbstractOfficeConstructTestCase,AbstractPolyglotObjectTest,AbstractPolyglotProcedureTest
public abstract class OfficeFrameTestCase extends junit.framework.TestCaseTestCaseproviding additional helper functions.- Author:
- Daniel Sagenschneider
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static interfaceOfficeFrameTestCase.FailOperationOperation forassertFail(net.officefloor.frame.test.OfficeFrameTestCase.FailOperation, java.lang.Class<F>)that should fail.protected static interfaceOfficeFrameTestCase.GuiTestprotected static interfaceOfficeFrameTestCase.MultithreadedTestLogic<T extends java.lang.Throwable>Multi-threaded test logic interface.protected static interfaceOfficeFrameTestCase.StressTestprotected static interfaceOfficeFrameTestCase.TestCapture<T extends java.lang.Throwable>Test capture interface.protected static interfaceOfficeFrameTestCase.TestLogic<R,T extends java.lang.Throwable>Test logic interface.protected static interfaceOfficeFrameTestCase.UsesDockerTestprotected static interfaceOfficeFrameTestCase.UsesGCloudTeststatic interfaceOfficeFrameTestCase.WaitForTruePredicate<T extends java.lang.Throwable>Predicate to check for is true.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringCLASS_LOADER_EXTRA_CLASS_NAMEClassname of the extra class for the newClassLoader.static java.lang.StringCLASS_LOADER_EXTRA_PACKAGE_NAMEPackagename of the extra class for the newClassLoader.ClassLoaderTestSupportclassLoaderTestSupportprotected static java.lang.StringEND_OF_LINEEnd line.FileTestSupportfileTestSupportLogTestSupportlogTestSupportMockTestSupportmockTestSupportThreadedTestSupportthreadedTestSupport
-
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 voidassertContents(java.io.File expected, java.io.File actual)Asserts the contents of the inputFileinstances are the same.static voidassertContents(java.io.Reader expected, java.io.Reader actual)Asserts the contents of the inputReaderinstances 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 verifyMethodwill 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 verifyMethodwill fail.static <F extends java.lang.Throwable>
FassertFail(OfficeFrameTestCase.FailOperation operation, java.lang.Class<F> expectedFailureType)Asserts the failure.static <O> voidassertGraph(O expectedRoot, O actualRoot, java.lang.String... ignoreMethodNames)Assets that the input graph is as expected.static <O> voidassertList(java.lang.String[] methods, java.util.List<O> list, O... expectedItems)Asserts that properties on items within list match.static <O> voidassertList(java.lang.String[] methods, O[] array, O... expectedItems)Asserts that properties on items within the array match.static <O> voidassertList(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> voidassertList(java.util.List<O> list, O... expectedItems)Asserts that the input list equals the expected.static <O> voidassertList(ListItemMatcher<O> matcher, java.util.List<O> list, O... expectedItems)Asserts that the input list is as expected.static <O> voidassertProperties(O expected, O actual, java.lang.String... methods)Asserts that properties on the input objects match for the specified methods.static voidassertTextEquals(java.lang.String message, java.lang.String expected, java.lang.String actual)Asserts the input texts match taking into account platform differences.static voidassertXmlEquals(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 errof test logic.voidclearDirectory(java.io.File directory)Creates the input directory.voidcopyDirectory(java.io.File source, java.io.File target)Copies the contents of thesourcedirectory to thetargetdirectory.voidcreateFile(java.io.File target, java.io.InputStream content)Creates the target file with the content.<M> McreateMock(java.lang.Class<M> classToMock)Creates a mock object registering the mock object with registry for management.java.lang.ClassLoadercreateNewClassLoader()Creates a newClassLoaderfrom current process's java class path.static java.lang.StringcreatePlatformIndependentText(java.lang.String rawText)Creates the platform independent text for comparing.<M> McreateSynchronizedMock(java.lang.Class<M> interfaceToMock)Creates a thread safe mock object.voiddeleteDirectory(java.io.File directory)Deletes the input directory.voiddisplayGraph(java.lang.Object root)Displays the graph of objects starting at root.voiddisplayGraph(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.RuntimeExceptionfail(java.lang.Throwable ex)Triggers failure due to exception.java.io.FilefindFile(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.FilefindFile(java.lang.String relativePath)Obtains the file at the relative path.java.io.InputStreamfindInputStream(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.StringgetDisplayRunTime(long startTime)Obtains run time in human readable form.java.lang.StringgetDisplayRunTime(long startTime, long endTime)Obtains run time in human readable form.java.lang.StringgetFileContents(java.io.File file)Obtains the contents of the output file.java.lang.StringgetFileLocation(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> TgetItem(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.StringgetPackageRelativePath(java.lang.Class<?> packageClass)Obtains the relative path of the package of the class.static java.lang.ObjectgetProperty(java.lang.Object object, java.lang.String methodName)Obtains the property on the Object.protected booleanisGuiAvailable()Indicates if the GUI is available.protected booleanisPrintMessages()Determines if printing messages.static booleanisSkipStressTests()Indicates if not to run stress tests.static booleanisSkipTestsUsingDocker()Indicates if not to run tests using docker.static booleanisSkipTestsUsingGCloud()Indicates if not to run tests using GCloud (Google Cloud).<T> Tparam(T value)Wraps a parameter value when attempting to capture.<T> TparamType(java.lang.Class<T> type)Wraps a parameter type expected.voidprintHeapMemoryDiagnostics()Prints heap memory details.voidprintMessage(java.io.InputStream message)Prints a message regarding the test.voidprintMessage(java.io.Reader message)Prints a message regarding the test.voidprintMessage(java.lang.String message)Prints a message regarding the test.<T> voidrecordReturn(java.lang.Object mockObject, T ignore, T recordedReturn)Convenience method to record a method and its return on a mock object.<T> voidrecordReturn(java.lang.Object mockObject, T ignore, T recordedReturn, ArgumentsMatcher matcher)Convenience method to record a method, anArgumentsMatcherand return value.<T> voidrecordThrows(java.lang.Object mockObject, T ignore, java.lang.Throwable exception)Convenience method to record anException.voidrecordVoid(java.lang.Object mockObject, ArgumentsMatcher matcher)Convenience method to record void method.static java.lang.StringremoveXmlWhiteSpacing(java.lang.String xml)Removes the white spacing from the XML.protected voidreplayMockObjects()Flags all the mock objects to replay.voidrunBare()voidsetDebugVerbose()Specifies to provide debug verbose output to aid in debugging.voidsetLogGC()Turns on logging of GC as part of test.voidsetName(java.lang.String name)voidsetVerbose(boolean isVerbose)Specifies to provide verbose output to aid in debugging.voidsleep(int time)Facade helper function for invokingThread.sleep(long).static voidthrowException(java.lang.Throwable ex)Propagates theThrowableas either: downcastExceptiondowncastErrorThrowablewrapped with anExceptionvoidtimeout(long startTime)Facade method to timeout operations after 3 seconds.voidtimeout(long startTime, int secondsToRun)Facade method to timeout operations after a second.protected voidverifyMockObjects()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
Packagename 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
Classname 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:
runBarein 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:
trueto 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:
trueto 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:
trueto 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:
RuntimeExceptionto 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.ExceptionPropagates the
Throwableas either:- downcast
Exception - downcast
Error Throwablewrapped with anException
This is useful for such methods as
TestCase.tearDown()that do not allow throwingThrowable.- Parameters:
ex-Throwableto 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.FailOperationthat 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 verifyMethodwill fail.- Type Parameters:
F- Failure type.- Parameters:
expectedFailureType- Expected failure of method.object- Object to invokeMethodon.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 verifyMethodwill fail.- Type Parameters:
F- Failure type.- Parameters:
expectedFailureType- Expected failure of method.object- Object to invokeMethodon.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.ExceptionAssets 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.IOExceptionAsserts the contents of the inputFileinstances 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 inputReaderinstances 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:
setNamein classjunit.framework.TestCase
-
isGuiAvailable
protected boolean isGuiAvailable()
Indicates if the GUI is available.- Returns:
trueif the GUI is available.
-
setVerbose
public void setVerbose(boolean isVerbose)
Specifies to provide verbose output to aid in debugging.- Parameters:
isVerbose-trueto 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
ClassLoaderfrom current process's java class path.Classinstances loaded via thisClassLoaderwill be different to the currentClassLoader. This is to allow testing multipleClassLoaderenvironments (such as Eclipse plug-ins).- Returns:
- New
ClassLoader.
-
displayGraph
public void displayGraph(java.lang.Object root) throws java.lang.ExceptionDisplays 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.ExceptionDisplays 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-Classto 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-Classto 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, anArgumentsMatcherand 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.ThrowableUndertakes multi-threaded testing ofOfficeFrameTestCase.TestLogic.- Parameters:
threadCount- Number ofThreadinstances to run in parallel.iterationCount- Number of iterations ofOfficeFrameTestCase.TestLogicperThread.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.ThrowableUndertakes multi-threaded testing ofOfficeFrameTestCase.TestLogic.- Parameters:
threadCount- Number ofThreadinstances to run in parallel.iterationCount- Number of iterations ofOfficeFrameTestCase.TestLogicperThread.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 errof test logic.- Type Parameters:
T- PossibleExceptiontype.- Parameters:
test- Test logic to capturestd err.- Returns:
std erroutput.- Throws:
T- PossibleThrowable.T extends java.lang.Throwable
-
findFile
public java.io.File findFile(java.lang.String relativePath) throws java.io.FileNotFoundExceptionObtains 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.FileNotFoundExceptionObtains 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.IOExceptionCopies the contents of thesourcedirectory to thetargetdirectory.- 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.FileNotFoundExceptionObtains 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.IOExceptionObtains 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.IOExceptionCreates 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:
trueto 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.IOExceptionPrints 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.IOExceptionPrints a message regarding the test.- Parameters:
message- Message to be printed.- Throws:
java.io.IOException- If fails to print message.
-
-