summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Negrea <snegrea@redhat.com>2012-08-29 03:39:35 (GMT)
committerStefan Negrea <snegrea@redhat.com>2012-08-29 03:39:35 (GMT)
commitc1655d4d576311b9034a31b505e75981b1d6e720 (patch)
treec53017d7bf06a518a31ba05241b5608d518ffe1c
parente1d2190442ddcfe023696fa59b040f78929a27c6 (diff)
downloadrhq-c1655d4d576311b9034a31b505e75981b1d6e720.zip
rhq-c1655d4d576311b9034a31b505e75981b1d6e720.tar.gz
rhq-c1655d4d576311b9034a31b505e75981b1d6e720.tar.xz
[BZ 852552] Send unset properties to AS7 as null.
Existing code was not sending updates for unset properties at all to AS7 making it impossible to unset (or set to empty) a property after it was set to something not null.
-rw-r--r--modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ConfigurationWriteDelegate.java17
-rw-r--r--modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/ConfigurationUpdatingTest.java21
2 files changed, 28 insertions, 10 deletions
diff --git a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ConfigurationWriteDelegate.java b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ConfigurationWriteDelegate.java
index aad2105..f73ccf5 100644
--- a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ConfigurationWriteDelegate.java
+++ b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ConfigurationWriteDelegate.java
@@ -431,16 +431,25 @@ public class ConfigurationWriteDelegate implements ConfigurationFacet {
private void createWriteAttributePropertySimple(CompositeOperation cop, PropertySimple property,
PropertyDefinitionSimple propertyDefinition, Address address) {
- // If the property value is null and the property is optional, skip too
- if (property.getStringValue() == null && !propertyDefinition.isRequired())
- return;
-
if (property.getName().endsWith(":ignore")) // Caller takes care
return;
if (propertyDefinition.isReadOnly() && !createChildRequested)
return;
+ //If the property value is null and the property is optional,
+ //then send default value or null to the server
+ if (property.getStringValue() == null && !propertyDefinition.isRequired()) {
+ String name = property.getName();
+ if (name.indexOf(':') != -1) {
+ name = name.substring(0, name.indexOf(":"));
+ }
+
+ Operation writeAttribute = new WriteAttribute(address, name, null);
+ cop.addStep(writeAttribute);
+ return;
+ }
+
SimpleEntry<String, Object> entry = this.preparePropertySimple(property, propertyDefinition);
Operation writeAttribute = new WriteAttribute(address, entry.getKey(), entry.getValue());
cop.addStep(writeAttribute);
diff --git a/modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/ConfigurationUpdatingTest.java b/modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/ConfigurationUpdatingTest.java
index 21e3d5f..48b6783 100644
--- a/modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/ConfigurationUpdatingTest.java
+++ b/modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/ConfigurationUpdatingTest.java
@@ -59,7 +59,6 @@ public class ConfigurationUpdatingTest extends AbstractConfigurationHandlingTest
public void test1() throws Exception {
ConfigurationDefinition definition = loadDescriptor("simple1");
-
FakeConnection connection = new FakeConnection();
ConfigurationWriteDelegate delegate = new ConfigurationWriteDelegate(definition, connection, null);
@@ -70,12 +69,22 @@ public class ConfigurationUpdatingTest extends AbstractConfigurationHandlingTest
CompositeOperation cop = delegate.updateGenerateOperationFromProperties(conf, new Address());
- assert cop.numberOfSteps() == 1;
- Operation step1 = cop.step(0);
- assert step1.getOperation().equals("write-attribute");
- Map<String, Object> props = step1.getAdditionalProperties();
- assert props.size() == 2;
+ Assert.assertEquals(cop.numberOfSteps(), 2);
+ for (int i = 0; i < cop.numberOfSteps(); i++) {
+ Operation step = cop.step(0);
+ Assert.assertEquals(step.getOperation(), "write-attribute");
+ Map<String, Object> stepProps = step.getAdditionalProperties();
+ Assert.assertEquals(stepProps.size(), 2);
+
+ if (stepProps.get("name").equals("needed")) {
+ Assert.assertEquals(stepProps.get("value"), "test");
+ } else if (stepProps.get("name").equals("optional")) {
+ Assert.assertEquals(stepProps.get("value"), null);
+ } else {
+ Assert.fail("Unexepected property found!");
+ }
+ }
}
public void test2() throws Exception {