Skip to content

Package: KeyAttributeDMRValidation_Test

KeyAttributeDMRValidation_Test

nameinstructionbranchcomplexitylinemethod
KeyAttributeDMRValidation_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(KeyAttributeDMRValidation_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: 73
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 18
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%
keyAttributeFeature()
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%
keyAttributeKey()
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%
keyAttributeKeyValue()
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%
keyAttributePath()
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%
keyAttributeValue()
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%
keyFeature()
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%
okKey()
M: 0 C: 13
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
okKeyAttribute()
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%
okValue()
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%
testBadEFeatureOnPathToKeyAttributeAttribute()
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%
testBadEFeatureOnPathToKeyAttributeAttributeNoContainer()
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%
testBadEFeatureOnPathToKeyAttributeSingleRef()
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%
testBadEFeatureOnPathToKeyAttributeSingleRefNoContainer()
M: 0 C: 41
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 10
100%
M: 0 C: 1
100%
testBadKeyDMR()
M: 0 C: 45
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 9
100%
M: 0 C: 1
100%
testBadKeyDMRNoContainer()
M: 0 C: 42
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 10
100%
M: 0 C: 1
100%
testBadReferenceOnPathToKeyAttribute()
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%
testBadReferenceOnPathToKeyAttributeNoContainer()
M: 0 C: 48
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 11
100%
M: 0 C: 1
100%
testBadRootEClass()
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%
testBadRootEClassGoodRootEClassInContext()
M: 0 C: 36
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 10
100%
M: 0 C: 1
100%
testBadValueDMR()
M: 0 C: 45
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 9
100%
M: 0 C: 1
100%
testBadValueDMRNoContainer()
M: 0 C: 42
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 10
100%
M: 0 C: 1
100%
testNoEFeatureOnPathToKeyAttribute()
M: 0 C: 32
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
testNoEFeatureOnPathToKeyAttributeNoContainer()
M: 0 C: 29
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
testNoKeyDMR()
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%
testNoKeyDMRNoContainer()
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%
testNoKeyValue()
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%
testNoKeyValueNoContainer()
M: 0 C: 36
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 10
100%
M: 0 C: 1
100%
testNoValueDMR()
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%
testNoValueDMRNoContainer()
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%
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: 26
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%
valuePath()
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%

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.keyattributedmr.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.keyattribute.test.example.ExamplePackage;
36: import org.eclipse.emf.ecp.view.spi.keyattributedmr.model.VKeyAttributeDomainModelReference;
37: import org.eclipse.emf.ecp.view.spi.keyattributedmr.model.VKeyattributedmrFactory;
38: import org.eclipse.emf.ecp.view.spi.keyattributedmr.model.VKeyattributedmrPackage;
39: import org.eclipse.emf.ecp.view.spi.keyattributedmr.model.util.KeyattributedmrValidator;
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.Test;
48: import org.junit.runner.RunWith;
49: import org.junit.runners.Parameterized;
50: import org.junit.runners.Parameterized.Parameters;
51:
52: /**
53: * @author jfaltermeier
54: *
55: */
56: @RunWith(Parameterized.class)
57: public class KeyAttributeDMRValidation_Test {
58:
59:         private VView view;
60:         private VControl control;
61:         private VKeyAttributeDomainModelReference keyAttribute;
62:
63:         private EValidator validator;
64:         private BasicDiagnostic chain;
65:         private LinkedHashMap<Object, Object> context;
66:         private final Boolean createChain;
67:         private VFeaturePathDomainModelReference key;
68:         private VFeaturePathDomainModelReference value;
69:
70:         public KeyAttributeDMRValidation_Test(Boolean createChain) {
71:                 this.createChain = createChain;
72:         }
73:
74:         @Parameters
75:         public static Collection<Object[]> data() {
76:                 // run all tests once with a diagnostic chain and once without
77:                 final List<Object[]> parameters = new ArrayList<Object[]>();
78:                 parameters.add(new Object[] { true });
79:                 parameters.add(new Object[] { false });
80:                 return parameters;
81:         }
82:
83:         @Before
84:         public void before() {
85:                 view = VViewFactory.eINSTANCE.createView();
86:                 view.setRootEClass(ExamplePackage.eINSTANCE.getRoot());
87:                 control = VViewFactory.eINSTANCE.createControl();
88:                 view.getChildren().add(control);
89:                 keyAttribute = VKeyattributedmrFactory.eINSTANCE.createKeyAttributeDomainModelReference();
90:                 keyAttribute.setKeyValue("key"); //$NON-NLS-1$
91:                 key = VViewFactory.eINSTANCE.createFeaturePathDomainModelReference();
92:                 value = VViewFactory.eINSTANCE.createFeaturePathDomainModelReference();
93:                 keyAttribute.setKeyDMR(key);
94:                 keyAttribute.setValueDMR(value);
95:                 control.setDomainModelReference(keyAttribute);
96:
97:                 validator = KeyattributedmrValidator.INSTANCE;
98:                 context = new LinkedHashMap<Object, Object>();
99:•                if (createChain) {
100:                         chain = new BasicDiagnostic();
101:                 } else {
102:                         chain = null;
103:                 }
104:         }
105:
106:         private boolean validate() {
107:                 return validator.validate(keyAttribute, chain, context);
108:         }
109:
110:         private void noContainer() {
111:                 control.eUnset(VViewPackage.eINSTANCE.getControl_DomainModelReference());
112:         }
113:
114:         private void okKeyAttribute() {
115:                 keyAttribute.getDomainModelEReferencePath().add(ExamplePackage.eINSTANCE.getRoot_Intermediate());
116:                 keyAttribute.getDomainModelEReferencePath().add(ExamplePackage.eINSTANCE.getIntermediate_Container());
117:                 keyAttribute.setDomainModelEFeature(ExamplePackage.eINSTANCE.getContainer_Children());
118:         }
119:
120:         private void okKey() {
121:                 key.getDomainModelEReferencePath().add(ExamplePackage.eINSTANCE.getChild_Key());
122:                 key.setDomainModelEFeature(ExamplePackage.eINSTANCE.getKeyContainer_Key());
123:         }
124:
125:         private void okValue() {
126:                 value.getDomainModelEReferencePath().add(ExamplePackage.eINSTANCE.getChild_IntermediateTarget());
127:                 value.getDomainModelEReferencePath().add(ExamplePackage.eINSTANCE.getIntermediateTarget_Target());
128:                 value.setDomainModelEFeature(ExamplePackage.eINSTANCE.getTarget_Name());
129:         }
130:
131:         private DiagnosticInfo keyAttributeKey() {
132:                 return new DiagnosticInfo(Diagnostic.ERROR, keyAttribute,
133:                         VKeyattributedmrPackage.eINSTANCE.getKeyAttributeDomainModelReference_KeyDMR());
134:         }
135:
136:         private DiagnosticInfo controlDMR() {
137:                 return new DiagnosticInfo(Diagnostic.ERROR, control, VViewPackage.eINSTANCE.getControl_DomainModelReference());
138:         }
139:
140:         private DiagnosticInfo keyAttributeFeature() {
141:                 return new DiagnosticInfo(Diagnostic.ERROR, keyAttribute,
142:                         VViewPackage.eINSTANCE.getFeaturePathDomainModelReference_DomainModelEFeature());
143:         }
144:
145:         private DiagnosticInfo keyAttributePath() {
146:                 return new DiagnosticInfo(Diagnostic.ERROR, keyAttribute,
147:                         VViewPackage.eINSTANCE.getFeaturePathDomainModelReference_DomainModelEReferencePath());
148:         }
149:
150:         private DiagnosticInfo keyAttributeKeyValue() {
151:                 return new DiagnosticInfo(Diagnostic.ERROR, keyAttribute,
152:                         VKeyattributedmrPackage.eINSTANCE.getKeyAttributeDomainModelReference_KeyValue());
153:         }
154:
155:         private DiagnosticInfo keyAttributeValue() {
156:                 return new DiagnosticInfo(Diagnostic.ERROR, keyAttribute,
157:                         VKeyattributedmrPackage.eINSTANCE.getKeyAttributeDomainModelReference_ValueDMR());
158:         }
159:
160:         private DiagnosticInfo keyFeature() {
161:                 return new DiagnosticInfo(Diagnostic.ERROR, key,
162:                         VViewPackage.eINSTANCE.getFeaturePathDomainModelReference_DomainModelEFeature());
163:         }
164:
165:         private DiagnosticInfo valuePath() {
166:                 return new DiagnosticInfo(Diagnostic.ERROR, value,
167:                         VViewPackage.eINSTANCE.getFeaturePathDomainModelReference_DomainModelEReferencePath());
168:         }
169:
170:         @Test
171:         public void testNoKeyDMR() {
172:                 okKeyAttribute();
173:                 okValue();
174:                 keyAttribute.setKeyDMR(null);
175:                 assertFalse(validate());
176:•                if (createChain) {
177:                         assertEquals(Diagnostic.ERROR, chain.getSeverity());
178:                         assertChain(controlDMR(), keyAttributeKey());
179:                 }
180:         }
181:
182:         @Test
183:         public void testNoKeyDMRNoContainer() {
184:                 noContainer();
185:                 okKeyAttribute();
186:                 okValue();
187:                 keyAttribute.setKeyDMR(null);
188:                 assertFalse(validate());
189:•                if (createChain) {
190:                         assertEquals(Diagnostic.ERROR, chain.getSeverity());
191:                         assertChain(keyAttributeKey());
192:                 }
193:         }
194:
195:         @Test
196:         public void testNoValueDMR() {
197:                 okKeyAttribute();
198:                 okKey();
199:                 keyAttribute.setValueDMR(null);
200:                 assertFalse(validate());
201:•                if (createChain) {
202:                         assertEquals(Diagnostic.ERROR, chain.getSeverity());
203:                         assertChain(controlDMR(), keyAttributeValue());
204:                 }
205:         }
206:
207:         @Test
208:         public void testNoValueDMRNoContainer() {
209:                 noContainer();
210:                 okKeyAttribute();
211:                 okKey();
212:                 keyAttribute.setValueDMR(null);
213:                 assertFalse(validate());
214:•                if (createChain) {
215:                         assertEquals(Diagnostic.ERROR, chain.getSeverity());
216:                         assertChain(keyAttributeValue());
217:                 }
218:         }
219:
220:         @Test
221:         public void testNoEFeatureOnPathToKeyAttribute() {
222:                 okKey();
223:                 okValue();
224:                 assertFalse(validate());
225:•                if (createChain) {
226:                         assertEquals(Diagnostic.ERROR, chain.getSeverity());
227:                         assertChain(controlDMR(), keyAttributeFeature());
228:                 }
229:         }
230:
231:         @Test
232:         public void testNoEFeatureOnPathToKeyAttributeNoContainer() {
233:                 noContainer();
234:                 okKey();
235:                 okValue();
236:                 assertFalse(validate());
237:•                if (createChain) {
238:                         assertEquals(Diagnostic.ERROR, chain.getSeverity());
239:                         assertChain(keyAttributeFeature());
240:                 }
241:         }
242:
243:         @Test
244:         public void testBadReferenceOnPathToKeyAttribute() {
245:                 okKeyAttribute();
246:                 okKey();
247:                 okValue();
248:                 keyAttribute.getDomainModelEReferencePath().remove(0);
249:                 assertFalse(validate());
250:•                if (createChain) {
251:                         assertEquals(Diagnostic.ERROR, chain.getSeverity());
252:                         assertChain(controlDMR(), keyAttributePath());
253:                 }
254:         }
255:
256:         @Test
257:         public void testBadReferenceOnPathToKeyAttributeNoContainer() {
258:                 noContainer();
259:                 okKey();
260:                 okValue();
261:                 keyAttribute.getDomainModelEReferencePath().add(ExamplePackage.eINSTANCE.getRoot_Intermediate());
262:                 keyAttribute.getDomainModelEReferencePath().add(ExamplePackage.eINSTANCE.getRoot_Intermediate());
263:                 keyAttribute.setDomainModelEFeature(ExamplePackage.eINSTANCE.getContainer_Children());
264:                 assertFalse(validate());
265:•                if (createChain) {
266:                         assertEquals(Diagnostic.ERROR, chain.getSeverity());
267:                         assertChain(keyAttributePath());
268:                 }
269:         }
270:
271:         @Test
272:         public void testBadEFeatureOnPathToKeyAttributeSingleRef() {
273:                 okKey();
274:                 okValue();
275:                 keyAttribute.getDomainModelEReferencePath().add(ExamplePackage.eINSTANCE.getRoot_Intermediate());
276:                 keyAttribute.setDomainModelEFeature(ExamplePackage.eINSTANCE.getIntermediateTarget_Target());
277:                 assertFalse(validate());
278:•                if (createChain) {
279:                         assertEquals(Diagnostic.ERROR, chain.getSeverity());
280:                         assertChain(controlDMR(), keyAttributeFeature());
281:                 }
282:         }
283:
284:         @Test
285:         public void testBadEFeatureOnPathToKeyAttributeSingleRefNoContainer() {
286:                 noContainer();
287:                 okKey();
288:                 okValue();
289:                 keyAttribute.getDomainModelEReferencePath().add(ExamplePackage.eINSTANCE.getRoot_Intermediate());
290:                 keyAttribute.setDomainModelEFeature(ExamplePackage.eINSTANCE.getIntermediateTarget_Target());
291:                 assertFalse(validate());
292:•                if (createChain) {
293:                         assertEquals(Diagnostic.ERROR, chain.getSeverity());
294:                         assertChain(keyAttributeFeature());
295:                 }
296:         }
297:
298:         @Test
299:         public void testBadEFeatureOnPathToKeyAttributeAttribute() {
300:                 okKey();
301:                 okValue();
302:                 keyAttribute.setDomainModelEFeature(ExamplePackage.eINSTANCE.getTarget_Name());
303:                 assertFalse(validate());
304:•                if (createChain) {
305:                         assertEquals(Diagnostic.ERROR, chain.getSeverity());
306:                         assertChain(controlDMR(), keyAttributeFeature());
307:                 }
308:         }
309:
310:         @Test
311:         public void testBadEFeatureOnPathToKeyAttributeAttributeNoContainer() {
312:                 noContainer();
313:                 okKey();
314:                 okValue();
315:                 keyAttribute.setDomainModelEFeature(ExamplePackage.eINSTANCE.getTarget_Name());
316:                 assertFalse(validate());
317:•                if (createChain) {
318:                         assertEquals(Diagnostic.ERROR, chain.getSeverity());
319:                         assertChain(keyAttributeFeature());
320:                 }
321:         }
322:
323:         @Test
324:         public void testNoKeyValue() {
325:                 okKeyAttribute();
326:                 okValue();
327:                 okKey();
328:                 keyAttribute.eUnset(VKeyattributedmrPackage.eINSTANCE.getKeyAttributeDomainModelReference_KeyValue());
329:                 assertFalse(validate());
330:•                if (createChain) {
331:                         assertEquals(Diagnostic.ERROR, chain.getSeverity());
332:                         assertChain(controlDMR(), keyAttributeKeyValue());
333:                 }
334:         }
335:
336:         @Test
337:         public void testNoKeyValueNoContainer() {
338:                 noContainer();
339:                 okKeyAttribute();
340:                 okValue();
341:                 okKey();
342:                 keyAttribute.eUnset(VKeyattributedmrPackage.eINSTANCE.getKeyAttributeDomainModelReference_KeyValue());
343:                 assertFalse(validate());
344:•                if (createChain) {
345:                         assertEquals(Diagnostic.ERROR, chain.getSeverity());
346:                         assertChain(keyAttributeKeyValue());
347:                 }
348:         }
349:
350:         @Test
351:         public void testOK() {
352:                 okKey();
353:                 okKeyAttribute();
354:                 okValue();
355:                 assertTrue(validate());
356:•                if (createChain) {
357:                         assertEquals(Diagnostic.OK, chain.getSeverity());
358:                         assertChain();
359:                 }
360:         }
361:
362:         @Test
363:         public void testOKNoContainer() {
364:                 noContainer();
365:                 okKey();
366:                 okKeyAttribute();
367:                 okValue();
368:                 assertTrue(validate());
369:•                if (createChain) {
370:                         assertEquals(Diagnostic.OK, chain.getSeverity());
371:                         assertChain();
372:                 }
373:         }
374:
375:         @Test
376:         public void testBadRootEClass() {
377:                 okKey();
378:                 okKeyAttribute();
379:                 okValue();
380:                 view.setRootEClass(ExamplePackage.eINSTANCE.getIntermediate());
381:                 assertFalse(validate());
382:•                if (createChain) {
383:                         assertEquals(Diagnostic.ERROR, chain.getSeverity());
384:                         assertChain(controlDMR(), keyAttributePath());
385:                 }
386:         }
387:
388:         @Test
389:         public void testBadRootEClassGoodRootEClassInContext() {
390:                 okKey();
391:                 okKeyAttribute();
392:                 okValue();
393:                 view.setRootEClass(ExamplePackage.eINSTANCE.getIntermediate());
394:                 context.put(ViewValidator.ECLASS_KEY, ExamplePackage.eINSTANCE.getRoot());
395:                 assertTrue(validate());
396:•                if (createChain) {
397:                         assertEquals(Diagnostic.OK, chain.getSeverity());
398:                         assertChain();
399:                 }
400:         }
401:
402:         @Test
403:         public void testBadKeyDMR() {
404:                 okKeyAttribute();
405:                 okValue();
406:                 okKey();
407:                 key.getDomainModelEReferencePath().remove(0);
408:                 assertFalse(validate());
409:•                if (createChain) {
410:                         assertEquals(Diagnostic.ERROR, chain.getSeverity());
411:                         assertChain(controlDMR(), keyAttributeKey(), keyFeature());
412:                 }
413:         }
414:
415:         @Test
416:         public void testBadKeyDMRNoContainer() {
417:                 noContainer();
418:                 okKeyAttribute();
419:                 okValue();
420:                 okKey();
421:                 key.getDomainModelEReferencePath().remove(0);
422:                 assertFalse(validate());
423:•                if (createChain) {
424:                         assertEquals(Diagnostic.ERROR, chain.getSeverity());
425:                         assertChain(keyAttributeKey(), keyFeature());
426:                 }
427:         }
428:
429:         @Test
430:         public void testBadValueDMR() {
431:                 okKeyAttribute();
432:                 okValue();
433:                 okKey();
434:                 value.getDomainModelEReferencePath().remove(0);
435:                 assertFalse(validate());
436:•                if (createChain) {
437:                         assertEquals(Diagnostic.ERROR, chain.getSeverity());
438:                         assertChain(controlDMR(), keyAttributeValue(), valuePath());
439:                 }
440:         }
441:
442:         @Test
443:         public void testBadValueDMRNoContainer() {
444:                 noContainer();
445:                 okKeyAttribute();
446:                 okValue();
447:                 okKey();
448:                 value.getDomainModelEReferencePath().remove(0);
449:                 assertFalse(validate());
450:•                if (createChain) {
451:                         assertEquals(Diagnostic.ERROR, chain.getSeverity());
452:                         assertChain(keyAttributeValue(), valuePath());
453:                 }
454:         }
455:
456:         private void assertChain(DiagnosticInfo... infos) {
457:                 final Set<DiagnosticInfo> infoSet = new LinkedHashSet<DiagnosticInfo>(Arrays.asList(infos));
458:                 assertEquals(infos.length, chain.getChildren().size());
459:•                for (final Diagnostic child : chain.getChildren()) {
460:                         boolean found = false;
461:                         final Iterator<DiagnosticInfo> iterator = infoSet.iterator();
462:•                        while (iterator.hasNext()) {
463:                                 final DiagnosticInfo next = iterator.next();
464:•                                if (next.sameData(child)) {
465:                                         found = true;
466:                                         iterator.remove();
467:                                         break;
468:                                 }
469:                         }
470:•                        if (!found) {
471:                                 fail("Chain is missing child diagnostic."); //$NON-NLS-1$
472:                         }
473:                 }
474:         }
475:
476:         private class DiagnosticInfo {
477:                 private final int severity;
478:                 private final EObject object;
479:                 private final EStructuralFeature feature;
480:
481:                 DiagnosticInfo(int severity, EObject object, EStructuralFeature feature) {
482:                         this.severity = severity;
483:                         this.object = object;
484:                         this.feature = feature;
485:                 }
486:
487:                 public boolean sameData(Diagnostic diagnostic) {
488:                         if (diagnostic.getSeverity() != severity) {
489:                                 return false;
490:                         }
491:                         if (!object.equals(diagnostic.getData().get(0))) {
492:                                 return false;
493:                         }
494:                         if (!feature.equals(diagnostic.getData().get(1))) {
495:                                 return false;
496:                         }
497:                         return true;
498:                 }
499:
500:         }
501: }