Skip to content

Package: EMFFormsMappingDMRExpander_Test

EMFFormsMappingDMRExpander_Test

nameinstructionbranchcomplexitylinemethod
EMFFormsMappingDMRExpander_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: 26
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
testIsApplicable()
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
testIsApplicableNull()
M: 0 C: 17
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
testIsApplicableWrongReferenceType()
M: 0 C: 13
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
testPrepareDomainObject()
M: 0 C: 49
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 13
100%
M: 0 C: 1
100%
testPrepareDomainObjectBothNull()
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%
testPrepareDomainObjectNoMap()
M: 6 C: 24
80%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 9
82%
M: 0 C: 1
100%
testPrepareDomainObjectObjectNull()
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
testPrepareDomainObjectReferenceNull()
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2015 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.domainexpander.mapping;
15:
16: import static org.junit.Assert.assertEquals;
17: import static org.junit.Assert.assertNotNull;
18: import static org.mockito.Matchers.any;
19: import static org.mockito.Mockito.mock;
20: import static org.mockito.Mockito.times;
21: import static org.mockito.Mockito.verify;
22:
23: import org.eclipse.emf.ecore.EObject;
24: import org.eclipse.emf.ecp.view.spi.mappingdmr.model.VMappingDomainModelReference;
25: import org.eclipse.emf.ecp.view.spi.mappingdmr.model.VMappingdmrFactory;
26: import org.eclipse.emf.ecp.view.spi.model.VDomainModelReference;
27: import org.eclipse.emf.ecp.view.spi.model.VFeaturePathDomainModelReference;
28: import org.eclipse.emf.ecp.view.spi.model.VViewFactory;
29: import org.eclipse.emfforms.core.services.databinding.testmodel.test.model.C;
30: import org.eclipse.emfforms.core.services.databinding.testmodel.test.model.TestFactory;
31: import org.eclipse.emfforms.core.services.databinding.testmodel.test.model.TestPackage;
32: import org.eclipse.emfforms.spi.common.report.AbstractReport;
33: import org.eclipse.emfforms.spi.common.report.ReportService;
34: import org.eclipse.emfforms.spi.core.services.domainexpander.EMFFormsDMRExpander;
35: import org.eclipse.emfforms.spi.core.services.domainexpander.EMFFormsDomainExpander;
36: import org.eclipse.emfforms.spi.core.services.domainexpander.EMFFormsExpandingFailedException;
37: import org.junit.Before;
38: import org.junit.Test;
39:
40: /**
41: * JUnit test cases for {@link EMFFormsMappingDMRExpander}.
42: *
43: * @author Lucas Koehler
44: *
45: */
46: public class EMFFormsMappingDMRExpander_Test {
47:
48:         private EMFFormsMappingDMRExpander mappingExpander;
49:         private ReportService reportService;
50:         private EMFFormsDomainExpander domainExpander;
51:
52:         @Before
53:         public void setUp() {
54:                 mappingExpander = new EMFFormsMappingDMRExpander();
55:                 reportService = mock(ReportService.class);
56:                 domainExpander = mock(EMFFormsDomainExpander.class);
57:                 mappingExpander.setReportService(reportService);
58:                 mappingExpander.setEMFFormsDomainExpander(domainExpander);
59:         }
60:
61:         /**
62:          * Test method for
63:          * {@link org.eclipse.emfforms.internal.core.services.domainexpander.mapping.EMFFormsMappingDMRExpander#prepareDomainObject(org.eclipse.emf.ecp.view.spi.model.VDomainModelReference, org.eclipse.emf.ecore.EObject)}
64:          * .
65:          *
66:          * @throws EMFFormsExpandingFailedException
67:          */
68:         @Test(expected = IllegalArgumentException.class)
69:         public void testPrepareDomainObjectReferenceNull() throws EMFFormsExpandingFailedException {
70:                 mappingExpander.prepareDomainObject(null, mock(EObject.class));
71:         }
72:
73:         /**
74:          * Test method for
75:          * {@link org.eclipse.emfforms.internal.core.services.domainexpander.mapping.EMFFormsMappingDMRExpander#prepareDomainObject(org.eclipse.emf.ecp.view.spi.model.VDomainModelReference, org.eclipse.emf.ecore.EObject)}
76:          * .
77:          *
78:          * @throws EMFFormsExpandingFailedException
79:          */
80:         @Test(expected = IllegalArgumentException.class)
81:         public void testPrepareDomainObjectObjectNull() throws EMFFormsExpandingFailedException {
82:                 mappingExpander.prepareDomainObject(mock(VMappingDomainModelReference.class), null);
83:         }
84:
85:         /**
86:          * Test method for
87:          * {@link org.eclipse.emfforms.internal.core.services.domainexpander.mapping.EMFFormsMappingDMRExpander#prepareDomainObject(org.eclipse.emf.ecp.view.spi.model.VDomainModelReference, org.eclipse.emf.ecore.EObject)}
88:          * .
89:          *
90:          * @throws EMFFormsExpandingFailedException
91:          */
92:         @Test(expected = IllegalArgumentException.class)
93:         public void testPrepareDomainObjectBothNull() throws EMFFormsExpandingFailedException {
94:                 mappingExpander.prepareDomainObject(null, null);
95:         }
96:
97:         /**
98:          * Test method for
99:          * {@link org.eclipse.emfforms.internal.core.services.domainexpander.mapping.EMFFormsMappingDMRExpander#prepareDomainObject(org.eclipse.emf.ecp.view.spi.model.VDomainModelReference, org.eclipse.emf.ecore.EObject)}
100:          * .
101:          *
102:          * @throws EMFFormsExpandingFailedException
103:          */
104:         @Test
105:         public void testPrepareDomainObject() throws EMFFormsExpandingFailedException {
106:                 /*
107:                  * Note: Testing in JUnit tests is afaik only possible without using domain model e reference paths because
108:                  * they get expanded by the EMFFormsDomainExpander that has to be mocked in a JUnit test.
109:                  */
110:
111:                 final VMappingDomainModelReference mappingDMR = VMappingdmrFactory.eINSTANCE
112:                         .createMappingDomainModelReference();
113:                 mappingDMR.setDomainModelEFeature(TestPackage.eINSTANCE.getC_EClassToA());
114:                 final VFeaturePathDomainModelReference targetDMR = VViewFactory.eINSTANCE
115:                         .createFeaturePathDomainModelReference();
116:                 targetDMR.setDomainModelEFeature(TestPackage.eINSTANCE.getA_B());
117:
118:                 mappingDMR.setDomainModelReference(targetDMR);
119:                 mappingDMR.setMappedClass(TestPackage.eINSTANCE.getA());
120:
121:                 final C domainObject = TestFactory.eINSTANCE.createC();
122:
123:                 mappingExpander.prepareDomainObject(mappingDMR, domainObject);
124:                 assertNotNull(domainObject.getEClassToA().get(TestPackage.eINSTANCE.getA()));
125:                 verify(domainExpander, times(2)).prepareDomainObject(any(VDomainModelReference.class), any(EObject.class));
126:         }
127:
128:         /**
129:          * Test method for
130:          * {@link org.eclipse.emfforms.internal.core.services.domainexpander.mapping.EMFFormsMappingDMRExpander#prepareDomainObject(org.eclipse.emf.ecp.view.spi.model.VDomainModelReference, org.eclipse.emf.ecore.EObject)}
131:          * .
132:          *
133:          * @throws EMFFormsExpandingFailedException
134:          */
135:         @Test(expected = EMFFormsExpandingFailedException.class)
136:         public void testPrepareDomainObjectNoMap() throws EMFFormsExpandingFailedException {
137:                 /*
138:                  * Note: Testing in JUnit tests is afaik only possible without using domain model e reference paths because
139:                  * they get expanded by the EMFFormsDomainExpander that has to be mocked in a JUnit test.
140:                  */
141:
142:                 final VMappingDomainModelReference mappingDMR = VMappingdmrFactory.eINSTANCE
143:                         .createMappingDomainModelReference();
144:                 mappingDMR.setDomainModelEFeature(TestPackage.eINSTANCE.getC_D());
145:                 final VFeaturePathDomainModelReference targetDMR = VViewFactory.eINSTANCE
146:                         .createFeaturePathDomainModelReference();
147:                 targetDMR.setDomainModelEFeature(TestPackage.eINSTANCE.getD_X());
148:
149:                 mappingDMR.setDomainModelReference(targetDMR);
150:                 mappingDMR.setMappedClass(TestPackage.eINSTANCE.getD());
151:
152:                 final C domainObject = TestFactory.eINSTANCE.createC();
153:
154:                 mappingExpander.prepareDomainObject(mappingDMR, domainObject);
155:         }
156:
157:         /**
158:          * Test method for
159:          * {@link org.eclipse.emfforms.internal.core.services.domainexpander.mapping.EMFFormsMappingDMRExpander#isApplicable(org.eclipse.emf.ecp.view.spi.model.VDomainModelReference)}
160:          * .
161:          */
162:         @Test
163:         public void testIsApplicable() {
164:                 final VMappingDomainModelReference reference = mock(VMappingDomainModelReference.class);
165:                 assertEquals(5d, mappingExpander.isApplicable(reference), 0d);
166:
167:         }
168:
169:         /**
170:          * Test method for
171:          * {@link org.eclipse.emfforms.internal.core.services.domainexpander.mapping.EMFFormsMappingDMRExpander#isApplicable(org.eclipse.emf.ecp.view.spi.model.VDomainModelReference)}
172:          * .
173:          */
174:         @Test
175:         public void testIsApplicableNull() {
176:                 assertEquals(EMFFormsDMRExpander.NOT_APPLICABLE, mappingExpander.isApplicable(null), 0d);
177:                 verify(reportService).report(any(AbstractReport.class));
178:         }
179:
180:         /**
181:          * Test method for
182:          * {@link org.eclipse.emfforms.internal.core.services.domainexpander.mapping.EMFFormsMappingDMRExpander#isApplicable(org.eclipse.emf.ecp.view.spi.model.VDomainModelReference)}
183:          * .
184:          */
185:         @Test
186:         public void testIsApplicableWrongReferenceType() {
187:                 final VDomainModelReference reference = mock(VDomainModelReference.class);
188:                 assertEquals(EMFFormsDMRExpander.NOT_APPLICABLE, mappingExpander.isApplicable(reference), 0d);
189:         }
190: }