Search in sources :

Example 1 with MultiTenantUtil

use of com.qcadoo.tenant.api.MultiTenantUtil 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 2 with MultiTenantUtil

use of com.qcadoo.tenant.api.MultiTenantUtil 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);
}
Also used : MultiTenantUtil(com.qcadoo.tenant.api.MultiTenantUtil) PluginManager(com.qcadoo.plugin.api.PluginManager) SessionFactory(org.hibernate.SessionFactory) PluginUtilsService(com.qcadoo.plugin.internal.PluginUtilsService) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) PluginStateResolver(com.qcadoo.plugin.api.PluginStateResolver) InternalPluginAccessor(com.qcadoo.plugin.internal.api.InternalPluginAccessor) File(java.io.File) DefaultMultiTenantService(com.qcadoo.tenant.internal.DefaultMultiTenantService) Before(org.junit.Before)

Example 3 with MultiTenantUtil

use of com.qcadoo.tenant.api.MultiTenantUtil 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);
}
Also used : MultiTenantUtil(com.qcadoo.tenant.api.MultiTenantUtil) SessionFactory(org.hibernate.SessionFactory) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) InternalDataDefinitionService(com.qcadoo.model.internal.api.InternalDataDefinitionService) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) DefaultMultiTenantService(com.qcadoo.tenant.internal.DefaultMultiTenantService) BeforeClass(org.junit.BeforeClass)

Example 4 with MultiTenantUtil

use of com.qcadoo.tenant.api.MultiTenantUtil 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);
}
Also used : MultiTenantUtil(com.qcadoo.tenant.api.MultiTenantUtil) PluginStateResolver(com.qcadoo.plugin.api.PluginStateResolver) DefaultMultiTenantService(com.qcadoo.tenant.internal.DefaultMultiTenantService) Test(org.junit.Test)

Aggregations

MultiTenantUtil (com.qcadoo.tenant.api.MultiTenantUtil)4 DefaultMultiTenantService (com.qcadoo.tenant.internal.DefaultMultiTenantService)4 PluginStateResolver (com.qcadoo.plugin.api.PluginStateResolver)3 PluginUtilsService (com.qcadoo.plugin.internal.PluginUtilsService)2 SessionFactory (org.hibernate.SessionFactory)2 Test (org.junit.Test)2 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)2 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 InternalDataDefinitionService (com.qcadoo.model.internal.api.InternalDataDefinitionService)1 Module (com.qcadoo.plugin.api.Module)1 ModuleFactory (com.qcadoo.plugin.api.ModuleFactory)1 Plugin (com.qcadoo.plugin.api.Plugin)1 PluginManager (com.qcadoo.plugin.api.PluginManager)1 InternalPlugin (com.qcadoo.plugin.internal.api.InternalPlugin)1 InternalPluginAccessor (com.qcadoo.plugin.internal.api.InternalPluginAccessor)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1 BeforeClass (org.junit.BeforeClass)1 InOrder (org.mockito.InOrder)1