Search in sources :

Example 21 with Plugin

use of com.qcadoo.plugin.api.Plugin in project qcadoo by qcadoo.

the class PluginManagerTest method shouldEnableDisabledPlugin.

@Test
public void shouldEnableDisabledPlugin() throws Exception {
    // given
    PluginDependencyResult pluginDependencyResult = PluginDependencyResultImpl.satisfiedDependencies();
    given(pluginDependencyManager.getDependenciesToEnable(Mockito.eq(singletonList((Plugin) plugin)), Mockito.any(SimplePluginStatusResolver.class))).willReturn(pluginDependencyResult);
    given(pluginDependencyManager.sortPluginsInDependencyOrder(singletonList((Plugin) plugin))).willReturn(singletonList((Plugin) plugin));
    // when
    PluginOperationResult pluginOperationResult = pluginManager.enablePlugin("pluginname");
    // then
    verify(plugin).changeStateTo(PluginState.ENABLED);
    verify(pluginDao).save(plugin);
    verify(pluginAccessor).savePlugin(plugin);
    assertTrue(pluginOperationResult.isSuccess());
    assertEquals(PluginOperationStatus.SUCCESS, pluginOperationResult.getStatus());
    assertEquals(0, pluginOperationResult.getPluginDependencyResult().getDependenciesToEnable().size());
    assertEquals(0, pluginOperationResult.getPluginDependencyResult().getUnsatisfiedDependencies().size());
}
Also used : PluginDependencyResult(com.qcadoo.plugin.api.PluginDependencyResult) PluginOperationResult(com.qcadoo.plugin.api.PluginOperationResult) SimplePluginStatusResolver(com.qcadoo.plugin.internal.dependencymanager.SimplePluginStatusResolver) Plugin(com.qcadoo.plugin.api.Plugin) InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin) Test(org.junit.Test)

Example 22 with Plugin

use of com.qcadoo.plugin.api.Plugin in project qcadoo by qcadoo.

the class PluginManagerTest method shouldUninstallMultiplePlugins.

@Test
public void shouldUninstallMultiplePlugins() throws Exception {
    // given
    given(plugin.hasState(PluginState.TEMPORARY)).willReturn(false);
    given(plugin.hasState(PluginState.ENABLED)).willReturn(true);
    given(plugin.getFilename()).willReturn("filename");
    given(anotherPlugin.hasState(PluginState.TEMPORARY)).willReturn(true);
    given(anotherPlugin.hasState(PluginState.ENABLED)).willReturn(false);
    given(anotherPlugin.getFilename()).willReturn("anotherFilename");
    InternalPlugin nextPlugin = mock(InternalPlugin.class, "nextPlugin");
    given(nextPlugin.hasState(PluginState.TEMPORARY)).willReturn(false);
    given(nextPlugin.hasState(PluginState.ENABLED)).willReturn(true);
    given(nextPlugin.getFilename()).willReturn("nextPluginFilename");
    given(pluginAccessor.getPlugin("nextPluginname")).willReturn(nextPlugin);
    PluginDependencyResult pluginDependencyResult = PluginDependencyResultImpl.satisfiedDependencies();
    given(pluginDependencyManager.getDependenciesToUninstall(Mockito.eq(newArrayList((Plugin) plugin, (Plugin) anotherPlugin, (Plugin) nextPlugin)), Mockito.any(SimplePluginStatusResolver.class))).willReturn(pluginDependencyResult);
    given(pluginDependencyManager.sortPluginsInDependencyOrder(newArrayList((Plugin) plugin, (Plugin) anotherPlugin, (Plugin) nextPlugin))).willReturn(newArrayList((Plugin) nextPlugin, (Plugin) plugin, (Plugin) anotherPlugin));
    // when
    PluginOperationResult pluginOperationResult = pluginManager.uninstallPlugin("pluginname", "anotherPluginname", "nextPluginname");
    // then
    InOrder inOrder = inOrder(plugin, nextPlugin);
    inOrder.verify(plugin).changeStateTo(PluginState.DISABLED);
    inOrder.verify(nextPlugin).changeStateTo(PluginState.DISABLED);
    verify(anotherPlugin, never()).changeStateTo(PluginState.DISABLED);
    verify(pluginDao).delete(plugin);
    verify(pluginAccessor).removePlugin(plugin);
    verify(pluginDao).delete(nextPlugin);
    verify(pluginAccessor).removePlugin(nextPlugin);
    verify(pluginDao).delete(anotherPlugin);
    verify(pluginAccessor).removePlugin(anotherPlugin);
    verify(pluginFileManager).uninstallPlugin("filename", "anotherFilename", "nextPluginFilename");
    assertTrue(pluginOperationResult.isSuccess());
    assertEquals(PluginOperationStatus.SUCCESS_WITH_RESTART, pluginOperationResult.getStatus());
    assertEquals(0, pluginOperationResult.getPluginDependencyResult().getDependenciesToUninstall().size());
}
Also used : InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin) PluginDependencyResult(com.qcadoo.plugin.api.PluginDependencyResult) InOrder(org.mockito.InOrder) PluginOperationResult(com.qcadoo.plugin.api.PluginOperationResult) SimplePluginStatusResolver(com.qcadoo.plugin.internal.dependencymanager.SimplePluginStatusResolver) Plugin(com.qcadoo.plugin.api.Plugin) InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin) Test(org.junit.Test)

Example 23 with Plugin

use of com.qcadoo.plugin.api.Plugin in project qcadoo by qcadoo.

the class ModuleFactoryAccessorTest method shouldCallInitOnAllModuleFactories.

@Test
public void shouldCallInitOnAllModuleFactories() throws Exception {
    // given
    MultiTenantUtil multiTenantUtil = new MultiTenantUtil();
    ReflectionTestUtils.setField(multiTenantUtil, "multiTenantService", new DefaultMultiTenantService());
    multiTenantUtil.init();
    PluginStateResolver mockPluginStateResolver = mock(PluginStateResolver.class);
    given(mockPluginStateResolver.isEnabled("plugin1")).willReturn(false);
    given(mockPluginStateResolver.isEnabled("plugin2")).willReturn(true);
    PluginUtilsService pluginUtil = new PluginUtilsService(mockPluginStateResolver);
    pluginUtil.init();
    ModuleFactory<?> moduleFactory1 = mock(ModuleFactory.class);
    given(moduleFactory1.getIdentifier()).willReturn("module1");
    ModuleFactory<?> moduleFactory2 = mock(ModuleFactory.class);
    given(moduleFactory2.getIdentifier()).willReturn("module2");
    DefaultModuleFactoryAccessor moduleFactoryAccessor = new DefaultModuleFactoryAccessor();
    List<ModuleFactory<?>> factoriesList = new ArrayList<>();
    factoriesList.add(moduleFactory1);
    factoriesList.add(moduleFactory2);
    moduleFactoryAccessor.setModuleFactories(factoriesList);
    InternalPlugin plugin1 = mock(InternalPlugin.class);
    Module module111 = mock(Module.class);
    Module module112 = mock(Module.class);
    Module module12 = mock(Module.class);
    given(plugin1.getModules(moduleFactory1)).willReturn(newArrayList(module111, module112));
    given(plugin1.getModules(moduleFactory2)).willReturn(newArrayList(module12));
    given(plugin1.hasState(PluginState.ENABLED)).willReturn(false);
    given(plugin1.getIdentifier()).willReturn("plugin1");
    InternalPlugin plugin2 = mock(InternalPlugin.class);
    Module module21 = mock(Module.class);
    Module module22 = mock(Module.class);
    given(plugin2.getModules(moduleFactory1)).willReturn(newArrayList(module21));
    given(plugin2.getModules(moduleFactory2)).willReturn(newArrayList(module22));
    given(plugin2.hasState(PluginState.ENABLED)).willReturn(true);
    given(plugin2.getIdentifier()).willReturn("plugin2");
    List<Plugin> plugins = newArrayList(plugin1, plugin2);
    // when
    moduleFactoryAccessor.init(plugins);
    // then
    InOrder inOrder = inOrder(moduleFactory1, moduleFactory2, module111, module112, module12, module21, module22);
    inOrder.verify(moduleFactory1).preInit();
    inOrder.verify(module111).init();
    inOrder.verify(module112).init();
    inOrder.verify(module21).init();
    inOrder.verify(moduleFactory1).postInit();
    inOrder.verify(moduleFactory2).preInit();
    inOrder.verify(module12).init();
    inOrder.verify(module22).init();
    inOrder.verify(moduleFactory2).postInit();
    inOrder.verify(module21).enableOnStartup();
    inOrder.verify(module21).multiTenantEnableOnStartup();
    inOrder.verify(module22).enableOnStartup();
    inOrder.verify(module22).multiTenantEnableOnStartup();
    inOrder.verify(module12).disableOnStartup();
    inOrder.verify(module12).multiTenantDisableOnStartup();
    inOrder.verify(module112).disableOnStartup();
    inOrder.verify(module112).multiTenantDisableOnStartup();
    inOrder.verify(module111).disableOnStartup();
    inOrder.verify(module111).multiTenantDisableOnStartup();
}
Also used : MultiTenantUtil(com.qcadoo.tenant.api.MultiTenantUtil) PluginUtilsService(com.qcadoo.plugin.internal.PluginUtilsService) InOrder(org.mockito.InOrder) ArrayList(java.util.ArrayList) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin) ModuleFactory(com.qcadoo.plugin.api.ModuleFactory) PluginStateResolver(com.qcadoo.plugin.api.PluginStateResolver) Module(com.qcadoo.plugin.api.Module) DefaultMultiTenantService(com.qcadoo.tenant.internal.DefaultMultiTenantService) Plugin(com.qcadoo.plugin.api.Plugin) InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin) Test(org.junit.Test)

Example 24 with Plugin

use of com.qcadoo.plugin.api.Plugin in project qcadoo by qcadoo.

the class PluginTest method shouldHaveVersion.

@Test
public void shouldHaveVersion() throws Exception {
    // given
    Plugin plugin = DefaultPlugin.Builder.identifier("identifier1", Collections.<ModuleFactory<?>>emptyList()).withVersion("1.2.3").build();
    // then
    assertEquals(new Version("1.2.3"), plugin.getVersion());
}
Also used : Version(com.qcadoo.plugin.api.Version) Plugin(com.qcadoo.plugin.api.Plugin) Test(org.junit.Test)

Example 25 with Plugin

use of com.qcadoo.plugin.api.Plugin in project qcadoo by qcadoo.

the class PluginAccessorTest method shouldRemovePlugin.

@Test
public void shouldRemovePlugin() throws Exception {
    // given
    InternalPlugin plugin1 = mock(InternalPlugin.class, "plugin1");
    given(plugin1.getIdentifier()).willReturn("identifier1");
    QcadooPluginPlugin pluginsPlugin1 = mock(QcadooPluginPlugin.class);
    given(pluginsPlugin1.getIdentifier()).willReturn("identifier1");
    given(pluginsPlugin1.getState()).willReturn("ENABLED");
    given(pluginsPlugin1.getVersion()).willReturn("0.0.0");
    InternalPlugin plugin2 = mock(InternalPlugin.class);
    given(plugin2.getIdentifier()).willReturn("identifier2");
    QcadooPluginPlugin pluginsPlugin2 = mock(QcadooPluginPlugin.class);
    given(pluginsPlugin2.getIdentifier()).willReturn("identifier2");
    given(pluginsPlugin2.getState()).willReturn("ENABLED");
    given(pluginsPlugin2.getVersion()).willReturn("0.0.0");
    given(pluginDescriptorParser.loadPlugins()).willReturn(Sets.newHashSet(plugin1, plugin2));
    given(pluginDao.list()).willReturn(Sets.<QcadooPluginPlugin>newHashSet(pluginsPlugin1, pluginsPlugin2));
    pluginAccessor.init();
    // when
    pluginAccessor.removePlugin(plugin1);
    // then
    assertEquals(1, pluginAccessor.getPlugins().size());
    assertThat(pluginAccessor.getPlugins(), hasItems((Plugin) plugin2));
}
Also used : InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin) QcadooPluginPlugin(com.qcadoo.model.beans.qcadooPlugin.QcadooPluginPlugin) QcadooPluginPlugin(com.qcadoo.model.beans.qcadooPlugin.QcadooPluginPlugin) Plugin(com.qcadoo.plugin.api.Plugin) InternalPlugin(com.qcadoo.plugin.internal.api.InternalPlugin) Test(org.junit.Test)

Aggregations

Plugin (com.qcadoo.plugin.api.Plugin)71 InternalPlugin (com.qcadoo.plugin.internal.api.InternalPlugin)59 Test (org.junit.Test)58 PluginDependencyResult (com.qcadoo.plugin.api.PluginDependencyResult)38 PluginDependencyInformation (com.qcadoo.plugin.api.PluginDependencyInformation)28 HashSet (java.util.HashSet)25 ArrayList (java.util.ArrayList)15 QcadooPluginPlugin (com.qcadoo.model.beans.qcadooPlugin.QcadooPluginPlugin)13 DefaultPlugin (com.qcadoo.plugin.internal.DefaultPlugin)11 PluginOperationResult (com.qcadoo.plugin.api.PluginOperationResult)8 Version (com.qcadoo.plugin.api.Version)8 SimplePluginStatusResolver (com.qcadoo.plugin.internal.dependencymanager.SimplePluginStatusResolver)8 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)6 InOrder (org.mockito.InOrder)6 ModuleFactory (com.qcadoo.plugin.api.ModuleFactory)5 VersionOfDependency (com.qcadoo.plugin.api.VersionOfDependency)4 Entity (com.qcadoo.model.api.Entity)2 EntityList (com.qcadoo.model.api.EntityList)2 Module (com.qcadoo.plugin.api.Module)2 PluginException (com.qcadoo.plugin.internal.PluginException)2