Skip to content

Package: SettingToControlMapper_ITest

SettingToControlMapper_ITest

nameinstructionbranchcomplexitylinemethod
SettingToControlMapper_ITest()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
childContextDisposed()
M: 0 C: 131
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 29
100%
M: 0 C: 1
100%
childContextDisposed_533827_InfiniteLoop()
M: 0 C: 95
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 22
100%
M: 0 C: 1
100%
childContextDisposed_NoSetting()
M: 0 C: 47
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 12
100%
M: 0 C: 1
100%
childContextDomainModelChanged()
M: 0 C: 158
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 30
100%
M: 0 C: 1
100%
getControlsForChildContextAdd()
M: 0 C: 54
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 14
100%
M: 0 C: 1
100%
getControlsForChildContextPerformance()
M: 1 C: 118
99%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 0 C: 26
100%
M: 0 C: 1
100%
getControlsForDirectControlAdd()
M: 0 C: 25
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
getControlsForGrandChildContextAdd()
M: 0 C: 87
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 22
100%
M: 0 C: 1
100%
getEObjectsWithSettings_VElement()
M: 0 C: 155
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 33
100%
M: 0 C: 1
100%
hasMapping_UniqueSetting_VElement()
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
hasMapping_UniqueSetting_VElement(EMFFormsSettingToControlMapper)
M: 0 C: 83
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 16
100%
M: 0 C: 1
100%
hasMapping_default_UniqueSetting_VElement()
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
set(Object[])
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
setup()
M: 0 C: 65
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 12
100%
M: 0 C: 1
100%
updateMappingsConcurrently()
M: 0 C: 55
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 11
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2019 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: * Edgar Mueller - initial API and implementation
13: * Christian W. Damus - bugs 543190, 527686
14: ******************************************************************************/
15: package org.eclipse.emfforms.internal.core.services.scoped;
16:
17: import static org.hamcrest.CoreMatchers.anything;
18: import static org.hamcrest.CoreMatchers.hasItem;
19: import static org.hamcrest.CoreMatchers.hasItems;
20: import static org.hamcrest.CoreMatchers.is;
21: import static org.hamcrest.CoreMatchers.not;
22: import static org.hamcrest.MatcherAssert.assertThat;
23: import static org.junit.Assert.assertEquals;
24: import static org.junit.Assert.assertTrue;
25: import static org.mockito.Matchers.any;
26: import static org.mockito.Matchers.isA;
27: import static org.mockito.Matchers.same;
28: import static org.mockito.Mockito.mock;
29: import static org.mockito.Mockito.when;
30:
31: import java.text.MessageFormat;
32: import java.util.ArrayList;
33: import java.util.Arrays;
34: import java.util.Collection;
35: import java.util.Collections;
36: import java.util.LinkedHashSet;
37: import java.util.List;
38: import java.util.Set;
39: import java.util.concurrent.CountDownLatch;
40: import java.util.concurrent.ExecutorService;
41: import java.util.concurrent.Executors;
42:
43: import org.eclipse.emf.ecore.EAttribute;
44: import org.eclipse.emf.ecore.EClass;
45: import org.eclipse.emf.ecore.EObject;
46: import org.eclipse.emf.ecore.EcoreFactory;
47: import org.eclipse.emf.ecore.EcorePackage;
48: import org.eclipse.emf.ecore.util.EcoreUtil;
49: import org.eclipse.emf.ecp.common.spi.UniqueSetting;
50: import org.eclipse.emf.ecp.view.spi.model.VControl;
51: import org.eclipse.emf.ecp.view.spi.model.VDomainModelReference;
52: import org.eclipse.emf.ecp.view.spi.model.VElement;
53: import org.eclipse.emf.ecp.view.spi.model.VView;
54: import org.eclipse.emf.ecp.view.spi.model.VViewFactory;
55: import org.eclipse.emfforms.internal.core.services.controlmapper.SettingToControlMapperImpl;
56: import org.eclipse.emfforms.spi.core.services.controlmapper.EMFFormsSettingToControlMapper;
57: import org.eclipse.emfforms.spi.core.services.controlmapper.SubControlMapper;
58: import org.eclipse.emfforms.spi.core.services.mappingprovider.EMFFormsMappingProviderManager;
59: import org.junit.Before;
60: import org.junit.Test;
61: import org.mockito.invocation.InvocationOnMock;
62: import org.mockito.stubbing.Answer;
63:
64: public class SettingToControlMapper_ITest {
65:
66:         private static final int NR_UPDATES = 100;
67:         private static final int NR_RUNNABLES = 100;
68:
69:         private SettingToControlMapperImpl mapper;
70:         private EObject domainObject;
71:         private VControl control;
72:         private FakeViewContext context;
73:         private EMFFormsMappingProviderManager mappingManager;
74:
75:         @Before
76:         public void setup() {
77:                 final VView view = VViewFactory.eINSTANCE.createView();
78:                 control = VViewFactory.eINSTANCE.createControl();
79:                 control.setDomainModelReference(EcorePackage.eINSTANCE.getEClass_EAttributes());
80:                 view.getChildren().add(control);
81:                 domainObject = EcoreUtil.create(EcorePackage.eINSTANCE.getEClass());
82:                 context = new FakeViewContext(domainObject, view);
83:
84:                 mappingManager = mock(EMFFormsMappingProviderManager.class);
85:                 when(mappingManager.getAllSettingsFor(any(VDomainModelReference.class), isA(EClass.class)))
86:                         .then(new Answer<Set<UniqueSetting>>() {
87:
88:                                 @Override
89:                                 public Set<UniqueSetting> answer(InvocationOnMock invocation) throws Throwable {
90:                                         final Set<UniqueSetting> settings = new LinkedHashSet<UniqueSetting>();
91:                                         final Object[] arguments = invocation.getArguments();
92:                                         settings.add(
93:                                                 UniqueSetting.createSetting((EObject) arguments[1],
94:                                                         EcorePackage.eINSTANCE.getEClass_EAttributes()));
95:                                         settings.add(
96:                                                 UniqueSetting.createSetting((EObject) arguments[1],
97:                                                         EcorePackage.eINSTANCE.getEClass_EReferences()));
98:                                         return settings;
99:                                 }
100:                         });
101:                 mapper = new SettingToControlMapperImpl(mappingManager, context);
102:                 context.initialize();
103:         }
104:
105:         @Test
106:         public void updateMappingsConcurrently() throws InterruptedException {
107:                 // setup
108:                 final CountDownLatch latch = new CountDownLatch(NR_RUNNABLES);
109:
110:                 final List<Throwable> exceptions = Collections.synchronizedList(new ArrayList<Throwable>());
111:                 final ArrayList<Runnable> runnables = new ArrayList<Runnable>();
112:•                for (int i = 0; i < NR_RUNNABLES; i++) {
113:                         runnables.add(new Runnable() {
114:                                 @Override
115:                                 public void run() {
116:                                         try {
117:                                                 int j = 0;
118:                                                 while (j < NR_UPDATES) {
119:                                                         mapper.updateControlMapping(control);
120:                                                         Thread.sleep(1);
121:                                                         j += 1;
122:                                                 }
123:                                                 // BEGIN SUPRESS CATCH EXCEPTION
124:                                         } catch (final Exception exception) {
125:                                                 exceptions.add(exception);
126:                                                 // END SUPRESS CATCH EXCEPTION
127:                                         } finally {
128:                                                 latch.countDown();
129:                                         }
130:
131:                                 }
132:                         });
133:                 }
134:                 final ExecutorService newFixedThreadPool = Executors.newFixedThreadPool(runnables.size());
135:
136:                 // act
137:•                for (final Runnable runnable : runnables) {
138:                         newFixedThreadPool.submit(runnable);
139:                 }
140:
141:                 latch.await();
142:
143:                 // assert
144:                 assertTrue(exceptions.isEmpty());
145:         }
146:
147:         @Test
148:         public void getControlsForDirectControlAdd() {
149:                 mapper.vControlAdded(control);
150:                 final Set<VElement> controlsFor = mapper
151:                         .getControlsFor(UniqueSetting.createSetting(domainObject, EcorePackage.eINSTANCE.getEClass_EAttributes()));
152:                 assertEquals(1, controlsFor.size());
153:                 assertTrue(controlsFor.contains(control));
154:         }
155:
156:         @Test
157:         public void getControlsForChildContextAdd() {
158:                 final VView childView = VViewFactory.eINSTANCE.createView();
159:                 final VControl childControl = VViewFactory.eINSTANCE.createControl();
160:                 childControl.setDomainModelReference(EcorePackage.eINSTANCE.getEClass_EAttributes());
161:                 childView.getChildren().add(childControl);
162:                 final EObject childDomainObject = EcoreUtil.create(EcorePackage.eINSTANCE.getEClass());
163:                 final FakeViewContext childContext = new FakeViewContext(childDomainObject, childView);
164:                 context.addChildContext(control, childContext);
165:                 final Set<VElement> controlsFor = mapper
166:                         .getControlsFor(
167:                                 UniqueSetting.createSetting(childDomainObject, EcorePackage.eINSTANCE.getEClass_EAttributes()));
168:                 assertEquals(2, controlsFor.size());
169:                 assertTrue(controlsFor.contains(control));
170:                 assertTrue(controlsFor.contains(childControl));
171:         }
172:
173:         @Test
174:         public void childContextDisposed() {
175:                 // Add parent control to later verify that it is not illegally removed during child context disposal
176:                 mapper.vControlAdded(control);
177:
178:                 // Setup and add child context with one control and one setting
179:                 final VView childView = VViewFactory.eINSTANCE.createView();
180:                 final VControl childControl = VViewFactory.eINSTANCE.createControl();
181:                 childControl.setDomainModelReference(EcorePackage.eINSTANCE.getEClass_EAttributes());
182:                 childView.getChildren().add(childControl);
183:                 final EClass childDomainObject = EcoreFactory.eINSTANCE.createEClass();
184:                 childDomainObject.setName("child"); //$NON-NLS-1$
185:                 final FakeViewContext childContext = new FakeViewContext(childDomainObject, childView);
186:                 context.addChildContext(control, childContext);
187:
188:                 final UniqueSetting childSettingAttributes = UniqueSetting.createSetting(childDomainObject,
189:                         EcorePackage.eINSTANCE.getEClass_EAttributes());
190:                 final UniqueSetting childSettingReferences = UniqueSetting.createSetting(childDomainObject,
191:                         EcorePackage.eINSTANCE.getEClass_EReferences());
192:                 assertEquals(2, mapper.getControlsFor(childSettingAttributes).size());
193:                 assertEquals(2, mapper.getControlsFor(childSettingReferences).size());
194:
195:                 // Verification that add control and add child context work is done by other test cases.
196:                 context.removeChildContext(childContext);
197:
198:                 // Verify that the mapping for the child setting is empty
199:                 final Set<UniqueSetting> settingsForControl = mapper.getSettingsForControl(childControl);
200:                 assertEquals(0, settingsForControl.size());
201:
202:                 // Verify that after disposing the child context, the mapping from setting to parent control is also removed
203:                 assertEquals(0, mapper.getControlsFor(childSettingAttributes).size());
204:                 assertEquals(0, mapper.getControlsFor(childSettingReferences).size());
205:
206:                 final UniqueSetting parentSetting = UniqueSetting.createSetting(domainObject,
207:                         EcorePackage.eINSTANCE.getEClass_EAttributes());
208:
209:                 // Verify that disposing a child context does not clear the mapping of the parent's control
210:                 final Set<UniqueSetting> settingsForParentControl = mapper.getSettingsForControl(control);
211:                 assertEquals(2, settingsForParentControl.size());
212:                 assertTrue(settingsForParentControl.contains(parentSetting));
213:
214:                 // Verify that disposing a child context does not clear the mapping of the parent's setting
215:                 final Set<VElement> controlsForParentSetting = mapper.getControlsFor(parentSetting);
216:                 assertEquals(1, controlsForParentSetting.size());
217:                 assertTrue(controlsForParentSetting.contains(control));
218:         }
219:
220:         @Test
221:         public void childContextDisposed_NoSetting() {
222:                 // Add parent control to later verify that it is not illegally removed during child context disposal
223:                 mapper.vControlAdded(control);
224:
225:                 // Setup and add child context with one control and one setting
226:                 final VView childView = VViewFactory.eINSTANCE.createView();
227:                 final VControl childControl = VViewFactory.eINSTANCE.createControl();
228:                 childControl.setDomainModelReference(EcorePackage.eINSTANCE.getEClass_EAttributes());
229:                 childView.getChildren().add(childControl);
230:                 final EClass childDomainObject = EcoreFactory.eINSTANCE.createEClass();
231:                 childDomainObject.setName("child"); //$NON-NLS-1$
232:                 final FakeViewContext childContext = new FakeViewContext(childDomainObject, childView);
233:                 context.addChildContext(control, childContext);
234:
235:                 mapper.vControlRemoved(childControl);
236:                 context.removeChildContext(childContext);
237:
238:         }
239:
240:         @Test
241:         public void getControlsForGrandChildContextAdd() {
242:                 final VView childView = VViewFactory.eINSTANCE.createView();
243:                 final VControl childControl = VViewFactory.eINSTANCE.createControl();
244:                 childControl.setDomainModelReference(EcorePackage.eINSTANCE.getEClass_EAttributes());
245:                 childView.getChildren().add(childControl);
246:                 final EObject childDomainObject = EcoreUtil.create(EcorePackage.eINSTANCE.getEClass());
247:                 final FakeViewContext childContext = new FakeViewContext(childDomainObject, childView);
248:                 context.addChildContext(control, childContext);
249:
250:                 final VView grandChildView = VViewFactory.eINSTANCE.createView();
251:                 final VControl grandChildControl = VViewFactory.eINSTANCE.createControl();
252:                 grandChildControl.setDomainModelReference(EcorePackage.eINSTANCE.getEClass_EAttributes());
253:                 grandChildView.getChildren().add(grandChildControl);
254:                 final EObject grandChildDomainObject = EcoreUtil.create(EcorePackage.eINSTANCE.getEClass());
255:                 final FakeViewContext grandChildContext = new FakeViewContext(grandChildDomainObject, grandChildView);
256:                 childContext.addChildContext(childControl, grandChildContext);
257:
258:                 final Set<VElement> controlsFor = mapper
259:                         .getControlsFor(
260:                                 UniqueSetting.createSetting(grandChildDomainObject, EcorePackage.eINSTANCE.getEClass_EAttributes()));
261:                 assertEquals(3, controlsFor.size());
262:                 assertTrue(controlsFor.contains(control));
263:                 assertTrue(controlsFor.contains(childControl));
264:                 assertTrue(controlsFor.contains(grandChildControl));
265:         }
266:
267:         @Test
268:         public void getControlsForChildContextPerformance() {
269:
270:•                for (int i = 0; i < 4999; i++) {
271:                         final VView childView = VViewFactory.eINSTANCE.createView();
272:                         final VControl childControl = VViewFactory.eINSTANCE.createControl();
273:                         childControl.setDomainModelReference(EcorePackage.eINSTANCE.getEClass_EAttributes());
274:                         childView.getChildren().add(childControl);
275:                         final EObject childDomainObject = EcoreUtil.create(EcorePackage.eINSTANCE.getEClass());
276:                         final FakeViewContext childContext = new FakeViewContext(childDomainObject, childView);
277:                         context.addChildContext(control, childContext);
278:                 }
279:                 final VView childView = VViewFactory.eINSTANCE.createView();
280:                 final VControl childControl = VViewFactory.eINSTANCE.createControl();
281:                 childControl.setDomainModelReference(EcorePackage.eINSTANCE.getEClass_EAttributes());
282:                 childView.getChildren().add(childControl);
283:                 final EObject childDomainObject = EcoreUtil.create(EcorePackage.eINSTANCE.getEClass());
284:                 final FakeViewContext childContext = new FakeViewContext(childDomainObject, childView);
285:                 context.addChildContext(control, childContext);
286:                 final long startTime = System.nanoTime();
287:                 final Set<VElement> controlsFor = mapper
288:                         .getControlsFor(
289:                                 UniqueSetting.createSetting(childDomainObject, EcorePackage.eINSTANCE.getEClass_EAttributes()));
290:                 final long endTime = System.nanoTime();
291:                 assertEquals(2, controlsFor.size());
292:                 assertTrue(controlsFor.contains(control));
293:                 assertTrue(controlsFor.contains(childControl));
294:                 final long durationYs = (endTime - startTime) / 1000;
295:                 // half a millisecond should be more then enough time
296:•                assertTrue(MessageFormat.format("Duration was {0}.", durationYs), durationYs < 500); //$NON-NLS-1$
297:         }
298:
299:         @Test
300:         public void childContextDisposed_533827_InfiniteLoop() {
301:                 // Add parent control to later verify that it is not illegally removed during child context disposal
302:                 mapper.vControlAdded(control);
303:
304:                 // Setup and add child context with one control and one setting
305:                 final VView childView = VViewFactory.eINSTANCE.createView();
306:                 final VControl childControl = VViewFactory.eINSTANCE.createControl();
307:                 childControl.setDomainModelReference(EcorePackage.eINSTANCE.getEClass_EAttributes());
308:                 childView.getChildren().add(childControl);
309:                 final EClass childDomainObject = EcoreFactory.eINSTANCE.createEClass();
310:                 childDomainObject.setName("child"); //$NON-NLS-1$
311:                 final Set<UniqueSetting> uniqueSettings = Collections.emptySet();
312:                 when(mappingManager.getAllSettingsFor(same(childControl.getDomainModelReference()), any(EObject.class)))
313:                         .thenReturn(uniqueSettings);
314:                 final FakeViewContext childContext = new FakeViewContext(childDomainObject, childView);
315:                 context.addChildContext(control, childContext);
316:
317:                 // Verification that add control and add child context work is done by other test cases.
318:                 // mapper.vControlRemoved(childControl);
319:                 context.removeChildContext(childContext);
320:
321:                 final UniqueSetting parentSetting = UniqueSetting.createSetting(domainObject,
322:                         EcorePackage.eINSTANCE.getEClass_EAttributes());
323:
324:                 // Verify that disposing a child context does not clear the mapping of the parent's control
325:                 final Set<UniqueSetting> settingsForParentControl = mapper.getSettingsForControl(control);
326:                 assertEquals(2, settingsForParentControl.size());
327:                 assertTrue(settingsForParentControl.contains(parentSetting));
328:
329:                 // Verify that disposing a child context does not clear the mapping of the parent's setting
330:                 final Set<VElement> controlsForParentSetting = mapper.getControlsFor(parentSetting);
331:                 assertEquals(1, controlsForParentSetting.size());
332:                 assertTrue(controlsForParentSetting.contains(control));
333:         }
334:
335:         /**
336:          * Test case for {@link SubControlMapper#getEObjectsWithSettings(VElement)} implementation.
337:          */
338:         @Test
339:         @SuppressWarnings("nls")
340:         public void getEObjectsWithSettings_VElement() {
341:                 // Create a child view for the EClass showing the name of its ID attribute
342:                 // and the name of that ID attribute's type. These are two objects, one
343:                 // contained and one not, that are presented by the child context
344:                 final VView childView = VViewFactory.eINSTANCE.createView();
345:                 final VControl attributeControl = VViewFactory.eINSTANCE.createControl();
346:                 attributeControl.setDomainModelReference(EcorePackage.Literals.ENAMED_ELEMENT__NAME);
347:                 childView.getChildren().add(attributeControl);
348:                 final VControl isIdControl = VViewFactory.eINSTANCE.createControl();
349:                 isIdControl.setDomainModelReference(EcorePackage.Literals.EATTRIBUTE__ID);
350:                 childView.getChildren().add(isIdControl); // This one doesn't add anything interesting
351:                 final VControl typeNameControl = VViewFactory.eINSTANCE.createControl();
352:                 typeNameControl.setDomainModelReference(EcorePackage.Literals.ENAMED_ELEMENT__NAME,
353:                         Arrays.asList(EcorePackage.Literals.EATTRIBUTE__EATTRIBUTE_TYPE));
354:                 childView.getChildren().add(typeNameControl);
355:
356:                 final EAttribute idAttribute = EcoreFactory.eINSTANCE.createEAttribute();
357:                 idAttribute.setName("id");
358:                 idAttribute.setID(true);
359:                 idAttribute.setEType(EcorePackage.Literals.ESTRING);
360:                 ((EClass) domainObject).getEStructuralFeatures().add(idAttribute);
361:
362:                 // Update mocking for the new DMRs
363:                 when(mappingManager.getAllSettingsFor(attributeControl.getDomainModelReference(),
364:                         idAttribute))
365:                                 .thenReturn(set(UniqueSetting.createSetting(idAttribute, EcorePackage.Literals.ENAMED_ELEMENT__NAME)));
366:                 when(mappingManager.getAllSettingsFor(isIdControl.getDomainModelReference(),
367:                         idAttribute))
368:                                 .thenReturn(
369:                                         set(UniqueSetting.createSetting(idAttribute, EcorePackage.Literals.EATTRIBUTE__EATTRIBUTE_TYPE)));
370:                 when(mappingManager.getAllSettingsFor(typeNameControl.getDomainModelReference(),
371:                         idAttribute))
372:                                 .thenReturn(set(UniqueSetting.createSetting(EcorePackage.Literals.ESTRING,
373:                                         EcorePackage.Literals.ENAMED_ELEMENT__NAME)));
374:
375:                 final FakeViewContext childContext = new FakeViewContext(idAttribute, childView);
376:                 context.addChildContext(control, childContext);
377:                 final Collection<EObject> objects = mapper.getEObjectsWithSettings(childView);
378:                 assertThat("Wrong number of objects in child context", objects.size(), is(2));
379:                 assertThat(objects, hasItems(idAttribute, EcorePackage.Literals.ESTRING));
380:         }
381:
382:         /**
383:          * Verify that we can handle the reuse of a child context and its controls for
384:          * another domain model object.
385:          */
386:         @SuppressWarnings("nls")
387:         @Test
388:         public void childContextDomainModelChanged() {
389:                 // Setup and add child context with one control and one setting
390:                 final VView childView = VViewFactory.eINSTANCE.createView();
391:                 final VControl childControl = VViewFactory.eINSTANCE.createControl();
392:                 childControl.setDomainModelReference(EcorePackage.Literals.ECLASS__EATTRIBUTES);
393:                 childView.getChildren().add(childControl);
394:                 final EClass childDomainObject1 = EcoreFactory.eINSTANCE.createEClass();
395:                 childDomainObject1.setName("Child1");
396:                 final EClass childDomainObject2 = EcoreFactory.eINSTANCE.createEClass();
397:                 childDomainObject2.setName("Child2");
398:
399:                 final FakeViewContext childContext = new FakeViewContext(childDomainObject1, childView);
400:                 context.addChildContext(control, childContext);
401:
402:                 final UniqueSetting child1SettingAttributes = UniqueSetting.createSetting(childDomainObject1,
403:                         EcorePackage.Literals.ECLASS__EATTRIBUTES);
404:                 final UniqueSetting child1SettingReferences = UniqueSetting.createSetting(childDomainObject1,
405:                         EcorePackage.Literals.ECLASS__EREFERENCES);
406:                 assertThat(mapper.getControlsFor(child1SettingAttributes).size(), is(2));
407:                 assertThat(mapper.getControlsFor(child1SettingReferences).size(), is(2));
408:
409:                 // Verification that add control and add child context work is done by other test cases.
410:
411:                 // Change the domain model in the child context
412:                 childContext.changeDomainModel(childDomainObject2);
413:
414:                 // Verify that the mappings are now for the other object
415:                 final Set<UniqueSetting> settingsForControl = mapper.getSettingsForControl(childControl);
416:                 assertThat(settingsForControl.size(), is(2));
417:
418:                 final UniqueSetting child2SettingAttributes = UniqueSetting.createSetting(childDomainObject2,
419:                         EcorePackage.eINSTANCE.getEClass_EAttributes());
420:                 final UniqueSetting child2SettingReferences = UniqueSetting.createSetting(childDomainObject2,
421:                         EcorePackage.eINSTANCE.getEClass_EReferences());
422:                 assertThat(settingsForControl, hasItems(child2SettingAttributes, child2SettingReferences));
423:                 assertThat(mapper.getControlsFor(child2SettingAttributes).size(), is(2));
424:                 assertThat(mapper.getControlsFor(child2SettingReferences).size(), is(2));
425:                 assertThat(mapper.getControlsFor(child2SettingAttributes), hasItems(control, childControl));
426:
427:                 // There's nothing now for the original object
428:                 assertThat(mapper.getControlsFor(child1SettingAttributes), not(hasItem(anything())));
429:                 assertThat(mapper.getControlsFor(child1SettingReferences), not(hasItem(anything())));
430:         }
431:
432:         /**
433:          * Verify the {@link EMFFormsSettingToControlMapper#hasMapping(UniqueSetting, VElement)}
434:          * implementation.
435:          */
436:         @Test
437:         public void hasMapping_UniqueSetting_VElement() {
438:                 hasMapping_UniqueSetting_VElement(mapper);
439:         }
440:
441:         @SuppressWarnings("nls")
442:         private void hasMapping_UniqueSetting_VElement(EMFFormsSettingToControlMapper mapper) {
443:                 // Setup and add child context with one control and one setting
444:                 final VView childView = VViewFactory.eINSTANCE.createView();
445:                 final VControl childControl = VViewFactory.eINSTANCE.createControl();
446:                 childControl.setDomainModelReference(EcorePackage.Literals.ECLASS__EATTRIBUTES);
447:                 childView.getChildren().add(childControl);
448:                 final EClass childDomainObject = EcoreFactory.eINSTANCE.createEClass();
449:                 childDomainObject.setName("Child");
450:
451:                 final FakeViewContext childContext = new FakeViewContext(childDomainObject, childView);
452:                 context.addChildContext(control, childContext);
453:
454:                 final UniqueSetting childSetting = UniqueSetting.createSetting(childDomainObject,
455:                         EcorePackage.Literals.ECLASS__EATTRIBUTES);
456:
457:                 assertThat("No child mapping", mapper.hasMapping(childSetting, childControl), is(true));
458:                 assertThat("No parent mapping", mapper.hasMapping(childSetting, control), is(true));
459:
460:                 context.removeChildContext(childContext);
461:
462:                 assertThat("Still have child mapping", mapper.hasMapping(childSetting, childControl), is(false));
463:                 assertThat("Still have parent mapping", mapper.hasMapping(childSetting, control), is(false));
464:         }
465:
466:         /**
467:          * Verify the {@link EMFFormsSettingToControlMapper#hasMapping(UniqueSetting, VElement)}
468:          * default method.
469:          */
470:         @Test
471:         public void hasMapping_default_UniqueSetting_VElement() {
472:                 hasMapping_UniqueSetting_VElement(new InterfaceDelegator(mapper));
473:         }
474:
475:         //
476:         // Test framework
477:         //
478:
479:         @SafeVarargs
480:         static <T> Set<T> set(T... elements) {
481:                 return new LinkedHashSet<>(Arrays.asList(elements));
482:         }
483:
484: }