Skip to content

Package: RuleService_PTest$2

RuleService_PTest$2

nameinstructionbranchcomplexitylinemethod
getDomainModel()
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
{...}
M: 0 C: 8
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-2017 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: * Edgar Mueller - additional test cases
14: * Edgar Mueller - more test cases
15: * Christian W. Damus - bug 527740
16: *******************************************************************************/
17: package org.eclipse.emf.ecp.view.rule.test;
18:
19: import static org.junit.Assert.assertEquals;
20: import static org.junit.Assert.assertFalse;
21: import static org.junit.Assert.assertTrue;
22:
23: import java.math.BigDecimal;
24: import java.util.ArrayList;
25: import java.util.Collections;
26: import java.util.LinkedHashMap;
27: import java.util.List;
28: import java.util.Map;
29: import java.util.Set;
30:
31: import org.eclipse.emf.common.util.Diagnostic;
32: import org.eclipse.emf.ecore.EAttribute;
33: import org.eclipse.emf.ecore.EObject;
34: import org.eclipse.emf.ecore.EReference;
35: import org.eclipse.emf.ecore.EStructuralFeature;
36: import org.eclipse.emf.ecore.EStructuralFeature.Setting;
37: import org.eclipse.emf.ecore.impl.BasicEObjectImpl;
38: import org.eclipse.emf.ecore.util.EcoreUtil;
39: import org.eclipse.emf.ecp.common.spi.UniqueSetting;
40: import org.eclipse.emf.ecp.test.common.DefaultRealm;
41: import org.eclipse.emf.ecp.test.university.Assistant;
42: import org.eclipse.emf.ecp.test.university.Person;
43: import org.eclipse.emf.ecp.test.university.Professor;
44: import org.eclipse.emf.ecp.test.university.Staff;
45: import org.eclipse.emf.ecp.test.university.UniversityFactory;
46: import org.eclipse.emf.ecp.test.university.UniversityPackage;
47: import org.eclipse.emf.ecp.test.university.impl.StaffImpl;
48: import org.eclipse.emf.ecp.view.internal.rule.RuleService;
49: import org.eclipse.emf.ecp.view.internal.rule.RuleServiceHelperImpl;
50: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
51: import org.eclipse.emf.ecp.view.spi.context.ViewModelContextDisposeListener;
52: import org.eclipse.emf.ecp.view.spi.context.ViewModelContextFactory;
53: import org.eclipse.emf.ecp.view.spi.context.ViewModelService;
54: import org.eclipse.emf.ecp.view.spi.context.ViewModelServiceProvider;
55: import org.eclipse.emf.ecp.view.spi.indexdmr.model.VIndexDomainModelReference;
56: import org.eclipse.emf.ecp.view.spi.indexdmr.model.VIndexdmrFactory;
57: import org.eclipse.emf.ecp.view.spi.model.ModelChangeListener;
58: import org.eclipse.emf.ecp.view.spi.model.VAttachment;
59: import org.eclipse.emf.ecp.view.spi.model.VControl;
60: import org.eclipse.emf.ecp.view.spi.model.VElement;
61: import org.eclipse.emf.ecp.view.spi.model.VFeaturePathDomainModelReference;
62: import org.eclipse.emf.ecp.view.spi.model.VView;
63: import org.eclipse.emf.ecp.view.spi.model.VViewFactory;
64: import org.eclipse.emf.ecp.view.spi.rule.RuleServiceHelper;
65: import org.eclipse.emf.ecp.view.spi.rule.model.AndCondition;
66: import org.eclipse.emf.ecp.view.spi.rule.model.LeafCondition;
67: import org.eclipse.emf.ecp.view.spi.rule.model.OrCondition;
68: import org.eclipse.emf.ecp.view.spi.rule.model.Rule;
69: import org.eclipse.emf.ecp.view.spi.rule.model.RuleFactory;
70: import org.eclipse.emf.ecp.view.spi.rule.model.ShowRule;
71: import org.eclipse.emf.ecp.view.spi.validation.ValidationProvider;
72: import org.eclipse.emf.ecp.view.spi.validation.ValidationService;
73: import org.eclipse.emf.ecp.view.spi.vertical.model.VVerticalFactory;
74: import org.eclipse.emf.ecp.view.spi.vertical.model.VVerticalLayout;
75: import org.eclipse.emf.emfstore.bowling.BowlingFactory;
76: import org.eclipse.emf.emfstore.bowling.BowlingPackage;
77: import org.eclipse.emf.emfstore.bowling.Fan;
78: import org.eclipse.emf.emfstore.bowling.Game;
79: import org.eclipse.emf.emfstore.bowling.League;
80: import org.eclipse.emf.emfstore.bowling.Merchandise;
81: import org.eclipse.emf.emfstore.bowling.Player;
82: import org.eclipse.emf.emfstore.bowling.impl.FanImpl;
83: import org.eclipse.emf.emfstore.bowling.impl.LeagueImpl;
84: import org.eclipse.emfforms.spi.core.services.view.EMFFormsContextListener;
85: import org.eclipse.emfforms.spi.core.services.view.RootDomainModelChangeListener;
86: import org.junit.After;
87: import org.junit.Before;
88: import org.junit.Ignore;
89: import org.junit.Test;
90:
91: /**
92: * Things to be tested.
93: *
94: * tests on control with rule:
95: * init wrong value , right value
96: * lifecycle wrong -> right; right -> wrong; wrong -> wrong; right -> right
97: * types: show, enable, hide, disable
98: * (2+4)*4
99: *
100: * propagation tests:
101: * - test propagation from parent to child (no rule) [combinations same as rule on control]
102: * - test propagation from parent to child (rule != parent.rule) [combinations same as rule on control]
103: *
104: *
105: * domain wrong
106: * parent (s: disabled r:enable)
107: * child1 (s:visible r:hidden) child2 (s:enabled r:disable)
108: *
109: * init
110: * parent (s: disabled r:enable)
111: * child1 (s:visible r:hidden) child2 (s:disabled r:disable)
112: *
113: * parent(s:enabled)
114: * child (s:hidden) child2(s:disabled)
115: *
116: *
117: * dispose
118: *
119: * getInvolvedObjects
120: * objects if no change -> none, empty list
121: * objects if change -> only container of rule
122: * no side effects
123: *
124: * @author Eugen Neufeld
125: * @author emueller
126: */
127: public class RuleService_PTest extends CommonRuleTest {
128:
129:         /**
130:          * @author Jonas
131:          *
132:          */
133:         private class ViewModelContextStub implements ViewModelContext {
134:
135:                 private boolean hasRegisteredViewListener;
136:                 private boolean hasRegisteredDomainListener;
137:
138:                 @Override
139:                 public void unregisterViewChangeListener(ModelChangeListener modelChangeListener) {
140:                         hasRegisteredViewListener = false;
141:                 }
142:
143:                 @Override
144:                 public void unregisterDomainChangeListener(ModelChangeListener modelChangeListener) {
145:                         hasRegisteredDomainListener = false;
146:                 }
147:
148:                 @Override
149:                 public void registerViewChangeListener(ModelChangeListener modelChangeListener) {
150:                         hasRegisteredViewListener = true;
151:                 }
152:
153:                 @Override
154:                 public void registerDomainChangeListener(ModelChangeListener modelChangeListener) {
155:                         hasRegisteredDomainListener = true;
156:                 }
157:
158:                 @Override
159:                 public VElement getViewModel() {
160:                         return view;
161:                 }
162:
163:                 @Override
164:                 public EObject getDomainModel() {
165:                         return null;
166:                 }
167:
168:                 @Override
169:                 public void dispose() {
170:
171:                 }
172:
173:                 @Override
174:                 public <T> boolean hasService(Class<T> serviceType) {
175:                         // not used in tests
176:                         return false;
177:                 }
178:
179:                 @Override
180:                 public <T> T getService(Class<T> serviceType) {
181:                         // not used in tests
182:                         return null;
183:                 }
184:
185:                 /**
186:                  * @deprecated
187:                  */
188:                 @Deprecated
189:                 @Override
190:                 public Set<VControl> getControlsFor(Setting setting) {
191:                         return null;
192:                 }
193:
194:                 /**
195:                  * @deprecated
196:                  */
197:                 @Deprecated
198:                 @Override
199:                 public Set<VElement> getControlsFor(UniqueSetting setting) {
200:                         return null;
201:                 }
202:
203:                 @Override
204:                 public Object getContextValue(String key) {
205:                         return null;
206:                 }
207:
208:                 @Override
209:                 public void putContextValue(String key, Object value) {
210:                 }
211:
212:                 @Deprecated
213:                 @Override
214:                 public ViewModelContext getChildContext(EObject eObject, VElement parent, VView vView,
215:                         ViewModelService... viewModelServices) {
216:                         return null;
217:                 }
218:
219:                 @Override
220:                 public ViewModelContext getChildContext(EObject eObject, VElement parent, VView vView,
221:                         ViewModelServiceProvider viewModelServiceProvider) {
222:                         return null;
223:                 }
224:
225:                 @Override
226:                 public void registerDisposeListener(ViewModelContextDisposeListener listener) {
227:                 }
228:
229:                 @Override
230:                 public void addContextUser(Object user) {
231:                 }
232:
233:                 @Override
234:                 public void removeContextUser(Object user) {
235:                 }
236:
237:                 @Override
238:                 public void registerEMFFormsContextListener(EMFFormsContextListener contextListener) {
239:                 }
240:
241:                 @Override
242:                 public void unregisterEMFFormsContextListener(EMFFormsContextListener contextListener) {
243:                         // do nothing
244:                 }
245:
246:                 @Override
247:                 public ViewModelContext getParentContext() {
248:                         return null;
249:                 }
250:
251:                 @Override
252:                 public void changeDomainModel(EObject newDomainModel) {
253:                         // do nothing
254:                 }
255:
256:                 @Override
257:                 public void registerRootDomainModelChangeListener(RootDomainModelChangeListener rootDomainModelChangeListener) {
258:                         // do nothing
259:                 }
260:
261:                 @Override
262:                 public void unregisterRootDomainModelChangeListener(
263:                         RootDomainModelChangeListener rootDomainModelChangeListener) {
264:                         // do nothing
265:                 }
266:
267:                 @Override
268:                 public VElement getParentVElement() {
269:                         return null;
270:                 }
271:
272:                 @Override
273:                 public void pause() {
274:                         // do nothing
275:                 }
276:
277:                 @Override
278:                 public void reactivate() {
279:                         // do nothing
280:                 }
281:
282:         }
283:
284:         /** The player. */
285:         private Player player;
286:
287:         /** The league. */
288:         private League league;
289:
290:         /** The view. */
291:         private VView view;
292:
293:         /** The control p name. */
294:         private VControl controlPName;
295:
296:         /** The column. */
297:         private VVerticalLayout column;
298:
299:         /** The parent column. */
300:         private VVerticalLayout parentColumn;
301:
302:         private ViewModelContext context;
303:
304:         private DefaultRealm realm;
305:
306:         /**
307:          * Sets the up.
308:          *
309:          * @throws Exception the exception
310:          */
311:         @Before
312:         public void setUp() throws Exception {
313:                 realm = new DefaultRealm();
314:                 player = BowlingFactory.eINSTANCE.createPlayer();
315:                 league = BowlingFactory.eINSTANCE.createLeague();
316:                 league.getPlayers().add(player);
317:
318:                 view = VViewFactory.eINSTANCE.createView();
319:                 view.setRootEClass(league.eClass());
320:
321:                 parentColumn = VVerticalFactory.eINSTANCE.createVerticalLayout();
322:                 view.getChildren().add(parentColumn);
323:
324:                 column = VVerticalFactory.eINSTANCE.createVerticalLayout();
325:                 parentColumn.getChildren().add(column);
326:
327:                 controlPName = VViewFactory.eINSTANCE.createControl();
328:
329:                 final VIndexDomainModelReference indexDMR = VIndexdmrFactory.eINSTANCE.createIndexDomainModelReference();
330:                 indexDMR.setIndex(0);
331:                 indexDMR.setDomainModelEFeature(BowlingPackage.eINSTANCE.getLeague_Players());
332:                 final VFeaturePathDomainModelReference domainModelReference = VViewFactory.eINSTANCE
333:                         .createFeaturePathDomainModelReference();
334:                 domainModelReference.setDomainModelEFeature(BowlingPackage.eINSTANCE.getPlayer_Name());
335:                 indexDMR.setTargetDMR(domainModelReference);
336:                 controlPName.setDomainModelReference(indexDMR);
337:
338:                 column.getChildren().add(controlPName);
339:
340:         }
341:
342:         /**
343:          * Tear down.
344:          *
345:          * @throws Exception the exception
346:          */
347:         @After
348:         public void tearDown() throws Exception {
349:                 if (context != null) {
350:                         context.dispose();
351:                 }
352:                 realm.dispose();
353:         }
354:
355:         private RuleService instantiateRuleService() {
356:                 return instantiateRuleService(league);
357:         }
358:
359:         /**
360:          * Instantiate rule service.
361:          *
362:          * @return the rule service
363:          */
364:         private RuleService instantiateRuleService(final EObject domainModel) {
365:                 final RuleService ruleService = new RuleService();
366:                 final RuleServiceHelperImpl ruleServiceHelper = new RuleServiceHelperImpl();
367:                 context = ViewModelContextFactory.INSTANCE.createViewModelContext(view, domainModel);
368:                 ruleService.instantiate(context);
369:                 ruleServiceHelper.instantiate(context);
370:                 return ruleService;
371:         }
372:
373:         /**
374:          * Sets the league to wrong.
375:          */
376:         private void setLeagueToWrong() {
377:                 league.setName("League_Wrong");
378:         }
379:
380:         /**
381:          * Sets the league to right.
382:          */
383:         private void setLeagueToRight() {
384:                 league.setName("League");
385:         }
386:
387:         private LeafCondition setupLeafConditionWithValueDMR(Object expectedValue, EReference domainRef,
388:                 List<EReference> domainPath, EAttribute valueAtt, List<EReference> valuePath) {
389:                 final LeafCondition leafCondition = RuleFactory.eINSTANCE.createLeafCondition();
390:                 leafCondition.setExpectedValue(expectedValue);
391:
392:                 final VFeaturePathDomainModelReference modelDMR = VViewFactory.eINSTANCE
393:                         .createFeaturePathDomainModelReference();
394:                 modelDMR.getDomainModelEReferencePath().addAll(domainPath);
395:                 modelDMR.setDomainModelEFeature(domainRef);
396:                 leafCondition.setDomainModelReference(modelDMR);
397:
398:                 final VFeaturePathDomainModelReference valueDMR = VViewFactory.eINSTANCE
399:                         .createFeaturePathDomainModelReference();
400:                 valueDMR.getDomainModelEReferencePath().addAll(valuePath);
401:                 valueDMR.setDomainModelEFeature(valueAtt);
402:                 leafCondition.setValueDomainModelReference(valueDMR);
403:
404:                 return leafCondition;
405:         }
406:
407:         private Setting getLeaguePlayersSetting() {
408:                 return ((LeagueImpl) league).eSetting(BowlingPackage.eINSTANCE.getLeague_Players());
409:         }
410:
411:         @Test
412:         @Ignore // Scenario is currently not supported
413:         public void testShowRuleWithConditionOnAttributeOfNonContainedObject() {
414:                 final Game game = BowlingFactory.eINSTANCE.createGame();
415:                 game.setPlayer(player);
416:                 game.getFrames().add(1);
417:
418:                 view = VViewFactory.eINSTANCE.createView();
419:                 view.setRootEClass(game.eClass());
420:
421:                 final VControl control1 = VViewFactory.eINSTANCE.createControl();
422:                 final VFeaturePathDomainModelReference domainModelReference = VViewFactory.eINSTANCE
423:                         .createFeaturePathDomainModelReference();
424:                 domainModelReference.setDomainModelEFeature(BowlingPackage.eINSTANCE.getGame_Frames());
425:
426:                 control1.setDomainModelReference(domainModelReference);
427:                 view.getChildren().add(control1);
428:
429:                 final ShowRule showRule = addShowRule(control1, false);
430:                 showRule.setCondition(createLeafCondition(BowlingPackage.eINSTANCE.getPlayer_Name(), "foo",
431:                         BowlingPackage.eINSTANCE.getGame_Player()));
432:
433:                 instantiateRuleService(game);
434:
435:                 player.setName("foo");
436:                 assertTrue(control1.isVisible());
437:                 player.setName("bar");
438:                 assertFalse(control1.isVisible());
439:         }
440:
441:         @Test
442:         public void testShowRuleWithConditionOnAttributeOfContainedObject() {
443:                 final Fan fan = BowlingFactory.eINSTANCE.createFan();
444:                 final Merchandise merchandise = BowlingFactory.eINSTANCE.createMerchandise();
445:                 fan.setFavouriteMerchandise(merchandise);
446:
447:                 view = VViewFactory.eINSTANCE.createView();
448:                 view.setRootEClass(fan.eClass());
449:
450:                 final VControl control1 = VViewFactory.eINSTANCE.createControl();
451:                 final VFeaturePathDomainModelReference domainModelReference = VViewFactory.eINSTANCE
452:                         .createFeaturePathDomainModelReference();
453:                 domainModelReference.setDomainModelEFeature(BowlingPackage.eINSTANCE.getFan_Gender());
454:                 control1.setDomainModelReference(domainModelReference);
455:                 view.getChildren().add(control1);
456:
457:                 final ShowRule showRule = addShowRule(control1, false);
458:                 showRule.setCondition(createLeafCondition(BowlingPackage.eINSTANCE.getMerchandise_Price(), new BigDecimal(5),
459:                         BowlingPackage.eINSTANCE.getFan_FavouriteMerchandise()));
460:
461:                 instantiateRuleService(fan);
462:                 merchandise.setPrice(new BigDecimal(5));
463:                 assertTrue(control1.isVisible());
464:                 merchandise.setPrice(new BigDecimal(55));
465:                 assertFalse(control1.isVisible());
466:         }
467:
468:         @Test
469:         public void testInitialization() {
470:                 final RuleService ruleService = new RuleService();
471:                 final ViewModelContextStub contextStub = new ViewModelContextStub() {
472:                         @Override
473:                         public EObject getDomainModel() {
474:                                 return view;
475:                         }
476:                 };
477:                 ruleService.instantiate(contextStub);
478:                 ruleService.contextInitialised();
479:                 assertTrue(contextStub.hasRegisteredViewListener);
480:                 assertTrue(contextStub.hasRegisteredDomainListener);
481:         }
482:
483:         @Test(expected = IllegalStateException.class)
484:         public void testInitializationWithNullDomainModel() {
485:                 final RuleService ruleService = new RuleService();
486:                 final ViewModelContextStub contextStub = new ViewModelContextStub();
487:                 ruleService.instantiate(contextStub);
488:                 ruleService.contextInitialised();
489:         }
490:
491:         @Test(expected = IllegalStateException.class)
492:         public void testInitializationWithNullViewModel() {
493:                 final RuleService ruleService = new RuleService();
494:                 final ViewModelContextStub contextStub = new ViewModelContextStub();
495:                 ruleService.instantiate(contextStub);
496:                 ruleService.contextInitialised();
497:         }
498:
499:         @Test
500:         public void testUnregisterOnViewModelContext() {
501:                 final RuleService ruleService = new RuleService();
502:                 final ViewModelContextStub contextStub = new ViewModelContextStub() {
503:                         @Override
504:                         public EObject getDomainModel() {
505:                                 return view;
506:                         }
507:                 };
508:                 ruleService.instantiate(contextStub);
509:                 ruleService.contextInitialised();
510:                 assertTrue(contextStub.hasRegisteredViewListener);
511:                 assertTrue(contextStub.hasRegisteredDomainListener);
512:                 ruleService.dispose();
513:                 assertFalse(contextStub.hasRegisteredViewListener);
514:                 assertFalse(contextStub.hasRegisteredDomainListener);
515:         }
516:
517:         /**
518:          * Test init right show rule.
519:          */
520:         @Test
521:         public void testInitRightShowRule() {
522:                 // if the expected value equals the model value, then the control should be visible
523:
524:                 addLeagueShowRule(controlPName, true);
525:                 setLeagueToRight();
526:                 instantiateRuleService();
527:                 assertTrue(controlPName.isVisible());
528:         }
529:
530:         /**
531:          * Test init wrong show rule.
532:          */
533:         @Test
534:         public void testInitWrongShowRule() {
535:                 // if the expected value equals the model value, then the control should be visible
536:
537:                 addLeagueShowRule(controlPName, true);
538:                 setLeagueToWrong();
539:                 instantiateRuleService();
540:                 assertFalse(controlPName.isVisible());
541:         }
542:
543:         /**
544:          * Test propagation show rule no child rule wrong init.
545:          */
546:         @Test
547:         public void testPropagationShowRuleNoChildRuleWrongInit() {
548:                 // if the expected value equals the model value, then the control should be visible
549:
550:                 addLeagueShowRule(column, true);
551:                 setLeagueToWrong();
552:                 instantiateRuleService();
553:                 assertFalse(controlPName.isVisible());
554:         }
555:
556:         /**
557:          * Test propagation show rule no child rule right init.
558:          */
559:         @Test
560:         public void testPropagationShowRuleNoChildRuleRightInit() {
561:                 // if the expected value equals the model value, then the control should be visible
562:
563:                 addLeagueShowRule(column, true);
564:                 setLeagueToRight();
565:                 instantiateRuleService();
566:                 assertTrue(controlPName.isVisible());
567:         }
568:
569:         /**
570:          * Test propagation show rule child rule wrong init.
571:          */
572:         @Test
573:         public void testPropagationShowRuleChildRuleWrongInit() {
574:                 // if the expected value equals the model value, then the control should be visible
575:
576:                 addLeagueShowRule(column, true);
577:                 addLeagueShowRule(controlPName, false);
578:                 setLeagueToWrong();
579:                 instantiateRuleService();
580:                 assertFalse(controlPName.isVisible());
581:         }
582:
583:         /**
584:          * Test propagation show rule child rule right init.
585:          */
586:         @Test
587:         public void testPropagationShowRuleChildRuleRightInit() {
588:                 // if the expected value equals the model value, then the control should be visible
589:
590:                 addLeagueShowRule(column, true);
591:                 addLeagueShowRule(controlPName, false);
592:                 setLeagueToRight();
593:                 instantiateRuleService();
594:                 assertFalse(controlPName.isVisible());
595:         }
596:
597:         /**
598:          * Test {@link org.eclipse.emf.ecp.view.spi.rule.model.OrCondition OrCondition} with first condition being true.
599:          * Controls should be visible.
600:          */
601:         @Test
602:         public void testShowRuleWithOrConditionFirstConditionApplies() {
603:                 addLeagueShowRuleWithOrCondition(column, true,
604:                         createLeafCondition(BowlingPackage.eINSTANCE.getLeague_Name(), "League"),
605:                         createLeafCondition(BowlingPackage.eINSTANCE.getLeague_Name(), "League2"));
606:                 instantiateRuleService();
607:                 setLeagueToRight();
608:                 assertTrue(column.isVisible());
609:                 assertTrue(controlPName.isVisible());
610:         }
611:
612:         /**
613:          * Test {@link org.eclipse.emf.ecp.view.spi.rule.model.OrCondition OrCondition} with first condition being true
614:          * while
615:          * initializing the rule service.
616:          * Controls should be visible.
617:          */
618:         @Test
619:         public void testInitShowRuleWithOrConditionFirstConditionApplies() {
620:                 addLeagueShowRuleWithOrCondition(column, true,
621:                         createLeafCondition(BowlingPackage.eINSTANCE.getLeague_Name(), "League"),
622:                         createLeafCondition(BowlingPackage.eINSTANCE.getLeague_Name(), "League2"));
623:                 setLeagueToRight();
624:                 instantiateRuleService();
625:                 assertTrue(column.isVisible());
626:                 assertTrue(controlPName.isVisible());
627:         }
628:
629:         /**
630:          * Test {@link org.eclipse.emf.ecp.view.spi.rule.model.OrCondition OrCondition} with second condition being true
631:          * while
632:          * initializing the rule service.
633:          * Controls should be visible.
634:          */
635:         @Test
636:         public void testInitShowRuleWithOrConditionSecondConditionApplies() {
637:                 addLeagueShowRuleWithOrCondition(column, true,
638:                         createLeafCondition(BowlingPackage.eINSTANCE.getLeague_Name(), "League"),
639:                         createLeafCondition(BowlingPackage.eINSTANCE.getLeague_Name(), "League2"));
640:                 league.setName("League2");
641:                 instantiateRuleService();
642:                 assertTrue(column.isVisible());
643:                 assertTrue(controlPName.isVisible());
644:         }
645:
646:         /**
647:          * Test {@link org.eclipse.emf.ecp.view.spi.rule.model.OrCondition OrCondition} with both conditions being true
648:          * while
649:          * initializing the rule service.
650:          * Controls should be visible.
651:          */
652:         @Test
653:         public void testInitShowRuleWithOrConditionBothConditionsApply() {
654:                 view = VViewFactory.eINSTANCE.createView();
655:                 view.setRootEClass(player.eClass());
656:
657:                 final VControl control1 = VViewFactory.eINSTANCE.createControl();
658:
659:                 final VFeaturePathDomainModelReference domainModelReference = VViewFactory.eINSTANCE
660:                         .createFeaturePathDomainModelReference();
661:                 domainModelReference.setDomainModelEFeature(BowlingPackage.eINSTANCE.getPlayer_Height());
662:                 control1.setDomainModelReference(domainModelReference);
663:
664:                 view.getChildren().add(control1);
665:
666:                 addLeagueShowRuleWithOrCondition(control1, true,
667:                         createLeafCondition(BowlingPackage.eINSTANCE.getPlayer_Name(), "foo"),
668:                         createLeafCondition(BowlingPackage.eINSTANCE.getPlayer_NumberOfVictories(), 3));
669:                 player.setName("foo");
670:                 player.setNumberOfVictories(3);
671:                 instantiateRuleService(player);
672:                 assertTrue(view.isVisible());
673:                 assertTrue(control1.isVisible());
674:         }
675:
676:         /**
677:          * Test {@link org.eclipse.emf.ecp.view.spi.rule.model.OrCondition OrCondition} with both conditions being true.
678:          * Controls should be visible.
679:          */
680:         @Test
681:         public void testShowRuleWithOrConditionBothConditionsApply() {
682:                 view = VViewFactory.eINSTANCE.createView();
683:                 view.setRootEClass(player.eClass());
684:
685:                 final VControl control1 = VViewFactory.eINSTANCE.createControl();
686:                 final VFeaturePathDomainModelReference domainModelReference = VViewFactory.eINSTANCE
687:                         .createFeaturePathDomainModelReference();
688:                 domainModelReference.setDomainModelEFeature(BowlingPackage.eINSTANCE.getPlayer_Height());
689:                 control1.setDomainModelReference(domainModelReference);
690:                 view.getChildren().add(control1);
691:
692:                 addLeagueShowRuleWithOrCondition(control1, true,
693:                         createLeafCondition(BowlingPackage.eINSTANCE.getPlayer_Name(), "foo"),
694:                         createLeafCondition(BowlingPackage.eINSTANCE.getPlayer_NumberOfVictories(), 3));
695:                 instantiateRuleService(player);
696:                 player.setName("foo");
697:                 player.setNumberOfVictories(3);
698:                 assertTrue(column.isVisible());
699:                 assertTrue(control1.isVisible());
700:         }
701:
702:         /**
703:          * Test {@link org.eclipse.emf.ecp.view.spi.rule.model.OrCondition OrCondition} with none of the conditions being
704:          * true.
705:          * Controls should not be visible.
706:          */
707:         @Test
708:         public void testInitShowRuleWithOrConditionNoConditionApplies() {
709:                 addLeagueShowRuleWithOrCondition(column, true,
710:                         createLeafCondition(BowlingPackage.eINSTANCE.getLeague_Name(), "League"),
711:                         createLeafCondition(BowlingPackage.eINSTANCE.getLeague_Name(), "League2"));
712:                 setLeagueToWrong();
713:                 instantiateRuleService();
714:                 assertFalse(column.isVisible());
715:                 assertFalse(controlPName.isVisible());
716:         }
717:
718:         /**
719:          * Test {@link org.eclipse.emf.ecp.view.spi.rule.model.AndCondition AndCondition} with first condition being true.
720:          * Controls should not be visible.
721:          */
722:         @Test
723:         public void testShowRuleWithAndConditionFirstConditionApplies() {
724:                 addLeagueShowRuleWithAndCondition(column, true,
725:                         createLeafCondition(BowlingPackage.eINSTANCE.getLeague_Name(), "League"),
726:                         createLeafCondition(BowlingPackage.eINSTANCE.getLeague_Name(), "League2"));
727:                 instantiateRuleService();
728:                 setLeagueToRight();
729:                 assertFalse(column.isVisible());
730:                 assertFalse(controlPName.isVisible());
731:         }
732:
733:         /**
734:          * Test {@link org.eclipse.emf.ecp.view.spi.rule.model.AndCondition AndCondition} with second condition being
735:          * true.
736:          * Controls should not be visible.
737:          */
738:         @Test
739:         public void testShowRuleWithAndConditionSecondConditionApplies() {
740:                 addLeagueShowRuleWithAndCondition(column, true,
741:                         createLeafCondition(BowlingPackage.eINSTANCE.getLeague_Name(), "League"),
742:                         createLeafCondition(BowlingPackage.eINSTANCE.getLeague_Name(), "League2"));
743:                 instantiateRuleService();
744:                 league.setName("League2");
745:                 assertFalse(column.isVisible());
746:                 assertFalse(controlPName.isVisible());
747:         }
748:
749:         /**
750:          * Test {@link org.eclipse.emf.ecp.view.spi.rule.model.AndCondition AndCondition} with none of the conditions
751:          * being
752:          * true.
753:          * Controls should not be visible.
754:          */
755:         @Test
756:         public void testShowRuleWithAndConditionNoConditionApplies() {
757:                 addLeagueShowRuleWithAndCondition(column, true,
758:                         createLeafCondition(BowlingPackage.eINSTANCE.getLeague_Name(), "League"),
759:                         createLeafCondition(BowlingPackage.eINSTANCE.getLeague_Name(), "League2"));
760:                 instantiateRuleService();
761:                 setLeagueToWrong();
762:                 assertFalse(column.isVisible());
763:                 assertFalse(controlPName.isVisible());
764:         }
765:
766:         /**
767:          * Test {@link org.eclipse.emf.ecp.view.spi.rule.model.AndCondition AndCondition} with both conditions being true.
768:          * Controls should be visible.
769:          */
770:         @Test
771:         public void testShowRuleWithAndConditionBothConditionsApply() {
772:
773:                 final VControl control1 = VViewFactory.eINSTANCE.createControl();
774:                 final VIndexDomainModelReference indexDMR = VIndexdmrFactory.eINSTANCE.createIndexDomainModelReference();
775:                 indexDMR.setDomainModelEFeature(BowlingPackage.eINSTANCE.getLeague_Players());
776:                 indexDMR.setIndex(0);
777:                 final VFeaturePathDomainModelReference domainModelReference = VViewFactory.eINSTANCE
778:                         .createFeaturePathDomainModelReference();
779:                 domainModelReference.setDomainModelEFeature(BowlingPackage.eINSTANCE.getPlayer_Height());
780:                 indexDMR.setTargetDMR(domainModelReference);
781:                 control1.setDomainModelReference(indexDMR);
782:                 column.getChildren().add(control1);
783:
784:                 addLeagueShowRuleWithAndCondition(
785:                         column,
786:                         true,
787:                         setupLeafConditionWithValueDMR("foo",
788:                                 BowlingPackage.eINSTANCE.getLeague_Players(), Collections.<EReference> emptyList(),
789:                                 BowlingPackage.eINSTANCE.getPlayer_Name(), Collections.<EReference> emptyList()),
790:                         setupLeafConditionWithValueDMR(3,
791:                                 BowlingPackage.eINSTANCE.getLeague_Players(), Collections.<EReference> emptyList(),
792:                                 BowlingPackage.eINSTANCE.getPlayer_NumberOfVictories(), Collections.<EReference> emptyList()));
793:                 instantiateRuleService(league);
794:                 player.setName("foo");
795:                 player.setNumberOfVictories(3);
796:                 assertTrue(column.isVisible());
797:                 assertTrue(control1.isVisible());
798:         }
799:
800:         /**
801:          * Test {@link org.eclipse.emf.ecp.view.spi.rule.model.AndCondition AndCondition} with first condition being true
802:          * while
803:          * initializing the rule service.
804:          * Controls should not be visible.
805:          */
806:         @Test
807:         public void testInitShowRuleInitWithAndConditionFirstConditionApplies() {
808:                 addLeagueShowRuleWithAndCondition(column, true,
809:                         createLeafCondition(BowlingPackage.eINSTANCE.getLeague_Name(), "League"),
810:                         createLeafCondition(BowlingPackage.eINSTANCE.getLeague_Name(), "League2"));
811:                 setLeagueToRight();
812:                 instantiateRuleService();
813:                 assertFalse(column.isVisible());
814:                 assertFalse(controlPName.isVisible());
815:         }
816:
817:         /**
818:          * Test {@link org.eclipse.emf.ecp.view.spi.rule.model.AndCondition AndCondition} with second condition being true
819:          * while
820:          * initializing the rule service.
821:          * Controls should not be visible.
822:          */
823:         @Test
824:         public void testInitShowRuleWithAndConditionSecondConditionApplies() {
825:                 addLeagueShowRuleWithAndCondition(column, true,
826:                         createLeafCondition(BowlingPackage.eINSTANCE.getLeague_Name(), "League"),
827:                         createLeafCondition(BowlingPackage.eINSTANCE.getLeague_Name(), "League2"));
828:                 league.setName("League2");
829:                 instantiateRuleService();
830:                 assertFalse(column.isVisible());
831:                 assertFalse(controlPName.isVisible());
832:         }
833:
834:         /**
835:          * Test {@link org.eclipse.emf.ecp.view.spi.rule.model.AndCondition AndCondition} with none of the conditions
836:          * being
837:          * true
838:          * while initializing the rule service.
839:          * Controls should not be visible.
840:          */
841:         @Test
842:         public void testInitShowRuleWithAndConditionNoConditionApplies() {
843:                 addLeagueShowRuleWithAndCondition(column, true,
844:                         createLeafCondition(BowlingPackage.eINSTANCE.getLeague_Name(), "League"),
845:                         createLeafCondition(BowlingPackage.eINSTANCE.getLeague_Name(), "League2"));
846:                 setLeagueToWrong();
847:                 instantiateRuleService();
848:                 assertFalse(column.isVisible());
849:                 assertFalse(controlPName.isVisible());
850:         }
851:
852:         @Test
853:         public void testShowRuleWithTwoPossibleTargetsWhereOnlyOneSettingShouldApply() {
854:                 view = VViewFactory.eINSTANCE.createView();
855:                 view.setRootEClass(player.eClass());
856:
857:                 final VControl control1 = VViewFactory.eINSTANCE.createControl();
858:                 final VFeaturePathDomainModelReference domainModelReference = VViewFactory.eINSTANCE
859:                         .createFeaturePathDomainModelReference();
860:                 domainModelReference.setDomainModelEFeature(BowlingPackage.eINSTANCE.getPlayer_Height());
861:                 control1.setDomainModelReference(domainModelReference);
862:                 view.getChildren().add(control1);
863:
864:                 final VControl control2 = VViewFactory.eINSTANCE.createControl();
865:
866:                 final VFeaturePathDomainModelReference domainModelReference2 = VViewFactory.eINSTANCE
867:                         .createFeaturePathDomainModelReference();
868:                 domainModelReference2.setDomainModelEFeature(BowlingPackage.eINSTANCE.getPlayer_Height());
869:                 control2.setDomainModelReference(domainModelReference2);
870:
871:                 view.getChildren().add(control2);
872:
873:                 addShowRule(control1, true, BowlingPackage.eINSTANCE.getPlayer_Name(), "foo");
874:                 addShowRule(control2, true, BowlingPackage.eINSTANCE.getPlayer_NumberOfVictories(), 3);
875:
876:                 instantiateRuleService(player);
877:                 player.setName("foo");
878:                 assertTrue(control1.isVisible());
879:                 assertFalse(control2.isVisible());
880:         }
881:
882:         @Test
883:         public void testShowRuleWithTwoPossibleTargetsWhereTheOtherSettingShouldApply() {
884:                 view = VViewFactory.eINSTANCE.createView();
885:                 view.setRootEClass(player.eClass());
886:
887:                 final VControl control1 = VViewFactory.eINSTANCE.createControl();
888:
889:                 final VFeaturePathDomainModelReference domainModelReference = VViewFactory.eINSTANCE
890:                         .createFeaturePathDomainModelReference();
891:                 domainModelReference.setDomainModelEFeature(BowlingPackage.eINSTANCE.getPlayer_Height());
892:                 control1.setDomainModelReference(domainModelReference);
893:
894:                 view.getChildren().add(control1);
895:
896:                 final VControl control2 = VViewFactory.eINSTANCE.createControl();
897:
898:                 final VFeaturePathDomainModelReference domainModelReference2 = VViewFactory.eINSTANCE
899:                         .createFeaturePathDomainModelReference();
900:                 domainModelReference2.setDomainModelEFeature(BowlingPackage.eINSTANCE.getPlayer_Height());
901:                 control2.setDomainModelReference(domainModelReference2);
902:
903:                 view.getChildren().add(control2);
904:
905:                 addShowRule(control1, true, BowlingPackage.eINSTANCE.getPlayer_Name(), "foo");
906:                 addShowRule(control2, true, BowlingPackage.eINSTANCE.getPlayer_NumberOfVictories(), 3);
907:
908:                 instantiateRuleService(player);
909:                 player.setNumberOfVictories(3);
910:                 assertFalse(control1.isVisible());
911:                 assertTrue(control2.isVisible());
912:         }
913:
914:         @Test
915:         public void testShowRuleWhereConditionReferencesAnotherTarget() {
916:                 final Fan fan = BowlingFactory.eINSTANCE.createFan();
917:                 final Merchandise merchandise = BowlingFactory.eINSTANCE.createMerchandise();
918:                 view = VViewFactory.eINSTANCE.createView();
919:                 view.setRootEClass(fan.eClass());
920:                 fan.setFavouriteMerchandise(merchandise);
921:
922:                 final VControl control1 = VViewFactory.eINSTANCE.createControl();
923:
924:                 final VFeaturePathDomainModelReference domainModelReference = VViewFactory.eINSTANCE
925:                         .createFeaturePathDomainModelReference();
926:                 domainModelReference.setDomainModelEFeature(BowlingPackage.eINSTANCE.getMerchandise_Name());
927:                 domainModelReference.getDomainModelEReferencePath().add(BowlingPackage.eINSTANCE.getFan_FavouriteMerchandise());
928:                 control1.setDomainModelReference(domainModelReference);
929:
930:                 view.getChildren().add(control1);
931:
932:                 addShowRule(control1, true, BowlingPackage.eINSTANCE.getMerchandise_Name(), "foo");
933:
934:                 Rule rule = null;
935:                 for (final VAttachment attachment : control1.getAttachments()) {
936:                         if (Rule.class.isInstance(attachment)) {
937:                                 rule = (Rule) attachment;
938:                         }
939:                 }
940:
941:                 ((VFeaturePathDomainModelReference) ((LeafCondition) rule.getCondition()).getDomainModelReference())
942:                         .getDomainModelEReferencePath().add(
943:                                 BowlingPackage.eINSTANCE.getFan_FavouriteMerchandise());
944:
945:                 instantiateRuleService(fan);
946:                 merchandise.setName("foo");
947:                 assertTrue(control1.isVisible());
948:                 merchandise.setName("bar");
949:                 assertFalse(control1.isVisible());
950:         }
951:
952:         @Test
953:         public void testShowRuleWithTwoPossibleTargetsWhereBothSettingShouldApply() {
954:                 view = VViewFactory.eINSTANCE.createView();
955:                 view.setRootEClass(player.eClass());
956:
957:                 final VControl control1 = VViewFactory.eINSTANCE.createControl();
958:
959:                 final VFeaturePathDomainModelReference domainModelReference = VViewFactory.eINSTANCE
960:                         .createFeaturePathDomainModelReference();
961:                 domainModelReference.setDomainModelEFeature(BowlingPackage.eINSTANCE.getPlayer_Height());
962:                 control1.setDomainModelReference(domainModelReference);
963:
964:                 view.getChildren().add(control1);
965:
966:                 final VControl control2 = VViewFactory.eINSTANCE.createControl();
967:
968:                 final VFeaturePathDomainModelReference domainModelReference2 = VViewFactory.eINSTANCE
969:                         .createFeaturePathDomainModelReference();
970:                 domainModelReference2.setDomainModelEFeature(BowlingPackage.eINSTANCE.getPlayer_Height());
971:                 control2.setDomainModelReference(domainModelReference2);
972:
973:                 view.getChildren().add(control2);
974:
975:                 addShowRule(control1, true, BowlingPackage.eINSTANCE.getPlayer_Name(), "foo");
976:                 addShowRule(control2, true, BowlingPackage.eINSTANCE.getPlayer_NumberOfVictories(), 3);
977:
978:                 instantiateRuleService(player);
979:                 player.setName("foo");
980:                 player.setNumberOfVictories(3);
981:                 assertTrue(control1.isVisible());
982:                 assertTrue(control2.isVisible());
983:         }
984:
985:         @Test
986:         public void testInitShowRuleWithTwoPossibleTargetsWhereOnlyOneSettingShouldApply() {
987:                 view = VViewFactory.eINSTANCE.createView();
988:                 view.setRootEClass(player.eClass());
989:
990:                 final VControl control1 = VViewFactory.eINSTANCE.createControl();
991:                 final VFeaturePathDomainModelReference domainModelReference = VViewFactory.eINSTANCE
992:                         .createFeaturePathDomainModelReference();
993:                 domainModelReference.setDomainModelEFeature(BowlingPackage.eINSTANCE.getPlayer_Height());
994:                 control1.setDomainModelReference(domainModelReference);
995:                 view.getChildren().add(control1);
996:
997:                 final VControl control2 = VViewFactory.eINSTANCE.createControl();
998:                 final VFeaturePathDomainModelReference domainModelReference2 = VViewFactory.eINSTANCE
999:                         .createFeaturePathDomainModelReference();
1000:                 domainModelReference2.setDomainModelEFeature(BowlingPackage.eINSTANCE.getPlayer_Height());
1001:                 control2.setDomainModelReference(domainModelReference2);
1002:                 view.getChildren().add(control2);
1003:
1004:                 addShowRule(control1, true, BowlingPackage.eINSTANCE.getPlayer_Name(), "foo");
1005:                 addShowRule(control2, true, BowlingPackage.eINSTANCE.getPlayer_NumberOfVictories(), 3);
1006:
1007:                 player.setName("foo");
1008:                 instantiateRuleService(player);
1009:                 assertTrue(control1.isVisible());
1010:                 assertFalse(control2.isVisible());
1011:         }
1012:
1013:         @Test
1014:         public void testInitShowRuleWithTwoPossibleTargetsWhereTheOtherSettingShouldApply() {
1015:                 view = VViewFactory.eINSTANCE.createView();
1016:                 view.setRootEClass(player.eClass());
1017:
1018:                 final VControl control1 = VViewFactory.eINSTANCE.createControl();
1019:                 final VFeaturePathDomainModelReference domainModelReference = VViewFactory.eINSTANCE
1020:                         .createFeaturePathDomainModelReference();
1021:                 domainModelReference.setDomainModelEFeature(BowlingPackage.eINSTANCE.getPlayer_Height());
1022:                 control1.setDomainModelReference(domainModelReference);
1023:                 view.getChildren().add(control1);
1024:
1025:                 final VControl control2 = VViewFactory.eINSTANCE.createControl();
1026:                 final VFeaturePathDomainModelReference domainModelReference2 = VViewFactory.eINSTANCE
1027:                         .createFeaturePathDomainModelReference();
1028:                 domainModelReference2.setDomainModelEFeature(BowlingPackage.eINSTANCE.getPlayer_Height());
1029:                 control2.setDomainModelReference(domainModelReference2);
1030:                 view.getChildren().add(control2);
1031:
1032:                 addShowRule(control1, true, BowlingPackage.eINSTANCE.getPlayer_Name(), "foo");
1033:                 addShowRule(control2, true, BowlingPackage.eINSTANCE.getPlayer_NumberOfVictories(), 3);
1034:
1035:                 player.setNumberOfVictories(3);
1036:                 instantiateRuleService(player);
1037:                 assertFalse(control1.isVisible());
1038:                 assertTrue(control2.isVisible());
1039:         }
1040:
1041:         @Test
1042:         public void testInitShowRuleWithTwoPossibleTargetsWhereBothSettingShouldApply() {
1043:                 view = VViewFactory.eINSTANCE.createView();
1044:                 view.setRootEClass(player.eClass());
1045:
1046:                 final VControl control1 = VViewFactory.eINSTANCE.createControl();
1047:                 final VFeaturePathDomainModelReference domainModelReference = VViewFactory.eINSTANCE
1048:                         .createFeaturePathDomainModelReference();
1049:                 domainModelReference.setDomainModelEFeature(BowlingPackage.eINSTANCE.getPlayer_Height());
1050:                 control1.setDomainModelReference(domainModelReference);
1051:                 view.getChildren().add(control1);
1052:
1053:                 final VControl control2 = VViewFactory.eINSTANCE.createControl();
1054:                 final VFeaturePathDomainModelReference domainModelReference2 = VViewFactory.eINSTANCE
1055:                         .createFeaturePathDomainModelReference();
1056:                 domainModelReference2.setDomainModelEFeature(BowlingPackage.eINSTANCE.getPlayer_Height());
1057:                 control2.setDomainModelReference(domainModelReference2);
1058:                 view.getChildren().add(control2);
1059:
1060:                 addShowRule(control1, true, BowlingPackage.eINSTANCE.getPlayer_Name(), "foo");
1061:                 addShowRule(control2, true, BowlingPackage.eINSTANCE.getPlayer_NumberOfVictories(), 3);
1062:
1063:                 player.setName("foo");
1064:                 player.setNumberOfVictories(3);
1065:                 instantiateRuleService(player);
1066:                 assertTrue(control1.isVisible());
1067:                 assertTrue(control2.isVisible());
1068:         }
1069:
1070:         /**
1071:          * Test default wrong to right show rule.
1072:          */
1073:         @Test
1074:         public void testDefaultWrongToRightShowRule() {
1075:                 // if the expected value equals the model value, then the control should be visible
1076:
1077:                 addLeagueShowRule(controlPName, true);
1078:                 setLeagueToWrong();
1079:                 instantiateRuleService();
1080:                 setLeagueToRight();
1081:                 assertTrue(controlPName.isVisible());
1082:         }
1083:
1084:         /**
1085:          * Test default wrong to wrong show rule.
1086:          */
1087:         @Test
1088:         public void testDefaultWrongToWrongShowRule() {
1089:                 // if the expected value equals the model value, then the control should be visible
1090:
1091:                 addLeagueShowRule(controlPName, true);
1092:                 setLeagueToWrong();
1093:                 instantiateRuleService();
1094:                 setLeagueToWrong();
1095:                 assertFalse(controlPName.isVisible());
1096:         }
1097:
1098:         /**
1099:          * Test default right to wrong show rule.
1100:          */
1101:         @Test
1102:         public void testDefaultRightToWrongShowRule() {
1103:                 // if the expected value equals the model value, then the control should be visible
1104:
1105:                 addLeagueShowRule(controlPName, true);
1106:                 setLeagueToRight();
1107:                 instantiateRuleService();
1108:                 setLeagueToWrong();
1109:                 assertFalse(controlPName.isVisible());
1110:         }
1111:
1112:         /**
1113:          * Test default right to right show rule.
1114:          */
1115:         @Test
1116:         public void testDefaultRightToRightShowRule() {
1117:                 // if the expected value equals the model value, then the control should be visible
1118:
1119:                 addLeagueShowRule(controlPName, true);
1120:                 setLeagueToRight();
1121:                 instantiateRuleService();
1122:                 setLeagueToRight();
1123:                 assertTrue(controlPName.isVisible());
1124:         }
1125:
1126:         /**
1127:          * Test propagation show rule no child rule wrong to right.
1128:          */
1129:         @Test
1130:         public void testPropagationShowRuleNoChildRuleWrongToRight() {
1131:                 // if the expected value equals the model value, then the control should be visible
1132:
1133:                 addLeagueShowRule(column, true);
1134:                 setLeagueToWrong();
1135:                 instantiateRuleService();
1136:                 setLeagueToRight();
1137:                 assertTrue(controlPName.isVisible());
1138:         }
1139:
1140:         /**
1141:          * Test propagation show rule no child rule wrong to wrong.
1142:          */
1143:         @Test
1144:         public void testPropagationShowRuleNoChildRuleWrongToWrong() {
1145:                 // if the expected value equals the model value, then the control should be visible
1146:
1147:                 addLeagueShowRule(column, true);
1148:                 setLeagueToWrong();
1149:                 instantiateRuleService();
1150:                 setLeagueToWrong();
1151:                 assertFalse(controlPName.isVisible());
1152:         }
1153:
1154:         /**
1155:          * Test propagation show rule no child rule right to wrong.
1156:          */
1157:         @Test
1158:         public void testPropagationShowRuleNoChildRuleRightToWrong() {
1159:                 // if the expected value equals the model value, then the control should be visible
1160:
1161:                 addLeagueShowRule(column, true);
1162:                 setLeagueToRight();
1163:                 instantiateRuleService();
1164:                 setLeagueToWrong();
1165:                 assertFalse(controlPName.isVisible());
1166:         }
1167:
1168:         /**
1169:          * Test propagation show rule no child rule right to right.
1170:          */
1171:         @Test
1172:         public void testPropagationShowRuleNoChildRuleRightToRight() {
1173:                 // if the expected value equals the model value, then the control should be visible
1174:
1175:                 addLeagueShowRule(column, true);
1176:                 setLeagueToRight();
1177:                 instantiateRuleService();
1178:                 setLeagueToRight();
1179:                 assertTrue(controlPName.isVisible());
1180:         }
1181:
1182:         /**
1183:          * Test propagation show rule child rule wrong to right.
1184:          */
1185:         @Test
1186:         public void testPropagationShowRuleChildRuleWrongToRight() {
1187:                 // if the expected value equals the model value, then the control should be visible
1188:
1189:                 addLeagueShowRule(column, true);
1190:                 addLeagueShowRule(controlPName, false);
1191:                 setLeagueToWrong();
1192:                 instantiateRuleService();
1193:                 setLeagueToRight();
1194:                 assertFalse(controlPName.isVisible());
1195:         }
1196:
1197:         /**
1198:          * Test propagation show rule child rule wrong to wrong.
1199:          */
1200:         @Test
1201:         public void testPropagationShowRuleChildRuleWrongToWrong() {
1202:                 // if the expected value equals the model value, then the control should be visible
1203:
1204:                 addLeagueShowRule(column, true);
1205:                 addLeagueShowRule(controlPName, false);
1206:                 setLeagueToWrong();
1207:                 instantiateRuleService();
1208:                 setLeagueToWrong();
1209:                 assertFalse(controlPName.isVisible());
1210:         }
1211:
1212:         /**
1213:          * Test propagation show rule child rule right to wrong.
1214:          *
1215:          * Control should not be visible since its parent will be hidden.
1216:          */
1217:         @Test
1218:         public void testPropagationShowRuleChildRuleRightToWrong() {
1219:                 // if the expected value equals the model value, then the control should be visible
1220:
1221:                 addLeagueShowRule(column, true);
1222:                 addLeagueShowRule(controlPName, false);
1223:                 setLeagueToRight();
1224:                 instantiateRuleService();
1225:                 setLeagueToWrong();
1226:                 assertFalse(controlPName.isVisible());
1227:         }
1228:
1229:         /**
1230:          * Test propagation show rule child rule right to right.
1231:          */
1232:         @Test
1233:         public void testPropagationShowRuleChildRuleRightToRight() {
1234:                 // if the expected value equals the model value, then the control should be visible
1235:
1236:                 addLeagueShowRule(column, true);
1237:                 addLeagueShowRule(controlPName, false);
1238:                 setLeagueToRight();
1239:                 instantiateRuleService();
1240:                 setLeagueToRight();
1241:                 assertFalse(controlPName.isVisible());
1242:         }
1243:
1244:         /**
1245:          * Test init right enable rule.
1246:          */
1247:         @Test
1248:         public void testInitRightEnableRule() {
1249:                 // if the expected value equals the model value, then the control should be enabled
1250:
1251:                 addLeagueEnableRule(controlPName, true);
1252:                 setLeagueToRight();
1253:                 instantiateRuleService();
1254:                 assertTrue(controlPName.isEnabled());
1255:         }
1256:
1257:         /**
1258:          * Test init wrong enable rule.
1259:          */
1260:         @Test
1261:         public void testInitWrongEnableRule() {
1262:                 // if the expected value equals the model value, then the control should be enabled
1263:
1264:                 addLeagueEnableRule(controlPName, true);
1265:                 setLeagueToWrong();
1266:                 instantiateRuleService();
1267:                 assertFalse(controlPName.isEnabled());
1268:         }
1269:
1270:         /**
1271:          * Test propagation enable rule no child rule wrong init.
1272:          */
1273:         @Test
1274:         public void testPropagationEnableRuleNoChildRuleWrongInit() {
1275:                 addLeagueEnableRule(column, true);
1276:                 setLeagueToWrong();
1277:                 instantiateRuleService();
1278:                 assertFalse(controlPName.isEnabled());
1279:         }
1280:
1281:         /**
1282:          * Test propagation enable rule no child rule right init.
1283:          */
1284:         @Test
1285:         public void testPropagationEnableRuleNoChildRuleRightInit() {
1286:                 addLeagueEnableRule(column, true);
1287:                 setLeagueToRight();
1288:                 instantiateRuleService();
1289:                 assertTrue(controlPName.isVisible());
1290:         }
1291:
1292:         /**
1293:          * Test propagation enable rule child rule wrong init.
1294:          */
1295:         @Test
1296:         public void testPropagationEnableRuleChildRuleWrongInit() {
1297:                 addLeagueEnableRule(column, true);
1298:                 addLeagueEnableRule(controlPName, false);
1299:                 setLeagueToWrong();
1300:                 instantiateRuleService();
1301:                 assertFalse(controlPName.isEnabled());
1302:         }
1303:
1304:         /**
1305:          * Test propagation enable rule child rule right init.
1306:          */
1307:         @Test
1308:         public void testPropagationEnableRuleChildRuleRightInit() {
1309:                 addLeagueEnableRule(column, true);
1310:                 addLeagueEnableRule(controlPName, false);
1311:                 setLeagueToRight();
1312:                 instantiateRuleService();
1313:                 assertTrue(controlPName.isVisible());
1314:         }
1315:
1316:         /**
1317:          * Test default wrong to right enable rule.
1318:          */
1319:         @Test
1320:         public void testDefaultWrongToRightEnableRule() {
1321:                 // if the expected value equals the model value, then the control should be enabled
1322:
1323:                 addLeagueEnableRule(controlPName, true);
1324:                 setLeagueToWrong();
1325:                 instantiateRuleService();
1326:                 setLeagueToRight();
1327:                 assertTrue(controlPName.isEnabled());
1328:         }
1329:
1330:         /**
1331:          * Test default wrong to wrong enable rule.
1332:          */
1333:         @Test
1334:         public void testDefaultWrongToWrongEnableRule() {
1335:                 // if the expected value equals the model value, then the control should be enabled
1336:
1337:                 addLeagueEnableRule(controlPName, true);
1338:                 setLeagueToWrong();
1339:                 instantiateRuleService();
1340:                 setLeagueToWrong();
1341:                 assertFalse(controlPName.isEnabled());
1342:         }
1343:
1344:         /**
1345:          * Test default right to wrong enable rule.
1346:          */
1347:         @Test
1348:         public void testDefaultRightToWrongEnableRule() {
1349:                 // if the expected value equals the model value, then the control should be enabled
1350:
1351:                 addLeagueEnableRule(controlPName, true);
1352:                 setLeagueToRight();
1353:                 instantiateRuleService();
1354:                 setLeagueToWrong();
1355:                 assertFalse(controlPName.isEnabled());
1356:         }
1357:
1358:         /**
1359:          * Test default right to right enable rule.
1360:          */
1361:         @Test
1362:         public void testDefaultRightToRightEnableRule() {
1363:                 // if the expected value equals the model value, then the control should be enabled
1364:
1365:                 addLeagueEnableRule(controlPName, true);
1366:                 setLeagueToRight();
1367:                 instantiateRuleService();
1368:                 setLeagueToRight();
1369:                 assertTrue(controlPName.isEnabled());
1370:         }
1371:
1372:         /**
1373:          * Test propagation enable rule no child rule wrong to right.
1374:          */
1375:         @Test
1376:         public void testPropagationEnableRuleNoChildRuleWrongToRight() {
1377:                 // if the expected value equals the model value, then the control should be enabled
1378:
1379:                 addLeagueEnableRule(column, true);
1380:                 setLeagueToWrong();
1381:                 instantiateRuleService();
1382:                 setLeagueToRight();
1383:                 assertTrue(controlPName.isEnabled());
1384:         }
1385:
1386:         /**
1387:          * Test propagation enable rule no child rule wrong to wrong.
1388:          */
1389:         @Test
1390:         public void testPropagationEnableRuleNoChildRuleWrongToWrong() {
1391:                 // if the expected value equals the model value, then the control should be enabled
1392:
1393:                 addLeagueEnableRule(column, true);
1394:                 setLeagueToWrong();
1395:                 instantiateRuleService();
1396:                 setLeagueToWrong();
1397:                 assertFalse(controlPName.isEnabled());
1398:         }
1399:
1400:         /**
1401:          * Test propagation enable rule no child rule right to wrong.
1402:          */
1403:         @Test
1404:         public void testPropagationEnableRuleNoChildRuleRightToWrong() {
1405:                 // if the expected value equals the model value, then the control should be enabled
1406:
1407:                 addLeagueEnableRule(column, true);
1408:                 setLeagueToRight();
1409:                 instantiateRuleService();
1410:                 setLeagueToWrong();
1411:                 assertFalse(controlPName.isEnabled());
1412:         }
1413:
1414:         /**
1415:          * Test propagation enable rule no child rule right to right.
1416:          */
1417:         @Test
1418:         public void testPropagationEnableRuleNoChildRuleRightToRight() {
1419:                 // if the expected value equals the model value, then the control should be enabled
1420:
1421:                 addLeagueEnableRule(column, true);
1422:                 setLeagueToRight();
1423:                 instantiateRuleService();
1424:                 setLeagueToRight();
1425:                 assertTrue(controlPName.isEnabled());
1426:         }
1427:
1428:         /**
1429:          * Test propagation enable rule child rule wrong to right.
1430:          */
1431:         @Test
1432:         public void testPropagationEnableRuleChildRuleWrongToRight() {
1433:                 // if the expected value equals the model value, then the control should be enabled
1434:
1435:                 addLeagueEnableRule(column, true);
1436:                 addLeagueEnableRule(controlPName, false);
1437:                 setLeagueToWrong();
1438:                 instantiateRuleService();
1439:                 setLeagueToRight();
1440:                 assertFalse(controlPName.isEnabled());
1441:         }
1442:
1443:         /**
1444:          * Test propagation enable rule child rule wrong to wrong.
1445:          */
1446:         @Test
1447:         public void testPropagationEnableRuleChildRuleWrongToWrong() {
1448:                 // if the expected value equals the model value, then the control should be enabled
1449:
1450:                 addLeagueEnableRule(column, true);
1451:                 addLeagueEnableRule(controlPName, false);
1452:                 setLeagueToWrong();
1453:                 instantiateRuleService();
1454:                 setLeagueToWrong();
1455:                 assertFalse(controlPName.isEnabled());
1456:         }
1457:
1458:         /**
1459:          * Test propagation enable rule child rule right to wrong.
1460:          */
1461:         @Test
1462:         public void testPropagationEnableRuleChildRuleRightToWrong() {
1463:                 // if the expected value equals the model value, then the control should be enabled
1464:
1465:                 addLeagueEnableRule(column, true);
1466:                 addLeagueEnableRule(controlPName, false);
1467:                 setLeagueToRight();
1468:                 instantiateRuleService();
1469:                 setLeagueToWrong();
1470:                 assertFalse(controlPName.isEnabled());
1471:         }
1472:
1473:         /**
1474:          * Test propagation enable rule child rule right to right.
1475:          */
1476:         @Test
1477:         public void testPropagationEnableRuleChildRuleRightToRight() {
1478:                 // if the expected value equals the model value, then the control should be enabled
1479:
1480:                 addLeagueEnableRule(column, true);
1481:                 addLeagueEnableRule(controlPName, false);
1482:                 setLeagueToRight();
1483:                 instantiateRuleService();
1484:                 setLeagueToRight();
1485:                 assertFalse(controlPName.isEnabled());
1486:         }
1487:
1488:         /**
1489:          * Test init right hide rule.
1490:          */
1491:         @Test
1492:         public void testInitRightHideRule() {
1493:                 // if the expected value equals the model value, then the control should be invisible
1494:
1495:                 addLeagueShowRule(controlPName, false);
1496:                 setLeagueToRight();
1497:                 instantiateRuleService();
1498:                 assertFalse(controlPName.isVisible());
1499:         }
1500:
1501:         /**
1502:          * Test init wrong hide rule.
1503:          */
1504:         @Test
1505:         public void testInitWrongHideRule() {
1506:                 // if the expected value equals the model value, then the control should be invisible
1507:
1508:                 addLeagueShowRule(controlPName, false);
1509:                 setLeagueToWrong();
1510:                 instantiateRuleService();
1511:                 assertTrue(controlPName.isVisible());
1512:         }
1513:
1514:         /**
1515:          * Test propagation hide rule no child rule right init.
1516:          */
1517:         @Test
1518:         public void testPropagationHideRuleNoChildRuleRightInit() {
1519:                 addLeagueShowRule(column, false);
1520:                 setLeagueToRight();
1521:                 instantiateRuleService();
1522:                 assertFalse(controlPName.isVisible());
1523:         }
1524:
1525:         /**
1526:          * Test propagation hide rule no child rule wrong init.
1527:          */
1528:         @Test
1529:         public void testPropagationHideRuleNoChildRuleWrongInit() {
1530:                 addLeagueShowRule(column, false);
1531:                 setLeagueToWrong();
1532:                 instantiateRuleService();
1533:                 assertTrue(controlPName.isVisible());
1534:         }
1535:
1536:         /**
1537:          * Test propagation hide rule child rule right init.
1538:          */
1539:         @Test
1540:         public void testPropagationHideRuleChildRuleRightInit() {
1541:                 addLeagueShowRule(column, false);
1542:                 addLeagueShowRule(controlPName, true);
1543:                 setLeagueToRight();
1544:                 instantiateRuleService();
1545:                 assertFalse(controlPName.isVisible());
1546:         }
1547:
1548:         /**
1549:          * Test propagation hide rule child rule wrong init.
1550:          */
1551:         @Test
1552:         public void testPropagationHideRuleChildRuleWrongInit() {
1553:                 addLeagueShowRule(column, false);
1554:                 addLeagueShowRule(controlPName, true);
1555:                 setLeagueToWrong();
1556:                 instantiateRuleService();
1557:                 assertFalse(controlPName.isVisible());
1558:         }
1559:
1560:         /**
1561:          * Test default wrong to right hide rule.
1562:          */
1563:         @Test
1564:         public void testDefaultWrongToRightHideRule() {
1565:                 // if the expected value equals the model value, then the control should be invisible
1566:
1567:                 addLeagueShowRule(controlPName, false);
1568:                 setLeagueToWrong();
1569:                 instantiateRuleService();
1570:                 setLeagueToRight();
1571:                 assertFalse(controlPName.isVisible());
1572:         }
1573:
1574:         /**
1575:          * Test default wrong to wrong hide rule.
1576:          */
1577:         @Test
1578:         public void testDefaultWrongToWrongHideRule() {
1579:                 // if the expected value equals the model value, then the control should be invisible
1580:
1581:                 addLeagueShowRule(controlPName, false);
1582:                 setLeagueToWrong();
1583:                 instantiateRuleService();
1584:                 setLeagueToWrong();
1585:                 assertTrue(controlPName.isVisible());
1586:         }
1587:
1588:         /**
1589:          * Test default right to wrong hide rule.
1590:          */
1591:         @Test
1592:         public void testDefaultRightToWrongHideRule() {
1593:                 // if the expected value equals the model value, then the control should be invisible
1594:
1595:                 addLeagueShowRule(controlPName, false);
1596:                 setLeagueToRight();
1597:                 instantiateRuleService();
1598:                 setLeagueToWrong();
1599:                 assertTrue(controlPName.isVisible());
1600:         }
1601:
1602:         /**
1603:          * Test default right to right hide rule.
1604:          */
1605:         @Test
1606:         public void testDefaultRightToRightHideRule() {
1607:                 // if the expected value equals the model value, then the control should be invisible
1608:
1609:                 addLeagueShowRule(controlPName, false);
1610:                 setLeagueToRight();
1611:                 instantiateRuleService();
1612:                 setLeagueToRight();
1613:                 assertFalse(controlPName.isVisible());
1614:         }
1615:
1616:         /**
1617:          * Test propagation hide rule no child rule wrong to right.
1618:          */
1619:         @Test
1620:         public void testPropagationHideRuleNoChildRuleWrongToRight() {
1621:                 // if the expected value equals the model value, then the control should be invisible
1622:
1623:                 addLeagueShowRule(column, false);
1624:                 setLeagueToWrong();
1625:                 instantiateRuleService();
1626:                 setLeagueToRight();
1627:                 assertFalse(controlPName.isVisible());
1628:         }
1629:
1630:         /**
1631:          * Test propagation hide rule no child rule wrong to wrong.
1632:          */
1633:         @Test
1634:         public void testPropagationHideRuleNoChildRuleWrongToWrong() {
1635:                 // if the expected value equals the model value, then the control should be invisible
1636:
1637:                 addLeagueShowRule(column, false);
1638:                 setLeagueToWrong();
1639:                 instantiateRuleService();
1640:                 setLeagueToWrong();
1641:                 assertTrue(controlPName.isVisible());
1642:         }
1643:
1644:         @Test
1645:         public void testContainmentConditionWithShowRule() {
1646:                 final ShowRule showRule = addShowRule(controlPName, false);
1647:                 final LeafCondition leafCondition1 = setupLeafConditionWithValueDMR("asdf@asdf.com",
1648:                         BowlingPackage.eINSTANCE.getLeague_Players(), Collections.<EReference> emptyList(),
1649:                         BowlingPackage.eINSTANCE.getPlayer_EMails(), Collections.<EReference> emptyList());
1650:                 showRule.setCondition(leafCondition1);
1651:                 instantiateRuleService();
1652:
1653:                 assertFalse(controlPName.isVisible());
1654:
1655:                 player.getEMails().add("asdf@asdf.com");
1656:
1657:                 assertTrue(controlPName.isVisible());
1658:         }
1659:
1660:         @Test
1661:         public void testGetInvolvedEObjetsContainedMultiAttributeNoMatch() {
1662:                 final ShowRule showRule = addShowRule(controlPName, false);
1663:                 final LeafCondition leafCondition1 = setupLeafConditionWithValueDMR("asdf@asdf.com",
1664:                         BowlingPackage.eINSTANCE.getLeague_Players(), Collections.<EReference> emptyList(),
1665:                         BowlingPackage.eINSTANCE.getPlayer_EMails(), Collections.<EReference> emptyList());
1666:                 showRule.setCondition(leafCondition1);
1667:                 instantiateRuleService();
1668:
1669:                 player.getEMails().add("foo@bar.com");
1670:                 final Player newPlayer = BowlingFactory.eINSTANCE.createPlayer();
1671:                 newPlayer.getEMails().add("asdf@asdf.com");
1672:
1673:                 final RuleServiceHelper helper = context.getService(RuleServiceHelper.class);
1674:
1675:                 final List<Player> newValue = new ArrayList<Player>();
1676:                 newValue.add(EcoreUtil.copy(player));
1677:                 newValue.get(0).getEMails().clear();
1678:                 newValue.add(newPlayer);
1679:
1680:                 final Set<VControl> involvedEObjects = helper.getInvolvedEObjects(
1681:                         ((LeagueImpl) league).eSetting(BowlingPackage.eINSTANCE.getLeague_Players()), newValue, VControl.class);
1682:
1683:                 assertEquals(0, involvedEObjects.size());
1684:         }
1685:
1686:         @Test
1687:         public void testGetInvolvedEObjetsContainedMultiAttributeEmptySet() {
1688:                 final ShowRule showRule = addShowRule(controlPName, false);
1689:                 final LeafCondition leafCondition1 = setupLeafConditionWithValueDMR("asdf@asdf.com",
1690:                         BowlingPackage.eINSTANCE.getLeague_Players(), Collections.<EReference> emptyList(),
1691:                         BowlingPackage.eINSTANCE.getPlayer_EMails(), Collections.<EReference> emptyList());
1692:                 showRule.setCondition(leafCondition1);
1693:                 instantiateRuleService();
1694:
1695:                 player.getEMails().add("foo@bar.com");
1696:                 final Player newPlayer = BowlingFactory.eINSTANCE.createPlayer();
1697:                 newPlayer.getEMails().add("asdf@asdf.com");
1698:
1699:                 final RuleServiceHelper helper = context.getService(RuleServiceHelper.class);
1700:
1701:                 final Set<VControl> involvedEObjects = helper.getInvolvedEObjects(getLeaguePlayersSetting(),
1702:                         new ArrayList<Player>(), VControl.class);
1703:
1704:                 assertEquals(0, involvedEObjects.size());
1705:         }
1706:
1707:         @Test
1708:         public void testGetInvolvedEObjetsContainedMultiAttributeNoMatchViaUpdatePlayer() {
1709:                 final ShowRule showRule = addShowRule(controlPName, false);
1710:                 final LeafCondition leafCondition1 = setupLeafConditionWithValueDMR("asdf@asdf.com",
1711:                         BowlingPackage.eINSTANCE.getLeague_Players(), Collections.<EReference> emptyList(),
1712:                         BowlingPackage.eINSTANCE.getPlayer_EMails(), Collections.<EReference> emptyList());
1713:                 showRule.setCondition(leafCondition1);
1714:                 instantiateRuleService();
1715:
1716:                 player.getEMails().add("foo@bar.com");
1717:
1718:                 final RuleServiceHelper helper = context.getService(RuleServiceHelper.class);
1719:
1720:                 final List<Player> newValues = new ArrayList<Player>();
1721:                 newValues.add(EcoreUtil.copy(player));
1722:                 newValues.get(0).getEMails().add("asdf@asdf.com");
1723:
1724:                 final Set<VControl> involvedEObjects = helper.getInvolvedEObjects(getLeaguePlayersSetting(), newValues,
1725:                         VControl.class);
1726:
1727:                 assertEquals(0, involvedEObjects.size());
1728:         }
1729:
1730:         @Test
1731:         public void testGetInvolvedEObjetsContainedMultiAttributeMatch() {
1732:                 final ShowRule showRule = addShowRule(controlPName, true);
1733:                 final LeafCondition leafCondition1 = setupLeafConditionWithValueDMR("asdf@asdf.com",
1734:                         BowlingPackage.eINSTANCE.getLeague_Players(), Collections.<EReference> emptyList(),
1735:                         BowlingPackage.eINSTANCE.getPlayer_EMails(), Collections.<EReference> emptyList());
1736:                 showRule.setCondition(leafCondition1);
1737:                 instantiateRuleService();
1738:
1739:                 player.getEMails().add("foo@bar.com");
1740:                 final Player newPlayer = BowlingFactory.eINSTANCE.createPlayer();
1741:                 newPlayer.getEMails().add("asdf@asdf.com");
1742:
1743:                 final RuleServiceHelper helper = context.getService(RuleServiceHelper.class);
1744:                 final Map<Setting, Object> expectedValues = new LinkedHashMap<EStructuralFeature.Setting, Object>();
1745:
1746:                 expectedValues.put(
1747:                         ((BasicEObjectImpl) player).eSetting(BowlingPackage.eINSTANCE.getPlayer_EMails()),
1748:                         player.getEMails());
1749:                 expectedValues.put(
1750:                         ((BasicEObjectImpl) newPlayer).eSetting(BowlingPackage.eINSTANCE.getPlayer_EMails()),
1751:                         newPlayer.getEMails());
1752:
1753:                 final List<Player> newValue = new ArrayList<Player>();
1754:                 newValue.add(player);
1755:                 newValue.add(newPlayer);
1756:
1757:                 final Set<VControl> involvedEObjects = helper.getInvolvedEObjects(
1758:                         ((LeagueImpl) league).eSetting(BowlingPackage.eINSTANCE.getLeague_Players()),
1759:                         newValue, VControl.class);
1760:
1761:                 assertEquals(1, involvedEObjects.size());
1762:         }
1763:
1764:         @Test
1765:         public void testGetInvolvedEObjetsContainedMultiAttributeMatchViaNewEmptyListValue() {
1766:                 final ShowRule showRule = addShowRule(controlPName, false);
1767:                 final LeafCondition leafCondition1 = setupLeafConditionWithValueDMR("asdf@asdf.com",
1768:                         BowlingPackage.eINSTANCE.getLeague_Players(), Collections.<EReference> emptyList(),
1769:                         BowlingPackage.eINSTANCE.getPlayer_EMails(), Collections.<EReference> emptyList());
1770:                 showRule.setCondition(leafCondition1);
1771:                 instantiateRuleService();
1772:
1773:                 player.getEMails().add("asdf@asdf.com");
1774:
1775:                 final RuleServiceHelper helper = context.getService(RuleServiceHelper.class);
1776:
1777:                 final List<Player> newValue = new ArrayList<Player>();
1778:                 newValue.add(EcoreUtil.copy(player));
1779:                 newValue.get(0).getEMails().clear();
1780:
1781:                 final Set<VControl> involvedEObjects = helper.getInvolvedEObjects(getLeaguePlayersSetting(), newValue,
1782:                         VControl.class);
1783:
1784:                 assertEquals(1, involvedEObjects.size());
1785:         }
1786:
1787:         @Test
1788:         public void testContainmentConditionWithShowRuleWithClearedMultiref() {
1789:                 final ShowRule showRule = addShowRule(controlPName, false);
1790:                 final LeafCondition leafCondition1 = setupLeafConditionWithValueDMR("doe",
1791:                         BowlingPackage.eINSTANCE.getLeague_Players(), Collections.<EReference> emptyList(),
1792:                         BowlingPackage.eINSTANCE.getPlayer_Name(), Collections.<EReference> emptyList());
1793:                 showRule.setCondition(leafCondition1);
1794:                 player.setName("doe");
1795:                 instantiateRuleService();
1796:                 assertTrue(controlPName.isVisible());
1797:                 league.getPlayers().clear();
1798:                 assertFalse(controlPName.isVisible());
1799:         }
1800:
1801:         @Test
1802:         public void testContainmentConditionWithShowRuleFulFillCondition() {
1803:                 final ShowRule showRule = addShowRule(controlPName, false);
1804:                 final LeafCondition leafCondition1 = setupLeafConditionWithValueDMR("doe",
1805:                         BowlingPackage.eINSTANCE.getLeague_Players(), Collections.<EReference> emptyList(),
1806:                         BowlingPackage.eINSTANCE.getPlayer_Name(), Collections.<EReference> emptyList());
1807:                 showRule.setCondition(leafCondition1);
1808:                 instantiateRuleService();
1809:                 assertFalse(controlPName.isVisible());
1810:                 player.setName("doe");
1811:                 assertTrue(controlPName.isVisible());
1812:         }
1813:
1814:         @Test
1815:         public void testContainmentConditionInitEmptyList() {
1816:                 league = BowlingFactory.eINSTANCE.createLeague();
1817:                 final ShowRule showRule = addShowRule(controlPName, false);
1818:                 final LeafCondition leafCondition1 = setupLeafConditionWithValueDMR("doe",
1819:                         BowlingPackage.eINSTANCE.getLeague_Players(), Collections.<EReference> emptyList(),
1820:                         BowlingPackage.eINSTANCE.getPlayer_Name(), Collections.<EReference> emptyList());
1821:                 showRule.setCondition(leafCondition1);
1822:                 instantiateRuleService();
1823:                 assertFalse(controlPName.isVisible());
1824:         }
1825:
1826:         @Test
1827:         public void testContainmentConditionAddToEmptyList() {
1828:                 league = BowlingFactory.eINSTANCE.createLeague();
1829:                 final ShowRule showRule = addShowRule(controlPName, false);
1830:                 final LeafCondition leafCondition1 = setupLeafConditionWithValueDMR("doe",
1831:                         BowlingPackage.eINSTANCE.getLeague_Players(), Collections.<EReference> emptyList(),
1832:                         BowlingPackage.eINSTANCE.getPlayer_Name(), Collections.<EReference> emptyList());
1833:                 showRule.setCondition(leafCondition1);
1834:                 instantiateRuleService();
1835:                 assertFalse(controlPName.isVisible());
1836:                 league.getPlayers().add(player);
1837:                 player.setName("doe");
1838:                 assertTrue(controlPName.isVisible());
1839:         }
1840:
1841:         /**
1842:          * Test {@link org.eclipse.emf.ecp.view.spi.rule.model.OrCondition OrCondition} with the second condition being
1843:          * true.
1844:          * Controls should be visible.
1845:          */
1846:         @Test
1847:         public void testShowRuleWithOrConditionSecondConditionApplies() {
1848:                 addLeagueShowRuleWithOrCondition(column, true,
1849:                         createLeafCondition(BowlingPackage.eINSTANCE.getLeague_Name(), "League"),
1850:                         createLeafCondition(BowlingPackage.eINSTANCE.getLeague_Name(), "League2"));
1851:                 instantiateRuleService();
1852:                 league.setName("League2");
1853:                 assertTrue(column.isVisible());
1854:                 assertTrue(controlPName.isVisible());
1855:         }
1856:
1857:         /**
1858:          * Test {@link org.eclipse.emf.ecp.view.spi.rule.model.OrCondition OrCondition} with none of the conditions being
1859:          * true.
1860:          * Controls should not be visible.
1861:          */
1862:         @Test
1863:         public void testShowRuleWithOrConditionNoConditionApplies() {
1864:                 addLeagueShowRuleWithOrCondition(column, true,
1865:                         createLeafCondition(BowlingPackage.eINSTANCE.getLeague_Name(), "League"),
1866:                         createLeafCondition(BowlingPackage.eINSTANCE.getLeague_Name(), "League2"));
1867:                 instantiateRuleService();
1868:                 setLeagueToWrong();
1869:                 assertFalse(column.isVisible());
1870:                 assertFalse(controlPName.isVisible());
1871:         }
1872:
1873:         /**
1874:          * Test propagation hide rule no child rule right to wrong.
1875:          */
1876:         @Test
1877:         public void testPropagationHideRuleNoChildRuleRightToWrong() {
1878:                 // if the expected value equals the model value, then the control should be invisible
1879:
1880:                 addLeagueShowRule(column, false);
1881:                 setLeagueToRight();
1882:                 instantiateRuleService();
1883:                 setLeagueToWrong();
1884:                 assertTrue(controlPName.isVisible());
1885:         }
1886:
1887:         /**
1888:          * Test propagation hide rule no child rule right to right.
1889:          */
1890:         @Test
1891:         public void testPropagationHideRuleNoChildRuleRightToRight() {
1892:                 // if the expected value equals the model value, then the control should be invisible
1893:
1894:                 addLeagueShowRule(column, false);
1895:                 setLeagueToRight();
1896:                 instantiateRuleService();
1897:                 setLeagueToRight();
1898:                 assertFalse(controlPName.isVisible());
1899:         }
1900:
1901:         /**
1902:          * Test propagation hide rule child rule wrong to right.
1903:          */
1904:         @Test
1905:         public void testPropagationHideRuleChildRuleWrongToRight() {
1906:                 // if the expected value equals the model value, then the control should be invisible
1907:
1908:                 addLeagueShowRule(column, false);
1909:                 addLeagueShowRule(controlPName, true);
1910:                 setLeagueToWrong();
1911:                 instantiateRuleService();
1912:                 setLeagueToRight();
1913:                 assertFalse(controlPName.isVisible());
1914:         }
1915:
1916:         /**
1917:          * Test propagation hide rule child rule wrong to wrong.
1918:          */
1919:         @Test
1920:         public void testPropagationHideRuleChildRuleWrongToWrong() {
1921:                 // if the expected value equals the model value, then the control should be invisible
1922:
1923:                 addLeagueShowRule(column, false);
1924:                 addLeagueShowRule(controlPName, true);
1925:                 setLeagueToWrong();
1926:                 instantiateRuleService();
1927:                 setLeagueToWrong();
1928:                 assertFalse(controlPName.isVisible());
1929:         }
1930:
1931:         /**
1932:          * Test propagation hide rule child rule right to wrong.
1933:          */
1934:         @Test
1935:         public void testPropagationHideRuleChildRuleRightToWrong() {
1936:                 // if the expected value equals the model value, then the control should be invisible
1937:
1938:                 addLeagueShowRule(column, false);
1939:                 addLeagueShowRule(controlPName, true);
1940:                 setLeagueToRight();
1941:                 instantiateRuleService();
1942:                 setLeagueToWrong();
1943:                 assertFalse(controlPName.isVisible());
1944:         }
1945:
1946:         /**
1947:          * Test propagation hide rule child rule right to right.
1948:          */
1949:         @Test
1950:         public void testPropagationHideRuleChildRuleRightToRight() {
1951:                 // if the expected value equals the model value, then the control should be invisible
1952:
1953:                 addLeagueShowRule(column, false);
1954:                 addLeagueShowRule(controlPName, true);
1955:                 setLeagueToRight();
1956:                 instantiateRuleService();
1957:                 setLeagueToRight();
1958:                 assertFalse(controlPName.isVisible());
1959:         }
1960:
1961:         /**
1962:          * Test init right disable rule.
1963:          */
1964:         @Test
1965:         public void testInitRightDisableRule() {
1966:                 // if the expected value equals the model value, then the control should be disabled
1967:
1968:                 addLeagueEnableRule(controlPName, false);
1969:                 setLeagueToRight();
1970:                 instantiateRuleService();
1971:                 assertFalse(controlPName.isEnabled());
1972:         }
1973:
1974:         /**
1975:          * Test init wrong disable rule.
1976:          */
1977:         @Test
1978:         public void testInitWrongDisableRule() {
1979:                 // if the expected value equals the model value, then the control should be disabled
1980:
1981:                 addLeagueEnableRule(controlPName, false);
1982:                 setLeagueToWrong();
1983:                 instantiateRuleService();
1984:                 assertTrue(controlPName.isEnabled());
1985:         }
1986:
1987:         /**
1988:          * Test propagation disable rule no child rule right init.
1989:          */
1990:         @Test
1991:         public void testPropagationDisableRuleNoChildRuleRightInit() {
1992:                 addLeagueEnableRule(column, false);
1993:                 setLeagueToRight();
1994:                 instantiateRuleService();
1995:                 assertFalse(controlPName.isEnabled());
1996:         }
1997:
1998:         /**
1999:          * Test propagation disable rule no child rule wrong init.
2000:          */
2001:         @Test
2002:         public void testPropagationDisableRuleNoChildRuleWrongInit() {
2003:                 addLeagueEnableRule(column, false);
2004:                 setLeagueToWrong();
2005:                 instantiateRuleService();
2006:                 assertTrue(controlPName.isEnabled());
2007:         }
2008:
2009:         /**
2010:          * Test propagation disable rule child rule right init.
2011:          */
2012:         @Test
2013:         public void testPropagationDisableRuleChildRuleRightInit() {
2014:                 addLeagueEnableRule(column, false);
2015:                 addLeagueEnableRule(controlPName, true);
2016:                 setLeagueToRight();
2017:                 instantiateRuleService();
2018:                 assertFalse(controlPName.isEnabled());
2019:         }
2020:
2021:         /**
2022:          * Test propagation disable rule child rule wrong init.
2023:          */
2024:         @Test
2025:         public void testPropagationDisableRuleChildRuleWrongInit() {
2026:                 addLeagueEnableRule(column, false);
2027:                 addLeagueEnableRule(controlPName, true);
2028:                 setLeagueToWrong();
2029:                 instantiateRuleService();
2030:                 assertFalse(controlPName.isEnabled());
2031:         }
2032:
2033:         /**
2034:          * Test default right to wrong disable rule.
2035:          */
2036:         @Test
2037:         public void testDefaultRightToWrongDisableRule() {
2038:                 // if the expected value equals the model value, then the control should be disabled
2039:
2040:                 addLeagueEnableRule(controlPName, false);
2041:                 setLeagueToRight();
2042:                 instantiateRuleService();
2043:                 setLeagueToWrong();
2044:                 assertTrue(controlPName.isEnabled());
2045:         }
2046:
2047:         /**
2048:          * Test default right to right disable rule.
2049:          */
2050:         @Test
2051:         public void testDefaultRightToRightDisableRule() {
2052:                 // if the expected value equals the model value, then the control should be disabled
2053:
2054:                 addLeagueEnableRule(controlPName, false);
2055:                 setLeagueToRight();
2056:                 instantiateRuleService();
2057:                 setLeagueToRight();
2058:                 assertFalse(controlPName.isEnabled());
2059:         }
2060:
2061:         /**
2062:          * Test default wrong to right disable rule.
2063:          */
2064:         @Test
2065:         public void testDefaultWrongToRightDisableRule() {
2066:                 // if the expected value equals the model value, then the control should be disabled
2067:
2068:                 addLeagueEnableRule(controlPName, false);
2069:                 setLeagueToWrong();
2070:                 instantiateRuleService();
2071:                 setLeagueToRight();
2072:                 assertFalse(controlPName.isEnabled());
2073:         }
2074:
2075:         /**
2076:          * Test default wrong to wrong disable rule.
2077:          */
2078:         @Test
2079:         public void testDefaultWrongToWrongDisableRule() {
2080:                 // if the expected value equals the model value, then the control should be disabled
2081:
2082:                 addLeagueEnableRule(controlPName, false);
2083:                 setLeagueToWrong();
2084:                 instantiateRuleService();
2085:                 setLeagueToWrong();
2086:                 assertTrue(controlPName.isEnabled());
2087:         }
2088:
2089:         /**
2090:          * Test propagation disable rule no child rule right to wrong.
2091:          */
2092:         @Test
2093:         public void testPropagationDisableRuleNoChildRuleRightToWrong() {
2094:                 // if the expected value equals the model value, then the control should be disabled
2095:
2096:                 addLeagueEnableRule(column, false);
2097:                 setLeagueToRight();
2098:                 instantiateRuleService();
2099:                 setLeagueToWrong();
2100:                 assertTrue(controlPName.isEnabled());
2101:         }
2102:
2103:         /**
2104:          * Test propagation disable rule no child rule right to right.
2105:          */
2106:         @Test
2107:         public void testPropagationDisableRuleNoChildRuleRightToRight() {
2108:                 // if the expected value equals the model value, then the control should be disabled
2109:
2110:                 addLeagueEnableRule(column, false);
2111:                 setLeagueToRight();
2112:                 instantiateRuleService();
2113:                 setLeagueToRight();
2114:                 assertFalse(controlPName.isEnabled());
2115:         }
2116:
2117:         /**
2118:          * Test propagation disable rule no child rule wrong to right.
2119:          */
2120:         @Test
2121:         public void testPropagationDisableRuleNoChildRuleWrongToRight() {
2122:                 // if the expected value equals the model value, then the control should be disabled
2123:
2124:                 addLeagueEnableRule(column, false);
2125:                 setLeagueToWrong();
2126:                 instantiateRuleService();
2127:                 setLeagueToRight();
2128:                 assertFalse(controlPName.isEnabled());
2129:         }
2130:
2131:         /**
2132:          * Test propagation disable rule no child rule wrong to wrong.
2133:          */
2134:         @Test
2135:         public void testPropagationDisableRuleNoChildRuleWrongToWrong() {
2136:                 // if the expected value equals the model value, then the control should be disabled
2137:
2138:                 addLeagueEnableRule(column, false);
2139:                 setLeagueToWrong();
2140:                 instantiateRuleService();
2141:                 setLeagueToWrong();
2142:                 assertTrue(controlPName.isEnabled());
2143:         }
2144:
2145:         /**
2146:          * Test propagation disable rule child rule right to wrong.
2147:          */
2148:         @Test
2149:         public void testPropagationDisableRuleChildRuleRightToWrong() {
2150:                 // if the expected value equals the model value, then the control should be disabled
2151:
2152:                 addLeagueEnableRule(column, false);
2153:                 addLeagueEnableRule(controlPName, true);
2154:                 setLeagueToRight();
2155:                 instantiateRuleService();
2156:                 setLeagueToWrong();
2157:                 assertFalse(controlPName.isEnabled());
2158:         }
2159:
2160:         /**
2161:          * Test propagation disable rule child rule right to right.
2162:          */
2163:         @Test
2164:         public void testPropagationDisableRuleChildRuleRightToRight() {
2165:                 // if the expected value equals the model value, then the control should be disabled
2166:
2167:                 addLeagueEnableRule(column, false);
2168:                 addLeagueEnableRule(controlPName, true);
2169:                 setLeagueToRight();
2170:                 instantiateRuleService();
2171:                 setLeagueToRight();
2172:                 assertFalse(controlPName.isEnabled());
2173:         }
2174:
2175:         /**
2176:          * Test propagation disable rule child rule wrong to right.
2177:          */
2178:         @Test
2179:         public void testPropagationDisableRuleChildRuleWrongToRight() {
2180:                 // if the expected value equals the model value, then the control should be disabled
2181:
2182:                 addLeagueEnableRule(column, false);
2183:                 addLeagueEnableRule(controlPName, true);
2184:                 setLeagueToWrong();
2185:                 instantiateRuleService();
2186:                 setLeagueToRight();
2187:                 assertFalse(controlPName.isEnabled());
2188:         }
2189:
2190:         /**
2191:          * Test propagation disable rule child rule wrong to wrong.
2192:          */
2193:         @Test
2194:         public void testPropagationDisableRuleChildRuleWrongToWrong() {
2195:                 // if the expected value equals the model value, then the control should be disabled
2196:
2197:                 addLeagueEnableRule(column, false);
2198:                 addLeagueEnableRule(controlPName, true);
2199:                 setLeagueToWrong();
2200:                 instantiateRuleService();
2201:                 setLeagueToWrong();
2202:                 assertFalse(controlPName.isEnabled());
2203:         }
2204:
2205:         /**
2206:          * Test multi level propagation on init.
2207:          */
2208:         @Test
2209:         public void testMultiLevelPropagationOnInit() {
2210:                 addLeagueEnableRule(parentColumn, false);
2211:                 addLeagueEnableRule(controlPName, true);
2212:                 setLeagueToRight();
2213:                 instantiateRuleService();
2214:                 assertFalse(controlPName.isEnabled());
2215:         }
2216:
2217:         /**
2218:          * Test multi level propagation on lifecycle.
2219:          */
2220:         @Test
2221:         public void testMultiLevelPropagationOnLifecycle() {
2222:                 // if the expected value equals the model value, then the control should be disabled
2223:
2224:                 addLeagueEnableRule(parentColumn, false);
2225:                 addLeagueEnableRule(controlPName, true);
2226:                 setLeagueToRight();
2227:                 instantiateRuleService();
2228:                 setLeagueToWrong();
2229:                 assertFalse(controlPName.isEnabled());
2230:         }
2231:
2232:         @Test
2233:         public void testParentShowVsChildShow() {
2234:                 addShowRule(parentColumn, true, BowlingPackage.eINSTANCE.getLeague_Name(), "foo");
2235:                 addShowRule(controlPName, true, BowlingPackage.eINSTANCE.getLeague_Name(), "foo");
2236:                 instantiateRuleService();
2237:                 league.setName("foo");
2238:                 assertTrue(parentColumn.isVisible());
2239:                 assertTrue(controlPName.isVisible());
2240:         }
2241:
2242:         @Test
2243:         public void testParentShowVsChildHide() {
2244:                 addShowRule(parentColumn, true, BowlingPackage.eINSTANCE.getLeague_Name(), "foo");
2245:                 addShowRule(controlPName, false, BowlingPackage.eINSTANCE.getLeague_Name(), "foo");
2246:                 instantiateRuleService();
2247:                 league.setName("foo");
2248:                 assertTrue(parentColumn.isVisible());
2249:                 assertFalse(controlPName.isVisible());
2250:         }
2251:
2252:         @Test
2253:         public void testParentHideVsChildHide() {
2254:                 addShowRule(parentColumn, false, BowlingPackage.eINSTANCE.getLeague_Name(), "foo");
2255:                 addShowRule(controlPName, false, BowlingPackage.eINSTANCE.getLeague_Name(), "foo");
2256:                 instantiateRuleService();
2257:                 league.setName("foo");
2258:                 assertFalse(parentColumn.isVisible());
2259:                 assertFalse(controlPName.isVisible());
2260:         }
2261:
2262:         @Test
2263:         public void testParentHideVsChildShow() {
2264:                 addShowRule(parentColumn, false, BowlingPackage.eINSTANCE.getLeague_Name(), "foo");
2265:                 addShowRule(controlPName, true, BowlingPackage.eINSTANCE.getLeague_Name(), "foo");
2266:                 instantiateRuleService();
2267:                 league.setName("foo");
2268:                 assertFalse(parentColumn.isVisible());
2269:                 assertFalse(controlPName.isVisible());
2270:         }
2271:
2272:         @Test
2273:         public void testParentEnableVsChildEnable() {
2274:                 addEnableRule(parentColumn, true, BowlingPackage.eINSTANCE.getLeague_Name(), "foo");
2275:                 addEnableRule(controlPName, true, BowlingPackage.eINSTANCE.getLeague_Name(), "foo");
2276:                 instantiateRuleService();
2277:                 league.setName("foo");
2278:                 assertTrue(parentColumn.isEnabled());
2279:                 assertTrue(controlPName.isEnabled());
2280:         }
2281:
2282:         @Test
2283:         public void testParentEnableVsChildDisable() {
2284:                 addEnableRule(parentColumn, true, BowlingPackage.eINSTANCE.getLeague_Name(), "foo");
2285:                 addEnableRule(controlPName, false, BowlingPackage.eINSTANCE.getLeague_Name(), "foo");
2286:                 instantiateRuleService();
2287:                 league.setName("foo");
2288:                 assertTrue(parentColumn.isEnabled());
2289:                 assertFalse(controlPName.isEnabled());
2290:         }
2291:
2292:         @Test
2293:         public void testParentDisableVsChildDisable() {
2294:                 addEnableRule(parentColumn, false, BowlingPackage.eINSTANCE.getLeague_Name(), "foo");
2295:                 addEnableRule(controlPName, false, BowlingPackage.eINSTANCE.getLeague_Name(), "foo");
2296:                 instantiateRuleService();
2297:                 league.setName("foo");
2298:                 assertFalse(parentColumn.isEnabled());
2299:                 assertFalse(controlPName.isEnabled());
2300:         }
2301:
2302:         @Test
2303:         public void testParentDisableVsChildEnable() {
2304:                 addEnableRule(parentColumn, false, BowlingPackage.eINSTANCE.getLeague_Name(), "foo");
2305:                 addEnableRule(controlPName, true, BowlingPackage.eINSTANCE.getLeague_Name(), "foo");
2306:                 instantiateRuleService();
2307:                 league.setName("foo");
2308:                 assertFalse(parentColumn.isEnabled());
2309:                 assertFalse(controlPName.isEnabled());
2310:         }
2311:
2312:         @Test
2313:         public void testInitParentShowVsChildShow() {
2314:                 addShowRule(parentColumn, true, BowlingPackage.eINSTANCE.getLeague_Name(), "foo");
2315:                 addShowRule(controlPName, true, BowlingPackage.eINSTANCE.getLeague_Name(), "foo");
2316:                 league.setName("foo");
2317:                 instantiateRuleService();
2318:                 assertTrue(parentColumn.isVisible());
2319:                 assertTrue(controlPName.isVisible());
2320:         }
2321:
2322:         @Test
2323:         public void testInitParentShowVsChildHide() {
2324:                 addShowRule(parentColumn, true, BowlingPackage.eINSTANCE.getLeague_Name(), "foo");
2325:                 addShowRule(controlPName, false, BowlingPackage.eINSTANCE.getLeague_Name(), "foo");
2326:                 league.setName("foo");
2327:                 instantiateRuleService();
2328:                 assertTrue(parentColumn.isVisible());
2329:                 assertFalse(controlPName.isVisible());
2330:         }
2331:
2332:         @Test
2333:         public void testInitParentHideVsChildHide() {
2334:                 addShowRule(parentColumn, false, BowlingPackage.eINSTANCE.getLeague_Name(), "foo");
2335:                 addShowRule(controlPName, false, BowlingPackage.eINSTANCE.getLeague_Name(), "foo");
2336:                 league.setName("foo");
2337:                 instantiateRuleService();
2338:                 assertFalse(parentColumn.isVisible());
2339:                 assertFalse(controlPName.isVisible());
2340:         }
2341:
2342:         @Test
2343:         public void testInitParentHideVsChildShow() {
2344:                 addShowRule(parentColumn, false, BowlingPackage.eINSTANCE.getLeague_Name(), "foo");
2345:                 addShowRule(controlPName, true, BowlingPackage.eINSTANCE.getLeague_Name(), "foo");
2346:                 league.setName("foo");
2347:                 instantiateRuleService();
2348:                 assertFalse(parentColumn.isVisible());
2349:                 assertFalse(controlPName.isVisible());
2350:         }
2351:
2352:         @Test
2353:         public void testInitParentEnableVsChildEnable() {
2354:                 addEnableRule(parentColumn, true, BowlingPackage.eINSTANCE.getLeague_Name(), "foo");
2355:                 addEnableRule(controlPName, true, BowlingPackage.eINSTANCE.getLeague_Name(), "foo");
2356:                 league.setName("foo");
2357:                 instantiateRuleService();
2358:                 assertTrue(parentColumn.isEnabled());
2359:                 assertTrue(controlPName.isEnabled());
2360:         }
2361:
2362:         @Test
2363:         public void testInitParentEnableVsChildDisable() {
2364:                 addEnableRule(parentColumn, true, BowlingPackage.eINSTANCE.getLeague_Name(), "foo");
2365:                 addEnableRule(controlPName, false, BowlingPackage.eINSTANCE.getLeague_Name(), "foo");
2366:                 league.setName("foo");
2367:                 instantiateRuleService();
2368:                 assertTrue(parentColumn.isEnabled());
2369:                 assertFalse(controlPName.isEnabled());
2370:         }
2371:
2372:         @Test
2373:         public void testInitParentDisableVsChildDisable() {
2374:                 addEnableRule(parentColumn, false, BowlingPackage.eINSTANCE.getLeague_Name(), "foo");
2375:                 addEnableRule(controlPName, false, BowlingPackage.eINSTANCE.getLeague_Name(), "foo");
2376:                 league.setName("foo");
2377:                 instantiateRuleService();
2378:                 assertFalse(parentColumn.isEnabled());
2379:                 assertFalse(controlPName.isEnabled());
2380:         }
2381:
2382:         @Test
2383:         public void testInitParentDisableVsChildEnable() {
2384:                 addEnableRule(parentColumn, false, BowlingPackage.eINSTANCE.getLeague_Name(), "foo");
2385:                 addEnableRule(controlPName, true, BowlingPackage.eINSTANCE.getLeague_Name(), "foo");
2386:                 league.setName("foo");
2387:                 instantiateRuleService();
2388:                 assertFalse(parentColumn.isEnabled());
2389:                 assertFalse(controlPName.isEnabled());
2390:         }
2391:
2392:         @Test
2393:         public void testInitEnableShowSameControl() {
2394:                 addEnableRule(controlPName, true, BowlingPackage.eINSTANCE.getLeague_Name(), "foo");
2395:                 addShowRule(controlPName, true, BowlingPackage.eINSTANCE.getLeague_Name(), "bar");
2396:                 instantiateRuleService();
2397:                 assertFalse(controlPName.isEnabled());
2398:                 assertFalse(controlPName.isVisible());
2399:                 league.setName("foo");
2400:                 assertTrue(controlPName.isEnabled());
2401:                 assertFalse(controlPName.isVisible());
2402:                 league.setName("bar");
2403:                 assertFalse(controlPName.isEnabled());
2404:                 assertTrue(controlPName.isVisible());
2405:         }
2406:
2407:         /**
2408:          * Test dispose.
2409:          */
2410:         @Test
2411:         public void testDispose() {
2412:                 addLeagueEnableRule(controlPName, false);
2413:                 setLeagueToRight();
2414:                 final RuleService ruleService = instantiateRuleService();
2415:                 ruleService.dispose();
2416:                 setLeagueToWrong();
2417:                 assertTrue(controlPName.isEnabled());
2418:         }
2419:
2420:         /**
2421:          * Test get involved e object no change.
2422:          */
2423:         @Test
2424:         public void testGetInvolvedEObjectNoChange() {
2425:                 // if the expected value equals the model value, then the control should be enabled
2426:
2427:                 addLeagueEnableRule(controlPName, true);
2428:                 setLeagueToRight();
2429:                 final RuleService ruleService = instantiateRuleService();
2430:
2431:                 final Map<VElement, Boolean> involvedEObjects = ruleService.getDisabledRenderables(
2432:                         createSettingsMapping(((LeagueImpl) league).eSetting(BowlingPackage.eINSTANCE.getLeague_Name()), "League"),
2433:                         UniqueSetting.createSetting(league, BowlingPackage.eINSTANCE.getLeague_Name()));
2434:                 assertTrue(involvedEObjects.isEmpty());
2435:         }
2436:
2437:         /**
2438:          * Test get involved e object no side effects.
2439:          */
2440:         @Test
2441:         public void testGetInvolvedEObjectNoSideEffects() {
2442:                 // if the expected value equals the model value, then the control should be enabled
2443:
2444:                 addLeagueEnableRule(controlPName, true);
2445:                 setLeagueToRight();
2446:                 final RuleService ruleService = instantiateRuleService();
2447:
2448:                 ruleService.getDisabledRenderables(
2449:                         createSettingsMapping(((LeagueImpl) league).eSetting(BowlingPackage.eINSTANCE.getLeague_Name()), "League"),
2450:                         UniqueSetting.createSetting(league, BowlingPackage.eINSTANCE.getLeague_Name()));
2451:                 assertTrue(controlPName.isEnabled());
2452:         }
2453:
2454:         private static Map<Setting, Object> createSettingsMapping(Setting setting, Object newValue) {
2455:                 final Map<Setting, Object> result = new LinkedHashMap<EStructuralFeature.Setting, Object>();
2456:                 result.put(setting, newValue);
2457:                 return result;
2458:         }
2459:
2460:         /**
2461:          * Test get involved e object change.
2462:          */
2463:         @Test
2464:         public void testGetInvolvedEObjectChange() {
2465:
2466:                 addLeagueEnableRule(controlPName, true);
2467:                 addLeagueShowRule(parentColumn, true);
2468:                 setLeagueToRight();
2469:                 final RuleService ruleService = instantiateRuleService();
2470:                 ruleService.contextInitialised();
2471:
2472:                 final Map<VElement, Boolean> disabledRenderables = ruleService.getDisabledRenderables(
2473:                         createSettingsMapping(((LeagueImpl) league).eSetting(BowlingPackage.eINSTANCE.getLeague_Name()),
2474:                                 "League_Wrong"),
2475:                         UniqueSetting.createSetting(league, BowlingPackage.eINSTANCE.getLeague_Name()));
2476:                 final Map<VElement, Boolean> hiddenRenderables = ruleService.getHiddenRenderables(
2477:                         createSettingsMapping(((LeagueImpl) league).eSetting(BowlingPackage.eINSTANCE.getLeague_Name()),
2478:                                 "League_Wrong"),
2479:                         UniqueSetting.createSetting(league, BowlingPackage.eINSTANCE.getLeague_Name()));
2480:
2481:                 assertEquals(3, hiddenRenderables.size());
2482:                 assertTrue(hiddenRenderables.containsKey(parentColumn));
2483:                 assertTrue(hiddenRenderables.containsKey(column));
2484:                 assertTrue(hiddenRenderables.containsKey(controlPName));
2485:
2486:                 assertEquals(1, disabledRenderables.size());
2487:                 assertTrue(disabledRenderables.containsKey(controlPName));
2488:         }
2489:
2490:         /**
2491:          * Test get involved e object change.
2492:          */
2493:         @Test
2494:         public void testGetInvolvedEObjectChangeWithoutChangedValue() {
2495:                 addLeagueEnableRule(controlPName, true);
2496:                 addLeagueShowRule(parentColumn, true);
2497:                 setLeagueToRight();
2498:                 final RuleService ruleService = instantiateRuleService();
2499:
2500:                 final Map<VElement, Boolean> disabledRenderables = ruleService.getDisabledRenderables(
2501:                         createSettingsMapping(((LeagueImpl) league).eSetting(BowlingPackage.eINSTANCE.getLeague_Name()),
2502:                                 "League"),
2503:                         UniqueSetting.createSetting(league, BowlingPackage.eINSTANCE.getLeague_Name()));
2504:                 final Map<VElement, Boolean> hiddenRenderables = ruleService.getHiddenRenderables(
2505:                         createSettingsMapping(((LeagueImpl) league).eSetting(BowlingPackage.eINSTANCE.getLeague_Name()),
2506:                                 "League"),
2507:                         UniqueSetting.createSetting(league, BowlingPackage.eINSTANCE.getLeague_Name()));
2508:
2509:                 assertEquals(0, disabledRenderables.size());
2510:                 assertEquals(0, hiddenRenderables.size());
2511:         }
2512:
2513:         /**
2514:          * Test get involved e object change.
2515:          */
2516:         @Test
2517:         public void testGetInvolvedEObjectNoVanishingRenderables() {
2518:                 // if the expected value equals the model value, then the control should be enabled
2519:
2520:                 addLeagueEnableRule(controlPName, true);
2521:                 addLeagueShowRule(parentColumn, true);
2522:                 setLeagueToRight();
2523:                 instantiateRuleService();
2524:                 final RuleServiceHelper helper = context.getService(RuleServiceHelper.class);
2525:
2526:                 final Set<VControl> involvedEControls = helper.getInvolvedEObjects(
2527:                         ((LeagueImpl) league).eSetting(BowlingPackage.eINSTANCE.getLeague_Name()),
2528:                         "League", VControl.class);
2529:                 assertEquals(0, involvedEControls.size());
2530:         }
2531:
2532:         /**
2533:          * Should return the control. Changing the league's name to
2534:          * 'League2' should not alter the disabled/show state of the
2535:          * control.
2536:          */
2537:         @Test
2538:         public void testGetInvolvedEObjectsHelperBothRulesApply() {
2539:                 addLeagueEnableRule(controlPName, true);
2540:                 addLeagueShowRule(parentColumn, true);
2541:                 setLeagueToWrong();
2542:                 instantiateRuleService();
2543:                 final RuleServiceHelper helper = context.getService(RuleServiceHelper.class);
2544:
2545:                 final Set<VControl> involvedEControls = helper.getInvolvedEObjects(
2546:                         ((LeagueImpl) league).eSetting(BowlingPackage.eINSTANCE.getLeague_Name()),
2547:                         "League2", VControl.class);
2548:                 assertEquals(0, involvedEControls.size());
2549:         }
2550:
2551:         /**
2552:          * Should return the parent columns of the control.
2553:          * Changing the league's name to 'League2' should not alter
2554:          * the disabled/show state of the control.
2555:          */
2556:         @Test
2557:         public void testGetInvolvedEObjectsHelperNoRuleAppliesFilterForComposite() {
2558:                 addLeagueEnableRule(controlPName, true);
2559:                 addLeagueShowRule(parentColumn, true);
2560:                 setLeagueToWrong();
2561:                 instantiateRuleService();
2562:                 final RuleServiceHelper helper = context.getService(RuleServiceHelper.class);
2563:
2564:                 final Set<VVerticalLayout> involvedEControls = helper.getInvolvedEObjects(
2565:                         ((LeagueImpl) league).eSetting(BowlingPackage.eINSTANCE.getLeague_Name()),
2566:                         "League2", VVerticalLayout.class);
2567:                 assertEquals(0, involvedEControls.size());
2568:         }
2569:
2570:         /**
2571:          * Should return nothing since the correct value is set.
2572:          */
2573:         @Test
2574:         public void testGetInvolvedEObjectsHelperNoRuleApplies() {
2575:                 addLeagueEnableRule(controlPName, true);
2576:                 addLeagueShowRule(parentColumn, true);
2577:                 setLeagueToWrong();
2578:                 instantiateRuleService();
2579:                 final RuleServiceHelper helper = context.getService(RuleServiceHelper.class);
2580:
2581:                 final Set<VControl> involvedEControls = helper.getInvolvedEObjects(
2582:                         ((LeagueImpl) league).eSetting(BowlingPackage.eINSTANCE.getLeague_Name()),
2583:                         "League", VControl.class);
2584:                 assertEquals(0, involvedEControls.size());
2585:         }
2586:
2587:         /**
2588:          * Should return the control since the disable rule applies because
2589:          * of the wrong value.
2590:          */
2591:         @Test
2592:         public void testGetInvolvedEObjectsHelperEnableRuleAppliesWrongValue() {
2593:                 addLeagueEnableRule(controlPName, false);
2594:                 addLeagueShowRule(parentColumn, true);
2595:                 setLeagueToWrong();
2596:                 instantiateRuleService();
2597:                 final RuleServiceHelper helper = context.getService(RuleServiceHelper.class);
2598:
2599:                 final Set<VControl> involvedEControls = helper.getInvolvedEObjects(
2600:                         ((LeagueImpl) league).eSetting(BowlingPackage.eINSTANCE.getLeague_Name()),
2601:                         "League2", VControl.class);
2602:                 assertEquals(0, involvedEControls.size());
2603:         }
2604:
2605:         /**
2606:          * Should return the control because of the {@link org.eclipse.emf.ecp.view.spi.rule.model.EnableRule EnableRule}
2607:          * on
2608:          * the
2609:          * control.
2610:          */
2611:         @Test
2612:         public void testGetInvolvedEObjectsHelperEnableRuleAppliesCorrectValue() {
2613:                 addLeagueEnableRule(controlPName, false);
2614:                 addLeagueShowRule(parentColumn, true);
2615:                 setLeagueToWrong();
2616:                 instantiateRuleService();
2617:                 final RuleServiceHelper helper = context.getService(RuleServiceHelper.class);
2618:
2619:                 final Set<VControl> hiddenOrDisabledControls = helper.getInvolvedEObjects(
2620:                         ((LeagueImpl) league).eSetting(BowlingPackage.eINSTANCE.getLeague_Name()),
2621:                         "League", VControl.class);
2622:
2623:                 assertEquals(1, hiddenOrDisabledControls.size());
2624:         }
2625:
2626:         /**
2627:          * Should return nothing because the column should be visible, since
2628:          * 'League2' is the wrong value and the we have a disable rule.
2629:          */
2630:
2631:         /**
2632:          * Should return the control because the column should be hidden, since
2633:          * 'League' is the right value and the we have a disable rule.
2634:          */
2635:         @Test
2636:         public void testGetInvolvedEObjectsHelperShowRuleAppliesCorrectValue() {
2637:                 addLeagueEnableRule(controlPName, true);
2638:                 addLeagueShowRule(parentColumn, false);
2639:                 setLeagueToWrong();
2640:                 instantiateRuleService();
2641:                 final RuleServiceHelper helper = context.getService(RuleServiceHelper.class);
2642:
2643:                 final Set<VControl> involvedEControls = helper.getInvolvedEObjects(
2644:                         ((LeagueImpl) league).eSetting(BowlingPackage.eINSTANCE.getLeague_Name()),
2645:                         "League", VControl.class);
2646:                 assertEquals(1, involvedEControls.size());
2647:         }
2648:
2649:         /**
2650:          * Test get involved e object change.
2651:          */
2652:         @Test
2653:         public void testGetInvolvedEObjectParentAffectedIfChildChanged() {
2654:                 // if the expected value equals the model value, then the control should be enabled
2655:
2656:                 addLeagueEnableRule(controlPName, true);
2657:                 setLeagueToRight();
2658:                 instantiateRuleService();
2659:                 final RuleServiceHelper helper = context.getService(RuleServiceHelper.class);
2660:
2661:                 final Set<VVerticalLayout> involvedColumns = helper.getInvolvedEObjects(
2662:                         ((LeagueImpl) league).eSetting(BowlingPackage.eINSTANCE.getLeague_Name()),
2663:                         "League2", VVerticalLayout.class);
2664:                 assertEquals(1, involvedColumns.size());
2665:         }
2666:
2667:         /**
2668:          * Test get involved e object change.
2669:          */
2670:         @Test
2671:         public void testGetInvolvedEObjectParentAffectedIfChildNotChanged() {
2672:                 // if the expected value equals the model value, then the control should be enabled
2673:
2674:                 addLeagueEnableRule(controlPName, true);
2675:                 setLeagueToRight();
2676:                 instantiateRuleService();
2677:                 final RuleServiceHelper helper = context.getService(RuleServiceHelper.class);
2678:
2679:                 final Set<VVerticalLayout> involvedColumns = helper.getInvolvedEObjects(
2680:                         ((LeagueImpl) league).eSetting(BowlingPackage.eINSTANCE.getLeague_Name()),
2681:                         "League", VVerticalLayout.class);
2682:                 assertEquals(0, involvedColumns.size());
2683:         }
2684:
2685:         /**
2686:          * Test get involved e object change.
2687:          */
2688:         @Test
2689:         public void testGetInvolvedEObjectWithVanishingRenderableShowRuleApplies() {
2690:                 // if the expected value equals the model value, then the control should be enabled
2691:
2692:                 addLeagueShowRule(parentColumn, true);
2693:                 setLeagueToRight();
2694:                 instantiateRuleService();
2695:                 final RuleServiceHelper helper = context.getService(RuleServiceHelper.class);
2696:
2697:                 final Set<VControl> involvedControls = helper.getInvolvedEObjects(
2698:                         ((LeagueImpl) league).eSetting(BowlingPackage.eINSTANCE.getLeague_Name()),
2699:                         "League2", VControl.class);
2700:                 assertEquals(1, involvedControls.size());
2701:                 assertTrue(involvedControls.contains(controlPName));
2702:         }
2703:
2704:         /**
2705:          * Test get involved e object change.
2706:          */
2707:         @Test
2708:         public void testGetInvolvedEObjectWithVanishingRenderableEnableRuleApplies() {
2709:                 addLeagueEnableRule(controlPName, true);
2710:
2711:                 setLeagueToRight();
2712:                 instantiateRuleService();
2713:                 final RuleServiceHelper helper = context.getService(RuleServiceHelper.class);
2714:
2715:                 final Set<VControl> involvedControls = helper.getInvolvedEObjects(
2716:                         ((LeagueImpl) league).eSetting(BowlingPackage.eINSTANCE.getLeague_Name()),
2717:                         "League2", VControl.class);
2718:                 assertEquals(1, involvedControls.size());
2719:                 assertTrue(involvedControls.contains(controlPName));
2720:         }
2721:
2722:         /**
2723:          * Test get involved e object change.
2724:          */
2725:         @Test
2726:         public void testGetInvolvedEObjectWithVanishingRenderableTwoRulesApply() {
2727:                 // if the expected value equals the model value, then the control should be enabled
2728:
2729:                 addLeagueEnableRule(controlPName, true);
2730:                 addLeagueShowRule(parentColumn, true);
2731:                 setLeagueToRight();
2732:                 instantiateRuleService();
2733:                 final RuleServiceHelper helper = context.getService(RuleServiceHelper.class);
2734:
2735:                 final Set<VControl> involvedControls = helper.getInvolvedEObjects(
2736:                         ((LeagueImpl) league).eSetting(BowlingPackage.eINSTANCE.getLeague_Name()),
2737:                         "League2", VControl.class);
2738:                 assertEquals(1, involvedControls.size());
2739:                 assertTrue(involvedControls.contains(controlPName));
2740:         }
2741:
2742:         @Test
2743:         public void testGetInvolvedWithUnrelatedChangeInMultiReference() {
2744:                 // domain
2745:                 final Staff staff = UniversityFactory.eINSTANCE.createStaff();
2746:                 final Assistant assistant = UniversityFactory.eINSTANCE.createAssistant();
2747:                 assistant.setName("Josef");
2748:                 final Professor professor = UniversityFactory.eINSTANCE.createProfessor();
2749:                 staff.getAssistants().add(assistant);
2750:                 staff.getProfessors().add(professor);
2751:
2752:                 // view
2753:                 view = VViewFactory.eINSTANCE.createView();
2754:                 final VControl wholeStaff = VViewFactory.eINSTANCE.createControl();
2755:                 wholeStaff.setDomainModelReference(UniversityPackage.eINSTANCE.getStaff_Staff());
2756:                 view.getChildren().add(wholeStaff);
2757:
2758:                 // rules
2759:                 final LeafCondition condition = setupLeafConditionWithValueDMR("Josef",
2760:                         UniversityPackage.eINSTANCE.getStaff_Assistants(), Collections.<EReference> emptyList(),
2761:                         UniversityPackage.eINSTANCE.getPerson_Name(), Collections.<EReference> emptyList());
2762:                 final ShowRule rule = RuleFactory.eINSTANCE.createShowRule();
2763:                 rule.setHide(false);
2764:                 rule.setCondition(condition);
2765:                 wholeStaff.getAttachments().add(rule);
2766:
2767:                 // init
2768:                 instantiateRuleService(staff);
2769:                 assertTrue(wholeStaff.isVisible());
2770:
2771:                 // act
2772:                 final RuleServiceHelper helper = context.getService(RuleServiceHelper.class);
2773:
2774:                 final List<Person> newValue = new ArrayList<Person>();
2775:                 newValue.add(EcoreUtil.copy(professor));
2776:                 newValue.get(0).setName("Hans");
2777:
2778:                 final Setting setting = ((StaffImpl) staff).eSetting(UniversityPackage.eINSTANCE.getStaff_Professors());
2779:
2780:                 final Set<VControl> involvedControls = helper.getInvolvedEObjects(setting, newValue, VControl.class);
2781:
2782:                 // assert
2783:                 assertTrue(wholeStaff.isVisible());
2784:                 assertTrue(involvedControls.isEmpty());
2785:
2786:                 professor.setName("Hans");
2787:                 assertTrue(wholeStaff.isVisible());
2788:
2789:         }
2790:
2791:         @Test
2792:         public void testGetInvolvedWithAndOrConditions() {
2793:                 // setup
2794:                 final Fan fan = BowlingFactory.eINSTANCE.createFan();
2795:                 fan.setHasSeasonTicket(true);
2796:                 fan.setNumberOfTournamentsVisited(2);
2797:
2798:                 final ShowRule rule = RuleFactory.eINSTANCE.createShowRule();
2799:                 final AndCondition andCondition = RuleFactory.eINSTANCE.createAndCondition();
2800:                 final LeafCondition seasonTicketCondition = RuleFactory.eINSTANCE.createLeafCondition();
2801:                 final VFeaturePathDomainModelReference seasonTicketDMR = VViewFactory.eINSTANCE
2802:                         .createFeaturePathDomainModelReference();
2803:                 seasonTicketDMR.setDomainModelEFeature(BowlingPackage.eINSTANCE.getFan_HasSeasonTicket());
2804:                 seasonTicketCondition.setDomainModelReference(seasonTicketDMR);
2805:                 seasonTicketCondition.setExpectedValue(true);
2806:                 andCondition.getConditions().add(seasonTicketCondition);
2807:                 final OrCondition orCondition = RuleFactory.eINSTANCE.createOrCondition();
2808:                 final LeafCondition visitedTwoLeafCondition = RuleFactory.eINSTANCE.createLeafCondition();
2809:                 final VFeaturePathDomainModelReference visitedTwoDMR = VViewFactory.eINSTANCE
2810:                         .createFeaturePathDomainModelReference();
2811:                 visitedTwoDMR.setDomainModelEFeature(BowlingPackage.eINSTANCE.getFan_NumberOfTournamentsVisited());
2812:                 visitedTwoLeafCondition.setDomainModelReference(visitedTwoDMR);
2813:                 visitedTwoLeafCondition.setExpectedValue(2);
2814:                 orCondition.getConditions().add(visitedTwoLeafCondition);
2815:                 final LeafCondition visitedThreeLeafCondition = RuleFactory.eINSTANCE.createLeafCondition();
2816:                 final VFeaturePathDomainModelReference visitedThreeDMR = VViewFactory.eINSTANCE
2817:                         .createFeaturePathDomainModelReference();
2818:                 visitedThreeDMR.setDomainModelEFeature(BowlingPackage.eINSTANCE.getFan_NumberOfTournamentsVisited());
2819:                 visitedThreeLeafCondition.setDomainModelReference(visitedThreeDMR);
2820:                 visitedThreeLeafCondition.setExpectedValue(3);
2821:                 orCondition.getConditions().add(visitedThreeLeafCondition);
2822:                 andCondition.getConditions().add(orCondition);
2823:                 rule.setCondition(andCondition);
2824:
2825:                 view = VViewFactory.eINSTANCE.createView();
2826:                 final VControl control = VViewFactory.eINSTANCE.createControl();
2827:                 control.setDomainModelReference(BowlingPackage.eINSTANCE.getFan_Gender());
2828:                 control.getAttachments().add(rule);
2829:                 view.getChildren().add(control);
2830:
2831:                 // init
2832:                 instantiateRuleService(fan);
2833:                 assertTrue(control.isVisible());
2834:
2835:                 // act
2836:                 final RuleServiceHelper helper = context.getService(RuleServiceHelper.class);
2837:                 final Setting setting = ((FanImpl) fan).eSetting(BowlingPackage.eINSTANCE.getFan_NumberOfTournamentsVisited());
2838:                 final Set<VControl> involvedControls = helper.getInvolvedEObjects(setting, 3, VControl.class);
2839:
2840:                 // assert
2841:                 assertTrue(involvedControls.isEmpty());
2842:         }
2843:
2844:         @Test
2845:         public void testRuleAndValidationForChildContext() {
2846:
2847:                 final Fan fan = BowlingFactory.eINSTANCE.createFan();
2848:                 final Merchandise merchandise = BowlingFactory.eINSTANCE.createMerchandise();
2849:                 fan.setFavouriteMerchandise(merchandise);
2850:
2851:                 // Fan
2852:                 final VView view1 = VViewFactory.eINSTANCE.createView();
2853:                 view1.setRootEClass(fan.eClass());
2854:
2855:                 final VControl control1 = VViewFactory.eINSTANCE.createControl();
2856:                 final VFeaturePathDomainModelReference domainModelReference = VViewFactory.eINSTANCE
2857:                         .createFeaturePathDomainModelReference();
2858:                 domainModelReference.setDomainModelEFeature(BowlingPackage.eINSTANCE.getFan_Gender());
2859:                 control1.setDomainModelReference(domainModelReference);
2860:                 view1.getChildren().add(control1);
2861:
2862:                 final ShowRule showRule = addShowRule(control1, false);
2863:                 showRule.setCondition(createLeafCondition(BowlingPackage.eINSTANCE.getMerchandise_Price(), new BigDecimal(5),
2864:                         BowlingPackage.eINSTANCE.getFan_FavouriteMerchandise()));
2865:
2866:                 // merchandise
2867:                 final VView view2 = VViewFactory.eINSTANCE.createView();
2868:                 view2.setRootEClass(merchandise.eClass());
2869:
2870:                 final VControl control2 = VViewFactory.eINSTANCE.createControl();
2871:                 final VFeaturePathDomainModelReference domainModelReference2 = VViewFactory.eINSTANCE
2872:                         .createFeaturePathDomainModelReference();
2873:                 domainModelReference2.setDomainModelEFeature(BowlingPackage.eINSTANCE.getMerchandise_Price());
2874:                 control2.setDomainModelReference(domainModelReference2);
2875:                 view2.getChildren().add(control2);
2876:
2877:                 final RuleService ruleService = new RuleService();
2878:                 final RuleServiceHelperImpl ruleServiceHelper = new RuleServiceHelperImpl();
2879:
2880:                 context = ViewModelContextFactory.INSTANCE.createViewModelContext(view2, merchandise);
2881:                 context.getChildContext(fan, view2, view1);
2882:
2883:                 ruleService.instantiate(context);
2884:                 ruleServiceHelper.instantiate(context);
2885:
2886:                 final ValidationService validationService = context.getService(ValidationService.class);
2887:                 final List<Boolean> validated = new ArrayList<Boolean>(1);
2888:
2889:                 validationService.addValidationProvider(new ValidationProvider() {
2890:
2891:                         @Override
2892:                         public List<Diagnostic> validate(EObject eObject) {
2893:                                 if (eObject == fan) {
2894:                                         validated.add(0, true);
2895:                                 }
2896:                                 return null;
2897:                         }
2898:                 });
2899:
2900:                 validated.add(0, false);
2901:                 merchandise.setPrice(new BigDecimal(5));
2902:                 assertTrue(validated.get(0));
2903:                 assertTrue(control1.isVisible());
2904:                 validated.add(0, false);
2905:                 merchandise.setPrice(new BigDecimal(55));
2906:                 assertFalse(control1.isVisible());
2907:                 assertTrue(validated.get(0));
2908:
2909:         }
2910:
2911:         @Test
2912:         @Ignore // Scenario is currently not supported
2913:         public void testRuleAndValidationForChildContextOnNonContainedAttribute() {
2914:
2915:                 final Game game = BowlingFactory.eINSTANCE.createGame();
2916:                 game.setPlayer(player);
2917:                 game.getFrames().add(1);
2918:
2919:                 // Game
2920:                 final VView view1 = VViewFactory.eINSTANCE.createView();
2921:                 view1.setRootEClass(game.eClass());
2922:
2923:                 final VControl control1 = VViewFactory.eINSTANCE.createControl();
2924:                 final VFeaturePathDomainModelReference domainModelReference = VViewFactory.eINSTANCE
2925:                         .createFeaturePathDomainModelReference();
2926:                 domainModelReference.setDomainModelEFeature(BowlingPackage.eINSTANCE.getGame_Frames());
2927:                 control1.setDomainModelReference(domainModelReference);
2928:                 view1.getChildren().add(control1);
2929:
2930:                 final ShowRule showRule = addShowRule(control1, false);
2931:                 showRule.setCondition(createLeafCondition(BowlingPackage.eINSTANCE.getPlayer_Name(), "foo",
2932:                         BowlingPackage.eINSTANCE.getGame_Player()));
2933:
2934:                 // player
2935:                 final VView view2 = VViewFactory.eINSTANCE.createView();
2936:                 view2.setRootEClass(player.eClass());
2937:
2938:                 final VControl control2 = VViewFactory.eINSTANCE.createControl();
2939:                 final VFeaturePathDomainModelReference domainModelReference2 = VViewFactory.eINSTANCE
2940:                         .createFeaturePathDomainModelReference();
2941:                 domainModelReference2.setDomainModelEFeature(BowlingPackage.eINSTANCE.getPlayer_Name());
2942:                 control2.setDomainModelReference(domainModelReference2);
2943:                 view2.getChildren().add(control2);
2944:
2945:                 final RuleService ruleService = new RuleService();
2946:                 final RuleServiceHelperImpl ruleServiceHelper = new RuleServiceHelperImpl();
2947:
2948:                 context = ViewModelContextFactory.INSTANCE.createViewModelContext(view1, game);
2949:                 context.getChildContext(player, view1, view2);
2950:
2951:                 ruleService.instantiate(context);
2952:                 ruleServiceHelper.instantiate(context);
2953:
2954:                 final ValidationService validationService = context.getService(ValidationService.class);
2955:
2956:                 final List<Boolean> validated = new ArrayList<Boolean>(1);
2957:
2958:                 validationService.addValidationProvider(new ValidationProvider() {
2959:
2960:                         @Override
2961:                         public List<Diagnostic> validate(EObject eObject) {
2962:                                 if (game == player) {
2963:                                         validated.add(0, true);
2964:                                 }
2965:                                 return null;
2966:                         }
2967:                 });
2968:
2969:                 validated.add(0, false);
2970:                 player.setName("foo");
2971:                 assertTrue(control1.isVisible());
2972:                 assertTrue(validated.get(0));
2973:
2974:                 validated.add(0, false);
2975:                 player.setName("bar");
2976:                 assertTrue(validated.get(0));
2977:                 assertFalse(control1.isVisible());
2978:
2979:         }
2980: }