summaryrefslogtreecommitdiff
path: root/qpid/java/client/src/test
diff options
context:
space:
mode:
authorKeith Wall <kwall@apache.org>2014-07-20 14:39:35 +0000
committerKeith Wall <kwall@apache.org>2014-07-20 14:39:35 +0000
commitd9653e77fa93275cb9782581796d0a3bcf39b569 (patch)
treeb2e2387c3c7c5420d29f29dc1220a7f201c83512 /qpid/java/client/src/test
parentcd126b93a9ec0b3891e19a2b3012e5ccc222cbbd (diff)
downloadqpid-python-d9653e77fa93275cb9782581796d0a3bcf39b569.tar.gz
QPID-2969: Make AMQConnectionFactory and AMQDestination (and subclasses) serializable
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1612097 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/client/src/test')
-rw-r--r--qpid/java/client/src/test/java/org/apache/qpid/client/AMQConnectionFactoryTest.java27
-rw-r--r--qpid/java/client/src/test/java/org/apache/qpid/client/AMQDestinationTest.java73
-rw-r--r--qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/connectionurl/ConnectionURLTest.java30
3 files changed, 128 insertions, 2 deletions
diff --git a/qpid/java/client/src/test/java/org/apache/qpid/client/AMQConnectionFactoryTest.java b/qpid/java/client/src/test/java/org/apache/qpid/client/AMQConnectionFactoryTest.java
index bb92fa4ecd..6c6aa04ec1 100644
--- a/qpid/java/client/src/test/java/org/apache/qpid/client/AMQConnectionFactoryTest.java
+++ b/qpid/java/client/src/test/java/org/apache/qpid/client/AMQConnectionFactoryTest.java
@@ -20,6 +20,12 @@
*/
package org.apache.qpid.client;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+
import javax.jms.JMSException;
import junit.framework.TestCase;
@@ -76,4 +82,25 @@ public class AMQConnectionFactoryTest extends TestCase
assertEquals("Unexpected exception", AMQConnectionFactory.NO_URL_CONFIGURED, e.getMessage());
}
}
+
+ public void testSerialization() throws Exception
+ {
+ AMQConnectionFactory factory = new AMQConnectionFactory();
+ assertTrue(factory instanceof Serializable);
+ factory.setConnectionURLString("amqp://guest:guest@clientID/test?brokerlist='tcp://localhost:5672'");
+
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(bos);
+ oos.writeObject(factory);
+ oos.close();
+
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+ ObjectInputStream ois = new ObjectInputStream(bis);
+ Object deserializedObject = ois.readObject();
+ ois.close();
+
+ AMQConnectionFactory deserialisedFactory = (AMQConnectionFactory) deserializedObject;
+ assertEquals(factory, deserialisedFactory);
+ assertEquals(factory.hashCode(), deserialisedFactory.hashCode());
+ }
}
diff --git a/qpid/java/client/src/test/java/org/apache/qpid/client/AMQDestinationTest.java b/qpid/java/client/src/test/java/org/apache/qpid/client/AMQDestinationTest.java
index 6433c9acb7..a494192148 100644
--- a/qpid/java/client/src/test/java/org/apache/qpid/client/AMQDestinationTest.java
+++ b/qpid/java/client/src/test/java/org/apache/qpid/client/AMQDestinationTest.java
@@ -20,10 +20,19 @@
*/
package org.apache.qpid.client;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
+import javax.jms.Destination;
+import javax.jms.Queue;
+import javax.jms.Topic;
+
import junit.framework.TestCase;
public class AMQDestinationTest extends TestCase
@@ -132,11 +141,12 @@ public class AMQDestinationTest extends TestCase
assertEmptyLinkBindingsAndSubscriptionArgs(new AMQAnyDestination(xSubscribeAddr));
}
- private void assertEmptyLinkBindingsAndSubscriptionArgs(AMQDestination dest) {
+ private void assertEmptyLinkBindingsAndSubscriptionArgs(AMQDestination dest)
+ {
assertEquals("Default link subscription arguments should be the constant Collections empty map.",
Collections.emptyMap(), dest.getLink().getSubscription().getArgs());
assertSame("Defaultl link bindings should be the constant Collections empty list.",
- Collections.emptyList(), dest.getLink().getBindings());
+ Collections.emptyList(), dest.getLink().getBindings());
}
/**
@@ -152,10 +162,69 @@ public class AMQDestinationTest extends TestCase
assertEmptyNodeBindings(new AMQAnyDestination("ADDR:testDest3; {node: {type: topic}}"));
}
+ public void testSerializeAMQQueue_BURL() throws Exception
+ {
+ Queue queue = new AMQQueue("BURL:direct://amq.direct/test-route/Foo?routingkey='Foo'");
+ assertTrue(queue instanceof Serializable);
+
+ Queue deserialisedQueue = (Queue) serialiseDeserialiseDestination(queue);
+
+ assertEquals(queue, deserialisedQueue);
+ assertEquals(queue.hashCode(), deserialisedQueue.hashCode());
+ }
+
+ public void testSerializeAMQQueue_ADDR() throws Exception
+ {
+ Queue queue = new AMQQueue("ADDR:testDest2; {node: {type: queue}}");
+ assertTrue(queue instanceof Serializable);
+
+ Queue deserialisedQueue = (Queue) serialiseDeserialiseDestination(queue);
+
+ assertEquals(queue, deserialisedQueue);
+ assertEquals(queue.hashCode(), deserialisedQueue.hashCode());
+ }
+
+ public void testSerializeAMQTopic_BURL() throws Exception
+ {
+ Topic topic = new AMQTopic("BURL:topic://amq.topic/mytopic/?routingkey='mytopic'");
+ assertTrue(topic instanceof Serializable);
+
+ Topic deserialisedTopic = (Topic) serialiseDeserialiseDestination(topic);
+
+ assertEquals(topic, deserialisedTopic);
+ assertEquals(topic.hashCode(), deserialisedTopic.hashCode());
+ }
+
+ public void testSerializeAMQTopic_ADDR() throws Exception
+ {
+ Topic topic = new AMQTopic("ADDR:my-topic; {assert: always, node:{ type: topic }}");
+ assertTrue(topic instanceof Serializable);
+
+ Topic deserialisedTopic = (Topic) serialiseDeserialiseDestination(topic);
+
+ assertEquals(topic, deserialisedTopic);
+ assertEquals(topic.hashCode(), deserialisedTopic.hashCode());
+ }
+
private void assertEmptyNodeBindings(AMQDestination dest)
{
assertSame("Empty node bindings should refer to the constant Collections empty list.",
Collections.emptyList(), dest.getNode().getBindings());
}
+ private Destination serialiseDeserialiseDestination(final Destination dest) throws Exception
+ {
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(bos);
+ oos.writeObject(dest);
+ oos.close();
+
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+ ObjectInputStream ois = new ObjectInputStream(bis);
+ Object deserializedObject = ois.readObject();
+ ois.close();
+ return (Destination)deserializedObject;
+ }
+
+
}
diff --git a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/connectionurl/ConnectionURLTest.java b/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/connectionurl/ConnectionURLTest.java
index 7f2288ea3d..c14ea3a101 100644
--- a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/connectionurl/ConnectionURLTest.java
+++ b/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/connectionurl/ConnectionURLTest.java
@@ -20,6 +20,12 @@
*/
package org.apache.qpid.test.unit.client.connectionurl;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+
import junit.framework.TestCase;
import org.apache.qpid.client.AMQBrokerDetails;
@@ -620,5 +626,29 @@ public class ConnectionURLTest extends TestCase
assertFalse("value should be false", Boolean.valueOf(connectionURL.getOption(ConnectionURL.OPTIONS_VERIFY_QUEUE_ON_SEND)));
}
+
+ public void testSerialization() throws Exception
+ {
+ String url = "amqp://ritchiem:bob@/test?brokerlist='tcp://localhost:5672'";
+ ConnectionURL connectionurl = new AMQConnectionURL(url);
+
+
+ assertTrue(connectionurl instanceof Serializable);
+
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(bos);
+ oos.writeObject(connectionurl);
+ oos.close();
+
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+ ObjectInputStream ois = new ObjectInputStream(bis);
+ Object deserializedObject = ois.readObject();
+ ois.close();
+
+ ConnectionURL deserialisedConnectionUrl = (AMQConnectionURL) deserializedObject;
+ assertEquals(connectionurl, deserialisedConnectionUrl);
+ assertEquals(connectionurl.hashCode(), deserialisedConnectionUrl.hashCode());
+
+ }
}