Skip to content

Package: KeyAttributeDomainModelReferenceConverter_Test

KeyAttributeDomainModelReferenceConverter_Test

nameinstructionbranchcomplexitylinemethod
KeyAttributeDomainModelReferenceConverter_Test()
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%
createValidEObject()
M: 5 C: 36
88%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 9
90%
M: 0 C: 1
100%
setUp()
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
setupClass()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
tearDown()
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
testConvertToListProperty()
M: 0 C: 93
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 24
100%
M: 0 C: 1
100%
testConvertToListPropertyDMRNull()
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
testConvertToListPropertyNoFeature()
M: 7 C: 63
90%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 17
89%
M: 0 C: 1
100%
testConvertToListPropertyNoReferencePath()
M: 0 C: 87
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 23
100%
M: 0 C: 1
100%
testConvertToListPropertyObjectNull()
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
testConvertToListPropertyWrongReferenceType()
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
testConvertToValueProperty()
M: 0 C: 93
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 23
100%
M: 0 C: 1
100%
testConvertToValuePropertyDMRNull()
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
testConvertToValuePropertyNoFeature()
M: 7 C: 63
90%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 17
89%
M: 0 C: 1
100%
testConvertToValuePropertyNoReferencePath()
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%
testConvertToValuePropertyObjectNull()
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
testConvertToValuePropertyWrongReferenceType()
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
testGetSettingKeyNotPresent()
M: 9 C: 129
93%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 3 C: 34
92%
M: 0 C: 1
100%
testGetSettingKeyPresent()
M: 0 C: 143
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 38
100%
M: 0 C: 1
100%
testGetSettingObjectNull()
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
testGetSettingReferenceNull()
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
testGetSettingWrongReferenceType()
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
testIsApplicable()
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
testIsApplicableNullReference()
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
testIsApplicableWrongReferenceType()
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2016 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: * Lucas Koehler - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emfforms.internal.core.services.databinding.keyattribute;
15:
16: import static org.junit.Assert.assertEquals;
17: import static org.mockito.Mockito.mock;
18: import static org.mockito.Mockito.when;
19:
20: import org.eclipse.emf.common.command.BasicCommandStack;
21: import org.eclipse.emf.common.util.URI;
22: import org.eclipse.emf.databinding.EMFProperties;
23: import org.eclipse.emf.databinding.IEMFListProperty;
24: import org.eclipse.emf.databinding.IEMFValueProperty;
25: import org.eclipse.emf.ecore.EObject;
26: import org.eclipse.emf.ecore.EStructuralFeature.Setting;
27: import org.eclipse.emf.ecore.EcoreFactory;
28: import org.eclipse.emf.ecore.InternalEObject;
29: import org.eclipse.emf.ecore.resource.Resource;
30: import org.eclipse.emf.ecore.resource.ResourceSet;
31: import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
32: import org.eclipse.emf.ecp.test.common.DefaultRealm;
33: import org.eclipse.emf.ecp.view.spi.keyattributedmr.model.VKeyAttributeDomainModelReference;
34: import org.eclipse.emf.ecp.view.spi.keyattributedmr.model.VKeyattributedmrFactory;
35: import org.eclipse.emf.ecp.view.spi.model.VFeaturePathDomainModelReference;
36: import org.eclipse.emf.ecp.view.spi.model.VViewFactory;
37: import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
38: import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
39: import org.eclipse.emfforms.core.services.databinding.testmodel.test.model.A;
40: import org.eclipse.emfforms.core.services.databinding.testmodel.test.model.B;
41: import org.eclipse.emfforms.core.services.databinding.testmodel.test.model.C;
42: import org.eclipse.emfforms.core.services.databinding.testmodel.test.model.D;
43: import org.eclipse.emfforms.core.services.databinding.testmodel.test.model.TestFactory;
44: import org.eclipse.emfforms.core.services.databinding.testmodel.test.model.TestPackage;
45: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedException;
46: import org.eclipse.emfforms.spi.core.services.databinding.DomainModelReferenceConverter;
47: import org.eclipse.emfforms.spi.core.services.databinding.emf.EMFFormsDatabindingEMF;
48: import org.junit.After;
49: import org.junit.Before;
50: import org.junit.BeforeClass;
51: import org.junit.Test;
52:
53: /**
54: * JUnit test cases for {@link KeyAttributeDomainModelReferenceConverter}.
55: *
56: * @author Lucas Koehler
57: *
58: */
59: public class KeyAttributeDomainModelReferenceConverter_Test {
60:
61:         private static final String WRONG_TEST_KEY = "WrongTestKey"; //$NON-NLS-1$
62:
63:         private static final String CORRECT_TEST_KEY = "CorrectTestKey"; //$NON-NLS-1$
64:
65:         private static EObject validEObject;
66:
67:         private KeyAttributeDomainModelReferenceConverter converter;
68:
69:         @BeforeClass
70:         public static void setupClass() {
71:                 validEObject = createValidEObject();
72:         }
73:
74:         private static EObject createValidEObject() {
75:                 final ResourceSet rs = new ResourceSetImpl();
76:                 final AdapterFactoryEditingDomain domain = new AdapterFactoryEditingDomain(
77:                         new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE),
78:                         new BasicCommandStack(), rs);
79:                 rs.eAdapters().add(new AdapterFactoryEditingDomain.EditingDomainProvider(domain));
80:                 final Resource resource = rs.createResource(URI.createURI("VIRTAUAL_URI")); //$NON-NLS-1$
81:                 final EObject domainObject = EcoreFactory.eINSTANCE.createEObject();
82:•                if (resource != null) {
83:                         resource.getContents().add(domainObject);
84:                 }
85:                 return domainObject;
86:         }
87:
88:         /**
89:          * @throws java.lang.Exception
90:          */
91:         @Before
92:         public void setUp() throws Exception {
93:                 converter = new KeyAttributeDomainModelReferenceConverter();
94:         }
95:
96:         /**
97:          * @throws java.lang.Exception
98:          */
99:         @After
100:         public void tearDown() throws Exception {
101:         }
102:
103:         /**
104:          * Test method for
105:          * {@link org.eclipse.emfforms.internal.core.services.databinding.keyattribute.KeyAttributeDomainModelReferenceConverter#convertToValueProperty(org.eclipse.emf.ecp.view.spi.model.VDomainModelReference, org.eclipse.emf.ecore.EObject)}
106:          * .
107:          *
108:          * @throws DatabindingFailedException
109:          */
110:         @Test
111:         public void testConvertToValueProperty() throws DatabindingFailedException {
112:                 final VKeyAttributeDomainModelReference keyAttributeDMR = VKeyattributedmrFactory.eINSTANCE
113:                         .createKeyAttributeDomainModelReference();
114:                 final VFeaturePathDomainModelReference keyDMR = VViewFactory.eINSTANCE.createFeaturePathDomainModelReference();
115:                 final VFeaturePathDomainModelReference valueDMR = VViewFactory.eINSTANCE
116:                         .createFeaturePathDomainModelReference();
117:
118:                 keyAttributeDMR.setKeyValue(CORRECT_TEST_KEY);
119:                 keyAttributeDMR.getDomainModelEReferencePath().add(TestPackage.eINSTANCE.getA_B());
120:                 keyAttributeDMR.setDomainModelEFeature(TestPackage.eINSTANCE.getB_CList());
121:
122:                 keyDMR.getDomainModelEReferencePath().add(TestPackage.eINSTANCE.getC_D());
123:                 keyDMR.setDomainModelEFeature(TestPackage.eINSTANCE.getD_X());
124:
125:                 valueDMR.getDomainModelEReferencePath().add(TestPackage.eINSTANCE.getC_A());
126:                 valueDMR.setDomainModelEFeature(TestPackage.eINSTANCE.getA_B());
127:
128:                 keyAttributeDMR.setKeyDMR(keyDMR);
129:                 keyAttributeDMR.setValueDMR(valueDMR);
130:
131:                 IEMFValueProperty targetValueProperty = EMFProperties.value(TestPackage.eINSTANCE.getC_A());
132:                 targetValueProperty = targetValueProperty.value(TestPackage.eINSTANCE.getA_B());
133:
134:                 final EMFFormsDatabindingEMF emfFormsDatabinding = mock(EMFFormsDatabindingEMF.class);
135:                 when(emfFormsDatabinding.getValueProperty(valueDMR, TestPackage.Literals.C)).thenReturn(targetValueProperty);
136:
137:                 converter.setEMFFormsDatabinding(emfFormsDatabinding);
138:
139:                 final IEMFValueProperty resultValueProperty = converter.convertToValueProperty(keyAttributeDMR, validEObject);
140:
141:                 final String expected = String.format("A.b<B> => B.cList<C> key '%s' => C.a<A> => A.b<B>", CORRECT_TEST_KEY); //$NON-NLS-1$
142:                 assertEquals(expected, resultValueProperty.toString());
143:         }
144:
145:         /**
146:          * Test method for
147:          * {@link org.eclipse.emfforms.internal.core.services.databinding.keyattribute.KeyAttributeDomainModelReferenceConverter#convertToValueProperty(org.eclipse.emf.ecp.view.spi.model.VDomainModelReference, org.eclipse.emf.ecore.EObject)}
148:          * .
149:          *
150:          * @throws DatabindingFailedException
151:          */
152:         @Test
153:         public void testConvertToValuePropertyNoReferencePath() throws DatabindingFailedException {
154:                 final VKeyAttributeDomainModelReference keyAttributeDMR = VKeyattributedmrFactory.eINSTANCE
155:                         .createKeyAttributeDomainModelReference();
156:                 final VFeaturePathDomainModelReference keyDMR = VViewFactory.eINSTANCE.createFeaturePathDomainModelReference();
157:                 final VFeaturePathDomainModelReference valueDMR = VViewFactory.eINSTANCE
158:                         .createFeaturePathDomainModelReference();
159:
160:                 keyAttributeDMR.setKeyValue(CORRECT_TEST_KEY);
161:                 keyAttributeDMR.setDomainModelEFeature(TestPackage.eINSTANCE.getB_CList());
162:
163:                 keyDMR.getDomainModelEReferencePath().add(TestPackage.eINSTANCE.getC_D());
164:                 keyDMR.setDomainModelEFeature(TestPackage.eINSTANCE.getD_X());
165:
166:                 valueDMR.getDomainModelEReferencePath().add(TestPackage.eINSTANCE.getC_A());
167:                 valueDMR.setDomainModelEFeature(TestPackage.eINSTANCE.getA_B());
168:
169:                 keyAttributeDMR.setKeyDMR(keyDMR);
170:                 keyAttributeDMR.setValueDMR(valueDMR);
171:
172:                 IEMFValueProperty targetValueProperty = EMFProperties.value(TestPackage.eINSTANCE.getC_A());
173:                 targetValueProperty = targetValueProperty.value(TestPackage.eINSTANCE.getA_B());
174:
175:                 final EMFFormsDatabindingEMF emfFormsDatabinding = mock(EMFFormsDatabindingEMF.class);
176:                 when(emfFormsDatabinding.getValueProperty(valueDMR, TestPackage.Literals.C)).thenReturn(targetValueProperty);
177:
178:                 converter.setEMFFormsDatabinding(emfFormsDatabinding);
179:
180:                 final IEMFValueProperty resultValueProperty = converter.convertToValueProperty(keyAttributeDMR, validEObject);
181:
182:                 final String expected = String.format("B.cList<C> key '%s' => C.a<A> => A.b<B>", CORRECT_TEST_KEY); //$NON-NLS-1$
183:                 assertEquals(expected, resultValueProperty.toString());
184:         }
185:
186:         /**
187:          * Test method for
188:          * {@link org.eclipse.emfforms.internal.core.services.databinding.keyattribute.KeyAttributeDomainModelReferenceConverter#convertToValueProperty(org.eclipse.emf.ecp.view.spi.model.VDomainModelReference, org.eclipse.emf.ecore.EObject)}
189:          * .
190:          *
191:          * @throws DatabindingFailedException
192:          */
193:         @Test(expected = DatabindingFailedException.class)
194:         public void testConvertToValuePropertyNoFeature() throws DatabindingFailedException {
195:                 final VKeyAttributeDomainModelReference keyAttributeDMR = VKeyattributedmrFactory.eINSTANCE
196:                         .createKeyAttributeDomainModelReference();
197:                 final VFeaturePathDomainModelReference keyDMR = VViewFactory.eINSTANCE.createFeaturePathDomainModelReference();
198:                 final VFeaturePathDomainModelReference valueDMR = VViewFactory.eINSTANCE
199:                         .createFeaturePathDomainModelReference();
200:
201:                 keyAttributeDMR.setKeyValue(CORRECT_TEST_KEY);
202:
203:                 keyDMR.getDomainModelEReferencePath().add(TestPackage.eINSTANCE.getC_D());
204:                 keyDMR.setDomainModelEFeature(TestPackage.eINSTANCE.getD_X());
205:
206:                 valueDMR.getDomainModelEReferencePath().add(TestPackage.eINSTANCE.getC_A());
207:                 valueDMR.setDomainModelEFeature(TestPackage.eINSTANCE.getA_B());
208:
209:                 keyAttributeDMR.setKeyDMR(keyDMR);
210:                 keyAttributeDMR.setValueDMR(valueDMR);
211:
212:                 IEMFValueProperty targetValueProperty = EMFProperties.value(TestPackage.eINSTANCE.getC_A());
213:                 targetValueProperty = targetValueProperty.value(TestPackage.eINSTANCE.getA_B());
214:
215:                 final EMFFormsDatabindingEMF emfFormsDatabinding = mock(EMFFormsDatabindingEMF.class);
216:                 when(emfFormsDatabinding.getValueProperty(valueDMR, validEObject)).thenReturn(targetValueProperty);
217:
218:                 converter.setEMFFormsDatabinding(emfFormsDatabinding);
219:
220:                 converter.convertToValueProperty(keyAttributeDMR, validEObject);
221:         }
222:
223:         /**
224:          * Test method for
225:          * {@link org.eclipse.emfforms.internal.core.services.databinding.keyattribute.KeyAttributeDomainModelReferenceConverter#convertToValueProperty(org.eclipse.emf.ecp.view.spi.model.VDomainModelReference, org.eclipse.emf.ecore.EObject)}
226:          * .
227:          *
228:          * @throws DatabindingFailedException
229:          */
230:         @Test(expected = IllegalArgumentException.class)
231:         public void testConvertToValuePropertyDMRNull() throws DatabindingFailedException {
232:                 converter.convertToValueProperty(null, validEObject);
233:         }
234:
235:         /**
236:          * Test method for
237:          * {@link org.eclipse.emfforms.internal.core.services.databinding.keyattribute.KeyAttributeDomainModelReferenceConverter#convertToValueProperty(org.eclipse.emf.ecp.view.spi.model.VDomainModelReference, org.eclipse.emf.ecore.EObject)}
238:          * .
239:          *
240:          * @throws DatabindingFailedException
241:          */
242:         @Test(expected = DatabindingFailedException.class)
243:         public void testConvertToValuePropertyObjectNull() throws DatabindingFailedException {
244:                 converter.convertToValueProperty(mock(VKeyAttributeDomainModelReference.class), null);
245:         }
246:
247:         /**
248:          * Test method for
249:          * {@link org.eclipse.emfforms.internal.core.services.databinding.keyattribute.KeyAttributeDomainModelReferenceConverter#convertToValueProperty(org.eclipse.emf.ecp.view.spi.model.VDomainModelReference, org.eclipse.emf.ecore.EObject)}
250:          * .
251:          *
252:          * @throws DatabindingFailedException
253:          */
254:         @Test(expected = IllegalArgumentException.class)
255:         public void testConvertToValuePropertyWrongReferenceType() throws DatabindingFailedException {
256:                 converter.convertToValueProperty(mock(VFeaturePathDomainModelReference.class), validEObject);
257:         }
258:
259:         /**
260:          * Test method for
261:          * {@link org.eclipse.emfforms.internal.core.services.databinding.keyattribute.KeyAttributeDomainModelReferenceConverter#convertToListProperty(org.eclipse.emf.ecp.view.spi.model.VDomainModelReference, org.eclipse.emf.ecore.EObject)}
262:          * .
263:          *
264:          * @throws DatabindingFailedException
265:          */
266:         @Test
267:         public void testConvertToListProperty() throws DatabindingFailedException {
268:                 final VKeyAttributeDomainModelReference keyAttributeDMR = VKeyattributedmrFactory.eINSTANCE
269:                         .createKeyAttributeDomainModelReference();
270:                 final VFeaturePathDomainModelReference keyDMR = VViewFactory.eINSTANCE.createFeaturePathDomainModelReference();
271:                 final VFeaturePathDomainModelReference valueDMR = VViewFactory.eINSTANCE
272:                         .createFeaturePathDomainModelReference();
273:
274:                 keyAttributeDMR.setKeyValue(CORRECT_TEST_KEY);
275:                 keyAttributeDMR.getDomainModelEReferencePath().add(TestPackage.eINSTANCE.getA_B());
276:                 keyAttributeDMR.setDomainModelEFeature(TestPackage.eINSTANCE.getB_CList());
277:
278:                 keyDMR.getDomainModelEReferencePath().add(TestPackage.eINSTANCE.getC_D());
279:                 keyDMR.setDomainModelEFeature(TestPackage.eINSTANCE.getD_X());
280:
281:                 valueDMR.getDomainModelEReferencePath().add(TestPackage.eINSTANCE.getC_D());
282:                 valueDMR.setDomainModelEFeature(TestPackage.eINSTANCE.getD_YList());
283:
284:                 keyAttributeDMR.setKeyDMR(keyDMR);
285:                 keyAttributeDMR.setValueDMR(valueDMR);
286:
287:                 final IEMFValueProperty targetValueProperty = EMFProperties.value(TestPackage.eINSTANCE.getC_D());
288:                 final IEMFListProperty targetListProperty = targetValueProperty.list(TestPackage.eINSTANCE.getD_YList());
289:
290:                 final EMFFormsDatabindingEMF emfFormsDatabinding = mock(EMFFormsDatabindingEMF.class);
291:                 when(emfFormsDatabinding.getListProperty(valueDMR, validEObject)).thenReturn(targetListProperty);
292:
293:                 converter.setEMFFormsDatabinding(emfFormsDatabinding);
294:
295:                 final IEMFListProperty resultListProperty = converter.convertToListProperty(keyAttributeDMR, validEObject);
296:
297:                 final String expected = String.format("A.b<B> => B.cList<C> key '%s' => C.d<D> => D.yList[]<EInt>", //$NON-NLS-1$
298:                         CORRECT_TEST_KEY);
299:                 assertEquals(expected, resultListProperty.toString());
300:         }
301:
302:         /**
303:          * Test method for
304:          * {@link org.eclipse.emfforms.internal.core.services.databinding.keyattribute.KeyAttributeDomainModelReferenceConverter#convertToListProperty(org.eclipse.emf.ecp.view.spi.model.VDomainModelReference, org.eclipse.emf.ecore.EObject)}
305:          * .
306:          *
307:          * @throws DatabindingFailedException
308:          */
309:         @Test
310:         public void testConvertToListPropertyNoReferencePath() throws DatabindingFailedException {
311:                 final VKeyAttributeDomainModelReference keyAttributeDMR = VKeyattributedmrFactory.eINSTANCE
312:                         .createKeyAttributeDomainModelReference();
313:                 final VFeaturePathDomainModelReference keyDMR = VViewFactory.eINSTANCE.createFeaturePathDomainModelReference();
314:                 final VFeaturePathDomainModelReference valueDMR = VViewFactory.eINSTANCE
315:                         .createFeaturePathDomainModelReference();
316:
317:                 keyAttributeDMR.setKeyValue(CORRECT_TEST_KEY);
318:                 keyAttributeDMR.setDomainModelEFeature(TestPackage.eINSTANCE.getB_CList());
319:
320:                 keyDMR.getDomainModelEReferencePath().add(TestPackage.eINSTANCE.getC_D());
321:                 keyDMR.setDomainModelEFeature(TestPackage.eINSTANCE.getD_X());
322:
323:                 valueDMR.getDomainModelEReferencePath().add(TestPackage.eINSTANCE.getC_D());
324:                 valueDMR.setDomainModelEFeature(TestPackage.eINSTANCE.getD_YList());
325:
326:                 keyAttributeDMR.setKeyDMR(keyDMR);
327:                 keyAttributeDMR.setValueDMR(valueDMR);
328:
329:                 final IEMFValueProperty targetValueProperty = EMFProperties.value(TestPackage.eINSTANCE.getC_D());
330:                 final IEMFListProperty targetListProperty = targetValueProperty.list(TestPackage.eINSTANCE.getD_YList());
331:
332:                 final EMFFormsDatabindingEMF emfFormsDatabinding = mock(EMFFormsDatabindingEMF.class);
333:                 when(emfFormsDatabinding.getListProperty(valueDMR, validEObject)).thenReturn(targetListProperty);
334:
335:                 converter.setEMFFormsDatabinding(emfFormsDatabinding);
336:
337:                 final IEMFListProperty resultListProperty = converter.convertToListProperty(keyAttributeDMR, validEObject);
338:
339:                 final String expected = String.format("B.cList<C> key '%s' => C.d<D> => D.yList[]<EInt>", //$NON-NLS-1$
340:                         CORRECT_TEST_KEY);
341:                 assertEquals(expected, resultListProperty.toString());
342:         }
343:
344:         /**
345:          * Test method for
346:          * {@link org.eclipse.emfforms.internal.core.services.databinding.keyattribute.KeyAttributeDomainModelReferenceConverter#convertToListProperty(org.eclipse.emf.ecp.view.spi.model.VDomainModelReference, org.eclipse.emf.ecore.EObject)}
347:          * .
348:          *
349:          * @throws DatabindingFailedException
350:          */
351:         @Test(expected = DatabindingFailedException.class)
352:         public void testConvertToListPropertyNoFeature() throws DatabindingFailedException {
353:                 final VKeyAttributeDomainModelReference keyAttributeDMR = VKeyattributedmrFactory.eINSTANCE
354:                         .createKeyAttributeDomainModelReference();
355:                 final VFeaturePathDomainModelReference keyDMR = VViewFactory.eINSTANCE.createFeaturePathDomainModelReference();
356:                 final VFeaturePathDomainModelReference valueDMR = VViewFactory.eINSTANCE
357:                         .createFeaturePathDomainModelReference();
358:
359:                 keyAttributeDMR.setKeyValue(CORRECT_TEST_KEY);
360:
361:                 keyDMR.getDomainModelEReferencePath().add(TestPackage.eINSTANCE.getC_D());
362:                 keyDMR.setDomainModelEFeature(TestPackage.eINSTANCE.getD_X());
363:
364:                 valueDMR.getDomainModelEReferencePath().add(TestPackage.eINSTANCE.getC_D());
365:                 valueDMR.setDomainModelEFeature(TestPackage.eINSTANCE.getD_YList());
366:
367:                 keyAttributeDMR.setKeyDMR(keyDMR);
368:                 keyAttributeDMR.setValueDMR(valueDMR);
369:
370:                 final IEMFValueProperty targetValueProperty = EMFProperties.value(TestPackage.eINSTANCE.getC_D());
371:                 final IEMFListProperty targetListProperty = targetValueProperty.list(TestPackage.eINSTANCE.getD_YList());
372:
373:                 final EMFFormsDatabindingEMF emfFormsDatabinding = mock(EMFFormsDatabindingEMF.class);
374:                 when(emfFormsDatabinding.getListProperty(valueDMR, validEObject)).thenReturn(targetListProperty);
375:
376:                 converter.setEMFFormsDatabinding(emfFormsDatabinding);
377:
378:                 converter.convertToListProperty(keyAttributeDMR, validEObject);
379:         }
380:
381:         /**
382:          * Test method for
383:          * {@link org.eclipse.emfforms.internal.core.services.databinding.keyattribute.KeyAttributeDomainModelReferenceConverter#convertToListProperty(org.eclipse.emf.ecp.view.spi.model.VDomainModelReference, org.eclipse.emf.ecore.EObject)}
384:          * .
385:          *
386:          * @throws DatabindingFailedException
387:          */
388:         @Test(expected = IllegalArgumentException.class)
389:         public void testConvertToListPropertyDMRNull() throws DatabindingFailedException {
390:                 converter.convertToListProperty(null, validEObject);
391:         }
392:
393:         /**
394:          * Test method for
395:          * {@link org.eclipse.emfforms.internal.core.services.databinding.keyattribute.KeyAttributeDomainModelReferenceConverter#convertToListProperty(org.eclipse.emf.ecp.view.spi.model.VDomainModelReference, org.eclipse.emf.ecore.EObject)}
396:          * .
397:          *
398:          * @throws DatabindingFailedException
399:          */
400:         @Test(expected = IllegalArgumentException.class)
401:         public void testConvertToListPropertyWrongReferenceType() throws DatabindingFailedException {
402:                 converter.convertToListProperty(mock(VFeaturePathDomainModelReference.class), validEObject);
403:         }
404:
405:         /**
406:          * Test method for
407:          * {@link org.eclipse.emfforms.internal.core.services.databinding.keyattribute.KeyAttributeDomainModelReferenceConverter#convertToListProperty(org.eclipse.emf.ecp.view.spi.model.VDomainModelReference, org.eclipse.emf.ecore.EObject)}
408:          * .
409:          *
410:          * @throws DatabindingFailedException
411:          */
412:         @Test(expected = IllegalArgumentException.class)
413:         public void testConvertToListPropertyObjectNull() throws DatabindingFailedException {
414:                 converter.convertToListProperty(mock(VKeyAttributeDomainModelReference.class), null);
415:         }
416:
417:         /**
418:          * Test method for
419:          * {@link org.eclipse.emfforms.internal.core.services.databinding.keyattribute.KeyAttributeDomainModelReferenceConverter#getSetting(org.eclipse.emf.ecp.view.spi.model.VDomainModelReference, org.eclipse.emf.ecore.EObject)}
420:          * .
421:          *
422:          * @throws DatabindingFailedException
423:          */
424:         @Test
425:         public void testGetSettingKeyPresent() throws DatabindingFailedException {
426:                 final DefaultRealm realm = new DefaultRealm();
427:
428:                 final VKeyAttributeDomainModelReference keyAttributeDMR = VKeyattributedmrFactory.eINSTANCE
429:                         .createKeyAttributeDomainModelReference();
430:                 final VFeaturePathDomainModelReference keyDMR = VViewFactory.eINSTANCE.createFeaturePathDomainModelReference();
431:                 final VFeaturePathDomainModelReference valueDMR = VViewFactory.eINSTANCE
432:                         .createFeaturePathDomainModelReference();
433:
434:                 keyAttributeDMR.setKeyValue(CORRECT_TEST_KEY);
435:                 keyAttributeDMR.getDomainModelEReferencePath().add(TestPackage.eINSTANCE.getA_B());
436:                 keyAttributeDMR.setDomainModelEFeature(TestPackage.eINSTANCE.getB_CList());
437:
438:                 keyDMR.getDomainModelEReferencePath().add(TestPackage.eINSTANCE.getC_D());
439:                 keyDMR.setDomainModelEFeature(TestPackage.eINSTANCE.getD_X());
440:
441:                 valueDMR.getDomainModelEReferencePath().add(TestPackage.eINSTANCE.getC_A());
442:                 valueDMR.setDomainModelEFeature(TestPackage.eINSTANCE.getA_B());
443:
444:                 keyAttributeDMR.setKeyDMR(keyDMR);
445:                 keyAttributeDMR.setValueDMR(valueDMR);
446:
447:                 final A a = TestFactory.eINSTANCE.createA();
448:                 final B b = TestFactory.eINSTANCE.createB();
449:                 final C cWithKey = TestFactory.eINSTANCE.createC();
450:                 final D dWithKey = TestFactory.eINSTANCE.createD();
451:                 final A aOfC = TestFactory.eINSTANCE.createA();
452:                 final B bOfC = TestFactory.eINSTANCE.createB();
453:
454:                 a.setB(b);
455:                 b.getCList().add(cWithKey);
456:                 cWithKey.setD(dWithKey);
457:                 cWithKey.setA(aOfC);
458:                 aOfC.setB(bOfC);
459:                 dWithKey.setX(CORRECT_TEST_KEY);
460:
461:                 IEMFValueProperty targetValueProperty = EMFProperties.value(TestPackage.eINSTANCE.getC_A());
462:                 targetValueProperty = targetValueProperty.value(TestPackage.eINSTANCE.getA_B());
463:
464:                 final EMFFormsDatabindingEMF emfFormsDatabinding = mock(EMFFormsDatabindingEMF.class);
465:                 when(emfFormsDatabinding.getValueProperty(valueDMR, TestPackage.Literals.C)).thenReturn(targetValueProperty);
466:
467:                 final Setting keySetting = ((InternalEObject) dWithKey).eSetting(TestPackage.eINSTANCE.getD_X());
468:                 when(emfFormsDatabinding.getSetting(keyDMR, cWithKey)).thenReturn(keySetting);
469:                 converter.setEMFFormsDatabinding(emfFormsDatabinding);
470:
471:                 final Setting resultSetting = converter.getSetting(keyAttributeDMR, a);
472:                 assertEquals(bOfC, resultSetting.get(true));
473:
474:                 realm.dispose();
475:         }
476:
477:         /**
478:          * Test method for
479:          * {@link org.eclipse.emfforms.internal.core.services.databinding.keyattribute.KeyAttributeDomainModelReferenceConverter#getSetting(org.eclipse.emf.ecp.view.spi.model.VDomainModelReference, org.eclipse.emf.ecore.EObject)}
480:          * .
481:          *
482:          * @throws DatabindingFailedException
483:          */
484:         @Test(expected = DatabindingFailedException.class)
485:         public void testGetSettingKeyNotPresent() throws DatabindingFailedException {
486:                 final DefaultRealm realm = new DefaultRealm();
487:
488:                 final VKeyAttributeDomainModelReference keyAttributeDMR = VKeyattributedmrFactory.eINSTANCE
489:                         .createKeyAttributeDomainModelReference();
490:                 final VFeaturePathDomainModelReference keyDMR = VViewFactory.eINSTANCE.createFeaturePathDomainModelReference();
491:                 final VFeaturePathDomainModelReference valueDMR = VViewFactory.eINSTANCE
492:                         .createFeaturePathDomainModelReference();
493:
494:                 keyAttributeDMR.setKeyValue(CORRECT_TEST_KEY);
495:                 keyAttributeDMR.getDomainModelEReferencePath().add(TestPackage.eINSTANCE.getA_B());
496:                 keyAttributeDMR.setDomainModelEFeature(TestPackage.eINSTANCE.getB_CList());
497:
498:                 keyDMR.getDomainModelEReferencePath().add(TestPackage.eINSTANCE.getC_D());
499:                 keyDMR.setDomainModelEFeature(TestPackage.eINSTANCE.getD_X());
500:
501:                 valueDMR.getDomainModelEReferencePath().add(TestPackage.eINSTANCE.getC_A());
502:                 valueDMR.setDomainModelEFeature(TestPackage.eINSTANCE.getA_B());
503:
504:                 keyAttributeDMR.setKeyDMR(keyDMR);
505:                 keyAttributeDMR.setValueDMR(valueDMR);
506:
507:                 final A a = TestFactory.eINSTANCE.createA();
508:                 final B b = TestFactory.eINSTANCE.createB();
509:                 final C cWithoutKey = TestFactory.eINSTANCE.createC();
510:                 final D dWithoutKey = TestFactory.eINSTANCE.createD();
511:                 final A aOfC = TestFactory.eINSTANCE.createA();
512:                 final B bOfC = TestFactory.eINSTANCE.createB();
513:
514:                 a.setB(b);
515:                 b.getCList().add(cWithoutKey);
516:                 cWithoutKey.setD(dWithoutKey);
517:                 cWithoutKey.setA(aOfC);
518:                 aOfC.setB(bOfC);
519:                 dWithoutKey.setX(WRONG_TEST_KEY);
520:
521:                 IEMFValueProperty targetValueProperty = EMFProperties.value(TestPackage.eINSTANCE.getC_A());
522:                 targetValueProperty = targetValueProperty.value(TestPackage.eINSTANCE.getA_B());
523:
524:                 final EMFFormsDatabindingEMF emfFormsDatabinding = mock(EMFFormsDatabindingEMF.class);
525:                 when(emfFormsDatabinding.getValueProperty(valueDMR, TestPackage.Literals.C)).thenReturn(targetValueProperty);
526:
527:                 final Setting keySetting = ((InternalEObject) dWithoutKey).eSetting(TestPackage.eINSTANCE.getD_X());
528:                 when(emfFormsDatabinding.getSetting(keyDMR, cWithoutKey)).thenReturn(keySetting);
529:                 converter.setEMFFormsDatabinding(emfFormsDatabinding);
530:
531:                 converter.getSetting(keyAttributeDMR, a);
532:
533:                 realm.dispose();
534:         }
535:
536:         /**
537:          * Test method for
538:          * {@link org.eclipse.emfforms.internal.core.services.databinding.keyattribute.KeyAttributeDomainModelReferenceConverter#getSetting(org.eclipse.emf.ecp.view.spi.model.VDomainModelReference, org.eclipse.emf.ecore.EObject)}
539:          * .
540:          *
541:          * @throws DatabindingFailedException
542:          */
543:         @Test(expected = IllegalArgumentException.class)
544:         public void testGetSettingReferenceNull() throws DatabindingFailedException {
545:                 converter.getSetting(null, validEObject);
546:         }
547:
548:         /**
549:          * Test method for
550:          * {@link org.eclipse.emfforms.internal.core.services.databinding.keyattribute.KeyAttributeDomainModelReferenceConverter#getSetting(org.eclipse.emf.ecp.view.spi.model.VDomainModelReference, org.eclipse.emf.ecore.EObject)}
551:          * .
552:          *
553:          * @throws DatabindingFailedException
554:          */
555:         @Test(expected = IllegalArgumentException.class)
556:         public void testGetSettingObjectNull() throws DatabindingFailedException {
557:                 converter.getSetting(mock(VKeyAttributeDomainModelReference.class), null);
558:         }
559:
560:         /**
561:          * Test method for
562:          * {@link org.eclipse.emfforms.internal.core.services.databinding.keyattribute.KeyAttributeDomainModelReferenceConverter#getSetting(org.eclipse.emf.ecp.view.spi.model.VDomainModelReference, org.eclipse.emf.ecore.EObject)}
563:          * .
564:          *
565:          * @throws DatabindingFailedException
566:          */
567:         @Test(expected = IllegalArgumentException.class)
568:         public void testGetSettingWrongReferenceType() throws DatabindingFailedException {
569:                 converter.getSetting(mock(VFeaturePathDomainModelReference.class), validEObject);
570:         }
571:
572:         /**
573:          * Test method for
574:          * {@link org.eclipse.emfforms.internal.core.services.databinding.keyattribute.KeyAttributeDomainModelReferenceConverter#isApplicable(org.eclipse.emf.ecp.view.spi.model.VDomainModelReference)}
575:          * .
576:          */
577:         @Test
578:         public void testIsApplicable() {
579:                 assertEquals(10d, converter.isApplicable(mock(VKeyAttributeDomainModelReference.class)), 0d);
580:         }
581:
582:         /**
583:          * Test method for
584:          * {@link org.eclipse.emfforms.internal.core.services.databinding.keyattribute.KeyAttributeDomainModelReferenceConverter#isApplicable(org.eclipse.emf.ecp.view.spi.model.VDomainModelReference)}
585:          * .
586:          */
587:         @Test(expected = IllegalArgumentException.class)
588:         public void testIsApplicableNullReference() {
589:                 converter.isApplicable(null);
590:         }
591:
592:         /**
593:          * Test method for
594:          * {@link org.eclipse.emfforms.internal.core.services.databinding.keyattribute.KeyAttributeDomainModelReferenceConverter#isApplicable(org.eclipse.emf.ecp.view.spi.model.VDomainModelReference)}
595:          * .
596:          */
597:         @Test
598:         public void testIsApplicableWrongReferenceType() {
599:                 assertEquals(DomainModelReferenceConverter.NOT_APPLICABLE,
600:                         converter.isApplicable(mock(VFeaturePathDomainModelReference.class)), 0d);
601:         }
602: }