Skip to content

Package: TableDMRValidation_Test

TableDMRValidation_Test

nameinstructionbranchcomplexitylinemethod
TableDMRValidation_Test(Boolean)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
assertChain(TableDMRValidation_Test.DiagnosticInfo[])
M: 2 C: 53
96%
M: 2 C: 6
75%
M: 2 C: 3
60%
M: 1 C: 13
93%
M: 0 C: 1
100%
before()
M: 0 C: 91
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 20
100%
M: 0 C: 1
100%
controlDMR()
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
data()
M: 0 C: 26
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
noContainer()
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
okColumn1()
M: 4 C: 24
86%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 1 C: 5
83%
M: 0 C: 1
100%
okColumn2()
M: 4 C: 24
86%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 1 C: 5
83%
M: 0 C: 1
100%
okTable()
M: 4 C: 37
90%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 1 C: 8
89%
M: 0 C: 1
100%
tableColumns()
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
tableDMR()
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
tableDMREFeature()
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
tableDMRPath()
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
testBadColumn()
M: 0 C: 32
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
testBadColumnNoContainer()
M: 0 C: 34
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 9
100%
M: 0 C: 1
100%
testBadEFeatureAttribute()
M: 4 C: 60
94%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 1 C: 12
92%
M: 0 C: 1
100%
testBadEFeatureAttributeNoContainer()
M: 4 C: 57
93%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 1 C: 13
93%
M: 0 C: 1
100%
testBadEFeatureSingleRef()
M: 4 C: 60
94%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 1 C: 12
92%
M: 0 C: 1
100%
testBadEFeatureSingleRefNoContainer()
M: 4 C: 57
93%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 1 C: 13
93%
M: 0 C: 1
100%
testBadReferenceOnPathToTable()
M: 0 C: 46
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 9
100%
M: 0 C: 1
100%
testBadReferenceOnPathToTableNoContainer()
M: 0 C: 43
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 10
100%
M: 0 C: 1
100%
testBadRootEClass()
M: 0 C: 44
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 9
100%
M: 0 C: 1
100%
testNoColumns()
M: 0 C: 24
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
testNoColumnsNoContainer()
M: 0 C: 31
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
testNoEFeatureOnPathToTable()
M: 0 C: 43
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 9
100%
M: 0 C: 1
100%
testNoEFeatureOnPathToTableNoContainer()
M: 0 C: 40
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 10
100%
M: 0 C: 1
100%
testOK()
M: 0 C: 24
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
testOKNoContainer()
M: 0 C: 31
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 9
100%
M: 0 C: 1
100%
validate()
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2014 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: * jfaltermeier - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.view.spi.table.model.util;
15:
16: import static org.junit.Assert.assertEquals;
17: import static org.junit.Assert.assertFalse;
18: import static org.junit.Assert.assertTrue;
19: import static org.junit.Assert.fail;
20: import static org.mockito.Matchers.any;
21: import static org.mockito.Matchers.same;
22:
23: import java.util.ArrayList;
24: import java.util.Arrays;
25: import java.util.Collection;
26: import java.util.Iterator;
27: import java.util.LinkedHashMap;
28: import java.util.LinkedHashSet;
29: import java.util.List;
30: import java.util.Set;
31:
32: import org.eclipse.emf.common.util.BasicDiagnostic;
33: import org.eclipse.emf.common.util.Diagnostic;
34: import org.eclipse.emf.databinding.EMFProperties;
35: import org.eclipse.emf.ecore.EClass;
36: import org.eclipse.emf.ecore.EObject;
37: import org.eclipse.emf.ecore.EStructuralFeature;
38: import org.eclipse.emf.ecp.view.spi.model.VControl;
39: import org.eclipse.emf.ecp.view.spi.model.VFeaturePathDomainModelReference;
40: import org.eclipse.emf.ecp.view.spi.model.VView;
41: import org.eclipse.emf.ecp.view.spi.model.VViewFactory;
42: import org.eclipse.emf.ecp.view.spi.model.VViewPackage;
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.emf.ecp.view.spi.table.model.VTablePackage;
46: import org.eclipse.emf.emfstore.bowling.BowlingPackage;
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: import org.junit.runner.RunWith;
52: import org.junit.runners.Parameterized;
53: import org.junit.runners.Parameterized.Parameters;
54: import org.mockito.Mockito;
55:
56: /**
57: * @author jfaltermeier
58: *
59: */
60: @RunWith(Parameterized.class)
61: public class TableDMRValidation_Test {
62:         private VView view;
63:         private VControl control;
64:         private VTableDomainModelReference table;
65:
66:         private TableValidator validator;
67:         private BasicDiagnostic chain;
68:         private LinkedHashMap<Object, Object> context;
69:         private final Boolean createChain;
70:         private VFeaturePathDomainModelReference column1;
71:         private VFeaturePathDomainModelReference column2;
72:         private VFeaturePathDomainModelReference tableDMR;
73:         private EMFFormsDatabindingEMF emfFormsDatabinding;
74:
75:         public TableDMRValidation_Test(Boolean createChain) {
76:                 this.createChain = createChain;
77:         }
78:
79:         @Parameters
80:         public static Collection<Object[]> data() {
81:                 // run all tests once with a diagnostic chain and once without
82:                 final List<Object[]> parameters = new ArrayList<Object[]>();
83:                 parameters.add(new Object[] { true });
84:                 parameters.add(new Object[] { false });
85:                 return parameters;
86:         }
87:
88:         @Before
89:         public void before() {
90:                 view = VViewFactory.eINSTANCE.createView();
91:                 view.setRootEClass(BowlingPackage.eINSTANCE.getReferee());
92:                 control = VViewFactory.eINSTANCE.createControl();
93:                 view.getChildren().add(control);
94:                 table = VTableFactory.eINSTANCE.createTableDomainModelReference();
95:                 tableDMR = VViewFactory.eINSTANCE.createFeaturePathDomainModelReference();
96:                 table.setDomainModelReference(tableDMR);
97:                 column1 = VViewFactory.eINSTANCE.createFeaturePathDomainModelReference();
98:                 column2 = VViewFactory.eINSTANCE.createFeaturePathDomainModelReference();
99:                 table.getColumnDomainModelReferences().add(column1);
100:                 table.getColumnDomainModelReferences().add(column2);
101:                 control.setDomainModelReference(table);
102:
103:                 emfFormsDatabinding = Mockito.mock(EMFFormsDatabindingEMF.class);
104:                 validator = new TableValidator(emfFormsDatabinding);
105:                 context = new LinkedHashMap<Object, Object>();
106:•                if (createChain) {
107:                         chain = new BasicDiagnostic();
108:                 } else {
109:                         chain = null;
110:                 }
111:         }
112:
113:         private void noContainer() {
114:                 control.eUnset(VViewPackage.eINSTANCE.getControl_DomainModelReference());
115:         }
116:
117:         private void okTable() {
118:                 final VFeaturePathDomainModelReference ref = (VFeaturePathDomainModelReference) table.getDomainModelReference();
119:                 ref.getDomainModelEReferencePath().add(BowlingPackage.eINSTANCE.getReferee_League());
120:                 ref.setDomainModelEFeature(BowlingPackage.eINSTANCE.getLeague_Players());
121:                 table.setDomainModelReference(ref);
122:                 try {
123:                         Mockito.doReturn(EMFProperties.value(BowlingPackage.eINSTANCE.getLeague_Players())).when(
124:                                 emfFormsDatabinding).getValueProperty(same(ref), any(EClass.class));
125:                 } catch (final DatabindingFailedException ex) {
126:                         fail(ex.getMessage());
127:                 }
128:         }
129:
130:         private void okColumn1() {
131:                 column1.setDomainModelEFeature(BowlingPackage.eINSTANCE.getPlayer_Name());
132:                 try {
133:                         Mockito.doReturn(EMFProperties.value(BowlingPackage.eINSTANCE.getPlayer_Name())).when(
134:                                 emfFormsDatabinding).getValueProperty(same(column1), any(EClass.class));
135:                 } catch (final DatabindingFailedException ex) {
136:                         fail(ex.getMessage());
137:                 }
138:         }
139:
140:         private void okColumn2() {
141:                 column2.setDomainModelEFeature(BowlingPackage.eINSTANCE.getPlayer_Gender());
142:                 try {
143:                         Mockito.doReturn(EMFProperties.value(BowlingPackage.eINSTANCE.getPlayer_Gender())).when(
144:                                 emfFormsDatabinding).getValueProperty(same(column2), any(EClass.class));
145:                 } catch (final DatabindingFailedException ex) {
146:                         fail(ex.getMessage());
147:                 }
148:         }
149:
150:         private boolean validate() {
151:                 return validator.validate(table, chain, context);
152:         }
153:
154:         private DiagnosticInfo controlDMR() {
155:                 return new DiagnosticInfo(Diagnostic.ERROR, control, VViewPackage.eINSTANCE.getControl_DomainModelReference());
156:         }
157:
158:         private DiagnosticInfo tableDMR() {
159:                 return new DiagnosticInfo(Diagnostic.ERROR, table,
160:                         VTablePackage.eINSTANCE.getTableDomainModelReference_DomainModelReference());
161:         }
162:
163:         private DiagnosticInfo tableDMREFeature() {
164:                 return new DiagnosticInfo(Diagnostic.ERROR, table.getDomainModelReference(),
165:                         VViewPackage.eINSTANCE.getFeaturePathDomainModelReference_DomainModelEFeature());
166:         }
167:
168:         private DiagnosticInfo tableDMRPath() {
169:                 return new DiagnosticInfo(Diagnostic.ERROR, table.getDomainModelReference(),
170:                         VViewPackage.eINSTANCE.getFeaturePathDomainModelReference_DomainModelEReferencePath());
171:         }
172:
173:         private DiagnosticInfo tableColumns() {
174:                 return new DiagnosticInfo(Diagnostic.WARNING, table,
175:                         VTablePackage.eINSTANCE.getTableDomainModelReference_ColumnDomainModelReferences());
176:         }
177:
178:         @Test
179:         public void testNoColumns() {
180:                 table.getColumnDomainModelReferences().clear();
181:                 okTable();
182:                 assertTrue(validate());
183:•                if (createChain) {
184:                         assertEquals(Diagnostic.OK, chain.getSeverity());
185:                         assertChain();
186:                 }
187:         }
188:
189:         @Test
190:         public void testNoColumnsNoContainer() {
191:                 noContainer();
192:                 table.getColumnDomainModelReferences().clear();
193:                 okTable();
194:                 // The validation fails because the a dmr that has no container cannot be resolved as its root EClass cannot be
195:                 // determined
196:                 assertFalse(validate());
197:•                if (createChain) {
198:                         assertEquals(Diagnostic.ERROR, chain.getSeverity());
199:                         assertChain(tableDMR());
200:                 }
201:         }
202:
203:         @Test
204:         public void testNoEFeatureOnPathToTable() {
205:                 okTable();
206:                 okColumn1();
207:                 okColumn2();
208:                 tableDMR.setDomainModelEFeature(null);
209:                 assertFalse(validate());
210:•                if (createChain) {
211:                         assertEquals(Diagnostic.ERROR, chain.getSeverity());
212:                         assertChain(controlDMR(), tableDMR(), tableDMREFeature());
213:                 }
214:         }
215:
216:         @Test
217:         public void testNoEFeatureOnPathToTableNoContainer() {
218:                 noContainer();
219:                 okTable();
220:                 okColumn1();
221:                 okColumn2();
222:                 tableDMR.setDomainModelEFeature(null);
223:                 assertFalse(validate());
224:•                if (createChain) {
225:                         assertEquals(Diagnostic.ERROR, chain.getSeverity());
226:                         assertChain(tableDMR(), tableDMREFeature());
227:                 }
228:         }
229:
230:         @Test
231:         public void testBadReferenceOnPathToTable() {
232:                 okTable();
233:                 okColumn1();
234:                 okColumn2();
235:                 tableDMR.getDomainModelEReferencePath().add(BowlingPackage.eINSTANCE.getFan_FanMerchandise());
236:                 assertFalse(validate());
237:•                if (createChain) {
238:                         assertEquals(Diagnostic.ERROR, chain.getSeverity());
239:                         assertChain(controlDMR(), tableDMR(), tableDMRPath());
240:                 }
241:         }
242:
243:         @Test
244:         public void testBadReferenceOnPathToTableNoContainer() {
245:                 noContainer();
246:                 okTable();
247:                 okColumn1();
248:                 okColumn2();
249:                 tableDMR.getDomainModelEReferencePath().add(BowlingPackage.eINSTANCE.getFan_FanMerchandise());
250:                 assertFalse(validate());
251:•                if (createChain) {
252:                         assertEquals(Diagnostic.ERROR, chain.getSeverity());
253:                         assertChain(tableDMR(), tableDMRPath());
254:                 }
255:         }
256:
257:         @Test
258:         public void testBadEFeatureSingleRef() {
259:                 okColumn1();
260:                 okColumn2();
261:                 view.setRootEClass(BowlingPackage.eINSTANCE.getFan());
262:                 tableDMR.setDomainModelEFeature(BowlingPackage.eINSTANCE.getFan_FavouritePlayer());
263:                 try {
264:                         Mockito.doReturn(EMFProperties.value(BowlingPackage.eINSTANCE.getFan_FavouritePlayer())).when(
265:                                 emfFormsDatabinding).getValueProperty(same(tableDMR), any(EClass.class));
266:                 } catch (final DatabindingFailedException ex) {
267:                         fail(ex.getMessage());
268:                 }
269:                 assertFalse(validate());
270:•                if (createChain) {
271:                         assertEquals(Diagnostic.ERROR, chain.getSeverity());
272:                         assertChain(controlDMR(), tableDMR());
273:                 }
274:         }
275:
276:         @Test
277:         public void testBadEFeatureSingleRefNoContainer() {
278:                 noContainer();
279:                 okColumn1();
280:                 okColumn2();
281:                 view.setRootEClass(BowlingPackage.eINSTANCE.getFan());
282:                 tableDMR.setDomainModelEFeature(BowlingPackage.eINSTANCE.getFan_FavouritePlayer());
283:                 try {
284:                         Mockito.doReturn(EMFProperties.value(BowlingPackage.eINSTANCE.getFan_FavouritePlayer())).when(
285:                                 emfFormsDatabinding).getValueProperty(same(tableDMR), any(EClass.class));
286:                 } catch (final DatabindingFailedException ex) {
287:                         fail(ex.getMessage());
288:                 }
289:                 assertFalse(validate());
290:•                if (createChain) {
291:                         assertEquals(Diagnostic.ERROR, chain.getSeverity());
292:                         assertChain(tableDMR());
293:                 }
294:         }
295:
296:         @Test
297:         public void testBadEFeatureAttribute() {
298:                 okColumn1();
299:                 okColumn2();
300:                 view.setRootEClass(BowlingPackage.eINSTANCE.getFan());
301:                 tableDMR.setDomainModelEFeature(BowlingPackage.eINSTANCE.getFan_EMails());
302:                 try {
303:                         Mockito.doReturn(EMFProperties.value(BowlingPackage.eINSTANCE.getFan_EMails())).when(
304:                                 emfFormsDatabinding).getValueProperty(same(tableDMR), any(EClass.class));
305:                 } catch (final DatabindingFailedException ex) {
306:                         fail(ex.getMessage());
307:                 }
308:                 assertFalse(validate());
309:•                if (createChain) {
310:                         assertEquals(Diagnostic.ERROR, chain.getSeverity());
311:                         assertChain(controlDMR(), tableDMR());
312:                 }
313:         }
314:
315:         @Test
316:         public void testBadEFeatureAttributeNoContainer() {
317:                 noContainer();
318:                 okColumn1();
319:                 okColumn2();
320:                 view.setRootEClass(BowlingPackage.eINSTANCE.getFan());
321:                 tableDMR.setDomainModelEFeature(BowlingPackage.eINSTANCE.getFan_EMails());
322:                 try {
323:                         Mockito.doReturn(EMFProperties.value(BowlingPackage.eINSTANCE.getFan_EMails())).when(
324:                                 emfFormsDatabinding).getValueProperty(same(tableDMR), any(EClass.class));
325:                 } catch (final DatabindingFailedException ex) {
326:                         fail(ex.getMessage());
327:                 }
328:                 assertFalse(validate());
329:•                if (createChain) {
330:                         assertEquals(Diagnostic.ERROR, chain.getSeverity());
331:                         assertChain(tableDMR());
332:                 }
333:         }
334:
335:         @Test
336:         public void testBadColumn() {
337:                 okTable();
338:                 okColumn1();
339:                 column2.setDomainModelEFeature(BowlingPackage.eINSTANCE.getFan_Gender());
340:                 assertFalse(validate());
341:•                if (createChain) {
342:                         assertEquals(Diagnostic.WARNING, chain.getSeverity());
343:                         assertChain(tableColumns());
344:                 }
345:         }
346:
347:         @Test
348:         public void testBadColumnNoContainer() {
349:                 noContainer();
350:                 okTable();
351:                 okColumn1();
352:                 column2.setDomainModelEFeature(BowlingPackage.eINSTANCE.getFan_Gender());
353:                 assertFalse(validate());
354:•                if (createChain) {
355:                         assertEquals(Diagnostic.ERROR, chain.getSeverity());
356:                         // There is only a diagnostic on the table dmr but not the columns: The columns cannot be validated if the
357:                         // table DMR cannot be resolved
358:                         assertChain(tableDMR());
359:                 }
360:         }
361:
362:         @Test
363:         public void testOK() {
364:                 okColumn1();
365:                 okColumn2();
366:                 okTable();
367:                 assertTrue(validate());
368:•                if (createChain) {
369:                         assertEquals(Diagnostic.OK, chain.getSeverity());
370:                         assertChain();
371:                 }
372:         }
373:
374:         @Test
375:         public void testOKNoContainer() {
376:                 noContainer();
377:                 okColumn1();
378:                 okColumn2();
379:                 okTable();
380:                 // The validation fails because the a dmr that has no container cannot be resolved as its root EClass cannot be
381:                 // determined
382:                 assertFalse(validate());
383:•                if (createChain) {
384:                         assertEquals(Diagnostic.ERROR, chain.getSeverity());
385:                         assertChain(tableDMR());
386:                 }
387:         }
388:
389:         @Test
390:         public void testBadRootEClass() {
391:                 okColumn1();
392:                 okColumn2();
393:                 okTable();
394:                 view.setRootEClass(BowlingPackage.eINSTANCE.getFan());
395:                 assertFalse(validate());
396:•                if (createChain) {
397:                         assertEquals(Diagnostic.ERROR, chain.getSeverity());
398:                         assertChain(controlDMR(), tableDMR(), tableDMRPath());
399:                 }
400:         }
401:
402:         private void assertChain(DiagnosticInfo... infos) {
403:                 final Set<DiagnosticInfo> infoSet = new LinkedHashSet<DiagnosticInfo>(Arrays.asList(infos));
404:                 assertEquals(infos.length, chain.getChildren().size());
405:•                for (final Diagnostic child : chain.getChildren()) {
406:                         boolean found = false;
407:                         final Iterator<DiagnosticInfo> iterator = infoSet.iterator();
408:•                        while (iterator.hasNext()) {
409:                                 final DiagnosticInfo next = iterator.next();
410:•                                if (next.sameData(child)) {
411:                                         found = true;
412:                                         iterator.remove();
413:                                         break;
414:                                 }
415:                         }
416:•                        if (!found) {
417:                                 fail("Chain is missing child diagnostic."); //$NON-NLS-1$
418:                         }
419:                 }
420:         }
421:
422:         private class DiagnosticInfo {
423:                 private final int severity;
424:                 private final EObject object;
425:                 private final EStructuralFeature feature;
426:
427:                 DiagnosticInfo(int severity, EObject object, EStructuralFeature feature) {
428:                         this.severity = severity;
429:                         this.object = object;
430:                         this.feature = feature;
431:                 }
432:
433:                 public boolean sameData(Diagnostic diagnostic) {
434:                         if (diagnostic.getSeverity() != severity) {
435:                                 return false;
436:                         }
437:                         if (!object.equals(diagnostic.getData().get(0))) {
438:                                 return false;
439:                         }
440:                         if (!feature.equals(diagnostic.getData().get(1))) {
441:                                 return false;
442:                         }
443:                         return true;
444:                 }
445:
446:         }
447: }