org.mockejb
Class MockEjbContext

java.lang.Object
  extended byorg.mockejb.MockEjbContext
All Implemented Interfaces:
javax.ejb.EJBContext, javax.ejb.EntityContext, javax.ejb.MessageDrivenContext, java.io.Serializable, javax.ejb.SessionContext

public class MockEjbContext
extends java.lang.Object
implements javax.ejb.SessionContext, javax.ejb.MessageDrivenContext, javax.ejb.EntityContext, java.io.Serializable

Provides implementation of javax.ejb.SessionContext, javax.ejb.MessageDrivenContext and javax.ejb.EntityContext as well as some extra convenience methods.

Author:
Alexander Ananiev
See Also:
Serialized Form

Method Summary
 java.security.Identity getCallerIdentity()
          This method is not supported
 java.security.Principal getCallerPrincipal()
          Returns the principal that was logged in using MockContainer.login.
 javax.ejb.EJBHome getEJBHome()
           
 javax.ejb.EJBLocalHome getEJBLocalHome()
           
 javax.ejb.EJBLocalObject getEJBLocalObject()
          Obtains a reference to the EJB local object that is currently associated with the instance.
 javax.ejb.EJBObject getEJBObject()
          Obtains a reference to the EJB object that is currently associated with the instance.
 java.util.Properties getEnvironment()
          Always returns empty Properties object.
 java.lang.Object getPrimaryKey()
          Returns the primary key for entity beans.
 boolean getRollbackOnly()
           
 javax.transaction.UserTransaction getUserTransaction()
          Calls TransactionManager to get the javax.transaction.UserTransaction object.
 boolean isCallerInRole(java.security.Identity arg0)
          This method is not supported
 boolean isCallerInRole(java.lang.String role)
           
 boolean isRemote()
          Tests if the business interface for this context's bean is remote interface meaning that it extends EJBObject.
 void setPrimaryKey(java.lang.Object primaryKey)
           
 void setRollbackOnly()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

isRemote

public boolean isRemote()
Tests if the business interface for this context's bean is remote interface meaning that it extends EJBObject.
This is useful for exception handling and in other places where local/remote interfaces behave differently.

Returns:
true if the business interface of this context's EJB implements remote interface. Always returns false for message-driven beans.

getEJBHome

public javax.ejb.EJBHome getEJBHome()
Specified by:
getEJBHome in interface javax.ejb.EJBContext
See Also:
EJBContext.getEJBHome()

getEJBLocalHome

public javax.ejb.EJBLocalHome getEJBLocalHome()
Specified by:
getEJBLocalHome in interface javax.ejb.EJBContext
See Also:
EJBContext.getEJBLocalHome()

getEnvironment

public java.util.Properties getEnvironment()
Always returns empty Properties object. Bean-scoped environment is not supported directly.

Specified by:
getEnvironment in interface javax.ejb.EJBContext
See Also:
EJBContext.getEnvironment()

getCallerIdentity

public java.security.Identity getCallerIdentity()
This method is not supported

Specified by:
getCallerIdentity in interface javax.ejb.EJBContext
See Also:
EJBContext.getCallerIdentity()

getCallerPrincipal

public java.security.Principal getCallerPrincipal()
Returns the principal that was logged in using MockContainer.login. Returns the anonymous principal if login was not called.

Specified by:
getCallerPrincipal in interface javax.ejb.EJBContext
Returns:
principal of the logged in user or anonymous principal
See Also:
EJBContext.getCallerPrincipal()

isCallerInRole

public boolean isCallerInRole(java.security.Identity arg0)
This method is not supported

Specified by:
isCallerInRole in interface javax.ejb.EJBContext
See Also:
EJBContext.isCallerInRole(java.security.Identity)

isCallerInRole

public boolean isCallerInRole(java.lang.String role)
Specified by:
isCallerInRole in interface javax.ejb.EJBContext
See Also:
EJBContext.isCallerInRole(java.lang.String)

getUserTransaction

public javax.transaction.UserTransaction getUserTransaction()
                                                     throws java.lang.IllegalStateException
Calls TransactionManager to get the javax.transaction.UserTransaction object.

Specified by:
getUserTransaction in interface javax.ejb.EJBContext
Returns:
javax.transaction.UserTransaction object
Throws:
java.lang.IllegalStateException
See Also:
EJBContext.getUserTransaction()

setRollbackOnly

public void setRollbackOnly()
                     throws java.lang.IllegalStateException
Specified by:
setRollbackOnly in interface javax.ejb.EJBContext
Throws:
java.lang.IllegalStateException
See Also:
EJBContext.setRollbackOnly()

getRollbackOnly

public boolean getRollbackOnly()
                        throws java.lang.IllegalStateException
Specified by:
getRollbackOnly in interface javax.ejb.EJBContext
Throws:
java.lang.IllegalStateException
See Also:
EJBContext.getRollbackOnly()

getEJBLocalObject

public javax.ejb.EJBLocalObject getEJBLocalObject()
                                           throws java.lang.IllegalStateException
Obtains a reference to the EJB local object that is currently associated with the instance.

Specified by:
getEJBLocalObject in interface javax.ejb.SessionContext
Returns:
the EJB object currently associated with the instance
Throws:
java.lang.IllegalStateException

getEJBObject

public javax.ejb.EJBObject getEJBObject()
                                 throws java.lang.IllegalStateException
Obtains a reference to the EJB object that is currently associated with the instance.

Specified by:
getEJBObject in interface javax.ejb.SessionContext
Returns:
the EJB object currently associated with the instance
Throws:
java.lang.IllegalStateException

getPrimaryKey

public java.lang.Object getPrimaryKey()
                               throws java.lang.IllegalStateException
Returns the primary key for entity beans. If the context is assotiated with Session bean or MDB, returns null. MockEJB does not automatically handles primary keys for entity beans. Since "create" returns null, you need to intercept "create" methods of your entity bean and return the real PK.

Specified by:
getPrimaryKey in interface javax.ejb.EntityContext
Throws:
java.lang.IllegalStateException
See Also:
EntityContext.getPrimaryKey()

setPrimaryKey

public void setPrimaryKey(java.lang.Object primaryKey)