001 package com.mockrunner.mock.jms;
002
003 import javax.jms.JMSException;
004 import javax.jms.QueueSession;
005 import javax.jms.ServerSession;
006 import javax.jms.Session;
007
008 /**
009 * Mock implementation of JMS <code>ServerSession</code>.
010 * The <code>ServerSession</code> is not meant for application
011 * use. This simple implementation only returns a
012 * {@link MockSession} when calling {@link #getSession}.
013 */
014 public class MockServerSession implements ServerSession
015 {
016 private MockConnection connection;
017 private Session session;
018 private boolean started;
019
020 public MockServerSession(MockConnection connection)
021 {
022 this.connection = connection;
023 session = new MockSession(connection, false, QueueSession.AUTO_ACKNOWLEDGE);
024 started = false;
025 }
026
027 /**
028 * Returns if this server session was started.
029 * @return <code>true</code> if this server session is started
030 */
031 public boolean isStarted()
032 {
033 return started;
034 }
035
036 public void setSession(Session session)
037 {
038 this.session = session;
039 }
040
041 public Session getSession() throws JMSException
042 {
043 connection.throwJMSException();
044 return session;
045 }
046
047 public void start() throws JMSException
048 {
049 connection.throwJMSException();
050 started = true;
051 }
052 }