diff options
| author | Keith Wall <kwall@apache.org> | 2014-10-20 19:57:57 +0000 |
|---|---|---|
| committer | Keith Wall <kwall@apache.org> | 2014-10-20 19:57:57 +0000 |
| commit | 3c847f448c02cf66822cf906f09bbd0b40823188 (patch) | |
| tree | f379cae362f373f3e7f2635469d5bd2b0a63f127 /qpid/java | |
| parent | ad08039f584f14f2d783908d55748624d46d072f (diff) | |
| download | qpid-python-3c847f448c02cf66822cf906f09bbd0b40823188.tar.gz | |
QPID-6168: [Java Broker] Improve unit tests around valid values and setting of enums
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1633216 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java')
5 files changed, 161 insertions, 12 deletions
diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/AbstractConfiguredObjectTest.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/AbstractConfiguredObjectTest.java index 9b4826a383..2da5a988f5 100644 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/AbstractConfiguredObjectTest.java +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/AbstractConfiguredObjectTest.java @@ -20,6 +20,7 @@ */ package org.apache.qpid.server.model; +import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -27,6 +28,7 @@ import java.util.Map; import org.apache.qpid.server.configuration.IllegalConfigurationException; import org.apache.qpid.server.model.testmodel.TestChildCategory; import org.apache.qpid.server.model.testmodel.TestConfiguredObject; +import org.apache.qpid.server.model.testmodel.TestEnum; import org.apache.qpid.server.model.testmodel.TestModel; import org.apache.qpid.server.model.testmodel.TestRootCategory; import org.apache.qpid.server.store.ConfiguredObjectRecord; @@ -104,6 +106,36 @@ public class AbstractConfiguredObjectTest extends QpidTestCase assertEquals("override", object2.getDefaultedValue()); } + public void testEnumAttributeValueFromString() + { + final String objectName = "myName"; + + Map<String, Object> attributes = new HashMap<>(); + attributes.put(ConfiguredObject.NAME, objectName); + attributes.put(TestRootCategory.ENUM_VALUE, TestEnum.TEST_ENUM1.name()); + + TestRootCategory object1 = _model.getObjectFactory().create(TestRootCategory.class, + attributes); + + assertEquals(objectName, object1.getName()); + assertEquals(TestEnum.TEST_ENUM1, object1.getEnumValue()); + } + + public void testEnumAttributeValueFromEnum() + { + final String objectName = "myName"; + + Map<String, Object> attributes = new HashMap<>(); + attributes.put(ConfiguredObject.NAME, objectName); + attributes.put(TestRootCategory.ENUM_VALUE, TestEnum.TEST_ENUM1); + + TestRootCategory object1 = _model.getObjectFactory().create(TestRootCategory.class, + attributes); + + assertEquals(objectName, object1.getName()); + assertEquals(TestEnum.TEST_ENUM1, object1.getEnumValue()); + } + public void testStringAttributeValueFromContextVariableProvidedBySystemProperty() { String sysPropertyName = "testStringAttributeValueFromContextVariableProvidedBySystemProperty"; @@ -181,11 +213,13 @@ public class AbstractConfiguredObjectTest extends QpidTestCase attributes); - assertTrue("context default not in contextKeys", object.getContextKeys(true).contains(TestRootCategory.TEST_CONTEXT_DEFAULT)); + assertTrue("context default not in contextKeys", + object.getContextKeys(true).contains(TestRootCategory.TEST_CONTEXT_DEFAULT)); assertEquals(object.getContextValue(String.class, TestRootCategory.TEST_CONTEXT_DEFAULT), "default"); setTestSystemProperty(TestRootCategory.TEST_CONTEXT_DEFAULT, "notdefault"); - assertTrue("context default not in contextKeys", object.getContextKeys(true).contains(TestRootCategory.TEST_CONTEXT_DEFAULT)); + assertTrue("context default not in contextKeys", + object.getContextKeys(true).contains(TestRootCategory.TEST_CONTEXT_DEFAULT)); assertEquals(object.getContextValue(String.class, TestRootCategory.TEST_CONTEXT_DEFAULT), "notdefault"); } @@ -465,7 +499,7 @@ public class AbstractConfiguredObjectTest extends QpidTestCase assertEquals("Unexpected child1 state", State.ERRORED, child1.getState()); } - public void testConstructionEnforcesAttributeValidValues() throws Exception + public void testCreateEnforcesAttributeValidValues() throws Exception { final String objectName = getName(); Map<String, Object> illegalCreateAttributes = new HashMap<>(); @@ -486,9 +520,8 @@ public class AbstractConfiguredObjectTest extends QpidTestCase legalCreateAttributes.put(ConfiguredObject.NAME, objectName); legalCreateAttributes.put(TestRootCategory.VALID_VALUE, TestRootCategory.VALID_VALUE1); - _model.getObjectFactory().create(TestRootCategory.class, legalCreateAttributes); - // PASS - + TestRootCategory object = _model.getObjectFactory().create(TestRootCategory.class, legalCreateAttributes); + assertEquals(TestRootCategory.VALID_VALUE1, object.getValidValue()); } public void testChangeEnforcesAttributeValidValues() throws Exception @@ -518,4 +551,41 @@ public class AbstractConfiguredObjectTest extends QpidTestCase } + public void testCreateEnforcesAttributeValidValuesWithSets() throws Exception + { + final String objectName = getName(); + final Map<String, Object> name = Collections.singletonMap(ConfiguredObject.NAME, (Object)objectName); + + Map<String, Object> illegalCreateAttributes = new HashMap<>(name); + illegalCreateAttributes.put(TestRootCategory.ENUMSET_VALUES, Collections.singleton(TestEnum.TEST_ENUM3)); + + try + { + _model.getObjectFactory().create(TestRootCategory.class, illegalCreateAttributes); + fail("Exception not thrown"); + } + catch (IllegalConfigurationException ice) + { + // PASS + } + + { + Map<String, Object> legalCreateAttributesEnums = new HashMap<>(name); + legalCreateAttributesEnums.put(TestRootCategory.ENUMSET_VALUES, + Arrays.asList(TestEnum.TEST_ENUM2, TestEnum.TEST_ENUM3)); + + TestRootCategory obj = _model.getObjectFactory().create(TestRootCategory.class, legalCreateAttributesEnums); + assertTrue(obj.getEnumSetValues().containsAll(Arrays.asList(TestEnum.TEST_ENUM2, TestEnum.TEST_ENUM3))); + } + + { + Map<String, Object> legalCreateAttributesStrings = new HashMap<>(name); + legalCreateAttributesStrings.put(TestRootCategory.ENUMSET_VALUES, + Arrays.asList(TestEnum.TEST_ENUM2.name(), TestEnum.TEST_ENUM3.name())); + + TestRootCategory obj = _model.getObjectFactory().create(TestRootCategory.class, legalCreateAttributesStrings); + assertTrue(obj.getEnumSetValues().containsAll(Arrays.asList(TestEnum.TEST_ENUM2, TestEnum.TEST_ENUM3))); + } + } + } diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/Test2RootCategoryImpl.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/Test2RootCategoryImpl.java index 5be708e8f5..238863e708 100644 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/Test2RootCategoryImpl.java +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/Test2RootCategoryImpl.java @@ -23,6 +23,7 @@ package org.apache.qpid.server.model.testmodel; import java.util.Collection; import java.util.Collections; import java.util.Map; +import java.util.Set; import org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor; import org.apache.qpid.server.configuration.updater.TaskExecutor; @@ -30,7 +31,6 @@ import org.apache.qpid.server.model.AbstractConfiguredObject; import org.apache.qpid.server.model.ManagedAttributeField; import org.apache.qpid.server.model.ManagedObject; import org.apache.qpid.server.model.ManagedObjectFactoryConstructor; -import org.apache.qpid.server.model.State; @ManagedObject( category = false , type = "test2" ) public class Test2RootCategoryImpl extends AbstractConfiguredObject<Test2RootCategoryImpl> @@ -54,6 +54,12 @@ public class Test2RootCategoryImpl extends AbstractConfiguredObject<Test2RootCat @ManagedAttributeField private String _validValue; + @ManagedAttributeField + private TestEnum _enumValue; + + @ManagedAttributeField + private Set<TestEnum> _enumSetValues; + @ManagedObjectFactoryConstructor public Test2RootCategoryImpl(final Map<String, Object> attributes) { @@ -115,6 +121,18 @@ public class Test2RootCategoryImpl extends AbstractConfiguredObject<Test2RootCat return _mapValue; } + @Override + public TestEnum getEnumValue() + { + return _enumValue; + } + + @Override + public Set<TestEnum> getEnumSetValues() + { + return _enumSetValues; + } + public static Collection<String> functionGeneratedValidValues() { return Collections.singleton("generated"); diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestEnum.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestEnum.java new file mode 100644 index 0000000000..75c6c197ce --- /dev/null +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestEnum.java @@ -0,0 +1,32 @@ +/* + * 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.server.model.testmodel; + + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +public enum TestEnum +{ + TEST_ENUM1, + TEST_ENUM2, + TEST_ENUM3; +} diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestRootCategory.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestRootCategory.java index 69f429da36..cb47ee63cb 100644 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestRootCategory.java +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestRootCategory.java @@ -20,7 +20,11 @@ */ package org.apache.qpid.server.model.testmodel; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; import java.util.Map; +import java.util.Set; import org.apache.qpid.server.model.ConfiguredObject; import org.apache.qpid.server.model.ManagedAttribute; @@ -36,7 +40,8 @@ public interface TestRootCategory<X extends TestRootCategory<X>> extends Configu String STRING_VALUE = "stringValue"; String MAP_VALUE = "mapValue"; String VALID_VALUE = "validValue"; - + String ENUM_VALUE = "enumValue"; + String ENUMSET_VALUES = "enumSetValues"; String TEST_CONTEXT_DEFAULT = "TEST_CONTEXT_DEFAULT"; @@ -57,13 +62,19 @@ public interface TestRootCategory<X extends TestRootCategory<X>> extends Configu @ManagedAttribute( defaultValue = DEFAULTED_VALUE_DEFAULT) String getDefaultedValue(); - @ManagedAttribute(validValues = {VALID_VALUE1, VALID_VALUE2} ) - String getValidValue(); - @ManagedAttribute String getStringValue(); @ManagedAttribute Map<String,String> getMapValue(); + @ManagedAttribute + TestEnum getEnumValue(); + + @ManagedAttribute(validValues = {VALID_VALUE1, VALID_VALUE2} ) + String getValidValue(); + + @ManagedAttribute( validValues = {"[\"TEST_ENUM1\"]", "[\"TEST_ENUM2\", \"TEST_ENUM3\"]"}) + Set<TestEnum> getEnumSetValues(); + } diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestRootCategoryImpl.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestRootCategoryImpl.java index baac082cc7..7e921866fa 100644 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestRootCategoryImpl.java +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestRootCategoryImpl.java @@ -21,6 +21,7 @@ package org.apache.qpid.server.model.testmodel; import java.util.Map; +import java.util.Set; import org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor; import org.apache.qpid.server.configuration.updater.TaskExecutor; @@ -28,7 +29,6 @@ import org.apache.qpid.server.model.AbstractConfiguredObject; import org.apache.qpid.server.model.ManagedAttributeField; import org.apache.qpid.server.model.ManagedObject; import org.apache.qpid.server.model.ManagedObjectFactoryConstructor; -import org.apache.qpid.server.model.State; @ManagedObject( category = false , type = "test" ) public class TestRootCategoryImpl extends AbstractConfiguredObject<TestRootCategoryImpl> @@ -52,6 +52,12 @@ public class TestRootCategoryImpl extends AbstractConfiguredObject<TestRootCateg @ManagedAttributeField private String _validValue; + @ManagedAttributeField + private TestEnum _enumValue; + + @ManagedAttributeField + private Set<TestEnum> _enumSetValues; + @ManagedObjectFactoryConstructor public TestRootCategoryImpl(final Map<String, Object> attributes) @@ -104,6 +110,18 @@ public class TestRootCategoryImpl extends AbstractConfiguredObject<TestRootCateg } @Override + public TestEnum getEnumValue() + { + return _enumValue; + } + + @Override + public Set<TestEnum> getEnumSetValues() + { + return _enumSetValues; + } + + @Override public String getValidValue() { return _validValue; |
