Update of /cvsroot/mockobjects/mockobjects-java/src/j2ee/common/com/mockobjects/jms In directory usw-pr-cvs1:/tmp/cvs-serv13797/com/mockobjects/jms Added Files: MockConnection.java MockMessage.java MockMessageConsumer.java MockMessageProducer.java MockQueue.java MockQueueConnection.java MockQueueConnectionFactory.java MockQueueReceiver.java MockQueueSender.java MockQueueSession.java MockSession.java MockTemporaryQueue.java MockTextMessage.java Log Message: Setup files common to all j2ee versions --- NEW FILE: MockConnection.java --- package com.mockobjects.jms; import javax.jms.Connection; import javax.jms.ConnectionMetaData; import javax.jms.ExceptionListener; import javax.jms.JMSException; import com.mockobjects.ExpectationCounter; import com.mockobjects.MockObject; public class MockConnection extends MockObject implements Connection { protected ExpectationCounter myCloseCalls = new ExpectationCounter("MockConnection.close"); protected ExpectationCounter myStartCalls = new ExpectationCounter("MockConnection.start"); protected ExpectationCounter myStopCalls = new ExpectationCounter("MockConnection.stop"); private JMSException myException; public MockConnection() { } public void close() throws JMSException { myCloseCalls.inc(); throwExceptionIfAny(); } public String getClientID() throws JMSException { notImplemented(); return null; } public ExceptionListener getExceptionListener() throws JMSException { notImplemented(); return null; } public ConnectionMetaData getMetaData() throws JMSException { notImplemented(); return null; } public void setClientID(String clientID) throws JMSException { notImplemented(); } public void setExceptionListener(ExceptionListener listener) throws JMSException { //does nothing } public void start() throws JMSException { myStartCalls.inc(); throwExceptionIfAny(); } public void stop() throws JMSException { myStopCalls.inc(); throwExceptionIfAny(); } public void setExpectedCloseCalls(int callCount) { myCloseCalls.setExpected(callCount); } public void setExpectedStartCalls(int callCount) { myStartCalls.setExpected(callCount); } public void setExpectedStopCalls(int callCount) { myStopCalls.setExpected(callCount); } public void setupThrowException(JMSException e) { myException = e; } protected void throwExceptionIfAny() throws JMSException { if (null != myException) { throw myException; } } } --- NEW FILE: MockMessage.java --- package com.mockobjects.jms; import com.mockobjects.*; import javax.jms.*; public abstract class MockMessage extends MockObject implements Message { protected ExpectationValue myJMSReplyTo = new ExpectationValue("MockMessage.setJMSReplyTo"); protected ExpectationCounter mySetJMSCorrelationIDCalls = new ExpectationCounter("MockMessage.setJMSCorrelationID"); private JMSException myException; /** * Used for both messageID and correlationID */ private String myJMSMessageID; public MockMessage() { } public void acknowledge() throws JMSException { notImplemented(); } public void clearBody() { notImplemented(); } public void clearProperties() { notImplemented(); } public boolean getBooleanProperty(String name) { notImplemented(); return false; } public byte getByteProperty(String name) { notImplemented(); return 0; } public double getDoubleProperty(String name) { notImplemented(); return 0; } public float getFloatProperty(String name) { notImplemented(); return 0; } public int getIntProperty(String name) { notImplemented(); return 0; } public String getJMSCorrelationID() { return myJMSMessageID; } public byte[] getJMSCorrelationIDAsBytes() { notImplemented(); return null; } public int getJMSDeliveryMode() { notImplemented(); return 0; } public Destination getJMSDestination() { notImplemented(); return null; } public long getJMSExpiration() { notImplemented(); return 0; } public String getJMSMessageID() { return myJMSMessageID; } public int getJMSPriority() { notImplemented(); return 0; } public boolean getJMSRedelivered() { notImplemented(); return false; } public Destination getJMSReplyTo() { notImplemented(); return null; } public long getJMSTimestamp() { notImplemented(); return 0; } public String getJMSType() { notImplemented(); return null; } public long getLongProperty(String name) { notImplemented(); return 0; } public Object getObjectProperty(String name) { notImplemented(); return null; } public java.util.Enumeration getPropertyNames() { notImplemented(); return null; } public short getShortProperty(String name) { notImplemented(); return 0; } public String getStringProperty(String name) { notImplemented(); return null; } public boolean propertyExists(String name) { notImplemented(); return false; } public void setBooleanProperty(String name, boolean value) { notImplemented(); } public void setByteProperty(String name, byte value) { notImplemented(); } public void setDoubleProperty(String name, double value) { notImplemented(); } public void setFloatProperty(String name, float value) { notImplemented(); } public void setIntProperty(String name, int value) { notImplemented(); } public void setJMSCorrelationID(String jmsCorrelationID) { mySetJMSCorrelationIDCalls.inc(); } public void setJMSCorrelationIDAsBytes(byte[] correlationID) { notImplemented(); } public void setJMSDeliveryMode(int deliveryMode) { notImplemented(); } public void setJMSDestination(Destination destination) { notImplemented(); } public void setJMSExpiration(long expiration) { notImplemented(); } public void setJMSMessageID(String id) { notImplemented(); } public void setJMSPriority(int priority) { notImplemented(); } public void setJMSRedelivered(boolean redelivered) { notImplemented(); } public void setJMSReplyTo(Destination replyTo) throws JMSException { throwExceptionIfAny(); myJMSReplyTo.setActual(replyTo); } public void setJMSTimestamp(long timestamp) { notImplemented(); } public void setJMSType(String type) { notImplemented(); } public void setLongProperty(String name, long value) { notImplemented(); } public void setObjectProperty(String name, Object value) { notImplemented(); } public void setShortProperty(String name, short value) { notImplemented(); } public void setStringProperty(String name, String value) { notImplemented(); } public void setExpectedJMSReplyTo(Destination expectedJMSReplyTo) { myJMSReplyTo.setExpected(expectedJMSReplyTo); } public void setExpectedSetJMSCorrelationIDCalls(int callCount) { mySetJMSCorrelationIDCalls.setExpected(callCount); } public void setupJMSMessageID(String jmsMessageID) { myJMSMessageID = jmsMessageID; } public void setupThrowException(JMSException e) { myException = e; } protected void throwExceptionIfAny() throws JMSException { if (null != myException) { throw myException; } } } --- NEW FILE: MockMessageConsumer.java --- package com.mockobjects.jms; import com.mockobjects.*; import javax.jms.*; public abstract class MockMessageConsumer extends MockObject implements MessageConsumer { protected ExpectationCounter myCloseCalls = new ExpectationCounter("MockMessageConsumer.close"); protected ExpectationCounter myReceiveCalls = new ExpectationCounter("MockMessageConsumer.receive"); private Message myMessage; private boolean myExpiresOnTimeout = false; private JMSException myException; public MockMessageConsumer() { } public void close() throws JMSException { throwExceptionIfAny(); myCloseCalls.inc(); } public MessageListener getMessageListener() throws JMSException { notImplemented(); return null; } public String getMessageSelector() throws JMSException { notImplemented(); return null; } public Message receive() throws JMSException { throwExceptionIfAny(); myReceiveCalls.inc(); if (myExpiresOnTimeout) { synchronized(this) { try { wait(); } catch (InterruptedException e) { throw new junit.framework.AssertionFailedError("Thread interrupted"); } } } return myMessage; } public Message receive(long timeout) throws JMSException { throwExceptionIfAny(); myReceiveCalls.inc(); if (myExpiresOnTimeout) { return null; } else { return myMessage; } } public Message receiveNoWait() throws JMSException { throwExceptionIfAny(); myReceiveCalls.inc(); return myMessage; } public void setMessageListener(MessageListener listener) throws JMSException { notImplemented(); } public void setExpectedCloseCalls(int callCount) { myCloseCalls.setExpected(callCount); } public void setExpectedReceiveCalls(int callCount) { myReceiveCalls.setExpected(callCount); } public void setupReceivedMessage(Message message) { myMessage = message; } public void setupExpiresOnTimeout(boolean expiresOnTimeout) { myExpiresOnTimeout = expiresOnTimeout; } public void setupThrowException(JMSException e) { myException = e; } protected void throwExceptionIfAny() throws JMSException { if (null != myException) { throw myException; } } } --- NEW FILE: MockMessageProducer.java --- package com.mockobjects.jms; import com.mockobjects.*; import javax.jms.*; public abstract class MockMessageProducer extends MockObject implements MessageProducer { protected ExpectationCounter myCloseCalls = new ExpectationCounter("MockMessageConsumer.close"); private JMSException myException; public MockMessageProducer() { } public void close() throws JMSException { myCloseCalls.inc(); } public int getDeliveryMode() throws JMSException { notImplemented(); return 0; } public boolean getDisableMessageID() throws JMSException { notImplemented(); return false; } public boolean getDisableMessageTimestamp() throws JMSException { notImplemented(); return false; } public int getPriority() throws JMSException { notImplemented(); return 0; } public long getTimeToLive() throws JMSException { notImplemented(); return 0l; } public void setDeliveryMode(int deliveryMode) throws JMSException { notImplemented(); } public void setDisableMessageID(boolean value) throws JMSException { notImplemented(); } public void setDisableMessageTimestamp(boolean value) throws JMSException { notImplemented(); } public void setPriority(int defaultPriority) throws JMSException { notImplemented(); } public void setTimeToLive(long timeToLive) throws JMSException { notImplemented(); } public void setExpectedCloseCalls(int callCount) { myCloseCalls.setExpected(callCount); } public void setupThrowException(JMSException e) { myException = e; } protected void throwExceptionIfAny() throws JMSException { if (null != myException) { throw myException; } } } --- NEW FILE: MockQueue.java --- package com.mockobjects.jms; import javax.jms.JMSException; import javax.jms.Queue; import com.mockobjects.MockObject; public class MockQueue extends MockObject implements Queue { private JMSException myException; private String myName; public MockQueue(String name) { myName = name; } public String getQueueName() throws JMSException { throwExceptionIfAny(); return myName; } public boolean equals(Object object) { if (!(object instanceof Queue)) return false; try { return myName.equals(((Queue) object).getQueueName()); } catch (JMSException e) { throw new junit.framework.AssertionFailedError( "JMSException caught while getting actual queue name"); } } public int hashCode() { return myName.hashCode(); } public String toString() { return this.getClass().getName() + ", " + myName; } public void setupThrowException(JMSException e) { myException = e; } protected void throwExceptionIfAny() throws JMSException { if (null != myException) { throw myException; } } } --- NEW FILE: MockQueueConnection.java --- package com.mockobjects.jms; import com.mockobjects.*; import javax.jms.*; public class MockQueueConnection extends MockConnection implements QueueConnection { private QueueSession myQueueSession; public MockQueueConnection() { } public ConnectionConsumer createConnectionConsumer(Queue queue, String messageSelector, ServerSessionPool sessionPool, int mexMessages) throws JMSException { notImplemented(); return null; } public QueueSession createQueueSession(boolean transacted, int acknowledgeMode) throws JMSException { throwExceptionIfAny(); return myQueueSession; } public void setupQueueSession(QueueSession queueSession) { myQueueSession = queueSession; } } --- NEW FILE: MockQueueConnectionFactory.java --- package com.mockobjects.jms; import com.mockobjects.*; import javax.jms.*; public class MockQueueConnectionFactory extends MockObject implements QueueConnectionFactory { protected ExpectationValue myUserName = new ExpectationValue("MockQueueConnectionFactory.createQueueConnection"); protected ExpectationValue myPassword = new ExpectationValue("MockQueueConnectionFactory.createQueueConnection"); private JMSException myException; private QueueConnection myQueueConnection; public MockQueueConnectionFactory() { } public QueueConnection createQueueConnection() throws JMSException { throwExceptionIfAny(); return myQueueConnection; } public QueueConnection createQueueConnection(String userName, String password) throws JMSException { throwExceptionIfAny(); myUserName.setActual(userName); myPassword.setActual(password); return myQueueConnection; } public void setExpectedUserName(String userName) { myUserName.setExpected(userName); } public void setExpectedPassword(String password) { myPassword.setExpected(password); } public void setupQueueConnection(QueueConnection queueConnection) { myQueueConnection = queueConnection; } public void setupThrowException(JMSException e) { myException = e; } private void throwExceptionIfAny() throws JMSException { if (null != myException) { throw myException; } } } --- NEW FILE: MockQueueReceiver.java --- package com.mockobjects.jms; import com.mockobjects.*; import javax.jms.*; public class MockQueueReceiver extends MockMessageConsumer implements QueueReceiver { public MockQueueReceiver() { } public Queue getQueue() { notImplemented(); return null; } } --- NEW FILE: MockQueueSender.java --- package com.mockobjects.jms; import com.mockobjects.*; import javax.jms.*; public class MockQueueSender extends MockMessageProducer implements QueueSender { protected ExpectationCounter mySendCalls = new ExpectationCounter("MockQueueSender.send"); public MockQueueSender() { } public Queue getQueue() throws JMSException { notImplemented(); return null; } public void send(Message message) throws JMSException { mySendCalls.inc(); throwExceptionIfAny(); } public void send(Message message, int deliveryMode, int priority, long timeToLive) throws JMSException { notImplemented(); } public void send(Queue queue, Message message) throws JMSException { notImplemented(); } public void send(Queue queue, Message message, int deliveryMode, int priority, long timeToLive) throws JMSException { notImplemented(); } public void setExpectedSendCalls(int callCount) { mySendCalls.setExpected(callCount); } } --- NEW FILE: MockQueueSession.java --- package com.mockobjects.jms; import com.mockobjects.*; import javax.jms.*; public class MockQueueSession extends MockSession implements QueueSession { protected ExpectationValue mySendingQueue = new ExpectationValue("MockQueueSession.createSender"); protected ExpectationValue myReceivingQueue = new ExpectationValue("MockQueueSession.createReceiver"); private QueueReceiver myReceiver; private QueueSender mySender; private TemporaryQueue myTemporaryQueue; public MockQueueSession() { } public QueueBrowser createBrowser(Queue queue) throws JMSException { notImplemented(); return null; } public QueueBrowser createBrowser(Queue queue, String messageSelector) throws JMSException { notImplemented(); return null; } public Queue createQueue(String queueName) throws JMSException { throwExceptionIfAny(); return new MockQueue(queueName); } public QueueReceiver createReceiver(Queue queue) throws JMSException { throwExceptionIfAny(); myReceivingQueue.setActual(queue); return myReceiver; } public QueueReceiver createReceiver(Queue queue, String messageSelector) throws JMSException { myReceivingQueue.setActual(queue); throwExceptionIfAny(); return myReceiver; } public QueueSender createSender(Queue queue) throws JMSException { mySendingQueue.setActual(queue); throwExceptionIfAny(); return mySender; } public TemporaryQueue createTemporaryQueue() throws JMSException { throwExceptionIfAny(); return myTemporaryQueue; } public void setExpectedSendingQueue(Queue queue) { mySendingQueue.setExpected(queue); } public void setExpectedReceivingQueue(Queue queue) { myReceivingQueue.setExpected(queue); } public void setupReceiver(QueueReceiver receiver) { myReceiver = receiver; } public void setupSender(QueueSender sender) { mySender = sender; } public void setupTemporaryQueue(MockTemporaryQueue temporaryQueue) { myTemporaryQueue = temporaryQueue; } } --- NEW FILE: MockSession.java --- package com.mockobjects.jms; import com.mockobjects.*; import java.io.Serializable; import javax.jms.*; public class MockSession extends MockObject implements Session { protected ExpectationCounter myCloseCalls = new ExpectationCounter("MockSession.close"); protected ExpectationCounter myCreateTextMessageCalls = new ExpectationCounter("MockSession.createTextMessage"); private TextMessage myTextMessage = new MockTextMessage(); private JMSException myException; public MockSession() { } public void close() throws JMSException { throwExceptionIfAny(); myCloseCalls.inc(); } public void commit() throws JMSException { notImplemented(); } public BytesMessage createBytesMessage() throws JMSException { notImplemented(); return null; } public MapMessage createMapMessage() throws JMSException { notImplemented(); return null; } public Message createMessage() throws JMSException { notImplemented(); return null; } public ObjectMessage createObjectMessage() throws JMSException { notImplemented(); return null; } public ObjectMessage createObjectMessage(Serializable object) throws JMSException { notImplemented(); return null; } public StreamMessage createStreamMessage() throws JMSException { notImplemented(); return null; } public TextMessage createTextMessage() throws JMSException { myCreateTextMessageCalls.inc(); return myTextMessage; } public TextMessage createTextMessage(String text) throws JMSException { myTextMessage.setText(text); return myTextMessage; } public MessageListener getMessageListener() throws JMSException { notImplemented(); return null; } public boolean getTransacted() throws JMSException { notImplemented(); return false; } public void recover() throws JMSException { notImplemented(); } public void rollback() throws JMSException { notImplemented(); } public void run() { notImplemented(); } public void setMessageListener(MessageListener listener) throws JMSException { notImplemented(); } public void setExpectedCloseCalls(int callCount) { myCloseCalls.setExpected(callCount); } public void setExpectedCreateTextMessageCalls(int callCount) { myCreateTextMessageCalls.setExpected(callCount); } public void setupTextMessage(TextMessage textMessage) { myTextMessage = textMessage; } public void setupThrowException(JMSException e) { myException = e; } protected void throwExceptionIfAny() throws JMSException { if (null != myException) { throw myException; } } } --- NEW FILE: MockTemporaryQueue.java --- package com.mockobjects.jms; import javax.jms.JMSException; import javax.jms.TemporaryQueue; import com.mockobjects.ExpectationCounter; public class MockTemporaryQueue extends MockQueue implements TemporaryQueue { protected ExpectationCounter myDeleteCalls = new ExpectationCounter("MockTemporaryQueue.delete"); public MockTemporaryQueue() { super("TemporaryQueue"); } public void delete() throws JMSException { myDeleteCalls.inc(); throwExceptionIfAny(); } public void setExpectedDeleteCalls(int callCount) { myDeleteCalls.setExpected(callCount); } } --- NEW FILE: MockTextMessage.java --- package com.mockobjects.jms; import com.mockobjects.*; import javax.jms.*; public class MockTextMessage extends MockMessage implements TextMessage { protected ExpectationValue myExpectedText = new ExpectationValue("MockTextMessage.setText"); private String myText; public MockTextMessage() { } public MockTextMessage(String text) { myText = text; } public void setText(String text) { myExpectedText.setActual(text); } public String getText() { return myText; } public void setExpectedText(String text) { myExpectedText.setExpected(text); } } |