allowing(pluginManager).getInstalledPlugins();
will(returnValue(installedPlugins));
}
});
DeployedAgentPluginsValidator validator = new DeployedAgentPluginsValidator(pluginManager);
Set<DeployedAgentPluginsValidator.ConsistentPlugin> pluginsToValidate = getDeployedPlugins();
validator.initialize(null, null);
validator.setPluginsToValidate(pluginsToValidate);
//this should validate cleanly
validator.validateExportedState();
//now add 1 plugin to the validated state
DeployedAgentPluginsValidator.ConsistentPlugin newPlugin = createPlugin("superfluous", "1", "md5_4");
pluginsToValidate.add(newPlugin);
try {
validator.validateExportedState();
fail("validation should have detected that the current installation has one plugin less.");
} catch (InconsistentStateException e) {
//this is expected
}
//ok, remove the new plugin from the "exported state" and put it in the current state
pluginsToValidate.remove(newPlugin);
installedPlugins.add(newPlugin);
try {
validator.validateExportedState();
fail("validation should have detected that the current installation has one plugin more.");
} catch (InconsistentStateException e) {
//ok
}
//make the current state and exported state be in sync again
DeployedAgentPluginsValidator.ConsistentPlugin newPluginCopy = new DeployedAgentPluginsValidator.ConsistentPlugin(newPlugin);
pluginsToValidate.add(newPluginCopy);
//change the newPlugin to not be equal
newPlugin.setMd5("md5_different");
try {
validator.validateExportedState();
fail("validation should have failed because one of the plugins differs between current and exported states.");
} catch (InconsistentStateException e) {
//ok
}
newPlugin.setMd5(newPluginCopy.getMd5());
newPluginCopy.setMd5("md5_different");
try {
validator.validateExportedState();
fail("validation should have failed because one of the plugins differs between current and exported states.");
} catch (InconsistentStateException e) {
//ok
}
}