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 /** 031 * Returns the list of {@link MockQueueSession} objects that were created 032 * with {@link #createQueueSession}. 033 * @return the list 034 */ 035 public List getQueueSessionList() 036 { 037 return super.getSessionList(); 038 } 039 040 /** 041 * Returns a {@link MockQueueSession} that was created with 042 * {@link #createQueueSession}. If there's no such 043 * {@link MockQueueSession}, <code>null</code> is returned. 044 * @param index the index of the session object 045 * @return the session object 046 */ 047 public MockQueueSession getQueueSession(int index) 048 { 049 return (MockQueueSession)super.getSession(index); 050 } 051 052 public Session createSession(boolean transacted, int acknowledgeMode) throws JMSException 053 { 054 return createQueueSession(transacted, acknowledgeMode); 055 } 056 057 public QueueSession createQueueSession(boolean transacted, int acknowledgeMode) throws JMSException 058 { 059 throwJMSException(); 060 MockQueueSession session = new MockQueueSession(this, transacted, acknowledgeMode); 061 sessions().add(session); 062 return session; 063 } 064 065 public ConnectionConsumer createConnectionConsumer(Queue queue, String messageSelector, ServerSessionPool sessionPool, int maxMessages) throws JMSException 066 { 067 return super.createConnectionConsumer(queue, messageSelector, sessionPool, maxMessages); 068 } 069 }