Search in sources :

Example 1 with PluginUtilsService

use of com.qcadoo.plugin.internal.PluginUtilsService 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 PluginUtilsService

use of com.qcadoo.plugin.internal.PluginUtilsService in project qcadoo by qcadoo.

the class RunIfEnabledTest method init.

@SuppressWarnings("deprecation")
@Before
public final void init() {
    MockitoAnnotations.initMocks(this);
    pluginStateResolver = mock(PluginStateResolver.class);
    PluginUtilsService pluginUtilsService = new PluginUtilsService(pluginStateResolver);
    given(pluginStateResolver.isEnabled(Mockito.anyString())).willReturn(false);
    given(pluginStateResolver.isEnabledOrEnabling(Mockito.anyString())).willReturn(false);
    pluginUtilsService.init();
    aspectDependencyMock = mock(AspectDependencyMock.class);
}
Also used : PluginUtilsService(com.qcadoo.plugin.internal.PluginUtilsService) PluginStateResolver(com.qcadoo.plugin.api.PluginStateResolver) Before(org.junit.Before)

Example 3 with PluginUtilsService

use of com.qcadoo.plugin.internal.PluginUtilsService 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 4 with PluginUtilsService

use of com.qcadoo.plugin.internal.PluginUtilsService in project qcadoo by qcadoo.

the class GridComponentPatternTest method shouldNotFilterOutColumnsVisibleForTenant.

@Test
public void shouldNotFilterOutColumnsVisibleForTenant() throws Exception {
    // given
    PluginStateResolver pluginStateResolver = mock(PluginStateResolver.class);
    PluginUtilsService pluginUtil = new PluginUtilsService(pluginStateResolver);
    pluginUtil.init();
    given(pluginStateResolver.isEnabled("disabledPlugin")).willReturn(true);
    InternalViewDefinitionState viewDefinitionState = mock(InternalViewDefinitionState.class);
    DataDefinition dataDefinition = mock(DataDefinition.class);
    InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
    given(viewDefinition.getDataDefinition()).willReturn(dataDefinition);
    ComponentDefinition componentDefinition = getComponentDefinition(QcadooViewConstants.L_GRID, viewDefinition);
    componentDefinition.setTranslationService(translationService);
    componentDefinition.setApplicationContext(applicationContext);
    componentDefinition.setDataDefinition(dataDefinition);
    GridComponentPattern pattern = new GridComponentPattern(componentDefinition);
    FieldDefinition nameFieldDefinition = mock(FieldDefinition.class);
    given(nameFieldDefinition.getType()).willReturn(new EnumType(translationService, "", true, "v1", "v2"));
    given(dataDefinition.getField("name")).willReturn(nameFieldDefinition);
    pattern.addOption(new ComponentOption("column", ImmutableMap.of("name", "name", "fields", "name", "hidden", "true")));
    pattern.addOption(new ComponentOption("order", ImmutableMap.of("column", "name", "direction", "asc")));
    ViewGridColumnModuleColumnModel columnModel = new ViewGridColumnModuleColumnModel("invisible", "name");
    columnModel.setWidth(100);
    pattern.addColumn("disabledPlugin", columnModel);
    pattern.initialize();
    // when
    ComponentState state = pattern.createComponentState(viewDefinitionState);
    // then
    assertTrue(state instanceof GridComponent);
    @SuppressWarnings("unchecked") Map<String, GridComponentColumn> patternColumns = (Map<String, GridComponentColumn>) getField(pattern, "columns");
    @SuppressWarnings("unchecked") Map<String, GridComponentColumn> stateColumns = (Map<String, GridComponentColumn>) getField(state, "columns");
    assertEquals(2, patternColumns.size());
    assertEquals(2, stateColumns.size());
    assertTrue(patternColumns.keySet().contains("name"));
    assertNotNull(patternColumns.get("name"));
    assertTrue(patternColumns.keySet().contains("invisible"));
    assertNotNull(patternColumns.get("invisible"));
    assertTrue(stateColumns.keySet().contains("name"));
    assertNotNull(stateColumns.get("name"));
    assertTrue(stateColumns.keySet().contains("invisible"));
    assertNotNull(stateColumns.get("invisible"));
}
Also used : PluginUtilsService(com.qcadoo.plugin.internal.PluginUtilsService) ViewGridColumnModuleColumnModel(com.qcadoo.view.internal.module.gridColumn.ViewGridColumnModuleColumnModel) InternalViewDefinitionState(com.qcadoo.view.internal.api.InternalViewDefinitionState) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) ComponentOption(com.qcadoo.view.internal.ComponentOption) GridComponent(com.qcadoo.view.api.components.GridComponent) FieldDefinition(com.qcadoo.model.api.FieldDefinition) GridComponentColumn(com.qcadoo.view.internal.components.grid.GridComponentColumn) DataDefinition(com.qcadoo.model.api.DataDefinition) GridComponentPattern(com.qcadoo.view.internal.components.grid.GridComponentPattern) PluginStateResolver(com.qcadoo.plugin.api.PluginStateResolver) EnumType(com.qcadoo.model.internal.types.EnumType) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ComponentDefinition(com.qcadoo.view.internal.ComponentDefinition) ComponentState(com.qcadoo.view.api.ComponentState) AbstractPatternTest(com.qcadoo.view.internal.patterns.AbstractPatternTest) Test(org.junit.Test)

Example 5 with PluginUtilsService

use of com.qcadoo.plugin.internal.PluginUtilsService in project qcadoo by qcadoo.

the class IntegrationTest method resetPluginUtils.

private void resetPluginUtils() {
    InternalPluginStateResolver pluginStateResolver = new DefaultPluginStateResolver();
    pluginStateResolver.setPluginAccessor(applicationContext.getBean(PluginAccessor.class));
    PluginUtilsService pluginUtil = new PluginUtilsService(pluginStateResolver);
    pluginUtil.init();
}
Also used : PluginAccessor(com.qcadoo.plugin.api.PluginAccessor) PluginUtilsService(com.qcadoo.plugin.internal.PluginUtilsService) DefaultPluginStateResolver(com.qcadoo.plugin.internal.stateresolver.DefaultPluginStateResolver) InternalPluginStateResolver(com.qcadoo.plugin.internal.stateresolver.InternalPluginStateResolver)

Aggregations

PluginUtilsService (com.qcadoo.plugin.internal.PluginUtilsService)11 PluginStateResolver (com.qcadoo.plugin.api.PluginStateResolver)9 Test (org.junit.Test)5 DataDefinition (com.qcadoo.model.api.DataDefinition)4 Before (org.junit.Before)4 ImmutableMap (com.google.common.collect.ImmutableMap)2 Entity (com.qcadoo.model.api.Entity)2 FieldDefinition (com.qcadoo.model.api.FieldDefinition)2 EnumType (com.qcadoo.model.internal.types.EnumType)2 Plugin (com.qcadoo.plugin.api.Plugin)2 MultiTenantUtil (com.qcadoo.tenant.api.MultiTenantUtil)2 DefaultMultiTenantService (com.qcadoo.tenant.internal.DefaultMultiTenantService)2 ComponentState (com.qcadoo.view.api.ComponentState)2 GridComponent (com.qcadoo.view.api.components.GridComponent)2 ComponentDefinition (com.qcadoo.view.internal.ComponentDefinition)2 ComponentOption (com.qcadoo.view.internal.ComponentOption)2 InternalViewDefinition (com.qcadoo.view.internal.api.InternalViewDefinition)2 InternalViewDefinitionState (com.qcadoo.view.internal.api.InternalViewDefinitionState)2 GridComponentColumn (com.qcadoo.view.internal.components.grid.GridComponentColumn)2 GridComponentPattern (com.qcadoo.view.internal.components.grid.GridComponentPattern)2