Skip to content

Package: IndexSegmentStructuralChangeTester_ITest

IndexSegmentStructuralChangeTester_ITest

nameinstructionbranchcomplexitylinemethod
IndexSegmentStructuralChangeTester_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%
lambda$0(ServiceReference)
M: 0 C: 5
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: 18
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
setUpBeforeClass()
M: 0 C: 35
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 9
100%
M: 0 C: 1
100%
tearDownAfterAll()
M: 0 C: 5
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: 91
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 19
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2016 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.index;
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.reset;
20: import static org.mockito.Mockito.verify;
21: import static org.mockito.Mockito.when;
22:
23: import java.util.Collection;
24: import java.util.Dictionary;
25: import java.util.Hashtable;
26: import java.util.Optional;
27:
28: import org.eclipse.emf.common.notify.Notification;
29: import org.eclipse.emf.ecore.EObject;
30: import org.eclipse.emf.ecore.EStructuralFeature.Setting;
31: import org.eclipse.emf.ecp.view.spi.model.ModelChangeNotification;
32: import org.eclipse.emf.ecp.view.spi.model.VDomainModelReferenceSegment;
33: import org.eclipse.emfforms.spi.common.report.AbstractReport;
34: import org.eclipse.emfforms.spi.common.report.ReportService;
35: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedException;
36: import org.eclipse.emfforms.spi.core.services.databinding.emf.EMFFormsSegmentResolver;
37: import org.eclipse.emfforms.spi.core.services.structuralchange.StructuralChangeSegmentTester;
38: import org.eclipse.emfforms.spi.view.indexsegment.model.VIndexDomainModelReferenceSegment;
39: import org.junit.AfterClass;
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.InvalidSyntaxException;
47: import org.osgi.framework.ServiceReference;
48: import org.osgi.framework.ServiceRegistration;
49:
50: /**
51: * JUnit integration tests for {@link IndexSegmentStructuralChangeTester}.
52: *
53: * @author Lucas Koehler
54: *
55: */
56: public class IndexSegmentStructuralChangeTester_ITest {
57:
58:         private static BundleContext bundleContext;
59:         private static ServiceRegistration<ReportService> reportServiceRegistration;
60:         private static ServiceRegistration<EMFFormsSegmentResolver> segmentResolverRegistration;
61:         private static EMFFormsSegmentResolver segmentResolver;
62:         private static ReportService reportService;
63:         private Collection<ServiceReference<StructuralChangeSegmentTester>> serviceReferences;
64:
65:         @BeforeClass
66:         public static void setUpBeforeClass() {
67:                 bundleContext = FrameworkUtil.getBundle(IndexSegmentStructuralChangeTester_ITest.class).getBundleContext();
68:                 final Dictionary<String, Object> dictionary = new Hashtable<String, Object>();
69:                 dictionary.put(Constants.SERVICE_RANKING, 5000);
70:                 reportService = mock(ReportService.class);
71:                 segmentResolver = mock(EMFFormsSegmentResolver.class);
72:                 reportServiceRegistration = bundleContext.registerService(ReportService.class, reportService, dictionary);
73:                 segmentResolverRegistration = bundleContext.registerService(EMFFormsSegmentResolver.class, segmentResolver,
74:                         dictionary);
75:         }
76:
77:         @Before
78:         public void setUp() throws InvalidSyntaxException {
79:                 reset(reportService, segmentResolver);
80:                 serviceReferences = bundleContext.getServiceReferences(StructuralChangeSegmentTester.class, null);
81:         }
82:
83:         @AfterClass
84:         public static void tearDownAfterAll() {
85:                 reportServiceRegistration.unregister();
86:                 segmentResolverRegistration.unregister();
87:         }
88:
89:         @Test
90:         public void testIntegration() throws DatabindingFailedException {
91:                 final Optional<IndexSegmentStructuralChangeTester> indexService = serviceReferences.stream()
92:                         .map(ref -> bundleContext.getService(ref))
93:                         .filter(IndexSegmentStructuralChangeTester.class::isInstance)
94:                         .findFirst()
95:                         .map(IndexSegmentStructuralChangeTester.class::cast);
96:
97:                 assertTrue("IndexSegmentStructuralChangeTester present: ", indexService.isPresent()); //$NON-NLS-1$
98:                 when(segmentResolver.resolveSegment(any(VDomainModelReferenceSegment.class), any(EObject.class)))
99:                         .thenReturn(mock(Setting.class));
100:
101:                 final Notification notification = mock(Notification.class);
102:                 when(notification.isTouch()).thenReturn(false);
103:                 final ModelChangeNotification mcn = new ModelChangeNotification(notification);
104:                 final VIndexDomainModelReferenceSegment segment = mock(VIndexDomainModelReferenceSegment.class);
105:                 final EObject domain = mock(EObject.class);
106:
107:                 final IndexSegmentStructuralChangeTester changeTester = indexService.get();
108:
109:                 changeTester.isApplicable(null);
110:                 changeTester.isStructureChanged(segment, domain, mcn);
111:
112:                 verify(reportService).report(any(AbstractReport.class));
113:                 verify(segmentResolver).resolveSegment(segment, domain);
114:         }
115:
116: }