org.apache.hivemind.test
Class HiveMindTestCase

java.lang.Object
  |
  +--junit.framework.Assert
        |
        +--junit.framework.TestCase
              |
              +--org.apache.hivemind.test.HiveMindTestCase
All Implemented Interfaces:
junit.framework.Test

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.

Author:
Howard Lewis Ship

Field Summary
protected  org.apache.hivemind.test.StoreAppender _appender
           
protected  java.lang.String _interceptedLoggerName
           
 
Constructor Summary
HiveMindTestCase()
           
 
Method Summary
protected  void addControl(org.easymock.MockControl control)
          Adds the control to the list of managed controls used by replayControls() and verifyControls().
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[]).
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.
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  Registry buildFrameworkRegistry(java.lang.String file)
          Convienience method for invoking buildFrameworkRegistry(String[]) with only a single file.
protected  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  Registry buildMinimalRegistry(Resource l)
          Builds a registry from exactly the provided resource; this registry will not include the hivemind module.
protected  Location fabricateLocation(int line)
           
protected  java.lang.Throwable findNestedException(ApplicationRuntimeException ex)
          Digs down through (potentially) a stack of ApplicationRuntimeExceptions until it reaches the originating exception, which is returned.
protected  java.util.List getInterceptedLogEvents()
          Gets the list of events most recently intercepted.
protected  Resource getResource(java.lang.String file)
          Returns the given file as a Resource from the classpath.
protected  void interceptLogging(java.lang.String loggerName)
          Sets up a StoreAppender to intercept logging for the specified logger.
protected  boolean matches(java.lang.String input, java.lang.String pattern)
           
protected  org.easymock.MockControl newControl(java.lang.Class mockClass)
          Creates a managed control via MockControl.createStrictControl(java.lang.Class).
protected  java.lang.Object newMock(java.lang.Class mockClass)
          Convienience for invoking newControl(Class) and then invoking MockControl.getMock() on the result.
protected  void replayControls()
          Invokes MockControl.replay() on all controls created by newControl(Class).
protected  void resetControls()
          Invokes MockControl.reset() on all controls.
protected  void tearDown()
          Removes the StoreAppender that may have been setup by interceptLogging(String).
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 MockControl.verify() and MockControl.reset() on all controls created by newControl(Class).
 
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

_interceptedLoggerName

protected java.lang.String _interceptedLoggerName

_appender

protected org.apache.hivemind.test.StoreAppender _appender
Constructor Detail

HiveMindTestCase

public HiveMindTestCase()
Method Detail

getResource

protected Resource getResource(java.lang.String file)
Returns the given file as a 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[]).


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 a StoreAppender to intercept logging for the specified logger. Captured log events can be recovered via getInterceptedLogEvents().


getInterceptedLogEvents

protected java.util.List getInterceptedLogEvents()
Gets the list of events most recently intercepted. This resets the StoreAppender (it clears its list of log events).

See Also:
interceptLogging(String), StoreAppender#getEvents()

tearDown

protected void tearDown()
                 throws java.lang.Exception
Removes the StoreAppender that may have been setup by interceptLogging(String).

Overrides:
tearDown in class junit.framework.TestCase
java.lang.Exception

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.

java.lang.Exception

assertRegexp

protected void assertRegexp(java.lang.String pattern,
                            java.lang.String actual)
                     throws java.lang.Exception
java.lang.Exception

findNestedException

protected java.lang.Throwable findNestedException(ApplicationRuntimeException ex)
Digs down through (potentially) a stack of ApplicationRuntimeExceptions until it reaches the originating exception, which is returned.


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.

Parameters:
message - to search for; success is finding a logged message contain the parameter as a substring
events - from getInterceptedLogEvents()

assertLoggedMessagePattern

protected void assertLoggedMessagePattern(java.lang.String pattern)
                                   throws java.lang.Exception
java.lang.Exception

assertLoggedMessagePattern

protected void assertLoggedMessagePattern(java.lang.String pattern,
                                          java.util.List events)
                                   throws java.lang.Exception
java.lang.Exception

buildFrameworkRegistry

protected Registry buildFrameworkRegistry(java.lang.String file)
                                   throws java.lang.Exception
Convienience method for invoking buildFrameworkRegistry(String[]) with only a single file.

java.lang.Exception

buildFrameworkRegistry

protected 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).

java.lang.Exception

buildMinimalRegistry

protected Registry buildMinimalRegistry(Resource l)
                                 throws java.lang.Exception
Builds a registry from exactly the provided resource; this registry will not include the hivemind module.

java.lang.Exception

newControl

protected org.easymock.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 by replayControls(), verifyControls(), etc..


addControl

protected void addControl(org.easymock.MockControl control)
Adds the control to the list of managed controls used by replayControls() and verifyControls().


newMock

protected java.lang.Object newMock(java.lang.Class mockClass)
Convienience for invoking newControl(Class) and then invoking MockControl.getMock() on the result.


replayControls

protected void replayControls()
Invokes MockControl.replay() on all controls created by newControl(Class).


verifyControls

protected void verifyControls()
Invokes MockControl.verify() and MockControl.reset() on all controls created by newControl(Class).


resetControls

protected void resetControls()
Invokes MockControl.reset() on all controls.


fabricateLocation

protected Location fabricateLocation(int line)

matches

protected boolean matches(java.lang.String input,
                          java.lang.String pattern)
                   throws java.lang.Exception
java.lang.Exception