Skip to content

Package: DelegatingDmrSegmentConverter_PTest

DelegatingDmrSegmentConverter_PTest

nameinstructionbranchcomplexitylinemethod
DelegatingDmrSegmentConverter_PTest()
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%
convertToListProperty()
M: 0 C: 52
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
convertToValueProperty()
M: 0 C: 52
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 11
100%
M: 0 C: 1
100%
createFixture()
M: 0 C: 132
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 22
100%
M: 0 C: 1
100%
createFixture(VFeatureDomainModelReferenceSegment, EStructuralFeature, EObject)
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
createRealm()
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%
destroyRealm()
M: 0 C: 10
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
getSetting()
M: 0 C: 23
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
isApplicable()
M: 0 C: 30
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
lambda$0(EObject, EObject)
M: 0 C: 2
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2019 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.swt.internal.reference.table;
15:
16: import static org.eclipse.emfforms.spi.core.services.databinding.DomainModelReferenceConverter.NOT_APPLICABLE;
17: import static org.hamcrest.CoreMatchers.hasItem;
18: import static org.hamcrest.CoreMatchers.is;
19: import static org.hamcrest.CoreMatchers.not;
20: import static org.junit.Assert.assertThat;
21:
22: import java.util.Arrays;
23:
24: import org.eclipse.core.databinding.observable.IObservable;
25: import org.eclipse.core.databinding.observable.list.IObservableList;
26: import org.eclipse.core.databinding.observable.value.IObservableValue;
27: import org.eclipse.core.databinding.property.value.IValueProperty;
28: import org.eclipse.emf.ecore.EAttribute;
29: import org.eclipse.emf.ecore.EClass;
30: import org.eclipse.emf.ecore.ENamedElement;
31: import org.eclipse.emf.ecore.EObject;
32: import org.eclipse.emf.ecore.EPackage;
33: import org.eclipse.emf.ecore.EStructuralFeature;
34: import org.eclipse.emf.ecore.ETypedElement;
35: import org.eclipse.emf.ecore.EcoreFactory;
36: import org.eclipse.emf.ecore.EcorePackage;
37: import org.eclipse.emf.ecore.util.EcoreUtil;
38: import org.eclipse.emf.ecp.test.common.DefaultRealm;
39: import org.eclipse.emf.ecp.view.spi.model.VFeatureDomainModelReferenceSegment;
40: import org.eclipse.emf.ecp.view.spi.model.VViewFactory;
41: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedException;
42: import org.eclipse.emfforms.spi.core.services.databinding.emf.SegmentConverterListResultEMF;
43: import org.eclipse.emfforms.spi.core.services.databinding.emf.SegmentConverterValueResultEMF;
44: import org.junit.After;
45: import org.junit.Before;
46: import org.junit.Test;
47:
48: /**
49: * Test cases for {@link DelegatingDmrSegmentConverter}.
50: *
51: * @author Lucas Koehler
52: *
53: */
54: public class DelegatingDmrSegmentConverter_PTest {
55:
56:         private DefaultRealm realm;
57:
58:         private EPackage textPackage;
59:         private EClass text;
60:         private EAttribute words;
61:
62:         private EObject doc1;
63:         private EObject doc2;
64:
65:         private DelegatingDmrSegmentConverter fixture;
66:
67:         private IObservable observable;
68:
69:         private VFeatureDomainModelReferenceSegment ecoreNameSegment;
70:         private VFeatureDomainModelReferenceSegment wordsSegment;
71:
72:         @Test
73:         public void isApplicable() {
74:                 assertThat("Should be applicable", fixture.isApplicable(wordsSegment), not(NOT_APPLICABLE));
75:
76:                 final VFeatureDomainModelReferenceSegment other = VViewFactory.eINSTANCE
77:                         .createFeatureDomainModelReferenceSegment();
78:                 other.setDomainModelFeature(words.getName());
79:                 assertThat("Should not be applicable", fixture.isApplicable(other), is(NOT_APPLICABLE));
80:         }
81:
82:         @SuppressWarnings("unchecked")
83:         @Test
84:         public void convertToListProperty() throws DatabindingFailedException {
85:                 final SegmentConverterListResultEMF result = fixture.convertToListProperty(wordsSegment, text, null);
86:
87:                 final IObservableList<String> list = result.getListProperty().observe(doc2);
88:                 observable = list;
89:                 assertThat(list.getElementType(), is(words));
90:                 assertThat(list, hasItem("world"));
91:
92:                 list.set(0, "Goodbye");
93:
94:                 assertThat(doc1.eGet(words), is(Arrays.asList("Goodbye", "world")));
95:         }
96:
97:         @Test
98:         public void convertToValueProperty() throws DatabindingFailedException {
99:                 createFixture(ecoreNameSegment, EcorePackage.Literals.ENAMED_ELEMENT__NAME, text);
100:
101:                 // The editing domain is not used
102:                 final SegmentConverterValueResultEMF result = fixture.convertToValueProperty(wordsSegment, text, null);
103:                 @SuppressWarnings("unchecked")
104:                 final IValueProperty<ENamedElement, String> property = result.getValueProperty();
105:                 // If this doesn't work, Ecore package is frozen, so it will throw on attempt to change the
106:                 // name of the EObject EClass
107:                 final IObservableValue<String> value = property.observe(EcorePackage.Literals.EOBJECT);
108:                 observable = value;
109:
110:                 assertThat(value.getValueType(), is(EcorePackage.Literals.ENAMED_ELEMENT__NAME));
111:                 assertThat(value.getValue(), is("Text"));
112:
113:                 value.setValue("Document");
114:
115:                 assertThat(text.getName(), is("Document"));
116:
117:                 assertThat(EcorePackage.Literals.EOBJECT.getName(), not("Document"));
118:         }
119:
120:         @Test
121:         public void getSetting() throws DatabindingFailedException {
122:                 final EStructuralFeature.Setting setting = fixture.getSetting(wordsSegment, doc2);
123:                 assertThat("Wrong feature", setting.getEStructuralFeature(), is(words));
124:                 assertThat("Wrong owner", setting.getEObject(), is(doc1));
125:         }
126:
127:         //
128:         // Test framework
129:         //
130:
131:         @Before
132:         public void createRealm() {
133:                 realm = new DefaultRealm();
134:         }
135:
136:         @Before
137:         public void createFixture() {
138:                 textPackage = EcoreFactory.eINSTANCE.createEPackage();
139:                 textPackage.setName("text");
140:                 textPackage.setNsURI("http://text");
141:                 text = EcoreFactory.eINSTANCE.createEClass();
142:                 text.setName("Text");
143:                 textPackage.getEClassifiers().add(text);
144:                 words = EcoreFactory.eINSTANCE.createEAttribute();
145:                 words.setName("words");
146:                 words.setEType(EcorePackage.Literals.ESTRING);
147:                 words.setLowerBound(1);
148:                 words.setUpperBound(ETypedElement.UNBOUNDED_MULTIPLICITY);
149:                 text.getEStructuralFeatures().add(words);
150:
151:                 doc1 = EcoreUtil.create(text);
152:                 doc1.eSet(words, Arrays.asList("Hello", "world"));
153:                 doc2 = EcoreUtil.create(text);
154:                 doc2.eSet(words, Arrays.asList("This", "is", "a", "test"));
155:
156:                 wordsSegment = VViewFactory.eINSTANCE.createFeatureDomainModelReferenceSegment();
157:                 wordsSegment.setDomainModelFeature(words.getName());
158:
159:                 createFixture(wordsSegment, words, doc1);
160:
161:                 ecoreNameSegment = VViewFactory.eINSTANCE.createFeatureDomainModelReferenceSegment();
162:                 ecoreNameSegment.setDomainModelFeature(EcorePackage.Literals.ENAMED_ELEMENT__NAME.getName());
163:         }
164:
165:         @After
166:         public void destroyRealm() {
167:•                if (observable != null) {
168:                         observable.dispose();
169:                 }
170:                 realm.dispose();
171:         }
172:
173:         void createFixture(VFeatureDomainModelReferenceSegment segment, EStructuralFeature feature, EObject delegate) {
174:                 fixture = new DelegatingDmrSegmentConverter(segment, feature, __ -> delegate);
175:         }
176:
177: }