use of com.qcadoo.plugin.internal.PluginUtilsService in project qcadoo by qcadoo.
the class ValidatorTest method stubPluginIsEnabled.
private void stubPluginIsEnabled(final boolean isEnabled) {
PluginStateResolver pluginStateResolver = mock(PluginStateResolver.class);
PluginUtilsService pluginUtil = new PluginUtilsService(pluginStateResolver);
pluginUtil.init();
given(pluginStateResolver.isEnabled(PLUGIN_IDENTIFIER)).willReturn(isEnabled);
given(pluginStateResolver.isEnabledOrEnabling(PLUGIN_IDENTIFIER)).willReturn(isEnabled);
}
use of com.qcadoo.plugin.internal.PluginUtilsService in project qcadoo by qcadoo.
the class DataAccessTest method superInit.
@Before
public void superInit() {
pluginStateResolver = Mockito.mock(PluginStateResolver.class);
given(pluginStateResolver.isEnabled(Mockito.anyString())).willReturn(true);
given(pluginStateResolver.isEnabled(Mockito.any(Plugin.class))).willReturn(true);
given(pluginStateResolver.isEnabledOrEnabling(Mockito.anyString())).willReturn(true);
given(pluginStateResolver.isEnabledOrEnabling(Mockito.any(Plugin.class))).willReturn(true);
PluginUtilsService pluginUtilsService = new PluginUtilsService(pluginStateResolver);
pluginUtilsService.init();
validationService = new ValidationServiceImpl();
entityService = new EntityServiceImpl();
ReflectionTestUtils.setField(entityService, "hibernateService", hibernateService);
priorityService = new PriorityServiceImpl();
ReflectionTestUtils.setField(priorityService, "entityService", entityService);
ReflectionTestUtils.setField(priorityService, "hibernateService", hibernateService);
dataAccessService = new DataAccessServiceImpl();
ReflectionTestUtils.setField(dataAccessService, "entityService", entityService);
ReflectionTestUtils.setField(dataAccessService, "priorityService", priorityService);
ReflectionTestUtils.setField(dataAccessService, "validationService", validationService);
ReflectionTestUtils.setField(dataAccessService, "hibernateService", hibernateService);
AnnotationTransactionAspect.aspectOf();
SearchRestrictions restrictions = new SearchRestrictions();
ReflectionTestUtils.setField(restrictions, "dataAccessService", dataAccessService);
buildParentDataDefinition();
buildTreeDataDefinition();
buildDataDefinition();
given(hibernateService.getCurrentSession()).willReturn(session);
given(session.createCriteria(any(Class.class))).willReturn(criteria);
given(criteria.add(any(Criterion.class))).willReturn(criteria);
given(criteria.setProjection(any(Projection.class))).willReturn(criteria);
given(criteria.setFirstResult(anyInt())).willReturn(criteria);
given(criteria.setMaxResults(anyInt())).willReturn(criteria);
given(criteria.addOrder(any(Order.class))).willReturn(criteria);
}
use of com.qcadoo.plugin.internal.PluginUtilsService in project qcadoo by qcadoo.
the class FieldModuleIntegrationTest method shouldNotCallAdditinanalFieldValidatorsIfPluginIsDisabledForCurrentUser.
@Test
public void shouldNotCallAdditinanalFieldValidatorsIfPluginIsDisabledForCurrentUser() throws Exception {
// given
DataDefinition machineDao = dataDefinitionService.get(PLUGIN_MACHINES_NAME, ENTITY_NAME_MACHINE);
machineDao.save(createMachine("asd"));
pluginManager.enablePlugin(PLUGIN_MACHINES_NAME);
// This should be considered as an anti-pattern. Replacing static fields with mocks in an integration test suite weren't
// my smartest idea ever..
PluginStateResolver pluginStateResolver = mock(PluginStateResolver.class);
PluginUtilsService pluginUtil = new PluginUtilsService(pluginStateResolver);
pluginUtil.init();
given(pluginStateResolver.isEnabled(PLUGIN_MACHINES_NAME)).willReturn(false);
DataDefinition productDao = dataDefinitionService.get(PLUGIN_PRODUCTS_NAME, ENTITY_NAME_PRODUCT);
DataDefinition componentDao = dataDefinitionService.get(PLUGIN_PRODUCTS_NAME, ENTITY_NAME_COMPONENT);
Entity product = createProduct("asd", "asd");
product = productDao.save(product);
Entity component = createComponent("name", product, null);
component.setField("machineDescription", "as");
// when
component = componentDao.save(component);
// then
Assert.assertTrue(component.isValid());
}
use of com.qcadoo.plugin.internal.PluginUtilsService in project qcadoo by qcadoo.
the class EntityHookDefinitionImplTest method init.
@Before
public final void init() throws HookInitializationException {
MockitoAnnotations.initMocks(this);
ApplicationContext applicationContext = Mockito.mock(ApplicationContext.class);
BDDMockito.given(applicationContext.getBean(CustomEntityService.class)).willReturn(new CustomEntityService());
entityHookDefinitionImpl = new EntityHookDefinitionImpl("com.qcadoo.model.beans.sample.CustomEntityService", "onSave", SOME_PLUGIN_IDENTIFIER, applicationContext);
PluginUtilsService pluginUtil = new PluginUtilsService(pluginStateResolver);
pluginUtil.init();
}
use of com.qcadoo.plugin.internal.PluginUtilsService in project qcadoo by qcadoo.
the class ModuleIntegrationTest method shouldNotCallAdditionalHooksIfPluginIsDisabledOnlyForCurrentTenant.
@Test
public void shouldNotCallAdditionalHooksIfPluginIsDisabledOnlyForCurrentTenant() throws Exception {
// given
pluginManager.enablePlugin(PLUGIN_MACHINES_NAME);
DataDefinition machineDao = dataDefinitionService.get(PLUGIN_MACHINES_NAME, ENTITY_NAME_MACHINE);
machineDao.save(createMachine("asd"));
PluginStateResolver pluginStateResolver = mock(PluginStateResolver.class);
PluginUtilsService pluginUtil = new PluginUtilsService(pluginStateResolver);
pluginUtil.init();
given(pluginStateResolver.isEnabled(PLUGIN_MACHINES_NAME)).willReturn(false);
given(pluginStateResolver.isEnabledOrEnabling(PLUGIN_MACHINES_NAME)).willReturn(false);
DataDefinition productDao = dataDefinitionService.get(PLUGIN_PRODUCTS_NAME, ENTITY_NAME_PRODUCT);
DataDefinition componentDao = dataDefinitionService.get(PLUGIN_PRODUCTS_NAME, ENTITY_NAME_COMPONENT);
Entity product = createProduct("asd", "asd");
product.setField("changeableName", "xxx");
product = productDao.save(product);
Entity component = createComponent("name", product, null);
component.setField("machineName", "test");
// when
component = componentDao.save(component);
// then
assertEquals("xxx", product.getField("changeableName"));
assertNotNull(component.getField("machineName"));
assertNull(component.getField("machine"));
Map<String, Object> componentResult = jdbcTemplate.queryForMap("select * from " + TABLE_NAME_COMPONENT);
assertNotNull(componentResult);
assertNotNull(componentResult.get("machineName"));
Map<String, Object> productResult = jdbcTemplate.queryForMap("select * from " + TABLE_NAME_PRODUCT);
assertNotNull(productResult);
assertEquals("xxx", productResult.get("changeableName"));
assertThat(((EnumeratedType) productDao.getField("enum").getType()).activeValues(Locale.ENGLISH).keySet(), JUnitMatchers.hasItems("one", "two"));
}
Aggregations