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.Queue;
008    import javax.jms.QueueConnection;
009    import javax.jms.QueueSession;
010    import javax.jms.ServerSessionPool;
011    import javax.jms.Session;
012    
013    import com.mockrunner.jms.ConfigurationManager;
014    import com.mockrunner.jms.DestinationManager;
015    
016    /**
017     * Mock implementation of JMS <code>QueueConnection</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 MockQueueConnection extends MockConnection implements QueueConnection
024    {
025        public MockQueueConnection(DestinationManager destinationManager, ConfigurationManager configurationManager)
026        {
027            super(destinationManager, configurationManager);
028        }
029        
030        public MockQueueConnection(DestinationManager destinationManager, ConfigurationManager configurationManager, String userName, String password)
031        {
032            super(destinationManager, configurationManager, userName, password);
033        }
034    
035        /**
036         * Returns the list of {@link MockQueueSession} objects that were created 
037         * with {@link #createQueueSession}.
038         * @return the list
039         */
040        public List getQueueSessionList()
041        {
042            return super.getSessionList();
043        }
044    
045        /**
046         * Returns a {@link MockQueueSession} that was created with
047         * {@link #createQueueSession}. If there's no such
048         * {@link MockQueueSession}, <code>null</code> is returned.
049         * @param index the index of the session object
050         * @return the session object
051         */
052        public MockQueueSession getQueueSession(int index)
053        {
054            return (MockQueueSession)super.getSession(index);
055        }
056        
057        public Session createSession(boolean transacted, int acknowledgeMode) throws JMSException
058        {
059            return createQueueSession(transacted, acknowledgeMode);
060        }
061        
062        public QueueSession createQueueSession(boolean transacted, int acknowledgeMode) throws JMSException
063        {
064            throwJMSException();
065            MockQueueSession session = new MockQueueSession(this, transacted, acknowledgeMode);
066            sessions().add(session);
067            return session;
068        }
069    
070        public ConnectionConsumer createConnectionConsumer(Queue queue, String messageSelector, ServerSessionPool sessionPool, int maxMessages) throws JMSException
071        {
072            return super.createConnectionConsumer(queue, messageSelector, sessionPool, maxMessages);
073        }
074    }