org.mockcentral.server
Class Fixture

java.lang.Object
  extended by org.mockcentral.server.Fixture

public class Fixture
extends java.lang.Object

A class used to build and group Mock Objects and Proxy instances accessible to the MockCentralServer. This class serves several purposes: it allows for organization of Mock Object definitions into logical collections, for verifying expectations on all such definitions in one step, and for specifying a distinct group of objects to be bound into the MockCentralTestingContext under their supplied JNDI names with one call to the server. A collection of simple (non-Mock) objects which are additionally to be bound into the context are also associated with individual instances of this class, and are loaded along with the Proxy instances. All JNDI names should be unique within each Fixture.

Instances may declare that they import other instances, inheriting all of their Mock Object and simple (non-Mock) JNDI-bound object definitions, which will be added at runtime. Note that an exception will be thrown if there are circular references within the imports list. Also note that if there are duplicated JNDI names among JNDI-bound objects inherited from different Fixture instances, the "last-built" object will be the one finally bound under the name. Since the build order of inherited Fixture instances is determined dynamically by the server, the result will not necessarily be from the last or latest Fixture in your imports list. The logger will post a warning when a binding is overridden.

This class accepts MockObjectSetup and SimpleBoundObjectBean instances built within the MockDataLoader for use in constructing the maps of Mocks and simple objects and performs validation to assure that the Mock Object definitions do not contain circular references. The "add" and "set" methods defined in this class are invoked by the org.apache.commons.digester.Digester when the configuration file is parsed, and should not be called by clients.

Author:
David Hutchinson
See Also:
MockCentralServer, MockCentralTestingContext, MockObjectSetup, SimpleBoundObjectBean, MockDataLoader

Constructor Summary
Fixture()
          Creates a new instance.
 
Method Summary
 void addImport(java.lang.String importedFixtureName)
          Adds the supplied Fixture name to the list of names of Fixture instances imported by this instance.
 void addMockObjectSetup(MockObjectSetup mockObjectSetup)
          Adds the supplied MockObjectSetup to the list from which the Mocks and Proxy objects will be created.
 void addSimpleBoundObject(SimpleBoundObjectBean bean)
          Creates and adds a simple (non-Mock) object to map of JNDI-bound objects.
protected static java.lang.String getCurrentFixtureName()
          Returns the name of the Fixture currently being created.
 java.lang.String getFixtureDescription()
          Returns the description of this instance.
 java.lang.String getFixtureName()
          Returns the name of this instance.
 java.util.ArrayList<java.lang.String> getImportedFixtureNames()
          Returns the list of names of Fixture instances imported by this instance.
 java.util.HashMap<java.lang.String,java.lang.Object> getJNDIBoundObjectsMap()
          Returns the map of Proxy objects and simple(non-Mock) objects used in this Fixture that will be bound under a JNDI name in the MockCentralTestingContext.
 java.util.HashMap<java.lang.String,com.mockobjects.dynamic.Mock> getMockObjectsMap()
          Returns the map of the Mock Objects used in this instance.
 java.util.HashMap<java.lang.String,java.lang.Object> getProxiesMap()
          Returns the map of Proxy objects for the Mock objects used in this instance.
 java.lang.Object getProxy(SignaturePartBean bean)
          Returns the Proxy stored under the name matching the value field of the supplied SignaturepartBean.
 void loadImports()
          Processes the list of imported Fixture instances to add the Mock Objects, Proxy objects and simple (non-Mock) JNDI-bound objects of each imported Fixture to the maps in this instance.
 void processMockObjectSetups()
          Processes the list of MockObjectSetup instances to create the Mocks and Proxy objects, adding them to the appropriate maps defined in this class.
 void setFixtureDescription(java.lang.String fixtureDescription)
          Sets the description of this instance.
 void setFixtureName(java.lang.String fixtureName)
          Sets the name of this instance.
 java.lang.String toString()
           
 void verifyMockObject(java.lang.String mockObjectName)
          Calls the Mock.verify method on the indicated Mock to verify that its expected methods were called.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Fixture

public Fixture()
Creates a new instance.

Method Detail

setFixtureName

public void setFixtureName(java.lang.String fixtureName)
Sets the name of this instance.

Parameters:
fixtureName - the name of this instance.

getFixtureName

public java.lang.String getFixtureName()
Returns the name of this instance.

Returns:
the name of this instance.

setFixtureDescription

public void setFixtureDescription(java.lang.String fixtureDescription)
Sets the description of this instance. The description is optional, it exists to add additional information to the logger output.

Parameters:
fixtureDescription - the description to set.

getFixtureDescription

public java.lang.String getFixtureDescription()
Returns the description of this instance. The description is optional, it exists to add additional information to the logger output.

Returns:
the description of this instance.

addImport

public void addImport(java.lang.String importedFixtureName)
Adds the supplied Fixture name to the list of names of Fixture instances imported by this instance.

Parameters:
importedFixtureName - the name of the Fixture to add to the list.

getImportedFixtureNames

public java.util.ArrayList<java.lang.String> getImportedFixtureNames()
Returns the list of names of Fixture instances imported by this instance.

Returns:
the list of names of Fixture instances imported by this instance.

loadImports

public void loadImports()
Processes the list of imported Fixture instances to add the Mock Objects, Proxy objects and simple (non-Mock) JNDI-bound objects of each imported Fixture to the maps in this instance.


addSimpleBoundObject

public void addSimpleBoundObject(SimpleBoundObjectBean bean)
                          throws MockCentralServerException
Creates and adds a simple (non-Mock) object to map of JNDI-bound objects. The supplied SimpleBoundObjectBean is used to assign the JNDI name and build the object itself.

Parameters:
bean - the SimpleBoundObjectBean to add.
Throws:
MockCentralServerException - if the object could not be constructed.
See Also:
SimpleBoundObjectBean

getMockObjectsMap

public java.util.HashMap<java.lang.String,com.mockobjects.dynamic.Mock> getMockObjectsMap()
Returns the map of the Mock Objects used in this instance. The keys are the mockObjectName field values defined in each MockObjectSetup added to this Fixture.

Returns:
a map of the Mock Objects used in this Fixture.
See Also:
MockObjectSetup

getProxiesMap

public java.util.HashMap<java.lang.String,java.lang.Object> getProxiesMap()
Returns the map of Proxy objects for the Mock objects used in this instance. The keys are the mockObjectName field values defined in each MockObjectSetup added to this Fixture.

Returns:
a map of Proxy objects for the Mock objects used in this instance.
See Also:
MockObjectSetup

getProxy

public java.lang.Object getProxy(SignaturePartBean bean)
Returns the Proxy stored under the name matching the value field of the supplied SignaturepartBean.

Parameters:
bean - the SignaturepartBean.
Returns:
the Proxy stored under the name matching the value field of the supplied SignaturepartBean.

getJNDIBoundObjectsMap

public java.util.HashMap<java.lang.String,java.lang.Object> getJNDIBoundObjectsMap()
Returns the map of Proxy objects and simple(non-Mock) objects used in this Fixture that will be bound under a JNDI name in the MockCentralTestingContext. The keys are the jndiName field values defined in each MockObjectSetup or SimpleBoundObject added to this Fixture.

Returns:
a map of Proxy objects for the Mock objects used in this instance that will be bound under a JNDI name in the MockCentralTestingContext .
See Also:
MockObjectSetup, SimpleBoundObjectBean, MockCentralTestingContext

addMockObjectSetup

public void addMockObjectSetup(MockObjectSetup mockObjectSetup)
Adds the supplied MockObjectSetup to the list from which the Mocks and Proxy objects will be created.

Parameters:
mockObjectSetup - the MockObjectSetup to add.
See Also:
MockObjectSetup

processMockObjectSetups

public void processMockObjectSetups()
                             throws MockCentralServerException
Processes the list of MockObjectSetup instances to create the Mocks and Proxy objects, adding them to the appropriate maps defined in this class. The processIncompleteSetups method is invoked after the list has been iterated through to process any instances that could not be processed the first time through because they contained references to other Mock Objects not yet created.

Throws:
MockCentralServerException - if a MockObjectSetup could not be processed.
See Also:
MockObjectSetup

verifyMockObject

public void verifyMockObject(java.lang.String mockObjectName)
Calls the Mock.verify method on the indicated Mock to verify that its expected methods were called.

Parameters:
mockObjectName - the name of the Mock Object to verify.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getCurrentFixtureName

protected static java.lang.String getCurrentFixtureName()
Returns the name of the Fixture currently being created.

Returns:
the name of the Fixture currently being created.