Skip to content

Package: EMFFormsMappingProviderTable_Test

EMFFormsMappingProviderTable_Test

nameinstructionbranchcomplexitylinemethod
EMFFormsMappingProviderTable_Test()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
containsSettingWithEObject(Set, EObject)
M: 2 C: 18
90%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 1 C: 3
75%
M: 0 C: 1
100%
setUp()
M: 0 C: 36
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
testGetMappingFor()
M: 0 C: 197
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 35
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2018 EclipseSource Muenchen GmbH and others.
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License 2.0
6: * which accompanies this distribution, and is available at
7: * https://www.eclipse.org/legal/epl-2.0/
8: *
9: * SPDX-License-Identifier: EPL-2.0
10: *
11: * Contributors:
12: * Eugen Neufeld - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emfforms.internal.core.services.mappingprovider.table.panel;
15:
16: import static org.junit.Assert.assertEquals;
17: import static org.junit.Assert.assertTrue;
18: import static org.mockito.Matchers.any;
19: import static org.mockito.Matchers.anyBoolean;
20: import static org.mockito.Matchers.same;
21: import static org.mockito.Mockito.mock;
22: import static org.mockito.Mockito.times;
23: import static org.mockito.Mockito.verify;
24: import static org.mockito.Mockito.when;
25:
26: import java.util.Collections;
27: import java.util.Set;
28:
29: import org.eclipse.emf.common.util.BasicEList;
30: import org.eclipse.emf.common.util.EList;
31: import org.eclipse.emf.ecore.EClass;
32: import org.eclipse.emf.ecore.EObject;
33: import org.eclipse.emf.ecore.EStructuralFeature;
34: import org.eclipse.emf.ecore.EStructuralFeature.Setting;
35: import org.eclipse.emf.ecp.common.spi.UniqueSetting;
36: import org.eclipse.emf.ecp.view.spi.model.VControl;
37: import org.eclipse.emf.ecp.view.spi.model.VDomainModelReference;
38: import org.eclipse.emf.ecp.view.spi.model.VView;
39: import org.eclipse.emf.ecp.view.spi.model.VViewFactory;
40: import org.eclipse.emf.ecp.view.spi.model.VViewModelProperties;
41: import org.eclipse.emf.ecp.view.spi.provider.EMFFormsViewService;
42: import org.eclipse.emf.ecp.view.spi.table.model.VTableControl;
43: import org.eclipse.emf.ecp.view.spi.table.model.VTableDomainModelReference;
44: import org.eclipse.emf.ecp.view.spi.table.model.VTableFactory;
45: import org.eclipse.emfforms.spi.common.report.AbstractReport;
46: import org.eclipse.emfforms.spi.common.report.ReportService;
47: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedException;
48: import org.eclipse.emfforms.spi.core.services.databinding.emf.EMFFormsDatabindingEMF;
49: import org.junit.Before;
50: import org.junit.Test;
51:
52: /**
53: * Unit tests for {@link EMFFormsMappingProviderTable}.
54: *
55: * @author Eugen Neufeld
56: *
57: */
58: public class EMFFormsMappingProviderTable_Test {
59:
60:         private EMFFormsMappingProviderTable provider;
61:         private ReportService reportService;
62:         private EMFFormsDatabindingEMF databinding;
63:         private EMFFormsViewService viewService;
64:
65:         @Before
66:         public void setUp() {
67:                 provider = new EMFFormsMappingProviderTable();
68:                 reportService = mock(ReportService.class);
69:                 databinding = mock(EMFFormsDatabindingEMF.class);
70:                 viewService = mock(EMFFormsViewService.class);
71:
72:                 provider.setReportService(reportService);
73:                 provider.setEMFFormsDatabinding(databinding);
74:                 provider.setEMFFormsViewService(viewService);
75:         }
76:
77:         /**
78:          * Tests that the get mapping for method does not fail and does not report an error if the data binding of a column
79:          * dmr fails.
80:          *
81:          * @throws DatabindingFailedException
82:          */
83:         @SuppressWarnings("unchecked")
84:         @Test
85:         public void testGetMappingFor() throws DatabindingFailedException {
86:                 final VTableDomainModelReference tableDmr = VTableFactory.eINSTANCE.createTableDomainModelReference();
87:                 final VTableControl table = VTableFactory.eINSTANCE.createTableControl();
88:                 table.setDomainModelReference(tableDmr);
89:                 final VView view = VViewFactory.eINSTANCE.createView();
90:                 view.getChildren().add(table);
91:
92:                 final Setting tableSetting = mock(Setting.class);
93:                 final EObject tableEntry = mock(EObject.class);
94:                 final EClass tableEntryClass = mock(EClass.class);
95:                 when(tableEntry.eClass()).thenReturn(tableEntryClass);
96:                 final EList<EStructuralFeature> allFeatures = new BasicEList<EStructuralFeature>();
97:                 when(tableEntryClass.getEAllStructuralFeatures()).thenReturn(allFeatures);
98:                 allFeatures.add(mock(EStructuralFeature.class));
99:                 when(tableSetting.get(anyBoolean())).thenReturn(Collections.singletonList(tableEntry));
100:
101:                 // Return mocked EObject's to avoid the created unique settings being equal.
102:                 final EObject tableSettingEObject = mock(EObject.class);
103:                 when(tableSetting.getEObject()).thenReturn(tableSettingEObject);
104:
105:                 // Cannot mock dmrs because mocked dmrs cannot be added to an EList
106:                 final VDomainModelReference columnInvalid = VViewFactory.eINSTANCE.createFeaturePathDomainModelReference();
107:                 tableDmr.getColumnDomainModelReferences().add(columnInvalid);
108:
109:                 final VView detailView = VViewFactory.eINSTANCE.createView();
110:                 final VControl innerControl = VViewFactory.eINSTANCE.createControl();
111:                 final VDomainModelReference innerControlDMR = VViewFactory.eINSTANCE.createFeaturePathDomainModelReference();
112:                 innerControl.setDomainModelReference(innerControlDMR);
113:                 detailView.getChildren().add(innerControl);
114:
115:                 when(viewService.getView(same(tableEntry), any(VViewModelProperties.class))).thenReturn(detailView);
116:
117:                 when(databinding.getSetting(same(columnInvalid), any(EObject.class)))
118:                         .thenThrow(DatabindingFailedException.class);
119:                 when(databinding.getSetting(same(tableDmr), any(EObject.class))).thenReturn(tableSetting);
120:
121:                 final Setting panelSetting = mock(Setting.class);
122:                 when(panelSetting.getEObject()).thenReturn(tableEntry);
123:                 when(databinding.getSetting(same(innerControlDMR), same(tableEntry))).thenReturn(panelSetting);
124:
125:                 final Set<UniqueSetting> result = provider.getMappingFor(tableDmr, mock(EObject.class));
126:
127:                 assertEquals(2, result.size());
128:                 assertTrue("Result must contain the table setting.", containsSettingWithEObject(result, tableSettingEObject)); //$NON-NLS-1$
129:                 assertTrue("Result must contain the setting of table entries.", containsSettingWithEObject(result, tableEntry)); //$NON-NLS-1$
130:                 verify(reportService, times(0)).report(any(AbstractReport.class));
131:         }
132:
133:         private boolean containsSettingWithEObject(Set<UniqueSetting> set, EObject eObject) {
134:•                for (final UniqueSetting unique : set) {
135:•                        if (unique.getEObject().equals(eObject)) {
136:                                 return true;
137:                         }
138:                 }
139:                 return false;
140:         }
141: }