You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ro...@apache.org on 2016/11/09 18:04:13 UTC

qpid-jms git commit: QPIDJMS-207: ensure JMSProducer throws IDRE during send when given a null destination

Repository: qpid-jms
Updated Branches:
  refs/heads/master 3afe79d46 -> 78e6f64e2


QPIDJMS-207: ensure JMSProducer throws IDRE during send when given a null destination


Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/78e6f64e
Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/78e6f64e
Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/78e6f64e

Branch: refs/heads/master
Commit: 78e6f64e2bee3a55e8d53d0790ffdd165a3790c4
Parents: 3afe79d
Author: Robert Gemmell <ro...@apache.org>
Authored: Wed Nov 9 17:39:02 2016 +0000
Committer: Robert Gemmell <ro...@apache.org>
Committed: Wed Nov 9 17:39:12 2016 +0000

----------------------------------------------------------------------
 .../org/apache/qpid/jms/JmsMessageProducer.java |   4 -
 .../java/org/apache/qpid/jms/JmsSession.java    |   4 +
 .../org/apache/qpid/jms/JmsSessionTest.java     | 372 +++++++++++++++++++
 .../qpid/jms/producer/JmsProducerTest.java      |  39 ++
 .../apache/qpid/jms/session/JmsSessionTest.java | 361 ------------------
 5 files changed, 415 insertions(+), 365 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/78e6f64e/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsMessageProducer.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsMessageProducer.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsMessageProducer.java
index 64cdf8b..c0b8538 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsMessageProducer.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsMessageProducer.java
@@ -226,10 +226,6 @@ public class JmsMessageProducer implements AutoCloseable, MessageProducer {
     }
 
     private void sendMessage(Destination destination, Message message, int deliveryMode, int priority, long timeToLive, CompletionListener listener) throws JMSException {
-        if (destination == null) {
-            throw new InvalidDestinationException("Don't understand null destinations");
-        }
-
         this.session.send(this, destination, message, deliveryMode, priority, timeToLive, disableMessageId, disableTimestamp, deliveryDelay, listener);
     }
 

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/78e6f64e/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsSession.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsSession.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsSession.java
index 2595498..0bca8bc 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsSession.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsSession.java
@@ -711,6 +711,10 @@ public class JmsSession implements AutoCloseable, Session, QueueSession, TopicSe
     }
 
     protected void send(JmsMessageProducer producer, Destination dest, Message msg, int deliveryMode, int priority, long timeToLive, boolean disableMsgId, boolean disableTimestamp, long deliveryDelay, CompletionListener listener) throws JMSException {
+        if (dest == null) {
+            throw new InvalidDestinationException("Destination must not be null");
+        }
+
         JmsDestination destination = JmsMessageTransformation.transformDestination(connection, dest);
 
         if (destination.isTemporary() && ((JmsTemporaryDestination) destination).isDeleted()) {

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/78e6f64e/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsSessionTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsSessionTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsSessionTest.java
new file mode 100644
index 0000000..be3e668
--- /dev/null
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsSessionTest.java
@@ -0,0 +1,372 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.qpid.jms;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.UUID;
+
+import javax.jms.IllegalStateException;
+import javax.jms.InvalidDestinationException;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.MessageProducer;
+import javax.jms.ObjectMessage;
+import javax.jms.Session;
+import javax.jms.TemporaryQueue;
+import javax.jms.TextMessage;
+
+import org.apache.qpid.jms.JmsSession;
+import org.apache.qpid.jms.JmsTemporaryQueue;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+/**
+ * Test basic contracts of the JmsSession class using a mocked connection.
+ */
+public class JmsSessionTest extends JmsConnectionTestSupport {
+
+    @Override
+    @Before
+    public void setUp() throws Exception {
+        super.setUp();
+        connection = createConnectionToMockProvider();
+    }
+
+    @Test(timeout = 10000)
+    public void testGetMessageListener() throws JMSException {
+        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        assertNull(session.getMessageListener());
+        session.setMessageListener(new MessageListener() {
+
+            @Override
+            public void onMessage(Message message) {
+            }
+        });
+        assertNotNull(session.getMessageListener());
+    }
+
+    @Test(timeout = 10000)
+    public void testGetAcknowledgementMode() throws JMSException {
+        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        assertEquals(Session.AUTO_ACKNOWLEDGE, session.getAcknowledgeMode());
+        session = (JmsSession) connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+        assertEquals(Session.CLIENT_ACKNOWLEDGE, session.getAcknowledgeMode());
+        session = (JmsSession) connection.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
+        assertEquals(Session.DUPS_OK_ACKNOWLEDGE, session.getAcknowledgeMode());
+        session = (JmsSession) connection.createSession(true, Session.SESSION_TRANSACTED);
+        assertEquals(Session.SESSION_TRANSACTED, session.getAcknowledgeMode());
+    }
+
+    @Test(timeout = 10000)
+    public void testIsAutoAcknowledge() throws JMSException {
+        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        assertTrue(session.isAutoAcknowledge());
+        assertFalse(session.isClientAcknowledge());
+        assertFalse(session.isDupsOkAcknowledge());
+    }
+
+    @Test(timeout = 10000)
+    public void testIsDupsOkAcknowledge() throws JMSException {
+        JmsSession session = (JmsSession) connection.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
+        assertFalse(session.isAutoAcknowledge());
+        assertFalse(session.isClientAcknowledge());
+        assertTrue(session.isDupsOkAcknowledge());
+    }
+
+    @Test(timeout = 10000)
+    public void testIsClientAcknowledge() throws JMSException {
+        JmsSession session = (JmsSession) connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+        assertFalse(session.isAutoAcknowledge());
+        assertTrue(session.isClientAcknowledge());
+        assertFalse(session.isDupsOkAcknowledge());
+    }
+
+    @Test(timeout = 10000)
+    public void testIsTransacted() throws JMSException {
+        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        assertFalse(session.isTransacted());
+        session = (JmsSession) connection.createSession(true, Session.SESSION_TRANSACTED);
+        assertTrue(session.isTransacted());
+    }
+
+    @Test(timeout = 10000, expected=IllegalStateException.class)
+    public void testRecoverThrowsForTxSession() throws JMSException {
+        JmsSession session = (JmsSession) connection.createSession(true, Session.SESSION_TRANSACTED);
+        session.recover();
+    }
+
+    @Test(timeout = 10000)
+    public void testRecoverWithNoSessionActivity() throws JMSException {
+        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        session.recover();
+    }
+
+    @Test(timeout = 10000, expected=JMSException.class)
+    public void testRollbackThrowsOnNonTxSession() throws JMSException {
+        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        session.rollback();
+    }
+
+    @Test(timeout = 10000, expected=JMSException.class)
+    public void testCommitThrowsOnNonTxSession() throws JMSException {
+        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        session.commit();
+    }
+
+    @Test(timeout = 10000)
+    public void testCreateMessage() throws JMSException {
+        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        assertNotNull(session.createMessage());
+    }
+
+    @Test(timeout = 10000)
+    public void testCreateBytesMessage() throws JMSException {
+        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        assertNotNull(session.createBytesMessage());
+    }
+
+    @Test(timeout = 10000)
+    public void testCreateStreamMessage() throws JMSException {
+        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        assertNotNull(session.createStreamMessage());
+    }
+
+    @Test(timeout = 10000)
+    public void testCreateMapMessage() throws JMSException {
+        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        assertNotNull(session.createMapMessage());
+    }
+
+    @Test(timeout = 10000)
+    public void testCreateObjectMessage() throws JMSException {
+        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        assertNotNull(session.createObjectMessage());
+    }
+
+    @Test(timeout = 10000)
+    public void testCreateObjectMessageWithValue() throws JMSException {
+        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        ObjectMessage message = session.createObjectMessage("TEST-MESSAGE");
+        assertNotNull(message);
+        assertNotNull(message.getObject());
+        assertTrue(message.getObject() instanceof String);
+        assertEquals("TEST-MESSAGE", message.getObject());
+    }
+
+    @Test(timeout = 10000)
+    public void testCreateTextMessage() throws JMSException {
+        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        assertNotNull(session.createTextMessage());
+    }
+
+    @Test(timeout = 10000)
+    public void testCreateTextMessageWithValue() throws JMSException {
+        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        TextMessage message = session.createTextMessage("TEST-MESSAGE");
+        assertNotNull(message);
+        assertEquals("TEST-MESSAGE", message.getText());
+    }
+
+    @Test(timeout = 10000)
+    public void testUnsubscribe() throws JMSException {
+        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        session.unsubscribe("some-subscription");
+    }
+
+    @Test(timeout = 10000, expected=InvalidDestinationException.class)
+    public void testCreateConsumerNullDestinationThrowsIDE() throws JMSException {
+        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        session.createConsumer(null);
+    }
+
+    @Test(timeout = 10000, expected=InvalidDestinationException.class)
+    public void testCreateConsumerNullDestinationWithSelectorThrowsIDE() throws JMSException {
+        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        session.createConsumer(null, "a > b");
+    }
+
+    @Test(timeout = 10000, expected=InvalidDestinationException.class)
+    public void testCreateConsumerNullDestinationWithSelectorNoLocalThrowsIDE() throws JMSException {
+        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        session.createConsumer(null, "a > b", true);
+    }
+
+    @Test(timeout = 10000, expected=InvalidDestinationException.class)
+    public void testCreateReceiverNullDestinationThrowsIDE() throws JMSException {
+        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        session.createReceiver(null);
+    }
+
+    @Test(timeout = 10000, expected=InvalidDestinationException.class)
+    public void testCreateReceiverNullDestinationWithSelectorThrowsIDE() throws JMSException {
+        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        session.createConsumer(null, "a > b");
+    }
+
+    @Test(timeout = 10000, expected=InvalidDestinationException.class)
+    public void testCreateBrowserNullDestinationThrowsIDE() throws JMSException {
+        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        session.createBrowser(null);
+    }
+
+    @Test(timeout = 10000, expected=InvalidDestinationException.class)
+    public void testCreateBrowserNullDestinationWithSelectorThrowsIDE() throws JMSException {
+        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        session.createBrowser(null, "a > b");
+    }
+
+    @Test(timeout = 10000, expected=InvalidDestinationException.class)
+    public void testCreateSubscriberNullDestinationThrowsIDE() throws JMSException {
+        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        session.createSubscriber(null);
+    }
+
+    @Test(timeout = 10000, expected=InvalidDestinationException.class)
+    public void testCreateSubscriberNullDestinationWithSelectorNoLocalThrowsIDE() throws JMSException {
+        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        session.createSubscriber(null, "a > b", true);
+    }
+
+    @Test(timeout = 10000, expected=InvalidDestinationException.class)
+    public void testCreateDurableSubscriberNullDestinationThrowsIDE() throws JMSException {
+        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        session.createDurableSubscriber(null, "name");
+    }
+
+    @Test(timeout = 10000, expected=InvalidDestinationException.class)
+    public void testCreateDurableSubscriberNullDestinationWithSelectorNoLocalThrowsIDE() throws JMSException {
+        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        session.createDurableSubscriber(null, "name", "a > b", true);
+    }
+
+    @Test(timeout = 10000, expected=InvalidDestinationException.class)
+    public void testCreateDurableConsumerNullDestinationThrowsIDE() throws JMSException {
+        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        session.createDurableConsumer(null, "name");
+    }
+
+    @Test(timeout = 10000, expected=InvalidDestinationException.class)
+    public void testCreateDurableConsumerNullDestinationWithSelectorNoLocalThrowsIDE() throws JMSException {
+        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        session.createDurableConsumer(null, "name", "a > b", true);
+    }
+
+    @Test(timeout = 10000)
+    public void testSendWithNullDestThrowsIDE() throws JMSException {
+        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        JmsMessageProducer mockProducer = Mockito.mock(JmsMessageProducer.class);
+
+        try {
+            session.send(mockProducer, null, null, 0, 0, 0, true, true, 0, null);
+            fail("Should not be able to send");
+        } catch (InvalidDestinationException idex) {}
+    }
+
+    @Test(timeout = 10000)
+    public void testCannotCreateConsumerOnTempDestinationFromSomeOtherSource() throws JMSException {
+        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        TemporaryQueue tempQueue = new JmsTemporaryQueue("ID:" + UUID.randomUUID().toString());
+
+        try {
+            session.createConsumer(tempQueue);
+            fail("Should not be able to create a consumer");
+        } catch (InvalidDestinationException idex) {}
+    }
+
+    @Test(timeout = 10000)
+    public void testCannotCreateConsumerOnDeletedTemporaryDestination() throws JMSException {
+        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        TemporaryQueue tempQueue = session.createTemporaryQueue();
+        MessageProducer producer = session.createProducer(tempQueue);
+
+        try {
+            producer.send(session.createMessage());
+        } catch (Exception ex) {
+            fail("Should be able to send to this temporary destination");
+        }
+
+        tempQueue.delete();
+
+        try {
+            producer.send(session.createMessage());
+            fail("Should not be able to send to this temporary destination");
+        } catch (IllegalStateException ise) {}
+    }
+
+    @Test(timeout = 10000)
+    public void testSessionRunFailsWhenSessionIsClosed() throws Exception {
+        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+        try {
+            session.run();
+            fail("Not implemented");
+        } catch (UnsupportedOperationException usoe) {}
+
+        session.close();
+
+        try {
+            session.run();
+            fail("Session is closed.");
+        } catch (RuntimeException re) {}
+    }
+
+    //----- Not yet implemented, should all be cleared on implementation -----//
+
+    @Test(timeout = 10000)
+    public void testCreateSharedConsumer() throws Exception {
+        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        try {
+            session.createSharedConsumer(session.createTopic("test"), "subscription");
+            fail("Should fail until implemented.");
+        } catch (JMSException ex) {}
+    }
+
+    @Test(timeout = 10000)
+    public void testCreateSharedConsumerWithSelector() throws Exception {
+        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        try {
+            session.createSharedConsumer(session.createTopic("test"), "subscription", "a = b");
+            fail("Should fail until implemented.");
+        } catch (JMSException ex) {}
+    }
+
+    @Test(timeout = 10000)
+    public void testCreateSharedDurableConsumer() throws Exception {
+        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        try {
+            session.createSharedDurableConsumer(session.createTopic("test"), "subscription");
+            fail("Should fail until implemented.");
+        } catch (JMSException ex) {}
+    }
+
+    @Test(timeout = 10000)
+    public void testCreateSharedDurableConsumerWithSelector() throws Exception {
+        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        try {
+            session.createSharedDurableConsumer(session.createTopic("test"), "subscription", "a = b");
+            fail("Should fail until implemented.");
+        } catch (JMSException ex) {}
+    }
+}

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/78e6f64e/qpid-jms-client/src/test/java/org/apache/qpid/jms/producer/JmsProducerTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/producer/JmsProducerTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/producer/JmsProducerTest.java
index 457b51e..4569e4e 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/producer/JmsProducerTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/producer/JmsProducerTest.java
@@ -36,12 +36,15 @@ import javax.jms.DeliveryMode;
 import javax.jms.Destination;
 import javax.jms.IllegalStateException;
 import javax.jms.IllegalStateRuntimeException;
+import javax.jms.InvalidDestinationException;
+import javax.jms.InvalidDestinationRuntimeException;
 import javax.jms.JMSException;
 import javax.jms.JMSProducer;
 import javax.jms.Message;
 import javax.jms.MessageFormatRuntimeException;
 import javax.jms.Queue;
 
+import org.apache.qpid.jms.JmsConnection;
 import org.apache.qpid.jms.JmsConnectionTestSupport;
 import org.apache.qpid.jms.JmsContext;
 import org.apache.qpid.jms.JmsMessageProducer;
@@ -51,6 +54,7 @@ import org.apache.qpid.jms.JmsTemporaryQueue;
 import org.apache.qpid.jms.JmsTopic;
 import org.apache.qpid.jms.message.JmsMessage;
 import org.apache.qpid.jms.message.JmsOutboundMessageDispatch;
+import org.apache.qpid.jms.meta.JmsSessionId;
 import org.apache.qpid.jms.provider.mock.MockRemotePeer;
 import org.junit.Before;
 import org.junit.Test;
@@ -1264,6 +1268,41 @@ public class JmsProducerTest extends JmsConnectionTestSupport {
         } catch (IllegalStateRuntimeException isre) {}
     }
 
+    @Test
+    public void testRuntimeExceptionFromSendToInvalidDestination() throws JMSException {
+        class TestJmsSession extends JmsSession {
+            protected TestJmsSession(JmsConnection connection, JmsSessionId sessionId, int acknowledgementMode) throws JMSException {
+                super(connection, sessionId, acknowledgementMode);
+            }
+
+            @Override
+            public void send(JmsMessageProducer producer, Destination dest, Message msg, int deliveryMode, int priority, long timeToLive,
+                             boolean disableMsgId, boolean disableTimestamp, long deliveryDelay, CompletionListener listener) throws JMSException {
+                super.send(producer, dest, msg, deliveryMode, priority, timeToLive, disableMsgId, disableTimestamp, deliveryDelay, listener);
+            }
+        };
+
+        JmsMessageProducer mockMessageProducer = Mockito.mock(JmsMessageProducer.class);
+        TestJmsSession mockSession = Mockito.mock(TestJmsSession.class);
+
+        Mockito.doThrow(new InvalidDestinationException("ide"))
+                .when(mockSession)
+                .send(Mockito.any(JmsMessageProducer.class), Mockito.any(Destination.class), Mockito.any(Message.class),
+                      Mockito.any(int.class),    Mockito.any(int.class), Mockito.any(long.class), Mockito.any(boolean.class),
+                      Mockito.any(boolean.class), Mockito.any(long.class), Mockito.any(CompletionListener.class));
+
+        JmsProducer producer = new JmsProducer(mockSession, mockMessageProducer);
+
+        try {
+            producer.send(null, Mockito.mock(Message.class));
+            fail("Should have thrown an InvalidDestinationRuntimeException");
+        } catch (InvalidDestinationRuntimeException idre) {}
+
+        Mockito.verify(mockSession).send(Mockito.any(JmsMessageProducer.class), Mockito.any(Destination.class), Mockito.any(Message.class),
+                Mockito.any(int.class),    Mockito.any(int.class), Mockito.any(long.class), Mockito.any(boolean.class),
+                Mockito.any(boolean.class), Mockito.any(long.class), Mockito.any(CompletionListener.class));
+    }
+
     //----- Internal Support -------------------------------------------------//
 
     private void sendWithBodyOfType(JMSProducer producer, Class<?> asType) {

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/78e6f64e/qpid-jms-client/src/test/java/org/apache/qpid/jms/session/JmsSessionTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/session/JmsSessionTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/session/JmsSessionTest.java
deleted file mode 100644
index 6cbc308..0000000
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/session/JmsSessionTest.java
+++ /dev/null
@@ -1,361 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.qpid.jms.session;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.util.UUID;
-
-import javax.jms.IllegalStateException;
-import javax.jms.InvalidDestinationException;
-import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.MessageListener;
-import javax.jms.MessageProducer;
-import javax.jms.ObjectMessage;
-import javax.jms.Session;
-import javax.jms.TemporaryQueue;
-import javax.jms.TextMessage;
-
-import org.apache.qpid.jms.JmsConnectionTestSupport;
-import org.apache.qpid.jms.JmsSession;
-import org.apache.qpid.jms.JmsTemporaryQueue;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * Test basic contracts of the JmsSession class using a mocked connection.
- */
-public class JmsSessionTest extends JmsConnectionTestSupport {
-
-    @Override
-    @Before
-    public void setUp() throws Exception {
-        super.setUp();
-        connection = createConnectionToMockProvider();
-    }
-
-    @Test(timeout = 10000)
-    public void testGetMessageListener() throws JMSException {
-        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-        assertNull(session.getMessageListener());
-        session.setMessageListener(new MessageListener() {
-
-            @Override
-            public void onMessage(Message message) {
-            }
-        });
-        assertNotNull(session.getMessageListener());
-    }
-
-    @Test(timeout = 10000)
-    public void testGetAcknowledgementMode() throws JMSException {
-        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-        assertEquals(Session.AUTO_ACKNOWLEDGE, session.getAcknowledgeMode());
-        session = (JmsSession) connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
-        assertEquals(Session.CLIENT_ACKNOWLEDGE, session.getAcknowledgeMode());
-        session = (JmsSession) connection.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
-        assertEquals(Session.DUPS_OK_ACKNOWLEDGE, session.getAcknowledgeMode());
-        session = (JmsSession) connection.createSession(true, Session.SESSION_TRANSACTED);
-        assertEquals(Session.SESSION_TRANSACTED, session.getAcknowledgeMode());
-    }
-
-    @Test(timeout = 10000)
-    public void testIsAutoAcknowledge() throws JMSException {
-        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-        assertTrue(session.isAutoAcknowledge());
-        assertFalse(session.isClientAcknowledge());
-        assertFalse(session.isDupsOkAcknowledge());
-    }
-
-    @Test(timeout = 10000)
-    public void testIsDupsOkAcknowledge() throws JMSException {
-        JmsSession session = (JmsSession) connection.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
-        assertFalse(session.isAutoAcknowledge());
-        assertFalse(session.isClientAcknowledge());
-        assertTrue(session.isDupsOkAcknowledge());
-    }
-
-    @Test(timeout = 10000)
-    public void testIsClientAcknowledge() throws JMSException {
-        JmsSession session = (JmsSession) connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
-        assertFalse(session.isAutoAcknowledge());
-        assertTrue(session.isClientAcknowledge());
-        assertFalse(session.isDupsOkAcknowledge());
-    }
-
-    @Test(timeout = 10000)
-    public void testIsTransacted() throws JMSException {
-        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-        assertFalse(session.isTransacted());
-        session = (JmsSession) connection.createSession(true, Session.SESSION_TRANSACTED);
-        assertTrue(session.isTransacted());
-    }
-
-    @Test(timeout = 10000, expected=IllegalStateException.class)
-    public void testRecoverThrowsForTxSession() throws JMSException {
-        JmsSession session = (JmsSession) connection.createSession(true, Session.SESSION_TRANSACTED);
-        session.recover();
-    }
-
-    @Test(timeout = 10000)
-    public void testRecoverWithNoSessionActivity() throws JMSException {
-        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-        session.recover();
-    }
-
-    @Test(timeout = 10000, expected=JMSException.class)
-    public void testRollbackThrowsOnNonTxSession() throws JMSException {
-        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-        session.rollback();
-    }
-
-    @Test(timeout = 10000, expected=JMSException.class)
-    public void testCommitThrowsOnNonTxSession() throws JMSException {
-        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-        session.commit();
-    }
-
-    @Test(timeout = 10000)
-    public void testCreateMessage() throws JMSException {
-        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-        assertNotNull(session.createMessage());
-    }
-
-    @Test(timeout = 10000)
-    public void testCreateBytesMessage() throws JMSException {
-        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-        assertNotNull(session.createBytesMessage());
-    }
-
-    @Test(timeout = 10000)
-    public void testCreateStreamMessage() throws JMSException {
-        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-        assertNotNull(session.createStreamMessage());
-    }
-
-    @Test(timeout = 10000)
-    public void testCreateMapMessage() throws JMSException {
-        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-        assertNotNull(session.createMapMessage());
-    }
-
-    @Test(timeout = 10000)
-    public void testCreateObjectMessage() throws JMSException {
-        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-        assertNotNull(session.createObjectMessage());
-    }
-
-    @Test(timeout = 10000)
-    public void testCreateObjectMessageWithValue() throws JMSException {
-        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-        ObjectMessage message = session.createObjectMessage("TEST-MESSAGE");
-        assertNotNull(message);
-        assertNotNull(message.getObject());
-        assertTrue(message.getObject() instanceof String);
-        assertEquals("TEST-MESSAGE", message.getObject());
-    }
-
-    @Test(timeout = 10000)
-    public void testCreateTextMessage() throws JMSException {
-        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-        assertNotNull(session.createTextMessage());
-    }
-
-    @Test(timeout = 10000)
-    public void testCreateTextMessageWithValue() throws JMSException {
-        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-        TextMessage message = session.createTextMessage("TEST-MESSAGE");
-        assertNotNull(message);
-        assertEquals("TEST-MESSAGE", message.getText());
-    }
-
-    @Test(timeout = 10000)
-    public void testUnsubscribe() throws JMSException {
-        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-        session.unsubscribe("some-subscription");
-    }
-
-    @Test(timeout = 10000, expected=InvalidDestinationException.class)
-    public void testCreateConsumerNullDestinationThrowsIDE() throws JMSException {
-        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-        session.createConsumer(null);
-    }
-
-    @Test(timeout = 10000, expected=InvalidDestinationException.class)
-    public void testCreateConsumerNullDestinationWithSelectorThrowsIDE() throws JMSException {
-        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-        session.createConsumer(null, "a > b");
-    }
-
-    @Test(timeout = 10000, expected=InvalidDestinationException.class)
-    public void testCreateConsumerNullDestinationWithSelectorNoLocalThrowsIDE() throws JMSException {
-        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-        session.createConsumer(null, "a > b", true);
-    }
-
-    @Test(timeout = 10000, expected=InvalidDestinationException.class)
-    public void testCreateReceiverNullDestinationThrowsIDE() throws JMSException {
-        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-        session.createReceiver(null);
-    }
-
-    @Test(timeout = 10000, expected=InvalidDestinationException.class)
-    public void testCreateReceiverNullDestinationWithSelectorThrowsIDE() throws JMSException {
-        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-        session.createConsumer(null, "a > b");
-    }
-
-    @Test(timeout = 10000, expected=InvalidDestinationException.class)
-    public void testCreateBrowserNullDestinationThrowsIDE() throws JMSException {
-        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-        session.createBrowser(null);
-    }
-
-    @Test(timeout = 10000, expected=InvalidDestinationException.class)
-    public void testCreateBrowserNullDestinationWithSelectorThrowsIDE() throws JMSException {
-        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-        session.createBrowser(null, "a > b");
-    }
-
-    @Test(timeout = 10000, expected=InvalidDestinationException.class)
-    public void testCreateSubscriberNullDestinationThrowsIDE() throws JMSException {
-        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-        session.createSubscriber(null);
-    }
-
-    @Test(timeout = 10000, expected=InvalidDestinationException.class)
-    public void testCreateSubscriberNullDestinationWithSelectorNoLocalThrowsIDE() throws JMSException {
-        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-        session.createSubscriber(null, "a > b", true);
-    }
-
-    @Test(timeout = 10000, expected=InvalidDestinationException.class)
-    public void testCreateDurableSubscriberNullDestinationThrowsIDE() throws JMSException {
-        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-        session.createDurableSubscriber(null, "name");
-    }
-
-    @Test(timeout = 10000, expected=InvalidDestinationException.class)
-    public void testCreateDurableSubscriberNullDestinationWithSelectorNoLocalThrowsIDE() throws JMSException {
-        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-        session.createDurableSubscriber(null, "name", "a > b", true);
-    }
-
-    @Test(timeout = 10000, expected=InvalidDestinationException.class)
-    public void testCreateDurableConsumerNullDestinationThrowsIDE() throws JMSException {
-        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-        session.createDurableConsumer(null, "name");
-    }
-
-    @Test(timeout = 10000, expected=InvalidDestinationException.class)
-    public void testCreateDurableConsumerNullDestinationWithSelectorNoLocalThrowsIDE() throws JMSException {
-        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-        session.createDurableConsumer(null, "name", "a > b", true);
-    }
-
-    @Test(timeout = 10000)
-    public void testCannotCreateConsumerOnTempDestinationFromSomeOtherSource() throws JMSException {
-        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-        TemporaryQueue tempQueue = new JmsTemporaryQueue("ID:" + UUID.randomUUID().toString());
-
-        try {
-            session.createConsumer(tempQueue);
-            fail("Should not be able to create a consumer");
-        } catch (InvalidDestinationException idex) {}
-    }
-
-    @Test(timeout = 10000)
-    public void testCannotCreateConsumerOnDeletedTemporaryDestination() throws JMSException {
-        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-        TemporaryQueue tempQueue = session.createTemporaryQueue();
-        MessageProducer producer = session.createProducer(tempQueue);
-
-        try {
-            producer.send(session.createMessage());
-        } catch (Exception ex) {
-            fail("Should be able to send to this temporary destination");
-        }
-
-        tempQueue.delete();
-
-        try {
-            producer.send(session.createMessage());
-            fail("Should not be able to send to this temporary destination");
-        } catch (IllegalStateException ise) {}
-    }
-
-    @Test(timeout = 10000)
-    public void testSessionRunFailsWhenSessionIsClosed() throws Exception {
-        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
-        try {
-            session.run();
-            fail("Not implemented");
-        } catch (UnsupportedOperationException usoe) {}
-
-        session.close();
-
-        try {
-            session.run();
-            fail("Session is closed.");
-        } catch (RuntimeException re) {}
-    }
-
-    //----- Not yet implemented, should all be cleared on implementation -----//
-
-    @Test(timeout = 10000)
-    public void testCreateSharedConsumer() throws Exception {
-        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-        try {
-            session.createSharedConsumer(session.createTopic("test"), "subscription");
-            fail("Should fail until implemented.");
-        } catch (JMSException ex) {}
-    }
-
-    @Test(timeout = 10000)
-    public void testCreateSharedConsumerWithSelector() throws Exception {
-        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-        try {
-            session.createSharedConsumer(session.createTopic("test"), "subscription", "a = b");
-            fail("Should fail until implemented.");
-        } catch (JMSException ex) {}
-    }
-
-    @Test(timeout = 10000)
-    public void testCreateSharedDurableConsumer() throws Exception {
-        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-        try {
-            session.createSharedDurableConsumer(session.createTopic("test"), "subscription");
-            fail("Should fail until implemented.");
-        } catch (JMSException ex) {}
-    }
-
-    @Test(timeout = 10000)
-    public void testCreateSharedDurableConsumerWithSelector() throws Exception {
-        JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-        try {
-            session.createSharedDurableConsumer(session.createTopic("test"), "subscription", "a = b");
-            fail("Should fail until implemented.");
-        } catch (JMSException ex) {}
-    }
-}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org