use of com.qcadoo.plugin.internal.api.InternalPlugin in project qcadoo by qcadoo.
the class PluginDependencyManagerTest method shouldSortPluginsWithMissingDependencies.
@Test
public void shouldSortPluginsWithMissingDependencies() {
// given
Set<PluginDependencyInformation> rp1 = new HashSet<PluginDependencyInformation>();
rp1.add(new PluginDependencyInformation("p2"));
Set<PluginDependencyInformation> rp2 = new HashSet<PluginDependencyInformation>();
rp2.add(new PluginDependencyInformation("p3"));
Set<PluginDependencyInformation> rp3 = new HashSet<PluginDependencyInformation>();
Set<PluginDependencyInformation> rp4 = new HashSet<PluginDependencyInformation>();
rp4.add(new PluginDependencyInformation("p2"));
rp4.add(new PluginDependencyInformation("p3"));
Set<PluginDependencyInformation> rp5 = new HashSet<PluginDependencyInformation>();
rp5.add(new PluginDependencyInformation("p1"));
rp5.add(new PluginDependencyInformation("p3"));
InternalPlugin p1 = mock(InternalPlugin.class, "p1");
given(p1.getIdentifier()).willReturn("p1");
given(p1.getVersion()).willReturn(new Version("1.1"));
given(p1.getRequiredPlugins()).willReturn(rp1);
InternalPlugin p2 = mock(InternalPlugin.class, "p2");
given(p2.getIdentifier()).willReturn("p2");
given(p2.getVersion()).willReturn(new Version("1.1"));
given(p2.getRequiredPlugins()).willReturn(rp2);
InternalPlugin p3 = mock(InternalPlugin.class, "p3");
given(p3.getIdentifier()).willReturn("p3");
given(p3.getVersion()).willReturn(new Version("1.1"));
given(p3.getRequiredPlugins()).willReturn(rp3);
InternalPlugin p4 = mock(InternalPlugin.class, "p4");
given(p4.getIdentifier()).willReturn("p4");
given(p4.getVersion()).willReturn(new Version("1.1"));
given(p4.getRequiredPlugins()).willReturn(rp4);
InternalPlugin p5 = mock(InternalPlugin.class, "p5");
given(p5.getIdentifier()).willReturn("p5");
given(p5.getVersion()).willReturn(new Version("1.1"));
given(p5.getRequiredPlugins()).willReturn(rp5);
given(pluginAccessor.getPlugin("p1")).willReturn(p1);
given(pluginAccessor.getPlugin("p2")).willReturn(p2);
given(pluginAccessor.getPlugin("p3")).willReturn(p3);
given(pluginAccessor.getPlugin("p4")).willReturn(p4);
given(pluginAccessor.getPlugin("p5")).willReturn(p5);
List<Plugin> argumentPlugins = new ArrayList<Plugin>();
argumentPlugins.add(p1);
argumentPlugins.add(p2);
argumentPlugins.add(p4);
argumentPlugins.add(p5);
// when
List<Plugin> sortedPlugins = manager.sortPluginsInDependencyOrder(argumentPlugins);
// then
assertEquals(4, sortedPlugins.size());
assertEquals(p2, sortedPlugins.get(0));
assertEquals(p4, sortedPlugins.get(1));
assertEquals(p1, sortedPlugins.get(2));
assertEquals(p5, sortedPlugins.get(3));
}
use of com.qcadoo.plugin.internal.api.InternalPlugin in project qcadoo by qcadoo.
the class PluginDescriptorParserTest method shouldParseAllPlugins.
@Test
public void shouldParseAllPlugins() throws Exception {
// given
Resource[] testXmlsList = new Resource[] { xmlFile1, xmlFile2 };
given(pluginDescriptorResolver.getDescriptors()).willReturn(testXmlsList);
Plugin p1 = parser.parse(xmlFile1);
Plugin p2 = parser.parse(xmlFile2);
// when
Set<InternalPlugin> result = parser.loadPlugins();
// then
assertEquals(2, result.size());
assertTrue(result.contains(p1));
assertTrue(result.contains(p2));
}
use of com.qcadoo.plugin.internal.api.InternalPlugin in project qcadoo by qcadoo.
the class PluginManagerTest method shouldEnableMultiplePlugins.
@Test
public void shouldEnableMultiplePlugins() throws Exception {
// given
given(plugin.hasState(PluginState.DISABLED)).willReturn(true);
InternalPlugin nextPlugin = mock(InternalPlugin.class, "nextPlugin");
given(nextPlugin.hasState(PluginState.DISABLED)).willReturn(true);
given(pluginAccessor.getPlugin("nextPluginname")).willReturn(nextPlugin);
given(anotherPlugin.hasState(PluginState.TEMPORARY)).willReturn(true);
given(anotherPlugin.getFilename()).willReturn("filename");
given(pluginFileManager.installPlugin("filename")).willReturn(true);
PluginDependencyResult pluginDependencyResult = PluginDependencyResultImpl.satisfiedDependencies();
given(pluginDependencyManager.getDependenciesToEnable(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) plugin, (Plugin) anotherPlugin, (Plugin) nextPlugin));
// when
PluginOperationResult pluginOperationResult = pluginManager.enablePlugin("pluginname", "anotherPluginname", "nextPluginname");
// then
InOrder inOrder = inOrder(plugin, anotherPlugin, nextPlugin);
inOrder.verify(plugin).changeStateTo(PluginState.ENABLED);
inOrder.verify(anotherPlugin).changeStateTo(PluginState.ENABLING);
inOrder.verify(nextPlugin).changeStateTo(PluginState.ENABLED);
verify(pluginDao).save(plugin);
verify(pluginAccessor).savePlugin(plugin);
verify(pluginDao).save(nextPlugin);
verify(pluginAccessor).savePlugin(nextPlugin);
verify(pluginDao).save(anotherPlugin);
verify(pluginAccessor).savePlugin(anotherPlugin);
assertTrue(pluginOperationResult.isSuccess());
assertEquals(PluginOperationStatus.SUCCESS_WITH_RESTART, pluginOperationResult.getStatus());
assertEquals(0, pluginOperationResult.getPluginDependencyResult().getDependenciesToEnable().size());
assertEquals(0, pluginOperationResult.getPluginDependencyResult().getUnsatisfiedDependencies().size());
}
use of com.qcadoo.plugin.internal.api.InternalPlugin 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.internal.api.InternalPlugin 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();
}
Aggregations