org.apache.hivemind.test
Class HiveMindTestCase

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by 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(ModuleDefinition customModule)
           
protected  Registry buildFrameworkRegistry(ModuleDefinition[] customModules)
          Builds a registry, containing only the modules delivered the parameter customModules, 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)
          Deprecated. To be removed in 1.2. Use newLocation() instead.
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  ClassResolver getClassResolver()
          Returns a DefaultClassResolver.
protected  org.easymock.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  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 an appender 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  Location newLocation()
          Returns a new Location instance.
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 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.
protected  void tearDown()
          Removes the appender 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 an appender 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 appender, clearing the list of stored events.

See Also:
interceptLogging(String)

tearDown

protected void tearDown()
                 throws java.lang.Exception
Removes the appender that may have been setup by interceptLogging(String). Also, invokes PropertyUtils.clearCache().

Overrides:
tearDown in class junit.framework.TestCase
Throws:
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.

Throws:
java.lang.Exception

assertRegexp

protected void assertRegexp(java.lang.String pattern,
                            java.lang.String actual)
                     throws java.lang.Exception
Throws:
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
Throws:
java.lang.Exception

assertLoggedMessagePattern

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

buildFrameworkRegistry

protected Registry buildFrameworkRegistry(ModuleDefinition customModule)

buildFrameworkRegistry

protected Registry buildFrameworkRegistry(ModuleDefinition[] customModules)
Builds a registry, containing only the modules delivered the parameter customModules, plus the master module descriptor (i.e., those visible on the classpath).


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.

Throws:
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.

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) is used to create the control and the mock, and setReturnValue(Object, Object) and setThrowable(Object, Throwable) are used to while training it. getControl(Object) is used for the rare cases where the MockControl itself is needed.


getControl

protected org.easymock.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.

Parameters:
mock - object whose control is needed
Returns:
the corresponding MockControl if found
Throws:
java.lang.IllegalArgumentException - if not found
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.

Parameters:
mock - the mock object being trained
t - the exception the object should throw when it replays
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.

Parameters:
mock - the mock object being trained
returnValue - the value to return from the most recently invoked methods
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.

Parameters:
mock - the mock object being trained
returnValue - the value to return from the most recently invoked methods
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.

Parameters:
mock - the mock object being trained
returnValue - the value to return from the most recently invoked methods
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.

Parameters:
mock - the mock object being trained
returnValue - the value to return from the most recently invoked methods
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.

Parameters:
mock - the mock object being trained
returnValue - the value to return from the most recently invoked methods
Since:
1.1

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)
Deprecated. To be removed in 1.2. Use newLocation() instead.


newLocation

protected Location newLocation()
Returns a new 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 ClassResolver getClassResolver()
Returns a 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
Throws:
java.lang.Exception


Copyright © 2003-2007 Apache Software Foundation. All Rights Reserved.