com.mockrunner.mock.jms
Class MockSession

java.lang.Object
  extended by com.mockrunner.mock.jms.MockSession
All Implemented Interfaces:
java.io.Serializable, java.lang.Runnable, javax.jms.Session
Direct Known Subclasses:
MockQueueSession, MockTopicSession

public class MockSession
extends java.lang.Object
implements javax.jms.Session, java.io.Serializable

Mock implementation of JMS Session. Please note that this implementation does not implement transaction isolation at the moment. Messages are immediately sent. If acknowledge mode is AUTO_ACKNOWLEDGE or DUPS_OK_ACKNOWLEDGE, the message will be automatically acknowledged, otherwise, it will not be acknowledged. According to JMS specification, the acknowledged mode must be ignored for transacted sessions. This is currently not implemented, i.e. transacted sessions behave like sessions with acknowledge mode AUTO_ACKNOWLEDGE. Messages are acknowledged even if the transaction is rolled back. However, the framework keeps track if a transaction is committed or rolled back, so you can test this and rely on the container for the rest. You can set a MessageListener directly to the session. This is an application server internal feature and not meant for application use in JMS. This mock session dispatches any message of any known Queue and Topic to the distinguished MessageListener, if such a MessageListener is registered.

See Also:
Serialized Form

Field Summary
 
Fields inherited from interface javax.jms.Session
AUTO_ACKNOWLEDGE, CLIENT_ACKNOWLEDGE, DUPS_OK_ACKNOWLEDGE, SESSION_TRANSACTED
 
Constructor Summary
MockSession(MockConnection connection, boolean transacted, int acknowledgeMode)
           
 
Method Summary
 void addSessionToQueue(javax.jms.Queue queue)
           
 void addSessionToTopic(javax.jms.Topic topic)
           
 void close()
           
 void commit()
           
 javax.jms.QueueBrowser createBrowser(javax.jms.Queue queue)
           
 javax.jms.QueueBrowser createBrowser(javax.jms.Queue queue, java.lang.String messageSelector)
           
 javax.jms.BytesMessage createBytesMessage()
           
 javax.jms.MessageConsumer createConsumer(javax.jms.Destination destination)
           
 javax.jms.MessageConsumer createConsumer(javax.jms.Destination destination, java.lang.String messageSelector)
           
 javax.jms.MessageConsumer createConsumer(javax.jms.Destination destination, java.lang.String messageSelector, boolean noLocal)
           
 javax.jms.TopicSubscriber createDurableSubscriber(javax.jms.Topic topic, java.lang.String name)
           
 javax.jms.TopicSubscriber createDurableSubscriber(javax.jms.Topic topic, java.lang.String name, java.lang.String messageSelector, boolean noLocal)
           
 javax.jms.MapMessage createMapMessage()
           
 javax.jms.Message createMessage()
           
 javax.jms.ObjectMessage createObjectMessage()
           
 javax.jms.ObjectMessage createObjectMessage(java.io.Serializable object)
           
 javax.jms.MessageProducer createProducer(javax.jms.Destination destination)
           
protected  javax.jms.MessageProducer createProducerForNullDestination()
           
 javax.jms.Queue createQueue(java.lang.String name)
           
 javax.jms.StreamMessage createStreamMessage()
           
 javax.jms.TemporaryQueue createTemporaryQueue()
           
 javax.jms.TemporaryTopic createTemporaryTopic()
           
 javax.jms.TextMessage createTextMessage()
           
 javax.jms.TextMessage createTextMessage(java.lang.String text)
           
 javax.jms.Topic createTopic(java.lang.String name)
           
 int getAcknowledgeMode()
          Note: Returns 0 if the session is transacted.
protected  MockConnection getConnection()
           
 GenericTransmissionManager getGenericTransmissionManager()
          Returns the GenericTransmissionManager.
 javax.jms.MessageListener getMessageListener()
           
 MessageManager getMessageManager()
          Returns the MessageManager for this session.
 int getNumberCommits()
          Returns the number of commits.
 int getNumberRollbacks()
          Returns the number of rollbacks.
 QueueTransmissionManager getQueueTransmissionManager()
          Returns the QueueTransmissionManager.
 MockTemporaryQueue getTemporaryQueue(int index)
          Returns a TemporaryQueue by its index.
 java.util.List getTemporaryQueueList()
          Returns the list of temporary queues.
 MockTemporaryTopic getTemporaryTopic(int index)
          Returns a TemporaryTopic by its index.
 java.util.List getTemporaryTopicList()
          Returns the list of temporary topics.
 TopicTransmissionManager getTopicTransmissionManager()
          Returns the TopicTransmissionManager.
 boolean getTransacted()
           
 TransmissionManagerWrapper getTransmissionManager()
          Deprecated. use getTransmissionManagerWrapper()
 TransmissionManagerWrapper getTransmissionManagerWrapper()
          Returns the TransmissionManagerWrapper.
 boolean isAutoAcknowledge()
          Returns if messages should be automatically acknowledged, i.e. if the acknowledge mode is not CLIENT_ACKNOWLEDGE.
 boolean isClosed()
          Returns if this session was closed.
 boolean isCommitted()
          Returns if the current transaction was committed.
 boolean isRecovered()
          Returns if this session was recovered.
 boolean isRolledBack()
          Returns if the current transaction was rolled back.
 void recover()
           
 void rollback()
           
 void run()
           
 void setMessageListener(javax.jms.MessageListener messageListener)
           
 void unsubscribe(java.lang.String name)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MockSession

public MockSession(MockConnection connection,
                   boolean transacted,
                   int acknowledgeMode)
Method Detail

getQueueTransmissionManager

public QueueTransmissionManager getQueueTransmissionManager()
Returns the QueueTransmissionManager.

Returns:
the QueueTransmissionManager

getTopicTransmissionManager

public TopicTransmissionManager getTopicTransmissionManager()
Returns the TopicTransmissionManager.

Returns:
the TopicTransmissionManager

getGenericTransmissionManager

public GenericTransmissionManager getGenericTransmissionManager()
Returns the GenericTransmissionManager.

Returns:
the GenericTransmissionManager

getTransmissionManager

public TransmissionManagerWrapper getTransmissionManager()
Deprecated. use getTransmissionManagerWrapper()


getTransmissionManagerWrapper

public TransmissionManagerWrapper getTransmissionManagerWrapper()
Returns the TransmissionManagerWrapper.

Returns:
the TransmissionManagerWrapper

getMessageManager

public MessageManager getMessageManager()
Returns the MessageManager for this session.

Returns:
the MessageManager

getTemporaryQueueList

public java.util.List getTemporaryQueueList()
Returns the list of temporary queues.

Returns:
the TemporaryQueue list

getTemporaryQueue

public MockTemporaryQueue getTemporaryQueue(int index)
Returns a TemporaryQueue by its index. The index represent the number of the queue. Returns null if no such TemporaryQueue is present.

Parameters:
index - the index
Returns:
the TemporaryQueue

getTemporaryTopicList

public java.util.List getTemporaryTopicList()
Returns the list of temporary topics.

Returns:
the TemporaryTopic list

getTemporaryTopic

public MockTemporaryTopic getTemporaryTopic(int index)
Returns a TemporaryTopic by its index. The index represent the number of the topic. Returns null if no such TemporaryTopic is present.

Parameters:
index - the index
Returns:
the TemporaryTopic

isClosed

public boolean isClosed()
Returns if this session was closed.

Returns:
true if this session is closed

isRecovered

public boolean isRecovered()
Returns if this session was recovered.

Returns:
true if this session was recovered

isCommitted

public boolean isCommitted()
Returns if the current transaction was committed.

Returns:
true if the transaction was committed

getNumberCommits

public int getNumberCommits()
Returns the number of commits.

Returns:
the number of commits

isRolledBack

public boolean isRolledBack()
Returns if the current transaction was rolled back.

Returns:
true if the transaction was rolled back

getNumberRollbacks

public int getNumberRollbacks()
Returns the number of rollbacks.

Returns:
the number of rollbacks

isAutoAcknowledge

public boolean isAutoAcknowledge()
Returns if messages should be automatically acknowledged, i.e. if the acknowledge mode is not CLIENT_ACKNOWLEDGE.

Returns:
true if messages are automatically acknowledged

getAcknowledgeMode

public int getAcknowledgeMode()
                       throws javax.jms.JMSException
Note: Returns 0 if the session is transacted. This method does not exist in JMS 1.0.2. In JMS 1.1 it should return Session.SESSION_TRANSACTED which is specified as 0. In order to avoid different versions for JMS 1.0.2 and 1.1 (Session.SESSION_TRANSACTED does not exist in 1.0.2) this method returns hardcoded 0, if the session is transacted.

Specified by:
getAcknowledgeMode in interface javax.jms.Session
Returns:
the acknowledge mode
Throws:
javax.jms.JMSException

getTransacted

public boolean getTransacted()
                      throws javax.jms.JMSException
Specified by:
getTransacted in interface javax.jms.Session
Throws:
javax.jms.JMSException

createBytesMessage

public javax.jms.BytesMessage createBytesMessage()
                                          throws javax.jms.JMSException
Specified by:
createBytesMessage in interface javax.jms.Session
Throws:
javax.jms.JMSException

createMapMessage

public javax.jms.MapMessage createMapMessage()
                                      throws javax.jms.JMSException
Specified by:
createMapMessage in interface javax.jms.Session
Throws:
javax.jms.JMSException

createMessage

public javax.jms.Message createMessage()
                                throws javax.jms.JMSException
Specified by:
createMessage in interface javax.jms.Session
Throws:
javax.jms.JMSException

createObjectMessage

public javax.jms.ObjectMessage createObjectMessage()
                                            throws javax.jms.JMSException
Specified by:
createObjectMessage in interface javax.jms.Session
Throws:
javax.jms.JMSException

createObjectMessage

public javax.jms.ObjectMessage createObjectMessage(java.io.Serializable object)
                                            throws javax.jms.JMSException
Specified by:
createObjectMessage in interface javax.jms.Session
Throws:
javax.jms.JMSException

createStreamMessage

public javax.jms.StreamMessage createStreamMessage()
                                            throws javax.jms.JMSException
Specified by:
createStreamMessage in interface javax.jms.Session
Throws:
javax.jms.JMSException

createTextMessage

public javax.jms.TextMessage createTextMessage()
                                        throws javax.jms.JMSException
Specified by:
createTextMessage in interface javax.jms.Session
Throws:
javax.jms.JMSException

createTextMessage

public javax.jms.TextMessage createTextMessage(java.lang.String text)
                                        throws javax.jms.JMSException
Specified by:
createTextMessage in interface javax.jms.Session
Throws:
javax.jms.JMSException

getMessageListener

public javax.jms.MessageListener getMessageListener()
                                             throws javax.jms.JMSException
Specified by:
getMessageListener in interface javax.jms.Session
Throws:
javax.jms.JMSException

setMessageListener

public void setMessageListener(javax.jms.MessageListener messageListener)
                        throws javax.jms.JMSException
Specified by:
setMessageListener in interface javax.jms.Session
Throws:
javax.jms.JMSException

run

public void run()
Specified by:
run in interface java.lang.Runnable
Specified by:
run in interface javax.jms.Session

commit

public void commit()
            throws javax.jms.JMSException
Specified by:
commit in interface javax.jms.Session
Throws:
javax.jms.JMSException

rollback

public void rollback()
              throws javax.jms.JMSException
Specified by:
rollback in interface javax.jms.Session
Throws:
javax.jms.JMSException

close

public void close()
           throws javax.jms.JMSException
Specified by:
close in interface javax.jms.Session
Throws:
javax.jms.JMSException

recover

public void recover()
             throws javax.jms.JMSException
Specified by:
recover in interface javax.jms.Session
Throws:
javax.jms.JMSException

unsubscribe

public void unsubscribe(java.lang.String name)
                 throws javax.jms.JMSException
Specified by:
unsubscribe in interface javax.jms.Session
Throws:
javax.jms.JMSException

createQueue

public javax.jms.Queue createQueue(java.lang.String name)
                            throws javax.jms.JMSException
Specified by:
createQueue in interface javax.jms.Session
Throws:
javax.jms.JMSException

createTemporaryQueue

public javax.jms.TemporaryQueue createTemporaryQueue()
                                              throws javax.jms.JMSException
Specified by:
createTemporaryQueue in interface javax.jms.Session
Throws:
javax.jms.JMSException

createTopic

public javax.jms.Topic createTopic(java.lang.String name)
                            throws javax.jms.JMSException
Specified by:
createTopic in interface javax.jms.Session
Throws:
javax.jms.JMSException

createTemporaryTopic

public javax.jms.TemporaryTopic createTemporaryTopic()
                                              throws javax.jms.JMSException
Specified by:
createTemporaryTopic in interface javax.jms.Session
Throws:
javax.jms.JMSException

createConsumer

public javax.jms.MessageConsumer createConsumer(javax.jms.Destination destination)
                                         throws javax.jms.JMSException
Specified by:
createConsumer in interface javax.jms.Session
Throws:
javax.jms.JMSException

createConsumer

public javax.jms.MessageConsumer createConsumer(javax.jms.Destination destination,
                                                java.lang.String messageSelector)
                                         throws javax.jms.JMSException
Specified by:
createConsumer in interface javax.jms.Session
Throws:
javax.jms.JMSException

createConsumer

public javax.jms.MessageConsumer createConsumer(javax.jms.Destination destination,
                                                java.lang.String messageSelector,
                                                boolean noLocal)
                                         throws javax.jms.JMSException
Specified by:
createConsumer in interface javax.jms.Session
Throws:
javax.jms.JMSException

createProducer

public javax.jms.MessageProducer createProducer(javax.jms.Destination destination)
                                         throws javax.jms.JMSException
Specified by:
createProducer in interface javax.jms.Session
Throws:
javax.jms.JMSException

createBrowser

public javax.jms.QueueBrowser createBrowser(javax.jms.Queue queue)
                                     throws javax.jms.JMSException
Specified by:
createBrowser in interface javax.jms.Session
Throws:
javax.jms.JMSException

createBrowser

public javax.jms.QueueBrowser createBrowser(javax.jms.Queue queue,
                                            java.lang.String messageSelector)
                                     throws javax.jms.JMSException
Specified by:
createBrowser in interface javax.jms.Session
Throws:
javax.jms.JMSException

createDurableSubscriber

public javax.jms.TopicSubscriber createDurableSubscriber(javax.jms.Topic topic,
                                                         java.lang.String name)
                                                  throws javax.jms.JMSException
Specified by:
createDurableSubscriber in interface javax.jms.Session
Throws:
javax.jms.JMSException

createDurableSubscriber

public javax.jms.TopicSubscriber createDurableSubscriber(javax.jms.Topic topic,
                                                         java.lang.String name,
                                                         java.lang.String messageSelector,
                                                         boolean noLocal)
                                                  throws javax.jms.JMSException
Specified by:
createDurableSubscriber in interface javax.jms.Session
Throws:
javax.jms.JMSException

getConnection

protected MockConnection getConnection()

addSessionToQueue

public void addSessionToQueue(javax.jms.Queue queue)

addSessionToTopic

public void addSessionToTopic(javax.jms.Topic topic)

createProducerForNullDestination

protected javax.jms.MessageProducer createProducerForNullDestination()