[rhq] modules/plugins
Heiko W. Rupp
pilhuhn at fedoraproject.org
Thu Aug 9 18:20:57 UTC 2012
modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/ConfigurationWriteDelegate.java | 20 ++
modules/plugins/jboss-as-7/src/main/resources/META-INF/rhq-plugin.xml | 2
modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/ConfigurationUpdatingTest.java | 86 ++++++++++
modules/plugins/jboss-as-7/src/test/resources/test-plugin.xml | 33 +++
4 files changed, 139 insertions(+), 2 deletions(-)
New commits:
commit 77cee38075da30754fa6081dcf5cfe239f547a71
Author: Heiko W. Rupp <hwr at redhat.com>
Date: Thu Aug 9 14:20:52 2012 -0400
BZ 839320 When a property is required and the user has not explicitly choosen a value and there is a defaultValue, use this.
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 366f840..86ba37a 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
@@ -500,7 +500,25 @@ public class ConfigurationWriteDelegate implements ConfigurationFacet {
entry = new SimpleEntry<String, Object>(realName, null);
}
} else {
- Object o = getObjectWithType(propertyDefinition,property.getStringValue());
+ Object o;
+/*
+ If no value is given in the property and the property is required,
+ we'll take the default value from the definition. This can e.g. happen
+ when you have
+ <c:simple-property name="mode" required="true" type="string" readOnly="false" default="SYNC" defaultValue="SYNC">
+ <c:property-options>
+ <c:option value="SYNC"/>
+ <c:option value="ASYNC"/>
+ </c:property-options>
+ </c:simple-property>
+ and the user chooses to just keep the default choice in the ui
+*/
+
+ if (property.getStringValue()==null && propertyDefinition.isRequired()) {
+ o = getObjectWithType(propertyDefinition,propertyDefinition.getDefaultValue());
+ } else {
+ o = getObjectWithType(propertyDefinition,property.getStringValue());
+ }
entry = new SimpleEntry<String, Object>(name, o);
}
diff --git a/modules/plugins/jboss-as-7/src/main/resources/META-INF/rhq-plugin.xml b/modules/plugins/jboss-as-7/src/main/resources/META-INF/rhq-plugin.xml
index 77bacfb..6a6a40c 100644
--- a/modules/plugins/jboss-as-7/src/main/resources/META-INF/rhq-plugin.xml
+++ b/modules/plugins/jboss-as-7/src/main/resources/META-INF/rhq-plugin.xml
@@ -11350,7 +11350,7 @@
</c:property-options>
</c:simple-property>
<c:simple-property name="jndi-name" required="false" type="string" readOnly="false" description="The jndi-name to which to bind this cache instance."/>
- <c:simple-property name="mode" required="true" type="string" readOnly="false" default="SYNC" description="Sets the clustered cache mode, ASYNC for asynchronous operation, or SYNC for synchronous operation.">
+ <c:simple-property name="mode" required="true" type="string" readOnly="false" default="SYNC" defaultValue="SYNC" description="Sets the clustered cache mode, ASYNC for asynchronous operation, or SYNC for synchronous operation.">
<c:property-options>
<c:option value="SYNC"/>
<c:option value="ASYNC"/>
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 ba2f13c..21e3d5f 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
@@ -862,4 +862,90 @@ public class ConfigurationUpdatingTest extends AbstractConfigurationHandlingTest
assert cop.numberOfSteps() == 1 : "One step was expected, but got " + cop.numberOfSteps();
}
+
+ /**
+ * Test that if a property is required and has a defaultValue and the user just uses this,
+ * we actually pass this default to the operation, as e.g. the CreateResourceReport may not
+ * include the default value.
+ * @throws Exception If anything goes wrong
+ */
+ public void testSimpleWithDefault1() throws Exception {
+
+ ConfigurationDefinition definition = loadDescriptor("simpleWithDefault1");
+
+ FakeConnection connection = new FakeConnection();
+
+ ConfigurationWriteDelegate delegate = new ConfigurationWriteDelegate(definition, connection, null);
+
+ Configuration conf = new Configuration();
+ PropertySimple ps = new PropertySimple("mode",null);
+ conf.put(ps);
+
+ 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 props.get("name").equals("mode");
+ assert props.get("value").equals("SYNC"); // the defaultValue
+ }
+
+ /**
+ * Check that if a property is required and has no defaultValue, but the user provides a value,
+ * that the user provided value ends up in the operation
+ * @throws Exception
+ */
+ public void testSimpleWithDefault2() throws Exception {
+
+ ConfigurationDefinition definition = loadDescriptor("simpleWithDefault2");
+
+ FakeConnection connection = new FakeConnection();
+
+ ConfigurationWriteDelegate delegate = new ConfigurationWriteDelegate(definition, connection, null);
+
+ Configuration conf = new Configuration();
+ PropertySimple ps = new PropertySimple("mode","ASYNC");
+ conf.put(ps);
+
+ 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 props.get("name").equals("mode");
+ assert props.get("value").equals("ASYNC"); // the user provided value
+ }
+
+ /**
+ * Check that if a property is required and has no defaultValue, and the user provides null
+ * as value, that we set null
+ * @throws Exception
+ */
+ public void testSimpleWithDefault3() throws Exception {
+
+ ConfigurationDefinition definition = loadDescriptor("simpleWithDefault2");
+
+ FakeConnection connection = new FakeConnection();
+
+ ConfigurationWriteDelegate delegate = new ConfigurationWriteDelegate(definition, connection, null);
+
+ Configuration conf = new Configuration();
+ PropertySimple ps = new PropertySimple("mode",null);
+ conf.put(ps);
+
+ 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 props.get("name").equals("mode");
+ assert props.get("value")==null; // no value
+ }
+
}
diff --git a/modules/plugins/jboss-as-7/src/test/resources/test-plugin.xml b/modules/plugins/jboss-as-7/src/test/resources/test-plugin.xml
index 4350230..f10f52b 100644
--- a/modules/plugins/jboss-as-7/src/test/resources/test-plugin.xml
+++ b/modules/plugins/jboss-as-7/src/test/resources/test-plugin.xml
@@ -290,6 +290,37 @@
</resource-configuration>
</server>
+ <server name="simpleWithDefault1"
+ class="BaseComponent"
+ discovery="SubsystemDiscovery">
+
+ <resource-configuration>
+ <c:simple-property name="mode" required="true" type="string" readOnly="false" default="SYNC" defaultValue="SYNC" >
+ <c:property-options>
+ <c:option value="SYNC"/>
+ <c:option value="ASYNC"/>
+ </c:property-options>
+ </c:simple-property>
+ </resource-configuration>
+
+ </server>
+
+ <server name="simpleWithDefault2"
+ class="BaseComponent"
+ discovery="SubsystemDiscovery">
+
+ <resource-configuration>
+ <c:simple-property name="mode" required="true" type="string" readOnly="false" default="SYNC" >
+ <c:property-options>
+ <c:option value="SYNC"/>
+ <c:option value="ASYNC"/>
+ </c:property-options>
+ </c:simple-property>
+ </resource-configuration>
+
+ </server>
+
+
<!-- Simple c:group entries from descriptor with no special handling. -->
<service name="simpleGroupNoSpecial"
class="BaseComponent"
@@ -327,4 +358,6 @@
</resource-configuration>
</service>
+
+
</plugin>
\ No newline at end of file
More information about the rhq-commits
mailing list