use of com.qcadoo.plugin.internal.api.InternalPlugin in project qcadoo by qcadoo.
the class PluginChangeStateToTest method assertOperationSupported.
private void assertOperationSupported(final PluginState from, final PluginState to, final boolean callEnable, final boolean callDisable) throws Exception {
// given
ModuleFactory<?> moduleFactory = mock(ModuleFactory.class);
Module module1 = mock(Module.class);
Module module2 = mock(Module.class);
InternalPlugin plugin = DefaultPlugin.Builder.identifier("identifier", Lists.<ModuleFactory<?>>newArrayList(moduleFactory)).withModule(moduleFactory, module1).withModule(moduleFactory, module2).build();
if (from != null) {
plugin.changeStateTo(from);
}
given(mockPluginStateResolver.isEnabled("identifier")).willReturn(PluginState.ENABLED.equals(to));
// when
plugin.changeStateTo(to);
// then
assertEquals(to, plugin.getState());
assertTrue(plugin.hasState(to));
if (callEnable) {
verify(module1).enable();
// verify(module1).multiTenantEnable();
verify(module2).enable();
} else {
verify(module1, never()).enable();
verify(module2, never()).multiTenantEnable();
}
if (callDisable) {
verify(module1).disable();
// verify(module2).multiTenantDisable();
} else {
verify(module1, never()).disable();
verify(module2, never()).multiTenantDisable();
}
}
use of com.qcadoo.plugin.internal.api.InternalPlugin 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.internal.api.InternalPlugin in project qcadoo by qcadoo.
the class PluginAccessorTest method shouldFailOnPluginDowngrade.
@Test(expected = IllegalStateException.class)
public void shouldFailOnPluginDowngrade() throws Exception {
// given
InternalPlugin plugin11 = mock(InternalPlugin.class);
given(plugin11.getIdentifier()).willReturn("identifier11");
QcadooPluginPlugin pluginsPlugin12 = mock(QcadooPluginPlugin.class);
given(pluginsPlugin12.getIdentifier()).willReturn("identifier11");
given(pluginsPlugin12.getVersion()).willReturn("0.0.0");
given(pluginsPlugin12.getState()).willReturn("ENABLED");
given(plugin11.compareVersion(new Version(pluginsPlugin12.getVersion()))).willReturn(-1);
Set<InternalPlugin> pluginsFromDescriptor = Sets.newHashSet(plugin11);
Set<QcadooPluginPlugin> pluginsFromDatabase = Sets.newHashSet(pluginsPlugin12);
given(pluginDescriptorParser.loadPlugins()).willReturn(pluginsFromDescriptor);
given(pluginDao.list()).willReturn(pluginsFromDatabase);
// when
pluginAccessor.init();
}
use of com.qcadoo.plugin.internal.api.InternalPlugin 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.internal.api.InternalPlugin 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