Skip to content

Package: StructuralChangeTesterKeyAttribute_ITest

StructuralChangeTesterKeyAttribute_ITest

nameinstructionbranchcomplexitylinemethod
StructuralChangeTesterKeyAttribute_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%
createKeyAttributeDMR(VFeaturePathDomainModelReference, VFeaturePathDomainModelReference)
M: 0 C: 24
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
createKeyDMR()
M: 0 C: 15
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
createValueDMR()
M: 0 C: 15
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
setUp()
M: 0 C: 39
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 9
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: 3
100%
M: 0 C: 1
100%
tearDown()
M: 0 C: 9
100%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 3
100%
M: 0 C: 1
100%
testIntegration()
M: 0 C: 94
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 24
100%
M: 0 C: 1
100%
testServicePresent()
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-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.structuralchange.keyattribute;
15:
16: import static org.junit.Assert.assertTrue;
17: import static org.mockito.Mockito.mock;
18: import static org.mockito.Mockito.when;
19:
20: import java.util.Collection;
21:
22: import org.eclipse.emf.common.notify.Notification;
23: import org.eclipse.emf.ecp.view.spi.keyattributedmr.model.VKeyAttributeDomainModelReference;
24: import org.eclipse.emf.ecp.view.spi.keyattributedmr.model.VKeyattributedmrFactory;
25: import org.eclipse.emf.ecp.view.spi.model.ModelChangeNotification;
26: import org.eclipse.emf.ecp.view.spi.model.VFeaturePathDomainModelReference;
27: import org.eclipse.emf.ecp.view.spi.model.VViewFactory;
28: import org.eclipse.emfforms.core.services.databinding.testmodel.test.model.A;
29: import org.eclipse.emfforms.core.services.databinding.testmodel.test.model.B;
30: import org.eclipse.emfforms.core.services.databinding.testmodel.test.model.C;
31: import org.eclipse.emfforms.core.services.databinding.testmodel.test.model.D;
32: import org.eclipse.emfforms.core.services.databinding.testmodel.test.model.TestFactory;
33: import org.eclipse.emfforms.core.services.databinding.testmodel.test.model.TestPackage;
34: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedException;
35: import org.eclipse.emfforms.spi.core.services.structuralchange.StructuralChangeTesterInternal;
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.FrameworkUtil;
42: import org.osgi.framework.InvalidSyntaxException;
43: import org.osgi.framework.ServiceReference;
44:
45: /**
46: * JUnit integration tests for {@link StructuralChangeTesterKeyAttribute}.
47: *
48: * @author Lucas Koehler
49: *
50: */
51: public class StructuralChangeTesterKeyAttribute_ITest {
52:
53:         private static final String CORRECT_TEST_KEY = "CORRECT_TEST_KEY"; //$NON-NLS-1$
54:         private static BundleContext bundleContext;
55:         private StructuralChangeTesterInternal service;
56:         private ServiceReference<StructuralChangeTesterInternal> serviceReference;
57:
58:         @BeforeClass
59:         public static void setUpBeforeClass() {
60:                 bundleContext = FrameworkUtil.getBundle(StructuralChangeTesterKeyAttribute_ITest.class)
61:                         .getBundleContext();
62:         }
63:
64:         @Before
65:         public void setUp() throws DatabindingFailedException, InvalidSyntaxException {
66:                 final Collection<ServiceReference<StructuralChangeTesterInternal>> serviceReferences = bundleContext
67:                         .getServiceReferences(StructuralChangeTesterInternal.class, null);
68:•                for (final ServiceReference<StructuralChangeTesterInternal> testerRef : serviceReferences) {
69:                         final StructuralChangeTesterInternal currentService = bundleContext.getService(testerRef);
70:•                        if (StructuralChangeTesterKeyAttribute.class.isInstance(currentService)) {
71:                                 service = currentService;
72:                                 serviceReference = testerRef;
73:                         }
74:                 }
75:                 service = bundleContext.getService(serviceReference);
76:
77:         }
78:
79:         @After
80:         public void tearDown() {
81:•                if (serviceReference != null) {
82:                         bundleContext.ungetService(serviceReference);
83:                 }
84:         }
85:
86:         @Test
87:         public void testServicePresent() {
88:                 assertTrue(StructuralChangeTesterKeyAttribute.class.isInstance(service));
89:         }
90:
91:         /**
92:          * This is the same test case as
93:          * {@link StructuralChangeTesterKeyAttribute_Test#testIsStructureChangedKeyPresentAndValueDMRChanged}
94:          * but with a real databinding and structural change tester.
95:          */
96:         @Test
97:         public void testIntegration() {
98:                 // Create and configure DMRs
99:                 final VFeaturePathDomainModelReference keyDMR = createKeyDMR();
100:                 final VFeaturePathDomainModelReference valueDMR = createValueDMR();
101:                 final VKeyAttributeDomainModelReference keyAttributeDMR = createKeyAttributeDMR(keyDMR, valueDMR);
102:
103:                 // Create domain model
104:                 final A a = TestFactory.eINSTANCE.createA();
105:                 final B b = TestFactory.eINSTANCE.createB();
106:                 final C c = TestFactory.eINSTANCE.createC();
107:                 final A aOfC = TestFactory.eINSTANCE.createA();
108:                 final B bOfC = TestFactory.eINSTANCE.createB();
109:                 final D dWithKey = TestFactory.eINSTANCE.createD();
110:                 dWithKey.setX(CORRECT_TEST_KEY);
111:
112:                 a.setB(b);
113:                 b.getCList().add(c);
114:                 c.setD(dWithKey);
115:                 c.setA(aOfC);
116:                 aOfC.setB(bOfC);
117:
118:                 final ModelChangeNotification notification = mock(ModelChangeNotification.class);
119:                 final Notification rawNotification = mock(Notification.class);
120:
121:                 when(rawNotification.isTouch()).thenReturn(false);
122:                 when(notification.getNotifier()).thenReturn(aOfC);
123:                 when(notification.getRawNotification()).thenReturn(rawNotification);
124:                 when(notification.getStructuralFeature()).thenReturn(TestPackage.eINSTANCE.getA_B());
125:
126:                 final boolean result = service.isStructureChanged(keyAttributeDMR, a, notification);
127:
128:                 assertTrue(result);
129:         }
130:
131:         /**
132:          * @param keyDMR
133:          * @param valueDMR
134:          * @return
135:          */
136:         private VKeyAttributeDomainModelReference createKeyAttributeDMR(final VFeaturePathDomainModelReference keyDMR,
137:                 final VFeaturePathDomainModelReference valueDMR) {
138:                 final VKeyAttributeDomainModelReference keyAttributeDMR = VKeyattributedmrFactory.eINSTANCE
139:                         .createKeyAttributeDomainModelReference();
140:
141:                 keyAttributeDMR.setKeyValue(CORRECT_TEST_KEY);
142:                 keyAttributeDMR.getDomainModelEReferencePath().add(TestPackage.eINSTANCE.getA_B());
143:                 keyAttributeDMR.setDomainModelEFeature(TestPackage.eINSTANCE.getB_CList());
144:
145:                 keyAttributeDMR.setKeyDMR(keyDMR);
146:                 keyAttributeDMR.setValueDMR(valueDMR);
147:                 return keyAttributeDMR;
148:         }
149:
150:         /**
151:          * @return
152:          */
153:         private VFeaturePathDomainModelReference createValueDMR() {
154:                 final VFeaturePathDomainModelReference valueDMR = VViewFactory.eINSTANCE
155:                         .createFeaturePathDomainModelReference();
156:                 valueDMR.getDomainModelEReferencePath().add(TestPackage.eINSTANCE.getC_A());
157:                 valueDMR.setDomainModelEFeature(TestPackage.eINSTANCE.getA_B());
158:                 return valueDMR;
159:         }
160:
161:         /**
162:          * @return
163:          */
164:         private VFeaturePathDomainModelReference createKeyDMR() {
165:                 final VFeaturePathDomainModelReference keyDMR = VViewFactory.eINSTANCE.createFeaturePathDomainModelReference();
166:                 keyDMR.getDomainModelEReferencePath().add(TestPackage.eINSTANCE.getC_D());
167:                 keyDMR.setDomainModelEFeature(TestPackage.eINSTANCE.getD_X());
168:                 return keyDMR;
169:         }
170: }