Skip to content

Package: MultiSegmentExpander_ITest

MultiSegmentExpander_ITest

nameinstructionbranchcomplexitylinemethod
MultiSegmentExpander_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: 0 C: 83
100%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 0 C: 21
100%
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: 15
100%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 5
100%
M: 0 C: 1
100%
testDomainExpanderIntegration()
M: 0 C: 43
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 12
100%
M: 0 C: 1
100%
testReportServiceIntegration()
M: 0 C: 14
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-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.multi;
15:
16: import static org.junit.Assert.assertNotNull;
17: import static org.mockito.Matchers.any;
18: import static org.mockito.Mockito.mock;
19: import static org.mockito.Mockito.verify;
20:
21: import java.util.Collection;
22: import java.util.Dictionary;
23: import java.util.Hashtable;
24:
25: import org.eclipse.emf.ecore.EReference;
26: import org.eclipse.emf.ecp.view.spi.model.VDomainModelReference;
27: import org.eclipse.emf.ecp.view.spi.model.VViewFactory;
28: import org.eclipse.emfforms.core.services.databinding.testmodel.test.model.B;
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.EMFFormsDMRSegmentExpander;
35: import org.eclipse.emfforms.spi.core.services.domainexpander.EMFFormsDomainExpander;
36: import org.eclipse.emfforms.spi.core.services.domainexpander.EMFFormsExpandingFailedException;
37: import org.eclipse.emfforms.view.spi.multisegment.model.VMultiDomainModelReferenceSegment;
38: import org.eclipse.emfforms.view.spi.multisegment.model.VMultisegmentFactory;
39: import org.junit.After;
40: import org.junit.Before;
41: import org.junit.BeforeClass;
42: import org.junit.Test;
43: import org.osgi.framework.BundleContext;
44: import org.osgi.framework.Constants;
45: import org.osgi.framework.FrameworkUtil;
46: import org.osgi.framework.ServiceReference;
47: import org.osgi.framework.ServiceRegistration;
48:
49: /**
50: * All JUnit integration tests for {@link MultiSegmentExpander}.
51: *
52: * @author Lucas Koehler
53: *
54: */
55: public class MultiSegmentExpander_ITest {
56:
57:         private static BundleContext bundleContext;
58:         private EMFFormsDMRSegmentExpander multiConverter;
59:         private ServiceReference<EMFFormsDMRSegmentExpander> serviceReference;
60:         private EMFFormsDomainExpander domainExpander;
61:         private ServiceRegistration<EMFFormsDomainExpander> domainExpanderRegistration;
62:         private ReportService reportService;
63:         private ServiceRegistration<ReportService> reportServiceRegistration;
64:
65:         @BeforeClass
66:         public static void setUpBeforeClass() {
67:                 bundleContext = FrameworkUtil.getBundle(MultiSegmentExpander_ITest.class).getBundleContext();
68:         }
69:
70:         /**
71:          * @throws java.lang.Exception
72:          */
73:         @Before
74:         public void setUp() throws Exception {
75:                 final Dictionary<String, Object> dictionary = new Hashtable<String, Object>();
76:                 dictionary.put(Constants.SERVICE_RANKING, 5000);
77:                 domainExpander = mock(EMFFormsDomainExpander.class);
78:                 domainExpanderRegistration = bundleContext.registerService(EMFFormsDomainExpander.class, domainExpander,
79:                         dictionary);
80:                 reportService = mock(ReportService.class);
81:                 reportServiceRegistration = bundleContext.registerService(ReportService.class, reportService, dictionary);
82:
83:                 final Collection<ServiceReference<EMFFormsDMRSegmentExpander>> serviceReferences = bundleContext
84:                         .getServiceReferences(EMFFormsDMRSegmentExpander.class, null);
85:                 multiConverter = null;
86:                 serviceReference = null;
87:•                for (final ServiceReference<EMFFormsDMRSegmentExpander> curRef : serviceReferences) {
88:                         final EMFFormsDMRSegmentExpander curService = bundleContext.getService(curRef);
89:•                        if (MultiSegmentExpander.class.isInstance(curService)) {
90:                                 multiConverter = curService;
91:                                 serviceReference = curRef;
92:                                 break;
93:                         }
94:                         bundleContext.ungetService(curRef);
95:                 }
96:
97:                 assertNotNull("MultiSegmentExpander was not registered as an EMFFormsDMRSegmentExpander.", //$NON-NLS-1$
98:                         multiConverter);
99:         }
100:
101:         @After
102:         public void tearDown() {
103:•                if (serviceReference != null) {
104:                         bundleContext.ungetService(serviceReference);
105:                 }
106:                 domainExpanderRegistration.unregister();
107:                 reportServiceRegistration.unregister();
108:         }
109:
110:         @Test
111:         public void testDomainExpanderIntegration() throws EMFFormsExpandingFailedException {
112:                 final EReference eReference = TestPackage.eINSTANCE.getB_CList();
113:                 final B domain = TestFactory.eINSTANCE.createB();
114:                 final C child = TestFactory.eINSTANCE.createC();
115:                 domain.getCList().add(child);
116:                 final VDomainModelReference childDMR = VViewFactory.eINSTANCE.createFeaturePathDomainModelReference();
117:                 final VMultiDomainModelReferenceSegment multiSegment = VMultisegmentFactory.eINSTANCE
118:                         .createMultiDomainModelReferenceSegment();
119:                 multiSegment.setDomainModelFeature(eReference.getName());
120:                 multiSegment.getChildDomainModelReferences().add(childDMR);
121:
122:                 multiConverter.prepareDomainObject(multiSegment, domain);
123:
124:                 verify(domainExpander).prepareDomainObject(childDMR, child);
125:         }
126:
127:         @Test
128:         public void testReportServiceIntegration() {
129:                 multiConverter.isApplicable(null);
130:                 verify(reportService).report(any(AbstractReport.class));
131:         }
132: }