modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/measurement/test/AvailabilityManagerTest.java
| 9
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/measurement/test/DriftServerPluginService.java
| 113 ++++++++++
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/measurement/test/DriftServerPluginServiceMBean.java
| 25 ++
3 files changed, 147 insertions(+)
New commits:
commit bafd62732f90a3b3153f41ce9df47de431a66380
Author: John Sanda <jsanda(a)redhat.com>
Date: Fri Oct 28 15:24:57 2011 -0400
fixing failing tests
Tests in AvailabilityManagerTest were failing because of a call in
AgentManagerBean to load the system settings. A list of the drift server
plugins is stored as part of the system settings. To obtain that list
SystemManagerBean attempts to access DriftServerPluginContainer via the
server plugin service.
I have supplied AvailabilityManagerTest with a stubbed out server plugin
service so that the SystemManagerBean is able to load the default
settings without error.
diff --git
a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/measurement/test/AvailabilityManagerTest.java
b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/measurement/test/AvailabilityManagerTest.java
index 37c5992..3fbc4f7 100644
---
a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/measurement/test/AvailabilityManagerTest.java
+++
b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/measurement/test/AvailabilityManagerTest.java
@@ -73,6 +73,8 @@ public class AvailabilityManagerTest extends AbstractEJB3Test {
private Availability availability2;
private Availability availability3;
+ private DriftServerPluginService driftServerPluginService;
+
@BeforeMethod
public void beforeMethod() {
try {
@@ -83,6 +85,11 @@ public class AvailabilityManagerTest extends AbstractEJB3Test {
this.resourceManager = LookupUtil.getResourceManager();
this.overlord = LookupUtil.getSubjectManager().getOverlord();
additionalResources = new ArrayList<Resource>();
+
+ driftServerPluginService = new DriftServerPluginService();
+ prepareCustomServerPluginService(driftServerPluginService);
+ driftServerPluginService.masterConfig.getPluginDirectory().mkdirs();
+ driftServerPluginService.startMasterPluginContainer();
} catch (Throwable t) {
// Catch RuntimeExceptions and Errors and dump their stack trace, because
Surefire will completely swallow them
// and throw a cryptic NPE (see
http://jira.codehaus.org/browse/SUREFIRE-157)!
@@ -131,6 +138,8 @@ public class AvailabilityManagerTest extends AbstractEJB3Test {
finally {
unprepareScheduler();
+ unprepareServerPluginService();
+ driftServerPluginService.stopMasterPluginContainer();
}
}
diff --git
a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/measurement/test/DriftServerPluginService.java
b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/measurement/test/DriftServerPluginService.java
new file mode 100644
index 0000000..b20155a
--- /dev/null
+++
b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/measurement/test/DriftServerPluginService.java
@@ -0,0 +1,113 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2011 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 as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * 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 for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+package org.rhq.enterprise.server.measurement.test;
+
+import java.io.File;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import org.rhq.core.domain.plugin.PluginKey;
+import org.rhq.core.domain.plugin.ServerPlugin;
+import org.rhq.enterprise.server.plugin.pc.AbstractTypeServerPluginContainer;
+import org.rhq.enterprise.server.plugin.pc.MasterServerPluginContainer;
+import org.rhq.enterprise.server.plugin.pc.MasterServerPluginContainerConfiguration;
+import org.rhq.enterprise.server.plugin.pc.ServerPluginEnvironment;
+import org.rhq.enterprise.server.plugin.pc.ServerPluginManager;
+import org.rhq.enterprise.server.plugin.pc.ServerPluginService;
+import org.rhq.enterprise.server.plugin.pc.drift.DriftServerPluginContainer;
+import org.rhq.enterprise.server.plugin.pc.drift.DriftServerPluginManager;
+import
org.rhq.enterprise.server.xmlschema.generated.serverplugin.ServerPluginDescriptorType;
+
+public class DriftServerPluginService extends ServerPluginService implements
DriftServerPluginServiceMBean {
+
+ public TestMasterServerPluginContainer master;
+ public MasterServerPluginContainerConfiguration masterConfig;
+
+ public DriftServerPluginService() {
+ // build the config at constructor time so tests have it even before the PC is
initialized
+ File dir = new File(System.getProperty("java.io.tmpdir"),
"test-server-plugins");
+ this.masterConfig = new MasterServerPluginContainerConfiguration(dir, dir, dir,
null);
+ }
+
+ @Override
+ public MasterServerPluginContainer createMasterPluginContainer() {
+ this.master = new TestMasterServerPluginContainer();
+ this.master.initialize(this.masterConfig);
+ return this.master;
+ }
+
+ class TestMasterServerPluginContainer extends MasterServerPluginContainer {
+ @Override
+ protected ClassLoader createRootServerPluginClassLoader() {
+ return getClass().getClassLoader();
+ }
+
+ @Override
+ protected Map<URL, ? extends ServerPluginDescriptorType>
preloadAllPlugins() throws Exception {
+ return Collections.emptyMap();
+ }
+
+ @Override
+ protected List<PluginKey> getDisabledPluginKeys() {
+ // in the real world, the db is checked for enable flag, here we say all
plugins are enabled
+ return new ArrayList<PluginKey>();
+ }
+
+ @Override
+ protected List<AbstractTypeServerPluginContainer> createPluginContainers()
{
+ ArrayList<AbstractTypeServerPluginContainer> pcs = new
ArrayList<AbstractTypeServerPluginContainer>(1);
+ DriftServerPluginContainer driftPC = new
TestDriftServerPluginContainer(this);
+ pcs.add(driftPC);
+
+ return pcs;
+ }
+ }
+
+ class TestDriftServerPluginContainer extends DriftServerPluginContainer {
+ public TestDriftServerPluginContainer(MasterServerPluginContainer master) {
+ super(master);
+ }
+
+ @Override
+ protected ServerPluginManager createPluginManager() {
+ return new TestDriftServerPluginManager(this);
+ }
+ }
+
+ class TestDriftServerPluginManager extends DriftServerPluginManager {
+ public TestDriftServerPluginManager(DriftServerPluginContainer pc) {
+ super(pc);
+ }
+
+ @Override
+ public Collection<ServerPluginEnvironment> getPluginEnvironments() {
+ return Collections.emptyList();
+ }
+
+ @Override
+ protected ServerPlugin getPlugin(ServerPluginEnvironment env) {
+ return null;
+ }
+ }
+}
diff --git
a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/measurement/test/DriftServerPluginServiceMBean.java
b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/measurement/test/DriftServerPluginServiceMBean.java
new file mode 100644
index 0000000..8473cf0
--- /dev/null
+++
b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/measurement/test/DriftServerPluginServiceMBean.java
@@ -0,0 +1,25 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2011 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 as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * 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 for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+package org.rhq.enterprise.server.measurement.test;
+
+import org.rhq.enterprise.server.plugin.pc.ServerPluginServiceManagement;
+
+public interface DriftServerPluginServiceMBean extends ServerPluginServiceManagement {
+}