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/02/12 00:46:04 UTC
[2/2] qpid-jms git commit: Additional test coverage
Additional test coverage
Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/e5ed52ec
Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/e5ed52ec
Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/e5ed52ec
Branch: refs/heads/master
Commit: e5ed52ec002562944b9479394fe24226e7ee7545
Parents: d876637
Author: Timothy Bish <ta...@gmail.com>
Authored: Wed Feb 11 18:45:56 2015 -0500
Committer: Timothy Bish <ta...@gmail.com>
Committed: Wed Feb 11 18:45:56 2015 -0500
----------------------------------------------------------------------
.../qpid/jms/JmsConnectionFactoryTest.java | 74 ++++++++++++++++
.../org/apache/qpid/jms/JmsConnectionTest.java | 91 ++++++++++++++++++--
.../qpid/jms/provider/mock/MockProvider.java | 2 +-
3 files changed, 160 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/e5ed52ec/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionFactoryTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionFactoryTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionFactoryTest.java
index baae401..3527db2 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionFactoryTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionFactoryTest.java
@@ -24,13 +24,16 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.net.URI;
import java.util.HashMap;
import java.util.Map;
+import java.util.concurrent.TimeUnit;
+import javax.jms.Connection;
import javax.jms.ExceptionListener;
import javax.jms.IllegalStateException;
import javax.jms.JMSException;
@@ -42,6 +45,7 @@ public class JmsConnectionFactoryTest extends QpidJmsTestCase {
private static final String CLIENT_ID_PROP = "clientID";
private static final String QUEUE_PREFIX_PROP = "queuePrefix";
+ private static final String TOPIC_PREFIX_PROP = "topicPrefix";
private static final String USER = "USER";
private static final String PASSWORD = "PASSWORD";
@@ -62,6 +66,76 @@ public class JmsConnectionFactoryTest extends QpidJmsTestCase {
}
@Test
+ public void testConnectionFactoryOptionsAreAppliedToConnection() throws JMSException {
+ JmsConnectionFactory factory = new JmsConnectionFactory(USER, PASSWORD, "mock://localhost");
+
+ factory.setTopicPrefix(TOPIC_PREFIX_PROP);
+ factory.setQueuePrefix(QUEUE_PREFIX_PROP);
+ factory.setClientID(CLIENT_ID_PROP);
+
+ factory.setAlwaysSyncSend(!factory.isAlwaysSyncSend());
+ factory.setForceAsyncSend(!factory.isForceAsyncSend());
+ factory.setLocalMessagePriority(!factory.isLocalMessagePriority());
+ factory.setSendAcksAsync(!factory.isSendAcksAsync());
+ factory.setConnectTimeout(TimeUnit.SECONDS.toMillis(30));
+ factory.setCloseTimeout(TimeUnit.SECONDS.toMillis(45));
+
+ factory.getPrefetchPolicy().setAll(1);
+
+ JmsConnection connection = (JmsConnection) factory.createConnection();
+ assertNotNull(connection);
+
+ assertEquals(USER, connection.getUsername());
+ assertEquals(PASSWORD, connection.getPassword());
+ assertEquals(CLIENT_ID_PROP, connection.getClientID());
+ assertEquals(TOPIC_PREFIX_PROP, connection.getTopicPrefix());
+ assertEquals(QUEUE_PREFIX_PROP, connection.getQueuePrefix());
+
+ assertEquals(factory.isAlwaysSyncSend(), connection.isAlwaysSyncSend());
+ assertEquals(factory.isForceAsyncSend(), connection.isForceAsyncSend());
+ assertEquals(factory.isLocalMessagePriority(), connection.isLocalMessagePriority());
+ assertEquals(factory.isSendAcksAsync(), connection.isSendAcksAsync());
+
+ assertEquals(TimeUnit.SECONDS.toMillis(30), connection.getConnectTimeout());
+ assertEquals(TimeUnit.SECONDS.toMillis(45), connection.getCloseTimeout());
+
+ assertEquals(1, connection.getPrefetchPolicy().getTopicPrefetch());
+ assertEquals(1, connection.getPrefetchPolicy().getQueuePrefetch());
+ assertEquals(1, connection.getPrefetchPolicy().getQueueBrowserPrefetch());
+ assertEquals(1, connection.getPrefetchPolicy().getDurableTopicPrefetch());
+ }
+
+ @Test
+ public void testConnectionGetConfiguredURIApplied() throws Exception {
+ URI mock = new URI("mock://localhost");
+
+ JmsConnectionFactory factory = new JmsConnectionFactory(mock);
+
+ JmsConnection connection = (JmsConnection) factory.createConnection();
+ assertEquals(mock, connection.getConfiguredURI());
+ connection.start();
+ assertEquals(mock, connection.getConnectedURI());
+ }
+
+ @Test
+ public void testGlobalExceptionListenerIsAppliedToCreatedConnection() throws Exception {
+ JmsConnectionFactory factory = new JmsConnectionFactory(new URI("mock://127.0.0.1:5763"));
+
+ ExceptionListener listener = new ExceptionListener() {
+
+ @Override
+ public void onException(JMSException exception) {
+ }
+ };
+
+ factory.setExceptionListener(listener);
+ Connection connection = factory.createConnection();
+ assertNotNull(connection);
+ assertNotNull(connection.getExceptionListener());
+ assertSame(listener, connection.getExceptionListener());
+ }
+
+ @Test
public void testCreateConnectionBadProviderURI() throws Exception {
JmsConnectionFactory factory = new JmsConnectionFactory(new URI("bad://127.0.0.1:5763"));
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/e5ed52ec/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
index a2058c7..231a8de 100644
--- 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
@@ -18,16 +18,23 @@ 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.assertNotSame;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.IOException;
import java.net.URI;
+import javax.jms.ExceptionListener;
import javax.jms.IllegalStateException;
import javax.jms.InvalidClientIDException;
import javax.jms.JMSException;
import javax.jms.Session;
+import javax.jms.TemporaryQueue;
+import javax.jms.TemporaryTopic;
import org.apache.qpid.jms.message.JmsInboundMessageDispatch;
import org.apache.qpid.jms.provider.mock.MockProvider;
@@ -59,13 +66,13 @@ public class JmsConnectionTest {
}
}
- @Test(expected=JMSException.class)
+ @Test(timeout=30000, expected=JMSException.class)
public void testJmsConnectionThrowsJMSExceptionProviderStartFails() throws JMSException, IllegalStateException, IOException {
provider.getConfiguration().setFailOnStart(true);
new JmsConnection("ID:TEST:1", provider, clientIdGenerator);
}
- @Test
+ @Test(timeout=30000)
public void testStateAfterCreate() throws JMSException {
connection = new JmsConnection("ID:TEST:1", provider, clientIdGenerator);
@@ -74,13 +81,40 @@ public class JmsConnectionTest {
assertFalse(connection.isConnected());
}
- @Test
+ @Test(timeout=30000)
+ public void testGetExceptionListener() throws JMSException {
+ connection = new JmsConnection("ID:TEST:1", provider, clientIdGenerator);
+
+ assertNull(connection.getExceptionListener());
+ connection.setExceptionListener(new ExceptionListener() {
+
+ @Override
+ public void onException(JMSException exception) {
+ }
+ });
+
+ assertNotNull(connection.getExceptionListener());
+ }
+
+ @Test(timeout=30000)
+ public void testReplacePrefetchPolicy() throws JMSException {
+ connection = new JmsConnection("ID:TEST:1", provider, clientIdGenerator);
+
+ JmsPrefetchPolicy newPolicy = new JmsPrefetchPolicy();
+ newPolicy.setAll(1);
+
+ assertNotSame(newPolicy, connection.getPrefetchPolicy());
+ connection.setPrefetchPolicy(newPolicy);
+ assertSame(newPolicy, connection.getPrefetchPolicy());
+ }
+
+ @Test(timeout=30000)
public void testGetConnectionId() throws JMSException {
connection = new JmsConnection("ID:TEST:1", provider, clientIdGenerator);
assertEquals("ID:TEST:1", connection.getConnectionId().toString());
}
- @Test
+ @Test(timeout=30000)
public void testAddConnectionListener() throws JMSException {
connection = new JmsConnection("ID:TEST:1", provider, clientIdGenerator);
JmsConnectionListener listener = new JmsConnectionListener() {
@@ -111,7 +145,7 @@ public class JmsConnectionTest {
assertTrue(connection.removeConnectionListener(listener));
}
- @Test
+ @Test(timeout=30000)
public void testConnectionStart() throws JMSException, IOException {
connection = new JmsConnection("ID:TEST:1", provider, clientIdGenerator);
@@ -120,7 +154,18 @@ public class JmsConnectionTest {
assertTrue(connection.isConnected());
}
- @Test
+ @Test(timeout=30000)
+ public void testConnectionMulitpleStartCalls() throws JMSException, IOException {
+ connection = new JmsConnection("ID:TEST:1", provider, clientIdGenerator);
+
+ assertFalse(connection.isConnected());
+ connection.start();
+ assertTrue(connection.isConnected());
+ connection.start();
+ assertTrue(connection.isConnected());
+ }
+
+ @Test(timeout=30000)
public void testConnectionStartAndStop() throws JMSException, IOException {
connection = new JmsConnection("ID:TEST:1", provider, clientIdGenerator);
@@ -189,6 +234,40 @@ public class JmsConnectionTest {
connection.setClientID("TEST-ID");
}
+ @Test(timeout=30000)
+ public void testDeleteOfTempQueueOnClosedConnection() throws JMSException, IOException {
+ connection = new JmsConnection("ID:TEST:1", provider, clientIdGenerator);
+ connection.start();
+
+ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ TemporaryQueue tempQueue = session.createTemporaryQueue();
+ assertNotNull(tempQueue);
+
+ connection.close();
+ try {
+ tempQueue.delete();
+ fail("Should have thrown an IllegalStateException");
+ } catch (IllegalStateException ex) {
+ }
+ }
+
+ @Test(timeout=30000)
+ public void testDeleteOfTempTopicOnClosedConnection() throws JMSException, IOException {
+ connection = new JmsConnection("ID:TEST:1", provider, clientIdGenerator);
+ connection.start();
+
+ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ TemporaryTopic tempTopic = session.createTemporaryTopic();
+ assertNotNull(tempTopic);
+
+ connection.close();
+ try {
+ tempTopic.delete();
+ fail("Should have thrown an IllegalStateException");
+ } catch (IllegalStateException ex) {
+ }
+ }
+
//----- Currently these are unimplemented, these will fail after that ----//
@Test(timeout=30000, expected=JMSException.class)
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/e5ed52ec/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/mock/MockProvider.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/mock/MockProvider.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/mock/MockProvider.java
index 90146d7..3d32509 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/mock/MockProvider.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/mock/MockProvider.java
@@ -452,7 +452,7 @@ public class MockProvider implements Provider {
this.connectTimeout = connectTimeout;
}
- //----- Implementation deatils -------------------------------------------//
+ //----- Implementation details -------------------------------------------//
private void checkClosed() throws ProviderClosedException {
if (closed.get()) {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org