Author: kwall
Date: Mon Oct 20 19:57:57 2014
New Revision: 1633216

URL: http://svn.apache.org/r1633216
Log:
QPID-6168: [Java Broker] Improve unit tests around valid values and setting of 
enums

Added:
    
qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestEnum.java
Modified:
    
qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/AbstractConfiguredObjectTest.java
    
qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/Test2RootCategoryImpl.java
    
qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestRootCategory.java
    
qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestRootCategoryImpl.java

Modified: 
qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/AbstractConfiguredObjectTest.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/AbstractConfiguredObjectTest.java?rev=1633216&r1=1633215&r2=1633216&view=diff
==============================================================================
--- 
qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/AbstractConfiguredObjectTest.java
 (original)
+++ 
qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/AbstractConfiguredObjectTest.java
 Mon Oct 20 19:57:57 2014
@@ -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 AbstractConfiguredObjectTes
         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 AbstractConfiguredObjectTes
                                                                     
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 AbstractConfiguredObjectTes
         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 AbstractConfiguredObjectTes
         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 AbstractConfiguredObjectTes
 
     }
 
+    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)));
+        }
+    }
+
 }

Modified: 
qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/Test2RootCategoryImpl.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/Test2RootCategoryImpl.java?rev=1633216&r1=1633215&r2=1633216&view=diff
==============================================================================
--- 
qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/Test2RootCategoryImpl.java
 (original)
+++ 
qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/Test2RootCategoryImpl.java
 Mon Oct 20 19:57:57 2014
@@ -23,6 +23,7 @@ package org.apache.qpid.server.model.tes
 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.Abst
 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 exten
     @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 exten
         return _mapValue;
     }
 
+    @Override
+    public TestEnum getEnumValue()
+    {
+        return _enumValue;
+    }
+
+    @Override
+    public Set<TestEnum> getEnumSetValues()
+    {
+        return _enumSetValues;
+    }
+
     public static Collection<String> functionGeneratedValidValues()
     {
         return Collections.singleton("generated");

Added: 
qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestEnum.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestEnum.java?rev=1633216&view=auto
==============================================================================
--- 
qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestEnum.java
 (added)
+++ 
qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestEnum.java
 Mon Oct 20 19:57:57 2014
@@ -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;
+}

Modified: 
qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestRootCategory.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestRootCategory.java?rev=1633216&r1=1633215&r2=1633216&view=diff
==============================================================================
--- 
qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestRootCategory.java
 (original)
+++ 
qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestRootCategory.java
 Mon Oct 20 19:57:57 2014
@@ -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 exte
     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 exte
     @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();
+
 }

Modified: 
qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestRootCategoryImpl.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestRootCategoryImpl.java?rev=1633216&r1=1633215&r2=1633216&view=diff
==============================================================================
--- 
qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestRootCategoryImpl.java
 (original)
+++ 
qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestRootCategoryImpl.java
 Mon Oct 20 19:57:57 2014
@@ -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.Abst
 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 extend
     @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 extend
     }
 
     @Override
+    public TestEnum getEnumValue()
+    {
+        return _enumValue;
+    }
+
+    @Override
+    public Set<TestEnum> getEnumSetValues()
+    {
+        return _enumSetValues;
+    }
+
+    @Override
     public String getValidValue()
     {
         return _validValue;



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to