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"));
}
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"));
}
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"));
}
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"));
}
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"));
}
Aggregations