You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ta...@apache.org on 2015/01/31 00:35:57 UTC

[3/4] qpid-jms git commit: Add some more contract validation tests for JMS spec.

Add some more contract validation tests for JMS spec.

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

Branch: refs/heads/master
Commit: 1f2e6de8da0f5606013d6ad6d9a69704266c2aa4
Parents: f36f04f
Author: Timothy Bish <ta...@gmail.com>
Authored: Fri Jan 30 17:48:05 2015 -0500
Committer: Timothy Bish <ta...@gmail.com>
Committed: Fri Jan 30 17:48:05 2015 -0500

----------------------------------------------------------------------
 .../qpid/jms/JmsConnectionTestSupport.java      |  23 ++++
 .../qpid/jms/session/JmsSessionClosedTest.java  |   2 +-
 .../apache/qpid/jms/session/JmsSessionTest.java | 112 +++++++++++++++++++
 .../jms/session/JmsTopicSessionClosedTest.java  |  29 ++++-
 4 files changed, 163 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/1f2e6de8/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionTestSupport.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionTestSupport.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionTestSupport.java
index 7f40329..05e5d4f 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionTestSupport.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionTestSupport.java
@@ -21,6 +21,7 @@ import java.net.URI;
 import org.apache.qpid.jms.message.facade.defaults.JmsDefaultMessageFactory;
 import org.apache.qpid.jms.meta.JmsConnectionInfo;
 import org.apache.qpid.jms.meta.JmsResource;
+import org.apache.qpid.jms.meta.JmsSessionId;
 import org.apache.qpid.jms.provider.Provider;
 import org.apache.qpid.jms.provider.ProviderFuture;
 import org.apache.qpid.jms.provider.ProviderListener;
@@ -80,6 +81,28 @@ public class JmsConnectionTestSupport extends QpidJmsTestCase {
             @Override
             public Object answer(InvocationOnMock invocation) throws Throwable {
                 Object[] args = invocation.getArguments();
+                LOG.trace("Handling provider recover: {}", args[0]);
+                ProviderFuture request = (ProviderFuture) args[1];
+                request.onSuccess();
+                return null;
+            }
+        }).when(provider).recover(Mockito.any(JmsSessionId.class), Mockito.any(ProviderFuture.class));
+
+        Mockito.doAnswer(new Answer<Object>() {
+            @Override
+            public Object answer(InvocationOnMock invocation) throws Throwable {
+                Object[] args = invocation.getArguments();
+                LOG.trace("Handling provider session acknowledge: {}", args[0]);
+                ProviderFuture request = (ProviderFuture) args[1];
+                request.onSuccess();
+                return null;
+            }
+        }).when(provider).acknowledge(Mockito.any(JmsSessionId.class), Mockito.any(ProviderFuture.class));
+
+        Mockito.doAnswer(new Answer<Object>() {
+            @Override
+            public Object answer(InvocationOnMock invocation) throws Throwable {
+                Object[] args = invocation.getArguments();
                 if (args[0] instanceof JmsResource) {
                     LOG.trace("Handling provider destroy resource: {}", args[0]);
                     ProviderFuture request = (ProviderFuture) args[1];

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/1f2e6de8/qpid-jms-client/src/test/java/org/apache/qpid/jms/session/JmsSessionClosedTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/session/JmsSessionClosedTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/session/JmsSessionClosedTest.java
index ec1d962..6834179 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/session/JmsSessionClosedTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/session/JmsSessionClosedTest.java
@@ -31,7 +31,7 @@ import org.junit.Before;
 import org.junit.Test;
 
 /**
- * Tests behaviour after a Session is closed.
+ * Tests behavior after a Session is closed.
  */
 public class JmsSessionClosedTest extends JmsConnectionTestSupport {
 

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/1f2e6de8/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
new file mode 100644
index 0000000..7867474
--- /dev/null
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/session/JmsSessionTest.java
@@ -0,0 +1,112 @@
+/**
+ * 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 javax.jms.IllegalStateException;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.Session;
+
+import org.apache.qpid.jms.JmsConnectionTestSupport;
+import org.apache.qpid.jms.JmsSession;
+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.isDupsOkAcknowledge());
+    }
+
+    @Test(timeout = 10000)
+    public void testIsDupsOkAcknowledge() throws JMSException {
+        JmsSession session = (JmsSession) connection.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
+        assertFalse(session.isAutoAcknowledge());
+        assertTrue(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, 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();
+    }
+}

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/1f2e6de8/qpid-jms-client/src/test/java/org/apache/qpid/jms/session/JmsTopicSessionClosedTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/session/JmsTopicSessionClosedTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/session/JmsTopicSessionClosedTest.java
index e47b532..58a3da3 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/session/JmsTopicSessionClosedTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/session/JmsTopicSessionClosedTest.java
@@ -35,12 +35,13 @@ public class JmsTopicSessionClosedTest extends JmsConnectionTestSupport {
     private TopicSession session;
     private TopicPublisher publisher;
     private TopicSubscriber subscriber;
+    private Topic destination;
 
     protected void createTestResources() throws Exception {
         connection = createTopicConnectionToMockProvider();
 
         session = ((TopicConnection) connection).createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
-        Topic destination = session.createTopic(_testName.getMethodName());
+        destination = session.createTopic(_testName.getMethodName());
 
         publisher = session.createPublisher(destination);
         subscriber = session.createSubscriber(destination);
@@ -58,10 +59,34 @@ public class JmsTopicSessionClosedTest extends JmsConnectionTestSupport {
 
     @Test(timeout=30000)
     public void testSessionCloseAgain() throws Exception {
-        // Close it again
         session.close();
     }
 
+    @Test(timeout=30000, expected=javax.jms.IllegalStateException.class)
+    public void testCreatePublisher() throws Exception {
+        session.createPublisher(destination);
+    }
+
+    @Test(timeout=30000, expected=javax.jms.IllegalStateException.class)
+    public void testCreateSubscriber() throws Exception {
+        session.createSubscriber(destination);
+    }
+
+    @Test(timeout=30000, expected=javax.jms.IllegalStateException.class)
+    public void testCreateSubscriberWithSelector() throws Exception {
+        session.createSubscriber(destination, "color = blue", false);
+    }
+
+    @Test(timeout=30000, expected=javax.jms.IllegalStateException.class)
+    public void testCreateDurableSubscriber() throws Exception {
+        session.createDurableSubscriber(destination, "foo");
+    }
+
+    @Test(timeout=30000, expected=javax.jms.IllegalStateException.class)
+    public void testCreateDurableSubscriberWithSelector() throws Exception {
+        session.createDurableSubscriber(destination, "foo", "color = blue", false);
+    }
+
     @Test(timeout=30000)
     public void testSubscriberCloseAgain() throws Exception {
         // Close it again (closing the session should have closed it already).


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