com.mockrunner.ejb
Class EJBTestModule

java.lang.Object
  extended by com.mockrunner.ejb.EJBTestModule

public class EJBTestModule
extends java.lang.Object

Module for EJB tests.


Constructor Summary
EJBTestModule(EJBMockObjectFactory mockFactory)
           
 
Method Summary
 void bindToContext(java.lang.String name, java.lang.Object object)
          Adds an object to the mock context by calling rebind
 java.lang.Object createBean(java.lang.String name)
          Create an EJB.
 java.lang.Object createBean(java.lang.String name, java.lang.Object[] parameters)
          Create an EJB.
 java.lang.Object createBean(java.lang.String name, java.lang.String createMethod, java.lang.Object[] parameters)
          Create an EJB.
 java.lang.Object createBean(java.lang.String name, java.lang.String createMethod, java.lang.Object[] parameters, java.lang.Class[] parameterTypes)
          Create an EJB.
 java.lang.Object createEntityBean(java.lang.String name, java.lang.Object primaryKey)
          Create an entity EJB.
 java.lang.Object createEntityBean(java.lang.String name, java.lang.Object[] parameters, java.lang.Object primaryKey)
          Create an entity EJB.
 java.lang.Object createEntityBean(java.lang.String name, java.lang.String createMethod, java.lang.Object[] parameters, java.lang.Class[] parameterTypes, java.lang.Object primaryKey)
          Create an entity EJB.
 java.lang.Object createEntityBean(java.lang.String name, java.lang.String createMethod, java.lang.Object[] parameters, java.lang.Object primaryKey)
          Create an entity EJB.
 void deploy(org.mockejb.BasicEjbDescriptor descriptor)
          Deploys a bean to the mock container using the specified descriptor.
 void deploy(org.mockejb.BasicEjbDescriptor descriptor, org.mockejb.TransactionPolicy policy)
          Deploys a bean to the mock container using the specified descriptor.
 void deployEntityBean(java.lang.String jndiName, java.lang.Class beanClass)
          Deploys an entity bean to the mock container.
 void deployEntityBean(java.lang.String jndiName, java.lang.Class beanClass, org.mockejb.TransactionPolicy policy)
          Deploys an entity bean to the mock container.
 void deployMessageBean(java.lang.String connectionFactoryJndiName, java.lang.String destinationJndiName, javax.jms.ConnectionFactory connectionFactory, javax.jms.Destination destination, java.lang.Object bean)
          Deploys a message driven bean to the mock container.
 void deployMessageBean(java.lang.String connectionFactoryJndiName, java.lang.String destinationJndiName, javax.jms.ConnectionFactory connectionFactory, javax.jms.Destination destination, java.lang.Object bean, org.mockejb.TransactionPolicy policy)
          Deploys a message driven bean to the mock container.
 void deploySessionBean(java.lang.String jndiName, java.lang.Class beanClass)
          Deploys a stateless session bean to the mock container.
 void deploySessionBean(java.lang.String jndiName, java.lang.Class beanClass, boolean stateful)
          Deploys a session bean to the mock container.
 void deploySessionBean(java.lang.String jndiName, java.lang.Class beanClass, boolean stateful, org.mockejb.TransactionPolicy policy)
          Deploys a session bean to the mock container.
 void deploySessionBean(java.lang.String jndiName, java.lang.Class beanClass, org.mockejb.TransactionPolicy policy)
          Deploys a stateless session bean to the mock container.
 void deploySessionBean(java.lang.String jndiName, java.lang.Object bean)
          Deploys a stateless session bean to the mock container.
 void deploySessionBean(java.lang.String jndiName, java.lang.Object bean, boolean stateful)
          Deploys a session bean to the mock container.
 void deploySessionBean(java.lang.String jndiName, java.lang.Object bean, boolean stateful, org.mockejb.TransactionPolicy policy)
          Deploys a session bean to the mock container.
 void deploySessionBean(java.lang.String jndiName, java.lang.Object bean, org.mockejb.TransactionPolicy policy)
          Deploys a stateless session bean to the mock container.
 java.lang.Object findByPrimaryKey(java.lang.String name, java.lang.Object primaryKey)
          Finds an entity EJB by its primary key.
 java.lang.Object lookup(java.lang.String name)
          Lookup an object.
 java.lang.Object lookupBean(java.lang.String name)
          Deprecated. use createBean(String)
 java.lang.Object lookupBean(java.lang.String name, java.lang.Object[] parameters)
          Deprecated. use createBean(String, Object[])
 java.lang.Object lookupBean(java.lang.String name, java.lang.String createMethod, java.lang.Object[] parameters)
          Deprecated. use createBean(String, String, Object[])
 void resetUserTransaction()
          Resets the MockUserTransaction.
 void setBusinessInterfacePackage(java.lang.String businessInterfacePackage)
          Sets the package for the bean remote (local respectively) interface.
 void setBusinessInterfaceSuffix(java.lang.String businessInterfaceSuffix)
          Sets the suffix of the remote (local respectively) interface.
 void setHomeInterfacePackage(java.lang.String homeInterfacePackage)
          Sets the package for the bean home (local home respectively) interface.
 void setHomeInterfaceSuffix(java.lang.String homeInterfaceSuffix)
          Sets the suffix of the home (local home respectively) interface.
 void setImplementationSuffix(java.lang.String impSuffix)
          Sets the suffix of the bean implementation class.
 void setInterfacePackage(java.lang.String interfacePackage)
          Sets the package for the bean home and remote interfaces.
 void verifyCommitted()
          Verifies that the transaction was committed.
 void verifyMarkedForRollback()
          Verifies that the transaction was marked for rollback using the method setRollbackOnly().
 void verifyNotCommitted()
          Verifies that the transaction was not committed.
 void verifyNotMarkedForRollback()
          Verifies that the transaction was not marked for rollback.
 void verifyNotRolledBack()
          Verifies that the transaction was not rolled back.
 void verifyRolledBack()
          Verifies that the transaction was rolled back.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EJBTestModule

public EJBTestModule(EJBMockObjectFactory mockFactory)
Method Detail

setImplementationSuffix

public void setImplementationSuffix(java.lang.String impSuffix)
Sets the suffix of the bean implementation class. The default is "Bean", i.e. if the remote interface has the name Test the implementation class is TestBean.

Parameters:
impSuffix - the bean implementation suffix

setBusinessInterfaceSuffix

public void setBusinessInterfaceSuffix(java.lang.String businessInterfaceSuffix)
Sets the suffix of the remote (local respectively) interface. The default is an empty string, i.e. if the implementation class is TestBean, the remote interface is Test

Parameters:
businessInterfaceSuffix - the bean remote interface suffix

setHomeInterfaceSuffix

public void setHomeInterfaceSuffix(java.lang.String homeInterfaceSuffix)
Sets the suffix of the home (local home respectively) interface. The default is "Home", i.e. if the implementation class is TestBean, the home interface is TestHome

Parameters:
homeInterfaceSuffix - the bean home interface suffix

setInterfacePackage

public void setInterfacePackage(java.lang.String interfacePackage)
Sets the package for the bean home and remote interfaces. Per default, the framework expects that the interfaces are in the same package as the bean implementation classes.

Parameters:
interfacePackage - the package name for home and remote interfaces

setHomeInterfacePackage

public void setHomeInterfacePackage(java.lang.String homeInterfacePackage)
Sets the package for the bean home (local home respectively) interface. Per default, the framework expects that the interfaces are in the same package as the bean implementation classes.

Parameters:
homeInterfacePackage - the package name for home interface

setBusinessInterfacePackage

public void setBusinessInterfacePackage(java.lang.String businessInterfacePackage)
Sets the package for the bean remote (local respectively) interface. Per default, the framework expects that the interfaces are in the same package as the bean implementation classes.

Parameters:
businessInterfacePackage - the package name for remote interface

deploy

public void deploy(org.mockejb.BasicEjbDescriptor descriptor)
Deploys a bean to the mock container using the specified descriptor. Sets the transaction policy SUPPORTS. Determines the type of bean (session, entity, message driven) using the descriptor.

Parameters:
descriptor - the descriptor

deploy

public void deploy(org.mockejb.BasicEjbDescriptor descriptor,
                   org.mockejb.TransactionPolicy policy)
Deploys a bean to the mock container using the specified descriptor. Determines the type of bean (session, entity, message driven) using the descriptor. The specified transaction policy will be automatically set. If the specified transaction policy is null, no transaction policy will be set. This makes sense for BMT EJBs. Please note that the deploy methods of this class without a transaction policy argument automatically set the SUPPORTS policy, which also works fine for BMT EJBs.

Parameters:
descriptor - the descriptor
policy - the transaction policy

deploySessionBean

public void deploySessionBean(java.lang.String jndiName,
                              java.lang.Class beanClass)
Deploys a stateless session bean to the mock container. You have to specify the implementation class and the JNDI name. The frameworks determines the home and remote interfaces based on the information specified with the setSuffix and setPackage methods. Sets the transaction policy SUPPORTS.

Parameters:
jndiName - the JNDI name
beanClass - the bean implementation class

deploySessionBean

public void deploySessionBean(java.lang.String jndiName,
                              java.lang.Class beanClass,
                              boolean stateful)
Deploys a session bean to the mock container. You have to specify the implementation class and the JNDI name. The frameworks determines the home and remote interfaces based on the information specified with the setSuffix and setPackage methods. Sets the transaction policy SUPPORTS.

Parameters:
jndiName - the JNDI name
beanClass - the bean implementation class
stateful - is the bean stateful

deploySessionBean

public void deploySessionBean(java.lang.String jndiName,
                              java.lang.Class beanClass,
                              org.mockejb.TransactionPolicy policy)
Deploys a stateless session bean to the mock container. You have to specify the implementation class and the JNDI name. The frameworks determines the home and remote interfaces based on the information specified with the setSuffix and setPackage methods. The specified transaction policy will be automatically set.

Parameters:
jndiName - the JNDI name
beanClass - the bean implementation class
policy - the transaction policy

deploySessionBean

public void deploySessionBean(java.lang.String jndiName,
                              java.lang.Class beanClass,
                              boolean stateful,
                              org.mockejb.TransactionPolicy policy)
Deploys a session bean to the mock container. You have to specify the implementation class and the JNDI name. The frameworks determines the home and remote interfaces based on the information specified with the setSuffix and setPackage methods. The specified transaction policy will be automatically set.

Parameters:
jndiName - the JNDI name
beanClass - the bean implementation class
stateful - is the bean stateful
policy - the transaction policy

deploySessionBean

public void deploySessionBean(java.lang.String jndiName,
                              java.lang.Object bean)
Deploys a stateless session bean to the mock container. You have to specify the implementation class and the JNDI name. The frameworks determines the home and remote interfaces based on the information specified with the setSuffix and setPackage methods. Sets the transaction policy SUPPORTS.

Parameters:
jndiName - the JNDI name
bean - the bean implementation

deploySessionBean

public void deploySessionBean(java.lang.String jndiName,
                              java.lang.Object bean,
                              boolean stateful)
Deploys a session bean to the mock container. You have to specify the implementation class and the JNDI name. The frameworks determines the home and remote interfaces based on the information specified with the setSuffix and setPackage methods. Sets the transaction policy SUPPORTS.

Parameters:
jndiName - the JNDI name
bean - the bean implementation
stateful - is the bean stateful

deploySessionBean

public void deploySessionBean(java.lang.String jndiName,
                              java.lang.Object bean,
                              org.mockejb.TransactionPolicy policy)
Deploys a stateless session bean to the mock container. You have to specify the implementation class and the JNDI name. The frameworks determines the home and remote interfaces based on the information specified with the setSuffix and setPackage methods. The specified transaction policy will be automatically set.

Parameters:
jndiName - the JNDI name
bean - the bean implementation
policy - the transaction policy

deploySessionBean

public void deploySessionBean(java.lang.String jndiName,
                              java.lang.Object bean,
                              boolean stateful,
                              org.mockejb.TransactionPolicy policy)
Deploys a session bean to the mock container. You have to specify the implementation class and the JNDI name. The frameworks determines the home and remote interfaces based on the information specified with the setSuffix and setPackage methods. The specified transaction policy will be automatically set.

Parameters:
jndiName - the JNDI name
bean - the bean implementation
stateful - is the bean stateful
policy - the transaction policy

deployEntityBean

public void deployEntityBean(java.lang.String jndiName,
                             java.lang.Class beanClass)
Deploys an entity bean to the mock container. You have to specify the implementation class and the JNDI name. The frameworks determines the home and remote interfaces based on the information specified with the setSuffix and setPackage methods. Sets the transaction policy SUPPORTS.

Parameters:
jndiName - the JNDI name
beanClass - the bean implementation class

deployEntityBean

public void deployEntityBean(java.lang.String jndiName,
                             java.lang.Class beanClass,
                             org.mockejb.TransactionPolicy policy)
Deploys an entity bean to the mock container. You have to specify the implementation class and the JNDI name. The frameworks determines the home and remote interfaces based on the information specified with the setSuffix and setPackage methods. The specified transaction policy will be automatically set.

Parameters:
jndiName - the JNDI name
beanClass - the bean implementation class
policy - the transaction policy

deployMessageBean

public void deployMessageBean(java.lang.String connectionFactoryJndiName,
                              java.lang.String destinationJndiName,
                              javax.jms.ConnectionFactory connectionFactory,
                              javax.jms.Destination destination,
                              java.lang.Object bean)
Deploys a message driven bean to the mock container. You have to specify JNDI names for connection factory and destination. For creating connection factory and destination objects you can use JMSMockObjectFactory and DestinationManager. The specified objects are automatically bound to JNDI using the specified names. The mock container automatically creates a connection and session. Sets the transaction policy NOT_SUPPORTED.

Parameters:
connectionFactoryJndiName - the JNDI name of the connection factory
destinationJndiName - the JNDI name of the destination
connectionFactory - the connection factory
destination - the destination
bean - the message driven bean instance

deployMessageBean

public void deployMessageBean(java.lang.String connectionFactoryJndiName,
                              java.lang.String destinationJndiName,
                              javax.jms.ConnectionFactory connectionFactory,
                              javax.jms.Destination destination,
                              java.lang.Object bean,
                              org.mockejb.TransactionPolicy policy)
Deploys a message driven bean to the mock container. You have to specify JNDI names for connection factory and destination. For creating connection factory and destination objects you can use JMSMockObjectFactory and DestinationManager. The specified objects are automatically bound to JNDI using the specified names. The mock container automatically creates a connection and session. The specified transaction policy will be automatically set.

Parameters:
connectionFactoryJndiName - the JNDI name of the connection factory
destinationJndiName - the JNDI name of the destination
connectionFactory - the connection factory
destination - the destination
bean - the message driven bean instance
policy - the transaction policy

bindToContext

public void bindToContext(java.lang.String name,
                          java.lang.Object object)
Adds an object to the mock context by calling rebind

Parameters:
name - JNDI name of the object
object - the object to add

lookup

public java.lang.Object lookup(java.lang.String name)
Lookup an object. If the object is not bound to the InitialContext, a RuntimeException will be thrown.

Parameters:
name - JNDI name of the object
Returns:
the object
Throws:
java.lang.RuntimeException - if an object with the specified name cannot be found.

lookupBean

public java.lang.Object lookupBean(java.lang.String name)
Deprecated. use createBean(String)


createBean

public java.lang.Object createBean(java.lang.String name)
Create an EJB. The method looks up the home interface, calls the create method and returns the result, which you can cast to the remote interface. This method only works with create methods that have an empty parameter list. The create method must have the name create with no suffix. It works with the mock container but may fail with a real remote container. This method throws a RuntimeException if no object with the specified name can be found. If the found object is no EJB home interface, or if the corresponding create method cannot be found, this method returns null.

Parameters:
name - JNDI name of the bean
Returns:
the bean
Throws:
java.lang.RuntimeException - in case of error

lookupBean

public java.lang.Object lookupBean(java.lang.String name,
                                   java.lang.Object[] parameters)
Deprecated. use createBean(String, Object[])


createBean

public java.lang.Object createBean(java.lang.String name,
                                   java.lang.Object[] parameters)
Create an EJB. The method looks up the home interface, calls the create method with the specified parameters and returns the result, which you can cast to the remote interface. The create method must have the name create with no suffix. This method works with the mock container but may fail with a real remote container. This method throws a RuntimeException if no object with the specified name can be found. If the found object is no EJB home interface, or if the corresponding create method cannot be found, this method returns null. This method does not allow null as a parameter, because the type of the parameter cannot be determined in this case.

Parameters:
name - JNDI name of the bean
parameters - the parameters, null parameters are not allowed, primitive types are automatically unwrapped
Returns:
the bean
Throws:
java.lang.RuntimeException - in case of error

lookupBean

public java.lang.Object lookupBean(java.lang.String name,
                                   java.lang.String createMethod,
                                   java.lang.Object[] parameters)
Deprecated. use createBean(String, String, Object[])


createBean

public java.lang.Object createBean(java.lang.String name,
                                   java.lang.String createMethod,
                                   java.lang.Object[] parameters)
Create an EJB. The method looks up the home interface, calls the create method with the specified parameters and returns the result, which you can cast to the remote interface. This method works with the mock container but may fail with a real remote container. This method throws a RuntimeException if no object with the specified name can be found. If the found object is no EJB home interface, or if the corresponding create method cannot be found, this method returns null. This method does not allow null as a parameter, because the type of the parameter cannot be determined in this case.

Parameters:
name - JNDI name of the bean
createMethod - the name of the create method
parameters - the parameters, null parameters are not allowed, primitive types are automatically unwrapped
Returns:
the bean
Throws:
java.lang.RuntimeException - in case of error

createBean

public java.lang.Object createBean(java.lang.String name,
                                   java.lang.String createMethod,
                                   java.lang.Object[] parameters,
                                   java.lang.Class[] parameterTypes)
Create an EJB. The method looks up the home interface, calls the create method with the specified parameters and returns the result, which you can cast to the remote interface. This method works with the mock container but may fail with a real remote container. This method throws a RuntimeException if no object with the specified name can be found. If the found object is no EJB home interface, or if the corresponding create method cannot be found, this method returns null. This method does allow null as a parameter.

Parameters:
name - JNDI name of the bean
createMethod - the name of the create method
parameters - the parameters, null is allowed as a parameter
parameterTypes - the type of the specified parameters
Returns:
the bean
Throws:
java.lang.RuntimeException - in case of error

createEntityBean

public java.lang.Object createEntityBean(java.lang.String name,
                                         java.lang.Object primaryKey)
Create an entity EJB. The method looks up the home interface, calls the create method and returns the result, which you can cast to the remote interface. This method only works with create methods that have an empty parameter list. The create method must have the name create with no suffix. It works with the mock container but may fail with a real remote container. This method throws a RuntimeException if no object with the specified name can be found. If the found object is no EJB home interface, or if the corresponding create method cannot be found, this method returns null. The created entity EJB is added to the mock database automatically using the provided primary key.

Parameters:
name - JNDI name of the bean
primaryKey - the primary key
Returns:
the bean
Throws:
java.lang.RuntimeException - in case of error

createEntityBean

public java.lang.Object createEntityBean(java.lang.String name,
                                         java.lang.Object[] parameters,
                                         java.lang.Object primaryKey)
Create an entity EJB. The method looks up the home interface, calls the create method with the specified parameters and returns the result, which you can cast to the remote interface. The create method must have the name create with no suffix. This method works with the mock container but may fail with a real remote container. This method throws a RuntimeException if no object with the specified name can be found. If the found object is no EJB home interface, or if the corresponding create method cannot be found, this method returns null. The created entity EJB is added to the mock database automatically using the provided primary key. This method does not allow null as a parameter, because the type of the parameter cannot be determined in this case.

Parameters:
name - JNDI name of the bean
parameters - the parameters, null parameters are not allowed, primitive types are automatically unwrapped
primaryKey - the primary key
Returns:
the bean
Throws:
java.lang.RuntimeException - in case of error

createEntityBean

public java.lang.Object createEntityBean(java.lang.String name,
                                         java.lang.String createMethod,
                                         java.lang.Object[] parameters,
                                         java.lang.Object primaryKey)
Create an entity EJB. The method looks up the home interface, calls the create method with the specified parameters and returns the result, which you can cast to the remote interface. This method works with the mock container but may fail with a real remote container. This method throws a RuntimeException if no object with the specified name can be found. If the found object is no EJB home interface, or if the corresponding create method cannot be found, this method returns null. The created entity EJB is added to the mock database automatically using the provided primary key. This method does not allow null as a parameter, because the type of the parameter cannot be determined in this case.

Parameters:
name - JNDI name of the bean
createMethod - the name of the create method
parameters - the parameters, null parameters are not allowed, primitive types are automatically unwrapped
primaryKey - the primary key
Returns:
the bean
Throws:
java.lang.RuntimeException - in case of error

createEntityBean

public java.lang.Object createEntityBean(java.lang.String name,
                                         java.lang.String createMethod,
                                         java.lang.Object[] parameters,
                                         java.lang.Class[] parameterTypes,
                                         java.lang.Object primaryKey)
Create an entity EJB. The method looks up the home interface, calls the create method with the specified parameters and returns the result, which you can cast to the remote interface. This method works with the mock container but may fail with a real remote container. This method throws a RuntimeException if no object with the specified name can be found. If the found object is no EJB home interface, or if the corresponding create method cannot be found, this method returns null. The created entity EJB is added to the mock database automatically using the provided primary key. This method does allow null as a parameter.

Parameters:
name - JNDI name of the bean
createMethod - the name of the create method
parameters - the parameters, null is allowed as a parameter
primaryKey - the primary key
Returns:
the bean
Throws:
java.lang.RuntimeException - in case of error

findByPrimaryKey

public java.lang.Object findByPrimaryKey(java.lang.String name,
                                         java.lang.Object primaryKey)
Finds an entity EJB by its primary key. The method looks up the home interface, calls the findByPrimaryKey method and returns the result, which you can cast to the remote interface. This method works with the mock container but may fail with a real remote container. This method throws a RuntimeException if no object with the specified name can be found. If the found object is no EJB home interface, or if the findByPrimaryKey method cannot be found, this method returns null. If the mock container throws an exception because the primary key cannot be found in the entity database, this method returns null.

Parameters:
name - JNDI name of the bean
primaryKey - the primary key
Returns:
the bean
Throws:
java.lang.RuntimeException - in case of error

resetUserTransaction

public void resetUserTransaction()
Resets the MockUserTransaction. Note: If you do not use the MockUserTransaction implementation, this method does nothing.


verifyCommitted

public void verifyCommitted()
Verifies that the transaction was committed. If you are using container managed transactions, you have to set an appropriate transaction policy, e.g. REQUIRED. Otherwise the container will not commit the mock transaction. Note: If you do not use the MockUserTransaction implementation, this method throws a VerifyFailedException.

Throws:
VerifyFailedException - if verification fails

verifyNotCommitted

public void verifyNotCommitted()
Verifies that the transaction was not committed. If you are using container managed transactions, you have to set an appropriate transaction policy, e.g. REQUIRED. Note: If you do not use the MockUserTransaction implementation, this method throws a VerifyFailedException.

Throws:
VerifyFailedException - if verification fails

verifyRolledBack

public void verifyRolledBack()
Verifies that the transaction was rolled back. If you are using container managed transactions, you have to set an appropriate transaction policy, e.g. REQUIRED. Otherwise the container will not rollback the mock transaction. Note: If you do not use the MockUserTransaction implementation, this method throws a VerifyFailedException.

Throws:
VerifyFailedException - if verification fails

verifyNotRolledBack

public void verifyNotRolledBack()
Verifies that the transaction was not rolled back. If you are using container managed transactions, you have to set an appropriate transaction policy, e.g. REQUIRED. Note: If you do not use the MockUserTransaction implementation, this method throws a VerifyFailedException.

Throws:
VerifyFailedException - if verification fails

verifyMarkedForRollback

public void verifyMarkedForRollback()
Verifies that the transaction was marked for rollback using the method setRollbackOnly(). Note: If you do not use the MockUserTransaction implementation, this method throws a VerifyFailedException.

Throws:
VerifyFailedException - if verification fails

verifyNotMarkedForRollback

public void verifyNotMarkedForRollback()
Verifies that the transaction was not marked for rollback. Note: If you do not use the MockUserTransaction implementation, this method throws a VerifyFailedException.

Throws:
VerifyFailedException - if verification fails