use of com.qcadoo.plugin.api.Module 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.Module 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();
}
});
}
}
}
use of com.qcadoo.plugin.api.Module 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();
}
});
}
}
}
}
}
use of com.qcadoo.plugin.api.Module 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();
}
}
use of com.qcadoo.plugin.api.Module in project qcadoo by qcadoo.
the class DefaultPluginDescriptorParser method addModules.
private void addModules(final Node modulesNode, final Builder pluginBuilder, final String pluginIdentifier) {
for (Node child : getChildNodes(modulesNode)) {
ModuleFactory<?> moduleFactory = moduleFactoryAccessor.getModuleFactory(child.getLocalName());
LOG.info("Parsing module " + child.getLocalName() + " for plugin " + pluginIdentifier);
Module module = moduleFactory.parse(pluginIdentifier, convertNodeToJdomElement(child));
checkNotNull(module, "Module for " + child.getLocalName() + " is null");
pluginBuilder.withModule(moduleFactory, module);
}
}
Aggregations