use of com.qcadoo.model.api.DataDefinition in project qcadoo by qcadoo.
the class InitializationTest method shouldTakeDataDefinitionFromView.
@Test
public void shouldTakeDataDefinitionFromView() throws Exception {
// given
DataDefinition dataDefinition = mock(DataDefinition.class);
InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
given(viewDefinition.getDataDefinition()).willReturn(dataDefinition);
AbstractComponentPattern pattern = new TextInputComponentPattern(getComponentDefinition("test", viewDefinition));
// when
pattern.initialize();
// then
Assert.assertEquals(dataDefinition, ReflectionTestUtils.getField(pattern, "dataDefinition"));
}
use of com.qcadoo.model.api.DataDefinition in project qcadoo by qcadoo.
the class DataDefinitionServiceImpl method get.
@Override
@Monitorable
public DataDefinition get(final String pluginIdentifier, final String modelName) {
DataDefinition dataDefinition = dataDefinitions.get(pluginIdentifier + "." + modelName);
checkNotNull(dataDefinition, "data definition for %s#%s cannot be found", pluginIdentifier, modelName);
return dataDefinition;
}
use of com.qcadoo.model.api.DataDefinition in project qcadoo by qcadoo.
the class ModuleIntegrationTest method shouldNotHaveAdditionalModels.
@Test
public void shouldNotHaveAdditionalModels() throws Exception {
// given
pluginManager.disablePlugin(PLUGIN_MACHINES_NAME);
DataDefinition machineDao = dataDefinitionService.get(PLUGIN_MACHINES_NAME, ENTITY_NAME_MACHINE);
// when & then
try {
machineDao.save(createMachine("asd"));
Assert.fail();
} catch (IllegalStateException ignored) {
// success!
}
}
use of com.qcadoo.model.api.DataDefinition in project qcadoo by qcadoo.
the class ModuleIntegrationTest method shouldHaveAdditionalModelsFieldsAndHooks.
@Test
public void shouldHaveAdditionalModelsFieldsAndHooks() 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"));
}
use of com.qcadoo.model.api.DataDefinition in project qcadoo by qcadoo.
the class AbstractEntityWrapperTest method superInit.
@Before
public final void superInit() {
belongsToFieldDefinition = mock(FieldDefinition.class);
BelongsToType belongsToType = mock(BelongsToType.class);
when(belongsToFieldDefinition.getType()).thenReturn(belongsToType);
belongsToFieldDataDefinition = mock(DataDefinition.class);
when(belongsToFieldDefinition.getDataDefinition()).thenReturn(belongsToFieldDataDefinition);
FieldDefinition stringFieldDefinition = mock(FieldDefinition.class);
when(stringFieldDefinition.isPersistent()).thenReturn(false);
dataDefinition = mock(DataDefinition.class);
FieldDefinition booleanFieldDefinition = mock(FieldDefinition.class);
Map<String, FieldDefinition> fieldsMap = Maps.newHashMap();
fieldsMap.put(BELONGS_TO_FIELD_NAME, belongsToFieldDefinition);
fieldsMap.put(STRING_FIELD_NAME, stringFieldDefinition);
fieldsMap.put(BOOLEAN_FIELD_NAME, booleanFieldDefinition);
for (Map.Entry<String, FieldDefinition> fieldEntry : fieldsMap.entrySet()) {
when(dataDefinition.getField(fieldEntry.getKey())).thenReturn(fieldEntry.getValue());
}
when(dataDefinition.getFields()).thenReturn(fieldsMap);
}
Aggregations