Skip to content

Package: DatabindingIntegration_ITest

DatabindingIntegration_ITest

nameinstructionbranchcomplexitylinemethod
DatabindingIntegration_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: 13
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
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: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
testIntegrationList()
M: 0 C: 56
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 16
100%
M: 0 C: 1
100%
testIntegrationValue()
M: 0 C: 56
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 16
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.core.services.databinding.integrationtest;
15:
16: import static org.junit.Assert.assertEquals;
17: import static org.junit.Assert.assertTrue;
18:
19: import java.util.LinkedList;
20:
21: import org.eclipse.core.databinding.property.list.IListProperty;
22: import org.eclipse.core.databinding.property.value.IValueProperty;
23: import org.eclipse.emf.databinding.IEMFListProperty;
24: import org.eclipse.emf.databinding.IEMFValueProperty;
25: import org.eclipse.emf.ecore.EReference;
26: import org.eclipse.emf.ecore.EStructuralFeature;
27: import org.eclipse.emf.ecp.view.spi.model.VFeaturePathDomainModelReference;
28: import org.eclipse.emf.ecp.view.spi.model.VViewFactory;
29: import org.eclipse.emfforms.core.services.databinding.testmodel.test.model.TestPackage;
30: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedException;
31: import org.eclipse.emfforms.spi.core.services.databinding.EMFFormsDatabinding;
32: import org.junit.After;
33: import org.junit.Before;
34: import org.junit.BeforeClass;
35: import org.junit.Test;
36: import org.osgi.framework.BundleContext;
37: import org.osgi.framework.FrameworkUtil;
38: import org.osgi.framework.ServiceReference;
39:
40: /**
41: * JUnit test to test the integration of the databinding services.
42: *
43: * @author Lucas Koehler
44: *
45: */
46: public class DatabindingIntegration_ITest {
47:
48:         private static BundleContext bundleContext;
49:         private EMFFormsDatabinding databindingService;
50:         private ServiceReference<EMFFormsDatabinding> serviceReference;
51:
52:         @BeforeClass
53:         public static void setUpBeforeClass() {
54:                 bundleContext = FrameworkUtil.getBundle(DatabindingIntegration_ITest.class).getBundleContext();
55:         }
56:
57:         @Before
58:         public void setUp() {
59:                 serviceReference = bundleContext
60:                         .getServiceReference(EMFFormsDatabinding.class);
61:                 databindingService = bundleContext.getService(serviceReference);
62:         }
63:
64:         @After
65:         public void tearDown() {
66:                 bundleContext.ungetService(serviceReference);
67:         }
68:
69:         @Test
70:         public void testIntegrationValue() throws DatabindingFailedException {
71:                 final VFeaturePathDomainModelReference pathReference = VViewFactory.eINSTANCE
72:                         .createFeaturePathDomainModelReference();
73:                 // create reference path to the attribute
74:                 final LinkedList<EReference> referencePath = new LinkedList<EReference>();
75:                 referencePath.add(TestPackage.eINSTANCE.getA_B());
76:                 referencePath.add(TestPackage.eINSTANCE.getB_C());
77:                 referencePath.add(TestPackage.eINSTANCE.getC_D());
78:
79:                 final EStructuralFeature feature = TestPackage.eINSTANCE.getD_X();
80:
81:                 pathReference.getDomainModelEReferencePath().addAll(referencePath);
82:                 pathReference.setDomainModelEFeature(feature);
83:
84:                 final IValueProperty valueProperty = databindingService.getValueProperty(pathReference, null);
85:
86:                 // The converter should return an IEMFValueProperty
87:                 assertTrue(valueProperty instanceof IEMFValueProperty);
88:
89:                 final IEMFValueProperty emfProperty = (IEMFValueProperty) valueProperty;
90:
91:                 // Check EStructuralFeature of the property.
92:                 assertEquals(feature, emfProperty.getStructuralFeature());
93:
94:                 // Check correct path.
95:                 final String expected = "A.b<B> => B.c<C> => C.d<D> => D.x<EString>"; //$NON-NLS-1$
96:                 assertEquals(expected, emfProperty.toString());
97:
98:         }
99:
100:         @Test
101:         public void testIntegrationList() throws DatabindingFailedException {
102:                 // TODO
103:                 final VFeaturePathDomainModelReference pathReference = VViewFactory.eINSTANCE
104:                         .createFeaturePathDomainModelReference();
105:                 // create reference path to the attribute
106:                 final LinkedList<EReference> referencePath = new LinkedList<EReference>();
107:                 referencePath.add(TestPackage.eINSTANCE.getA_B());
108:                 referencePath.add(TestPackage.eINSTANCE.getB_C());
109:                 referencePath.add(TestPackage.eINSTANCE.getC_D());
110:
111:                 final EStructuralFeature feature = TestPackage.eINSTANCE.getD_YList();
112:
113:                 pathReference.getDomainModelEReferencePath().addAll(referencePath);
114:                 pathReference.setDomainModelEFeature(feature);
115:
116:                 final IListProperty listProperty = databindingService.getListProperty(pathReference, null);
117:
118:                 // The converter should return an IEMFListProperty
119:                 assertTrue(listProperty instanceof IEMFListProperty);
120:
121:                 final IEMFListProperty emfListProperty = (IEMFListProperty) listProperty;
122:
123:                 // Check EStructuralFeature of the property.
124:                 assertEquals(feature, emfListProperty.getStructuralFeature());
125:
126:                 // Check correct path.
127:                 final String expected = "A.b<B> => B.c<C> => C.d<D> => D.yList[]<EInt>"; //$NON-NLS-1$
128:                 assertEquals(expected, emfListProperty.toString());
129:
130:         }
131: }