add tests for destination objects, including some around serialization
Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/aecd39ef Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/aecd39ef Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/aecd39ef Branch: refs/heads/master Commit: aecd39efcbf37e9d03d051a6f6981d83af5dc992 Parents: 41c040a Author: Robert Gemmell <[email protected]> Authored: Fri Jan 23 15:47:21 2015 +0000 Committer: Robert Gemmell <[email protected]> Committed: Fri Jan 23 17:39:01 2015 +0000 ---------------------------------------------------------------------- .../java/org/apache/qpid/jms/JmsQueueTest.java | 134 +++++++++++++++++ .../apache/qpid/jms/JmsTemporaryQueueTest.java | 142 +++++++++++++++++++ .../apache/qpid/jms/JmsTemporaryTopicTest.java | 142 +++++++++++++++++++ .../java/org/apache/qpid/jms/JmsTopicTest.java | 134 +++++++++++++++++ .../qpid/jms/SerializationTestSupport.java | 52 +++++++ 5 files changed, 604 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/aecd39ef/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsQueueTest.java ---------------------------------------------------------------------- diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsQueueTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsQueueTest.java new file mode 100644 index 0000000..9ba6b3d --- /dev/null +++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsQueueTest.java @@ -0,0 +1,134 @@ +/* + * 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.*; +import static org.apache.qpid.jms.SerializationTestSupport.roundTripSerializeDestination; +import static org.apache.qpid.jms.SerializationTestSupport.serializeDestination; + +import javax.jms.Destination; + +import org.apache.qpid.jms.test.QpidJmsTestCase; +import org.junit.Test; + +public class JmsQueueTest extends QpidJmsTestCase { + + @Test + public void testIsQueue() { + JmsQueue queue = new JmsQueue("myQueue"); + assertTrue("should be a queue", queue.isQueue()); + } + + @Test + public void testIsTopic() { + JmsQueue queue = new JmsQueue("myQueue"); + assertFalse("should not be a topic", queue.isTopic()); + } + + @Test + public void testIsTemporary() { + JmsQueue queue = new JmsQueue("myQueue"); + assertFalse("should not be temporary", queue.isTemporary()); + } + + @Test + public void testEqualsWithNull() { + JmsQueue queue = new JmsQueue("myQueue"); + assertFalse("should not be equal", queue.equals(null)); + } + + @Test + public void testEqualsWithDifferentObjectType() { + JmsQueue queue = new JmsQueue("name"); + JmsTopic otherObject = new JmsTopic("name"); + assertFalse("should not be equal", queue.equals(otherObject)); + } + + @Test + public void testEqualsWithSameObject() { + JmsQueue queue = new JmsQueue("name"); + assertTrue("should be equal to itself", queue.equals(queue)); + } + + @Test + public void testEqualsWithDifferentObject() { + JmsQueue queue1 = new JmsQueue("name"); + JmsQueue queue2 = new JmsQueue("name"); + assertTrue("should be equal", queue1.equals(queue2)); + assertTrue("should still be equal", queue2.equals(queue1)); + } + + @Test + public void testHashcodeWithEqualNamedObjects() { + JmsQueue queue1 = new JmsQueue("name"); + JmsQueue queue2 = new JmsQueue("name"); + assertEquals("should have same hashcode", queue1.hashCode(), queue2.hashCode()); + } + + @Test + public void testHashcodeWithDifferentNamedObjects() { + JmsQueue queue1 = new JmsQueue("name1"); + JmsQueue queue2 = new JmsQueue("name2"); + + // Not strictly a requirement, but expected in this case + assertNotEquals("should not have same hashcode", queue1.hashCode(), queue2.hashCode()); + } + + @Test + public void testSerializeThenDeserialize() throws Exception { + String name = "myQueue"; + JmsQueue queue = new JmsQueue(name); + + Destination roundTripped = roundTripSerializeDestination(queue); + + assertNotNull("Null destination returned", roundTripped); + assertEquals("Unexpected type", JmsQueue.class, roundTripped.getClass()); + assertEquals("Unexpected name", name, ((JmsQueue)roundTripped).getQueueName()); + assertEquals("Objects were not equal", queue, roundTripped); + } + + @Test + public void testSerializeTwoEqualDestinations() throws Exception { + JmsQueue queue1 = new JmsQueue("myQueue"); + JmsQueue queue2 = new JmsQueue("myQueue"); + + assertEquals("Destinations were not equal", queue1, queue2); + + byte[] bytes1 = serializeDestination(queue1); + byte[] bytes2 = serializeDestination(queue2); + + assertArrayEquals("Serialized bytes were not equal", bytes1, bytes2); + } + + @Test + public void testSerializeTwoDifferentDestinations() throws Exception { + JmsQueue queue1 = new JmsQueue("myQueue1"); + JmsQueue queue2 = new JmsQueue("myQueue2"); + + assertNotEquals("Destinations were not expected to be equal", queue1, queue2); + + byte[] bytes1 = serializeDestination(queue1); + byte[] bytes2 = serializeDestination(queue2); + + try { + assertArrayEquals(bytes1, bytes2); + fail("Expected arrays to differ"); + } catch (AssertionError ae) { + // Expected, pass + } + } +} http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/aecd39ef/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsTemporaryQueueTest.java ---------------------------------------------------------------------- diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsTemporaryQueueTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsTemporaryQueueTest.java new file mode 100644 index 0000000..1368f69 --- /dev/null +++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsTemporaryQueueTest.java @@ -0,0 +1,142 @@ +/* + * 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.*; +import static org.apache.qpid.jms.SerializationTestSupport.roundTripSerializeDestination; +import static org.apache.qpid.jms.SerializationTestSupport.serializeDestination; + +import javax.jms.Destination; + +import org.apache.qpid.jms.test.QpidJmsTestCase; +import org.junit.Test; + +public class JmsTemporaryQueueTest extends QpidJmsTestCase { + + @Test + public void testIsQueue() { + JmsTemporaryQueue queue = new JmsTemporaryQueue("myQueue"); + assertTrue("should be a queue", queue.isQueue()); + } + + @Test + public void testIsTopic() { + JmsTemporaryQueue queue = new JmsTemporaryQueue("myQueue"); + assertFalse("should not be a topic", queue.isTopic()); + } + + @Test + public void testIsTemporary() { + JmsTemporaryQueue queue = new JmsTemporaryQueue("myQueue"); + assertTrue("should be temporary", queue.isTemporary()); + } + + @Test + public void testIsDeleted() throws Exception { + JmsTemporaryQueue queue = new JmsTemporaryQueue("myQueue"); + assertFalse("should not be deleted", queue.isDeleted()); + queue.delete(); + assertTrue("should be deleted", queue.isDeleted()); + } + + @Test + public void testEqualsWithNull() { + JmsTemporaryQueue queue = new JmsTemporaryQueue("myQueue"); + assertFalse("should not be equal", queue.equals(null)); + } + + @Test + public void testEqualsWithDifferentObjectType() { + JmsTemporaryQueue queue = new JmsTemporaryQueue("name"); + JmsQueue otherObject = new JmsQueue("name"); + assertFalse("should not be equal", queue.equals(otherObject)); + } + + @Test + public void testEqualsWithSameObject() { + JmsTemporaryQueue queue = new JmsTemporaryQueue("name"); + assertTrue("should be equal to itself", queue.equals(queue)); + } + + @Test + public void testEqualsWithDifferentObject() { + JmsTemporaryQueue queue1 = new JmsTemporaryQueue("name"); + JmsTemporaryQueue queue2 = new JmsTemporaryQueue("name"); + assertTrue("should be equal", queue1.equals(queue2)); + assertTrue("should still be equal", queue2.equals(queue1)); + } + + @Test + public void testHashcodeWithEqualNamedObjects() { + JmsTemporaryQueue queue1 = new JmsTemporaryQueue("name"); + JmsTemporaryQueue queue2 = new JmsTemporaryQueue("name"); + assertEquals("should have same hashcode", queue1.hashCode(), queue2.hashCode()); + } + + @Test + public void testHashcodeWithDifferentNamedObjects() { + JmsTemporaryQueue queue1 = new JmsTemporaryQueue("name1"); + JmsTemporaryQueue queue2 = new JmsTemporaryQueue("name2"); + + // Not strictly a requirement, but expected in this case + assertNotEquals("should not have same hashcode", queue1.hashCode(), queue2.hashCode()); + } + + @Test + public void testSerializeThenDeserialize() throws Exception { + String name = "myQueue"; + JmsTemporaryQueue queue = new JmsTemporaryQueue(name); + + Destination roundTripped = roundTripSerializeDestination(queue); + + assertNotNull("Null destination returned", roundTripped); + assertEquals("Unexpected type", JmsTemporaryQueue.class, roundTripped.getClass()); + assertEquals("Unexpected name", name, ((JmsTemporaryQueue)roundTripped).getQueueName()); + assertEquals("Objects were not equal", queue, roundTripped); + } + + @Test + public void testSerializeTwoEqualDestinations() throws Exception { + JmsTemporaryQueue queue1 = new JmsTemporaryQueue("myQueue"); + JmsTemporaryQueue queue2 = new JmsTemporaryQueue("myQueue"); + + assertEquals("Destinations were not equal", queue1, queue2); + + byte[] bytes1 = serializeDestination(queue1); + byte[] bytes2 = serializeDestination(queue2); + + assertArrayEquals("Serialized bytes were not equal", bytes1, bytes2); + } + + @Test + public void testSerializeTwoDifferentDestinations() throws Exception { + JmsTemporaryQueue queue1 = new JmsTemporaryQueue("myQueue1"); + JmsTemporaryQueue queue2 = new JmsTemporaryQueue("myQueue2"); + + assertNotEquals("Destinations were not expected to be equal", queue1, queue2); + + byte[] bytes1 = serializeDestination(queue1); + byte[] bytes2 = serializeDestination(queue2); + + try { + assertArrayEquals(bytes1, bytes2); + fail("Expected arrays to differ"); + } catch (AssertionError ae) { + // Expected, pass + } + } +} http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/aecd39ef/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsTemporaryTopicTest.java ---------------------------------------------------------------------- diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsTemporaryTopicTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsTemporaryTopicTest.java new file mode 100644 index 0000000..b28068b --- /dev/null +++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsTemporaryTopicTest.java @@ -0,0 +1,142 @@ +/* + * 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.*; +import static org.apache.qpid.jms.SerializationTestSupport.roundTripSerializeDestination; +import static org.apache.qpid.jms.SerializationTestSupport.serializeDestination; + +import javax.jms.Destination; + +import org.apache.qpid.jms.test.QpidJmsTestCase; +import org.junit.Test; + +public class JmsTemporaryTopicTest extends QpidJmsTestCase { + + @Test + public void testIsQueue() { + JmsTemporaryTopic topic = new JmsTemporaryTopic("myTopic"); + assertFalse("should not be a queue", topic.isQueue()); + } + + @Test + public void testIsTopic() { + JmsTemporaryTopic topic = new JmsTemporaryTopic("myTopic"); + assertTrue("should be a topic", topic.isTopic()); + } + + @Test + public void testIsTemporary() { + JmsTemporaryTopic topic = new JmsTemporaryTopic("myTopic"); + assertTrue("should be temporary", topic.isTemporary()); + } + + @Test + public void testIsDeleted() throws Exception { + JmsTemporaryTopic topic = new JmsTemporaryTopic("myTopic"); + assertFalse("should not be deleted", topic.isDeleted()); + topic.delete(); + assertTrue("should be deleted", topic.isDeleted()); + } + + @Test + public void testEqualsWithNull() { + JmsTemporaryTopic topic = new JmsTemporaryTopic("myTopic"); + assertFalse("should not be equal", topic.equals(null)); + } + + @Test + public void testEqualsWithDifferentObjectType() { + JmsTemporaryTopic topic = new JmsTemporaryTopic("name"); + JmsQueue otherObject = new JmsQueue("name"); + assertFalse("should not be equal", topic.equals(otherObject)); + } + + @Test + public void testEqualsWithSameObject() { + JmsTemporaryTopic topic = new JmsTemporaryTopic("name"); + assertTrue("should be equal to itself", topic.equals(topic)); + } + + @Test + public void testEqualsWithDifferentObject() { + JmsTemporaryTopic topic1 = new JmsTemporaryTopic("name"); + JmsTemporaryTopic topic2 = new JmsTemporaryTopic("name"); + assertTrue("should be equal", topic1.equals(topic2)); + assertTrue("should still be equal", topic2.equals(topic1)); + } + + @Test + public void testHashcodeWithEqualNamedObjects() { + JmsTemporaryTopic topic1 = new JmsTemporaryTopic("name"); + JmsTemporaryTopic topic2 = new JmsTemporaryTopic("name"); + assertEquals("should have same hashcode", topic1.hashCode(), topic2.hashCode()); + } + + @Test + public void testHashcodeWithDifferentNamedObjects() { + JmsTemporaryTopic topic1 = new JmsTemporaryTopic("name1"); + JmsTemporaryTopic topic2 = new JmsTemporaryTopic("name2"); + + // Not strictly a requirement, but expected in this case + assertNotEquals("should not have same hashcode", topic1.hashCode(), topic2.hashCode()); + } + + @Test + public void testSerializeThenDeserialize() throws Exception { + String name = "myTopic"; + JmsTemporaryTopic topic = new JmsTemporaryTopic(name); + + Destination roundTripped = roundTripSerializeDestination(topic); + + assertNotNull("Null destination returned", roundTripped); + assertEquals("Unexpected type", JmsTemporaryTopic.class, roundTripped.getClass()); + assertEquals("Unexpected name", name, ((JmsTemporaryTopic)roundTripped).getTopicName()); + assertEquals("Objects were not equal", topic, roundTripped); + } + + @Test + public void testSerializeTwoEqualDestinations() throws Exception { + JmsTemporaryTopic topic1 = new JmsTemporaryTopic("myTopic"); + JmsTemporaryTopic topic2 = new JmsTemporaryTopic("myTopic"); + + assertEquals("Destinations were not equal", topic1, topic2); + + byte[] bytes1 = serializeDestination(topic1); + byte[] bytes2 = serializeDestination(topic2); + + assertArrayEquals("Serialized bytes were not equal", bytes1, bytes2); + } + + @Test + public void testSerializeTwoDifferentDestinations() throws Exception { + JmsTemporaryTopic topic1 = new JmsTemporaryTopic("myTopic1"); + JmsTemporaryTopic topic2 = new JmsTemporaryTopic("myTopic2"); + + assertNotEquals("Destinations were not expected to be equal", topic1, topic2); + + byte[] bytes1 = serializeDestination(topic1); + byte[] bytes2 = serializeDestination(topic2); + + try { + assertArrayEquals(bytes1, bytes2); + fail("Expected arrays to differ"); + } catch (AssertionError ae) { + // Expected, pass + } + } +} http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/aecd39ef/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsTopicTest.java ---------------------------------------------------------------------- diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsTopicTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsTopicTest.java new file mode 100644 index 0000000..c2556b4 --- /dev/null +++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsTopicTest.java @@ -0,0 +1,134 @@ +/* + * 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.*; +import static org.apache.qpid.jms.SerializationTestSupport.roundTripSerializeDestination; +import static org.apache.qpid.jms.SerializationTestSupport.serializeDestination; + +import javax.jms.Destination; + +import org.apache.qpid.jms.test.QpidJmsTestCase; +import org.junit.Test; + +public class JmsTopicTest extends QpidJmsTestCase { + + @Test + public void testIsQueue() { + JmsTopic topic = new JmsTopic("myTopic"); + assertFalse("should not be a queue", topic.isQueue()); + } + + @Test + public void testIsTopic() { + JmsTopic topic = new JmsTopic("myTopic"); + assertTrue("should be a topic", topic.isTopic()); + } + + @Test + public void testIsTemporary() { + JmsTopic topic = new JmsTopic("myTopic"); + assertFalse("should not be temporary", topic.isTemporary()); + } + + @Test + public void testEqualsWithNull() { + JmsTopic topic = new JmsTopic("myTopic"); + assertFalse("should not be equal", topic.equals(null)); + } + + @Test + public void testEqualsWithDifferentObjectType() { + JmsTopic topic = new JmsTopic("name"); + JmsQueue otherObject = new JmsQueue("name"); + assertFalse("should not be equal", topic.equals(otherObject)); + } + + @Test + public void testEqualsWithSameObject() { + JmsTopic topic = new JmsTopic("name"); + assertTrue("should be equal to itself", topic.equals(topic)); + } + + @Test + public void testEqualsWithDifferentObject() { + JmsTopic topic1 = new JmsTopic("name"); + JmsTopic topic2 = new JmsTopic("name"); + assertTrue("should be equal", topic1.equals(topic2)); + assertTrue("should still be equal", topic2.equals(topic1)); + } + + @Test + public void testHashcodeWithEqualNamedObjects() { + JmsTopic topic1 = new JmsTopic("name"); + JmsTopic topic2 = new JmsTopic("name"); + assertEquals("should have same hashcode", topic1.hashCode(), topic2.hashCode()); + } + + @Test + public void testHashcodeWithDifferentNamedObjects() { + JmsTopic topic1 = new JmsTopic("name1"); + JmsTopic topic2 = new JmsTopic("name2"); + + // Not strictly a requirement, but expected in this case + assertNotEquals("should not have same hashcode", topic1.hashCode(), topic2.hashCode()); + } + + @Test + public void testSerializeThenDeserialize() throws Exception { + String name = "myTopic"; + JmsTopic topic = new JmsTopic(name); + + Destination roundTripped = roundTripSerializeDestination(topic); + + assertNotNull("Null destination returned", roundTripped); + assertEquals("Unexpected type", JmsTopic.class, roundTripped.getClass()); + assertEquals("Unexpected name", name, ((JmsTopic)roundTripped).getTopicName()); + assertEquals("Objects were not equal", topic, roundTripped); + } + + @Test + public void testSerializeTwoEqualDestinations() throws Exception { + JmsTopic topic1 = new JmsTopic("myTopic"); + JmsTopic topic2 = new JmsTopic("myTopic"); + + assertEquals("Destinations were not equal", topic1, topic2); + + byte[] bytes1 = serializeDestination(topic1); + byte[] bytes2 = serializeDestination(topic2); + + assertArrayEquals("Serialized bytes were not equal", bytes1, bytes2); + } + + @Test + public void testSerializeTwoDifferentDestinations() throws Exception { + JmsTopic topic1 = new JmsTopic("myTopic1"); + JmsTopic topic2 = new JmsTopic("myTopic2"); + + assertNotEquals("Destinations were not expected to be equal", topic1, topic2); + + byte[] bytes1 = serializeDestination(topic1); + byte[] bytes2 = serializeDestination(topic2); + + try { + assertArrayEquals(bytes1, bytes2); + fail("Expected arrays to differ"); + } catch (AssertionError ae) { + // Expected, pass + } + } +} http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/aecd39ef/qpid-jms-client/src/test/java/org/apache/qpid/jms/SerializationTestSupport.java ---------------------------------------------------------------------- diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/SerializationTestSupport.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/SerializationTestSupport.java new file mode 100644 index 0000000..a4cef4c --- /dev/null +++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/SerializationTestSupport.java @@ -0,0 +1,52 @@ +/** + * 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 java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; + +import javax.jms.Destination; + +public class SerializationTestSupport { + + public static Destination roundTripSerializeDestination(final JmsDestination dest) throws IOException, ClassNotFoundException { + byte[] bytes = serializeDestination(dest); + Object deserializedObject = deserializeDestination(bytes); + + return (Destination) deserializedObject; + } + + public static byte[] serializeDestination(final JmsDestination dest) throws IOException { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(bos); + oos.writeObject(dest); + oos.close(); + byte[] bytes = bos.toByteArray(); + return bytes; + } + + public static Object deserializeDestination(byte[] bytes) throws IOException, ClassNotFoundException { + ByteArrayInputStream bis = new ByteArrayInputStream(bytes); + ObjectInputStream ois = new ObjectInputStream(bis); + Object deserializedObject = ois.readObject(); + ois.close(); + return deserializedObject; + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
