Skip to content

Package: EMFFormsStructuralChangeTesterImpl_ITest

EMFFormsStructuralChangeTesterImpl_ITest

nameinstructionbranchcomplexitylinemethod
EMFFormsStructuralChangeTesterImpl_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: 62
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 13
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: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
testIntegration()
M: 0 C: 108
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 20
100%
M: 0 C: 1
100%
testIntegrationReportService()
M: 0 C: 78
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 16
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.structuralchange;
15:
16: import static org.junit.Assert.assertFalse;
17: import static org.junit.Assert.assertTrue;
18: import static org.mockito.Matchers.any;
19: import static org.mockito.Mockito.mock;
20: import static org.mockito.Mockito.verify;
21: import static org.mockito.Mockito.when;
22:
23: import java.util.Dictionary;
24: import java.util.Hashtable;
25:
26: import org.eclipse.emf.common.notify.Notification;
27: import org.eclipse.emf.ecore.EReference;
28: import org.eclipse.emf.ecore.EStructuralFeature.Setting;
29: import org.eclipse.emf.ecore.InternalEObject;
30: import org.eclipse.emf.ecp.view.spi.model.ModelChangeNotification;
31: import org.eclipse.emf.ecp.view.spi.model.VDomainModelReference;
32: import org.eclipse.emf.ecp.view.spi.model.VFeatureDomainModelReferenceSegment;
33: import org.eclipse.emf.ecp.view.spi.model.VViewFactory;
34: import org.eclipse.emfforms.core.services.databinding.testmodel.test.model.B;
35: import org.eclipse.emfforms.core.services.databinding.testmodel.test.model.C;
36: import org.eclipse.emfforms.core.services.databinding.testmodel.test.model.TestFactory;
37: import org.eclipse.emfforms.core.services.databinding.testmodel.test.model.TestPackage;
38: import org.eclipse.emfforms.spi.common.report.AbstractReport;
39: import org.eclipse.emfforms.spi.common.report.ReportService;
40: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedException;
41: import org.eclipse.emfforms.spi.core.services.databinding.emf.EMFFormsSegmentResolver;
42: import org.eclipse.emfforms.spi.core.services.structuralchange.EMFFormsStructuralChangeTester;
43: import org.eclipse.emfforms.spi.core.services.structuralchange.StructuralChangeSegmentTester;
44: import org.junit.After;
45: import org.junit.Before;
46: import org.junit.BeforeClass;
47: import org.junit.Test;
48: import org.osgi.framework.BundleContext;
49: import org.osgi.framework.Constants;
50: import org.osgi.framework.FrameworkUtil;
51: import org.osgi.framework.ServiceReference;
52: import org.osgi.framework.ServiceRegistration;
53:
54: /**
55: * JUnit integration org.eclipse.emfforms.core.services.structuralchange.test for
56: * {@link EMFFormsStructuralChangeTesterImpl}.
57: *
58: * @author Lucas Koehler
59: *
60: */
61: public class EMFFormsStructuralChangeTesterImpl_ITest {
62:
63:         private static BundleContext bundleContext;
64:         private ServiceReference<EMFFormsStructuralChangeTester> serviceReference;
65:         private EMFFormsStructuralChangeTester service;
66:         private EMFFormsSegmentResolver segmentResolver;
67:         private ReportService reportService;
68:         private ServiceRegistration<ReportService> reportServiceRegistration;
69:         private ServiceRegistration<EMFFormsSegmentResolver> segmentResolverRegistration;
70:         private StructuralChangeSegmentTester segmentTester;
71:         private ServiceRegistration<StructuralChangeSegmentTester> segmentTesterRegistration;
72:
73:         @BeforeClass
74:         public static void setUpBeforeClass() {
75:                 bundleContext = FrameworkUtil.getBundle(EMFFormsStructuralChangeTesterImpl_ITest.class).getBundleContext();
76:         }
77:
78:         @Before
79:         public void setUp() {
80:                 reportService = mock(ReportService.class);
81:                 segmentResolver = mock(EMFFormsSegmentResolver.class);
82:                 segmentTester = mock(StructuralChangeSegmentTester.class);
83:
84:                 final Dictionary<String, Object> dictionary = new Hashtable<String, Object>();
85:                 dictionary.put(Constants.SERVICE_RANKING, 5000);
86:                 reportServiceRegistration = bundleContext.registerService(ReportService.class, reportService, dictionary);
87:                 segmentResolverRegistration = bundleContext.registerService(EMFFormsSegmentResolver.class, segmentResolver,
88:                         dictionary);
89:                 segmentTesterRegistration = bundleContext.registerService(StructuralChangeSegmentTester.class, segmentTester,
90:                         dictionary);
91:
92:                 serviceReference = bundleContext.getServiceReference(EMFFormsStructuralChangeTester.class);
93:                 service = bundleContext.getService(serviceReference);
94:         }
95:
96:         @After
97:         public void tearDown() {
98:                 reportServiceRegistration.unregister();
99:                 segmentResolverRegistration.unregister();
100:                 segmentTesterRegistration.unregister();
101:         }
102:
103:         @Test
104:         public void testServiceType() {
105:                 assertTrue(EMFFormsStructuralChangeTesterImpl.class.isInstance(service));
106:         }
107:
108:         @Test
109:         public void testIntegration() throws DatabindingFailedException {
110:                 final B domain = TestFactory.eINSTANCE.createB();
111:                 final EReference eReference = TestPackage.eINSTANCE.getB_C();
112:                 final Setting setting = ((InternalEObject) domain).eSetting(eReference);
113:                 final VFeatureDomainModelReferenceSegment segment = VViewFactory.eINSTANCE
114:                         .createFeatureDomainModelReferenceSegment();
115:                 segment.setDomainModelFeature(eReference.getName());
116:                 final VDomainModelReference dmr = VViewFactory.eINSTANCE.createFeaturePathDomainModelReference();
117:                 dmr.getSegments().add(segment);
118:
119:                 final C newValue = TestFactory.eINSTANCE.createC();
120:                 final TestNotification raw = new TestNotification(Notification.SET, null, newValue, domain, eReference);
121:                 final ModelChangeNotification mcn = new ModelChangeNotification(raw);
122:
123:                 when(segmentResolver.resolveSegment(segment, domain)).thenReturn(setting);
124:                 when(segmentTester.isApplicable(segment)).thenReturn(1d);
125:                 when(segmentTester.isStructureChanged(segment, domain, mcn)).thenReturn(true);
126:
127:                 final boolean isChanged = service.isStructureChanged(dmr, domain, mcn);
128:
129:                 assertTrue(isChanged);
130:                 verify(segmentResolver).resolveSegment(segment, domain);
131:                 verify(segmentTester).isApplicable(segment);
132:                 verify(segmentTester).isStructureChanged(segment, domain, mcn);
133:         }
134:
135:         @SuppressWarnings("unchecked")
136:         @Test
137:         public void testIntegrationReportService() throws DatabindingFailedException {
138:                 final B domain = TestFactory.eINSTANCE.createB();
139:                 final EReference eReference = TestPackage.eINSTANCE.getB_C();
140:                 final VFeatureDomainModelReferenceSegment segment = VViewFactory.eINSTANCE
141:                         .createFeatureDomainModelReferenceSegment();
142:                 segment.setDomainModelFeature(eReference.getName());
143:                 final VDomainModelReference dmr = VViewFactory.eINSTANCE.createFeaturePathDomainModelReference();
144:                 dmr.getSegments().add(segment);
145:
146:                 final C newValue = TestFactory.eINSTANCE.createC();
147:                 final TestNotification raw = new TestNotification(Notification.SET, null, newValue, domain, eReference);
148:                 final ModelChangeNotification mcn = new ModelChangeNotification(raw);
149:
150:                 when(segmentResolver.resolveSegment(segment, domain)).thenThrow(DatabindingFailedException.class);
151:
152:                 final boolean isChanged = service.isStructureChanged(dmr, domain, mcn);
153:
154:                 assertFalse(isChanged);
155:                 verify(segmentResolver).resolveSegment(segment, domain);
156:                 verify(reportService).report(any(AbstractReport.class));
157:         }
158: }