modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/ConfigManagementFactoryImpl.java
| 4
modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/LoadStructured.java
| 73 ---
modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/LoadStructuredAndRaw.java
| 90 ----
modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/StructuredAndRawConfigManagement.java
| 90 ++++
modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/StructuredConfigManagement.java
| 75 +++
modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/ConfigManagementFactoryImplTest.java
| 8
modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/LoadStructuredAndRawTest.java
| 191 ----------
modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/LoadStructuredTest.java
| 126 ------
modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/StructuredAndRawConfigManagementTest.java
| 191 ++++++++++
modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/StructuredConfigManagementTest.java
| 147 +++++++
10 files changed, 509 insertions(+), 486 deletions(-)
New commits:
commit f013bcd501ef15a8e5f93790629a44ba6796a741
Author: John Sanda <john(a)localhost.localdomain>
Date: Mon Nov 30 16:57:00 2009 -0500
[US 6] Adding support for updates of structured config with new
ResourceConfigurationFacet
Renaming some classes to be consistent with renamed interface.
diff --git
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/ConfigManagementFactoryImpl.java
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/ConfigManagementFactoryImpl.java
index 66aef29..6193fd2 100644
---
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/ConfigManagementFactoryImpl.java
+++
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/ConfigManagementFactoryImpl.java
@@ -64,7 +64,7 @@ public class ConfigManagementFactoryImpl implements
ConfigManagementFactory {
ResourceType resourceType = componentService.getResourceType(resourceId);
if (isStructured(resourceType)) {
- return new LoadStructured();
+ return new StructuredConfigManagement();
}
if (isRaw(resourceType)) {
@@ -72,7 +72,7 @@ public class ConfigManagementFactoryImpl implements
ConfigManagementFactory {
}
// else format is both structured and raw
- return new LoadStructuredAndRaw();
+ return new StructuredAndRawConfigManagement();
}
private boolean isLegacyVersion(String ampsVersion) {
diff --git
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/LoadStructured.java
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/LoadStructured.java
deleted file mode 100644
index 5e76590..0000000
---
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/LoadStructured.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * RHQ Management Platform
- * Copyright (C) 2005-2008 Red Hat, Inc.
- * All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation, and/or the GNU Lesser
- * General Public License, version 2.1, also as published by the Free
- * Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License and the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU General Public License
- * and the GNU Lesser General Public License along with this program;
- * if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.rhq.core.pc.configuration;
-
-import org.rhq.core.domain.configuration.Configuration;
-import org.rhq.core.domain.resource.ResourceType;
-import org.rhq.core.clientapi.agent.PluginContainerException;
-import org.rhq.core.pluginapi.configuration.ResourceConfigurationFacet;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import java.util.List;
-
-public class LoadStructured extends ConfigManagementSupport {
-
- private final Log log = LogFactory.getLog(LoadStructured.class);
-
- public Configuration execute(int resourceId) throws PluginContainerException {
- ResourceConfigurationFacet facet = loadResouceConfiguratonFacet(resourceId);
-
- Configuration configuration = facet.loadStructuredConfiguration();
-
- if (configuration == null) {
- return null;
- }
-
- ResourceType resourceType = componentService.getResourceType(resourceId);
-
- if (configuration.getNotes() == null) {
- configuration.setNotes("Resource config for " +
resourceType.getName() + " Resource w/ id " + resourceId);
- }
-
- configUtilityService.normalizeConfiguration(configuration,
resourceType.getResourceConfigurationDefinition());
- List<String> errorMsgs =
configUtilityService.validateConfiguration(configuration,
- resourceType.getResourceConfigurationDefinition());
-
- logErrorMsgs(errorMsgs, resourceType);
-
- return configuration;
- }
-
- private void logErrorMsgs(List<String> errorMsgs, ResourceType resourceType) {
- for (String errorMessage : errorMsgs) {
- log.warn("Plugin Error: Invalid " + resourceType.getName() + "
Resource configuration returned by "
- + resourceType.getPlugin() + " plugin - " + errorMessage);
- }
- }
-
- public void executeUpdate(int resourceId, Configuration configuration)
- throws PluginContainerException {
- }
-}
diff --git
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/LoadStructuredAndRaw.java
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/LoadStructuredAndRaw.java
deleted file mode 100644
index cbfca94..0000000
---
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/LoadStructuredAndRaw.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * RHQ Management Platform
- * Copyright (C) 2005-2008 Red Hat, Inc.
- * All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation, and/or the GNU Lesser
- * General Public License, version 2.1, also as published by the Free
- * Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License and the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU General Public License
- * and the GNU Lesser General Public License along with this program;
- * if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.rhq.core.pc.configuration;
-
-import static java.util.Collections.EMPTY_SET;
-
-import org.rhq.core.domain.configuration.Configuration;
-import org.rhq.core.domain.configuration.RawConfiguration;
-import org.rhq.core.domain.resource.ResourceType;
-import org.rhq.core.clientapi.agent.PluginContainerException;
-import org.rhq.core.pluginapi.configuration.ResourceConfigurationFacet;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import java.util.List;
-import java.util.Set;
-
-public class LoadStructuredAndRaw extends ConfigManagementSupport {
-
- private final Log log = LogFactory.getLog(LoadStructuredAndRaw.class);
-
- public Configuration execute(int resourceId) throws PluginContainerException {
- ResourceConfigurationFacet facet = loadResouceConfiguratonFacet(resourceId);
-
- Configuration configuration = facet.loadStructuredConfiguration();
- Set<RawConfiguration> rawConfigs = facet.loadRawConfigurations();
-
- if (configuration == null && rawConfigs == null) {
- return null;
- }
-
- if (configuration == null) {
- configuration = new Configuration();
- }
-
- if (rawConfigs == null) {
- rawConfigs = EMPTY_SET;
- }
-
- for (RawConfiguration rawConfig : rawConfigs) {
- configuration.addRawConfiguration(rawConfig);
- }
-
- ResourceType resourceType = componentService.getResourceType(resourceId);
-
- if (configuration.getNotes() == null) {
- configuration.setNotes("Resource config for " +
resourceType.getName() + " Resource w/ id " + resourceId);
- }
-
- configUtilityService.normalizeConfiguration(configuration,
resourceType.getResourceConfigurationDefinition());
- List<String> errorMsgs =
configUtilityService.validateConfiguration(configuration,
- resourceType.getResourceConfigurationDefinition());
-
- logErrorMsgs(errorMsgs, resourceType);
-
- return configuration;
- }
-
- private void logErrorMsgs(List<String> errorMsgs, ResourceType resourceType) {
- for (String errorMessage : errorMsgs) {
- log.warn("Plugin Error: Invalid " + resourceType.getName() + "
Resource configuration returned by "
- + resourceType.getPlugin() + " plugin - " + errorMessage);
- }
- }
-
- public void executeUpdate(int resourceId, Configuration configuration)
- throws PluginContainerException {
- }
-}
diff --git
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/StructuredAndRawConfigManagement.java
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/StructuredAndRawConfigManagement.java
new file mode 100644
index 0000000..d8a9ed1
--- /dev/null
+++
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/StructuredAndRawConfigManagement.java
@@ -0,0 +1,90 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2008 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.rhq.core.pc.configuration;
+
+import static java.util.Collections.EMPTY_SET;
+
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.RawConfiguration;
+import org.rhq.core.domain.resource.ResourceType;
+import org.rhq.core.clientapi.agent.PluginContainerException;
+import org.rhq.core.pluginapi.configuration.ResourceConfigurationFacet;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.List;
+import java.util.Set;
+
+public class StructuredAndRawConfigManagement extends ConfigManagementSupport {
+
+ private final Log log = LogFactory.getLog(StructuredAndRawConfigManagement.class);
+
+ public Configuration execute(int resourceId) throws PluginContainerException {
+ ResourceConfigurationFacet facet = loadResouceConfiguratonFacet(resourceId);
+
+ Configuration configuration = facet.loadStructuredConfiguration();
+ Set<RawConfiguration> rawConfigs = facet.loadRawConfigurations();
+
+ if (configuration == null && rawConfigs == null) {
+ return null;
+ }
+
+ if (configuration == null) {
+ configuration = new Configuration();
+ }
+
+ if (rawConfigs == null) {
+ rawConfigs = EMPTY_SET;
+ }
+
+ for (RawConfiguration rawConfig : rawConfigs) {
+ configuration.addRawConfiguration(rawConfig);
+ }
+
+ ResourceType resourceType = componentService.getResourceType(resourceId);
+
+ if (configuration.getNotes() == null) {
+ configuration.setNotes("Resource config for " +
resourceType.getName() + " Resource w/ id " + resourceId);
+ }
+
+ configUtilityService.normalizeConfiguration(configuration,
resourceType.getResourceConfigurationDefinition());
+ List<String> errorMsgs =
configUtilityService.validateConfiguration(configuration,
+ resourceType.getResourceConfigurationDefinition());
+
+ logErrorMsgs(errorMsgs, resourceType);
+
+ return configuration;
+ }
+
+ private void logErrorMsgs(List<String> errorMsgs, ResourceType resourceType) {
+ for (String errorMessage : errorMsgs) {
+ log.warn("Plugin Error: Invalid " + resourceType.getName() + "
Resource configuration returned by "
+ + resourceType.getPlugin() + " plugin - " + errorMessage);
+ }
+ }
+
+ public void executeUpdate(int resourceId, Configuration configuration)
+ throws PluginContainerException {
+ }
+}
diff --git
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/StructuredConfigManagement.java
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/StructuredConfigManagement.java
new file mode 100644
index 0000000..7a04d04
--- /dev/null
+++
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/configuration/StructuredConfigManagement.java
@@ -0,0 +1,75 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2008 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.rhq.core.pc.configuration;
+
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.resource.ResourceType;
+import org.rhq.core.clientapi.agent.PluginContainerException;
+import org.rhq.core.pluginapi.configuration.ResourceConfigurationFacet;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.List;
+
+public class StructuredConfigManagement extends ConfigManagementSupport {
+
+ private final Log log = LogFactory.getLog(StructuredConfigManagement.class);
+
+ public Configuration execute(int resourceId) throws PluginContainerException {
+ ResourceConfigurationFacet facet = loadResouceConfiguratonFacet(resourceId);
+
+ Configuration configuration = facet.loadStructuredConfiguration();
+
+ if (configuration == null) {
+ return null;
+ }
+
+ ResourceType resourceType = componentService.getResourceType(resourceId);
+
+ if (configuration.getNotes() == null) {
+ configuration.setNotes("Resource config for " +
resourceType.getName() + " Resource w/ id " + resourceId);
+ }
+
+ configUtilityService.normalizeConfiguration(configuration,
resourceType.getResourceConfigurationDefinition());
+ List<String> errorMsgs =
configUtilityService.validateConfiguration(configuration,
+ resourceType.getResourceConfigurationDefinition());
+
+ logErrorMsgs(errorMsgs, resourceType);
+
+ return configuration;
+ }
+
+ private void logErrorMsgs(List<String> errorMsgs, ResourceType resourceType) {
+ for (String errorMessage : errorMsgs) {
+ log.warn("Plugin Error: Invalid " + resourceType.getName() + "
Resource configuration returned by "
+ + resourceType.getPlugin() + " plugin - " + errorMessage);
+ }
+ }
+
+ public void executeUpdate(int resourceId, Configuration configuration) throws
PluginContainerException {
+ ResourceConfigurationFacet facet =
loadResourceConfigFacetWithWriteLock(resourceId);
+
+ facet.persistStructuredConfiguration(configuration);
+ }
+}
diff --git
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/ConfigManagementFactoryImplTest.java
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/ConfigManagementFactoryImplTest.java
index 8ea73cf..4e58e9c 100644
---
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/ConfigManagementFactoryImplTest.java
+++
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/ConfigManagementFactoryImplTest.java
@@ -103,8 +103,8 @@ public class ConfigManagementFactoryImplTest extends JMockTest {
ConfigManagement loadConfig = factory.getStrategy(resourceId);
assertTrue(
- loadConfig instanceof LoadStructured,
- "Expected to get an instance of " +
LoadStructured.class.getSimpleName() +
+ loadConfig instanceof StructuredConfigManagement,
+ "Expected to get an instance of " +
StructuredConfigManagement.class.getSimpleName() +
"when resource is from a plugin having an ampsversion >= " +
NON_LEGACY_AMPS_VERSION + " and the resource " +
"configuration format is structured."
);
@@ -197,8 +197,8 @@ public class ConfigManagementFactoryImplTest extends JMockTest {
ConfigManagement loadConfig = factory.getStrategy(resourceId);
assertTrue(
- loadConfig instanceof LoadStructuredAndRaw,
- "Expected to get an instance of" +
LoadStructuredAndRaw.class.getSimpleName() +
+ loadConfig instanceof StructuredAndRawConfigManagement,
+ "Expected to get an instance of" +
StructuredAndRawConfigManagement.class.getSimpleName() +
" when resource is from a plugin having an ampsVersion >= " +
NON_LEGACY_AMPS_VERSION + " and the " +
"resource configuration format is both (structured and raw)."
);
diff --git
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/LoadStructuredAndRawTest.java
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/LoadStructuredAndRawTest.java
deleted file mode 100644
index e275f82..0000000
---
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/LoadStructuredAndRawTest.java
+++ /dev/null
@@ -1,191 +0,0 @@
-/*
- * RHQ Management Platform
- * Copyright (C) 2005-2008 Red Hat, Inc.
- * All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation, and/or the GNU Lesser
- * General Public License, version 2.1, also as published by the Free
- * Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License and the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU General Public License
- * and the GNU Lesser General Public License along with this program;
- * if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.rhq.core.pc.configuration;
-
-import static org.testng.Assert.*;
-import static java.util.Collections.*;
-
-import org.rhq.core.pc.util.ComponentService;
-import org.rhq.core.pc.util.FacetLockType;
-import org.rhq.core.pluginapi.configuration.ResourceConfigurationFacet;
-import org.rhq.core.domain.configuration.Configuration;
-import org.rhq.core.domain.configuration.RawConfiguration;
-import org.rhq.core.domain.configuration.PropertySimple;
-import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
-import org.rhq.core.domain.resource.ResourceType;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-import org.jmock.Expectations;
-
-import java.util.Set;
-
-public class LoadStructuredAndRawTest extends ConfigManagementTest {
-
- ComponentService componentService;
-
- ConfigurationUtilityService configUtilityService;
-
- ResourceConfigurationFacet configFacet;
-
- LoadStructuredAndRaw loadStructuredAndRaw;
-
- @BeforeMethod
- public void setup() {
- resourceType = new ResourceType();
- resourceType.setResourceConfigurationDefinition(new
ConfigurationDefinition("", ""));
-
- componentService = context.mock(ComponentService.class);
- configUtilityService = context.mock(ConfigurationUtilityService.class);
-
- configFacet = context.mock(ResourceConfigurationFacet.class);
-
- loadStructuredAndRaw = new LoadStructuredAndRaw();
- loadStructuredAndRaw.setComponentService(componentService);
- loadStructuredAndRaw.setConfigurationUtilityService(configUtilityService);
- }
-
- @Test
- public void rawConfigshouldGetLoaded() throws Exception {
- Configuration config = new Configuration();
-
- Set<RawConfiguration> rawConfigs = toSet(
- createRawConfiguration("/tmp/foo.txt"),
- createRawConfiguration("/tmp/bar.txt")
- );
-
-
- addDefaultExpectations(config, rawConfigs);
-
- Configuration loadedConfig = loadStructuredAndRaw.execute(resourceId);
-
- assertRawsLoaded(rawConfigs, loadedConfig);
- }
-
- @Test
- public void structuredConfigShouldGetLoaded() throws Exception {
- Configuration config = new Configuration();
- config.put(new PropertySimple("x", "1"));
- config.put(new PropertySimple("y", "2"));
-
- addDefaultExpectations(config, EMPTY_SET);
-
- Configuration loadedConfig = loadStructuredAndRaw.execute(resourceId);
-
- assertStructuredLoaded(config, loadedConfig);
- }
-
- @Test
- public void theConfigNotesShouldGetSet() throws Exception {
- Configuration config = new Configuration();
- config.setNotes(null);
-
- addDefaultExpectations(config, EMPTY_SET);
-
- Configuration loadedConfig = loadStructuredAndRaw.execute(resourceId);
-
- assertNotesSetToDefault(loadedConfig);
- }
-
- @Test
- public void nullStructuredShouldBeIgnored() throws Exception {
- Configuration config = null;
-
- Set<RawConfiguration> rawConfigs =
toSet(createRawConfiguration("/tmp/foo.txt"));
-
- addDefaultExpectations(config, rawConfigs);
-
- Configuration loadedConfig = loadStructuredAndRaw.execute(resourceId);
-
- Configuration emptyStructured = new Configuration();
-
- assertRawsLoaded(rawConfigs, loadedConfig);
- assertStructuredLoaded(emptyStructured, loadedConfig);
- }
-
- @Test
- public void nullRawsShouldBeIgnored() throws Exception {
- Configuration config = new Configuration();
- config.put(new PropertySimple("x", "1"));
- config.put(new PropertySimple("y", "2"));
-
- Set<RawConfiguration> rawConfigs = null;
-
- addDefaultExpectations(config, rawConfigs);
-
- Configuration loadedConfig = loadStructuredAndRaw.execute(resourceId);
-
- assertRawsLoaded(EMPTY_SET, loadedConfig);
- assertStructuredLoaded(config, loadedConfig);
- }
-
- @Test
- public void nullShouldBeReturnedWhenStructuredAndRawAreNull() throws Exception {
- context.checking(new Expectations() {{
- atLeast(1).of(componentService).getComponent(resourceId,
- ResourceConfigurationFacet.class,
- FacetLockType.READ,
-
ConfigManagement.FACET_METHOD_TIMEOUT,
- daemonThread,
- onlyIfStarted);
- will(returnValue(configFacet));
-
- allowing(componentService).getResourceType(resourceId);
will(returnValue(resourceType));
-
- oneOf(configFacet).loadStructuredConfiguration(); will(returnValue(null));
-
- oneOf(configFacet).loadRawConfigurations(); will(returnValue(null));
- }});
-
- Configuration loadedConfig = loadStructuredAndRaw.execute(resourceId);
-
- assertNull(loadedConfig, "Expected null to be returned when facet returns
null for both structured and raw.");
- }
-
- private void addDefaultExpectations(final Configuration config, final
Set<RawConfiguration> rawConfigs)
- throws Exception {
-
- context.checking(new Expectations() {{
- atLeast(1).of(componentService).getComponent(resourceId,
- ResourceConfigurationFacet.class,
- FacetLockType.READ,
-
ConfigManagement.FACET_METHOD_TIMEOUT,
- daemonThread,
- onlyIfStarted);
- will(returnValue(configFacet));
-
- allowing(componentService).getResourceType(resourceId);
will(returnValue(resourceType));
-
- oneOf(configFacet).loadStructuredConfiguration(); will(returnValue(config));
-
- oneOf(configFacet).loadRawConfigurations(); will(returnValue(rawConfigs));
-
-
atLeast(1).of(configUtilityService).normalizeConfiguration(with(any(Configuration.class)),
- with(getResourceConfigDefinition()));
-
-
atLeast(1).of(configUtilityService).validateConfiguration(with(any(Configuration.class)),
- with(getResourceConfigDefinition()));
- }});
- }
-
-}
diff --git
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/LoadStructuredTest.java
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/LoadStructuredTest.java
deleted file mode 100644
index 3941afd..0000000
---
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/LoadStructuredTest.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * RHQ Management Platform
- * Copyright (C) 2005-2008 Red Hat, Inc.
- * All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation, and/or the GNU Lesser
- * General Public License, version 2.1, also as published by the Free
- * Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License and the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU General Public License
- * and the GNU Lesser General Public License along with this program;
- * if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.rhq.core.pc.configuration;
-
-import org.jmock.Expectations;
-import org.rhq.core.domain.configuration.Configuration;
-import org.rhq.core.domain.configuration.PropertySimple;
-import org.rhq.core.pc.util.ComponentService;
-import org.rhq.core.pc.util.FacetLockType;
-import org.rhq.core.pluginapi.configuration.ResourceConfigurationFacet;
-import static org.testng.Assert.assertNull;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-public class LoadStructuredTest extends ConfigManagementTest {
-
- ComponentService componentService;
-
- ConfigurationUtilityService configUtilityService;
-
- ResourceConfigurationFacet configFacet;
-
- LoadStructured loadStructured;
-
- @BeforeMethod
- public void setup() {
- componentService = context.mock(ComponentService.class);
- configUtilityService = context.mock(ConfigurationUtilityService.class);
-
- configFacet = context.mock(ResourceConfigurationFacet.class);
-
- loadStructured = new LoadStructured();
- loadStructured.setComponentService(componentService);
- loadStructured.setConfigurationUtilityService(configUtilityService);
- }
-
- @Test
- public void structuredConfigShouldGetLoaded() throws Exception {
- Configuration config = new Configuration();
- config.put(new PropertySimple("x", "1"));
- config.put(new PropertySimple("y", "2"));
-
- addDefaultExpectations(config);
-
- Configuration loadedConfig = loadStructured.execute(resourceId);
-
- assertStructuredLoaded(config, loadedConfig);
- }
-
- @Test
- public void theConfigNotesShouldGetSet() throws Exception {
- final Configuration config = new Configuration();
- config.setNotes(null);
-
- addDefaultExpectations(config);
-
- Configuration loadedConfig = loadStructured.execute(resourceId);
-
- assertNotesSetToDefault(loadedConfig);
- }
-
- @Test
- public void nullShouldBeReturnedWhenStructuredIsNull() throws Exception {
- final Configuration config = null;
-
- context.checking(new Expectations() {{
- atLeast(1).of(componentService).getComponent(resourceId,
-
ResourceConfigurationFacet.class,
- FacetLockType.READ,
-
ConfigManagement.FACET_METHOD_TIMEOUT,
- daemonThread,
- onlyIfStarted);
- will(returnValue(configFacet));
-
- allowing(componentService).getResourceType(resourceId);
will(returnValue(resourceType));
-
- atLeast(1).of(configFacet).loadStructuredConfiguration();
will(returnValue(null));
- }});
-
- Configuration loadedConfig = loadStructured.execute(resourceId);
-
- assertNull(loadedConfig, "Expected null to be returned when facet returns
null for structured.");
- }
-
- private void addDefaultExpectations(final Configuration config) throws Exception {
- context.checking(new Expectations() {{
- atLeast(1).of(componentService).getComponent(resourceId,
-
ResourceConfigurationFacet.class,
- FacetLockType.READ,
-
ConfigManagement.FACET_METHOD_TIMEOUT,
- daemonThread,
- onlyIfStarted);
- will(returnValue(configFacet));
-
- allowing(componentService).getResourceType(resourceId);
will(returnValue(resourceType));
-
- atLeast(1).of(configFacet).loadStructuredConfiguration();
will(returnValue(config));
-
- atLeast(1).of(configUtilityService).normalizeConfiguration(config,
getResourceConfigDefinition());
-
- atLeast(1).of(configUtilityService).validateConfiguration(config,
getResourceConfigDefinition());
- }});
- }
-
-}
diff --git
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/StructuredAndRawConfigManagementTest.java
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/StructuredAndRawConfigManagementTest.java
new file mode 100644
index 0000000..7dbc1b6
--- /dev/null
+++
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/StructuredAndRawConfigManagementTest.java
@@ -0,0 +1,191 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2008 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.rhq.core.pc.configuration;
+
+import static org.testng.Assert.*;
+import static java.util.Collections.*;
+
+import org.rhq.core.pc.util.ComponentService;
+import org.rhq.core.pc.util.FacetLockType;
+import org.rhq.core.pluginapi.configuration.ResourceConfigurationFacet;
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.RawConfiguration;
+import org.rhq.core.domain.configuration.PropertySimple;
+import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
+import org.rhq.core.domain.resource.ResourceType;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+import org.jmock.Expectations;
+
+import java.util.Set;
+
+public class StructuredAndRawConfigManagementTest extends ConfigManagementTest {
+
+ ComponentService componentService;
+
+ ConfigurationUtilityService configUtilityService;
+
+ ResourceConfigurationFacet configFacet;
+
+ StructuredAndRawConfigManagement structuredAndRawConfigManagement;
+
+ @BeforeMethod
+ public void setup() {
+ resourceType = new ResourceType();
+ resourceType.setResourceConfigurationDefinition(new
ConfigurationDefinition("", ""));
+
+ componentService = context.mock(ComponentService.class);
+ configUtilityService = context.mock(ConfigurationUtilityService.class);
+
+ configFacet = context.mock(ResourceConfigurationFacet.class);
+
+ structuredAndRawConfigManagement = new StructuredAndRawConfigManagement();
+ structuredAndRawConfigManagement.setComponentService(componentService);
+
structuredAndRawConfigManagement.setConfigurationUtilityService(configUtilityService);
+ }
+
+ @Test
+ public void rawConfigshouldGetLoaded() throws Exception {
+ Configuration config = new Configuration();
+
+ Set<RawConfiguration> rawConfigs = toSet(
+ createRawConfiguration("/tmp/foo.txt"),
+ createRawConfiguration("/tmp/bar.txt")
+ );
+
+
+ addDefaultExpectations(config, rawConfigs);
+
+ Configuration loadedConfig =
structuredAndRawConfigManagement.execute(resourceId);
+
+ assertRawsLoaded(rawConfigs, loadedConfig);
+ }
+
+ @Test
+ public void structuredConfigShouldGetLoaded() throws Exception {
+ Configuration config = new Configuration();
+ config.put(new PropertySimple("x", "1"));
+ config.put(new PropertySimple("y", "2"));
+
+ addDefaultExpectations(config, EMPTY_SET);
+
+ Configuration loadedConfig =
structuredAndRawConfigManagement.execute(resourceId);
+
+ assertStructuredLoaded(config, loadedConfig);
+ }
+
+ @Test
+ public void theConfigNotesShouldGetSet() throws Exception {
+ Configuration config = new Configuration();
+ config.setNotes(null);
+
+ addDefaultExpectations(config, EMPTY_SET);
+
+ Configuration loadedConfig =
structuredAndRawConfigManagement.execute(resourceId);
+
+ assertNotesSetToDefault(loadedConfig);
+ }
+
+ @Test
+ public void nullStructuredShouldBeIgnored() throws Exception {
+ Configuration config = null;
+
+ Set<RawConfiguration> rawConfigs =
toSet(createRawConfiguration("/tmp/foo.txt"));
+
+ addDefaultExpectations(config, rawConfigs);
+
+ Configuration loadedConfig =
structuredAndRawConfigManagement.execute(resourceId);
+
+ Configuration emptyStructured = new Configuration();
+
+ assertRawsLoaded(rawConfigs, loadedConfig);
+ assertStructuredLoaded(emptyStructured, loadedConfig);
+ }
+
+ @Test
+ public void nullRawsShouldBeIgnored() throws Exception {
+ Configuration config = new Configuration();
+ config.put(new PropertySimple("x", "1"));
+ config.put(new PropertySimple("y", "2"));
+
+ Set<RawConfiguration> rawConfigs = null;
+
+ addDefaultExpectations(config, rawConfigs);
+
+ Configuration loadedConfig =
structuredAndRawConfigManagement.execute(resourceId);
+
+ assertRawsLoaded(EMPTY_SET, loadedConfig);
+ assertStructuredLoaded(config, loadedConfig);
+ }
+
+ @Test
+ public void nullShouldBeReturnedWhenStructuredAndRawAreNull() throws Exception {
+ context.checking(new Expectations() {{
+ atLeast(1).of(componentService).getComponent(resourceId,
+ ResourceConfigurationFacet.class,
+ FacetLockType.READ,
+
ConfigManagement.FACET_METHOD_TIMEOUT,
+ daemonThread,
+ onlyIfStarted);
+ will(returnValue(configFacet));
+
+ allowing(componentService).getResourceType(resourceId);
will(returnValue(resourceType));
+
+ oneOf(configFacet).loadStructuredConfiguration(); will(returnValue(null));
+
+ oneOf(configFacet).loadRawConfigurations(); will(returnValue(null));
+ }});
+
+ Configuration loadedConfig =
structuredAndRawConfigManagement.execute(resourceId);
+
+ assertNull(loadedConfig, "Expected null to be returned when facet returns
null for both structured and raw.");
+ }
+
+ private void addDefaultExpectations(final Configuration config, final
Set<RawConfiguration> rawConfigs)
+ throws Exception {
+
+ context.checking(new Expectations() {{
+ atLeast(1).of(componentService).getComponent(resourceId,
+ ResourceConfigurationFacet.class,
+ FacetLockType.READ,
+
ConfigManagement.FACET_METHOD_TIMEOUT,
+ daemonThread,
+ onlyIfStarted);
+ will(returnValue(configFacet));
+
+ allowing(componentService).getResourceType(resourceId);
will(returnValue(resourceType));
+
+ oneOf(configFacet).loadStructuredConfiguration(); will(returnValue(config));
+
+ oneOf(configFacet).loadRawConfigurations(); will(returnValue(rawConfigs));
+
+
atLeast(1).of(configUtilityService).normalizeConfiguration(with(any(Configuration.class)),
+ with(getResourceConfigDefinition()));
+
+
atLeast(1).of(configUtilityService).validateConfiguration(with(any(Configuration.class)),
+ with(getResourceConfigDefinition()));
+ }});
+ }
+
+}
diff --git
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/StructuredConfigManagementTest.java
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/StructuredConfigManagementTest.java
new file mode 100644
index 0000000..cac0ca4
--- /dev/null
+++
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/configuration/StructuredConfigManagementTest.java
@@ -0,0 +1,147 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2008 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.rhq.core.pc.configuration;
+
+import org.jmock.Expectations;
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.PropertySimple;
+import org.rhq.core.pc.util.ComponentService;
+import org.rhq.core.pc.util.FacetLockType;
+import org.rhq.core.pluginapi.configuration.ResourceConfigurationFacet;
+import static org.testng.Assert.assertNull;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+public class StructuredConfigManagementTest extends ConfigManagementTest {
+
+ ComponentService componentService;
+
+ ConfigurationUtilityService configUtilityService;
+
+ ResourceConfigurationFacet configFacet;
+
+ StructuredConfigManagement structuredMgmt;
+
+ @BeforeMethod
+ public void setup() {
+ componentService = context.mock(ComponentService.class);
+ configUtilityService = context.mock(ConfigurationUtilityService.class);
+
+ configFacet = context.mock(ResourceConfigurationFacet.class);
+
+ structuredMgmt = new StructuredConfigManagement();
+ structuredMgmt.setComponentService(componentService);
+ structuredMgmt.setConfigurationUtilityService(configUtilityService);
+ }
+
+ @Test
+ public void structuredConfigShouldGetLoaded() throws Exception {
+ Configuration config = new Configuration();
+ config.put(new PropertySimple("x", "1"));
+ config.put(new PropertySimple("y", "2"));
+
+ addDefaultExpectationsForLoad(config);
+
+ Configuration loadedConfig = structuredMgmt.execute(resourceId);
+
+ assertStructuredLoaded(config, loadedConfig);
+ }
+
+ @Test
+ public void theConfigNotesShouldGetSet() throws Exception {
+ final Configuration config = new Configuration();
+ config.setNotes(null);
+
+ addDefaultExpectationsForLoad(config);
+
+ Configuration loadedConfig = structuredMgmt.execute(resourceId);
+
+ assertNotesSetToDefault(loadedConfig);
+ }
+
+ @Test
+ public void nullShouldBeReturnedWhenStructuredIsNull() throws Exception {
+ final Configuration config = null;
+
+ context.checking(new Expectations() {{
+ atLeast(1).of(componentService).getComponent(resourceId,
+
ResourceConfigurationFacet.class,
+ FacetLockType.READ,
+
ConfigManagement.FACET_METHOD_TIMEOUT,
+ daemonThread,
+ onlyIfStarted);
+ will(returnValue(configFacet));
+
+ allowing(componentService).getResourceType(resourceId);
will(returnValue(resourceType));
+
+ atLeast(1).of(configFacet).loadStructuredConfiguration();
will(returnValue(null));
+ }});
+
+ Configuration loadedConfig = structuredMgmt.execute(resourceId);
+
+ assertNull(loadedConfig, "Expected null to be returned when facet returns
null for structured.");
+ }
+
+ private void addDefaultExpectationsForLoad(final Configuration config) throws
Exception {
+ context.checking(new Expectations() {{
+ atLeast(1).of(componentService).getComponent(resourceId,
+
ResourceConfigurationFacet.class,
+ FacetLockType.READ,
+
ConfigManagement.FACET_METHOD_TIMEOUT,
+ daemonThread,
+ onlyIfStarted);
+ will(returnValue(configFacet));
+
+ allowing(componentService).getResourceType(resourceId);
will(returnValue(resourceType));
+
+ atLeast(1).of(configFacet).loadStructuredConfiguration();
will(returnValue(config));
+
+ atLeast(1).of(configUtilityService).normalizeConfiguration(config,
getResourceConfigDefinition());
+
+ atLeast(1).of(configUtilityService).validateConfiguration(config,
getResourceConfigDefinition());
+ }});
+ }
+
+ @Test
+ public void facetShouldBeCalledToUpdateStructured() throws Exception {
+ final Configuration structuredConfig = new Configuration();
+
+ final boolean isDaemonThread = false;
+
+ context.checking(new Expectations() {{
+ atLeast(1).of(componentService).getComponent(resourceId,
+
ResourceConfigurationFacet.class,
+ FacetLockType.WRITE,
+
ConfigManagement.FACET_METHOD_TIMEOUT,
+ isDaemonThread,
+ onlyIfStarted);
+ will(returnValue(configFacet));
+
+ atLeast(1).of(configFacet).persistStructuredConfiguration(structuredConfig);
+ }});
+
+ structuredMgmt.executeUpdate(resourceId, structuredConfig);
+ }
+
+}