You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2016/01/25 18:09:43 UTC
[1/3] activemq-artemis git commit: This closes #339
Repository: activemq-artemis
Updated Branches:
refs/heads/master 29ed1eae0 -> 094222bc7
This closes #339
Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/094222bc
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/094222bc
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/094222bc
Branch: refs/heads/master
Commit: 094222bc7338579d79a50c84a0defb74f3364bbf
Parents: 29ed1ea 3e783a1
Author: Clebert Suconic <cl...@apache.org>
Authored: Mon Jan 25 11:23:07 2016 -0500
Committer: Clebert Suconic <cl...@apache.org>
Committed: Mon Jan 25 11:23:07 2016 -0500
----------------------------------------------------------------------
.../activemq/artemis/utils/TypedProperties.java | 36 +--
.../artemis/utils/ConcurrentHashSetTest.java | 128 ++++++++
.../utils/TypedPropertiesConversionTest.java | 312 ++++++++++++++++++
.../artemis/utils/TypedPropertiesTest.java | 229 ++++++++++++++
.../artemis/util/ConcurrentHashSetTest.java | 131 --------
.../util/TypedPropertiesConversionTest.java | 314 -------------------
.../artemis/util/TypedPropertiesTest.java | 231 --------------
7 files changed, 679 insertions(+), 702 deletions(-)
----------------------------------------------------------------------
[2/3] activemq-artemis git commit: Include key name in property
conversion exception messages
Posted by cl...@apache.org.
Include key name in property conversion exception messages
Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/3e783a1c
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/3e783a1c
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/3e783a1c
Branch: refs/heads/master
Commit: 3e783a1c2f18394bdd99533b83c823b55c1cc3e6
Parents: ca34f7f
Author: Ville Skyttä <vi...@iki.fi>
Authored: Sun Jan 24 12:50:26 2016 +0200
Committer: Clebert Suconic <cl...@apache.org>
Committed: Mon Jan 25 11:23:07 2016 -0500
----------------------------------------------------------------------
.../activemq/artemis/utils/TypedProperties.java | 36 ++++++--------------
1 file changed, 10 insertions(+), 26 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/3e783a1c/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/TypedProperties.java
----------------------------------------------------------------------
diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/TypedProperties.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/TypedProperties.java
index 5bff66f..166f39e 100644
--- a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/TypedProperties.java
+++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/TypedProperties.java
@@ -161,9 +161,7 @@ public final class TypedProperties {
else if (value instanceof SimpleString) {
return Boolean.valueOf(((SimpleString) value).toString());
}
- else {
- throw new ActiveMQPropertyConversionException("Invalid conversion");
- }
+ throw new ActiveMQPropertyConversionException("Invalid conversion: " + key);
}
public Byte getByteProperty(final SimpleString key) throws ActiveMQPropertyConversionException {
@@ -177,23 +175,19 @@ public final class TypedProperties {
else if (value instanceof SimpleString) {
return Byte.parseByte(((SimpleString) value).toString());
}
- else {
- throw new ActiveMQPropertyConversionException("Invalid conversion");
- }
+ throw new ActiveMQPropertyConversionException("Invalid conversion: " + key);
}
public Character getCharProperty(final SimpleString key) throws ActiveMQPropertyConversionException {
Object value = doGetProperty(key);
if (value == null) {
- throw new NullPointerException("Invalid conversion");
+ throw new NullPointerException("Invalid conversion: " + key);
}
if (value instanceof Character) {
return ((Character) value);
}
- else {
- throw new ActiveMQPropertyConversionException("Invalid conversion");
- }
+ throw new ActiveMQPropertyConversionException("Invalid conversion: " + key);
}
public byte[] getBytesProperty(final SimpleString key) throws ActiveMQPropertyConversionException {
@@ -204,9 +198,7 @@ public final class TypedProperties {
else if (value instanceof byte[]) {
return (byte[]) value;
}
- else {
- throw new ActiveMQPropertyConversionException("Invalid conversion");
- }
+ throw new ActiveMQPropertyConversionException("Invalid conversion: " + key);
}
public Double getDoubleProperty(final SimpleString key) throws ActiveMQPropertyConversionException {
@@ -223,9 +215,7 @@ public final class TypedProperties {
else if (value instanceof SimpleString) {
return Double.parseDouble(((SimpleString) value).toString());
}
- else {
- throw new ActiveMQPropertyConversionException("Invalid conversion");
- }
+ throw new ActiveMQPropertyConversionException("Invalid conversion: " + key);
}
public Integer getIntProperty(final SimpleString key) throws ActiveMQPropertyConversionException {
@@ -245,9 +235,7 @@ public final class TypedProperties {
else if (value instanceof SimpleString) {
return Integer.parseInt(((SimpleString) value).toString());
}
- else {
- throw new ActiveMQPropertyConversionException("Invalid conversion");
- }
+ throw new ActiveMQPropertyConversionException("Invalid conversion: " + key);
}
public Long getLongProperty(final SimpleString key) throws ActiveMQPropertyConversionException {
@@ -270,9 +258,7 @@ public final class TypedProperties {
else if (value instanceof SimpleString) {
return Long.parseLong(((SimpleString) value).toString());
}
- else {
- throw new ActiveMQPropertyConversionException("Invalid conversion");
- }
+ throw new ActiveMQPropertyConversionException("Invalid conversion: " + key);
}
public Short getShortProperty(final SimpleString key) throws ActiveMQPropertyConversionException {
@@ -289,9 +275,7 @@ public final class TypedProperties {
else if (value instanceof SimpleString) {
return Short.parseShort(((SimpleString) value).toString());
}
- else {
- throw new ActiveMQPropertyConversionException("Invalid Conversion.");
- }
+ throw new ActiveMQPropertyConversionException("Invalid conversion: " + key);
}
public Float getFloatProperty(final SimpleString key) throws ActiveMQPropertyConversionException {
@@ -341,7 +325,7 @@ public final class TypedProperties {
else if (value instanceof Double) {
return new SimpleString(value.toString());
}
- throw new ActiveMQPropertyConversionException("Invalid conversion");
+ throw new ActiveMQPropertyConversionException("Invalid conversion: " + key);
}
public Object removeProperty(final SimpleString key) {
[3/3] activemq-artemis git commit: Move commons util tests to commons
Posted by cl...@apache.org.
Move commons util tests to commons
Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/ca34f7fb
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/ca34f7fb
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/ca34f7fb
Branch: refs/heads/master
Commit: ca34f7fbb2eee3e171825d2d86fb860cb1ad9400
Parents: 29ed1ea
Author: Ville Skyttä <vi...@iki.fi>
Authored: Sun Jan 24 12:48:11 2016 +0200
Committer: Clebert Suconic <cl...@apache.org>
Committed: Mon Jan 25 11:23:07 2016 -0500
----------------------------------------------------------------------
.../artemis/utils/ConcurrentHashSetTest.java | 128 ++++++++
.../utils/TypedPropertiesConversionTest.java | 312 ++++++++++++++++++
.../artemis/utils/TypedPropertiesTest.java | 229 ++++++++++++++
.../artemis/util/ConcurrentHashSetTest.java | 131 --------
.../util/TypedPropertiesConversionTest.java | 314 -------------------
.../artemis/util/TypedPropertiesTest.java | 231 --------------
6 files changed, 669 insertions(+), 676 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/ca34f7fb/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/ConcurrentHashSetTest.java
----------------------------------------------------------------------
diff --git a/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/ConcurrentHashSetTest.java b/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/ConcurrentHashSetTest.java
new file mode 100644
index 0000000..6bc4fde
--- /dev/null
+++ b/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/ConcurrentHashSetTest.java
@@ -0,0 +1,128 @@
+/*
+ * 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.activemq.artemis.utils;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Iterator;
+
+public class ConcurrentHashSetTest extends Assert {
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ private ConcurrentSet<String> set;
+
+ private String element;
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ @Test
+ public void testAdd() throws Exception {
+ Assert.assertTrue(set.add(element));
+ Assert.assertFalse(set.add(element));
+ }
+
+ @Test
+ public void testAddIfAbsent() throws Exception {
+ Assert.assertTrue(set.addIfAbsent(element));
+ Assert.assertFalse(set.addIfAbsent(element));
+ }
+
+ @Test
+ public void testRemove() throws Exception {
+ Assert.assertTrue(set.add(element));
+
+ Assert.assertTrue(set.remove(element));
+ Assert.assertFalse(set.remove(element));
+ }
+
+ @Test
+ public void testContains() throws Exception {
+ Assert.assertFalse(set.contains(element));
+
+ Assert.assertTrue(set.add(element));
+ Assert.assertTrue(set.contains(element));
+
+ Assert.assertTrue(set.remove(element));
+ Assert.assertFalse(set.contains(element));
+ }
+
+ @Test
+ public void testSize() throws Exception {
+ Assert.assertEquals(0, set.size());
+
+ Assert.assertTrue(set.add(element));
+ Assert.assertEquals(1, set.size());
+
+ Assert.assertTrue(set.remove(element));
+ Assert.assertEquals(0, set.size());
+ }
+
+ @Test
+ public void testClear() throws Exception {
+ Assert.assertTrue(set.add(element));
+
+ Assert.assertTrue(set.contains(element));
+ set.clear();
+ Assert.assertFalse(set.contains(element));
+ }
+
+ @Test
+ public void testIsEmpty() throws Exception {
+ Assert.assertTrue(set.isEmpty());
+
+ Assert.assertTrue(set.add(element));
+ Assert.assertFalse(set.isEmpty());
+
+ set.clear();
+ Assert.assertTrue(set.isEmpty());
+ }
+
+ @Test
+ public void testIterator() throws Exception {
+ set.add(element);
+
+ Iterator<String> iterator = set.iterator();
+ while (iterator.hasNext()) {
+ String e = iterator.next();
+ Assert.assertEquals(element, e);
+ }
+ }
+
+ // TestCase overrides --------------------------------------------
+
+ @Before
+ public void setUp() throws Exception {
+ set = new ConcurrentHashSet<>();
+ element = RandomUtil.randomString();
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+}
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/ca34f7fb/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/TypedPropertiesConversionTest.java
----------------------------------------------------------------------
diff --git a/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/TypedPropertiesConversionTest.java b/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/TypedPropertiesConversionTest.java
new file mode 100644
index 0000000..ff5d32d
--- /dev/null
+++ b/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/TypedPropertiesConversionTest.java
@@ -0,0 +1,312 @@
+/*
+ * 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.activemq.artemis.utils;
+
+import org.apache.activemq.artemis.api.core.ActiveMQPropertyConversionException;
+import org.apache.activemq.artemis.api.core.SimpleString;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TypedPropertiesConversionTest {
+
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ private TypedProperties props;
+
+ private SimpleString key;
+
+ private final SimpleString unknownKey = new SimpleString("this.key.is.never.used");
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ @Before
+ public void setUp() throws Exception {
+ key = RandomUtil.randomSimpleString();
+ props = new TypedProperties();
+ }
+
+ @Test
+ public void testBooleanProperty() throws Exception {
+ Boolean val = RandomUtil.randomBoolean();
+ props.putBooleanProperty(key, val);
+
+ Assert.assertEquals(val, props.getBooleanProperty(key));
+ Assert.assertEquals(new SimpleString(Boolean.toString(val)), props.getSimpleStringProperty(key));
+
+ props.putSimpleStringProperty(key, new SimpleString(Boolean.toString(val)));
+ Assert.assertEquals(val, props.getBooleanProperty(key));
+
+ try {
+ props.putByteProperty(key, RandomUtil.randomByte());
+ props.getBooleanProperty(key);
+ Assert.fail();
+ }
+ catch (ActiveMQPropertyConversionException e) {
+ }
+
+ Assert.assertFalse(props.getBooleanProperty(unknownKey));
+ }
+
+ @Test
+ public void testCharProperty() throws Exception {
+ Character val = RandomUtil.randomChar();
+ props.putCharProperty(key, val);
+
+ Assert.assertEquals(val, props.getCharProperty(key));
+ Assert.assertEquals(new SimpleString(Character.toString(val)), props.getSimpleStringProperty(key));
+
+ try {
+ props.putByteProperty(key, RandomUtil.randomByte());
+ props.getCharProperty(key);
+ Assert.fail();
+ }
+ catch (ActiveMQPropertyConversionException e) {
+ }
+
+ try {
+ props.getCharProperty(unknownKey);
+ Assert.fail();
+ }
+ catch (NullPointerException e) {
+ }
+ }
+
+ @Test
+ public void testByteProperty() throws Exception {
+ Byte val = RandomUtil.randomByte();
+ props.putByteProperty(key, val);
+
+ Assert.assertEquals(val, props.getByteProperty(key));
+ Assert.assertEquals(new SimpleString(Byte.toString(val)), props.getSimpleStringProperty(key));
+
+ props.putSimpleStringProperty(key, new SimpleString(Byte.toString(val)));
+ Assert.assertEquals(val, props.getByteProperty(key));
+
+ try {
+ props.putBooleanProperty(key, RandomUtil.randomBoolean());
+ props.getByteProperty(key);
+ Assert.fail();
+ }
+ catch (ActiveMQPropertyConversionException e) {
+ }
+
+ try {
+ props.getByteProperty(unknownKey);
+ Assert.fail();
+ }
+ catch (NumberFormatException e) {
+ }
+ }
+
+ @Test
+ public void testIntProperty() throws Exception {
+ Integer val = RandomUtil.randomInt();
+ props.putIntProperty(key, val);
+
+ Assert.assertEquals(val, props.getIntProperty(key));
+ Assert.assertEquals(new SimpleString(Integer.toString(val)), props.getSimpleStringProperty(key));
+
+ props.putSimpleStringProperty(key, new SimpleString(Integer.toString(val)));
+ Assert.assertEquals(val, props.getIntProperty(key));
+
+ Byte byteVal = RandomUtil.randomByte();
+ props.putByteProperty(key, byteVal);
+ Assert.assertEquals(Integer.valueOf(byteVal), props.getIntProperty(key));
+
+ try {
+ props.putBooleanProperty(key, RandomUtil.randomBoolean());
+ props.getIntProperty(key);
+ Assert.fail();
+ }
+ catch (ActiveMQPropertyConversionException e) {
+ }
+
+ try {
+ props.getIntProperty(unknownKey);
+ Assert.fail();
+ }
+ catch (NumberFormatException e) {
+ }
+ }
+
+ @Test
+ public void testLongProperty() throws Exception {
+ Long val = RandomUtil.randomLong();
+ props.putLongProperty(key, val);
+
+ Assert.assertEquals(val, props.getLongProperty(key));
+ Assert.assertEquals(new SimpleString(Long.toString(val)), props.getSimpleStringProperty(key));
+
+ props.putSimpleStringProperty(key, new SimpleString(Long.toString(val)));
+ Assert.assertEquals(val, props.getLongProperty(key));
+
+ Byte byteVal = RandomUtil.randomByte();
+ props.putByteProperty(key, byteVal);
+ Assert.assertEquals(Long.valueOf(byteVal), props.getLongProperty(key));
+
+ Short shortVal = RandomUtil.randomShort();
+ props.putShortProperty(key, shortVal);
+ Assert.assertEquals(Long.valueOf(shortVal), props.getLongProperty(key));
+
+ Integer intVal = RandomUtil.randomInt();
+ props.putIntProperty(key, intVal);
+ Assert.assertEquals(Long.valueOf(intVal), props.getLongProperty(key));
+
+ try {
+ props.putBooleanProperty(key, RandomUtil.randomBoolean());
+ props.getLongProperty(key);
+ Assert.fail();
+ }
+ catch (ActiveMQPropertyConversionException e) {
+ }
+
+ try {
+ props.getLongProperty(unknownKey);
+ Assert.fail();
+ }
+ catch (NumberFormatException e) {
+ }
+ }
+
+ @Test
+ public void testDoubleProperty() throws Exception {
+ Double val = RandomUtil.randomDouble();
+ props.putDoubleProperty(key, val);
+
+ Assert.assertEquals(val, props.getDoubleProperty(key));
+ Assert.assertEquals(new SimpleString(Double.toString(val)), props.getSimpleStringProperty(key));
+
+ props.putSimpleStringProperty(key, new SimpleString(Double.toString(val)));
+ Assert.assertEquals(val, props.getDoubleProperty(key));
+
+ try {
+ props.putBooleanProperty(key, RandomUtil.randomBoolean());
+ props.getDoubleProperty(key);
+ Assert.fail();
+ }
+ catch (ActiveMQPropertyConversionException e) {
+ }
+
+ try {
+ props.getDoubleProperty(unknownKey);
+ Assert.fail();
+ }
+ catch (Exception e) {
+ }
+ }
+
+ @Test
+ public void testFloatProperty() throws Exception {
+ Float val = RandomUtil.randomFloat();
+ props.putFloatProperty(key, val);
+
+ Assert.assertEquals(val, props.getFloatProperty(key));
+ Assert.assertEquals(Double.valueOf(val), props.getDoubleProperty(key));
+ Assert.assertEquals(new SimpleString(Float.toString(val)), props.getSimpleStringProperty(key));
+
+ props.putSimpleStringProperty(key, new SimpleString(Float.toString(val)));
+ Assert.assertEquals(val, props.getFloatProperty(key));
+
+ try {
+ props.putBooleanProperty(key, RandomUtil.randomBoolean());
+ props.getFloatProperty(key);
+ Assert.fail();
+ }
+ catch (ActiveMQPropertyConversionException e) {
+ }
+
+ try {
+ props.getFloatProperty(unknownKey);
+ Assert.fail();
+ }
+ catch (Exception e) {
+ }
+ }
+
+ @Test
+ public void testShortProperty() throws Exception {
+ Short val = RandomUtil.randomShort();
+ props.putShortProperty(key, val);
+
+ Assert.assertEquals(val, props.getShortProperty(key));
+ Assert.assertEquals(Integer.valueOf(val), props.getIntProperty(key));
+ Assert.assertEquals(new SimpleString(Short.toString(val)), props.getSimpleStringProperty(key));
+
+ props.putSimpleStringProperty(key, new SimpleString(Short.toString(val)));
+ Assert.assertEquals(val, props.getShortProperty(key));
+
+ Byte byteVal = RandomUtil.randomByte();
+ props.putByteProperty(key, byteVal);
+ Assert.assertEquals(Short.valueOf(byteVal), props.getShortProperty(key));
+
+ try {
+ props.putBooleanProperty(key, RandomUtil.randomBoolean());
+ props.getShortProperty(key);
+ Assert.fail();
+ }
+ catch (ActiveMQPropertyConversionException e) {
+ }
+
+ try {
+ props.getShortProperty(unknownKey);
+ Assert.fail();
+ }
+ catch (NumberFormatException e) {
+ }
+ }
+
+ @Test
+ public void testSimpleStringProperty() throws Exception {
+ SimpleString strVal = RandomUtil.randomSimpleString();
+ props.putSimpleStringProperty(key, strVal);
+ Assert.assertEquals(strVal, props.getSimpleStringProperty(key));
+ }
+
+ @Test
+ public void testBytesProperty() throws Exception {
+ byte[] val = RandomUtil.randomBytes();
+ props.putBytesProperty(key, val);
+
+ Assert.assertArrayEquals(val, props.getBytesProperty(key));
+
+ try {
+ props.putBooleanProperty(key, RandomUtil.randomBoolean());
+ props.getBytesProperty(key);
+ Assert.fail();
+ }
+ catch (ActiveMQPropertyConversionException e) {
+ }
+
+ Assert.assertNull(props.getBytesProperty(unknownKey));
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+
+}
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/ca34f7fb/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/TypedPropertiesTest.java
----------------------------------------------------------------------
diff --git a/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/TypedPropertiesTest.java b/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/TypedPropertiesTest.java
new file mode 100644
index 0000000..48c7630
--- /dev/null
+++ b/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/TypedPropertiesTest.java
@@ -0,0 +1,229 @@
+/*
+ * 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.activemq.artemis.utils;
+
+import java.util.Iterator;
+
+import org.apache.activemq.artemis.api.core.ActiveMQBuffer;
+import org.apache.activemq.artemis.api.core.ActiveMQBuffers;
+import org.apache.activemq.artemis.api.core.SimpleString;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TypedPropertiesTest {
+
+ private static void assertEqualsTypeProperties(final TypedProperties expected, final TypedProperties actual) {
+ Assert.assertNotNull(expected);
+ Assert.assertNotNull(actual);
+ Assert.assertEquals(expected.getEncodeSize(), actual.getEncodeSize());
+ Assert.assertEquals(expected.getPropertyNames(), actual.getPropertyNames());
+ Iterator<SimpleString> iterator = actual.getPropertyNames().iterator();
+ while (iterator.hasNext()) {
+ SimpleString key = iterator.next();
+ Object expectedValue = expected.getProperty(key);
+ Object actualValue = actual.getProperty(key);
+ if (expectedValue instanceof byte[] && actualValue instanceof byte[]) {
+ byte[] expectedBytes = (byte[]) expectedValue;
+ byte[] actualBytes = (byte[]) actualValue;
+ Assert.assertArrayEquals(expectedBytes, actualBytes);
+ }
+ else {
+ Assert.assertEquals(expectedValue, actualValue);
+ }
+ }
+ }
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ private TypedProperties props;
+
+ private SimpleString key;
+
+ @Test
+ public void testCopyContructor() throws Exception {
+ props.putSimpleStringProperty(key, RandomUtil.randomSimpleString());
+
+ TypedProperties copy = new TypedProperties(props);
+
+ Assert.assertEquals(props.getEncodeSize(), copy.getEncodeSize());
+ Assert.assertEquals(props.getPropertyNames(), copy.getPropertyNames());
+
+ Assert.assertTrue(copy.containsProperty(key));
+ Assert.assertEquals(props.getProperty(key), copy.getProperty(key));
+ }
+
+ @Test
+ public void testRemove() throws Exception {
+ props.putSimpleStringProperty(key, RandomUtil.randomSimpleString());
+
+ Assert.assertTrue(props.containsProperty(key));
+ Assert.assertNotNull(props.getProperty(key));
+
+ props.removeProperty(key);
+
+ Assert.assertFalse(props.containsProperty(key));
+ Assert.assertNull(props.getProperty(key));
+ }
+
+ @Test
+ public void testClear() throws Exception {
+ props.putSimpleStringProperty(key, RandomUtil.randomSimpleString());
+
+ Assert.assertTrue(props.containsProperty(key));
+ Assert.assertNotNull(props.getProperty(key));
+
+ props.clear();
+
+ Assert.assertFalse(props.containsProperty(key));
+ Assert.assertNull(props.getProperty(key));
+ }
+
+ @Test
+ public void testKey() throws Exception {
+ props.putBooleanProperty(key, true);
+ boolean bool = (Boolean) props.getProperty(key);
+ Assert.assertEquals(true, bool);
+
+ props.putCharProperty(key, 'a');
+ char c = (Character) props.getProperty(key);
+ Assert.assertEquals('a', c);
+ }
+
+ @Test
+ public void testGetPropertyOnEmptyProperties() throws Exception {
+ Assert.assertFalse(props.containsProperty(key));
+ Assert.assertNull(props.getProperty(key));
+ }
+
+ @Test
+ public void testRemovePropertyOnEmptyProperties() throws Exception {
+ Assert.assertFalse(props.containsProperty(key));
+ Assert.assertNull(props.removeProperty(key));
+ }
+
+ @Test
+ public void testNullProperty() throws Exception {
+ props.putSimpleStringProperty(key, null);
+ Assert.assertTrue(props.containsProperty(key));
+ Assert.assertNull(props.getProperty(key));
+ }
+
+ @Test
+ public void testBytesPropertyWithNull() throws Exception {
+ props.putBytesProperty(key, null);
+
+ Assert.assertTrue(props.containsProperty(key));
+ byte[] bb = (byte[]) props.getProperty(key);
+ Assert.assertNull(bb);
+ }
+
+ @Test
+ public void testTypedProperties() throws Exception {
+ SimpleString longKey = RandomUtil.randomSimpleString();
+ long longValue = RandomUtil.randomLong();
+ SimpleString simpleStringKey = RandomUtil.randomSimpleString();
+ SimpleString simpleStringValue = RandomUtil.randomSimpleString();
+ TypedProperties otherProps = new TypedProperties();
+ otherProps.putLongProperty(longKey, longValue);
+ otherProps.putSimpleStringProperty(simpleStringKey, simpleStringValue);
+
+ props.putTypedProperties(otherProps);
+
+ long ll = props.getLongProperty(longKey);
+ Assert.assertEquals(longValue, ll);
+ SimpleString ss = props.getSimpleStringProperty(simpleStringKey);
+ Assert.assertEquals(simpleStringValue, ss);
+ }
+
+ @Test
+ public void testEmptyTypedProperties() throws Exception {
+ Assert.assertEquals(0, props.getPropertyNames().size());
+
+ props.putTypedProperties(new TypedProperties());
+
+ Assert.assertEquals(0, props.getPropertyNames().size());
+ }
+
+ @Test
+ public void testNullTypedProperties() throws Exception {
+ Assert.assertEquals(0, props.getPropertyNames().size());
+
+ props.putTypedProperties(null);
+
+ Assert.assertEquals(0, props.getPropertyNames().size());
+ }
+
+ @Test
+ public void testEncodeDecode() throws Exception {
+ props.putByteProperty(RandomUtil.randomSimpleString(), RandomUtil.randomByte());
+ props.putBytesProperty(RandomUtil.randomSimpleString(), RandomUtil.randomBytes());
+ props.putBytesProperty(RandomUtil.randomSimpleString(), null);
+ props.putBooleanProperty(RandomUtil.randomSimpleString(), RandomUtil.randomBoolean());
+ props.putShortProperty(RandomUtil.randomSimpleString(), RandomUtil.randomShort());
+ props.putIntProperty(RandomUtil.randomSimpleString(), RandomUtil.randomInt());
+ props.putLongProperty(RandomUtil.randomSimpleString(), RandomUtil.randomLong());
+ props.putFloatProperty(RandomUtil.randomSimpleString(), RandomUtil.randomFloat());
+ props.putDoubleProperty(RandomUtil.randomSimpleString(), RandomUtil.randomDouble());
+ props.putCharProperty(RandomUtil.randomSimpleString(), RandomUtil.randomChar());
+ props.putSimpleStringProperty(RandomUtil.randomSimpleString(), RandomUtil.randomSimpleString());
+ props.putSimpleStringProperty(RandomUtil.randomSimpleString(), null);
+ SimpleString keyToRemove = RandomUtil.randomSimpleString();
+ props.putSimpleStringProperty(keyToRemove, RandomUtil.randomSimpleString());
+
+ ActiveMQBuffer buffer = ActiveMQBuffers.dynamicBuffer(1024);
+ props.encode(buffer);
+
+ Assert.assertEquals(props.getEncodeSize(), buffer.writerIndex());
+
+ TypedProperties decodedProps = new TypedProperties();
+ decodedProps.decode(buffer);
+
+ TypedPropertiesTest.assertEqualsTypeProperties(props, decodedProps);
+
+ buffer.clear();
+
+ // After removing a property, you should still be able to encode the Property
+ props.removeProperty(keyToRemove);
+ props.encode(buffer);
+
+ Assert.assertEquals(props.getEncodeSize(), buffer.writerIndex());
+ }
+
+ @Test
+ public void testEncodeDecodeEmpty() throws Exception {
+ TypedProperties emptyProps = new TypedProperties();
+
+ ActiveMQBuffer buffer = ActiveMQBuffers.dynamicBuffer(1024);
+ emptyProps.encode(buffer);
+
+ Assert.assertEquals(props.getEncodeSize(), buffer.writerIndex());
+
+ TypedProperties decodedProps = new TypedProperties();
+ decodedProps.decode(buffer);
+
+ TypedPropertiesTest.assertEqualsTypeProperties(emptyProps, decodedProps);
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ props = new TypedProperties();
+ key = RandomUtil.randomSimpleString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/ca34f7fb/artemis-core-client/src/test/java/org/apache/activemq/artemis/util/ConcurrentHashSetTest.java
----------------------------------------------------------------------
diff --git a/artemis-core-client/src/test/java/org/apache/activemq/artemis/util/ConcurrentHashSetTest.java b/artemis-core-client/src/test/java/org/apache/activemq/artemis/util/ConcurrentHashSetTest.java
deleted file mode 100644
index 79ffa06..0000000
--- a/artemis-core-client/src/test/java/org/apache/activemq/artemis/util/ConcurrentHashSetTest.java
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * 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.activemq.artemis.util;
-
-import org.apache.activemq.artemis.utils.ConcurrentHashSet;
-import org.apache.activemq.artemis.utils.ConcurrentSet;
-import org.apache.activemq.artemis.utils.RandomUtil;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.util.Iterator;
-
-public class ConcurrentHashSetTest extends Assert {
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- private ConcurrentSet<String> set;
-
- private String element;
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- // Public --------------------------------------------------------
-
- @Test
- public void testAdd() throws Exception {
- Assert.assertTrue(set.add(element));
- Assert.assertFalse(set.add(element));
- }
-
- @Test
- public void testAddIfAbsent() throws Exception {
- Assert.assertTrue(set.addIfAbsent(element));
- Assert.assertFalse(set.addIfAbsent(element));
- }
-
- @Test
- public void testRemove() throws Exception {
- Assert.assertTrue(set.add(element));
-
- Assert.assertTrue(set.remove(element));
- Assert.assertFalse(set.remove(element));
- }
-
- @Test
- public void testContains() throws Exception {
- Assert.assertFalse(set.contains(element));
-
- Assert.assertTrue(set.add(element));
- Assert.assertTrue(set.contains(element));
-
- Assert.assertTrue(set.remove(element));
- Assert.assertFalse(set.contains(element));
- }
-
- @Test
- public void testSize() throws Exception {
- Assert.assertEquals(0, set.size());
-
- Assert.assertTrue(set.add(element));
- Assert.assertEquals(1, set.size());
-
- Assert.assertTrue(set.remove(element));
- Assert.assertEquals(0, set.size());
- }
-
- @Test
- public void testClear() throws Exception {
- Assert.assertTrue(set.add(element));
-
- Assert.assertTrue(set.contains(element));
- set.clear();
- Assert.assertFalse(set.contains(element));
- }
-
- @Test
- public void testIsEmpty() throws Exception {
- Assert.assertTrue(set.isEmpty());
-
- Assert.assertTrue(set.add(element));
- Assert.assertFalse(set.isEmpty());
-
- set.clear();
- Assert.assertTrue(set.isEmpty());
- }
-
- @Test
- public void testIterator() throws Exception {
- set.add(element);
-
- Iterator<String> iterator = set.iterator();
- while (iterator.hasNext()) {
- String e = iterator.next();
- Assert.assertEquals(element, e);
- }
- }
-
- // TestCase overrides --------------------------------------------
-
- @Before
- public void setUp() throws Exception {
- set = new ConcurrentHashSet<>();
- element = RandomUtil.randomString();
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-}
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/ca34f7fb/artemis-core-client/src/test/java/org/apache/activemq/artemis/util/TypedPropertiesConversionTest.java
----------------------------------------------------------------------
diff --git a/artemis-core-client/src/test/java/org/apache/activemq/artemis/util/TypedPropertiesConversionTest.java b/artemis-core-client/src/test/java/org/apache/activemq/artemis/util/TypedPropertiesConversionTest.java
deleted file mode 100644
index e4e8c59..0000000
--- a/artemis-core-client/src/test/java/org/apache/activemq/artemis/util/TypedPropertiesConversionTest.java
+++ /dev/null
@@ -1,314 +0,0 @@
-/*
- * 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.activemq.artemis.util;
-
-import org.apache.activemq.artemis.api.core.ActiveMQPropertyConversionException;
-import org.apache.activemq.artemis.api.core.SimpleString;
-import org.apache.activemq.artemis.utils.RandomUtil;
-import org.apache.activemq.artemis.utils.TypedProperties;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-public class TypedPropertiesConversionTest {
-
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- private TypedProperties props;
-
- private SimpleString key;
-
- private final SimpleString unknownKey = new SimpleString("this.key.is.never.used");
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- // Public --------------------------------------------------------
-
- @Before
- public void setUp() throws Exception {
- key = RandomUtil.randomSimpleString();
- props = new TypedProperties();
- }
-
- @Test
- public void testBooleanProperty() throws Exception {
- Boolean val = RandomUtil.randomBoolean();
- props.putBooleanProperty(key, val);
-
- Assert.assertEquals(val, props.getBooleanProperty(key));
- Assert.assertEquals(new SimpleString(Boolean.toString(val)), props.getSimpleStringProperty(key));
-
- props.putSimpleStringProperty(key, new SimpleString(Boolean.toString(val)));
- Assert.assertEquals(val, props.getBooleanProperty(key));
-
- try {
- props.putByteProperty(key, RandomUtil.randomByte());
- props.getBooleanProperty(key);
- Assert.fail();
- }
- catch (ActiveMQPropertyConversionException e) {
- }
-
- Assert.assertFalse(props.getBooleanProperty(unknownKey));
- }
-
- @Test
- public void testCharProperty() throws Exception {
- Character val = RandomUtil.randomChar();
- props.putCharProperty(key, val);
-
- Assert.assertEquals(val, props.getCharProperty(key));
- Assert.assertEquals(new SimpleString(Character.toString(val)), props.getSimpleStringProperty(key));
-
- try {
- props.putByteProperty(key, RandomUtil.randomByte());
- props.getCharProperty(key);
- Assert.fail();
- }
- catch (ActiveMQPropertyConversionException e) {
- }
-
- try {
- props.getCharProperty(unknownKey);
- Assert.fail();
- }
- catch (NullPointerException e) {
- }
- }
-
- @Test
- public void testByteProperty() throws Exception {
- Byte val = RandomUtil.randomByte();
- props.putByteProperty(key, val);
-
- Assert.assertEquals(val, props.getByteProperty(key));
- Assert.assertEquals(new SimpleString(Byte.toString(val)), props.getSimpleStringProperty(key));
-
- props.putSimpleStringProperty(key, new SimpleString(Byte.toString(val)));
- Assert.assertEquals(val, props.getByteProperty(key));
-
- try {
- props.putBooleanProperty(key, RandomUtil.randomBoolean());
- props.getByteProperty(key);
- Assert.fail();
- }
- catch (ActiveMQPropertyConversionException e) {
- }
-
- try {
- props.getByteProperty(unknownKey);
- Assert.fail();
- }
- catch (NumberFormatException e) {
- }
- }
-
- @Test
- public void testIntProperty() throws Exception {
- Integer val = RandomUtil.randomInt();
- props.putIntProperty(key, val);
-
- Assert.assertEquals(val, props.getIntProperty(key));
- Assert.assertEquals(new SimpleString(Integer.toString(val)), props.getSimpleStringProperty(key));
-
- props.putSimpleStringProperty(key, new SimpleString(Integer.toString(val)));
- Assert.assertEquals(val, props.getIntProperty(key));
-
- Byte byteVal = RandomUtil.randomByte();
- props.putByteProperty(key, byteVal);
- Assert.assertEquals(Integer.valueOf(byteVal), props.getIntProperty(key));
-
- try {
- props.putBooleanProperty(key, RandomUtil.randomBoolean());
- props.getIntProperty(key);
- Assert.fail();
- }
- catch (ActiveMQPropertyConversionException e) {
- }
-
- try {
- props.getIntProperty(unknownKey);
- Assert.fail();
- }
- catch (NumberFormatException e) {
- }
- }
-
- @Test
- public void testLongProperty() throws Exception {
- Long val = RandomUtil.randomLong();
- props.putLongProperty(key, val);
-
- Assert.assertEquals(val, props.getLongProperty(key));
- Assert.assertEquals(new SimpleString(Long.toString(val)), props.getSimpleStringProperty(key));
-
- props.putSimpleStringProperty(key, new SimpleString(Long.toString(val)));
- Assert.assertEquals(val, props.getLongProperty(key));
-
- Byte byteVal = RandomUtil.randomByte();
- props.putByteProperty(key, byteVal);
- Assert.assertEquals(Long.valueOf(byteVal), props.getLongProperty(key));
-
- Short shortVal = RandomUtil.randomShort();
- props.putShortProperty(key, shortVal);
- Assert.assertEquals(Long.valueOf(shortVal), props.getLongProperty(key));
-
- Integer intVal = RandomUtil.randomInt();
- props.putIntProperty(key, intVal);
- Assert.assertEquals(Long.valueOf(intVal), props.getLongProperty(key));
-
- try {
- props.putBooleanProperty(key, RandomUtil.randomBoolean());
- props.getLongProperty(key);
- Assert.fail();
- }
- catch (ActiveMQPropertyConversionException e) {
- }
-
- try {
- props.getLongProperty(unknownKey);
- Assert.fail();
- }
- catch (NumberFormatException e) {
- }
- }
-
- @Test
- public void testDoubleProperty() throws Exception {
- Double val = RandomUtil.randomDouble();
- props.putDoubleProperty(key, val);
-
- Assert.assertEquals(val, props.getDoubleProperty(key));
- Assert.assertEquals(new SimpleString(Double.toString(val)), props.getSimpleStringProperty(key));
-
- props.putSimpleStringProperty(key, new SimpleString(Double.toString(val)));
- Assert.assertEquals(val, props.getDoubleProperty(key));
-
- try {
- props.putBooleanProperty(key, RandomUtil.randomBoolean());
- props.getDoubleProperty(key);
- Assert.fail();
- }
- catch (ActiveMQPropertyConversionException e) {
- }
-
- try {
- props.getDoubleProperty(unknownKey);
- Assert.fail();
- }
- catch (Exception e) {
- }
- }
-
- @Test
- public void testFloatProperty() throws Exception {
- Float val = RandomUtil.randomFloat();
- props.putFloatProperty(key, val);
-
- Assert.assertEquals(val, props.getFloatProperty(key));
- Assert.assertEquals(Double.valueOf(val), props.getDoubleProperty(key));
- Assert.assertEquals(new SimpleString(Float.toString(val)), props.getSimpleStringProperty(key));
-
- props.putSimpleStringProperty(key, new SimpleString(Float.toString(val)));
- Assert.assertEquals(val, props.getFloatProperty(key));
-
- try {
- props.putBooleanProperty(key, RandomUtil.randomBoolean());
- props.getFloatProperty(key);
- Assert.fail();
- }
- catch (ActiveMQPropertyConversionException e) {
- }
-
- try {
- props.getFloatProperty(unknownKey);
- Assert.fail();
- }
- catch (Exception e) {
- }
- }
-
- @Test
- public void testShortProperty() throws Exception {
- Short val = RandomUtil.randomShort();
- props.putShortProperty(key, val);
-
- Assert.assertEquals(val, props.getShortProperty(key));
- Assert.assertEquals(Integer.valueOf(val), props.getIntProperty(key));
- Assert.assertEquals(new SimpleString(Short.toString(val)), props.getSimpleStringProperty(key));
-
- props.putSimpleStringProperty(key, new SimpleString(Short.toString(val)));
- Assert.assertEquals(val, props.getShortProperty(key));
-
- Byte byteVal = RandomUtil.randomByte();
- props.putByteProperty(key, byteVal);
- Assert.assertEquals(Short.valueOf(byteVal), props.getShortProperty(key));
-
- try {
- props.putBooleanProperty(key, RandomUtil.randomBoolean());
- props.getShortProperty(key);
- Assert.fail();
- }
- catch (ActiveMQPropertyConversionException e) {
- }
-
- try {
- props.getShortProperty(unknownKey);
- Assert.fail();
- }
- catch (NumberFormatException e) {
- }
- }
-
- @Test
- public void testSimpleStringProperty() throws Exception {
- SimpleString strVal = RandomUtil.randomSimpleString();
- props.putSimpleStringProperty(key, strVal);
- Assert.assertEquals(strVal, props.getSimpleStringProperty(key));
- }
-
- @Test
- public void testBytesProperty() throws Exception {
- byte[] val = RandomUtil.randomBytes();
- props.putBytesProperty(key, val);
-
- Assert.assertArrayEquals(val, props.getBytesProperty(key));
-
- try {
- props.putBooleanProperty(key, RandomUtil.randomBoolean());
- props.getBytesProperty(key);
- Assert.fail();
- }
- catch (ActiveMQPropertyConversionException e) {
- }
-
- Assert.assertNull(props.getBytesProperty(unknownKey));
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-
-}
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/ca34f7fb/artemis-core-client/src/test/java/org/apache/activemq/artemis/util/TypedPropertiesTest.java
----------------------------------------------------------------------
diff --git a/artemis-core-client/src/test/java/org/apache/activemq/artemis/util/TypedPropertiesTest.java b/artemis-core-client/src/test/java/org/apache/activemq/artemis/util/TypedPropertiesTest.java
deleted file mode 100644
index cc31e75..0000000
--- a/artemis-core-client/src/test/java/org/apache/activemq/artemis/util/TypedPropertiesTest.java
+++ /dev/null
@@ -1,231 +0,0 @@
-/*
- * 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.activemq.artemis.util;
-
-import java.util.Iterator;
-
-import org.apache.activemq.artemis.api.core.ActiveMQBuffer;
-import org.apache.activemq.artemis.api.core.ActiveMQBuffers;
-import org.apache.activemq.artemis.api.core.SimpleString;
-import org.apache.activemq.artemis.utils.RandomUtil;
-import org.apache.activemq.artemis.utils.TypedProperties;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-public class TypedPropertiesTest {
-
- private static void assertEqualsTypeProperties(final TypedProperties expected, final TypedProperties actual) {
- Assert.assertNotNull(expected);
- Assert.assertNotNull(actual);
- Assert.assertEquals(expected.getEncodeSize(), actual.getEncodeSize());
- Assert.assertEquals(expected.getPropertyNames(), actual.getPropertyNames());
- Iterator<SimpleString> iterator = actual.getPropertyNames().iterator();
- while (iterator.hasNext()) {
- SimpleString key = iterator.next();
- Object expectedValue = expected.getProperty(key);
- Object actualValue = actual.getProperty(key);
- if (expectedValue instanceof byte[] && actualValue instanceof byte[]) {
- byte[] expectedBytes = (byte[]) expectedValue;
- byte[] actualBytes = (byte[]) actualValue;
- Assert.assertArrayEquals(expectedBytes, actualBytes);
- }
- else {
- Assert.assertEquals(expectedValue, actualValue);
- }
- }
- }
-
- // Constructors --------------------------------------------------
-
- // Public --------------------------------------------------------
-
- private TypedProperties props;
-
- private SimpleString key;
-
- @Test
- public void testCopyContructor() throws Exception {
- props.putSimpleStringProperty(key, RandomUtil.randomSimpleString());
-
- TypedProperties copy = new TypedProperties(props);
-
- Assert.assertEquals(props.getEncodeSize(), copy.getEncodeSize());
- Assert.assertEquals(props.getPropertyNames(), copy.getPropertyNames());
-
- Assert.assertTrue(copy.containsProperty(key));
- Assert.assertEquals(props.getProperty(key), copy.getProperty(key));
- }
-
- @Test
- public void testRemove() throws Exception {
- props.putSimpleStringProperty(key, RandomUtil.randomSimpleString());
-
- Assert.assertTrue(props.containsProperty(key));
- Assert.assertNotNull(props.getProperty(key));
-
- props.removeProperty(key);
-
- Assert.assertFalse(props.containsProperty(key));
- Assert.assertNull(props.getProperty(key));
- }
-
- @Test
- public void testClear() throws Exception {
- props.putSimpleStringProperty(key, RandomUtil.randomSimpleString());
-
- Assert.assertTrue(props.containsProperty(key));
- Assert.assertNotNull(props.getProperty(key));
-
- props.clear();
-
- Assert.assertFalse(props.containsProperty(key));
- Assert.assertNull(props.getProperty(key));
- }
-
- @Test
- public void testKey() throws Exception {
- props.putBooleanProperty(key, true);
- boolean bool = (Boolean) props.getProperty(key);
- Assert.assertEquals(true, bool);
-
- props.putCharProperty(key, 'a');
- char c = (Character) props.getProperty(key);
- Assert.assertEquals('a', c);
- }
-
- @Test
- public void testGetPropertyOnEmptyProperties() throws Exception {
- Assert.assertFalse(props.containsProperty(key));
- Assert.assertNull(props.getProperty(key));
- }
-
- @Test
- public void testRemovePropertyOnEmptyProperties() throws Exception {
- Assert.assertFalse(props.containsProperty(key));
- Assert.assertNull(props.removeProperty(key));
- }
-
- @Test
- public void testNullProperty() throws Exception {
- props.putSimpleStringProperty(key, null);
- Assert.assertTrue(props.containsProperty(key));
- Assert.assertNull(props.getProperty(key));
- }
-
- @Test
- public void testBytesPropertyWithNull() throws Exception {
- props.putBytesProperty(key, null);
-
- Assert.assertTrue(props.containsProperty(key));
- byte[] bb = (byte[]) props.getProperty(key);
- Assert.assertNull(bb);
- }
-
- @Test
- public void testTypedProperties() throws Exception {
- SimpleString longKey = RandomUtil.randomSimpleString();
- long longValue = RandomUtil.randomLong();
- SimpleString simpleStringKey = RandomUtil.randomSimpleString();
- SimpleString simpleStringValue = RandomUtil.randomSimpleString();
- TypedProperties otherProps = new TypedProperties();
- otherProps.putLongProperty(longKey, longValue);
- otherProps.putSimpleStringProperty(simpleStringKey, simpleStringValue);
-
- props.putTypedProperties(otherProps);
-
- long ll = props.getLongProperty(longKey);
- Assert.assertEquals(longValue, ll);
- SimpleString ss = props.getSimpleStringProperty(simpleStringKey);
- Assert.assertEquals(simpleStringValue, ss);
- }
-
- @Test
- public void testEmptyTypedProperties() throws Exception {
- Assert.assertEquals(0, props.getPropertyNames().size());
-
- props.putTypedProperties(new TypedProperties());
-
- Assert.assertEquals(0, props.getPropertyNames().size());
- }
-
- @Test
- public void testNullTypedProperties() throws Exception {
- Assert.assertEquals(0, props.getPropertyNames().size());
-
- props.putTypedProperties(null);
-
- Assert.assertEquals(0, props.getPropertyNames().size());
- }
-
- @Test
- public void testEncodeDecode() throws Exception {
- props.putByteProperty(RandomUtil.randomSimpleString(), RandomUtil.randomByte());
- props.putBytesProperty(RandomUtil.randomSimpleString(), RandomUtil.randomBytes());
- props.putBytesProperty(RandomUtil.randomSimpleString(), null);
- props.putBooleanProperty(RandomUtil.randomSimpleString(), RandomUtil.randomBoolean());
- props.putShortProperty(RandomUtil.randomSimpleString(), RandomUtil.randomShort());
- props.putIntProperty(RandomUtil.randomSimpleString(), RandomUtil.randomInt());
- props.putLongProperty(RandomUtil.randomSimpleString(), RandomUtil.randomLong());
- props.putFloatProperty(RandomUtil.randomSimpleString(), RandomUtil.randomFloat());
- props.putDoubleProperty(RandomUtil.randomSimpleString(), RandomUtil.randomDouble());
- props.putCharProperty(RandomUtil.randomSimpleString(), RandomUtil.randomChar());
- props.putSimpleStringProperty(RandomUtil.randomSimpleString(), RandomUtil.randomSimpleString());
- props.putSimpleStringProperty(RandomUtil.randomSimpleString(), null);
- SimpleString keyToRemove = RandomUtil.randomSimpleString();
- props.putSimpleStringProperty(keyToRemove, RandomUtil.randomSimpleString());
-
- ActiveMQBuffer buffer = ActiveMQBuffers.dynamicBuffer(1024);
- props.encode(buffer);
-
- Assert.assertEquals(props.getEncodeSize(), buffer.writerIndex());
-
- TypedProperties decodedProps = new TypedProperties();
- decodedProps.decode(buffer);
-
- TypedPropertiesTest.assertEqualsTypeProperties(props, decodedProps);
-
- buffer.clear();
-
- // After removing a property, you should still be able to encode the Property
- props.removeProperty(keyToRemove);
- props.encode(buffer);
-
- Assert.assertEquals(props.getEncodeSize(), buffer.writerIndex());
- }
-
- @Test
- public void testEncodeDecodeEmpty() throws Exception {
- TypedProperties emptyProps = new TypedProperties();
-
- ActiveMQBuffer buffer = ActiveMQBuffers.dynamicBuffer(1024);
- emptyProps.encode(buffer);
-
- Assert.assertEquals(props.getEncodeSize(), buffer.writerIndex());
-
- TypedProperties decodedProps = new TypedProperties();
- decodedProps.decode(buffer);
-
- TypedPropertiesTest.assertEqualsTypeProperties(emptyProps, decodedProps);
- }
-
- @Before
- public void setUp() throws Exception {
- props = new TypedProperties();
- key = RandomUtil.randomSimpleString();
- }
-}