Class OfficeFrameTestCase
- All Implemented Interfaces:
junit.framework.Test
- Direct Known Subclasses:
AbstractChangesTestCase,AbstractOfficeConstructTestCase,AbstractPolyglotObjectTest,AbstractPolyglotProcedureTest
TestCase providing additional helper functions.- Author:
- Daniel Sagenschneider
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static interfaceOperation forassertFail(net.officefloor.frame.test.OfficeFrameTestCase.FailOperation, java.lang.Class<F>)that should fail.protected static @interfaceMarks a GUI test.protected static interfaceMulti-threaded test logic interface.protected static @interfaceMarks a stress test.protected static interfaceOfficeFrameTestCase.TestCapture<T extends Throwable>Test capture interface.protected static interfaceOfficeFrameTestCase.TestLogic<R,T extends Throwable> Test logic interface.protected static @interfaceMarks a test that uses Docker.protected static @interfaceMarks a test that uses Google Cloud.static interfacePredicate to check for is true. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringClassname of the extra class for the newClassLoader.static final StringPackagename of the extra class for the newClassLoader.final ClassLoaderTestSupportprotected static StringEnd line.final FileTestSupportfinal LogTestSupportfinal MockTestSupportfinal ThreadedTestSupport -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor, so will usesetName(String).OfficeFrameTestCase(String name) Initiate allowing specifying name of test. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidassertContents(File expected, File actual) Asserts the contents of the inputFileinstances are the same.static voidassertContents(Reader expected, Reader actual) Asserts the contents of the inputReaderinstances are the same.static <F extends Throwable>
FassertFail(Class<F> expectedFailureType, Object object, Method method, Object... parameters) Provides simplified facade to verifyMethodwill fail.static <F extends Throwable>
FassertFail(Class<F> expectedFailureType, Object object, String methodName, Object... parameters) Provides simplified facade to verifyMethodwill fail.static <F extends Throwable>
FassertFail(OfficeFrameTestCase.FailOperation operation, Class<F> expectedFailureType) Asserts the failure.static <O> voidassertGraph(O expectedRoot, O actualRoot, String... ignoreMethodNames) Assets that the input graph is as expected.static <O> voidassertList(String[] methods, List<O> list, O... expectedItems) Asserts that properties on items within list match.static <O> voidassertList(String[] methods, O[] array, O... expectedItems) Asserts that properties on items within the array match.static <O> voidassertList(String sortMethod, String[] methods, List<O> list, O... expectedItems) Asserts that properties on items within list match after the list is sorted.static <O> voidassertList(List<O> list, O... expectedItems) Asserts that the input list equals the expected.static <O> voidassertList(ListItemMatcher<O> matcher, List<O> list, O... expectedItems) Asserts that the input list is as expected.static <O> voidassertProperties(O expected, O actual, String... methods) Asserts that properties on the input objects match for the specified methods.static voidassertTextEquals(String message, String expected, String actual) Asserts the input texts match taking into account platform differences.static voidassertXmlEquals(String message, String expected, String actual) Asserts the input XML's match with white spacing removed.Capturestd errof test logic.voidclearDirectory(File directory) Creates the input directory.voidcopyDirectory(File source, File target) Copies the contents of thesourcedirectory to thetargetdirectory.voidcreateFile(File target, InputStream content) Creates the target file with the content.final <M> McreateMock(Class<M> classToMock) Creates a mock object registering the mock object with registry for management.Creates a newClassLoaderfrom current process's java class path.static StringcreatePlatformIndependentText(String rawText) Creates the platform independent text for comparing.final <M> McreateSynchronizedMock(Class<M> interfaceToMock) Creates a thread safe mock object.voiddeleteDirectory(File directory) Deletes the input directory.voiddisplayGraph(Object root) Displays the graph of objects starting at root.voiddisplayGraph(Object root, String... ignoreMethodNames) Displays the graph of objects starting at root ignoring following verticies by the input method names.protected final <T extends Throwable>
voiddoMultiThreadedTest(int threadCount, int iterationCount, int timeout, OfficeFrameTestCase.MultithreadedTestLogic<T> test) Undertakes multi-threaded testing ofOfficeFrameTestCase.TestLogic.protected final <T extends Throwable>
voiddoMultiThreadedTest(int threadCount, int iterationCount, OfficeFrameTestCase.MultithreadedTestLogic<T> test) Undertakes multi-threaded testing ofOfficeFrameTestCase.TestLogic.protected final <R,T extends Throwable>
RdoTest(OfficeFrameTestCase.TestLogic<R, T> test) Undertakes test wrapping with mock object replay and verify.static RuntimeExceptionTriggers failure due to exception.Obtains the file by the input file name located in the package of the input class.Obtains the file at the relative path.findInputStream(Class<?> packageClass, String fileName) Obtains the input stream to the file by the input file name located in the package of the input class.getDisplayRunTime(long startTime) Obtains run time in human readable form.getDisplayRunTime(long startTime, long endTime) Obtains run time in human readable form.getFileContents(File file) Obtains the contents of the output file.getFileLocation(Class<?> packageClass, String fileName) Obtains the file location of the input file located in the package of the input class.static <T> TgetItem(Collection<T> items, String methodName, Object value) Obtains the item within the items whose property by methodName matches the input value.getPackageRelativePath(Class<?> packageClass) Obtains the relative path of the package of the class.static ObjectgetProperty(Object object, String methodName) Obtains the property on the Object.protected booleanIndicates if the GUI is available.protected booleanDetermines if printing messages.static booleanIndicates if not to run stress tests.static booleanIndicates if not to run tests using docker.static booleanIndicates if not to run tests using GCloud (Google Cloud).<T> Tparam(T value) Wraps a parameter value when attempting to capture.<T> TWraps a parameter type expected.voidPrints heap memory details.voidprintMessage(InputStream message) Prints a message regarding the test.voidprintMessage(Reader message) Prints a message regarding the test.voidprintMessage(String message) Prints a message regarding the test.final <T> voidrecordReturn(Object mockObject, T ignore, T recordedReturn) Convenience method to record a method and its return on a mock object.final <T> voidrecordReturn(Object mockObject, T ignore, T recordedReturn, ArgumentsMatcher matcher) Convenience method to record a method, anArgumentsMatcherand return value.final <T> voidrecordThrows(Object mockObject, T ignore, Throwable exception) Convenience method to record anException.final voidrecordVoid(Object mockObject, ArgumentsMatcher matcher) Convenience method to record void method.static StringRemoves the white spacing from the XML.protected final voidFlags all the mock objects to replay.voidrunBare()voidSpecifies to provide debug verbose output to aid in debugging.voidsetLogGC()Turns on logging of GC as part of test.voidvoidsetVerbose(boolean isVerbose) Specifies to provide verbose output to aid in debugging.voidsleep(int time) Facade helper function for invokingThread.sleep(long).static voidvoidtimeout(long startTime) Facade method to timeout operations after 3 seconds.voidtimeout(long startTime, int secondsToRun) Facade method to timeout operations after a second.protected final voidVerifies all mock objects.<T extends Throwable>
voidWaits for the check to betrue.<T extends 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 Details
-
END_OF_LINE
End line. -
CLASS_LOADER_EXTRA_PACKAGE_NAME
Packagename of the extra class for the newClassLoader.- See Also:
-
CLASS_LOADER_EXTRA_CLASS_NAME
Classname of the extra class for the newClassLoader.- See Also:
-
threadedTestSupport
-
fileTestSupport
-
classLoaderTestSupport
-
logTestSupport
-
mockTestSupport
-
-
Constructor Details
-
OfficeFrameTestCase
public OfficeFrameTestCase()Default constructor, so will usesetName(String). -
OfficeFrameTestCase
Initiate allowing specifying name of test.- Parameters:
name- Test name.
-
-
Method Details
-
runBare
- Overrides:
runBarein classjunit.framework.TestCase- Throws:
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
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.
-
throwException
-
assertFail
public static <F extends Throwable> F assertFail(OfficeFrameTestCase.FailOperation operation, 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 Throwable> F assertFail(Class<F> expectedFailureType, Object object, String methodName, Object... parameters) Provides simplified facade to verifyMethodwill fail. -
assertFail
public static <F extends Throwable> F assertFail(Class<F> expectedFailureType, Object object, Method method, Object... parameters) Provides simplified facade to verifyMethodwill fail. -
assertTextEquals
Asserts the input texts match taking into account platform differences.- Parameters:
message- Message.expected- Raw expected text.actual- Raw actual text.
-
createPlatformIndependentText
Creates the platform independent text for comparing.- Parameters:
rawText- Raw text.- Returns:
- Platform independent text.
-
assertXmlEquals
Asserts the input XML's match with white spacing removed.- Parameters:
message- Message.expected- Raw expected text.actual- Raw actual text.
-
removeXmlWhiteSpacing
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, String... ignoreMethodNames) throws 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:
Exception- If fails.
-
assertContents
Asserts the contents of the inputFileinstances are the same.- Parameters:
expected- Expected file.actual- Actual file.- Throws:
IOException- If fails to read contents.
-
assertContents
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, 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
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
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
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(String sortMethod, String[] methods, 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
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
Obtains the property on the Object.- Parameters:
object- Object.methodName- Method name to obtain property value.- Returns:
- Value of property.
-
getItem
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
- 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
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
Displays the graph of objects starting at root.- Parameters:
root- Root of graph to display.- Throws:
Exception- If fails.
-
displayGraph
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:
Exception- If fails.
-
createMock
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
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
Wraps a parameter type expected.- Type Parameters:
T- Value type.- Parameters:
type- Expected type.- Returns:
- Value for parameter.
-
recordReturn
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(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
Convenience method to record void method.- Parameters:
mockObject- Mock object.matcher-ArgumentsMatcher.
-
recordThrows
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
Undertakes test wrapping with mock object replay and verify. -
doMultiThreadedTest
protected final <T extends Throwable> void doMultiThreadedTest(int threadCount, int iterationCount, OfficeFrameTestCase.MultithreadedTestLogic<T> test) throws T Undertakes multi-threaded testing ofOfficeFrameTestCase.TestLogic.- Type Parameters:
T- Throwable type.- Parameters:
threadCount- Number ofThreadinstances to run in parallel.iterationCount- Number of iterations ofOfficeFrameTestCase.TestLogicperThread.test-OfficeFrameTestCase.TestLogic.- Throws:
T- Possible failure from failingOfficeFrameTestCase.TestLogic.
-
doMultiThreadedTest
protected final <T extends Throwable> void doMultiThreadedTest(int threadCount, int iterationCount, int timeout, OfficeFrameTestCase.MultithreadedTestLogic<T> test) throws T Undertakes multi-threaded testing ofOfficeFrameTestCase.TestLogic.- Type Parameters:
T- Throwable type.- 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.
-
captureLoggerOutput
protected final <T extends Throwable> String captureLoggerOutput(OfficeFrameTestCase.TestCapture<T> test) throws T Capturestd errof test logic. -
findFile
Obtains the file at the relative path.- Parameters:
relativePath- Relative path to the file.- Returns:
File.- Throws:
FileNotFoundException- If file could not be found.
-
findFile
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:
FileNotFoundException- Should the file not be found.
-
getFileLocation
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
Creates the input directory.- Parameters:
directory- Directory to be cleared.
-
deleteDirectory
Deletes the input directory.- Parameters:
directory- Directory to be deleted.
-
copyDirectory
Copies the contents of thesourcedirectory to thetargetdirectory.- Parameters:
source- Source directory.target- Target directory.- Throws:
IOException- If fails to copy the directory.
-
findInputStream
public InputStream findInputStream(Class<?> packageClass, String fileName) throws 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:
FileNotFoundException- Should the file not be found.
-
getPackageRelativePath
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
Obtains the contents of the output file.- Parameters:
file- File to obtain contents from.- Returns:
- Contents of the output file.
- Throws:
FileNotFoundException- Should output file not yet be created.IOException- Should fail to read from output file.
-
createFile
Creates the target file with the content.- Parameters:
content- Content for the file.target- Target file.- Throws:
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 Throwable> void waitForTrue(OfficeFrameTestCase.WaitForTruePredicate<T> check) throws T Waits for the check to betrue.- Type Parameters:
T- Possible failure type.- Parameters:
check- Check.- Throws:
T- Possible failure.
-
waitForTrue
public <T extends Throwable> void waitForTrue(OfficeFrameTestCase.WaitForTruePredicate<T> check, int secondsToRun) throws T 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.
-
isPrintMessages
protected boolean isPrintMessages()Determines if printing messages.- Returns:
trueto print messages.
-
printHeapMemoryDiagnostics
public void printHeapMemoryDiagnostics()Prints heap memory details. -
getDisplayRunTime
Obtains run time in human readable form.- Parameters:
startTime- Start time of running.- Returns:
- Run time in human readable form.
-
getDisplayRunTime
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
Prints a message regarding the test.- Parameters:
message- Message to be printed.
-
printMessage
Prints a message regarding the test.- Parameters:
message- Message to be printed.- Throws:
IOException- If fails to print message.
-
printMessage
Prints a message regarding the test.- Parameters:
message- Message to be printed.- Throws:
IOException- If fails to print message.
-