Search in sources :

Example 11 with InternalPlugin

use of com.qcadoo.plugin.internal.api.InternalPlugin in project qcadoo by qcadoo.

the class PluginAccessorTest method shouldListAllPlugins.

@Test
public void shouldListAllPlugins() 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.getVersion()).willReturn("0.0.0");
    given(plugin1.compareVersion(new Version(pluginsPlugin1.getVersion()))).willReturn(0);
    given(plugin1.hasState(PluginState.ENABLED)).willReturn(false);
    given(pluginsPlugin1.getState()).willReturn("DISABLED");
    QcadooPluginPlugin pluginsPlugin21 = mock(QcadooPluginPlugin.class, "plugin21");
    given(pluginsPlugin21.getIdentifier()).willReturn("identifier21");
    given(pluginsPlugin21.getState()).willReturn("ENABLED");
    InternalPlugin plugin22 = mock(InternalPlugin.class, "plugin22");
    given(plugin22.getIdentifier()).willReturn("identifier21");
    given(plugin22.hasState(PluginState.ENABLED)).willReturn(true);
    given(pluginsPlugin21.getVersion()).willReturn("0.0.0");
    given(plugin22.compareVersion(new Version(pluginsPlugin21.getVersion()))).willReturn(1);
    InternalPlugin plugin3 = mock(InternalPlugin.class, "plugin3");
    QcadooPluginPlugin pluginsPlugin3 = mock(QcadooPluginPlugin.class, "plugin3");
    given(plugin3.getIdentifier()).willReturn("identifier3");
    given(pluginsPlugin3.getIdentifier()).willReturn("identifier3");
    given(pluginsPlugin3.getVersion()).willReturn("0.0.0");
    given(plugin3.hasState(PluginState.ENABLED)).willReturn(true);
    given(plugin3.isSystemPlugin()).willReturn(true);
    given(pluginsPlugin3.getState()).willReturn("ENABLED");
    InternalPlugin plugin4 = mock(InternalPlugin.class, "plugin4");
    given(plugin4.getIdentifier()).willReturn("identifier4");
    given(plugin4.hasState(PluginState.ENABLED)).willReturn(false);
    Set<InternalPlugin> pluginsFromDescriptor = Sets.newHashSet(plugin1, plugin22, plugin3, plugin4);
    Set<QcadooPluginPlugin> pluginsFromDatabase = Sets.newHashSet(pluginsPlugin1, pluginsPlugin21, pluginsPlugin3);
    given(pluginDescriptorParser.loadPlugins()).willReturn(pluginsFromDescriptor);
    given(pluginDao.list()).willReturn(pluginsFromDatabase);
    // when
    pluginAccessor.init();
    // then
    verify(plugin1).changeStateTo(PluginState.DISABLED);
    verify(plugin22).changeStateTo(PluginState.ENABLED);
    verify(plugin3).changeStateTo(PluginState.ENABLED);
    verify(plugin4).changeStateTo(PluginState.ENABLING);
    assertThat(pluginAccessor.getPlugins(), hasItems((Plugin) plugin1, (Plugin) plugin22, (Plugin) plugin3, (Plugin) plugin4));
    assertThat(pluginAccessor.getEnabledPlugins(), hasItems((Plugin) plugin22, (Plugin) plugin3));
    assertThat(pluginAccessor.getEnabledPlugins(), not(hasItem((Plugin) plugin1)));
    assertThat(pluginAccessor.getEnabledPlugins(), not(hasItem((Plugin) plugin4)));
    assertThat(pluginAccessor.getSystemPlugins(), hasItem((Plugin) plugin3));
    assertEquals(plugin1, pluginAccessor.getPlugin("identifier1"));
    assertEquals(plugin22, pluginAccessor.getPlugin("identifier21"));
    assertEquals(plugin3, pluginAccessor.getPlugin("identifier3"));
    assertEquals(plugin4, pluginAccessor.getPlugin("identifier4"));
    assertNull(pluginAccessor.getEnabledPlugin("identifier1"));
    assertEquals(plugin22, pluginAccessor.getEnabledPlugin("identifier21"));
    assertEquals(plugin3, pluginAccessor.getEnabledPlugin("identifier3"));
    assertNull(pluginAccessor.getEnabledPlugin("identifier4"));
}
Also used : InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin) QcadooPluginPlugin(com.qcadoo.model.beans.qcadooPlugin.QcadooPluginPlugin) Version(com.qcadoo.plugin.api.Version) 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 12 with InternalPlugin

use of com.qcadoo.plugin.internal.api.InternalPlugin in project qcadoo by qcadoo.

the class PluginAccessorTest method shouldNotDeleteTemporaryPlugins.

@Test
public void shouldNotDeleteTemporaryPlugins() throws Exception {
    // given
    QcadooPluginPlugin pluginsPlugin1 = mock(QcadooPluginPlugin.class);
    given(pluginsPlugin1.getState()).willReturn(PluginState.TEMPORARY.toString());
    QcadooPluginPlugin pluginsPlugin2 = mock(QcadooPluginPlugin.class);
    given(pluginsPlugin2.getState()).willReturn(PluginState.ENABLED.toString());
    Set<InternalPlugin> pluginsFromDescriptor = Sets.newHashSet();
    Set<QcadooPluginPlugin> pluginsFromDatabase = Sets.newHashSet(pluginsPlugin1, pluginsPlugin2);
    given(pluginDescriptorParser.loadPlugins()).willReturn(pluginsFromDescriptor);
    given(pluginDao.list()).willReturn(pluginsFromDatabase);
    // when
    pluginAccessor.init();
    verify(pluginDao, never()).delete(pluginsPlugin1);
    verify(pluginDao).delete(pluginsPlugin2);
}
Also used : QcadooPluginPlugin(com.qcadoo.model.beans.qcadooPlugin.QcadooPluginPlugin) InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin) Test(org.junit.Test)

Example 13 with InternalPlugin

use of com.qcadoo.plugin.internal.api.InternalPlugin in project qcadoo by qcadoo.

the class DefaultModuleFactoryAccessor method multiTenantDisable.

@Override
public void multiTenantDisable(final int tenantId, final Plugin plugin) {
    List<ModuleFactory<?>> factories = new ArrayList<ModuleFactory<?>>(moduleFactoryRegistry.values());
    Collections.reverse(factories);
    for (ModuleFactory<?> moduleFactory : factories) {
        List<Module> modules = ((InternalPlugin) plugin).getModules(moduleFactory);
        Collections.reverse(modules);
        for (final Module module : modules) {
            MultiTenantUtil.doInMultiTenantContext(tenantId, new MultiTenantCallback() {

                @Override
                public void invoke() {
                    module.multiTenantDisable();
                }
            });
        }
    }
}
Also used : InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin) MultiTenantCallback(com.qcadoo.tenant.api.MultiTenantCallback) ModuleFactory(com.qcadoo.plugin.api.ModuleFactory) ArrayList(java.util.ArrayList) Module(com.qcadoo.plugin.api.Module)

Example 14 with InternalPlugin

use of com.qcadoo.plugin.internal.api.InternalPlugin in project qcadoo by qcadoo.

the class PluginIntegrationTest method shouldUpdateEnabledPlugin.

@Test
public void shouldUpdateEnabledPlugin() throws Exception {
    // given
    JarPluginArtifact artifact = new JarPluginArtifact(new File("src/test/resources/com/qcadoo/plugin/integration/plugin4.jar"));
    JarPluginArtifact artifact2 = new JarPluginArtifact(new File("src/test/resources/com/qcadoo/plugin/integration/plugin4.1.jar"));
    pluginManager.installPlugin(artifact);
    pluginManager.enablePlugin("plugin4");
    ((InternalPlugin) pluginAccessor.getPlugin("plugin4")).changeStateTo(PluginState.ENABLED);
    // when
    PluginOperationResult result = pluginManager.installPlugin(artifact2);
    // then
    assertTrue(result.isSuccess());
    assertTrue(result.isRestartNeccessary());
    assertNotNull(pluginAccessor.getPlugin("plugin4"));
    assertTrue(pluginAccessor.getPlugin("plugin4").hasState(PluginState.ENABLING));
    assertEquals(new Version("1.2.4"), pluginAccessor.getPlugin("plugin4").getVersion());
}
Also used : InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin) JarPluginArtifact(com.qcadoo.plugin.api.artifact.JarPluginArtifact) Version(com.qcadoo.plugin.api.Version) PluginOperationResult(com.qcadoo.plugin.api.PluginOperationResult) File(java.io.File) Test(org.junit.Test)

Example 15 with InternalPlugin

use of com.qcadoo.plugin.internal.api.InternalPlugin in project qcadoo by qcadoo.

the class DefaultModuleFactoryAccessor method init.

@Override
public void init(final List<Plugin> pluginsToInitialize) {
    for (ModuleFactory<?> moduleFactory : moduleFactoryRegistry.values()) {
        moduleFactory.preInit();
        for (Plugin plugin : pluginsToInitialize) {
            for (Module module : ((InternalPlugin) plugin).getModules(moduleFactory)) {
                module.init();
            }
        }
        moduleFactory.postInit();
    }
    List<ModuleFactory<?>> factories = new ArrayList<ModuleFactory<?>>(moduleFactoryRegistry.values());
    List<Plugin> plugins = new ArrayList<Plugin>(pluginsToInitialize);
    for (ModuleFactory<?> moduleFactory : factories) {
        for (final Plugin plugin : plugins) {
            List<Module> modules = ((InternalPlugin) plugin).getModules(moduleFactory);
            for (final Module module : modules) {
                if (plugin.hasState(PluginState.ENABLED)) {
                    module.enableOnStartup();
                    MultiTenantUtil.doInMultiTenantContext(new MultiTenantCallback() {

                        @Override
                        public void invoke() {
                            module.multiTenantEnableOnStartup();
                        }
                    });
                }
            }
        }
    }
    Collections.reverse(factories);
    Collections.reverse(plugins);
    for (ModuleFactory<?> moduleFactory : factories) {
        for (final Plugin plugin : plugins) {
            List<Module> modules = ((InternalPlugin) plugin).getModules(moduleFactory);
            Collections.reverse(modules);
            for (final Module module : modules) {
                if (!plugin.hasState(PluginState.ENABLED) && !plugin.hasState(PluginState.ENABLING)) {
                    module.disableOnStartup();
                    MultiTenantUtil.doInMultiTenantContext(new MultiTenantCallback() {

                        @Override
                        public void invoke() {
                            module.multiTenantDisableOnStartup();
                        }
                    });
                }
            }
        }
    }
}
Also used : InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin) MultiTenantCallback(com.qcadoo.tenant.api.MultiTenantCallback) ModuleFactory(com.qcadoo.plugin.api.ModuleFactory) ArrayList(java.util.ArrayList) Module(com.qcadoo.plugin.api.Module) 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