com.mockrunner.mock.jms
Class MockConnection

java.lang.Object
  extended by com.mockrunner.mock.jms.MockConnection
All Implemented Interfaces:
java.io.Serializable, javax.jms.Connection
Direct Known Subclasses:
MockQueueConnection, MockTopicConnection

public class MockConnection
extends java.lang.Object
implements javax.jms.Connection, java.io.Serializable

Mock implementation of JMS Connection. Please note: The interfaces ConnectionConsumer, ServerSessionPool and ServerSession are not meant for application use. Mockrunner provides very simple mock implementations but usually you won't need them.

See Also:
Serialized Form

Constructor Summary
MockConnection(DestinationManager destinationManager, ConfigurationManager configurationManager)
           
MockConnection(DestinationManager destinationManager, ConfigurationManager configurationManager, java.lang.String userName, java.lang.String password)
           
 
Method Summary
 void callExceptionListener()
          Calls the ExceptionListener if an exception is set setJMSException(javax.jms.JMSException).
 void callExceptionListener(javax.jms.JMSException exception)
          Calls the ExceptionListener using the specified exception.
 void close()
           
 javax.jms.ConnectionConsumer createConnectionConsumer(javax.jms.Destination destination, java.lang.String messageSelector, javax.jms.ServerSessionPool sessionPool, int maxMessages)
           
 javax.jms.ConnectionConsumer createDurableConnectionConsumer(javax.jms.Topic topic, java.lang.String subscriptionName, java.lang.String messageSelector, javax.jms.ServerSessionPool sessionPool, int maxMessages)
           
 javax.jms.Session createSession(boolean transacted, int acknowledgeMode)
           
 java.lang.String getClientID()
           
 ConfigurationManager getConfigurationManager()
          Returns the ConfigurationManager.
 DestinationManager getDestinationManager()
          Returns the DestinationManager.
 javax.jms.ExceptionListener getExceptionListener()
           
 javax.jms.ConnectionMetaData getMetaData()
           
 java.lang.String getPassword()
          Returns the password.
 MockSession getSession(int index)
          Returns a MockSession.
 java.util.List getSessionList()
          Returns the list of MockSession objects.
 java.lang.String getUserName()
          Returns the user name.
 boolean isClosed()
           
 boolean isStarted()
           
 boolean isStopped()
           
protected  java.util.List sessions()
           
 void setClientID(java.lang.String clientId)
           
 void setExceptionListener(javax.jms.ExceptionListener listener)
           
 void setJMSException(javax.jms.JMSException exception)
          Set an exception that will be thrown when calling one of the interface methods.
 void setMetaData(javax.jms.ConnectionMetaData metaData)
          You can use this to set the ConnectionMetaData.
 void start()
           
 void stop()
           
 void throwJMSException()
          Throws a JMSException if one is set with setJMSException(javax.jms.JMSException).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MockConnection

public MockConnection(DestinationManager destinationManager,
                      ConfigurationManager configurationManager)

MockConnection

public MockConnection(DestinationManager destinationManager,
                      ConfigurationManager configurationManager,
                      java.lang.String userName,
                      java.lang.String password)
Method Detail

getUserName

public java.lang.String getUserName()
Returns the user name.

Returns:
the user name

getPassword

public java.lang.String getPassword()
Returns the password.

Returns:
the password

getDestinationManager

public DestinationManager getDestinationManager()
Returns the DestinationManager.

Returns:
the DestinationManager

getConfigurationManager

public ConfigurationManager getConfigurationManager()
Returns the ConfigurationManager.

Returns:
the ConfigurationManager

getSessionList

public java.util.List getSessionList()
Returns the list of MockSession objects.

Returns:
the list

getSession

public MockSession getSession(int index)
Returns a MockSession. If there's no such MockSession, null is returned.

Parameters:
index - the index of the session object
Returns:
the session object

setJMSException

public void setJMSException(javax.jms.JMSException exception)
Set an exception that will be thrown when calling one of the interface methods. Since the mock implementation cannot fail like a full blown message server you can use this method to simulate server errors. After the exception was thrown it will be deleted.

Parameters:
exception - the exception to throw

throwJMSException

public void throwJMSException()
                       throws javax.jms.JMSException
Throws a JMSException if one is set with setJMSException(javax.jms.JMSException). Deletes the exception.

Throws:
javax.jms.JMSException

callExceptionListener

public void callExceptionListener()
Calls the ExceptionListener if an exception is set setJMSException(javax.jms.JMSException). Deletes the exception after calling the ExceptionListener.


callExceptionListener

public void callExceptionListener(javax.jms.JMSException exception)
Calls the ExceptionListener using the specified exception.

Parameters:
exception - the exception

setMetaData

public void setMetaData(javax.jms.ConnectionMetaData metaData)
You can use this to set the ConnectionMetaData. Usually this should not be necessary. Per default an instance of MockConnectionMetaData is returned when calling getMetaData().

Parameters:
metaData - the meta data

createSession

public javax.jms.Session createSession(boolean transacted,
                                       int acknowledgeMode)
                                throws javax.jms.JMSException
Specified by:
createSession in interface javax.jms.Connection
Throws:
javax.jms.JMSException

createConnectionConsumer

public javax.jms.ConnectionConsumer createConnectionConsumer(javax.jms.Destination destination,
                                                             java.lang.String messageSelector,
                                                             javax.jms.ServerSessionPool sessionPool,
                                                             int maxMessages)
                                                      throws javax.jms.JMSException
Specified by:
createConnectionConsumer in interface javax.jms.Connection
Throws:
javax.jms.JMSException

createDurableConnectionConsumer

public javax.jms.ConnectionConsumer createDurableConnectionConsumer(javax.jms.Topic topic,
                                                                    java.lang.String subscriptionName,
                                                                    java.lang.String messageSelector,
                                                                    javax.jms.ServerSessionPool sessionPool,
                                                                    int maxMessages)
                                                             throws javax.jms.JMSException
Specified by:
createDurableConnectionConsumer in interface javax.jms.Connection
Throws:
javax.jms.JMSException

getMetaData

public javax.jms.ConnectionMetaData getMetaData()
                                         throws javax.jms.JMSException
Specified by:
getMetaData in interface javax.jms.Connection
Throws:
javax.jms.JMSException

getClientID

public java.lang.String getClientID()
                             throws javax.jms.JMSException
Specified by:
getClientID in interface javax.jms.Connection
Throws:
javax.jms.JMSException

setClientID

public void setClientID(java.lang.String clientId)
                 throws javax.jms.JMSException
Specified by:
setClientID in interface javax.jms.Connection
Throws:
javax.jms.JMSException

getExceptionListener

public javax.jms.ExceptionListener getExceptionListener()
                                                 throws javax.jms.JMSException
Specified by:
getExceptionListener in interface javax.jms.Connection
Throws:
javax.jms.JMSException

setExceptionListener

public void setExceptionListener(javax.jms.ExceptionListener listener)
                          throws javax.jms.JMSException
Specified by:
setExceptionListener in interface javax.jms.Connection
Throws:
javax.jms.JMSException

start

public void start()
           throws javax.jms.JMSException
Specified by:
start in interface javax.jms.Connection
Throws:
javax.jms.JMSException

stop

public void stop()
          throws javax.jms.JMSException
Specified by:
stop in interface javax.jms.Connection
Throws:
javax.jms.JMSException

close

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

isStarted

public boolean isStarted()

isStopped

public boolean isStopped()

isClosed

public boolean isClosed()

sessions

protected java.util.List sessions()