Search in sources :

Example 66 with ComponentState

use of com.qcadoo.view.api.ComponentState 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)

Example 67 with ComponentState

use of com.qcadoo.view.api.ComponentState 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 68 with ComponentState

use of com.qcadoo.view.api.ComponentState in project qcadoo by qcadoo.

the class ViewDefinitionStateTest method shouldReturnNullWhenStateNoExists.

@Test
public void shouldReturnNullWhenStateNoExists() throws Exception {
    // given
    ViewDefinitionState viewDefinitionState = new ViewDefinitionStateImpl();
    // when
    ComponentState actualState = viewDefinitionState.getComponentByReference("xxx");
    // then
    assertNull(actualState);
}
Also used : ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) InternalViewDefinitionState(com.qcadoo.view.internal.api.InternalViewDefinitionState) ViewDefinitionStateImpl(com.qcadoo.view.internal.internal.ViewDefinitionStateImpl) ComponentState(com.qcadoo.view.api.ComponentState) InternalComponentState(com.qcadoo.view.internal.api.InternalComponentState) Test(org.junit.Test) AbstractStateTest(com.qcadoo.view.internal.states.AbstractStateTest)

Aggregations

ComponentState (com.qcadoo.view.api.ComponentState)68 Entity (com.qcadoo.model.api.Entity)33 FormComponent (com.qcadoo.view.api.components.FormComponent)31 GridComponent (com.qcadoo.view.api.components.GridComponent)23 ViewDefinitionState (com.qcadoo.view.api.ViewDefinitionState)21 Autowired (org.springframework.beans.factory.annotation.Autowired)17 FieldComponent (com.qcadoo.view.api.components.FieldComponent)16 Test (org.junit.Test)16 Service (org.springframework.stereotype.Service)16 QcadooViewConstants (com.qcadoo.view.constants.QcadooViewConstants)15 Collectors (java.util.stream.Collectors)14 List (java.util.List)13 DataDefinition (com.qcadoo.model.api.DataDefinition)12 Lists (com.google.common.collect.Lists)11 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)11 Map (java.util.Map)11 BigDecimal (java.math.BigDecimal)10 Maps (com.google.common.collect.Maps)8 LookupComponent (com.qcadoo.view.api.components.LookupComponent)8 Transactional (org.springframework.transaction.annotation.Transactional)8