Skip to content

Package: MappingDmrSegmentGenerator_ITest

MappingDmrSegmentGenerator_ITest

nameinstructionbranchcomplexitylinemethod
MappingDmrSegmentGenerator_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%
integration()
M: 0 C: 77
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 21
100%
M: 0 C: 1
100%
integration_failure()
M: 0 C: 44
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 12
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%
lambda$1(DmrSegmentGenerator)
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%
lambda$2(ServiceReference)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
lambda$3(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%
lambda$4(DmrSegmentGenerator)
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%
lambda$5(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%
lambda$6(DmrSegmentGenerator)
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%
serviceRegistered()
M: 0 C: 19
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
setUp()
M: 0 C: 15
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%
tearDownAfterClass()
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%

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.mapping;
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.never;
20: import static org.mockito.Mockito.reset;
21: import static org.mockito.Mockito.times;
22: import static org.mockito.Mockito.verify;
23: import static org.mockito.Mockito.when;
24:
25: import java.util.Collection;
26: import java.util.Collections;
27: import java.util.Dictionary;
28: import java.util.Hashtable;
29: import java.util.LinkedList;
30: import java.util.List;
31: import java.util.Optional;
32:
33: import org.eclipse.emf.ecp.view.spi.mappingdmr.model.VMappingDomainModelReference;
34: import org.eclipse.emf.ecp.view.spi.mappingdmr.model.VMappingdmrFactory;
35: import org.eclipse.emf.ecp.view.spi.model.VDomainModelReference;
36: import org.eclipse.emf.ecp.view.spi.model.VDomainModelReferenceSegment;
37: import org.eclipse.emf.ecp.view.spi.model.VFeaturePathDomainModelReference;
38: import org.eclipse.emf.ecp.view.spi.model.VViewFactory;
39: import org.eclipse.emfforms.core.services.databinding.testmodel.test.model.TestPackage;
40: import org.eclipse.emfforms.spi.common.report.AbstractReport;
41: import org.eclipse.emfforms.spi.common.report.ReportService;
42: import org.eclipse.emfforms.spi.core.services.segments.DmrSegmentGenerator;
43: import org.eclipse.emfforms.spi.core.services.segments.EMFFormsSegmentGenerator;
44: import org.junit.AfterClass;
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.InvalidSyntaxException;
52: import org.osgi.framework.ServiceReference;
53: import org.osgi.framework.ServiceRegistration;
54:
55: /**
56: * Intergration test cases {@link MappingDmrSegmentGenerator}.
57: *
58: * @author Lucas Koehler
59: *
60: */
61: public class MappingDmrSegmentGenerator_ITest {
62:
63:         private static BundleContext bundleContext;
64:         private static EMFFormsSegmentGenerator emfFormsSegmentGenerator;
65:         private static ReportService reportService;
66:         private static ServiceRegistration<EMFFormsSegmentGenerator> segmentGeneratorRegistration;
67:         private static ServiceRegistration<ReportService> reportServiceRegistration;
68:
69:         @BeforeClass
70:         public static void setUpBeforeClass() {
71:                 bundleContext = FrameworkUtil.getBundle(MappingDmrSegmentGenerator_ITest.class).getBundleContext();
72:
73:                 emfFormsSegmentGenerator = mock(EMFFormsSegmentGenerator.class);
74:                 reportService = mock(ReportService.class);
75:
76:                 final Dictionary<String, Object> dictionary = new Hashtable<String, Object>();
77:                 dictionary.put(Constants.SERVICE_RANKING, 5000);
78:
79:                 segmentGeneratorRegistration = bundleContext
80:                         .registerService(EMFFormsSegmentGenerator.class, emfFormsSegmentGenerator, dictionary);
81:                 reportServiceRegistration = bundleContext.registerService(ReportService.class, reportService, dictionary);
82:         }
83:
84:         @AfterClass
85:         public static void tearDownAfterClass() {
86:                 segmentGeneratorRegistration.unregister();
87:                 reportServiceRegistration.unregister();
88:         }
89:
90:         @Before
91:         public void setUp() {
92:                 reset(emfFormsSegmentGenerator);
93:                 reset(reportService);
94:         }
95:
96:         @Test
97:         public void serviceRegistered() throws InvalidSyntaxException {
98:                 final Collection<ServiceReference<DmrSegmentGenerator>> references = bundleContext
99:                         .getServiceReferences(DmrSegmentGenerator.class, null);
100:
101:                 final boolean registered = references.stream().map(ref -> bundleContext.getService(ref))
102:                         .anyMatch(service -> MappingDmrSegmentGenerator.class.equals(service.getClass()));
103:                 references.forEach(ref -> bundleContext.ungetService(ref));
104:
105:                 assertTrue("The MappingDmrSegmentGenerator was not registered as a service", registered); //$NON-NLS-1$
106:         }
107:
108:         @Test
109:         public void integration() throws InvalidSyntaxException {
110:                 final Collection<ServiceReference<DmrSegmentGenerator>> references = bundleContext
111:                         .getServiceReferences(DmrSegmentGenerator.class, null);
112:                 final Optional<DmrSegmentGenerator> generator = references.stream().map(ref -> bundleContext.getService(ref))
113:                         .filter(service -> MappingDmrSegmentGenerator.class.equals(service.getClass())).findFirst();
114:                 assertTrue(generator.isPresent());
115:
116:                 final VMappingDomainModelReference mappingDmr = VMappingdmrFactory.eINSTANCE
117:                         .createMappingDomainModelReference();
118:                 mappingDmr.setDomainModelEFeature(TestPackage.Literals.C__ECLASS_TO_A);
119:                 mappingDmr.setMappedClass(TestPackage.Literals.A);
120:                 final VFeaturePathDomainModelReference targetDmr = VViewFactory.eINSTANCE
121:                         .createFeaturePathDomainModelReference();
122:                 targetDmr.setDomainModelEFeature(TestPackage.Literals.A__B);
123:                 mappingDmr.setDomainModelReference(targetDmr);
124:
125:                 final VDomainModelReferenceSegment segment = VViewFactory.eINSTANCE.createFeatureDomainModelReferenceSegment();
126:                 final List<VDomainModelReferenceSegment> segments = new LinkedList<>();
127:                 segments.add(segment);
128:                 when(emfFormsSegmentGenerator.generateSegments(any(VDomainModelReference.class))).thenReturn(segments);
129:                 generator.get().generateSegments(mappingDmr);
130:
131:                 // Do not validate whether the generation works correctly: this is done extensively in the unit test
132:                 verify(emfFormsSegmentGenerator, times(1)).generateSegments(targetDmr);
133:                 verify(reportService, never()).report(any(AbstractReport.class));
134:         }
135:
136:         @Test
137:         public void integration_failure() throws InvalidSyntaxException {
138:                 final Collection<ServiceReference<DmrSegmentGenerator>> references = bundleContext
139:                         .getServiceReferences(DmrSegmentGenerator.class, null);
140:                 final Optional<DmrSegmentGenerator> generator = references.stream().map(ref -> bundleContext.getService(ref))
141:                         .filter(service -> MappingDmrSegmentGenerator.class.equals(service.getClass())).findFirst();
142:                 assertTrue(generator.isPresent());
143:
144:                 final VMappingDomainModelReference mappingDmr = VMappingdmrFactory.eINSTANCE
145:                         .createMappingDomainModelReference();
146:                 when(emfFormsSegmentGenerator.generateSegments(any(VDomainModelReference.class)))
147:                         .thenReturn(Collections.emptyList());
148:                 generator.get().generateSegments(mappingDmr);
149:
150:                 // Do not validate whether the generation works correctly: this is done extensively in the unit test
151:                 verify(reportService, times(1)).report(any(AbstractReport.class));
152:         }
153:
154: }