missingKey = new PluginKey(PluginDeploymentType.SERVER,
new ServerPluginType(GenericPluginDescriptorType.class).stringify(), TEST_PLUGIN_NAME_PREFIX + "2");
status = this.serverPluginsBean.getServerPluginStatus(missingKey);
assert status == null;
ServerPlugin p1 = registerPlugin(1);
ServerPlugin p2 = registerPlugin(2);
PluginKey p1key = new PluginKey(p1);
PluginKey p2key = new PluginKey(p2);
status = this.serverPluginsBean.getServerPluginStatus(p1key);
assert status == PluginStatusType.INSTALLED;
status = this.serverPluginsBean.getServerPluginStatus(p2key);
assert status == PluginStatusType.INSTALLED;
List<Integer> ids = new ArrayList<Integer>(2);
ids.add(p1.getId());
ids.add(p2.getId());
List<PluginKey> undeployed = this.serverPluginsBean.deleteServerPlugins(getOverlord(), ids);
assert undeployed.size() == 2 : undeployed;
assert undeployed.contains(p1key) : undeployed;
assert undeployed.contains(p2key) : undeployed;
ServerPlugin p1deleted = getDeletedPluginInTx(p1.getName());
assert p1deleted.getStatus() == PluginStatusType.DELETED;
assert p1deleted.getPluginConfiguration() == null; // undeploy should have removed this
assert p1deleted.getScheduledJobsConfiguration() == null; // undeploy should have removed this
ServerPlugin p2deleted = getDeletedPluginInTx(p1.getName());
assert p2deleted.getStatus() == PluginStatusType.DELETED;
assert p2deleted.getPluginConfiguration() == null; // undeploy should have removed this
assert p2deleted.getScheduledJobsConfiguration() == null; // undeploy should have removed this
List<PluginKey> pluginKeys = this.serverPluginsBean.getServerPluginKeysByEnabled(false);
assert !pluginKeys.contains(p1key) : "deleted plugins should not be returned even here" + pluginKeys;
assert !pluginKeys.contains(p2key) : "deleted plugins should not be returned even here" + pluginKeys;
pluginKeys = this.serverPluginsBean.getServerPluginKeysByEnabled(true);
assert !pluginKeys.contains(p1key) : pluginKeys;
assert !pluginKeys.contains(p2key) : pluginKeys;
// purge them completely from the DB to prepare to re-register them
this.serverPluginsBean.purgeServerPlugin(p1.getId());
this.serverPluginsBean.purgeServerPlugin(p2.getId());
// we just purged the database, make sure our entity ID's are all zero, since the original IDs are gone
p1.setId(0);
p2.setId(0);
p1.setPluginConfiguration(p1.getPluginConfiguration().deepCopy(false));
p2.setPluginConfiguration(p2.getPluginConfiguration().deepCopy(false));
p1.setScheduledJobsConfiguration(p1.getScheduledJobsConfiguration().deepCopy(false));
p2.setScheduledJobsConfiguration(p2.getScheduledJobsConfiguration().deepCopy(false));
// re-register them now
ServerPlugin p1again = this.serverPluginsBean.registerServerPlugin(getOverlord(), p1, null);
ServerPlugin p2again = this.serverPluginsBean.registerServerPlugin(getOverlord(), p2, null);
pluginKeys = this.serverPluginsBean.getServerPluginKeysByEnabled(true);
assert pluginKeys.contains(p1key) : pluginKeys;
assert pluginKeys.contains(p2key) : pluginKeys;
assert p1again.getStatus() == PluginStatusType.INSTALLED;
assert p2again.getStatus() == PluginStatusType.INSTALLED;
pluginKeys = this.serverPluginsBean.getServerPluginKeysByEnabled(false);
assert !pluginKeys.contains(p1key) : pluginKeys;
assert !pluginKeys.contains(p2key) : pluginKeys;
}