Skip to content

Package: IndexDMRValidation_Test

IndexDMRValidation_Test

nameinstructionbranchcomplexitylinemethod
IndexDMRValidation_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(IndexDMRValidation_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: 65
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 16
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%
indexFeature()
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%
indexIndex()
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%
indexPath()
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%
indexTarget()
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%
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%
okIndex()
M: 0 C: 20
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
okTarget()
M: 0 C: 20
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
targetPath()
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%
testBadEFeatureOnPathToIndexAttribute()
M: 0 C: 35
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
testBadEFeatureOnPathToIndexAttributeNoContainer()
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%
testBadEFeatureOnPathToIndexSingleReference()
M: 0 C: 42
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
testBadEFeatureOnPathToIndexSingleReferenceNoContainer()
M: 0 C: 39
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 9
100%
M: 0 C: 1
100%
testBadIndex()
M: 0 C: 36
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
testBadIndexNoContainer()
M: 0 C: 33
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 9
100%
M: 0 C: 1
100%
testBadPathOnTarget()
M: 0 C: 43
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
testBadPathOnTargetNoContainer()
M: 0 C: 40
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 9
100%
M: 0 C: 1
100%
testBadReferenceOnPathToIndex()
M: 0 C: 42
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
testBadReferenceOnPathToIndexNoContainer()
M: 0 C: 46
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: 37
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
testBadRootEClassGoodRootEClassInContext()
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%
testNoEFeatureOnPathToIndex()
M: 30 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
testNoEFeatureOnPathToIndexNoContainer()
M: 27 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
testNoTargetDMR()
M: 0 C: 34
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
testNoTargetDMRNoContainer()
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%
testOK()
M: 0 C: 22
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
testOKNoContainer()
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%
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.indexdmr.model.test;
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:
21: import java.util.ArrayList;
22: import java.util.Arrays;
23: import java.util.Collection;
24: import java.util.Iterator;
25: import java.util.LinkedHashMap;
26: import java.util.LinkedHashSet;
27: import java.util.List;
28: import java.util.Set;
29:
30: import org.eclipse.emf.common.util.BasicDiagnostic;
31: import org.eclipse.emf.common.util.Diagnostic;
32: import org.eclipse.emf.ecore.EObject;
33: import org.eclipse.emf.ecore.EStructuralFeature;
34: import org.eclipse.emf.ecore.EValidator;
35: import org.eclipse.emf.ecp.view.index.test.example.ExamplePackage;
36: import org.eclipse.emf.ecp.view.spi.indexdmr.model.VIndexDomainModelReference;
37: import org.eclipse.emf.ecp.view.spi.indexdmr.model.VIndexdmrFactory;
38: import org.eclipse.emf.ecp.view.spi.indexdmr.model.VIndexdmrPackage;
39: import org.eclipse.emf.ecp.view.spi.indexdmr.model.util.IndexdmrValidator;
40: import org.eclipse.emf.ecp.view.spi.model.VControl;
41: import org.eclipse.emf.ecp.view.spi.model.VFeaturePathDomainModelReference;
42: import org.eclipse.emf.ecp.view.spi.model.VView;
43: import org.eclipse.emf.ecp.view.spi.model.VViewFactory;
44: import org.eclipse.emf.ecp.view.spi.model.VViewPackage;
45: import org.eclipse.emf.ecp.view.spi.model.util.ViewValidator;
46: import org.junit.Before;
47: import org.junit.Ignore;
48: import org.junit.Test;
49: import org.junit.runner.RunWith;
50: import org.junit.runners.Parameterized;
51: import org.junit.runners.Parameterized.Parameters;
52:
53: /**
54: * Errors on path to index
55: * Index negative
56: * Errors on target Path
57: *
58: * @author jfaltermeier
59: *
60: */
61: @RunWith(Parameterized.class)
62: public class IndexDMRValidation_Test {
63:
64:         private VView view;
65:         private VControl control;
66:         private VIndexDomainModelReference index;
67:
68:         private EValidator validator;
69:         private BasicDiagnostic chain;
70:         private LinkedHashMap<Object, Object> context;
71:         private final Boolean createChain;
72:         private VFeaturePathDomainModelReference target;
73:
74:         public IndexDMRValidation_Test(Boolean createChain) {
75:                 this.createChain = createChain;
76:         }
77:
78:         @Parameters
79:         public static Collection<Object[]> data() {
80:                 // run all tests once with a diagnostic chain and once without
81:                 final List<Object[]> parameters = new ArrayList<Object[]>();
82:                 parameters.add(new Object[] { true });
83:                 parameters.add(new Object[] { false });
84:                 return parameters;
85:         }
86:
87:         @Before
88:         public void before() {
89:                 view = VViewFactory.eINSTANCE.createView();
90:                 view.setRootEClass(ExamplePackage.eINSTANCE.getRoot());
91:                 control = VViewFactory.eINSTANCE.createControl();
92:                 view.getChildren().add(control);
93:                 index = VIndexdmrFactory.eINSTANCE.createIndexDomainModelReference();
94:                 target = VViewFactory.eINSTANCE.createFeaturePathDomainModelReference();
95:                 index.setTargetDMR(target);
96:                 index.setPrefixDMR(VViewFactory.eINSTANCE.createFeaturePathDomainModelReference());
97:                 control.setDomainModelReference(index);
98:
99:                 validator = IndexdmrValidator.INSTANCE;
100:                 context = new LinkedHashMap<Object, Object>();
101:•                if (createChain) {
102:                         chain = new BasicDiagnostic();
103:                 } else {
104:                         chain = null;
105:                 }
106:         }
107:
108:         private void noContainer() {
109:                 control.eUnset(VViewPackage.eINSTANCE.getControl_DomainModelReference());
110:         }
111:
112:         private void okTarget() {
113:                 target.getDomainModelEReferencePath().add(ExamplePackage.eINSTANCE.getChild_IntermediateTarget());
114:                 target.getDomainModelEReferencePath().add(ExamplePackage.eINSTANCE.getIntermediateTarget_Target());
115:                 target.setDomainModelEFeature(ExamplePackage.eINSTANCE.getTarget_Name());
116:         }
117:
118:         private void okIndex() {
119:                 index.getDomainModelEReferencePath().add(ExamplePackage.eINSTANCE.getRoot_Intermediate());
120:                 index.getDomainModelEReferencePath().add(ExamplePackage.eINSTANCE.getIntermediate_Container());
121:                 index.setDomainModelEFeature(ExamplePackage.eINSTANCE.getContainer_Children());
122:         }
123:
124:         private DiagnosticInfo controlDMR() {
125:                 return new DiagnosticInfo(Diagnostic.ERROR, control, VViewPackage.eINSTANCE.getControl_DomainModelReference());
126:         }
127:
128:         private DiagnosticInfo indexFeature() {
129:                 return new DiagnosticInfo(Diagnostic.ERROR, index,
130:                         VViewPackage.eINSTANCE.getFeaturePathDomainModelReference_DomainModelEFeature());
131:         }
132:
133:         private DiagnosticInfo indexPath() {
134:                 return new DiagnosticInfo(Diagnostic.ERROR, index,
135:                         VViewPackage.eINSTANCE.getFeaturePathDomainModelReference_DomainModelEReferencePath());
136:         }
137:
138:         private DiagnosticInfo indexIndex() {
139:                 return new DiagnosticInfo(Diagnostic.ERROR, index,
140:                         VIndexdmrPackage.eINSTANCE.getIndexDomainModelReference_Index());
141:         }
142:
143:         private DiagnosticInfo indexTarget() {
144:                 return new DiagnosticInfo(Diagnostic.ERROR, index,
145:                         VIndexdmrPackage.eINSTANCE.getIndexDomainModelReference_TargetDMR());
146:         }
147:
148:         private DiagnosticInfo targetPath() {
149:                 return new DiagnosticInfo(Diagnostic.ERROR, target,
150:                         VViewPackage.eINSTANCE.getFeaturePathDomainModelReference_DomainModelEReferencePath());
151:         }
152:
153:         private boolean validate() {
154:                 return validator.validate(index, chain, context);
155:         }
156:
157:         @Test
158:         public void testNoTargetDMR() {
159:                 okIndex();
160:                 index.setTargetDMR(null);
161:                 assertFalse(validate());
162:•                if (createChain) {
163:                         assertEquals(Diagnostic.ERROR, chain.getSeverity());
164:                         assertChain(controlDMR(), indexTarget());
165:                 }
166:         }
167:
168:         @Test
169:         public void testNoTargetDMRNoContainer() {
170:                 noContainer();
171:                 okIndex();
172:                 index.setTargetDMR(null);
173:                 assertFalse(validate());
174:•                if (createChain) {
175:                         assertEquals(Diagnostic.ERROR, chain.getSeverity());
176:                         assertChain(indexTarget());
177:                 }
178:         }
179:
180:         // FIXME review test case
181:         @Ignore
182:         @Test
183:         public void testNoEFeatureOnPathToIndex() {
184:                 okTarget();
185:                 assertFalse(validate());
186:•                if (createChain) {
187:                         assertEquals(Diagnostic.ERROR, chain.getSeverity());
188:                         assertChain(controlDMR(), indexFeature());
189:                 }
190:         }
191:
192:         /**
193:          * Re-enable after FIXMEs in IndexdmrValidator are addressed
194:          */
195:         @Ignore
196:         @Test
197:         public void testNoEFeatureOnPathToIndexNoContainer() {
198:                 noContainer();
199:                 okTarget();
200:                 assertFalse(validate());
201:•                if (createChain) {
202:                         assertEquals(Diagnostic.ERROR, chain.getSeverity());
203:                         assertChain(indexFeature());
204:                 }
205:         }
206:
207:         @Test
208:         public void testBadReferenceOnPathToIndex() {
209:                 okTarget();
210:                 index.getDomainModelEReferencePath().add(ExamplePackage.eINSTANCE.getIntermediate_Container());
211:                 index.setDomainModelEFeature(ExamplePackage.eINSTANCE.getContainer_Children());
212:                 assertFalse(validate());
213:•                if (createChain) {
214:                         assertEquals(Diagnostic.ERROR, chain.getSeverity());
215:                         assertChain(controlDMR(), indexPath());
216:                 }
217:         }
218:
219:         @Test
220:         public void testBadReferenceOnPathToIndexNoContainer() {
221:                 noContainer();
222:                 okTarget();
223:                 index.getDomainModelEReferencePath().add(ExamplePackage.eINSTANCE.getIntermediate_Container());
224:                 index.getDomainModelEReferencePath().add(ExamplePackage.eINSTANCE.getIntermediate_Container());
225:                 index.setDomainModelEFeature(ExamplePackage.eINSTANCE.getContainer_Children());
226:                 assertFalse(validate());
227:•                if (createChain) {
228:                         assertEquals(Diagnostic.ERROR, chain.getSeverity());
229:                         assertChain(indexPath());
230:                 }
231:         }
232:
233:         @Test
234:         public void testBadEFeatureOnPathToIndexSingleReference() {
235:                 okTarget();
236:                 index.getDomainModelEReferencePath().add(ExamplePackage.eINSTANCE.getRoot_Intermediate());
237:                 index.setDomainModelEFeature(ExamplePackage.eINSTANCE.getIntermediate_Container());
238:                 assertFalse(validate());
239:•                if (createChain) {
240:                         assertEquals(Diagnostic.ERROR, chain.getSeverity());
241:                         assertChain(controlDMR(), indexFeature());
242:                 }
243:         }
244:
245:         @Test
246:         public void testBadEFeatureOnPathToIndexSingleReferenceNoContainer() {
247:                 noContainer();
248:                 okTarget();
249:                 index.getDomainModelEReferencePath().add(ExamplePackage.eINSTANCE.getRoot_Intermediate());
250:                 index.setDomainModelEFeature(ExamplePackage.eINSTANCE.getIntermediate_Container());
251:                 assertFalse(validate());
252:•                if (createChain) {
253:                         assertEquals(Diagnostic.ERROR, chain.getSeverity());
254:                         assertChain(indexFeature());
255:                 }
256:         }
257:
258:         @Test
259:         public void testBadEFeatureOnPathToIndexAttribute() {
260:                 okTarget();
261:                 index.setDomainModelEFeature(ExamplePackage.eINSTANCE.getTarget_Name());
262:                 assertFalse(validate());
263:•                if (createChain) {
264:                         assertEquals(Diagnostic.ERROR, chain.getSeverity());
265:                         assertChain(controlDMR(), indexFeature());
266:                 }
267:         }
268:
269:         @Test
270:         public void testBadEFeatureOnPathToIndexAttributeNoContainer() {
271:                 noContainer();
272:                 okTarget();
273:                 index.setDomainModelEFeature(ExamplePackage.eINSTANCE.getTarget_Name());
274:                 assertFalse(validate());
275:•                if (createChain) {
276:                         assertEquals(Diagnostic.ERROR, chain.getSeverity());
277:                         assertChain(indexFeature());
278:                 }
279:         }
280:
281:         @Test
282:         public void testBadIndex() {
283:                 okIndex();
284:                 okTarget();
285:                 index.setIndex(-1);
286:                 assertFalse(validate());
287:•                if (createChain) {
288:                         assertEquals(Diagnostic.ERROR, chain.getSeverity());
289:                         assertChain(controlDMR(), indexIndex());
290:                 }
291:         }
292:
293:         @Test
294:         public void testBadIndexNoContainer() {
295:                 noContainer();
296:                 okIndex();
297:                 okTarget();
298:                 index.setIndex(-1);
299:                 assertFalse(validate());
300:•                if (createChain) {
301:                         assertEquals(Diagnostic.ERROR, chain.getSeverity());
302:                         assertChain(indexIndex());
303:                 }
304:         }
305:
306:         @Test
307:         public void testOK() {
308:                 okIndex();
309:                 okTarget();
310:                 assertTrue(validate());
311:•                if (createChain) {
312:                         assertEquals(Diagnostic.OK, chain.getSeverity());
313:                         assertChain();
314:                 }
315:         }
316:
317:         @Test
318:         public void testOKNoContainer() {
319:                 noContainer();
320:                 okIndex();
321:                 okTarget();
322:                 assertTrue(validate());
323:•                if (createChain) {
324:                         assertEquals(Diagnostic.OK, chain.getSeverity());
325:                         assertChain();
326:                 }
327:         }
328:
329:         @Test
330:         public void testBadRootEClass() {
331:                 okIndex();
332:                 okTarget();
333:                 view.setRootEClass(ExamplePackage.eINSTANCE.getIntermediate());
334:                 assertFalse(validate());
335:•                if (createChain) {
336:                         assertEquals(Diagnostic.ERROR, chain.getSeverity());
337:                         assertChain(controlDMR(), indexPath());
338:                 }
339:         }
340:
341:         @Test
342:         public void testBadRootEClassGoodRootEClassInContext() {
343:                 okIndex();
344:                 okTarget();
345:                 view.setRootEClass(ExamplePackage.eINSTANCE.getIntermediate());
346:                 context.put(ViewValidator.ECLASS_KEY, ExamplePackage.eINSTANCE.getRoot());
347:                 assertTrue(validate());
348:•                if (createChain) {
349:                         assertEquals(Diagnostic.OK, chain.getSeverity());
350:                         assertChain();
351:                 }
352:         }
353:
354:         @Test
355:         public void testBadPathOnTarget() {
356:                 okIndex();
357:                 okTarget();
358:                 target.getDomainModelEReferencePath().remove(0);
359:                 assertFalse(validate());
360:•                if (createChain) {
361:                         assertEquals(Diagnostic.ERROR, chain.getSeverity());
362:                         assertChain(controlDMR(), indexTarget(), targetPath());
363:                 }
364:         }
365:
366:         @Test
367:         public void testBadPathOnTargetNoContainer() {
368:                 noContainer();
369:                 okIndex();
370:                 okTarget();
371:                 target.getDomainModelEReferencePath().remove(0);
372:                 assertFalse(validate());
373:•                if (createChain) {
374:                         assertEquals(Diagnostic.ERROR, chain.getSeverity());
375:                         assertChain(indexTarget(), targetPath());
376:                 }
377:         }
378:
379:         private void assertChain(DiagnosticInfo... infos) {
380:                 final Set<DiagnosticInfo> infoSet = new LinkedHashSet<DiagnosticInfo>(Arrays.asList(infos));
381:                 assertEquals(infos.length, chain.getChildren().size());
382:•                for (final Diagnostic child : chain.getChildren()) {
383:                         boolean found = false;
384:                         final Iterator<DiagnosticInfo> iterator = infoSet.iterator();
385:•                        while (iterator.hasNext()) {
386:                                 final DiagnosticInfo next = iterator.next();
387:•                                if (next.sameData(child)) {
388:                                         found = true;
389:                                         iterator.remove();
390:                                         break;
391:                                 }
392:                         }
393:•                        if (!found) {
394:                                 fail("Chain is missing child diagnostic."); //$NON-NLS-1$
395:                         }
396:                 }
397:         }
398:
399:         private class DiagnosticInfo {
400:                 private final int severity;
401:                 private final EObject object;
402:                 private final EStructuralFeature feature;
403:
404:                 DiagnosticInfo(int severity, EObject object, EStructuralFeature feature) {
405:                         this.severity = severity;
406:                         this.object = object;
407:                         this.feature = feature;
408:                 }
409:
410:                 public boolean sameData(Diagnostic diagnostic) {
411:                         if (diagnostic.getSeverity() != severity) {
412:                                 return false;
413:                         }
414:                         if (!object.equals(diagnostic.getData().get(0))) {
415:                                 return false;
416:                         }
417:                         if (!feature.equals(diagnostic.getData().get(1))) {
418:                                 return false;
419:                         }
420:                         return true;
421:                 }
422:
423:         }
424:
425: }