use of com.qcadoo.view.internal.api.InternalComponentState in project qcadoo by qcadoo.
the class ContainerStateTest method shouldHaveChildren.
@Test
public void shouldHaveChildren() throws Exception {
// given
InternalComponentState component1 = createMockComponent("component1");
InternalComponentState component2 = createMockComponent("component2");
FormComponentPattern pattern = mock(FormComponentPattern.class);
given(pattern.getExpressionNew()).willReturn(null);
given(pattern.getExpressionEdit()).willReturn(null);
setField(pattern, "applicationContext", applicationContext);
FormComponentState container = new FormComponentState(pattern);
container.addChild(component1);
container.addChild(component2);
// when
Map<String, InternalComponentState> children = container.getChildren();
// then
assertNotNull(children);
assertEquals(2, children.size());
}
use of com.qcadoo.view.internal.api.InternalComponentState in project qcadoo by qcadoo.
the class ContainerStateTest method shouldReturnChildByName.
@Test
public void shouldReturnChildByName() throws Exception {
// given
InternalComponentState component = createMockComponent("component");
FormComponentPattern pattern = mock(FormComponentPattern.class);
given(pattern.getExpressionNew()).willReturn(null);
given(pattern.getExpressionEdit()).willReturn(null);
setField(pattern, "applicationContext", applicationContext);
FormComponentState container = new FormComponentState(pattern);
container.addChild(component);
// when
ComponentState child = container.getChild("component");
// then
assertSame(component, child);
}
use of com.qcadoo.view.internal.api.InternalComponentState 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.InternalComponentState in project qcadoo by qcadoo.
the class ViewDefinitionStateTest method shouldPerformEventOnState.
@Test
public void shouldPerformEventOnState() throws Exception {
// given
ViewDefinitionStateImpl viewDefinitionState = new ViewDefinitionStateImpl();
ContainerState state1 = mock(ContainerState.class);
given(state1.getName()).willReturn("name1");
InternalComponentState state2 = mock(InternalComponentState.class);
viewDefinitionState.addChild(state1);
given(state1.getChild("name2")).willReturn(state2);
// when
viewDefinitionState.performEvent("name1.name2", "event", new String[] { "arg1", "arg2" });
// then
Mockito.verify(state2).performEvent(viewDefinitionState, "event", "arg1", "arg2");
}
Aggregations