Search in sources :

Example 36 with DataDefinition

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"));
}
Also used : InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) DataDefinition(com.qcadoo.model.api.DataDefinition) TextInputComponentPattern(com.qcadoo.view.internal.components.TextInputComponentPattern) Test(org.junit.Test)

Example 37 with 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;
}
Also used : DataDefinition(com.qcadoo.model.api.DataDefinition) Monitorable(com.qcadoo.model.api.aop.Monitorable)

Example 38 with 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!
    }
}
Also used : DataDefinition(com.qcadoo.model.api.DataDefinition) Test(org.junit.Test)

Example 39 with DataDefinition

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"));
}
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 40 with DataDefinition

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);
}
Also used : BelongsToType(com.qcadoo.model.api.types.BelongsToType) FieldDefinition(com.qcadoo.model.api.FieldDefinition) DataDefinition(com.qcadoo.model.api.DataDefinition) Map(java.util.Map) Before(org.junit.Before)

Aggregations

DataDefinition (com.qcadoo.model.api.DataDefinition)415 Entity (com.qcadoo.model.api.Entity)285 Test (org.junit.Test)165 BigDecimal (java.math.BigDecimal)53 FieldDefinition (com.qcadoo.model.api.FieldDefinition)48 List (java.util.List)32 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)32 Service (org.springframework.stereotype.Service)31 Autowired (org.springframework.beans.factory.annotation.Autowired)27 Date (java.util.Date)26 Map (java.util.Map)26 Collectors (java.util.stream.Collectors)26 FormComponent (com.qcadoo.view.api.components.FormComponent)25 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)23 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)22 IOException (java.io.IOException)21 Objects (java.util.Objects)21 GridComponent (com.qcadoo.view.api.components.GridComponent)20 InternalViewDefinition (com.qcadoo.view.internal.api.InternalViewDefinition)20 Lists (com.google.common.collect.Lists)16