Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'hqapi-2.x'

  • Loading branch information...
commit 40f020d6324569225634bfd839465cea942a497d 2 parents 54c1442 + fb1c864
Ryan Morgan authored
View
13 hqu/hqapi1/app/ResourceController.groovy
@@ -661,8 +661,19 @@ class ResourceController extends ApiController {
}
}
+ def existingConfig = resource.getConfig()
+ // 2nd pass over configuration to unset any variables that
+ // may already exist in the existing config, but are empty in
+ // the configuration being set.
+ xmlResource['ResourceConfig'].each {
+ if ((it.'@value' && it.'@value'.length() > 0) ||
+ (it.'@value' != null && !it.'@value'.equals(existingConfig[it.'@key']?.value))) {
+ config[it.'@key'] = it.'@value'
+ }
+ }
+
// Update
- if (!configsEqual(resource.getConfig(), config)) {
+ if (!configsEqual(existingConfig, config)) {
try {
resource.setConfig(config, user)
} catch (Throwable t) {
View
73 src/org/hyperic/hq/hqapi1/test/ResourceUpdate_test.java
@@ -95,15 +95,86 @@ public void testUpdateConfig() throws Exception {
hqAssertSuccess(updateResponse);
ResourceResponse getResponse = api.getResource(createdResource.getId(),
- false, false);
+ true, false);
hqAssertSuccess(getResponse);
Resource updatedResource = getResponse.getResource();
+ assertTrue("No configuration found for " + updatedResource.getName(),
+ updatedResource.getResourceConfig().size() > 0);
+ boolean foundHostname = false;
for (ResourceConfig c : updatedResource.getResourceConfig()) {
if (c.getKey().equals("hostname")) {
assertEquals(c.getValue(), UPDATED_HOSTNAME);
+ foundHostname = true;
}
}
+ assertTrue("Unable to find hostname configuration for " + updatedResource.getName(),
+ foundHostname);
+
+ // Cannot delete resources soon after modifying them..
+ try {
+ Thread.sleep(2000);
+ } catch (InterruptedException e) {
+ // Ignore
+ }
+
+ // Cleanup
+ StatusResponse deleteResponse = api.deleteResource(updatedResource.getId());
+ hqAssertSuccess(deleteResponse);
+ }
+
+ public void testUpdateResetConfig() throws Exception {
+ ResourceApi api = getApi().getResourceApi();
+ Resource createdResource = createTestHTTPService();
+
+ // Add pattern attribute
+ ResourceConfig patternConfig = new ResourceConfig();
+ patternConfig.setKey("pattern");
+ patternConfig.setValue("html");
+ createdResource.getResourceConfig().add(patternConfig);
+
+ StatusResponse updateResponse = api.updateResource(createdResource);
+ hqAssertSuccess(updateResponse);
+
+ ResourceResponse getResponse = api.getResource(createdResource.getId(),
+ true, false);
+ hqAssertSuccess(getResponse);
+
+ Resource updatedResource = getResponse.getResource();
+ assertTrue("No configuration found for " + updatedResource.getName(),
+ updatedResource.getResourceConfig().size() > 0);
+ boolean foundPattern = false;
+ for (ResourceConfig c : updatedResource.getResourceConfig()) {
+ if (c.getKey().equals("pattern")) {
+ assertEquals(c.getValue(), "html");
+ // Reset to ""
+ c.setValue("");
+ foundPattern = true;
+ }
+ }
+
+ assertTrue("Unable to find pattern configuration for " + updatedResource.getName(),
+ foundPattern);
+
+ updateResponse = api.updateResource(updatedResource);
+ hqAssertSuccess(updateResponse);
+
+ getResponse = api.getResource(createdResource.getId(), true, false);
+ hqAssertSuccess(getResponse);
+
+ updatedResource = getResponse.getResource();
+ assertTrue("No configuration found for " + updatedResource.getName(),
+ updatedResource.getResourceConfig().size() > 0);
+ foundPattern = false;
+ for (ResourceConfig c : updatedResource.getResourceConfig()) {
+ if (c.getKey().equals("pattern")) {
+ assertEquals("pattern is not empty", c.getValue(), "");
+ foundPattern = true;
+ }
+ }
+
+ assertTrue("Unable to find pattern configuration for " + updatedResource.getName(),
+ foundPattern);
pauseTest();

0 comments on commit 40f020d

Please sign in to comment.
Something went wrong with that request. Please try again.