Skip to content

Package: EMFFormsMappingDMRExpander_ITest

EMFFormsMappingDMRExpander_ITest

nameinstructionbranchcomplexitylinemethod
EMFFormsMappingDMRExpander_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%
setUp()
M: 2 C: 47
96%
M: 2 C: 4
67%
M: 2 C: 2
50%
M: 1 C: 13
93%
M: 0 C: 1
100%
setUpBeforeClass()
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%
tearDown()
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%
testPrepareDomainObject()
M: 0 C: 58
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 17
100%
M: 0 C: 1
100%
testServiceType()
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%

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.assertNotNull;
17: import static org.junit.Assert.assertTrue;
18: import static org.junit.Assert.fail;
19:
20: import java.util.Collection;
21:
22: import org.eclipse.emf.ecp.view.spi.mappingdmr.model.VMappingDomainModelReference;
23: import org.eclipse.emf.ecp.view.spi.mappingdmr.model.VMappingdmrFactory;
24: import org.eclipse.emf.ecp.view.spi.model.VFeaturePathDomainModelReference;
25: import org.eclipse.emf.ecp.view.spi.model.VViewFactory;
26: import org.eclipse.emfforms.core.services.databinding.testmodel.test.model.A;
27: import org.eclipse.emfforms.core.services.databinding.testmodel.test.model.B;
28: import org.eclipse.emfforms.core.services.databinding.testmodel.test.model.TestFactory;
29: import org.eclipse.emfforms.core.services.databinding.testmodel.test.model.TestPackage;
30: import org.eclipse.emfforms.spi.core.services.domainexpander.EMFFormsDMRExpander;
31: import org.eclipse.emfforms.spi.core.services.domainexpander.EMFFormsExpandingFailedException;
32: import org.junit.After;
33: import org.junit.Before;
34: import org.junit.BeforeClass;
35: import org.junit.Test;
36: import org.osgi.framework.BundleContext;
37: import org.osgi.framework.FrameworkUtil;
38: import org.osgi.framework.InvalidSyntaxException;
39: import org.osgi.framework.ServiceReference;
40:
41: /**
42: * JUnit integration test cases for {@link EMFFormsMappingDMRExpander}.
43: *
44: * @author Lucas Koehler
45: *
46: */
47: public class EMFFormsMappingDMRExpander_ITest {
48:
49:         private static BundleContext bundleContext;
50:         private ServiceReference<EMFFormsDMRExpander> serviceReference;
51:         private EMFFormsMappingDMRExpander mappingDMRExpander;
52:
53:         @BeforeClass
54:         public static void setUpBeforeClass() {
55:                 bundleContext = FrameworkUtil.getBundle(EMFFormsMappingDMRExpander_ITest.class).getBundleContext();
56:
57:         }
58:
59:         @Before
60:         public void setUp() throws InvalidSyntaxException {
61:                 final Collection<ServiceReference<EMFFormsDMRExpander>> serviceReferences = bundleContext.getServiceReferences(
62:                         EMFFormsDMRExpander.class, null);
63:                 mappingDMRExpander = null;
64:                 serviceReference = null;
65:•                for (final ServiceReference<EMFFormsDMRExpander> curRef : serviceReferences) {
66:                         final EMFFormsDMRExpander curService = bundleContext.getService(curRef);
67:•                        if (EMFFormsMappingDMRExpander.class.isInstance(curService)) {
68:                                 mappingDMRExpander = (EMFFormsMappingDMRExpander) curService;
69:                                 serviceReference = curRef;
70:                                 break;
71:                         }
72:                         bundleContext.ungetService(curRef);
73:                 }
74:
75:•                if (mappingDMRExpander == null) {
76:                         fail("The EMFFormsMappingDMRExpander could not be found."); //$NON-NLS-1$
77:                 }
78:         }
79:
80:         @After
81:         public void tearDown() {
82:                 bundleContext.ungetService(serviceReference);
83:         }
84:
85:         @Test
86:         public void testServiceType() {
87:                 assertTrue(EMFFormsMappingDMRExpander.class.isInstance(mappingDMRExpander));
88:         }
89:
90:         /**
91:          * Test method for
92:          * {@link org.eclipse.emfforms.internal.core.services.domainexpander.mapping.EMFFormsMappingDMRExpander#prepareDomainObject(org.eclipse.emf.ecp.view.spi.model.VDomainModelReference, org.eclipse.emf.ecore.EObject)}
93:          * .
94:          *
95:          * @throws EMFFormsExpandingFailedException
96:          */
97:         @Test
98:         public void testPrepareDomainObject() throws EMFFormsExpandingFailedException {
99:                 final VMappingDomainModelReference mappingDMR = VMappingdmrFactory.eINSTANCE
100:                         .createMappingDomainModelReference();
101:                 mappingDMR.getDomainModelEReferencePath().add(TestPackage.eINSTANCE.getB_C());
102:                 mappingDMR.setDomainModelEFeature(TestPackage.eINSTANCE.getC_EClassToA());
103:                 final VFeaturePathDomainModelReference targetDMR = VViewFactory.eINSTANCE
104:                         .createFeaturePathDomainModelReference();
105:                 targetDMR.getDomainModelEReferencePath().add(TestPackage.eINSTANCE.getA_B());
106:                 targetDMR.setDomainModelEFeature(TestPackage.eINSTANCE.getB_C());
107:
108:                 mappingDMR.setDomainModelReference(targetDMR);
109:                 mappingDMR.setMappedClass(TestPackage.eINSTANCE.getA());
110:
111:                 final B domainObject = TestFactory.eINSTANCE.createB();
112:
113:                 mappingDMRExpander.prepareDomainObject(mappingDMR, domainObject);
114:                 assertNotNull(domainObject.getC());
115:                 final A mapValue = domainObject.getC().getEClassToA().get(TestPackage.eINSTANCE.getA());
116:                 assertNotNull(mapValue);
117:                 assertNotNull(mapValue.getB());
118:         }
119: }