Search in sources :

Example 21 with InternalPlugin

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();
    }
}
Also used : InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin) ModuleFactory(com.qcadoo.plugin.api.ModuleFactory) Module(com.qcadoo.plugin.api.Module)

Example 22 with InternalPlugin

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);
}
Also used : InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin) QcadooPluginPlugin(com.qcadoo.model.beans.qcadooPlugin.QcadooPluginPlugin) InOrder(org.mockito.InOrder) QcadooPluginPlugin(com.qcadoo.model.beans.qcadooPlugin.QcadooPluginPlugin) Plugin(com.qcadoo.plugin.api.Plugin) InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin) Test(org.junit.Test)

Example 23 with InternalPlugin

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();
}
Also used : InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin) QcadooPluginPlugin(com.qcadoo.model.beans.qcadooPlugin.QcadooPluginPlugin) Version(com.qcadoo.plugin.api.Version) Test(org.junit.Test)

Example 24 with InternalPlugin

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);
}
Also used : InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin) QcadooPluginPlugin(com.qcadoo.model.beans.qcadooPlugin.QcadooPluginPlugin) InOrder(org.mockito.InOrder) QcadooPluginPlugin(com.qcadoo.model.beans.qcadooPlugin.QcadooPluginPlugin) Plugin(com.qcadoo.plugin.api.Plugin) InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin) Test(org.junit.Test)

Example 25 with InternalPlugin

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();
    }
}
Also used : InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin) PluginDependencyResult(com.qcadoo.plugin.api.PluginDependencyResult) ArrayList(java.util.ArrayList) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) QcadooPluginPlugin(com.qcadoo.model.beans.qcadooPlugin.QcadooPluginPlugin) Plugin(com.qcadoo.plugin.api.Plugin) InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin)

Aggregations

InternalPlugin (com.qcadoo.plugin.internal.api.InternalPlugin)31 Plugin (com.qcadoo.plugin.api.Plugin)21 Test (org.junit.Test)18 QcadooPluginPlugin (com.qcadoo.model.beans.qcadooPlugin.QcadooPluginPlugin)15 PluginDependencyResult (com.qcadoo.plugin.api.PluginDependencyResult)9 ArrayList (java.util.ArrayList)8 Version (com.qcadoo.plugin.api.Version)6 InOrder (org.mockito.InOrder)6 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)5 ModuleFactory (com.qcadoo.plugin.api.ModuleFactory)5 Module (com.qcadoo.plugin.api.Module)4 PluginDependencyInformation (com.qcadoo.plugin.api.PluginDependencyInformation)4 PluginOperationResult (com.qcadoo.plugin.api.PluginOperationResult)4 PluginException (com.qcadoo.plugin.internal.PluginException)4 SimplePluginStatusResolver (com.qcadoo.plugin.internal.dependencymanager.SimplePluginStatusResolver)3 File (java.io.File)3 HashSet (java.util.HashSet)3 MultiTenantCallback (com.qcadoo.tenant.api.MultiTenantCallback)2 Resource (org.springframework.core.io.Resource)2 PluginStateResolver (com.qcadoo.plugin.api.PluginStateResolver)1