org.apache.jackrabbit.test.api.observation
Class AbstractObservationTest

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.apache.jackrabbit.test.JUnitTest
              extended by org.apache.jackrabbit.test.AbstractJCRTest
                  extended by org.apache.jackrabbit.test.api.observation.AbstractObservationTest
All Implemented Interfaces:
junit.framework.Test
Direct Known Subclasses:
AddEventListenerTest, EventIteratorTest, EventJournalTest, EventTest, GetDateTest, GetIdentifierTest, GetInfoTest, GetRegisteredEventListenersTest, GetUserDataTest, LockingTest, NodeAddedTest, NodeMovedTest, NodeRemovedTest, NodeReorderTest, PropertyAddedTest, PropertyChangedTest, PropertyRemovedTest, WorkspaceOperationTest

public abstract class AbstractObservationTest
extends AbstractJCRTest

This class implements the basic setUp() and tearDown() methods for the observation test cases.


Nested Class Summary
protected static interface AbstractObservationTest.Callable
          Helper interface.
 
Field Summary
protected static int ALL_TYPES
           
protected static long DEFAULT_WAIT_TIMEOUT
          Default wait timeout for events: 5000 ms
protected  ObservationManager obsMgr
          The ObservationManager
 
Fields inherited from class org.apache.jackrabbit.test.AbstractJCRTest
isReadOnly, jcrBaseVersion, jcrCopiedFrom, jcrCreated, jcrFrozenNode, jcrFrozenUuid, jcrIsCheckedOut, jcrlockIsDeep, jcrLockOwner, jcrMergeFailed, jcrMixinTypes, jcrPredecessors, jcrPrimaryType, jcrRootVersion, jcrSuccessors, jcrSystem, jcrUUID, jcrVersionHistory, mixLockable, mixReferenceable, mixShareable, mixSimpleVersionable, mixVersionable, nodeName1, nodeName2, nodeName3, nodeName4, NS_JCR_URI, NS_MIX_URI, NS_NT_URI, NS_SV_URI, ntBase, ntFrozenNode, ntQuery, ntUnstructured, ntVersion, ntVersionHistory, ntVersionLabels, propertyName1, propertyName2, superuser, testNodeType, testNodeTypeNoChildren, testPath, testRoot, testRootNode, vf, workspaceName
 
Fields inherited from class org.apache.jackrabbit.test.JUnitTest
log, logger
 
Constructor Summary
AbstractObservationTest()
           
 
Method Summary
protected  void addEventListener(EventListener listener)
          Registers an EventListener for all events.
protected  void addEventListener(EventListener listener, int eventType)
          Registers an EventListener for events of the specified type(s).
protected  void checkNodeAdded(Event[] events, String[] requiredRelPaths, String[] optionalRelPaths)
          Checks Events for paths.
protected  void checkNodeRemoved(Event[] events, String[] requiredRelPaths, String[] optionalRelPaths)
          Checks Events for paths.
protected  void checkNodes(Event[] events, String[] requiredRelPaths, String[] optionalRelPaths, long eventType)
          Checks Events for paths.
protected  void checkPropertyAdded(Event[] events, String[] relPaths)
          Checks Events for paths.
protected  void checkPropertyChanged(Event[] events, String[] relPaths)
          Checks Events for paths.
protected  void checkPropertyRemoved(Event[] events, String[] relPaths)
          Checks Events for paths.
protected  Event getEventByPath(Event[] events, String path)
          Returns the first event with the given path.
protected  Event[] getEvents(AbstractObservationTest.Callable call, int eventTypes)
          Registers an event listener for the passed eventTypes and calls the callable.
protected  void removeEventListener(EventListener listener)
          Removes the EventListener from the ObservationManager.
protected  void setUp()
           
protected  void tearDown()
           
protected  EventListener[] toArray(EventListenerIterator it)
          Consumes the EventListenerIterator and returns the EventListener as an array.
 
Methods inherited from class org.apache.jackrabbit.test.AbstractJCRTest
checkSupportedOption, cleanUp, cleanUpTestRoot, createRandomString, ensureCanSetProperty, ensureCanSetProperty, ensureCanSetProperty, ensureKnowsNodeType, ensureMixinType, ensureMultipleWorkspacesSupported, getHelper, getJcrValue, getLocalName, getNonExistingWorkspaceName, getProperty, getProperty, getSize, isSupported, needsMixin, run
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, runBare, runTest, setName, 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

DEFAULT_WAIT_TIMEOUT

protected static final long DEFAULT_WAIT_TIMEOUT
Default wait timeout for events: 5000 ms

See Also:
Constant Field Values

ALL_TYPES

protected static final int ALL_TYPES
See Also:
Constant Field Values

obsMgr

protected ObservationManager obsMgr
The ObservationManager

Constructor Detail

AbstractObservationTest

public AbstractObservationTest()
Method Detail

setUp

protected void setUp()
              throws Exception
Overrides:
setUp in class AbstractJCRTest
Throws:
Exception

tearDown

protected void tearDown()
                 throws Exception
Overrides:
tearDown in class AbstractJCRTest
Throws:
Exception

addEventListener

protected void addEventListener(EventListener listener)
                         throws RepositoryException
Registers an EventListener for all events.

Parameters:
listener - the EventListener.
Throws:
RepositoryException - if registration fails.

addEventListener

protected void addEventListener(EventListener listener,
                                int eventType)
                         throws RepositoryException
Registers an EventListener for events of the specified type(s).

Parameters:
listener - the EventListener.
eventType - the event types
Throws:
RepositoryException - if registration fails.

removeEventListener

protected void removeEventListener(EventListener listener)
                            throws RepositoryException
Removes the EventListener from the ObservationManager.

Parameters:
listener - the EventListener to unregister.
Throws:
RepositoryException - if unregister fails.

toArray

protected EventListener[] toArray(EventListenerIterator it)
Consumes the EventListenerIterator and returns the EventListener as an array.

Parameters:
it - the iterator.
Returns:
array of EventListeners.

checkNodeAdded

protected void checkNodeAdded(Event[] events,
                              String[] requiredRelPaths,
                              String[] optionalRelPaths)
                       throws RepositoryException
Checks Events for paths. All relPaths are relative to AbstractJCRTest.testRoot.

Parameters:
events - the Events.
requiredRelPaths - paths to child nodes added relative to AbstractJCRTest.testRoot (required events).
optionalRelPaths - paths to child nodes added relative to AbstractJCRTest.testRoot (optional events).
Throws:
RepositoryException - if an error occurs while retrieving the nodes from event instances.

checkNodeRemoved

protected void checkNodeRemoved(Event[] events,
                                String[] requiredRelPaths,
                                String[] optionalRelPaths)
                         throws RepositoryException
Checks Events for paths. All relPaths are relative to AbstractJCRTest.testRoot.

Parameters:
events - the Events.
requiredRelPaths - paths to child nodes added relative to AbstractJCRTest.testRoot (required events).
optionalRelPaths - paths to child nodes added relative to AbstractJCRTest.testRoot (optional events).
Throws:
RepositoryException - if an error occurs while retrieving the nodes from event instances.

checkPropertyAdded

protected void checkPropertyAdded(Event[] events,
                                  String[] relPaths)
                           throws RepositoryException
Checks Events for paths. All relPaths are relative to AbstractJCRTest.testRoot.

Parameters:
events - the Events.
relPaths - paths to added properties relative to AbstractJCRTest.testRoot.
Throws:
RepositoryException - if an error occurs while retrieving the nodes from event instances.

checkPropertyChanged

protected void checkPropertyChanged(Event[] events,
                                    String[] relPaths)
                             throws RepositoryException
Checks Events for paths. All relPaths are relative to AbstractJCRTest.testRoot.

Parameters:
events - the Events.
relPaths - paths to changed properties relative to AbstractJCRTest.testRoot.
Throws:
RepositoryException - if an error occurs while retrieving the nodes from event instances.

checkPropertyRemoved

protected void checkPropertyRemoved(Event[] events,
                                    String[] relPaths)
                             throws RepositoryException
Checks Events for paths. All relPaths are relative to AbstractJCRTest.testRoot.

Parameters:
events - the Events.
relPaths - paths to removed properties relative to AbstractJCRTest.testRoot.
Throws:
RepositoryException - if an error occurs while retrieving the nodes from event instances.

checkNodes

protected void checkNodes(Event[] events,
                          String[] requiredRelPaths,
                          String[] optionalRelPaths,
                          long eventType)
                   throws RepositoryException
Checks Events for paths. All relPaths are relative to AbstractJCRTest.testRoot.

Parameters:
events - the Events.
requiredRelPaths - paths to required item events relative to AbstractJCRTest.testRoot.
optionalRelPaths - paths to optional item events relative to AbstractJCRTest.testRoot.
eventType - the type of event to check.
Throws:
RepositoryException - if an error occurs while retrieving the nodes from event instances.

getEvents

protected Event[] getEvents(AbstractObservationTest.Callable call,
                            int eventTypes)
                     throws RepositoryException
Registers an event listener for the passed eventTypes and calls the callable.

Parameters:
call - the callable.
eventTypes - the types of the events to listen for.
Returns:
the events that were generated during execution of the callable.
Throws:
RepositoryException - if an error occurs.

getEventByPath

protected Event getEventByPath(Event[] events,
                               String path)
                        throws RepositoryException
Returns the first event with the given path.

Parameters:
events - the events.
path - the path.
Returns:
the event with the given path or Assert.fail()s if no such event exists.
Throws:
RepositoryException - if an error occurs while reading from the repository.


Copyright © 2004-2010 The Apache Software Foundation. All Rights Reserved.