|
|||||||||
| Home >> All >> org >> apache >> hivemind >> [ test overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.apache.hivemind.test
Class HiveMindTestCase

java.lang.Objectjunit.framework.Assert
junit.framework.TestCase
org.apache.hivemind.test.HiveMindTestCase
- All Implemented Interfaces:
- junit.framework.Test
- Direct Known Subclasses:
- TestAggregateArgumentsMatcher, TestArrayMatcher, TestMockClass, TestRegexpMatcher
- public abstract class HiveMindTestCase
- extends junit.framework.TestCase
Contains some support for creating HiveMind tests; this is useful enough that has been moved into the main framework, to simplify creation of tests in the dependent libraries.
| Nested Class Summary | |
private static class |
HiveMindTestCase.ClassMockControlFactory
|
private static class |
HiveMindTestCase.InterfaceMockControlFactory
|
(package private) static interface |
HiveMindTestCase.MockControlFactory
|
(package private) static class |
HiveMindTestCase.PlaceholderClassMockControlFactory
|
| Field Summary | |
protected StoreAppender |
_appender
|
private static HiveMindTestCase.MockControlFactory |
_classMockControlFactory
|
private org.apache.hivemind.ClassResolver |
_classResolver
An instance of org.apache.hivemind.impl.DefaultClassResolver that can be used by tests. |
private static org.apache.oro.text.regex.Perl5Compiler |
_compiler
|
private java.util.List |
_controls
List of org.easymock.MockControl. |
protected java.lang.String |
_interceptedLoggerName
|
private static HiveMindTestCase.MockControlFactory |
_interfaceMockControlFactory
|
private int |
_line
|
private static org.apache.oro.text.regex.Perl5Matcher |
_matcher
|
| Fields inherited from class junit.framework.TestCase |
|
| Constructor Summary | |
HiveMindTestCase()
|
|
| Method Summary | |
protected void |
addControl(MockControl control)
Adds the control to the list of managed controls used by replayControls() 55 and
verifyControls() 55 . |
protected void |
assertExceptionRegexp(java.lang.Throwable ex,
java.lang.String pattern)
Checks that the message for an exception matches a regular expression. |
protected void |
assertExceptionSubstring(java.lang.Throwable ex,
java.lang.String substring)
Checks that the provided substring exists in the exceptions message. |
protected static void |
assertListsEqual(java.lang.Object[] expected,
java.util.List actual)
Converts the actual list to an array and invokes assertListsEqual(Object[], Object[]) 55 . |
protected static void |
assertListsEqual(java.lang.Object[] expected,
java.lang.Object[] actual)
Asserts that the two arrays are equal; same length and all elements equal. |
protected void |
assertLoggedMessage(java.lang.String message)
Asserts that some capture log event matches the given message exactly. |
protected void |
assertLoggedMessage(java.lang.String message,
java.util.List events)
Asserts that some capture log event matches the given message exactly. |
private void |
assertLoggedMessage(java.lang.String message,
java.util.List events,
int index)
Checks to see if a specific event matches the name and message. |
protected void |
assertLoggedMessagePattern(java.lang.String pattern)
|
protected void |
assertLoggedMessagePattern(java.lang.String pattern,
java.util.List events)
|
protected void |
assertLoggedMessages(java.lang.String[] messages)
Checks the messages for all logged events for exact match against the supplied list. |
protected void |
assertRegexp(java.lang.String pattern,
java.lang.String actual)
|
protected org.apache.hivemind.Registry |
buildFrameworkRegistry(org.apache.hivemind.ModuleDescriptorProvider customProvider)
Builds a registry, containing only the modules delivered by the specified org.apache.hivemind.ModuleDescriptorProvider, plus the master module descriptor (i.e., those visible on the classpath). |
protected org.apache.hivemind.Registry |
buildFrameworkRegistry(java.lang.String file)
Convienience method for invoking buildFrameworkRegistry(String[]) 55 with only a single
file. |
protected org.apache.hivemind.Registry |
buildFrameworkRegistry(java.lang.String[] files)
Builds a minimal registry, containing only the specified files, plus the master module descriptor (i.e., those visible on the classpath). |
protected org.apache.hivemind.Registry |
buildMinimalRegistry(org.apache.hivemind.Resource l)
Builds a registry from exactly the provided resource; this registry will not include the hivemind module. |
protected org.apache.hivemind.Location |
fabricateLocation(int line)
Deprecated. To be removed in 1.2. Use newLocation() 55 instead. |
protected java.lang.Throwable |
findNestedException(org.apache.hivemind.ApplicationRuntimeException ex)
Digs down through (potentially) a stack of ApplicationRuntimeExceptions until it reaches the originating exception, which is returned. |
protected org.apache.hivemind.ClassResolver |
getClassResolver()
Returns a org.apache.hivemind.impl.DefaultClassResolver. |
protected MockControl |
getControl(java.lang.Object mock)
Accesses the control for a previously created mock object. |
protected java.util.List |
getInterceptedLogEvents()
Gets the list of events most recently intercepted. |
protected org.apache.hivemind.Resource |
getResource(java.lang.String file)
Returns the given file as a org.apache.hivemind.Resource from the classpath. |
protected void |
interceptLogging(java.lang.String loggerName)
Sets up an appender to intercept logging for the specified logger. |
protected boolean |
matches(java.lang.String input,
java.lang.String pattern)
|
protected MockControl |
newControl(java.lang.Class mockClass)
Creates a managed control via MockControl#createStrictControl(java.lang.Class). |
protected org.apache.hivemind.Location |
newLocation()
Returns a new org.apache.hivemind.Location instance. |
protected java.lang.Object |
newMock(java.lang.Class mockClass)
Convienience for invoking newControl(Class) 55 and then invoking
MockControl#getMock() on the result. |
protected void |
replayControls()
Invokes MockControl#replay() on all controls created by newControl(Class) 55 . |
protected void |
resetControls()
Invokes org.easymock.MockControl#reset() on all controls. |
protected void |
setReturnValue(java.lang.Object mock,
boolean returnValue)
Invoked when training a mock object to set the return value for the most recently invoked method. |
protected void |
setReturnValue(java.lang.Object mock,
double returnValue)
Invoked when training a mock object to set the return value for the most recently invoked method. |
protected void |
setReturnValue(java.lang.Object mock,
float returnValue)
Invoked when training a mock object to set the return value for the most recently invoked method. |
protected void |
setReturnValue(java.lang.Object mock,
long returnValue)
Invoked when training a mock object to set the return value for the most recently invoked method. |
protected void |
setReturnValue(java.lang.Object mock,
java.lang.Object returnValue)
Invoked when training a mock object to set the return value for the most recently invoked method. |
protected void |
setThrowable(java.lang.Object mock,
java.lang.Throwable t)
Invoked when training a mock object to set the Throwable for the most recently invoked method. |
private void |
setupMatcher()
|
protected void |
tearDown()
Removes the appender that may have been setup by interceptLogging(String) 55 . |
protected static void |
unreachable()
Called when code should not be reachable (because a test is expected to throw an exception); throws AssertionFailedError always. |
protected void |
verifyControls()
Invokes org.easymock.MockControl#verify() and MockControl#reset() on all
controls created by newControl(Class) 55 . |
| Methods inherited from class junit.framework.TestCase |
countTestCases, createResult, getName, run, run, runBare, runTest, setName, setUp, toString |
| Methods inherited from class junit.framework.Assert |
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, fail, fail |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
_classResolver
private org.apache.hivemind.ClassResolver _classResolver
- An instance of org.apache.hivemind.impl.DefaultClassResolver that can be used by tests.
_interceptedLoggerName
protected java.lang.String _interceptedLoggerName
_appender
protected StoreAppender _appender
_compiler
private static org.apache.oro.text.regex.Perl5Compiler _compiler
_matcher
private static org.apache.oro.text.regex.Perl5Matcher _matcher
_controls
private java.util.List _controls
- List of
org.easymock.MockControl.
_interfaceMockControlFactory
private static final HiveMindTestCase.MockControlFactory _interfaceMockControlFactory
- Since:
- 1.1
_classMockControlFactory
private static HiveMindTestCase.MockControlFactory _classMockControlFactory
- Since:
- 1.1
_line
private int _line
| Constructor Detail |
HiveMindTestCase
public HiveMindTestCase()
| Method Detail |
getResource
protected org.apache.hivemind.Resource getResource(java.lang.String file)
- Returns the given file as a org.apache.hivemind.Resource from the classpath. Typically, this is to find
files in the same folder as the invoking class.
assertListsEqual
protected static void assertListsEqual(java.lang.Object[] expected, java.util.List actual)
- Converts the actual list to an array and invokes
assertListsEqual(Object[], Object[])55 .
assertListsEqual
protected static void assertListsEqual(java.lang.Object[] expected, java.lang.Object[] actual)
- Asserts that the two arrays are equal; same length and all elements equal. Checks the
elements first, then the length.
unreachable
protected static void unreachable()
- Called when code should not be reachable (because a test is expected to throw an exception);
throws AssertionFailedError always.
interceptLogging
protected void interceptLogging(java.lang.String loggerName)
- Sets up an appender to intercept logging for the specified logger. Captured log events can be
recovered via
getInterceptedLogEvents()55 .
getInterceptedLogEvents
protected java.util.List getInterceptedLogEvents()
- Gets the list of events most recently intercepted. This resets the appender, clearing the
list of stored events.
tearDown
protected void tearDown()
throws java.lang.Exception
- Removes the appender that may have been setup by
interceptLogging(String)55 . Also, invokes PropertyUtils.clearCache()>PropertyUtils.clearCache()55 .
assertExceptionSubstring
protected void assertExceptionSubstring(java.lang.Throwable ex, java.lang.String substring)
- Checks that the provided substring exists in the exceptions message.
assertExceptionRegexp
protected void assertExceptionRegexp(java.lang.Throwable ex, java.lang.String pattern) throws java.lang.Exception
- Checks that the message for an exception matches a regular expression.
assertRegexp
protected void assertRegexp(java.lang.String pattern, java.lang.String actual) throws java.lang.Exception
findNestedException
protected java.lang.Throwable findNestedException(org.apache.hivemind.ApplicationRuntimeException ex)
- Digs down through (potentially) a stack of ApplicationRuntimeExceptions until it reaches the
originating exception, which is returned.
assertLoggedMessage
private void assertLoggedMessage(java.lang.String message, java.util.List events, int index)
- Checks to see if a specific event matches the name and message.
assertLoggedMessages
protected void assertLoggedMessages(java.lang.String[] messages)
- Checks the messages for all logged events for exact match against the supplied list.
assertLoggedMessage
protected void assertLoggedMessage(java.lang.String message)
- Asserts that some capture log event matches the given message exactly.
assertLoggedMessage
protected void assertLoggedMessage(java.lang.String message, java.util.List events)
- Asserts that some capture log event matches the given message exactly.
assertLoggedMessagePattern
protected void assertLoggedMessagePattern(java.lang.String pattern) throws java.lang.Exception
assertLoggedMessagePattern
protected void assertLoggedMessagePattern(java.lang.String pattern, java.util.List events) throws java.lang.Exception
setupMatcher
private void setupMatcher()
buildFrameworkRegistry
protected org.apache.hivemind.Registry buildFrameworkRegistry(java.lang.String file) throws java.lang.Exception
- Convienience method for invoking
buildFrameworkRegistry(String[])55 with only a single file.
buildFrameworkRegistry
protected org.apache.hivemind.Registry buildFrameworkRegistry(java.lang.String[] files) throws java.lang.Exception
- Builds a minimal registry, containing only the specified files, plus the master module
descriptor (i.e., those visible on the classpath). Files are resolved using
getResource(String)55 .
buildFrameworkRegistry
protected org.apache.hivemind.Registry buildFrameworkRegistry(org.apache.hivemind.ModuleDescriptorProvider customProvider)
- Builds a registry, containing only the modules delivered by the specified
org.apache.hivemind.ModuleDescriptorProvider, plus the master module descriptor
(i.e., those visible on the classpath).
buildMinimalRegistry
protected org.apache.hivemind.Registry buildMinimalRegistry(org.apache.hivemind.Resource l) throws java.lang.Exception
- Builds a registry from exactly the provided resource; this registry will not include the
hivemindmodule.
newControl
protected MockControl newControl(java.lang.Class mockClass)
- Creates a managed control via
MockControl#createStrictControl(java.lang.Class). The created control is remembered, and will be invoked byreplayControls()55 ,verifyControls()55 , etc.The class to mock may be either an interface or a class. The EasyMock class extension (easymockclassextension-1.1.jar) and CGLIB (cglib-full-2.01.jar) must be present in the latter case (new since 1.1).
This method is not deprecated, but is rarely used; typically
newMock(Class)55 is used to create the control and the mock, andsetReturnValue(Object, Object)55 andsetThrowable(Object, Throwable)55 are used to while training it.getControl(Object)55 is used for the rare cases where the MockControl itself is needed.
getControl
protected MockControl getControl(java.lang.Object mock)
- Accesses the control for a previously created mock object. Iterates over the list of managed
controls until one is found whose mock object identity equals the mock object provided.
- Since:
- 1.1
setThrowable
protected void setThrowable(java.lang.Object mock, java.lang.Throwable t)
- Invoked when training a mock object to set the Throwable for the most recently invoked
method.
- Since:
- 1.1
setReturnValue
protected void setReturnValue(java.lang.Object mock, java.lang.Object returnValue)
- Invoked when training a mock object to set the return value for the most recently invoked
method. Overrides of this method exist to support a number of primitive types.
- Since:
- 1.1
setReturnValue
protected void setReturnValue(java.lang.Object mock, long returnValue)
- Invoked when training a mock object to set the return value for the most recently invoked
method. Overrides of this method exist to support a number of primitive types.
- Since:
- 1.1
setReturnValue
protected void setReturnValue(java.lang.Object mock, float returnValue)
- Invoked when training a mock object to set the return value for the most recently invoked
method. Overrides of this method exist to support a number of primitive types.
- Since:
- 1.1
setReturnValue
protected void setReturnValue(java.lang.Object mock, double returnValue)
- Invoked when training a mock object to set the return value for the most recently invoked
method. Overrides of this method exist to support a number of primitive types.
- Since:
- 1.1
setReturnValue
protected void setReturnValue(java.lang.Object mock, boolean returnValue)
- Invoked when training a mock object to set the return value for the most recently invoked
method. Overrides of this method exist to support a number of primitive types.
- Since:
- 1.1
addControl
protected void addControl(MockControl control)
- Adds the control to the list of managed controls used by
replayControls()55 andverifyControls()55 .
newMock
protected java.lang.Object newMock(java.lang.Class mockClass)
- Convienience for invoking
newControl(Class)55 and then invokingMockControl#getMock()on the result.
replayControls
protected void replayControls()
- Invokes
MockControl#replay()on all controls created bynewControl(Class)55 .
verifyControls
protected void verifyControls()
- Invokes
org.easymock.MockControl#verify()andMockControl#reset()on all controls created bynewControl(Class)55 .
resetControls
protected void resetControls()
- Invokes
org.easymock.MockControl#reset()on all controls.
fabricateLocation
protected org.apache.hivemind.Location fabricateLocation(int line)
- Deprecated. To be removed in 1.2. Use
newLocation()55 instead.
newLocation
protected org.apache.hivemind.Location newLocation()
- Returns a new org.apache.hivemind.Location instance. The resource is the test class, and the line number
increments by one from one for each invocation (thus each call will get a unique instance not
equal to any previously obtained instance).
- Since:
- 1.1
getClassResolver
protected org.apache.hivemind.ClassResolver getClassResolver()
- Returns a org.apache.hivemind.impl.DefaultClassResolver. Repeated calls in the same test return the same
value.
- Since:
- 1.1
matches
protected boolean matches(java.lang.String input, java.lang.String pattern) throws java.lang.Exception
|
|||||||||
| Home >> All >> org >> apache >> hivemind >> [ test overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC