Search in sources :

Example 26 with BelongsToType

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

the class InitializationTest method shouldInitializeAllComponents.

@Test
public void shouldInitializeAllComponents() throws Exception {
    // given
    DataDefinition dataDefinition = mock(DataDefinition.class);
    DataDefinition hasManyDataDefinition = mock(DataDefinition.class);
    DataDefinition belongsToDataDefinition = mock(DataDefinition.class);
    FieldDefinition fieldDefinition = mock(FieldDefinition.class);
    FieldDefinition hasManyFieldDefinition = mock(FieldDefinition.class);
    FieldDefinition belongsToFieldDefinition = mock(FieldDefinition.class);
    FieldType fieldType = mock(FieldType.class);
    BelongsToType belongsToType = mock(BelongsToType.class);
    HasManyType hasManyType = mock(HasManyType.class);
    given(dataDefinition.getField("hasMany")).willReturn(hasManyFieldDefinition);
    given(belongsToDataDefinition.getField("hasMany")).willReturn(hasManyFieldDefinition);
    given(dataDefinition.getField("belongsTo")).willReturn(belongsToFieldDefinition);
    given(dataDefinition.getField("field")).willReturn(fieldDefinition);
    given(fieldDefinition.getType()).willReturn(fieldType);
    given(hasManyFieldDefinition.getType()).willReturn(hasManyType);
    given(belongsToFieldDefinition.getType()).willReturn(belongsToType);
    given(hasManyType.getDataDefinition()).willReturn(hasManyDataDefinition);
    given(belongsToType.getDataDefinition()).willReturn(belongsToDataDefinition);
    InternalViewDefinition viewDefinition = new ViewDefinitionImpl("view", "plugin", dataDefinition, true, null);
    AbstractContainerPattern parent = new FormComponentPattern(getComponentDefinition("parent", viewDefinition));
    AbstractContainerPattern form = new FormComponentPattern(getComponentDefinition(QcadooViewConstants.L_FORM, null, null, parent, viewDefinition));
    AbstractComponentPattern input = new TextInputComponentPattern(getComponentDefinition("input", "field", null, form, viewDefinition));
    AbstractComponentPattern select = new TextInputComponentPattern(getComponentDefinition("select", "belongsTo", null, form, viewDefinition));
    AbstractComponentPattern subselect = new TextInputComponentPattern(getComponentDefinition("subselect", "#{parent.form}.hasMany", "#{parent.form.select}.hasMany", form, viewDefinition));
    AbstractComponentPattern grid = new TextInputComponentPattern(getComponentDefinition(QcadooViewConstants.L_GRID, null, "#{parent.form}.hasMany", parent, viewDefinition));
    parent.addChild(form);
    parent.addChild(grid);
    form.addChild(input);
    form.addChild(select);
    form.addChild(subselect);
    viewDefinition.addComponentPattern(parent);
    // when
    viewDefinition.initialize();
    // then
    assertEquals(dataDefinition, getField(parent, "dataDefinition"));
    assertEquals(dataDefinition, getField(form, "dataDefinition"));
    assertEquals(dataDefinition, getField(input, "dataDefinition"));
    assertEquals(belongsToDataDefinition, getField(select, "dataDefinition"));
    assertEquals(hasManyDataDefinition, getField(subselect, "dataDefinition"));
    assertEquals(hasManyDataDefinition, getField(grid, "dataDefinition"));
    assertNull(getField(parent, "scopeFieldDefinition"));
    assertNull(getField(form, "scopeFieldDefinition"));
    assertNull(getField(input, "scopeFieldDefinition"));
    assertNull(getField(select, "scopeFieldDefinition"));
    assertEquals(hasManyFieldDefinition, getField(subselect, "scopeFieldDefinition"));
    assertEquals(hasManyFieldDefinition, getField(grid, "scopeFieldDefinition"));
    assertNull(getField(parent, "fieldDefinition"));
    assertNull(getField(form, "fieldDefinition"));
    assertEquals(fieldDefinition, getField(input, "fieldDefinition"));
    assertEquals(belongsToFieldDefinition, getField(select, "fieldDefinition"));
    assertEquals(hasManyFieldDefinition, getField(subselect, "fieldDefinition"));
    assertNull(getField(grid, "fieldDefinition"));
}
Also used : HasManyType(com.qcadoo.model.api.types.HasManyType) ViewDefinitionImpl(com.qcadoo.view.internal.internal.ViewDefinitionImpl) BelongsToType(com.qcadoo.model.api.types.BelongsToType) FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) FieldDefinition(com.qcadoo.model.api.FieldDefinition) DataDefinition(com.qcadoo.model.api.DataDefinition) FieldType(com.qcadoo.model.api.types.FieldType) TextInputComponentPattern(com.qcadoo.view.internal.components.TextInputComponentPattern) Test(org.junit.Test)

Aggregations

BelongsToType (com.qcadoo.model.api.types.BelongsToType)26 FieldDefinition (com.qcadoo.model.api.FieldDefinition)19 Test (org.junit.Test)14 DataDefinition (com.qcadoo.model.api.DataDefinition)13 Entity (com.qcadoo.model.api.Entity)12 InternalDataDefinition (com.qcadoo.model.internal.api.InternalDataDefinition)10 HasManyType (com.qcadoo.model.api.types.HasManyType)5 InternalViewDefinition (com.qcadoo.view.internal.api.InternalViewDefinition)5 TextInputComponentPattern (com.qcadoo.view.internal.components.TextInputComponentPattern)5 Before (org.junit.Before)4 EntityList (com.qcadoo.model.api.EntityList)2 SearchCriteriaBuilder (com.qcadoo.model.api.search.SearchCriteriaBuilder)2 FieldType (com.qcadoo.model.api.types.FieldType)2 ComponentDefinition (com.qcadoo.view.internal.ComponentDefinition)2 ComponentOption (com.qcadoo.view.internal.ComponentOption)2 GridComponentPattern (com.qcadoo.view.internal.components.grid.GridComponentPattern)2 WindowComponentPattern (com.qcadoo.view.internal.components.window.WindowComponentPattern)2 AbstractComponentPattern (com.qcadoo.view.internal.patterns.AbstractComponentPattern)2 AbstractPatternTest (com.qcadoo.view.internal.patterns.AbstractPatternTest)2 Map (java.util.Map)2