Search in sources :

Example 46 with ViewDefinitionState

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

the class DefaultEventHandlerTest method shouldCallMultipleEventMethods.

@Test
public void shouldCallMultipleEventMethods() throws Exception {
    // given
    ViewDefinitionState viewDefinitionState = mock(ViewDefinitionState.class);
    FormComponentPattern pattern = mock(FormComponentPattern.class);
    given(pattern.getExpressionNew()).willReturn(null);
    given(pattern.getExpressionEdit()).willReturn(null);
    setField(pattern, "applicationContext", applicationContext);
    FormComponentState component = new FormComponentState(pattern);
    component.setFieldValue(13L);
    ViewEventListenerHook eventListener1 = mock(ViewEventListenerHook.class);
    given(eventListener1.getEventName()).willReturn("clear");
    component.registerCustomEvent(eventListener1);
    ViewEventListenerHook eventListener2 = mock(ViewEventListenerHook.class);
    given(eventListener2.getEventName()).willReturn("clear");
    component.registerCustomEvent(eventListener2);
    // when
    component.performEvent(viewDefinitionState, "clear");
    // then
    assertNull("value is " + component.getFieldValue(), component.getFieldValue());
    Mockito.verify(eventListener1).invokeEvent(viewDefinitionState, component, new String[0]);
    Mockito.verify(eventListener2).invokeEvent(viewDefinitionState, component, new String[0]);
}
Also used : ViewEventListenerHook(com.qcadoo.view.internal.hooks.ViewEventListenerHook) FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) FormComponentState(com.qcadoo.view.internal.components.form.FormComponentState) Test(org.junit.Test)

Example 47 with ViewDefinitionState

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

the class ContainerPatternTest method shouldCallStateOnChildren.

@Test
public void shouldCallStateOnChildren() throws Exception {
    // given
    ViewDefinitionState viewDefinitionState = Mockito.mock(ViewDefinitionState.class);
    AbstractComponentPattern child = Mockito.mock(AbstractComponentPattern.class);
    AbstractContainerPattern parent = new FormComponentPattern(getComponentDefinition("test", null));
    parent.addChild(child);
    // when
    parent.updateComponentStateListeners(viewDefinitionState);
    // then
    Mockito.verify(child).updateComponentStateListeners(viewDefinitionState);
}
Also used : FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) InternalViewDefinitionState(com.qcadoo.view.internal.api.InternalViewDefinitionState) Test(org.junit.Test)

Example 48 with ViewDefinitionState

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

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

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

ViewDefinitionState (com.qcadoo.view.api.ViewDefinitionState)50 Autowired (org.springframework.beans.factory.annotation.Autowired)35 QcadooViewConstants (com.qcadoo.view.constants.QcadooViewConstants)32 Service (org.springframework.stereotype.Service)31 ComponentState (com.qcadoo.view.api.ComponentState)29 Collectors (java.util.stream.Collectors)28 Entity (com.qcadoo.model.api.Entity)27 Lists (com.google.common.collect.Lists)25 GridComponent (com.qcadoo.view.api.components.GridComponent)25 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)24 FormComponent (com.qcadoo.view.api.components.FormComponent)23 BigDecimal (java.math.BigDecimal)21 List (java.util.List)21 Maps (com.google.common.collect.Maps)18 Map (java.util.Map)18 DataDefinition (com.qcadoo.model.api.DataDefinition)16 ProductFields (com.qcadoo.mes.basic.constants.ProductFields)15 SearchRestrictions (com.qcadoo.model.api.search.SearchRestrictions)13 FieldComponent (com.qcadoo.view.api.components.FieldComponent)11 Objects (java.util.Objects)11