Skip to content

Package: EMFFormsLabelProviderDefaultImpl_ITest

EMFFormsLabelProviderDefaultImpl_ITest

nameinstructionbranchcomplexitylinemethod
EMFFormsLabelProviderDefaultImpl_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: 9
100%
M: 0 C: 1
100%
setUpBeforeClass()
M: 0 C: 144
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 30
100%
M: 0 C: 1
100%
tearDown()
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
tearDownClass()
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
testServiceUsageDescriptionOneParam()
M: 0 C: 20
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
testServiceUsageDescriptionTwoParam()
M: 0 C: 21
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
testServiceUsageDisplayNameOneParam()
M: 0 C: 20
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
testServiceUsageDisplayNameTwoParam()
M: 0 C: 21
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2015 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.label;
15:
16: import static org.mockito.Matchers.any;
17: import static org.mockito.Matchers.isNull;
18: import static org.mockito.Matchers.same;
19: import static org.mockito.Mockito.mock;
20: import static org.mockito.Mockito.reset;
21: import static org.mockito.Mockito.verify;
22: import static org.mockito.Mockito.when;
23:
24: import java.util.Dictionary;
25: import java.util.Hashtable;
26:
27: import org.eclipse.emf.databinding.EObjectObservableValue;
28: import org.eclipse.emf.databinding.IEMFValueProperty;
29: import org.eclipse.emf.ecore.EClass;
30: import org.eclipse.emf.ecore.EObject;
31: import org.eclipse.emf.ecore.EStructuralFeature;
32: import org.eclipse.emf.ecp.test.common.DefaultRealm;
33: import org.eclipse.emf.ecp.view.spi.model.VDomainModelReference;
34: import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
35: import org.eclipse.emfforms.core.services.databinding.testmodel.test.model.TestPackage;
36: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedException;
37: import org.eclipse.emfforms.spi.core.services.databinding.emf.EMFFormsDatabindingEMF;
38: import org.eclipse.emfforms.spi.core.services.emfspecificservice.EMFSpecificService;
39: import org.eclipse.emfforms.spi.core.services.label.EMFFormsLabelProvider;
40: import org.eclipse.emfforms.spi.core.services.label.NoLabelFoundException;
41: import org.junit.After;
42: import org.junit.AfterClass;
43: import org.junit.Before;
44: import org.junit.BeforeClass;
45: import org.junit.Test;
46: import org.osgi.framework.BundleContext;
47: import org.osgi.framework.FrameworkUtil;
48: import org.osgi.framework.InvalidSyntaxException;
49: import org.osgi.framework.ServiceReference;
50: import org.osgi.framework.ServiceRegistration;
51:
52: /**
53: * JUnit integration test that tests that {@link EMFFormsLabelProviderDefaultImpl} uses the correct services.
54: *
55: * @author Lucas Koehler
56: *
57: */
58: public class EMFFormsLabelProviderDefaultImpl_ITest {
59:
60:         private static BundleContext bundleContext;
61:         private static EMFFormsDatabindingEMF databindingService;
62:         private static ServiceRegistration<EMFFormsDatabindingEMF> databindingRegisterService;
63:         private static EMFSpecificService emfSpecificService;
64:         private static ServiceRegistration<EMFSpecificService> emfSpecificRegisterService;
65:         private static EMFFormsLabelProviderDefaultImpl labelProvider;
66:         private static ServiceReference<EMFFormsLabelProvider> serviceReference;
67:         private static IEMFValueProperty valueProperty;
68:         private static EObjectObservableValue observableValue;
69:         private static IItemPropertyDescriptor itemPropertyDescriptor;
70:
71:         /**
72:          * Set up that is executed before every test case.
73:          * Registers a databinding and an emf specific service.
74:          * Mocks various objects for the tests.
75:          *
76:          * @throws DatabindingFailedException should not happen, just needs to be thrown because the databinding service
77:          * defines the throw in its interface.
78:          * @throws InvalidSyntaxException thrown by OSGI
79:          */
80:         @BeforeClass
81:         public static void setUpBeforeClass() throws DatabindingFailedException, InvalidSyntaxException {
82:                 bundleContext = FrameworkUtil.getBundle(EMFFormsLabelProviderDefaultImpl_ITest.class).getBundleContext();
83:
84:                 final Dictionary<String, Object> dictionary = new Hashtable<String, Object>();
85:                 dictionary.put("service.ranking", 5); //$NON-NLS-1$
86:
87:                 databindingService = mock(EMFFormsDatabindingEMF.class);
88:                 databindingRegisterService = bundleContext.registerService(EMFFormsDatabindingEMF.class, databindingService,
89:                         dictionary);
90:
91:                 emfSpecificService = mock(EMFSpecificService.class);
92:                 emfSpecificRegisterService = bundleContext.registerService(
93:                         EMFSpecificService.class, emfSpecificService, dictionary);
94:
95:                 final EClass eContainingClass = TestPackage.eINSTANCE.getD();
96:                 final EStructuralFeature structuralFeature = mock(EStructuralFeature.class);
97:                 when(structuralFeature.getEContainingClass()).thenReturn(eContainingClass);
98:                 valueProperty = mock(IEMFValueProperty.class);
99:                 when(valueProperty.getValueType()).thenReturn(structuralFeature);
100:                 observableValue = mock(EObjectObservableValue.class);
101:                 when(observableValue.getValueType()).thenReturn(structuralFeature);
102:                 when(observableValue.getObserved()).thenReturn(mock(EObject.class));
103:                 itemPropertyDescriptor = mock(IItemPropertyDescriptor.class);
104:                 when(itemPropertyDescriptor.getDescription(any(EObject.class))).thenReturn("description"); //$NON-NLS-1$
105:                 when(itemPropertyDescriptor.getDisplayName(any(EObject.class))).thenReturn("displayName"); //$NON-NLS-1$
106:
107:                 when(emfSpecificService.getIItemPropertyDescriptor(any(EObject.class), same(structuralFeature))).thenReturn(
108:                         itemPropertyDescriptor);
109:                 when(databindingService.getValueProperty(any(VDomainModelReference.class), any(EObject.class))).thenReturn(
110:                         valueProperty);
111:                 when(databindingService.getObservableValue(any(VDomainModelReference.class), any(EObject.class))).thenReturn(
112:                         observableValue);
113:
114:                 serviceReference = bundleContext.getServiceReferences(EMFFormsLabelProvider.class, "(service.ranking=1)") //$NON-NLS-1$
115:                         .iterator().next();
116:                 labelProvider = (EMFFormsLabelProviderDefaultImpl) bundleContext.getService(serviceReference);
117:         }
118:
119:         private DefaultRealm realm;
120:
121:         /**
122:          * Resets and newly configures the services for every test.
123:          *
124:          * @throws DatabindingFailedException should not happen, just needs to be thrown because the databinding service
125:          * defines the throw in its interface.
126:          */
127:         @Before
128:         public void setUp() throws DatabindingFailedException {
129:                 reset(databindingService);
130:                 when(databindingService.getValueProperty(any(VDomainModelReference.class), any(EObject.class))).thenReturn(
131:                         valueProperty);
132:                 when(databindingService.getValueProperty(any(VDomainModelReference.class), any(EClass.class))).thenReturn(
133:                         valueProperty);
134:                 when(databindingService.getObservableValue(any(VDomainModelReference.class), any(EObject.class))).thenReturn(
135:                         observableValue);
136:                 realm = new DefaultRealm();
137:         }
138:
139:         /**
140:          * Dispose the realm.
141:          */
142:         @After
143:         public void tearDown() {
144:                 realm.dispose();
145:         }
146:
147:         /**
148:          * Unregisters the services after every test.
149:          */
150:         @AfterClass
151:         public static void tearDownClass() {
152:                 databindingRegisterService.unregister();
153:                 emfSpecificRegisterService.unregister();
154:                 bundleContext.ungetService(serviceReference);
155:         }
156:
157:         /**
158:          * Tests that {@link EMFFormsLabelProviderDefaultImpl#getDisplayName(VDomainModelReference)} uses the databinding
159:          * and emf
160:          * specific services.
161:          *
162:          * @throws DatabindingFailedException should not happen, just needs to be thrown because the databinding service
163:          * defines the throw in its interface.
164:          * @throws NoLabelFoundException should not be thrown
165:          */
166:         @Test
167:         public void testServiceUsageDisplayNameOneParam() throws DatabindingFailedException, NoLabelFoundException {
168:                 final VDomainModelReference domainModelReference = mock(VDomainModelReference.class);
169:                 labelProvider.getDisplayName(domainModelReference);
170:
171:                 verify(databindingService).getValueProperty(same(domainModelReference), isNull(EObject.class));
172:         }
173:
174:         /**
175:          * Tests that {@link EMFFormsLabelProviderDefaultImpl#getDescription(VDomainModelReference)} uses the databinding
176:          * and emf
177:          * specific services.
178:          *
179:          * @throws DatabindingFailedException should not happen, just needs to be thrown because the databinding service
180:          * defines the throw in its interface.
181:          * @throws NoLabelFoundException should not be thrown
182:          */
183:         @Test
184:         public void testServiceUsageDescriptionOneParam() throws DatabindingFailedException, NoLabelFoundException {
185:                 final VDomainModelReference domainModelReference = mock(VDomainModelReference.class);
186:                 labelProvider.getDescription(domainModelReference);
187:
188:                 verify(databindingService).getValueProperty(same(domainModelReference), isNull(EObject.class));
189:         }
190:
191:         /**
192:          * Tests that {@link EMFFormsLabelProviderDefaultImpl#getDisplayName(VDomainModelReference, EObject)} uses the
193:          * databinding
194:          * and emf specific services.
195:          *
196:          * @throws DatabindingFailedException should not happen, just needs to be thrown because the databinding service
197:          * defines the throw in its interface.
198:          * @throws NoLabelFoundException Should not be thrown
199:          */
200:         @Test
201:         public void testServiceUsageDisplayNameTwoParam() throws DatabindingFailedException, NoLabelFoundException {
202:                 final VDomainModelReference domainModelReference = mock(VDomainModelReference.class);
203:                 final EObject eObject = mock(EObject.class);
204:                 labelProvider.getDisplayName(domainModelReference, eObject);
205:
206:                 verify(databindingService).getObservableValue(domainModelReference, eObject);
207:         }
208:
209:         /**
210:          * Tests that {@link EMFFormsLabelProviderDefaultImpl#getDescription(VDomainModelReference, EObject)} uses the
211:          * databinding
212:          * and emf specific services.
213:          *
214:          * @throws DatabindingFailedException should not happen, just needs to be thrown because the databinding service
215:          * defines the throw in its interface.
216:          * @throws NoLabelFoundException Should not be thrown
217:          */
218:         @Test
219:         public void testServiceUsageDescriptionTwoParam() throws DatabindingFailedException, NoLabelFoundException {
220:                 final VDomainModelReference domainModelReference = mock(VDomainModelReference.class);
221:                 final EObject eObject = mock(EObject.class);
222:                 labelProvider.getDescription(domainModelReference, eObject);
223:
224:                 verify(databindingService).getObservableValue(domainModelReference, eObject);
225:         }
226: }