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());
}
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());
}
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();
}
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());
}
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));
}
Aggregations