summaryrefslogtreecommitdiff
path: root/qpid/java
diff options
context:
space:
mode:
authorKeith Wall <kwall@apache.org>2014-10-21 10:22:24 +0000
committerKeith Wall <kwall@apache.org>2014-10-21 10:22:24 +0000
commit81b45698f40ea592c27f57c6d183dbbb501fd1bf (patch)
tree081457a26a002562dda3d57f14fb779ec20de218 /qpid/java
parent7924daede51ce20959c90d16d38930c7a92f69f1 (diff)
downloadqpid-python-81b45698f40ea592c27f57c6d183dbbb501fd1bf.tar.gz
QPID-6168: [Java Broker] Valid values check not to be applied for non mandatory fields where no value passed
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1633338 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java')
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java7
-rw-r--r--qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/AbstractConfiguredObjectTest.java30
2 files changed, 30 insertions, 7 deletions
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java
index bddda97f1b..9a1307c8dd 100644
--- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java
+++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java
@@ -755,7 +755,7 @@ public abstract class AbstractConfiguredObject<X extends ConfiguredObject<X>> im
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 AbstractConfiguredObject<X extends ConfiguredObject<X>> im
{
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: "
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 3764461841..9e1669fb28 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
@@ -99,11 +99,30 @@ public class AbstractConfiguredObjectTest extends QpidTestCase
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 AbstractConfiguredObjectTest extends QpidTestCase
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 AbstractConfiguredObjectTest extends QpidTestCase
assertEquals(TestRootCategory.VALID_VALUE2, object.getValidValue());
+ object.setAttributes(Collections.singletonMap(TestRootCategory.VALID_VALUE,null));
+ assertNull(object.getValidValue());
+
}
public void testCreateEnforcesAttributeValidValuesWithSets() throws Exception