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();
}
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);
}
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);
}
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"));
}
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();
}
Aggregations