Search in sources :

Example 36 with InternalViewDefinition

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

the class ContainerPatternTest method shouldCallCreateComponentStateOnChildren.

@Test
public void shouldCallCreateComponentStateOnChildren() throws Exception {
    // given
    InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
    InternalViewDefinitionState viewDefinitionState = mock(InternalViewDefinitionState.class);
    AbstractContainerState state = new EmptyContainerState();
    InternalComponentState state1 = mock(InternalComponentState.class);
    given(state1.getName()).willReturn("name1");
    InternalComponentState state2 = mock(InternalComponentState.class);
    given(state2.getName()).willReturn("name2");
    ComponentPattern pattern1 = mock(ComponentPattern.class);
    given(pattern1.getName()).willReturn("name1");
    given(pattern1.createComponentState(viewDefinitionState)).willReturn(state1);
    ComponentPattern pattern2 = mock(ComponentPattern.class);
    given(pattern2.getName()).willReturn("name2");
    given(pattern2.createComponentState(viewDefinitionState)).willReturn(state2);
    ContainerPatternMock parent = new ContainerPatternMock(getComponentDefinition("name", viewDefinition), state);
    parent.addChild(pattern1);
    parent.addChild(pattern2);
    // when
    ComponentState actualState = parent.createComponentState(viewDefinitionState);
    // then
    assertEquals(state, actualState);
    verify(pattern1).createComponentState(viewDefinitionState);
    verify(pattern2).createComponentState(viewDefinitionState);
    verify(viewDefinitionState).registerComponent("name", actualState);
    assertEquals(state1, state.getChild("name1"));
    assertEquals(state2, state.getChild("name2"));
}
Also used : AbstractContainerState(com.qcadoo.view.internal.states.AbstractContainerState) InternalViewDefinitionState(com.qcadoo.view.internal.api.InternalViewDefinitionState) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) EmptyContainerState(com.qcadoo.view.internal.components.EmptyContainerState) FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) ComponentPattern(com.qcadoo.view.internal.api.ComponentPattern) TextInputComponentPattern(com.qcadoo.view.internal.components.TextInputComponentPattern) InternalComponentState(com.qcadoo.view.internal.api.InternalComponentState) ComponentState(com.qcadoo.view.api.ComponentState) InternalComponentState(com.qcadoo.view.internal.api.InternalComponentState) Test(org.junit.Test)

Example 37 with InternalViewDefinition

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

the class FieldAndScopeListenerPatternTest method shouldHaveFieldListeners.

@Test
public void shouldHaveFieldListeners() throws Exception {
    // given
    InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
    AbstractContainerPattern parent = new ContainerPatternMock(getComponentDefinition("f1", viewDefinition));
    ComponentPatternMock child1 = new ComponentPatternMock(getComponentDefinition("t1", "t1", null, parent, viewDefinition));
    ComponentPatternMock child2 = new ComponentPatternMock(getComponentDefinition("t2", "t2", null, parent, viewDefinition));
    parent.addChild(child1);
    parent.addChild(child2);
    parent.initialize();
    child1.initialize();
    child2.initialize();
    // when
    Map<String, ComponentPattern> listeners = parent.getFieldEntityIdChangeListeners();
    // then
    Assert.assertEquals(2, listeners.size());
    Assert.assertEquals(child1, listeners.get("t1"));
    Assert.assertEquals(child2, listeners.get("t2"));
}
Also used : InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) ComponentPattern(com.qcadoo.view.internal.api.ComponentPattern) TextInputComponentPattern(com.qcadoo.view.internal.components.TextInputComponentPattern) Test(org.junit.Test)

Example 38 with InternalViewDefinition

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

the class FieldAndScopeListenerPatternTest method shouldHaveScopeListeners.

@Test
public void shouldHaveScopeListeners() throws Exception {
    // given
    InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
    AbstractContainerPattern parent = new ContainerPatternMock(getComponentDefinition("f1", viewDefinition));
    ComponentPatternMock child1 = new ComponentPatternMock(getComponentDefinition("t1", null, "t1", parent, viewDefinition));
    ComponentPatternMock child2 = new ComponentPatternMock(getComponentDefinition("t2", null, "t2", parent, viewDefinition));
    parent.addChild(child1);
    parent.addChild(child2);
    parent.initialize();
    child1.initialize();
    child2.initialize();
    // when
    Map<String, ComponentPattern> listeners = parent.getScopeEntityIdChangeListeners();
    // then
    Assert.assertEquals(2, listeners.size());
    Assert.assertEquals(child1, listeners.get("t1"));
    Assert.assertEquals(child2, listeners.get("t2"));
}
Also used : InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) ComponentPattern(com.qcadoo.view.internal.api.ComponentPattern) TextInputComponentPattern(com.qcadoo.view.internal.components.TextInputComponentPattern) Test(org.junit.Test)

Example 39 with InternalViewDefinition

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

the class FieldAndScopeListenerPatternTest method shouldAddItselfToRelationFieldComponentWhenComplexFieldPath.

@Test
public void shouldAddItselfToRelationFieldComponentWhenComplexFieldPath() throws Exception {
    // given
    InternalViewDefinition viewDefinition = Mockito.mock(InternalViewDefinition.class);
    AbstractContainerPattern parent = Mockito.mock(AbstractContainerPattern.class);
    TextInputComponentPattern pattern = new TextInputComponentPattern(getComponentDefinition("testName", "#{testComponent}.testField", null, parent, viewDefinition));
    ComponentPatternMock testComponent = new ComponentPatternMock(getComponentDefinition("name", viewDefinition));
    given(viewDefinition.getComponentByReference("testComponent")).willReturn(testComponent);
    // when
    pattern.initialize();
    // then
    Assert.assertEquals(pattern, testComponent.getFieldEntityIdChangeListeners().get("testField"));
}
Also used : InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) TextInputComponentPattern(com.qcadoo.view.internal.components.TextInputComponentPattern) Test(org.junit.Test)

Example 40 with InternalViewDefinition

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

the class FieldAndScopeListenerPatternTest method shouldUpdateStateScopeListeners.

@Test
public void shouldUpdateStateScopeListeners() throws Exception {
    // given
    InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
    AbstractContainerPattern parent = new ContainerPatternMock(getComponentDefinition("f1", viewDefinition));
    ComponentPatternMock child1 = new ComponentPatternMock(getComponentDefinition("t1", null, "field1", parent, viewDefinition));
    ComponentPatternMock child2 = new ComponentPatternMock(getComponentDefinition("t2", null, "field2", 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(ScopeEntityIdChangeListener.class));
    ComponentState t2State = Mockito.mock(ComponentState.class, withSettings().extraInterfaces(ScopeEntityIdChangeListener.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.getPublicScopeFieldEntityIdChangeListeners().get("field1"));
    assertEquals(t2State, f1State.getPublicScopeFieldEntityIdChangeListeners().get("field2"));
}
Also used : InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) ScopeEntityIdChangeListener(com.qcadoo.view.internal.ScopeEntityIdChangeListener) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) ComponentStateMock(com.qcadoo.view.internal.states.ComponentStateMock) ComponentState(com.qcadoo.view.api.ComponentState) 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