use of com.qcadoo.tenant.internal.DefaultMultiTenantService 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.tenant.internal.DefaultMultiTenantService in project qcadoo by qcadoo.
the class PluginIntegrationTest method init.
@Before
public void init() throws Exception {
MultiTenantUtil multiTenantUtil = new MultiTenantUtil();
ReflectionTestUtils.setField(multiTenantUtil, "multiTenantService", new DefaultMultiTenantService());
multiTenantUtil.init();
PluginStateResolver mockPluginStateResolver = mock(PluginStateResolver.class);
given(mockPluginStateResolver.isEnabled(Mockito.anyString())).willReturn(true);
PluginUtilsService pluginUtil = new PluginUtilsService(mockPluginStateResolver);
pluginUtil.init();
new File("target/plugins").mkdir();
new File("target/tmpPlugins").mkdir();
applicationContext = new ClassPathXmlApplicationContext();
applicationContext.setConfigLocation("com/qcadoo/plugin/integration/spring.xml");
applicationContext.registerShutdownHook();
applicationContext.refresh();
pluginAccessor = applicationContext.getBean(InternalPluginAccessor.class);
pluginManager = applicationContext.getBean(PluginManager.class);
sessionFactory = applicationContext.getBean(SessionFactory.class);
}
use of com.qcadoo.tenant.internal.DefaultMultiTenantService in project qcadoo by qcadoo.
the class IntegrationTest method classInit.
@BeforeClass
public static void classInit() throws Exception {
MultiTenantUtil multiTenantUtil = new MultiTenantUtil();
ReflectionTestUtils.setField(multiTenantUtil, "multiTenantService", new DefaultMultiTenantService());
multiTenantUtil.init();
applicationContext = new ClassPathXmlApplicationContext();
applicationContext.setConfigLocation("spring.xml");
applicationContext.refresh();
dataDefinitionService = applicationContext.getBean(InternalDataDefinitionService.class);
sessionFactory = applicationContext.getBean("sessionFactory", SessionFactory.class);
jdbcTemplate = applicationContext.getBean(JdbcTemplate.class);
verifyHooks = applicationContext.getBean(VerifyHooks.class);
}
use of com.qcadoo.tenant.internal.DefaultMultiTenantService in project qcadoo by qcadoo.
the class PluginChangeStateToTest method shouldChangeState.
@Test
public void shouldChangeState() throws Exception {
MultiTenantUtil multiTenantUtil = new MultiTenantUtil();
ReflectionTestUtils.setField(multiTenantUtil, "multiTenantService", new DefaultMultiTenantService());
multiTenantUtil.init();
mockPluginStateResolver = mock(PluginStateResolver.class);
PluginUtilsService pluginUtil = new PluginUtilsService(mockPluginStateResolver);
pluginUtil.init();
assertOperationNotSupported(null, PluginState.UNKNOWN);
assertOperationSupported(null, PluginState.TEMPORARY, false, false);
assertOperationSupported(null, PluginState.ENABLING, false, false);
assertOperationSupported(null, PluginState.ENABLED, false, false);
assertOperationSupported(null, PluginState.DISABLED, false, false);
assertOperationNotSupported(PluginState.TEMPORARY, PluginState.UNKNOWN);
assertOperationNotSupported(PluginState.TEMPORARY, PluginState.TEMPORARY);
assertOperationSupported(PluginState.TEMPORARY, PluginState.ENABLING, false, false);
assertOperationNotSupported(PluginState.TEMPORARY, PluginState.ENABLED);
assertOperationNotSupported(PluginState.TEMPORARY, PluginState.DISABLED);
assertOperationNotSupported(PluginState.ENABLING, PluginState.UNKNOWN);
assertOperationNotSupported(PluginState.ENABLING, PluginState.TEMPORARY);
assertOperationNotSupported(PluginState.ENABLING, PluginState.ENABLING);
assertOperationSupported(PluginState.ENABLING, PluginState.ENABLED, true, false);
assertOperationNotSupported(PluginState.ENABLING, PluginState.DISABLED);
assertOperationNotSupported(PluginState.ENABLED, PluginState.UNKNOWN);
assertOperationNotSupported(PluginState.ENABLED, PluginState.TEMPORARY);
assertOperationNotSupported(PluginState.ENABLED, PluginState.ENABLING);
assertOperationNotSupported(PluginState.ENABLED, PluginState.ENABLED);
assertOperationSupported(PluginState.ENABLED, PluginState.DISABLED, false, true);
assertOperationNotSupported(PluginState.DISABLED, PluginState.UNKNOWN);
assertOperationNotSupported(PluginState.DISABLED, PluginState.TEMPORARY);
assertOperationSupported(PluginState.DISABLED, PluginState.ENABLING, false, false);
assertOperationSupported(PluginState.DISABLED, PluginState.ENABLED, true, false);
assertOperationNotSupported(PluginState.DISABLED, PluginState.DISABLED);
}
Aggregations