add test for destination property population
Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/98447a5b Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/98447a5b Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/98447a5b Branch: refs/heads/master Commit: 98447a5baa3ffc1f90f07a3e4223d6f14fae1710 Parents: aecd39e Author: Robert Gemmell <[email protected]> Authored: Fri Jan 23 16:00:03 2015 +0000 Committer: Robert Gemmell <[email protected]> Committed: Fri Jan 23 17:39:01 2015 +0000 ---------------------------------------------------------------------- .../org/apache/qpid/jms/JmsDestination.java | 16 ++++++---- .../java/org/apache/qpid/jms/JmsQueueTest.java | 31 +++++++++++++++++++- .../apache/qpid/jms/JmsTemporaryQueueTest.java | 31 +++++++++++++++++++- .../apache/qpid/jms/JmsTemporaryTopicTest.java | 31 +++++++++++++++++++- .../java/org/apache/qpid/jms/JmsTopicTest.java | 31 +++++++++++++++++++- 5 files changed, 130 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/98447a5b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsDestination.java ---------------------------------------------------------------------- diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsDestination.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsDestination.java index 4471267..57c7d64 100644 --- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsDestination.java +++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsDestination.java @@ -29,6 +29,10 @@ import org.apache.qpid.jms.jndi.JNDIStorable; */ public abstract class JmsDestination extends JNDIStorable implements Externalizable, javax.jms.Destination, Comparable<JmsDestination> { + protected static final String TEMPORARY_PROP = "temporary"; + protected static final String TOPIC_PROP = "topic"; + protected static final String NAME_PROP = "name"; + protected transient String name; protected transient boolean topic; protected transient boolean temporary; @@ -85,10 +89,10 @@ public abstract class JmsDestination extends JNDIStorable implements Externaliza */ @Override protected void buildFromProperties(Map<String, String> props) { - setName(getProperty(props, "name", "")); - Boolean bool = Boolean.valueOf(getProperty(props, "topic", Boolean.TRUE.toString())); + setName(getProperty(props, NAME_PROP, "")); + Boolean bool = Boolean.valueOf(getProperty(props, TOPIC_PROP, Boolean.TRUE.toString())); this.topic = bool.booleanValue(); - bool = Boolean.valueOf(getProperty(props, "temporary", Boolean.FALSE.toString())); + bool = Boolean.valueOf(getProperty(props, TEMPORARY_PROP, Boolean.FALSE.toString())); this.temporary = bool.booleanValue(); } @@ -97,9 +101,9 @@ public abstract class JmsDestination extends JNDIStorable implements Externaliza */ @Override protected void populateProperties(Map<String, String> props) { - props.put("name", getName()); - props.put("topic", Boolean.toString(isTopic())); - props.put("temporary", Boolean.toString(isTemporary())); + props.put(NAME_PROP, getName()); + props.put(TOPIC_PROP, Boolean.toString(isTopic())); + props.put(TEMPORARY_PROP, Boolean.toString(isTemporary())); } /** http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/98447a5b/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 index 9ba6b3d..7f3a338 100644 --- 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 @@ -16,9 +16,21 @@ */ package org.apache.qpid.jms; -import static org.junit.Assert.*; +import static org.apache.qpid.jms.JmsDestination.NAME_PROP; +import static org.apache.qpid.jms.JmsDestination.TEMPORARY_PROP; +import static org.apache.qpid.jms.JmsDestination.TOPIC_PROP; import static org.apache.qpid.jms.SerializationTestSupport.roundTripSerializeDestination; import static org.apache.qpid.jms.SerializationTestSupport.serializeDestination; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.util.HashMap; +import java.util.Map; import javax.jms.Destination; @@ -89,6 +101,23 @@ public class JmsQueueTest extends QpidJmsTestCase { } @Test + public void testPopulateProperties() throws Exception { + String name = "myQueue"; + JmsQueue queue = new JmsQueue(name); + + Map<String, String> props = new HashMap<String, String>(); + queue.populateProperties(props); + + assertTrue("Property not found: " + TEMPORARY_PROP, props.containsKey(TEMPORARY_PROP)); + assertEquals("Unexpected value for property: " + TEMPORARY_PROP, "false", props.get(TEMPORARY_PROP)); + assertTrue("Property not found: " + NAME_PROP, props.containsKey(NAME_PROP)); + assertEquals("Unexpected value for property: " + NAME_PROP, name, props.get(NAME_PROP)); + assertTrue("Property not found: " + TOPIC_PROP, props.containsKey(TOPIC_PROP)); + assertEquals("Unexpected value for property: " + TOPIC_PROP, "false", props.get(TOPIC_PROP)); + assertEquals("Unexpected number of properties", 3, props.size()); + } + + @Test public void testSerializeThenDeserialize() throws Exception { String name = "myQueue"; JmsQueue queue = new JmsQueue(name); http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/98447a5b/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 index 1368f69..cc9a145 100644 --- 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 @@ -16,9 +16,21 @@ */ package org.apache.qpid.jms; -import static org.junit.Assert.*; +import static org.apache.qpid.jms.JmsDestination.NAME_PROP; +import static org.apache.qpid.jms.JmsDestination.TEMPORARY_PROP; +import static org.apache.qpid.jms.JmsDestination.TOPIC_PROP; import static org.apache.qpid.jms.SerializationTestSupport.roundTripSerializeDestination; import static org.apache.qpid.jms.SerializationTestSupport.serializeDestination; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.util.HashMap; +import java.util.Map; import javax.jms.Destination; @@ -97,6 +109,23 @@ public class JmsTemporaryQueueTest extends QpidJmsTestCase { } @Test + public void testPopulateProperties() throws Exception { + String name = "myQueue"; + JmsTemporaryQueue queue = new JmsTemporaryQueue(name); + + Map<String, String> props = new HashMap<String, String>(); + queue.populateProperties(props); + + assertTrue("Property not found: " + TEMPORARY_PROP, props.containsKey(TEMPORARY_PROP)); + assertEquals("Unexpected value for property: " + TEMPORARY_PROP, "true", props.get(TEMPORARY_PROP)); + assertTrue("Property not found: " + NAME_PROP, props.containsKey(NAME_PROP)); + assertEquals("Unexpected value for property: " + NAME_PROP, name, props.get(NAME_PROP)); + assertTrue("Property not found: " + TOPIC_PROP, props.containsKey(TOPIC_PROP)); + assertEquals("Unexpected value for property: " + TOPIC_PROP, "false", props.get(TOPIC_PROP)); + assertEquals("Unexpected number of properties", 3, props.size()); + } + + @Test public void testSerializeThenDeserialize() throws Exception { String name = "myQueue"; JmsTemporaryQueue queue = new JmsTemporaryQueue(name); http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/98447a5b/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 index b28068b..714dd32 100644 --- 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 @@ -16,9 +16,21 @@ */ package org.apache.qpid.jms; -import static org.junit.Assert.*; +import static org.apache.qpid.jms.JmsDestination.NAME_PROP; +import static org.apache.qpid.jms.JmsDestination.TEMPORARY_PROP; +import static org.apache.qpid.jms.JmsDestination.TOPIC_PROP; import static org.apache.qpid.jms.SerializationTestSupport.roundTripSerializeDestination; import static org.apache.qpid.jms.SerializationTestSupport.serializeDestination; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.util.HashMap; +import java.util.Map; import javax.jms.Destination; @@ -97,6 +109,23 @@ public class JmsTemporaryTopicTest extends QpidJmsTestCase { } @Test + public void testPopulateProperties() throws Exception { + String name = "myTopic"; + JmsTemporaryTopic topic = new JmsTemporaryTopic(name); + + Map<String, String> props = new HashMap<String, String>(); + topic.populateProperties(props); + + assertTrue("Property not found: " + TEMPORARY_PROP, props.containsKey(TEMPORARY_PROP)); + assertEquals("Unexpected value for property: " + TEMPORARY_PROP, "true", props.get(TEMPORARY_PROP)); + assertTrue("Property not found: " + NAME_PROP, props.containsKey(NAME_PROP)); + assertEquals("Unexpected value for property: " + NAME_PROP, name, props.get(NAME_PROP)); + assertTrue("Property not found: " + TOPIC_PROP, props.containsKey(TOPIC_PROP)); + assertEquals("Unexpected value for property: " + TOPIC_PROP, "true", props.get(TOPIC_PROP)); + assertEquals("Unexpected number of properties", 3, props.size()); + } + + @Test public void testSerializeThenDeserialize() throws Exception { String name = "myTopic"; JmsTemporaryTopic topic = new JmsTemporaryTopic(name); http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/98447a5b/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 index c2556b4..2d314f3 100644 --- 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 @@ -16,9 +16,21 @@ */ package org.apache.qpid.jms; -import static org.junit.Assert.*; +import static org.apache.qpid.jms.JmsDestination.NAME_PROP; +import static org.apache.qpid.jms.JmsDestination.TEMPORARY_PROP; +import static org.apache.qpid.jms.JmsDestination.TOPIC_PROP; import static org.apache.qpid.jms.SerializationTestSupport.roundTripSerializeDestination; import static org.apache.qpid.jms.SerializationTestSupport.serializeDestination; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.util.HashMap; +import java.util.Map; import javax.jms.Destination; @@ -89,6 +101,23 @@ public class JmsTopicTest extends QpidJmsTestCase { } @Test + public void testPopulateProperties() throws Exception { + String name = "myTopic"; + JmsTopic topic = new JmsTopic(name); + + Map<String, String> props = new HashMap<String, String>(); + topic.populateProperties(props); + + assertTrue("Property not found: " + TEMPORARY_PROP, props.containsKey(TEMPORARY_PROP)); + assertEquals("Unexpected value for property: " + TEMPORARY_PROP, "false", props.get(TEMPORARY_PROP)); + assertTrue("Property not found: " + NAME_PROP, props.containsKey(NAME_PROP)); + assertEquals("Unexpected value for property: " + NAME_PROP, name, props.get(NAME_PROP)); + assertTrue("Property not found: " + TOPIC_PROP, props.containsKey(TOPIC_PROP)); + assertEquals("Unexpected value for property: " + TOPIC_PROP, "true", props.get(TOPIC_PROP)); + assertEquals("Unexpected number of properties", 3, props.size()); + } + + @Test public void testSerializeThenDeserialize() throws Exception { String name = "myTopic"; JmsTopic topic = new JmsTopic(name); --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
