modules/enterprise/remoting/scripts/src/test/script/org/rhq/enterprise/remoting/cli/test_ConfigurationManager.js
| 94 ++++++++--
1 file changed, 81 insertions(+), 13 deletions(-)
New commits:
commit 9e269d8ce6dc397d83bb3836748f23fca49a58e0
Merge: 2f7c427... 8bdcdaf...
Author: John Sanda <john(a)localhost.localdomain>
Date: Mon Nov 30 16:25:51 2009 -0500
Merge branch 'raw-config' of
ssh://git.fedorahosted.org/git/rhq/rhq into
raw-config
commit 2f7c42750ea87ff28fbb86adf36f3ed6315839ee
Author: John Sanda <john(a)localhost.localdomain>
Date: Mon Nov 30 16:23:07 2009 -0500
[US 910] Refactoring testGetAndUpdateRawConfiguration() to eliminate some duplicate
code
diff --git
a/modules/enterprise/remoting/scripts/src/test/script/org/rhq/enterprise/remoting/cli/test_ConfigurationManager.js
b/modules/enterprise/remoting/scripts/src/test/script/org/rhq/enterprise/remoting/cli/test_ConfigurationManager.js
index f70682d..ed964ef 100644
---
a/modules/enterprise/remoting/scripts/src/test/script/org/rhq/enterprise/remoting/cli/test_ConfigurationManager.js
+++
b/modules/enterprise/remoting/scripts/src/test/script/org/rhq/enterprise/remoting/cli/test_ConfigurationManager.js
@@ -60,21 +60,8 @@ function testGetAndUpdateRawConfiguration() {
Assert.assertNotNull(rawServer, "Failed to find '" + resourceName +
"'");
- var latestUpdate =
ConfigurationManager.getLatestResourceConfigurationUpdate(rawServer.id);
-
- Assert.assertNotNull(latestUpdate, "Failed to find latest resource configuration
update for '" + resourceName + "'");
- Assert.assertTrue(
- latestUpdate.configuration.rawConfigurations.size() > 0,
- "Expected to find at least one raw config file for '" +
"'"
- );
-
- var rawConfigs = java.util.LinkedList(latestUpdate.configuration.rawConfigurations);
- var rawConfig = rawConfigs.get(0);
-
- Assert.assertTrue(
- rawConfig.contents.length > 0,
- "Contents of raw config file for '" + resourceName + "'
should not be empty."
- );
+ var latestUpdate = loadLatestResourceConfigurationUpdate(resourceName,
rawServer.id);
+ var rawConfig = getRawConfig(resourceName, latestUpdate.configuration, 0);
var contents = java.lang.String(rawConfig.contents);
var modifiedContents = java.lang.StringBuilder(contents).append("\nModified at
").append(getDate()).toString();
@@ -83,16 +70,9 @@ function testGetAndUpdateRawConfiguration() {
var configUdpate = ConfigurationManager.updateResourceConfiguration(rawServer.id,
latestUpdate.configuration);
- while (ConfigurationManager.isResourceConfigurationUpdateInProgress(rawServer.id)) {
- java.lang.Thread.sleep(1000);
- }
+ waitForResourceConfigUpdateToComplete(rawServer.id);
- latestUpdate =
ConfigurationManager.getLatestResourceConfigurationUpdate(rawServer.id);
- Assert.assertNotNull(latestUpdate, "Failed to find latest resource configuration
update for '" + resourceName + "'");
- Assert.assertTrue(
- latestUpdate.configuration.rawConfigurations.size() > 0,
- "Expected to find at least one raw config file for '" +
"'"
- );
+ latestUpdate = loadLatestResourceConfigurationUpdate(resourceName, rawServer.id);
rawConfigs = java.util.LinkedList(latestUpdate.configuration.rawConfigurations);
rawConfig = rawConfigs.get(0);
@@ -105,11 +85,41 @@ function testGetAndUpdateRawConfiguration() {
);
}
+function loadLatestResourceConfigurationUpdate(resourceName, resourceId) {
+ var latestUpdate =
ConfigurationManager.getLatestResourceConfigurationUpdate(resourceId);
+
+ Assert.assertNotNull(latestUpdate, "Failed to find latest resource configuration
update for '" + resourceName + "'");
+ Assert.assertTrue(
+ latestUpdate.configuration.rawConfigurations.size() > 0,
+ "Expected to find at least one raw config file for '" +
"'"
+ );
+
+ return latestUpdate;
+}
+
+function getRawConfig(resourceName, configuration, index) {
+ var rawConfigs = java.util.LinkedList(configuration.rawConfigurations);
+ var rawConfig = rawConfigs.get(index);
+
+ Assert.assertTrue(
+ rawConfig.contents.length > 0,
+ "Contents of raw config file for '" + resourceName + "'
should not be empty."
+ );
+
+ return rawConfig;
+}
+
function getDate() {
var format = java.text.DateFormat.getDateInstance();
return format.format(java.util.Date());
}
+function waitForResourceConfigUpdateToComplete(resourceId) {
+ while (ConfigurationManager.isResourceConfigurationUpdateInProgress(resourceId)) {
+ java.lang.Thread.sleep(1000);
+ }
+}
+
//function testUpdatePluginConfiguration() {
// var resource = findService('service-beta-0', 'server-omega-0');
// var pluginConfig = ConfigurationManager.getPluginConfiguration(resource.id);
commit 9735ccd93be5c8d7bbd7578f014106f655fcbf25
Author: John Sanda <john(a)localhost.localdomain>
Date: Mon Nov 30 16:05:12 2009 -0500
[US 910]
Adding a CLI script test to read and update a raw config.
diff --git
a/modules/enterprise/remoting/scripts/src/test/script/org/rhq/enterprise/remoting/cli/test_ConfigurationManager.js
b/modules/enterprise/remoting/scripts/src/test/script/org/rhq/enterprise/remoting/cli/test_ConfigurationManager.js
index 7157fb9..f70682d 100644
---
a/modules/enterprise/remoting/scripts/src/test/script/org/rhq/enterprise/remoting/cli/test_ConfigurationManager.js
+++
b/modules/enterprise/remoting/scripts/src/test/script/org/rhq/enterprise/remoting/cli/test_ConfigurationManager.js
@@ -26,11 +26,12 @@ rhq.login('rhqadmin', 'rhqadmin');
skippedTests.push('testUpdateResourceGroupConfiguration');
executeAllTests();
+//executeTests(['testGetAndUpdateRawConfiguration']);
rhq.logout();
function testUpdateResourceConfiguration() {
- var resource = findService('service-beta-1', 'server-omega-1');
+ var resource = findResourceByNameAndParentName('service-beta-1',
'server-omega-1');
var config = ConfigurationManager.getResourceConfiguration(resource.id);
var propertyName = 'beta-config0';
@@ -53,25 +54,81 @@ function testUpdateResourceConfiguration() {
Assert.assertEquals(updatedProperty.stringValue, propertyValue, 'Failed to update
resource configuration');
}
-function testUpdatePluginConfiguration() {
- var resource = findService('service-beta-0', 'server-omega-0');
- var pluginConfig = ConfigurationManager.getPluginConfiguration(resource.id);
+function testGetAndUpdateRawConfiguration() {
+ var resourceName = 'Raw Server'
+ var rawServer = findResourceByNameAndParentName(resourceName, 'localhost');
- var propertyName = 'beta-property0';
- var propertyValue = 'updated property value -- ' + java.util.Date();
+ Assert.assertNotNull(rawServer, "Failed to find '" + resourceName +
"'");
- var property = pluginConfig.getSimple(propertyName);
+ var latestUpdate =
ConfigurationManager.getLatestResourceConfigurationUpdate(rawServer.id);
- property.setStringValue(propertyValue);
+ Assert.assertNotNull(latestUpdate, "Failed to find latest resource configuration
update for '" + resourceName + "'");
+ Assert.assertTrue(
+ latestUpdate.configuration.rawConfigurations.size() > 0,
+ "Expected to find at least one raw config file for '" +
"'"
+ );
+
+ var rawConfigs = java.util.LinkedList(latestUpdate.configuration.rawConfigurations);
+ var rawConfig = rawConfigs.get(0);
+
+ Assert.assertTrue(
+ rawConfig.contents.length > 0,
+ "Contents of raw config file for '" + resourceName + "'
should not be empty."
+ );
+
+ var contents = java.lang.String(rawConfig.contents);
+ var modifiedContents = java.lang.StringBuilder(contents).append("\nModified at
").append(getDate()).toString();
+
+ rawConfig.contents = modifiedContents.getBytes();
- var configUpdate = ConfigurationManager.updatePluginConfiguration(resource.id,
pluginConfig);
+ var configUdpate = ConfigurationManager.updateResourceConfiguration(rawServer.id,
latestUpdate.configuration);
- pluginConfig = ConfigurationManager.getPluginConfiguration(resource.id);
- var updatedProperty = pluginConfig.getSimple(propertyName);
+ while (ConfigurationManager.isResourceConfigurationUpdateInProgress(rawServer.id)) {
+ java.lang.Thread.sleep(1000);
+ }
+
+ latestUpdate =
ConfigurationManager.getLatestResourceConfigurationUpdate(rawServer.id);
+ Assert.assertNotNull(latestUpdate, "Failed to find latest resource configuration
update for '" + resourceName + "'");
+ Assert.assertTrue(
+ latestUpdate.configuration.rawConfigurations.size() > 0,
+ "Expected to find at least one raw config file for '" +
"'"
+ );
+
+ rawConfigs = java.util.LinkedList(latestUpdate.configuration.rawConfigurations);
+ rawConfig = rawConfigs.get(0);
+ var updatedContents = rawConfig.contents;
+
+ Assert.assertEquals(
+ java.lang.String(updatedContents),
+ java.lang.String(modifiedContents),
+ "Failed to update raw config for '" + resourceName +
"'"
+ );
+}
- Assert.assertEquals(updatedProperty.stringValue, propertyValue, 'Failed to update
plugin configuration');
+function getDate() {
+ var format = java.text.DateFormat.getDateInstance();
+ return format.format(java.util.Date());
}
+//function testUpdatePluginConfiguration() {
+// var resource = findService('service-beta-0', 'server-omega-0');
+// var pluginConfig = ConfigurationManager.getPluginConfiguration(resource.id);
+//
+// var propertyName = 'beta-property0';
+// var propertyValue = 'updated property value -- ' + java.util.Date();
+//
+// var property = pluginConfig.getSimple(propertyName);
+//
+// property.setStringValue(propertyValue);
+//
+// var configUpdate = ConfigurationManager.updatePluginConfiguration(resource.id,
pluginConfig);
+//
+// pluginConfig = ConfigurationManager.getPluginConfiguration(resource.id);
+// var updatedProperty = pluginConfig.getSimple(propertyName);
+//
+// Assert.assertEquals(updatedProperty.stringValue, propertyValue, 'Failed to
update plugin configuration');
+//}
+
// This test is failing I think due to the asynchronous nature of the operations
involved. I have verified through the
// web UI that the configuration updates are actually happening. I just need to figure
out how to make the test wait
// so that it can (consistently) get the udpated values.
@@ -112,10 +169,11 @@ function testUpdateResourceGroupConfiguration() {
}
}
-function findService(name, parentName) {
+function findResourceByNameAndParentName(name, parentName) {
var criteria = ResourceCriteria();
criteria.addFilterName(name);
criteria.addFilterParentResourceName(parentName);
+ criteria.strict = true;
return ResourceManager.findResourcesByCriteria(criteria).get(0);
}