[jboss-cvs] JBoss Messaging SVN: r4524 - in trunk: tests/src/org/jboss/messaging/tests/unit/jms/client and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Jun 19 11:18:06 EDT 2008
Author: jmesnil
Date: 2008-06-19 11:18:05 -0400 (Thu, 19 Jun 2008)
New Revision: 4524
Added:
trunk/tests/src/org/jboss/messaging/tests/unit/jms/client/JBossMessageConsumerTest.java
trunk/tests/src/org/jboss/messaging/tests/unit/jms/client/JBossMessageProducerTest.java
trunk/tests/src/org/jboss/messaging/tests/unit/jms/client/JMSExceptionHelperTest.java
Modified:
trunk/src/main/org/jboss/messaging/jms/client/JBossMessageConsumer.java
trunk/src/main/org/jboss/messaging/jms/client/JBossMessageProducer.java
trunk/src/main/org/jboss/messaging/jms/client/JBossSession.java
Log:
unit tests for JBossMessageConsumer, JBossMessageProducer & JMSExceptionHelper
Modified: trunk/src/main/org/jboss/messaging/jms/client/JBossMessageConsumer.java
===================================================================
--- trunk/src/main/org/jboss/messaging/jms/client/JBossMessageConsumer.java 2008-06-19 15:17:21 UTC (rev 4523)
+++ trunk/src/main/org/jboss/messaging/jms/client/JBossMessageConsumer.java 2008-06-19 15:18:05 UTC (rev 4524)
@@ -71,12 +71,10 @@
private String selector;
- private boolean deleteQueueOnClose;
-
// Constructors --------------------------------------------------
public JBossMessageConsumer(JBossSession session, ClientConsumer consumer, boolean noLocal,
- Destination destination, String selector, boolean deleteQueueOnClose) throws JMSException
+ Destination destination, String selector) throws JMSException
{
this.session = session;
@@ -88,9 +86,7 @@
this.destination = destination;
- this.selector = selector;
-
- this.deleteQueueOnClose = deleteQueueOnClose;
+ this.selector = selector;
}
// MessageConsumer implementation --------------------------------
Modified: trunk/src/main/org/jboss/messaging/jms/client/JBossMessageProducer.java
===================================================================
--- trunk/src/main/org/jboss/messaging/jms/client/JBossMessageProducer.java 2008-06-19 15:17:21 UTC (rev 4523)
+++ trunk/src/main/org/jboss/messaging/jms/client/JBossMessageProducer.java 2008-06-19 15:18:05 UTC (rev 4524)
@@ -306,7 +306,7 @@
// Public --------------------------------------------------------
- public org.jboss.messaging.core.client.ClientProducer getDelegate()
+ public ClientProducer getDelegate()
{
return producer;
}
Modified: trunk/src/main/org/jboss/messaging/jms/client/JBossSession.java
===================================================================
--- trunk/src/main/org/jboss/messaging/jms/client/JBossSession.java 2008-06-19 15:17:21 UTC (rev 4523)
+++ trunk/src/main/org/jboss/messaging/jms/client/JBossSession.java 2008-06-19 15:18:05 UTC (rev 4524)
@@ -377,7 +377,7 @@
ClientConsumer cd = createConsumer(jbdest, null, messageSelector, noLocal);
- return new JBossMessageConsumer(this, cd, noLocal, destination, messageSelector, destination instanceof Topic);
+ return new JBossMessageConsumer(this, cd, noLocal, destination, messageSelector);
}
public Queue createQueue(final String queueName) throws JMSException
@@ -469,7 +469,7 @@
ClientConsumer cd = createConsumer(jbdest, name, messageSelector, noLocal);
- return new JBossMessageConsumer(this, cd, noLocal, topic, messageSelector, false);
+ return new JBossMessageConsumer(this, cd, noLocal, topic, messageSelector);
}
private ClientConsumer createConsumer(final JBossDestination dest,
Added: trunk/tests/src/org/jboss/messaging/tests/unit/jms/client/JBossMessageConsumerTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/jms/client/JBossMessageConsumerTest.java (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/jms/client/JBossMessageConsumerTest.java 2008-06-19 15:18:05 UTC (rev 4524)
@@ -0,0 +1,417 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.messaging.tests.unit.jms.client;
+
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.isA;
+import static org.easymock.classextension.EasyMock.createStrictMock;
+import static org.easymock.classextension.EasyMock.replay;
+import static org.easymock.classextension.EasyMock.verify;
+import static org.jboss.messaging.tests.util.RandomUtil.randomString;
+
+import javax.jms.Destination;
+import javax.jms.IllegalStateException;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageListener;
+import javax.jms.Session;
+
+import junit.framework.TestCase;
+
+import org.jboss.messaging.core.client.ClientConsumer;
+import org.jboss.messaging.core.client.ClientMessage;
+import org.jboss.messaging.core.client.ClientSession;
+import org.jboss.messaging.core.client.MessageHandler;
+import org.jboss.messaging.core.exception.MessagingException;
+import org.jboss.messaging.jms.JBossQueue;
+import org.jboss.messaging.jms.JBossTopic;
+import org.jboss.messaging.jms.client.JBossMessage;
+import org.jboss.messaging.jms.client.JBossMessageConsumer;
+import org.jboss.messaging.jms.client.JBossSession;
+import org.jboss.messaging.util.MessagingBuffer;
+
+/**
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ *
+ * @version <tt>$Revision$</tt>
+ *
+ */
+public class JBossMessageConsumerTest extends TestCase
+{
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ public void testClose() throws Exception
+ {
+ JBossSession session = createStrictMock(JBossSession.class);
+ expect(session.getAcknowledgeMode()).andReturn(Session.AUTO_ACKNOWLEDGE);
+ ClientConsumer clientConsumer = createStrictMock(ClientConsumer.class);
+ clientConsumer.close();
+
+ replay(session, clientConsumer);
+
+ Destination destination = new JBossQueue(randomString());
+ JBossMessageConsumer consumer = new JBossMessageConsumer(session,
+ clientConsumer, false, destination, null);
+
+ consumer.close();
+
+ verify(session, clientConsumer);
+ }
+
+ public void testCloseThrowsException() throws Exception
+ {
+ JBossSession session = createStrictMock(JBossSession.class);
+ Destination destination = new JBossQueue(randomString());
+ expect(session.getAcknowledgeMode()).andReturn(Session.AUTO_ACKNOWLEDGE);
+ ClientConsumer clientConsumer = createStrictMock(ClientConsumer.class);
+ clientConsumer.close();
+ expectLastCall().andThrow(new MessagingException());
+
+ replay(session, clientConsumer);
+
+ JBossMessageConsumer consumer = new JBossMessageConsumer(session,
+ clientConsumer, false, destination, null);
+
+ try
+ {
+ consumer.close();
+ fail("JMSException");
+ } catch (JMSException e)
+ {
+ }
+
+ verify(session, clientConsumer);
+ }
+
+ public void testCheckClosed() throws Exception
+ {
+ Destination destination = new JBossQueue(randomString());
+ JBossSession session = createStrictMock(JBossSession.class);
+ ClientSession clientSession = createStrictMock(ClientSession.class);
+ expect(session.getAcknowledgeMode()).andReturn(Session.AUTO_ACKNOWLEDGE);
+
+ expect(clientSession.isClosed()).andReturn(true);
+
+ expect(session.getCoreSession()).andReturn(clientSession);
+ ClientConsumer clientConsumer = createStrictMock(ClientConsumer.class);
+
+ replay(session, clientSession, clientConsumer);
+
+ JBossMessageConsumer consumer = new JBossMessageConsumer(session,
+ clientConsumer, false, destination, null);
+
+ try
+ {
+ consumer.getMessageSelector();
+ fail("IllegalStateException");
+ } catch (IllegalStateException e)
+ {
+ }
+
+ verify(session, clientSession, clientConsumer);
+ }
+
+ public void testGetMessageSelector() throws Exception
+ {
+ String messageSelector = "color = 'green'";
+ Destination destination = new JBossQueue(randomString());
+ JBossSession session = createStrictMock(JBossSession.class);
+ ClientSession clientSession = createStrictMock(ClientSession.class);
+ expect(session.getAcknowledgeMode()).andReturn(Session.AUTO_ACKNOWLEDGE);
+ expect(clientSession.isClosed()).andReturn(false);
+ expect(session.getCoreSession()).andReturn(clientSession);
+ ClientConsumer clientConsumer = createStrictMock(ClientConsumer.class);
+
+ replay(session, clientSession, clientConsumer);
+
+ JBossMessageConsumer consumer = new JBossMessageConsumer(session,
+ clientConsumer, false, destination, messageSelector);
+
+ assertEquals(messageSelector, consumer.getMessageSelector());
+
+ verify(session, clientSession, clientConsumer);
+ }
+
+ public void testGetNoLocal() throws Exception
+ {
+ boolean noLocal = true;
+ Destination destination = new JBossQueue(randomString());
+ JBossSession session = createStrictMock(JBossSession.class);
+ expect(session.getAcknowledgeMode()).andReturn(Session.AUTO_ACKNOWLEDGE);
+ ClientConsumer clientConsumer = createStrictMock(ClientConsumer.class);
+
+ replay(session, clientConsumer);
+
+ JBossMessageConsumer consumer = new JBossMessageConsumer(session,
+ clientConsumer, noLocal, destination, null);
+
+ assertEquals(noLocal, consumer.getNoLocal());
+
+ verify(session, clientConsumer);
+ }
+
+ public void testGetConsumer() throws Exception
+ {
+ Destination destination = new JBossQueue(randomString());
+ JBossSession session = createStrictMock(JBossSession.class);
+ expect(session.getAcknowledgeMode()).andReturn(Session.AUTO_ACKNOWLEDGE);
+ ClientConsumer clientConsumer = createStrictMock(ClientConsumer.class);
+
+ replay(session, clientConsumer);
+
+ JBossMessageConsumer consumer = new JBossMessageConsumer(session,
+ clientConsumer, false, destination, null);
+
+ assertEquals(clientConsumer, consumer.getConsumer());
+
+ verify(session, clientConsumer);
+ }
+
+ public void testGetQueue() throws Exception
+ {
+ Destination destination = new JBossQueue(randomString());
+ JBossSession session = createStrictMock(JBossSession.class);
+ expect(session.getAcknowledgeMode()).andReturn(Session.AUTO_ACKNOWLEDGE);
+ ClientConsumer clientConsumer = createStrictMock(ClientConsumer.class);
+
+ replay(session, clientConsumer);
+
+ JBossMessageConsumer consumer = new JBossMessageConsumer(session,
+ clientConsumer, false, destination, null);
+
+ assertEquals(destination, consumer.getQueue());
+
+ verify(session, clientConsumer);
+ }
+
+ public void testGetTopic() throws Exception
+ {
+ Destination destination = new JBossTopic(randomString());
+ JBossSession session = createStrictMock(JBossSession.class);
+ expect(session.getAcknowledgeMode()).andReturn(Session.AUTO_ACKNOWLEDGE);
+ ClientConsumer clientConsumer = createStrictMock(ClientConsumer.class);
+
+ replay(session, clientConsumer);
+
+ JBossMessageConsumer consumer = new JBossMessageConsumer(session,
+ clientConsumer, false, destination, null);
+
+ assertEquals(destination, consumer.getTopic());
+
+ verify(session, clientConsumer);
+ }
+
+ public void testGetMessageListenerIsNull() throws Exception
+ {
+ Destination destination = new JBossQueue(randomString());
+ JBossSession session = createStrictMock(JBossSession.class);
+ ClientSession clientSession = createStrictMock(ClientSession.class);
+ expect(session.getAcknowledgeMode()).andReturn(Session.AUTO_ACKNOWLEDGE);
+ expect(clientSession.isClosed()).andReturn(false);
+ expect(session.getCoreSession()).andReturn(clientSession);
+ ClientConsumer clientConsumer = createStrictMock(ClientConsumer.class);
+
+ replay(session, clientSession, clientConsumer);
+
+ JBossMessageConsumer consumer = new JBossMessageConsumer(session,
+ clientConsumer, false, destination, null);
+ assertNull(consumer.getMessageListener());
+
+ verify(session, clientSession, clientConsumer);
+ }
+
+ public void testSetMessageListener() throws Exception
+ {
+ Destination destination = new JBossQueue(randomString());
+ JBossSession session = createStrictMock(JBossSession.class);
+ ClientSession clientSession = createStrictMock(ClientSession.class);
+ expect(session.getAcknowledgeMode()).andReturn(Session.AUTO_ACKNOWLEDGE);
+ expect(clientSession.isClosed()).andReturn(false);
+ expect(session.getCoreSession()).andReturn(clientSession);
+ ClientConsumer clientConsumer = createStrictMock(ClientConsumer.class);
+ clientConsumer.setMessageHandler(isA(MessageHandler.class));
+ MessageListener listener = createStrictMock(MessageListener.class);
+
+ replay(session, clientSession, clientConsumer, listener);
+
+ JBossMessageConsumer consumer = new JBossMessageConsumer(session,
+ clientConsumer, false, destination, null);
+ consumer.setMessageListener(listener);
+ assertEquals(listener, consumer.getMessageListener());
+
+ verify(session, clientSession, clientConsumer, listener);
+ }
+
+ public void testSetMessageListenerThrowsException() throws Exception
+ {
+ Destination destination = new JBossQueue(randomString());
+ JBossSession session = createStrictMock(JBossSession.class);
+ ClientSession clientSession = createStrictMock(ClientSession.class);
+ expect(session.getAcknowledgeMode()).andReturn(Session.AUTO_ACKNOWLEDGE);
+ ClientConsumer clientConsumer = createStrictMock(ClientConsumer.class);
+ clientConsumer.setMessageHandler(isA(MessageHandler.class));
+ expectLastCall().andThrow(new MessagingException());
+ MessageListener listener = createStrictMock(MessageListener.class);
+
+ replay(session, clientSession, clientConsumer, listener);
+
+ JBossMessageConsumer consumer = new JBossMessageConsumer(session,
+ clientConsumer, false, destination, null);
+ try
+ {
+ consumer.setMessageListener(listener);
+ fail("JMSException");
+ } catch (JMSException e)
+ {
+ }
+
+ verify(session, clientSession, clientConsumer, listener);
+ }
+
+ public void testReceiveWithNoMessage() throws Exception
+ {
+ doReceiveWithNoMessage(0, new MessageReceiver()
+ {
+ public Message receive(MessageConsumer consumer) throws Exception
+ {
+ return consumer.receive();
+ }
+ });
+ }
+
+ public void testReceiveNoWaitWithNoMessage() throws Exception
+ {
+ doReceiveWithNoMessage(-1, new MessageReceiver()
+ {
+ public Message receive(MessageConsumer consumer) throws Exception
+ {
+ return consumer.receiveNoWait();
+ }
+ });
+ }
+
+ public void testReceiveWithTimeoutWithNoMessage() throws Exception
+ {
+ final long timeout = 1000;
+ doReceiveWithNoMessage(timeout, new MessageReceiver()
+ {
+ public Message receive(MessageConsumer consumer) throws Exception
+ {
+ return consumer.receive(timeout);
+ }
+ });
+ }
+
+ public void testReceiveThrowsException() throws Exception
+ {
+ Destination destination = new JBossQueue(randomString());
+ JBossSession session = createStrictMock(JBossSession.class);
+ expect(session.getAcknowledgeMode()).andReturn(Session.AUTO_ACKNOWLEDGE);
+ ClientConsumer clientConsumer = createStrictMock(ClientConsumer.class);
+ expect(clientConsumer.receive(0)).andThrow(new MessagingException());
+
+ replay(session, clientConsumer);
+
+ JBossMessageConsumer consumer = new JBossMessageConsumer(session,
+ clientConsumer, false, destination, null);
+
+ try
+ {
+ consumer.receive();
+ fail("JMSException");
+ } catch (JMSException e)
+ {
+ }
+
+ verify(session, clientConsumer);
+ }
+
+ public void testReceive() throws Exception
+ {
+ Destination destination = new JBossQueue(randomString());
+ JBossSession session = createStrictMock(JBossSession.class);
+ ClientSession clientSession = createStrictMock(ClientSession.class);
+ expect(session.getAcknowledgeMode()).andReturn(Session.AUTO_ACKNOWLEDGE);
+ clientSession.acknowledge();
+ expect(session.getCoreSession()).andStubReturn(clientSession);
+ ClientConsumer clientConsumer = createStrictMock(ClientConsumer.class);
+ ClientMessage clientMessage = createStrictMock(ClientMessage.class);
+ expect(clientMessage.getType()).andReturn(JBossMessage.TYPE);
+ MessagingBuffer body = createStrictMock(MessagingBuffer.class);
+ expect(clientMessage.getBody()).andStubReturn(body );
+ expect(clientConsumer.receive(0)).andReturn(clientMessage );
+
+ replay(session, clientSession, clientConsumer, clientMessage, body);
+
+ JBossMessageConsumer consumer = new JBossMessageConsumer(session,
+ clientConsumer, false, destination, null);
+
+ Message message = consumer.receive();
+ assertNotNull(message);
+
+ verify(session, clientSession, clientConsumer, clientMessage, body);
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ public void doReceiveWithNoMessage(long expectedTimeout,
+ MessageReceiver receiver) throws Exception
+ {
+ Destination destination = new JBossQueue(randomString());
+ JBossSession session = createStrictMock(JBossSession.class);
+ expect(session.getAcknowledgeMode()).andReturn(Session.AUTO_ACKNOWLEDGE);
+ ClientConsumer clientConsumer = createStrictMock(ClientConsumer.class);
+ expect(clientConsumer.receive(expectedTimeout)).andReturn(null);
+
+ replay(session, clientConsumer);
+
+ JBossMessageConsumer consumer = new JBossMessageConsumer(session,
+ clientConsumer, false, destination, null);
+
+ Message message = receiver.receive(consumer);
+ assertNull(message);
+
+ verify(session, clientConsumer);
+ }
+
+ // Inner classes -------------------------------------------------
+
+ private interface MessageReceiver
+ {
+ Message receive(MessageConsumer consumer) throws Exception;
+ }
+}
Added: trunk/tests/src/org/jboss/messaging/tests/unit/jms/client/JBossMessageProducerTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/jms/client/JBossMessageProducerTest.java (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/jms/client/JBossMessageProducerTest.java 2008-06-19 15:18:05 UTC (rev 4524)
@@ -0,0 +1,422 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.messaging.tests.unit.jms.client;
+
+import static org.easymock.EasyMock.anyInt;
+import static org.easymock.EasyMock.anyLong;
+import static org.easymock.EasyMock.eq;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.gt;
+import static org.easymock.EasyMock.isA;
+import static org.easymock.EasyMock.isNull;
+import static org.easymock.EasyMock.startsWith;
+import static org.easymock.classextension.EasyMock.createStrictMock;
+import static org.easymock.classextension.EasyMock.replay;
+import static org.easymock.classextension.EasyMock.verify;
+import static org.jboss.messaging.tests.util.RandomUtil.randomBoolean;
+import static org.jboss.messaging.tests.util.RandomUtil.randomBytes;
+import static org.jboss.messaging.tests.util.RandomUtil.randomString;
+
+import java.util.Vector;
+
+import javax.jms.DeliveryMode;
+import javax.jms.Destination;
+import javax.jms.IllegalStateException;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.Queue;
+import javax.jms.Topic;
+
+import junit.framework.TestCase;
+
+import org.easymock.EasyMock;
+import org.jboss.messaging.core.client.ClientMessage;
+import org.jboss.messaging.core.client.ClientProducer;
+import org.jboss.messaging.core.exception.MessagingException;
+import org.jboss.messaging.jms.JBossDestination;
+import org.jboss.messaging.jms.JBossQueue;
+import org.jboss.messaging.jms.JBossTopic;
+import org.jboss.messaging.jms.client.JBossMessageProducer;
+import org.jboss.messaging.util.SimpleString;
+
+/**
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ *
+ * @version <tt>$Revision$</tt>
+ *
+ */
+public class JBossMessageProducerTest extends TestCase
+{
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ public void testClose() throws Exception
+ {
+ ClientProducer clientProducer = createStrictMock(ClientProducer.class);
+ clientProducer.close();
+
+ replay(clientProducer);
+
+ JBossDestination destination = new JBossQueue(randomString());
+ JBossMessageProducer producer = new JBossMessageProducer(clientProducer,
+ destination);
+
+ producer.close();
+
+ verify(clientProducer);
+ }
+
+ public void testCloseThrowsException() throws Exception
+ {
+ ClientProducer clientProducer = createStrictMock(ClientProducer.class);
+ clientProducer.close();
+ expectLastCall().andThrow(new MessagingException());
+
+ replay(clientProducer);
+
+ JBossDestination destination = new JBossQueue(randomString());
+ JBossMessageProducer producer = new JBossMessageProducer(clientProducer,
+ destination);
+
+ try
+ {
+ producer.close();
+ fail("JMSException");
+ } catch (JMSException e)
+ {
+ }
+
+ verify(clientProducer);
+ }
+
+ public void testCheckClosed() throws Exception
+ {
+ JBossDestination destination = new JBossQueue(randomString());
+ ClientProducer clientProducer = createStrictMock(ClientProducer.class);
+ expect(clientProducer.isClosed()).andReturn(true);
+ replay(clientProducer);
+
+ JBossMessageProducer producer = new JBossMessageProducer(clientProducer,
+ destination);
+
+ try
+ {
+ producer.getDeliveryMode();
+ fail("IllegalStateException");
+ } catch (IllegalStateException e)
+ {
+ }
+
+ verify(clientProducer);
+ }
+
+ public void testDisabledMessageID() throws Exception
+ {
+ ClientProducer clientProducer = createStrictMock(ClientProducer.class);
+ EasyMock.expect(clientProducer.isClosed()).andStubReturn(false);
+ replay(clientProducer);
+
+ JBossDestination destination = new JBossQueue(randomString());
+ JBossMessageProducer producer = new JBossMessageProducer(clientProducer,
+ destination);
+ boolean disabledMessageID = randomBoolean();
+ producer.setDisableMessageID(disabledMessageID);
+ assertEquals(disabledMessageID, producer.getDisableMessageID());
+
+ verify(clientProducer);
+ }
+
+ public void testDisableMessageTimestamp() throws Exception
+ {
+ ClientProducer clientProducer = createStrictMock(ClientProducer.class);
+ EasyMock.expect(clientProducer.isClosed()).andStubReturn(false);
+ replay(clientProducer);
+
+ JBossDestination destination = new JBossQueue(randomString());
+ JBossMessageProducer producer = new JBossMessageProducer(clientProducer,
+ destination);
+ boolean disabledTimestamp = randomBoolean();
+ producer.setDisableMessageTimestamp(disabledTimestamp);
+ assertEquals(disabledTimestamp, producer.getDisableMessageTimestamp());
+
+ verify(clientProducer);
+ }
+
+ public void testDeliveryMode() throws Exception
+ {
+ ClientProducer clientProducer = createStrictMock(ClientProducer.class);
+ EasyMock.expect(clientProducer.isClosed()).andStubReturn(false);
+ replay(clientProducer);
+
+ JBossDestination destination = new JBossQueue(randomString());
+ JBossMessageProducer producer = new JBossMessageProducer(clientProducer,
+ destination);
+ int deliveryMode = DeliveryMode.PERSISTENT;
+ producer.setDeliveryMode(deliveryMode);
+ assertEquals(deliveryMode, producer.getDeliveryMode());
+
+ verify(clientProducer);
+ }
+
+ public void testPriority() throws Exception
+ {
+ ClientProducer clientProducer = createStrictMock(ClientProducer.class);
+ EasyMock.expect(clientProducer.isClosed()).andStubReturn(false);
+ replay(clientProducer);
+
+ JBossDestination destination = new JBossQueue(randomString());
+ JBossMessageProducer producer = new JBossMessageProducer(clientProducer,
+ destination);
+ int priority = 7;
+ producer.setPriority(priority);
+ assertEquals(priority, producer.getPriority());
+
+ verify(clientProducer);
+ }
+
+ public void testTimeToLive() throws Exception
+ {
+ ClientProducer clientProducer = createStrictMock(ClientProducer.class);
+ EasyMock.expect(clientProducer.isClosed()).andStubReturn(false);
+ replay(clientProducer);
+
+ JBossDestination destination = new JBossQueue(randomString());
+ JBossMessageProducer producer = new JBossMessageProducer(clientProducer,
+ destination);
+ long ttl = System.currentTimeMillis();
+ producer.setTimeToLive(ttl);
+ assertEquals(ttl, producer.getTimeToLive());
+
+ verify(clientProducer);
+ }
+
+ public void testGetDestination() throws Exception
+ {
+ ClientProducer clientProducer = createStrictMock(ClientProducer.class);
+ EasyMock.expect(clientProducer.isClosed()).andStubReturn(false);
+ replay(clientProducer);
+
+ JBossDestination destination = new JBossQueue(randomString());
+ JBossMessageProducer producer = new JBossMessageProducer(clientProducer,
+ destination);
+ assertEquals(destination, producer.getDestination());
+
+ verify(clientProducer);
+ }
+
+ public void testGetDelegate() throws Exception
+ {
+ ClientProducer clientProducer = createStrictMock(ClientProducer.class);
+ EasyMock.expect(clientProducer.isClosed()).andStubReturn(false);
+ replay(clientProducer);
+
+ JBossDestination destination = new JBossQueue(randomString());
+ JBossMessageProducer producer = new JBossMessageProducer(clientProducer,
+ destination);
+ assertEquals(clientProducer, producer.getDelegate());
+
+ verify(clientProducer);
+ }
+
+ public void testGetTopic() throws Exception
+ {
+ ClientProducer clientProducer = createStrictMock(ClientProducer.class);
+ EasyMock.expect(clientProducer.isClosed()).andStubReturn(false);
+ replay(clientProducer);
+
+ JBossDestination destination = new JBossTopic(randomString());
+ JBossMessageProducer producer = new JBossMessageProducer(clientProducer,
+ destination);
+ assertEquals(destination, producer.getTopic());
+
+ verify(clientProducer);
+ }
+
+ public void testGetQueue() throws Exception
+ {
+ ClientProducer clientProducer = createStrictMock(ClientProducer.class);
+ EasyMock.expect(clientProducer.isClosed()).andStubReturn(false);
+ replay(clientProducer);
+
+ JBossDestination destination = new JBossQueue(randomString());
+ JBossMessageProducer producer = new JBossMessageProducer(clientProducer,
+ destination);
+ assertEquals(destination, producer.getQueue());
+
+ verify(clientProducer);
+ }
+
+ public void testSend() throws Exception
+ {
+ doProduce(new MessageProduction()
+ {
+ public void produce(JBossMessageProducer producer, Message message,
+ Destination destination) throws Exception
+ {
+ producer.send(message);
+ }
+ });
+ }
+
+ public void testSendWithDestination() throws Exception
+ {
+ doProduceWithDestination(new JBossQueue(randomString()),
+ new MessageProduction()
+ {
+ public void produce(JBossMessageProducer producer,
+ Message message, Destination destination) throws Exception
+ {
+ producer.send(destination, message);
+ }
+ });
+ }
+
+ public void testSendWithQueue() throws Exception
+ {
+ doProduceWithDestination(new JBossQueue(randomString()),
+ new MessageProduction()
+ {
+ public void produce(JBossMessageProducer producer,
+ Message message, Destination destination) throws Exception
+ {
+ assertTrue(destination instanceof Queue);
+ producer.send((Queue)destination, message);
+ }
+ });
+ }
+
+ public void testPublish() throws Exception
+ {
+ doProduce(new MessageProduction()
+ {
+ public void produce(JBossMessageProducer producer, Message message,
+ Destination destination) throws Exception
+ {
+ producer.publish(message);
+ }
+ });
+ }
+
+ public void testPublishWithDestination() throws Exception
+ {
+ doProduceWithDestination(new JBossTopic(randomString()), new MessageProduction()
+ {
+ public void produce(JBossMessageProducer producer, Message message,
+ Destination destination) throws Exception
+ {
+ assertTrue(destination instanceof Topic);
+ producer.publish((Topic) destination, message);
+ }
+ });
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ private void doProduce(MessageProduction production) throws Exception
+ {
+ JBossDestination destination = new JBossQueue(randomString());
+ JBossDestination replyTo = new JBossQueue(randomString());
+ ClientProducer clientProducer = createStrictMock(ClientProducer.class);
+ Message message = createStrictMock(Message.class);
+ expect(clientProducer.isClosed()).andStubReturn(false);
+ message.setJMSDeliveryMode(anyInt());
+ message.setJMSPriority(anyInt());
+ message.setJMSExpiration(0);
+ message.setJMSTimestamp(anyLong());
+ expect(message.getJMSTimestamp()).andReturn(0L);
+ expect(message.getJMSCorrelationIDAsBytes()).andReturn(randomBytes());
+ expect(message.getJMSReplyTo()).andReturn(replyTo);
+ expect(message.getJMSDestination()).andReturn(destination);
+ expect(message.getJMSDeliveryMode()).andReturn(
+ DeliveryMode.NON_PERSISTENT);
+ expect(message.getJMSExpiration()).andReturn(0L);
+ expect(message.getJMSPriority()).andReturn(4);
+ expect(message.getJMSType()).andReturn(null);
+ expect(message.getPropertyNames()).andReturn(
+ (new Vector<String>()).elements());
+ message.setJMSDestination(destination);
+ message.setJMSMessageID(startsWith("ID:"));
+ clientProducer.send((SimpleString) isNull(), isA(ClientMessage.class));
+ replay(clientProducer, message);
+
+ JBossMessageProducer producer = new JBossMessageProducer(clientProducer,
+ destination);
+ production.produce(producer, message, destination);
+
+ verify(clientProducer, message);
+ }
+
+ private void doProduceWithDestination(JBossDestination destination,
+ MessageProduction production) throws Exception
+ {
+ JBossDestination replyTo = new JBossQueue(randomString());
+ ClientProducer clientProducer = createStrictMock(ClientProducer.class);
+ Message message = createStrictMock(Message.class);
+ expect(clientProducer.isClosed()).andStubReturn(false);
+ message.setJMSDeliveryMode(anyInt());
+ message.setJMSPriority(anyInt());
+ message.setJMSExpiration(0);
+ message.setJMSTimestamp(anyLong());
+ expect(message.getJMSTimestamp()).andReturn(0L);
+ expect(message.getJMSCorrelationIDAsBytes()).andReturn(randomBytes());
+ expect(message.getJMSReplyTo()).andReturn(replyTo);
+ expect(message.getJMSDestination()).andReturn(destination);
+ expect(message.getJMSDeliveryMode()).andReturn(
+ DeliveryMode.NON_PERSISTENT);
+ expect(message.getJMSExpiration()).andReturn(0L);
+ expect(message.getJMSPriority()).andReturn(4);
+ expect(message.getJMSType()).andReturn(null);
+ expect(message.getPropertyNames()).andReturn(
+ (new Vector<String>()).elements());
+ message.setJMSDestination(destination);
+ message.setJMSMessageID(startsWith("ID:"));
+ clientProducer.send(eq(destination.getSimpleAddress()), isA(ClientMessage.class));
+ replay(clientProducer, message);
+
+ JBossMessageProducer producer = new JBossMessageProducer(clientProducer,
+ destination);
+ production.produce(producer, message, destination);
+
+ verify(clientProducer, message);
+ }
+
+ // Inner classes -------------------------------------------------
+
+ private interface MessageProduction
+ {
+ void produce(JBossMessageProducer producer, Message message,
+ Destination destination) throws Exception;
+ }
+}
Added: trunk/tests/src/org/jboss/messaging/tests/unit/jms/client/JMSExceptionHelperTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/jms/client/JMSExceptionHelperTest.java (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/jms/client/JMSExceptionHelperTest.java 2008-06-19 15:18:05 UTC (rev 4524)
@@ -0,0 +1,135 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.messaging.tests.unit.jms.client;
+
+import javax.jms.IllegalStateException;
+import javax.jms.InvalidDestinationException;
+import javax.jms.InvalidSelectorException;
+import javax.jms.JMSException;
+import javax.jms.JMSSecurityException;
+
+import junit.framework.TestCase;
+
+import org.jboss.messaging.core.exception.MessagingException;
+import org.jboss.messaging.jms.client.JMSExceptionHelper;
+
+/**
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ *
+ * @version <tt>$Revision$</tt>
+ *
+ */
+public class JMSExceptionHelperTest extends TestCase
+{
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ public void testCONNECTION_TIMEDOUT() throws Exception
+ {
+ doConvertException(MessagingException.CONNECTION_TIMEDOUT,
+ JMSException.class);
+ }
+
+ public void testILLEGAL_STATE() throws Exception
+ {
+ doConvertException(MessagingException.ILLEGAL_STATE,
+ IllegalStateException.class);
+ }
+
+ public void testINTERNAL_ERROR() throws Exception
+ {
+ doConvertException(MessagingException.INTERNAL_ERROR,
+ JMSException.class);
+ }
+
+ public void testINVALID_FILTER_EXPRESSION() throws Exception
+ {
+ doConvertException(MessagingException.INVALID_FILTER_EXPRESSION,
+ InvalidSelectorException.class);
+ }
+
+ public void testNOT_CONNECTED() throws Exception
+ {
+ doConvertException(MessagingException.NOT_CONNECTED,
+ JMSException.class);
+ }
+
+ public void testOBJECT_CLOSED() throws Exception
+ {
+ doConvertException(MessagingException.OBJECT_CLOSED,
+ IllegalStateException.class);
+ }
+
+ public void testQUEUE_DOES_NOT_EXIST() throws Exception
+ {
+ doConvertException(MessagingException.QUEUE_DOES_NOT_EXIST,
+ InvalidDestinationException.class);
+ }
+
+ public void testQUEUE_EXISTS() throws Exception
+ {
+ doConvertException(MessagingException.QUEUE_EXISTS,
+ InvalidDestinationException.class);
+ }
+
+ public void testSECURITY_EXCEPTION() throws Exception
+ {
+ doConvertException(MessagingException.SECURITY_EXCEPTION,
+ JMSSecurityException.class);
+ }
+
+ public void testUNSUPPORTED_PACKET() throws Exception
+ {
+ doConvertException(MessagingException.UNSUPPORTED_PACKET,
+ IllegalStateException.class);
+ }
+
+ public void testDefault() throws Exception
+ {
+ int invalidErrorCode = 2000;
+ doConvertException(invalidErrorCode, JMSException.class);
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ private void doConvertException(int errorCode, Class expectedException)
+ {
+ MessagingException me = new MessagingException(errorCode);
+ Exception e = JMSExceptionHelper.convertFromMessagingException(me);
+ assertNotNull(e);
+ assertTrue(e.getClass().isAssignableFrom(expectedException));
+ }
+
+ // Inner classes -------------------------------------------------
+}
More information about the jboss-cvs-commits
mailing list