Author: kwall
Date: Tue Oct 21 10:22:24 2014
New Revision: 1633338

URL: http://svn.apache.org/r1633338
Log:
QPID-6168: [Java Broker] Valid values check not to be applied for non mandatory 
fields where no value passed

Modified:
    
qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java
    
qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/AbstractConfiguredObjectTest.java

Modified: 
qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java?rev=1633338&r1=1633337&r2=1633338&view=diff
==============================================================================
--- 
qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java
 (original)
+++ 
qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java
 Tue Oct 21 10:22:24 2014
@@ -755,7 +755,7 @@ public abstract class AbstractConfigured
                     if (desiredValueOrDefault != null && 
!checkValidValues(autoAttr, desiredValueOrDefault))
                     {
                         throw new IllegalConfigurationException("Attribute '" 
+ autoAttr.getName()
-                                                                + "' of 
instance of "+ getClass().getName()
+                                                                + "' instance 
of "+ getClass().getName()
                                                                 + " named '" + 
getName() + "'"
                                                                 + " cannot 
have value '" + desiredValueOrDefault + "'"
                                                                 + ". Valid 
values are: "
@@ -1544,10 +1544,11 @@ public abstract class AbstractConfigured
                 {
                     Object desiredValue = 
autoAttr.getValue(proxyForValidation);
 
-                    if (!checkValidValues(autoAttr, desiredValue))
+                    if ((autoAttr.isMandatory() || desiredValue != null)
+                        && !checkValidValues(autoAttr, desiredValue))
                     {
                         throw new IllegalConfigurationException("Attribute '" 
+ autoAttr.getName()
-                                                                + "' of 
instance of "+ getClass().getName()
+                                                                + "' instance 
of "+ getClass().getName()
                                                                 + " named '" + 
getName() + "'"
                                                                 + " cannot 
have value '" + desiredValue + "'"
                                                                 + ". Valid 
values are: "

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=1633338&r1=1633337&r2=1633338&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
 Tue Oct 21 10:22:24 2014
@@ -99,11 +99,30 @@ public class AbstractConfiguredObjectTes
         attributes.put(ConfiguredObject.NAME, objectName);
         attributes.put(TestRootCategory.DEFAULTED_VALUE, "override");
 
-        TestRootCategory object2 = 
_model.getObjectFactory().create(TestRootCategory.class,
+        TestRootCategory object = 
_model.getObjectFactory().create(TestRootCategory.class,
                                                                    attributes);
 
-        assertEquals(objectName, object2.getName());
-        assertEquals("override", object2.getDefaultedValue());
+        assertEquals(objectName, object.getName());
+        assertEquals("override", object.getDefaultedValue());
+
+    }
+
+    public void testOverriddenDefaultedAttributeValueRevertedToDefault()
+    {
+        final String objectName = "myName";
+
+        Map<String, Object> attributes = new HashMap<>();
+        attributes.put(ConfiguredObject.NAME, objectName);
+        attributes.put(TestRootCategory.DEFAULTED_VALUE, "override");
+
+        TestRootCategory object = 
_model.getObjectFactory().create(TestRootCategory.class,
+                                                                   attributes);
+
+        assertEquals(objectName, object.getName());
+        assertEquals("override", object.getDefaultedValue());
+
+        
object.setAttributes(Collections.singletonMap(TestRootCategory.DEFAULTED_VALUE, 
null));
+        assertEquals(TestRootCategory.DEFAULTED_VALUE_DEFAULT, 
object.getDefaultedValue());
     }
 
     public void testEnumAttributeValueFromString()
@@ -534,7 +553,7 @@ public class AbstractConfiguredObjectTes
         TestRootCategory object = 
_model.getObjectFactory().create(TestRootCategory.class, legalCreateAttributes);
         assertEquals(TestRootCategory.VALID_VALUE1, object.getValidValue());
 
-        object.setAttribute(TestRootCategory.VALID_VALUE, 
TestRootCategory.VALID_VALUE1, TestRootCategory.VALID_VALUE2);
+        
object.setAttributes(Collections.singletonMap(TestRootCategory.VALID_VALUE,TestRootCategory.VALID_VALUE2));
         assertEquals(TestRootCategory.VALID_VALUE2, object.getValidValue());
 
         try
@@ -549,6 +568,9 @@ public class AbstractConfiguredObjectTes
 
         assertEquals(TestRootCategory.VALID_VALUE2, object.getValidValue());
 
+        
object.setAttributes(Collections.singletonMap(TestRootCategory.VALID_VALUE,null));
+        assertNull(object.getValidValue());
+
     }
 
     public void testCreateEnforcesAttributeValidValuesWithSets() throws 
Exception



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

Reply via email to