Search in sources :

Example 6 with InternalViewDefinitionState

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

the class GridComponentPatternTest method shouldReturnState.

@Test
public void shouldReturnState() throws Exception {
    // given
    InternalViewDefinitionState viewDefinitionState = mock(InternalViewDefinitionState.class);
    DataDefinition dataDefinition = mock(DataDefinition.class);
    BelongsToType belongsToFieldType = mock(BelongsToType.class);
    FieldDefinition belongsToFieldDefinition = mock(FieldDefinition.class);
    given(belongsToFieldDefinition.getName()).willReturn("joinName");
    given(belongsToFieldDefinition.getType()).willReturn(belongsToFieldType);
    HasManyType hasManyFieldType = mock(HasManyType.class);
    given(hasManyFieldType.getJoinFieldName()).willReturn("joinName");
    given(hasManyFieldType.getDataDefinition()).willReturn(dataDefinition);
    FieldDefinition hasManyFieldDefinition = mock(FieldDefinition.class);
    given(hasManyFieldDefinition.getName()).willReturn("fieldName");
    given(hasManyFieldDefinition.getType()).willReturn(hasManyFieldType);
    given(dataDefinition.getField("field")).willReturn(hasManyFieldDefinition);
    given(dataDefinition.getField("joinName")).willReturn(belongsToFieldDefinition);
    InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
    AbstractComponentPattern sourceComponent = new TextInputComponentPattern(getComponentDefinition("component", viewDefinition));
    setField(sourceComponent, "dataDefinition", dataDefinition);
    setField(sourceComponent, "initialized", true);
    given(viewDefinition.getComponentByReference("component")).willReturn(sourceComponent);
    ComponentDefinition componentDefinition = getComponentDefinition(QcadooViewConstants.L_GRID, null, "#{component}.field", null, viewDefinition);
    componentDefinition.setTranslationService(translationService);
    componentDefinition.setApplicationContext(applicationContext);
    GridComponentPattern pattern = new GridComponentPattern(componentDefinition);
    pattern.addOption(new ComponentOption("order", ImmutableMap.of("column", "name", "direction", "asc")));
    pattern.initialize();
    // when
    ComponentState state = pattern.createComponentState(viewDefinitionState);
    // then
    assertTrue(state instanceof GridComponent);
    assertEquals(belongsToFieldDefinition, getField(state, "belongsToFieldDefinition"));
    assertEquals(getField(pattern, "columns"), getField(state, "columns"));
}
Also used : InternalViewDefinitionState(com.qcadoo.view.internal.api.InternalViewDefinitionState) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) ComponentOption(com.qcadoo.view.internal.ComponentOption) GridComponent(com.qcadoo.view.api.components.GridComponent) FieldDefinition(com.qcadoo.model.api.FieldDefinition) DataDefinition(com.qcadoo.model.api.DataDefinition) TextInputComponentPattern(com.qcadoo.view.internal.components.TextInputComponentPattern) HasManyType(com.qcadoo.model.api.types.HasManyType) BelongsToType(com.qcadoo.model.api.types.BelongsToType) GridComponentPattern(com.qcadoo.view.internal.components.grid.GridComponentPattern) AbstractComponentPattern(com.qcadoo.view.internal.patterns.AbstractComponentPattern) ComponentDefinition(com.qcadoo.view.internal.ComponentDefinition) ComponentState(com.qcadoo.view.api.ComponentState) AbstractPatternTest(com.qcadoo.view.internal.patterns.AbstractPatternTest) Test(org.junit.Test)

Example 7 with InternalViewDefinitionState

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

the class GridComponentPatternTest method shouldFilterOutColumnsInvisibleForTenant.

@Test
public void shouldFilterOutColumnsInvisibleForTenant() throws Exception {
    // given
    PluginStateResolver pluginStateResolver = mock(PluginStateResolver.class);
    PluginUtilsService pluginUtil = new PluginUtilsService(pluginStateResolver);
    pluginUtil.init();
    given(pluginStateResolver.isEnabled("disabledPlugin")).willReturn(false);
    InternalViewDefinitionState viewDefinitionState = mock(InternalViewDefinitionState.class);
    DataDefinition dataDefinition = mock(DataDefinition.class);
    InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
    given(viewDefinition.getDataDefinition()).willReturn(dataDefinition);
    ComponentDefinition componentDefinition = getComponentDefinition(QcadooViewConstants.L_GRID, viewDefinition);
    componentDefinition.setTranslationService(translationService);
    componentDefinition.setApplicationContext(applicationContext);
    componentDefinition.setDataDefinition(dataDefinition);
    GridComponentPattern pattern = new GridComponentPattern(componentDefinition);
    FieldDefinition nameFieldDefinition = mock(FieldDefinition.class);
    given(nameFieldDefinition.getType()).willReturn(new EnumType(translationService, "", true, "v1", "v2"));
    given(dataDefinition.getField("name")).willReturn(nameFieldDefinition);
    pattern.addOption(new ComponentOption("column", ImmutableMap.of("name", "name", "fields", "name", "hidden", "true")));
    pattern.addOption(new ComponentOption("order", ImmutableMap.of("column", "name", "direction", "asc")));
    ViewGridColumnModuleColumnModel columnModel = new ViewGridColumnModuleColumnModel("invisible", "name");
    columnModel.setWidth(100);
    pattern.addColumn("disabledPlugin", columnModel);
    pattern.initialize();
    // when
    ComponentState state = pattern.createComponentState(viewDefinitionState);
    // then
    assertTrue(state instanceof GridComponent);
    @SuppressWarnings("unchecked") Map<String, GridComponentColumn> patternColumns = (Map<String, GridComponentColumn>) getField(pattern, "columns");
    @SuppressWarnings("unchecked") Map<String, GridComponentColumn> stateColumns = (Map<String, GridComponentColumn>) getField(state, "columns");
    assertEquals(2, patternColumns.size());
    assertEquals(1, stateColumns.size());
    assertTrue(patternColumns.keySet().contains("name"));
    assertNotNull(patternColumns.get("name"));
    assertTrue(patternColumns.keySet().contains("invisible"));
    assertNotNull(patternColumns.get("invisible"));
    assertTrue(stateColumns.keySet().contains("name"));
    assertNotNull(stateColumns.get("name"));
    assertFalse(stateColumns.keySet().contains("invisible"));
    assertNull(stateColumns.get("invisible"));
}
Also used : PluginUtilsService(com.qcadoo.plugin.internal.PluginUtilsService) ViewGridColumnModuleColumnModel(com.qcadoo.view.internal.module.gridColumn.ViewGridColumnModuleColumnModel) InternalViewDefinitionState(com.qcadoo.view.internal.api.InternalViewDefinitionState) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) ComponentOption(com.qcadoo.view.internal.ComponentOption) GridComponent(com.qcadoo.view.api.components.GridComponent) FieldDefinition(com.qcadoo.model.api.FieldDefinition) GridComponentColumn(com.qcadoo.view.internal.components.grid.GridComponentColumn) DataDefinition(com.qcadoo.model.api.DataDefinition) GridComponentPattern(com.qcadoo.view.internal.components.grid.GridComponentPattern) PluginStateResolver(com.qcadoo.plugin.api.PluginStateResolver) EnumType(com.qcadoo.model.internal.types.EnumType) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ComponentDefinition(com.qcadoo.view.internal.ComponentDefinition) ComponentState(com.qcadoo.view.api.ComponentState) AbstractPatternTest(com.qcadoo.view.internal.patterns.AbstractPatternTest) Test(org.junit.Test)

Example 8 with InternalViewDefinitionState

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

the class ComponentPatternTest method shouldHaveValidInstance.

@Test
@SuppressWarnings("unchecked")
public void shouldHaveValidInstance() throws Exception {
    // given
    InternalViewDefinitionState viewDefinitionState = mock(InternalViewDefinitionState.class);
    TranslationService translationService = mock(TranslationService.class);
    ApplicationContext applicationContext = mock(ApplicationContext.class);
    InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
    ComponentDefinition componentDefinition = getComponentDefinition("testName", null);
    componentDefinition.setTranslationService(translationService);
    componentDefinition.setApplicationContext(applicationContext);
    componentDefinition.setViewDefinition(viewDefinition);
    AbstractComponentPattern pattern = new FormComponentPattern(componentDefinition);
    ViewEventListenerHook viewEventListenerHook = mock(ViewEventListenerHook.class);
    given(viewEventListenerHook.getEventName()).willReturn("save");
    pattern.addCustomEvent(viewEventListenerHook);
    // when
    ComponentState state = pattern.createComponentState(viewDefinitionState);
    // then
    assertTrue(state instanceof FormComponent);
    EventHandlerHolder eventHandlerHolder = (EventHandlerHolder) getField(state, "eventHandlerHolder");
    Map<String, List<EventHandlerHolder.EventHandler>> eventHandlers = (Map<String, List<EventHandlerHolder.EventHandler>>) getField(eventHandlerHolder, "eventHandlers");
    List<EventHandlerHolder.EventHandler> handlers = eventHandlers.get("save");
    assertNotNull(handlers);
    assertEquals(2, handlers.size());
    assertEquals(viewEventListenerHook, handlers.get(1));
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) InternalViewDefinitionState(com.qcadoo.view.internal.api.InternalViewDefinitionState) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) EventHandlerHolder(com.qcadoo.view.internal.internal.EventHandlerHolder) ApplicationContext(org.springframework.context.ApplicationContext) ViewEventListenerHook(com.qcadoo.view.internal.hooks.ViewEventListenerHook) FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) TranslationService(com.qcadoo.localization.api.TranslationService) List(java.util.List) Map(java.util.Map) ComponentDefinition(com.qcadoo.view.internal.ComponentDefinition) ComponentState(com.qcadoo.view.api.ComponentState) Test(org.junit.Test)

Example 9 with InternalViewDefinitionState

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

Aggregations

InternalViewDefinitionState (com.qcadoo.view.internal.api.InternalViewDefinitionState)9 Test (org.junit.Test)7 ComponentState (com.qcadoo.view.api.ComponentState)6 InternalViewDefinition (com.qcadoo.view.internal.api.InternalViewDefinition)6 ComponentDefinition (com.qcadoo.view.internal.ComponentDefinition)4 DataDefinition (com.qcadoo.model.api.DataDefinition)3 FieldDefinition (com.qcadoo.model.api.FieldDefinition)3 GridComponent (com.qcadoo.view.api.components.GridComponent)3 ComponentOption (com.qcadoo.view.internal.ComponentOption)3 InternalComponentState (com.qcadoo.view.internal.api.InternalComponentState)3 GridComponentPattern (com.qcadoo.view.internal.components.grid.GridComponentPattern)3 ViewDefinitionStateImpl (com.qcadoo.view.internal.internal.ViewDefinitionStateImpl)3 AbstractPatternTest (com.qcadoo.view.internal.patterns.AbstractPatternTest)3 Map (java.util.Map)3 JSONObject (org.json.JSONObject)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 EnumType (com.qcadoo.model.internal.types.EnumType)2 PluginStateResolver (com.qcadoo.plugin.api.PluginStateResolver)2 PluginUtilsService (com.qcadoo.plugin.internal.PluginUtilsService)2 TextInputComponentPattern (com.qcadoo.view.internal.components.TextInputComponentPattern)2