Search in sources :

Example 6 with EnumeratedType

use of com.qcadoo.model.api.types.EnumeratedType 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)

Example 7 with EnumeratedType

use of com.qcadoo.model.api.types.EnumeratedType in project qcadoo by qcadoo.

the class ModuleIntegrationTest method shouldNotHaveAdditionalFieldsAndHooks.

@Test
public void shouldNotHaveAdditionalFieldsAndHooks() throws Exception {
    // given
    DataDefinition machineDao = dataDefinitionService.get(PLUGIN_MACHINES_NAME, ENTITY_NAME_MACHINE);
    machineDao.save(createMachine("asd"));
    pluginManager.disablePlugin(PLUGIN_MACHINES_NAME);
    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"));
    assertNull(component.getField("machineName"));
    assertNull(component.getField("machine"));
    Map<String, Object> componentResult = jdbcTemplate.queryForMap("select * from " + TABLE_NAME_COMPONENT);
    assertNotNull(componentResult);
    assertNull(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) EnumeratedType(com.qcadoo.model.api.types.EnumeratedType) DataDefinition(com.qcadoo.model.api.DataDefinition) Test(org.junit.Test)

Example 8 with EnumeratedType

use of com.qcadoo.model.api.types.EnumeratedType in project qcadoo by qcadoo.

the class ModuleIntegrationTest method shouldCallAdditionalHooksIfPluginIsEnabledForCurrentTenant.

@Test
public void shouldCallAdditionalHooksIfPluginIsEnabledForCurrentTenant() throws Exception {
    // given
    DataDefinition productDao = dataDefinitionService.get(PLUGIN_PRODUCTS_NAME, ENTITY_NAME_PRODUCT);
    DataDefinition machineDao = dataDefinitionService.get(PLUGIN_MACHINES_NAME, ENTITY_NAME_MACHINE);
    DataDefinition componentDao = dataDefinitionService.get(PLUGIN_PRODUCTS_NAME, ENTITY_NAME_COMPONENT);
    Entity machine = machineDao.save(createMachine("asd"));
    Entity product = createProduct("asd", "asd");
    product.setField("changeableName", "xxx");
    product = productDao.save(product);
    Entity component = createComponent("name", product, machine);
    component.setField("machineName", "test");
    // when
    component = componentDao.save(component);
    // then
    assertEquals("test", component.getField("machineName"));
    assertEquals("XXX", product.getField("changeableName"));
    assertNotNull(component.getField("machine"));
    Map<String, Object> componentResult = jdbcTemplate.queryForMap("select * from " + TABLE_NAME_COMPONENT);
    assertNotNull(componentResult);
    assertEquals("test", 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", "three"));
}
Also used : Entity(com.qcadoo.model.api.Entity) EnumeratedType(com.qcadoo.model.api.types.EnumeratedType) DataDefinition(com.qcadoo.model.api.DataDefinition) Test(org.junit.Test)

Aggregations

EnumeratedType (com.qcadoo.model.api.types.EnumeratedType)8 Test (org.junit.Test)6 DataDefinition (com.qcadoo.model.api.DataDefinition)4 Entity (com.qcadoo.model.api.Entity)4 FieldDefinition (com.qcadoo.model.api.FieldDefinition)2 DataAccessTest (com.qcadoo.model.internal.DataAccessTest)2 ValueAndError (com.qcadoo.model.internal.api.ValueAndError)2 JSONObject (org.json.JSONObject)2 TranslationService (com.qcadoo.localization.api.TranslationService)1 DictionaryService (com.qcadoo.model.api.DictionaryService)1 DictionaryType (com.qcadoo.model.internal.types.DictionaryType)1 EnumType (com.qcadoo.model.internal.types.EnumType)1 PluginStateResolver (com.qcadoo.plugin.api.PluginStateResolver)1 PluginUtilsService (com.qcadoo.plugin.internal.PluginUtilsService)1 Map (java.util.Map)1 JSONArray (org.json.JSONArray)1