use of com.qcadoo.plugin.api.Plugin in project qcadoo by qcadoo.
the class PluginAccessorTest method shouldPerformEnableOnEnablingPlugins.
@SuppressWarnings("unchecked")
@Test
public void shouldPerformEnableOnEnablingPlugins() throws Exception {
// given
InternalPlugin plugin1 = mock(InternalPlugin.class);
QcadooPluginPlugin pluginsPlugin1 = mock(QcadooPluginPlugin.class);
given(plugin1.getIdentifier()).willReturn("identifier1");
given(pluginsPlugin1.getIdentifier()).willReturn("identifier1");
given(pluginsPlugin1.getState()).willReturn("ENABLING");
given(pluginsPlugin1.getVersion()).willReturn("0.0.0");
given(plugin1.hasState(PluginState.ENABLING)).willReturn(true);
InternalPlugin plugin2 = mock(InternalPlugin.class);
QcadooPluginPlugin pluginsPlugin2 = mock(QcadooPluginPlugin.class);
given(plugin2.getIdentifier()).willReturn("identifier2");
given(pluginsPlugin2.getIdentifier()).willReturn("identifier2");
given(pluginsPlugin2.getState()).willReturn("ENABLING");
given(pluginsPlugin2.getVersion()).willReturn("0.0.0");
given(plugin2.hasState(PluginState.ENABLING)).willReturn(true);
InternalPlugin plugin3 = mock(InternalPlugin.class);
QcadooPluginPlugin pluginsPlugin3 = mock(QcadooPluginPlugin.class);
given(pluginsPlugin3.getIdentifier()).willReturn("identifier3");
given(pluginsPlugin3.getVersion()).willReturn("0.0.0");
given(pluginsPlugin3.getState()).willReturn("DISABLED");
given(plugin3.getIdentifier()).willReturn("identifier3");
Set<InternalPlugin> pluginsFromDescriptor = Sets.newHashSet(plugin1, plugin2, plugin3);
Set<QcadooPluginPlugin> pluginsFromDatabase = Sets.newHashSet(pluginsPlugin1, pluginsPlugin2, pluginsPlugin3);
List<Plugin> sortedPluginsToInitialize = Lists.newArrayList((Plugin) plugin2, (Plugin) plugin1);
given(pluginDependencyManager.sortPluginsInDependencyOrder(Mockito.anyCollectionOf(Plugin.class), Mockito.anyMap())).willReturn(sortedPluginsToInitialize);
given(pluginDescriptorParser.loadPlugins()).willReturn(pluginsFromDescriptor);
given(pluginDao.list()).willReturn(pluginsFromDatabase);
// when
pluginAccessor.init();
pluginAccessor.onApplicationEvent(null);
// then
InOrder inOrder = inOrder(plugin2, plugin1, moduleFactoryAccessor);
inOrder.verify(moduleFactoryAccessor).init(sortedPluginsToInitialize);
inOrder.verify(plugin2).changeStateTo(PluginState.ENABLED);
inOrder.verify(plugin1).changeStateTo(PluginState.ENABLED);
verify(plugin3, never()).changeStateTo(PluginState.ENABLED);
verify(pluginDao).save(plugin1);
verify(pluginDao).save(plugin2);
verify(pluginDao, never()).save(plugin3);
}
use of com.qcadoo.plugin.api.Plugin in project qcadoo by qcadoo.
the class PluginAccessorTest method shouldPerformInit.
@SuppressWarnings("unchecked")
@Test
public void shouldPerformInit() throws Exception {
// given
InternalPlugin plugin1 = mock(InternalPlugin.class, "plugin1");
QcadooPluginPlugin pluginsPlugin1 = mock(QcadooPluginPlugin.class, "plugin1");
given(plugin1.getIdentifier()).willReturn("identifier1");
given(pluginsPlugin1.getIdentifier()).willReturn("identifier1");
given(pluginsPlugin1.getState()).willReturn("ENABLED");
given(pluginsPlugin1.getVersion()).willReturn("0.0.0");
InternalPlugin plugin2 = mock(InternalPlugin.class, "plugin2");
QcadooPluginPlugin pluginsPlugin2 = mock(QcadooPluginPlugin.class, "plugin2");
given(plugin2.getIdentifier()).willReturn("identifier2");
given(pluginsPlugin2.getIdentifier()).willReturn("identifier2");
given(pluginsPlugin2.getVersion()).willReturn("0.0.0");
given(pluginsPlugin2.getState()).willReturn("ENABLED");
Set<InternalPlugin> pluginsFromDescriptor = Sets.newHashSet(plugin1, plugin2);
Set<QcadooPluginPlugin> pluginsFromDatabase = Sets.newHashSet(pluginsPlugin1, pluginsPlugin2);
List<Plugin> sortedPluginsToInitialize = Lists.newArrayList((Plugin) plugin2, (Plugin) plugin1);
given(pluginDependencyManager.sortPluginsInDependencyOrder(Mockito.anyCollectionOf(Plugin.class), Mockito.anyMap())).willReturn(sortedPluginsToInitialize);
given(pluginDescriptorParser.loadPlugins()).willReturn(pluginsFromDescriptor);
given(pluginDao.list()).willReturn(pluginsFromDatabase);
// when
pluginAccessor.init();
pluginAccessor.onApplicationEvent(null);
// then
InOrder inOrder = inOrder(plugin2, plugin1, moduleFactoryAccessor);
inOrder.verify(moduleFactoryAccessor).init(sortedPluginsToInitialize);
}
use of com.qcadoo.plugin.api.Plugin in project qcadoo by qcadoo.
the class PluginDependencyManagerTest method shouldCheckDependenciesDependenciesAndReturnMultipleDependencies.
@Test
public void shouldCheckDependenciesDependenciesAndReturnMultipleDependencies() throws Exception {
// given
Set<PluginDependencyInformation> disabledRequiredPlugins = new HashSet<PluginDependencyInformation>();
disabledRequiredPlugins.add(dependencyInfo2);
given(plugin1.getRequiredPlugins()).willReturn(disabledRequiredPlugins);
given(plugin2.getState()).willReturn(PluginState.DISABLED);
Set<PluginDependencyInformation> disabledRequiredPlugins2 = new HashSet<PluginDependencyInformation>();
disabledRequiredPlugins2.add(dependencyInfo3);
given(plugin2.getRequiredPlugins()).willReturn(disabledRequiredPlugins2);
given(plugin3.getState()).willReturn(PluginState.TEMPORARY);
given(pluginAccessor.getPlugin("testPlugin2")).willReturn(plugin2);
given(pluginAccessor.getPlugin("testPlugin3")).willReturn(plugin3);
// when
PluginDependencyResult result = manager.getDependenciesToEnable(singletonList((Plugin) plugin1), pluginStatusResolver);
// then
assertFalse(result.isCyclic());
assertEquals(2, result.getDependenciesToEnable().size());
assertTrue(result.getDependenciesToEnable().contains(new PluginDependencyInformation("testPlugin2")));
assertTrue(result.getDependenciesToEnable().contains(new PluginDependencyInformation("testPlugin3")));
assertEquals(0, result.getUnsatisfiedDependencies().size());
assertEquals(0, result.getDependenciesToDisable().size());
}
use of com.qcadoo.plugin.api.Plugin in project qcadoo by qcadoo.
the class PluginDependencyManagerTest method shouldReturnValidResultForCyclicDependencies.
@Test
public void shouldReturnValidResultForCyclicDependencies() throws Exception {
// given
Set<PluginDependencyInformation> disabledRequiredPlugins1 = new HashSet<PluginDependencyInformation>();
disabledRequiredPlugins1.add(dependencyInfo2);
given(plugin1.getRequiredPlugins()).willReturn(disabledRequiredPlugins1);
Set<PluginDependencyInformation> disabledRequiredPlugins2 = new HashSet<PluginDependencyInformation>();
disabledRequiredPlugins2.add(dependencyInfo3);
disabledRequiredPlugins2.add(dependencyInfo4);
given(plugin2.getRequiredPlugins()).willReturn(disabledRequiredPlugins2);
Set<PluginDependencyInformation> disabledRequiredPlugins3 = new HashSet<PluginDependencyInformation>();
disabledRequiredPlugins3.add(dependencyInfo1);
given(plugin3.getRequiredPlugins()).willReturn(disabledRequiredPlugins3);
given(pluginAccessor.getPlugin("testPlugin1")).willReturn(plugin1);
given(pluginAccessor.getPlugin("testPlugin2")).willReturn(plugin2);
given(pluginAccessor.getPlugin("testPlugin3")).willReturn(plugin3);
given(pluginAccessor.getPlugin("testPlugin4")).willReturn(plugin4);
List<Plugin> plugins = new ArrayList<Plugin>();
plugins.add(plugin1);
plugins.add(plugin2);
plugins.add(plugin3);
// when
PluginDependencyResult result = manager.getDependenciesToEnable(plugins, pluginStatusResolver);
// then
assertTrue(result.isCyclic());
assertEquals(0, result.getDependenciesToEnable().size());
assertEquals(0, result.getUnsatisfiedDependencies().size());
assertEquals(0, result.getDependenciesToDisable().size());
}
use of com.qcadoo.plugin.api.Plugin in project qcadoo by qcadoo.
the class DefaultPluginManager method uninstallPlugin.
@Override
public PluginOperationResult uninstallPlugin(final String... keys) {
List<Plugin> plugins = new ArrayList<Plugin>();
for (String key : keys) {
Plugin plugin = pluginAccessor.getPlugin(key);
if (plugin.isSystemPlugin()) {
return PluginOperationResultImpl.systemPluginUninstalling();
}
plugins.add(plugin);
}
PluginDependencyResult pluginDependencyResult = pluginDependencyManager.getDependenciesToUninstall(plugins, pluginStatusResolver);
if (!pluginDependencyResult.isDependenciesSatisfied() && !pluginDependencyResult.getDependenciesToUninstall().isEmpty()) {
return PluginOperationResultImpl.dependenciesToUninstall(pluginDependencyResult);
}
boolean shouldRestart = false;
List<String> fileNames = new ArrayList<String>();
for (Plugin plugin : plugins) {
if (!plugin.hasState(PluginState.TEMPORARY)) {
shouldRestart = true;
}
fileNames.add(plugin.getFilename());
}
pluginFileManager.uninstallPlugin(fileNames.toArray(new String[fileNames.size()]));
plugins = pluginDependencyManager.sortPluginsInDependencyOrder(plugins);
Collections.reverse(plugins);
for (Plugin plugin : plugins) {
if (plugin.hasState(PluginState.ENABLED)) {
((InternalPlugin) plugin).changeStateTo(PluginState.DISABLED);
}
pluginDao.delete(plugin);
pluginAccessor.removePlugin(plugin);
}
if (shouldRestart) {
return PluginOperationResultImpl.successWithRestart();
} else {
return PluginOperationResultImpl.success();
}
}
Aggregations