Search in sources :

Example 41 with InternalViewDefinition

use of com.qcadoo.view.internal.api.InternalViewDefinition in project qcadoo by qcadoo.

the class FieldAndScopeListenerPatternTest method shouldUpdateStateFieldListeners.

@Test
public void shouldUpdateStateFieldListeners() throws Exception {
    // given
    InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
    AbstractContainerPattern parent = new ContainerPatternMock(getComponentDefinition("f1", viewDefinition));
    ComponentPatternMock child1 = new ComponentPatternMock(getComponentDefinition("t1", "field1", null, parent, viewDefinition));
    ComponentPatternMock child2 = new ComponentPatternMock(getComponentDefinition("t2", "field2", null, parent, viewDefinition));
    parent.addChild(child1);
    parent.addChild(child2);
    parent.initialize();
    child1.initialize();
    child2.initialize();
    ComponentStateMock f1State = new ComponentStateMock();
    ComponentState t1State = Mockito.mock(ComponentState.class, withSettings().extraInterfaces(FieldEntityIdChangeListener.class));
    ComponentState t2State = Mockito.mock(ComponentState.class, withSettings().extraInterfaces(FieldEntityIdChangeListener.class));
    ViewDefinitionState viewDefinitions = Mockito.mock(ViewDefinitionState.class);
    BDDMockito.given(viewDefinitions.getComponentByReference("f1")).willReturn(f1State);
    BDDMockito.given(viewDefinitions.getComponentByReference("f1.t1")).willReturn(t1State);
    BDDMockito.given(viewDefinitions.getComponentByReference("f1.t2")).willReturn(t2State);
    // when
    parent.updateComponentStateListeners(viewDefinitions);
    // then
    assertEquals(t1State, f1State.getPublicFieldEntityIdChangeListeners().get("field1"));
    assertEquals(t2State, f1State.getPublicFieldEntityIdChangeListeners().get("field2"));
}
Also used : InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) FieldEntityIdChangeListener(com.qcadoo.view.internal.FieldEntityIdChangeListener) ComponentStateMock(com.qcadoo.view.internal.states.ComponentStateMock) ComponentState(com.qcadoo.view.api.ComponentState) Test(org.junit.Test)

Example 42 with InternalViewDefinition

use of com.qcadoo.view.internal.api.InternalViewDefinition in project qcadoo by qcadoo.

the class InitializationTest method shouldSetFieldDefinitionWithoutFieldComponent.

@Test
public void shouldSetFieldDefinitionWithoutFieldComponent() throws Exception {
    // given
    FieldDefinition fieldDefinition = mock(FieldDefinition.class);
    DataDefinition dataDefinition = mock(DataDefinition.class);
    given(dataDefinition.getField("field")).willReturn(fieldDefinition);
    InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
    AbstractContainerPattern parent = new WindowComponentPattern(getComponentDefinition("parent", viewDefinition));
    setField(parent, "dataDefinition", dataDefinition);
    setField(parent, "initialized", true);
    AbstractComponentPattern pattern = new TextInputComponentPattern(getComponentDefinition("test", "field", null, parent, viewDefinition));
    // when
    pattern.initialize();
    // then
    Assert.assertEquals(dataDefinition, getField(pattern, "dataDefinition"));
    Assert.assertEquals(fieldDefinition, getField(pattern, "fieldDefinition"));
}
Also used : WindowComponentPattern(com.qcadoo.view.internal.components.window.WindowComponentPattern) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) FieldDefinition(com.qcadoo.model.api.FieldDefinition) DataDefinition(com.qcadoo.model.api.DataDefinition) TextInputComponentPattern(com.qcadoo.view.internal.components.TextInputComponentPattern) Test(org.junit.Test)

Example 43 with InternalViewDefinition

use of com.qcadoo.view.internal.api.InternalViewDefinition in project qcadoo by qcadoo.

the class InitializationTest method shouldGetDataDefinitionFromHasManyTypeFieldDefinition.

@Test
public void shouldGetDataDefinitionFromHasManyTypeFieldDefinition() throws Exception {
    // given
    HasManyType fieldType = mock(HasManyType.class);
    FieldDefinition fieldDefinition = mock(FieldDefinition.class);
    given(fieldDefinition.getType()).willReturn(fieldType);
    DataDefinition dataDefinition = mock(DataDefinition.class);
    given(dataDefinition.getField("field")).willReturn(fieldDefinition);
    DataDefinition belongsToDefinition = mock(DataDefinition.class);
    given(fieldType.getDataDefinition()).willReturn(belongsToDefinition);
    InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
    AbstractContainerPattern parent = new WindowComponentPattern(getComponentDefinition("parent", viewDefinition));
    setField(parent, "dataDefinition", dataDefinition);
    setField(parent, "initialized", true);
    AbstractComponentPattern pattern = new TextInputComponentPattern(getComponentDefinition("test", "field", null, parent, viewDefinition));
    // when
    pattern.initialize();
    // then
    Assert.assertEquals(belongsToDefinition, getField(pattern, "dataDefinition"));
    Assert.assertEquals(fieldDefinition, getField(pattern, "fieldDefinition"));
}
Also used : HasManyType(com.qcadoo.model.api.types.HasManyType) WindowComponentPattern(com.qcadoo.view.internal.components.window.WindowComponentPattern) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) FieldDefinition(com.qcadoo.model.api.FieldDefinition) DataDefinition(com.qcadoo.model.api.DataDefinition) TextInputComponentPattern(com.qcadoo.view.internal.components.TextInputComponentPattern) Test(org.junit.Test)

Example 44 with InternalViewDefinition

use of com.qcadoo.view.internal.api.InternalViewDefinition in project qcadoo by qcadoo.

the class InitializationTest method shouldGetDataDefinitionFromBelongsToTypeScopeFieldDefinition.

@Test
public void shouldGetDataDefinitionFromBelongsToTypeScopeFieldDefinition() throws Exception {
    // given
    BelongsToType fieldType = mock(BelongsToType.class);
    FieldDefinition fieldDefinition = mock(FieldDefinition.class);
    given(fieldDefinition.getType()).willReturn(fieldType);
    DataDefinition dataDefinition = mock(DataDefinition.class);
    given(dataDefinition.getField("field")).willReturn(fieldDefinition);
    DataDefinition belongsToDefinition = mock(DataDefinition.class);
    given(fieldType.getDataDefinition()).willReturn(belongsToDefinition);
    InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
    AbstractContainerPattern parent = new WindowComponentPattern(getComponentDefinition("parent", viewDefinition));
    setField(parent, "dataDefinition", dataDefinition);
    setField(parent, "initialized", true);
    AbstractComponentPattern pattern = new TextInputComponentPattern(getComponentDefinition("test", null, "field", parent, viewDefinition));
    // when
    pattern.initialize();
    // then
    Assert.assertEquals(belongsToDefinition, getField(pattern, "dataDefinition"));
    Assert.assertEquals(fieldDefinition, getField(pattern, "scopeFieldDefinition"));
}
Also used : BelongsToType(com.qcadoo.model.api.types.BelongsToType) WindowComponentPattern(com.qcadoo.view.internal.components.window.WindowComponentPattern) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) FieldDefinition(com.qcadoo.model.api.FieldDefinition) DataDefinition(com.qcadoo.model.api.DataDefinition) TextInputComponentPattern(com.qcadoo.view.internal.components.TextInputComponentPattern) Test(org.junit.Test)

Example 45 with InternalViewDefinition

use of com.qcadoo.view.internal.api.InternalViewDefinition 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

InternalViewDefinition (com.qcadoo.view.internal.api.InternalViewDefinition)49 Test (org.junit.Test)40 DataDefinition (com.qcadoo.model.api.DataDefinition)25 TextInputComponentPattern (com.qcadoo.view.internal.components.TextInputComponentPattern)21 WindowComponentPattern (com.qcadoo.view.internal.components.window.WindowComponentPattern)15 FieldDefinition (com.qcadoo.model.api.FieldDefinition)14 AbstractPatternTest (com.qcadoo.view.internal.patterns.AbstractPatternTest)14 ComponentPattern (com.qcadoo.view.internal.api.ComponentPattern)13 ComponentDefinition (com.qcadoo.view.internal.ComponentDefinition)11 JSONObject (org.json.JSONObject)10 FormComponentPattern (com.qcadoo.view.internal.components.form.FormComponentPattern)9 GridComponentPattern (com.qcadoo.view.internal.components.grid.GridComponentPattern)9 ComponentOption (com.qcadoo.view.internal.ComponentOption)8 ComponentState (com.qcadoo.view.api.ComponentState)7 ViewDefinitionImpl (com.qcadoo.view.internal.internal.ViewDefinitionImpl)7 InternalViewDefinitionState (com.qcadoo.view.internal.api.InternalViewDefinitionState)6 BelongsToType (com.qcadoo.model.api.types.BelongsToType)5 HasManyType (com.qcadoo.model.api.types.HasManyType)5 ModuleException (com.qcadoo.plugin.api.ModuleException)4 EnumType (com.qcadoo.model.internal.types.EnumType)3