Skip to content

Package: FeatureSegmentStructuralChangeTester_ITest

FeatureSegmentStructuralChangeTester_ITest

nameinstructionbranchcomplexitylinemethod
FeatureSegmentStructuralChangeTester_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: 49
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 10
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: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
testIntegration()
M: 0 C: 71
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 13
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-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.featurepath;
15:
16: import static org.junit.Assert.assertTrue;
17: import static org.mockito.Matchers.any;
18: import static org.mockito.Mockito.mock;
19: import static org.mockito.Mockito.verify;
20: import static org.mockito.Mockito.when;
21:
22: import java.util.Dictionary;
23: import java.util.Hashtable;
24:
25: import org.eclipse.emf.common.notify.Notification;
26: import org.eclipse.emf.ecore.EObject;
27: import org.eclipse.emf.ecore.EStructuralFeature.Setting;
28: import org.eclipse.emf.ecp.view.spi.model.ModelChangeNotification;
29: import org.eclipse.emf.ecp.view.spi.model.VDomainModelReferenceSegment;
30: import org.eclipse.emf.ecp.view.spi.model.VFeatureDomainModelReferenceSegment;
31: import org.eclipse.emfforms.spi.common.report.AbstractReport;
32: import org.eclipse.emfforms.spi.common.report.ReportService;
33: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedException;
34: import org.eclipse.emfforms.spi.core.services.databinding.emf.EMFFormsSegmentResolver;
35: import org.eclipse.emfforms.spi.core.services.structuralchange.StructuralChangeSegmentTester;
36: import org.junit.After;
37: import org.junit.Before;
38: import org.junit.BeforeClass;
39: import org.junit.Test;
40: import org.osgi.framework.BundleContext;
41: import org.osgi.framework.Constants;
42: import org.osgi.framework.FrameworkUtil;
43: import org.osgi.framework.ServiceReference;
44: import org.osgi.framework.ServiceRegistration;
45:
46: /**
47: * JUnit integration tests for {@link FeatureSegmentStructuralChangeTester}.
48: *
49: * @author Lucas Koehler
50: *
51: */
52: public class FeatureSegmentStructuralChangeTester_ITest {
53:
54:         private static BundleContext bundleContext;
55:         private ServiceReference<StructuralChangeSegmentTester> serviceReference;
56:         private StructuralChangeSegmentTester service;
57:         private EMFFormsSegmentResolver segmentResolver;
58:         private ReportService reportService;
59:         private ServiceRegistration<ReportService> reportServiceRegistration;
60:         private ServiceRegistration<EMFFormsSegmentResolver> segmentResolverRegistration;
61:
62:         @BeforeClass
63:         public static void setUpBeforeClass() {
64:                 bundleContext = FrameworkUtil.getBundle(FeatureSegmentStructuralChangeTester_ITest.class).getBundleContext();
65:         }
66:
67:         @Before
68:         public void setUp() {
69:                 reportService = mock(ReportService.class);
70:                 segmentResolver = mock(EMFFormsSegmentResolver.class);
71:
72:                 final Dictionary<String, Object> dictionary = new Hashtable<String, Object>();
73:                 dictionary.put(Constants.SERVICE_RANKING, 5000);
74:                 reportServiceRegistration = bundleContext.registerService(ReportService.class, reportService, dictionary);
75:                 segmentResolverRegistration = bundleContext.registerService(EMFFormsSegmentResolver.class, segmentResolver,
76:                         dictionary);
77:
78:                 serviceReference = bundleContext.getServiceReference(StructuralChangeSegmentTester.class);
79:                 service = bundleContext.getService(serviceReference);
80:         }
81:
82:         @After
83:         public void tearDown() {
84:                 reportServiceRegistration.unregister();
85:                 segmentResolverRegistration.unregister();
86:         }
87:
88:         @Test
89:         public void testServiceType() {
90:                 assertTrue(FeatureSegmentStructuralChangeTester.class.isInstance(service));
91:         }
92:
93:         @Test
94:         public void testIntegration() throws DatabindingFailedException {
95:                 when(segmentResolver.resolveSegment(any(VDomainModelReferenceSegment.class), any(EObject.class)))
96:                         .thenReturn(mock(Setting.class));
97:
98:                 final Notification notification = mock(Notification.class);
99:                 when(notification.isTouch()).thenReturn(false);
100:                 final ModelChangeNotification mcn = new ModelChangeNotification(notification);
101:                 final VFeatureDomainModelReferenceSegment segment = mock(VFeatureDomainModelReferenceSegment.class);
102:                 final EObject domain = mock(EObject.class);
103:
104:                 final FeatureSegmentStructuralChangeTester changeTester = (FeatureSegmentStructuralChangeTester) service;
105:
106:                 changeTester.isApplicable(null);
107:                 changeTester.isStructureChanged(segment, domain, mcn);
108:
109:                 verify(reportService).report(any(AbstractReport.class));
110:                 verify(segmentResolver).resolveSegment(segment, domain);
111:         }
112:
113: }