001    package com.mockrunner.mock.jms;
002    
003    import java.util.List;
004    
005    import javax.jms.ConnectionConsumer;
006    import javax.jms.JMSException;
007    import javax.jms.ServerSessionPool;
008    import javax.jms.Session;
009    import javax.jms.Topic;
010    import javax.jms.TopicConnection;
011    import javax.jms.TopicSession;
012    
013    import com.mockrunner.jms.ConfigurationManager;
014    import com.mockrunner.jms.DestinationManager;
015    
016    /**
017     * Mock implementation of JMS <code>TopicConnection</code>.
018     * Please note: The interfaces <code>ConnectionConsumer</code>,
019     * <code>ServerSessionPool</code> and <code>ServerSession</code>
020     * are not meant for application use. Mockrunner provides very
021     * simple mock implementations but usually you won't need them.
022     */
023    public class MockTopicConnection extends MockConnection implements TopicConnection
024    {
025        public MockTopicConnection(DestinationManager destinationManager, ConfigurationManager configurationManager)
026        {
027            super(destinationManager, configurationManager);
028        }
029        
030        public MockTopicConnection(DestinationManager destinationManager, ConfigurationManager configurationManager, String userName, String password)
031        {
032            super(destinationManager, configurationManager, userName, password);
033        }
034    
035        /**
036         * Returns the list of {@link MockTopicSession} objects that were created 
037         * with {@link #createTopicSession}.
038         * @return the list
039         */
040        public List getTopicSessionList()
041        {
042            return super.getSessionList();
043        }
044    
045        /**
046         * Returns a {@link MockTopicSession} that was created with
047         * {@link #createTopicSession}. If there's no such
048         * {@link MockTopicSession}, <code>null</code> is returned.
049         * @param index the index of the session object
050         * @return the session object
051         */
052        public MockTopicSession getTopicSession(int index)
053        {
054            return (MockTopicSession)super.getSession(index);
055        }
056        
057        public Session createSession(boolean transacted, int acknowledgeMode) throws JMSException
058        {
059            return createTopicSession(transacted, acknowledgeMode);
060        }
061    
062        public TopicSession createTopicSession(boolean transacted, int acknowledgeMode) throws JMSException
063        {
064            throwJMSException();
065            MockTopicSession session = new MockTopicSession(this, transacted, acknowledgeMode);
066            sessions().add(session);
067            return session;
068        }
069    
070        public ConnectionConsumer createConnectionConsumer(Topic topic, String messageSelector, ServerSessionPool sessionPool, int maxMessages) throws JMSException
071        {
072            return super.createConnectionConsumer(topic, messageSelector, sessionPool, maxMessages);
073        }
074    }