Add basic test of JmsConnection using mocked provider to test the basic
contracts of the object are honored. 

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

Branch: refs/heads/master
Commit: f315bd30948e8facd4e1ec553a084a6cd7a64494
Parents: b53f965
Author: Timothy Bish <[email protected]>
Authored: Tue Oct 7 18:46:45 2014 -0400
Committer: Timothy Bish <[email protected]>
Committed: Tue Oct 7 18:46:45 2014 -0400

----------------------------------------------------------------------
 .../org/apache/qpid/jms/JmsConnectionTest.java  | 97 ++++++++++++++++++++
 1 file changed, 97 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/f315bd30/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionTest.java
----------------------------------------------------------------------
diff --git 
a/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionTest.java 
b/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionTest.java
new file mode 100644
index 0000000..b5700be
--- /dev/null
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionTest.java
@@ -0,0 +1,97 @@
+/**
+ * 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.assertSame;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.net.URI;
+
+import javax.jms.JMSException;
+
+import org.apache.qpid.jms.message.JmsInboundMessageDispatch;
+import org.apache.qpid.jms.provider.Provider;
+import org.apache.qpid.jms.util.IdGenerator;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+/**
+ * Test basic functionality around JmsConnection
+ */
+public class JmsConnectionTest {
+
+    private final Provider provider = Mockito.mock(Provider.class);
+    private final IdGenerator clientIdGenerator = new IdGenerator();
+
+    @Test(expected=JMSException.class)
+    public void testJmsConnectionThrowsJMSExceptionProviderStartFails() throws 
JMSException, IllegalStateException, IOException {
+        Mockito.doThrow(IOException.class).when(provider).start();
+        new JmsConnection("ID:TEST:1", provider, clientIdGenerator);
+    }
+
+    @Test
+    public void testGetProvider() throws JMSException {
+        JmsConnection connection = new JmsConnection("ID:TEST:1", provider, 
clientIdGenerator);
+        assertSame(provider, connection.getProvider());
+    }
+
+    @Test(expected=javax.jms.IllegalStateException.class)
+    public void testSetClientIdWithNull() throws JMSException {
+        JmsConnection connection = new JmsConnection("ID:TEST:1", provider, 
clientIdGenerator);
+        connection.setClientID(null);
+    }
+
+    @Test
+    public void testGetConnectionId() throws JMSException {
+        JmsConnection connection = new JmsConnection("ID:TEST:1", provider, 
clientIdGenerator);
+        assertEquals("ID:TEST:1", connection.getConnectionId().toString());
+    }
+
+    @Test
+    public void testAddConnectionListener() throws JMSException {
+        JmsConnection connection = new JmsConnection("ID:TEST:1", provider, 
clientIdGenerator);
+        JmsConnectionListener listener = new JmsConnectionListener() {
+
+            @Override
+            public void onMessage(JmsInboundMessageDispatch envelope) {
+            }
+
+            @Override
+            public void onConnectionRestored(URI remoteURI) {
+            }
+
+            @Override
+            public void onConnectionInterrupted(URI remoteURI) {
+            }
+
+            @Override
+            public void onConnectionFailure(Throwable error) {
+            }
+
+            @Override
+            public void onConnectionEstablished(URI remoteURI) {
+            }
+        };
+
+        assertFalse(connection.removeConnectionListener(listener));
+        connection.addConnectionListener(listener);
+        assertTrue(connection.removeConnectionListener(listener));
+    }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to