Skip to content

Package: MappingSegmentConverter_Test

MappingSegmentConverter_Test

nameinstructionbranchcomplexitylinemethod
MappingSegmentConverter_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%
setUp()
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
tearDown()
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
testConvertToListProperty()
M: 3 C: 11
79%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 1 C: 2
67%
M: 0 C: 1
100%
testConvertToValuePropertyAttribute()
M: 11 C: 27
71%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 9
82%
M: 0 C: 1
100%
testConvertToValuePropertyNoMap()
M: 11 C: 16
59%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 6
75%
M: 0 C: 1
100%
testConvertToValuePropertyReference()
M: 0 C: 62
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 18
100%
M: 0 C: 1
100%
testGetSettingNoMap()
M: 7 C: 19
73%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 7
78%
M: 0 C: 1
100%
testGetSettingValueAttribute()
M: 7 C: 27
79%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 9
82%
M: 0 C: 1
100%
testGetSettingValueReference()
M: 0 C: 48
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 14
100%
M: 0 C: 1
100%
testIsApplicable()
M: 0 C: 13
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
testIsApplicableNull()
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%
testIsApplicableWrongSegmentType()
M: 0 C: 13
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2018 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.segments.mapping;
15:
16: import static org.junit.Assert.assertEquals;
17: import static org.junit.Assert.assertTrue;
18: import static org.mockito.Mockito.mock;
19:
20: import org.eclipse.emf.databinding.IEMFValueProperty;
21: import org.eclipse.emf.databinding.internal.EMFValuePropertyDecorator;
22: import org.eclipse.emf.ecore.EClass;
23: import org.eclipse.emf.ecore.EReference;
24: import org.eclipse.emf.ecore.EStructuralFeature.Setting;
25: import org.eclipse.emf.ecore.EcoreFactory;
26: import org.eclipse.emf.ecp.test.common.DefaultRealm;
27: import org.eclipse.emf.ecp.view.spi.model.VFeatureDomainModelReferenceSegment;
28: import org.eclipse.emf.ecp.view.spi.model.VViewFactory;
29: import org.eclipse.emf.edit.domain.EditingDomain;
30: import org.eclipse.emfforms.core.services.databinding.testmodel.test.model.A;
31: import org.eclipse.emfforms.core.services.databinding.testmodel.test.model.B;
32: import org.eclipse.emfforms.core.services.databinding.testmodel.test.model.C;
33: import org.eclipse.emfforms.core.services.databinding.testmodel.test.model.TestFactory;
34: import org.eclipse.emfforms.core.services.databinding.testmodel.test.model.TestPackage;
35: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedException;
36: import org.eclipse.emfforms.spi.core.services.databinding.emf.DomainModelReferenceSegmentConverterEMF;
37: import org.eclipse.emfforms.spi.core.services.databinding.emf.SegmentConverterValueResultEMF;
38: import org.eclipse.emfforms.spi.view.mappingsegment.model.VMappingDomainModelReferenceSegment;
39: import org.eclipse.emfforms.spi.view.mappingsegment.model.VMappingsegmentFactory;
40: import org.junit.After;
41: import org.junit.Before;
42: import org.junit.Test;
43:
44: /**
45: * JUnit tests for {@link MappingSegmentConverter}.
46: *
47: * @author Lucas Koehler
48: *
49: */
50: @SuppressWarnings("restriction")
51: public class MappingSegmentConverter_Test {
52:
53:         private MappingSegmentConverter converter;
54:         private DefaultRealm realm;
55:
56:         /**
57:          * Set up a new {@link MappingSegmentConverter} before every unit test.
58:          */
59:         @Before
60:         public void setUp() {
61:                 converter = new MappingSegmentConverter();
62:                 realm = new DefaultRealm();
63:         }
64:
65:         /**
66:          * Disposes the default realm after every unit test.
67:          */
68:         @After
69:         public void tearDown() {
70:                 realm.dispose();
71:         }
72:
73:         @Test
74:         public void testIsApplicable() {
75:                 final VMappingDomainModelReferenceSegment mappingSegment = VMappingsegmentFactory.eINSTANCE
76:                         .createMappingDomainModelReferenceSegment();
77:                 final double result = converter.isApplicable(mappingSegment);
78:                 assertEquals(10d, result, 0d);
79:         }
80:
81:         @Test(expected = IllegalArgumentException.class)
82:         public void testIsApplicableNull() {
83:                 converter.isApplicable(null);
84:         }
85:
86:         @Test
87:         public void testIsApplicableWrongSegmentType() {
88:                 final VFeatureDomainModelReferenceSegment segment = VViewFactory.eINSTANCE
89:                         .createFeatureDomainModelReferenceSegment();
90:                 final double result = converter.isApplicable(segment);
91:                 assertEquals(DomainModelReferenceSegmentConverterEMF.NOT_APPLICABLE, result, 0d);
92:         }
93:
94:         @SuppressWarnings("unchecked")
95:         @Test
96:         public void testConvertToValuePropertyReference() throws DatabindingFailedException {
97:                 final VMappingDomainModelReferenceSegment mappingSegment = VMappingsegmentFactory.eINSTANCE
98:                         .createMappingDomainModelReferenceSegment();
99:                 final EReference domainModelEFeature = TestPackage.eINSTANCE.getC_EClassToA();
100:
101:                 final A value = TestFactory.eINSTANCE.createA();
102:                 final EClass key = EcoreFactory.eINSTANCE.createEClass();
103:                 final C domainObject = TestFactory.eINSTANCE.createC();
104:                 domainObject.getEClassToA().put(key, value);
105:
106:                 mappingSegment.setMappedClass(key);
107:                 mappingSegment.setDomainModelFeature(domainModelEFeature.getName());
108:
109:                 final SegmentConverterValueResultEMF conversionResult = converter.convertToValueProperty(mappingSegment,
110:                         domainObject.eClass(), mock(EditingDomain.class));
111:                 final IEMFValueProperty valueProperty = conversionResult.getValueProperty();
112:
113:                 final Object returnedValue = valueProperty.getValue(domainObject);
114:                 assertEquals(value, returnedValue);
115:                 assertTrue(valueProperty instanceof EMFValuePropertyDecorator);
116:                 assertTrue(conversionResult.getNextEClass().isPresent());
117:                 assertEquals(TestPackage.eINSTANCE.getA(), conversionResult.getNextEClass().get());
118:         }
119:
120:         @Test(expected = DatabindingFailedException.class)
121:         public void testConvertToValuePropertyAttribute() throws DatabindingFailedException {
122:                 final VMappingDomainModelReferenceSegment mappingSegment = VMappingsegmentFactory.eINSTANCE
123:                         .createMappingDomainModelReferenceSegment();
124:                 final EReference domainModelEFeature = TestPackage.eINSTANCE.getC_EClassToString();
125:
126:                 final String value = "TestString"; //$NON-NLS-1$
127:                 final EClass key = EcoreFactory.eINSTANCE.createEClass();
128:                 final C domainObject = TestFactory.eINSTANCE.createC();
129:                 domainObject.getEClassToString().put(key, value);
130:
131:                 mappingSegment.setMappedClass(key);
132:                 mappingSegment.setDomainModelFeature(domainModelEFeature.getName());
133:
134:                 converter.convertToValueProperty(mappingSegment, domainObject.eClass(), mock(EditingDomain.class));
135:         }
136:
137:         @Test(expected = IllegalMapTypeException.class)
138:         public void testConvertToValuePropertyNoMap() throws DatabindingFailedException {
139:                 final VMappingDomainModelReferenceSegment mappingSegment = VMappingsegmentFactory.eINSTANCE
140:                         .createMappingDomainModelReferenceSegment();
141:                 final EReference domainModelEFeature = TestPackage.eINSTANCE.getB_CList();
142:
143:                 final EClass key = EcoreFactory.eINSTANCE.createEClass();
144:                 mappingSegment.setMappedClass(key);
145:                 mappingSegment.setDomainModelFeature(domainModelEFeature.getName());
146:
147:                 converter.convertToValueProperty(mappingSegment, TestPackage.eINSTANCE.getB(), mock(EditingDomain.class));
148:         }
149:
150:         @Test(expected = UnsupportedOperationException.class)
151:         public void testConvertToListProperty() throws DatabindingFailedException {
152:                 converter.convertToListProperty(mock(VMappingDomainModelReferenceSegment.class), mock(EClass.class),
153:                         mock(EditingDomain.class));
154:         }
155:
156:         @Test
157:         public void testGetSettingValueReference() throws DatabindingFailedException {
158:                 final VMappingDomainModelReferenceSegment mappingSegment = VMappingsegmentFactory.eINSTANCE
159:                         .createMappingDomainModelReferenceSegment();
160:                 final EReference domainModelEFeature = TestPackage.eINSTANCE.getC_EClassToA();
161:
162:                 final A value = TestFactory.eINSTANCE.createA();
163:                 final EClass key = EcoreFactory.eINSTANCE.createEClass();
164:                 final C domainObject = TestFactory.eINSTANCE.createC();
165:
166:                 domainObject.getEClassToA().put(key, value);
167:                 mappingSegment.setMappedClass(key);
168:                 mappingSegment.setDomainModelFeature(domainModelEFeature.getName());
169:
170:                 final Setting setting = converter.getSetting(mappingSegment, domainObject);
171:
172:                 assertEquals(domainModelEFeature, setting.getEStructuralFeature());
173:                 assertEquals(domainObject, setting.getEObject());
174:                 assertEquals(value, setting.get(true));
175:         }
176:
177:         @Test(expected = DatabindingFailedException.class)
178:         public void testGetSettingValueAttribute() throws DatabindingFailedException {
179:                 final VMappingDomainModelReferenceSegment mappingSegment = VMappingsegmentFactory.eINSTANCE
180:                         .createMappingDomainModelReferenceSegment();
181:                 final EReference domainModelEFeature = TestPackage.eINSTANCE.getC_EClassToString();
182:
183:                 final String value = "TestValue"; //$NON-NLS-1$
184:                 final EClass key = EcoreFactory.eINSTANCE.createEClass();
185:                 final C domainObject = TestFactory.eINSTANCE.createC();
186:
187:                 domainObject.getEClassToString().put(key, value);
188:                 mappingSegment.setMappedClass(key);
189:                 mappingSegment.setDomainModelFeature(domainModelEFeature.getName());
190:
191:                 converter.getSetting(mappingSegment, domainObject);
192:         }
193:
194:         @Test(expected = IllegalMapTypeException.class)
195:         public void testGetSettingNoMap() throws DatabindingFailedException {
196:                 final VMappingDomainModelReferenceSegment mappingSegment = VMappingsegmentFactory.eINSTANCE
197:                         .createMappingDomainModelReferenceSegment();
198:                 final EReference domainModelEFeature = TestPackage.eINSTANCE.getB_CList();
199:
200:                 final B domainObject = TestFactory.eINSTANCE.createB();
201:
202:                 final EClass key = EcoreFactory.eINSTANCE.createEClass();
203:                 mappingSegment.setMappedClass(key);
204:                 mappingSegment.setDomainModelFeature(domainModelEFeature.getName());
205:
206:                 converter.getSetting(mappingSegment, domainObject);
207:         }
208: }