com.mockrunner.mock.ejb
Class EJBMockObjectFactory

java.lang.Object
  extended by com.mockrunner.mock.ejb.EJBMockObjectFactory

public class EJBMockObjectFactory
extends java.lang.Object

Used to create all types of EJB mock objects. Maintains the necessary dependencies between the mock objects. If you use the mock objects returned by this factory in your tests you can be sure that they are all up to date. This factory takes the UserTransaction from the JNDI context. If there's no transaction bound to the context, the factory will create a MockUserTransaction and bind it to the context. If the bound transaction is no MockUserTransaction, the method getMockUserTransaction() returns null. Use getUserTransaction() instead in this case. You can configure the JNDI name of the UserTransaction and the JNDI Context with the class Configuration.


Constructor Summary
EJBMockObjectFactory()
          Creates a new set of mock objects.
EJBMockObjectFactory(Configuration configuration)
          Creates a new set of mock objects based on the specified configuration.
 
Method Summary
 MockUserTransaction createMockUserTransaction()
          Creates the MockUserTransaction using new.
 javax.naming.Context getContext()
          Returns the JNDI context that is used by this factory.
 org.mockejb.MockContainer getMockContainer()
          Returns the MockEJB MockContainer.
 MockUserTransaction getMockUserTransaction()
          Returns the MockUserTransaction.
 javax.transaction.UserTransaction getUserTransaction()
          Returns the UserTransaction.
 void initMockContextFactory()
          Calls MockContextFactory.setAsInitial(), if MockContextFactory is not already the current context factory.
 void resetMockContextFactory()
          Calls MockContextFactory.revertSetAsInitial(), if MockContextFactory is the current context factory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EJBMockObjectFactory

public EJBMockObjectFactory()
Creates a new set of mock objects.


EJBMockObjectFactory

public EJBMockObjectFactory(Configuration configuration)
Creates a new set of mock objects based on the specified configuration.

Method Detail

createMockUserTransaction

public MockUserTransaction createMockUserTransaction()
Creates the MockUserTransaction using new. This method can be overridden to return a subclass of MockUserTransaction.

Returns:
the MockUserTransaction

initMockContextFactory

public void initMockContextFactory()
                            throws javax.naming.NamingException
Calls MockContextFactory.setAsInitial(), if MockContextFactory is not already the current context factory.

Throws:
javax.naming.NamingException

resetMockContextFactory

public void resetMockContextFactory()
Calls MockContextFactory.revertSetAsInitial(), if MockContextFactory is the current context factory.


getMockUserTransaction

public MockUserTransaction getMockUserTransaction()
Returns the MockUserTransaction. If the bound transaction is no MockUserTransaction, this method returns null.

Returns:
the MockUserTransaction

getUserTransaction

public javax.transaction.UserTransaction getUserTransaction()
Returns the UserTransaction.

Returns:
the UserTransaction

getMockContainer

public org.mockejb.MockContainer getMockContainer()
Returns the MockEJB MockContainer.

Returns:
the MockContainer

getContext

public javax.naming.Context getContext()
Returns the JNDI context that is used by this factory. If you do not set a Context using Configuration.setContext(javax.naming.Context)}, the JNDI implementation of MockEJB is used.

Returns:
the JNDI context