Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

Commit

Permalink
Bug 1125423 - Fuse Fabric Groups Plugin cannot be enabled
Browse files Browse the repository at this point in the history
Fixed failing itest and also added test
  • Loading branch information
Libor Zoubek committed Sep 26, 2014
1 parent afe4b9a commit c4fc397
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 3 deletions.
Expand Up @@ -19,6 +19,8 @@

package org.rhq.enterprise.server.plugin;

import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -27,10 +29,15 @@
import org.hibernate.LazyInitializationException;
import org.testng.annotations.Test;

import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.exporter.ZipExporter;
import org.jboss.shrinkwrap.api.spec.JavaArchive;

import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.PropertyMap;
import org.rhq.core.domain.configuration.PropertySimple;
import org.rhq.core.domain.plugin.PluginConfigurationRequiredException;
import org.rhq.core.domain.plugin.PluginDeploymentType;
import org.rhq.core.domain.plugin.PluginKey;
import org.rhq.core.domain.plugin.PluginStatusType;
Expand All @@ -48,6 +55,7 @@
public class ServerPluginsBeanTest extends AbstractEJB3Test {

private static final String TEST_PLUGIN_NAME_PREFIX = "serverplugintest";
private static final String TEST_PLUGIN_JAR_NAME = "test-plugin.jar";

private ServerPluginManagerLocal serverPluginsBean;

Expand All @@ -58,6 +66,16 @@ protected void beforeMethod() {
prepareCustomServerPluginService(pluginService);

serverPluginsBean = LookupUtil.getServerPluginManager();
pluginService.masterConfig.getPluginDirectory().mkdirs();

JavaArchive archive = ShrinkWrap.create(JavaArchive.class);
URL res = this.getClass().getClassLoader().getResource("serverplugins/simple-generic-serverplugin.xml");
archive.addAsResource(res, "META-INF/rhq-serverplugin.xml");

File pluginFile = new File(pluginService.masterConfig.getPluginDirectory(), TEST_PLUGIN_JAR_NAME);

archive.as(ZipExporter.class).exportTo(pluginFile, true);

}

@Override
Expand Down Expand Up @@ -162,6 +180,32 @@ public void testUpdatePlugins() throws Exception {
p1update.getScheduledJobsConfiguration().equals(p1.getScheduledJobsConfiguration());
}

public void testTryEnableServerPluginsWithMissingRequiredConfiguration() throws Exception {
ServerPlugin p1 = registerPlugin(1, Configuration.builder().addSimple("foo", "bar").build());
ServerPlugin p2 = registerPlugin(2);
PluginKey p1key = new PluginKey(p1);
PluginKey p2key = new PluginKey(p2);

List<Integer> ids = new ArrayList<Integer>(2);
ids.add(p1.getId());
ids.add(p2.getId());

// first disable both plugins
List<PluginKey> disabled = this.serverPluginsBean.disableServerPlugins(getOverlord(), ids);
assert disabled.size() == 2 : disabled;
assert disabled.contains(p1key) : disabled;
assert disabled.contains(p2key) : disabled;

// try to enable, but expect failure
boolean caught = false;
try {
this.serverPluginsBean.enableServerPlugins(getOverlord(), ids);
} catch (PluginConfigurationRequiredException pcre) {
caught = true;
}
assert caught == true : "Exception must be thrown when attempting to enable plugin without required configuration set";
}

public void testDisableEnablePlugins() throws Exception {
ServerPlugin p1 = registerPlugin(1);
ServerPlugin p2 = registerPlugin(2);
Expand Down Expand Up @@ -330,10 +374,11 @@ public void testReRegisterPlugins() throws Exception {
assert !pluginKeys.contains(p2key) : pluginKeys;
}

private ServerPlugin registerPlugin(int index) throws Exception {
ServerPlugin plugin = new ServerPlugin(0, TEST_PLUGIN_NAME_PREFIX + index, "path", "displayName", true,
private ServerPlugin registerPlugin(int index, Configuration pluginConfiguration) throws Exception {
ServerPlugin plugin = new ServerPlugin(0, TEST_PLUGIN_NAME_PREFIX + index, TEST_PLUGIN_JAR_NAME, "displayName",
true,
PluginStatusType.INSTALLED, "description", "help", "md5", "version", "ampsVersion",
createPluginConfiguration(), createScheduledJobsConfiguration(), new ServerPluginType(
pluginConfiguration, createScheduledJobsConfiguration(), new ServerPluginType(
GenericPluginDescriptorType.class).stringify(), System.currentTimeMillis(), System.currentTimeMillis());

plugin = this.serverPluginsBean.registerServerPlugin(getOverlord(), plugin, null);
Expand All @@ -347,6 +392,10 @@ private ServerPlugin registerPlugin(int index) throws Exception {
return plugin;
}

private ServerPlugin registerPlugin(int index) throws Exception {
return registerPlugin(index, createPluginConfiguration());
}

private void assetLazyInitializationException(ServerPlugin plugin) {
try {
plugin.getPluginConfiguration().toString();
Expand All @@ -363,6 +412,8 @@ private void assetLazyInitializationException(ServerPlugin plugin) {
private Configuration createPluginConfiguration() {
Configuration config = new Configuration();
config.put(new PropertySimple("simpleprop1", "simpleprop1value"));
// set this property to something as this is defined as required in simple-generic-serverplugin.xml
config.put(new PropertySimple("plugin-simple-prop-1", "foo"));
return config;
}

Expand Down
Expand Up @@ -67,6 +67,11 @@ public MasterServerPluginContainer createMasterPluginContainer() {
return this.master;
}

@Override
public File getServerPluginsDirectory() {
return masterConfig.getPluginDirectory();
}

/**
* The test master PC
*/
Expand Down

0 comments on commit c4fc397

Please sign in to comment.