Search in sources :

Example 6 with PluginUtilsService

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);
}
Also used : PluginUtilsService(com.qcadoo.plugin.internal.PluginUtilsService) PluginStateResolver(com.qcadoo.plugin.api.PluginStateResolver)

Example 7 with PluginUtilsService

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);
}
Also used : Order(org.hibernate.criterion.Order) PluginUtilsService(com.qcadoo.plugin.internal.PluginUtilsService) Criterion(org.hibernate.criterion.Criterion) PluginStateResolver(com.qcadoo.plugin.api.PluginStateResolver) Projection(org.hibernate.criterion.Projection) SearchRestrictions(com.qcadoo.model.api.search.SearchRestrictions) Plugin(com.qcadoo.plugin.api.Plugin) Before(org.junit.Before)

Example 8 with PluginUtilsService

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());
}
Also used : Entity(com.qcadoo.model.api.Entity) PluginUtilsService(com.qcadoo.plugin.internal.PluginUtilsService) PluginStateResolver(com.qcadoo.plugin.api.PluginStateResolver) DataDefinition(com.qcadoo.model.api.DataDefinition) Test(org.junit.Test)

Example 9 with PluginUtilsService

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();
}
Also used : CustomEntityService(com.qcadoo.model.beans.sample.CustomEntityService) ApplicationContext(org.springframework.context.ApplicationContext) PluginUtilsService(com.qcadoo.plugin.internal.PluginUtilsService) Before(org.junit.Before)

Example 10 with PluginUtilsService

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"));
}
Also used : Entity(com.qcadoo.model.api.Entity) PluginUtilsService(com.qcadoo.plugin.internal.PluginUtilsService) EnumeratedType(com.qcadoo.model.api.types.EnumeratedType) PluginStateResolver(com.qcadoo.plugin.api.PluginStateResolver) DataDefinition(com.qcadoo.model.api.DataDefinition) Test(org.junit.Test)

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