Skip to content

Package: ECPAbstractCustomControlSWT_PTest

ECPAbstractCustomControlSWT_PTest

nameinstructionbranchcomplexitylinemethod
ECPAbstractCustomControlSWT_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%
createControlMap(Control[])
M: 0 C: 26
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
createEditableFeatures()
M: 0 C: 17
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
createFeatures()
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%
createReferencedFeatures()
M: 0 C: 17
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
getFeature(Collection, EStructuralFeature, boolean)
M: 4 C: 27
87%
M: 2 C: 2
50%
M: 2 C: 1
33%
M: 1 C: 8
89%
M: 0 C: 1
100%
getLabelFromComposite(Composite)
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%
init()
M: 0 C: 65
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 18
100%
M: 0 C: 1
100%
testCreateContentControl()
M: 0 C: 20
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
testCreateControl()
M: 0 C: 39
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 9
100%
M: 0 C: 1
100%
testCreateValidationLabel()
M: 0 C: 18
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
testCustomControlGetHelp()
M: 0 C: 47
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 12
100%
M: 0 C: 1
100%
testCustomControlGetHelpWrongFeature()
M: 9 C: 7
44%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 3 C: 3
50%
M: 0 C: 1
100%
testCustomControlGetLabel()
M: 0 C: 47
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 12
100%
M: 0 C: 1
100%
testCustomControlGetLabelWrongFeature()
M: 9 C: 7
44%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 3 C: 3
50%
M: 0 C: 1
100%
testDispose()
M: 0 C: 17
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
testDisposeCustomControl()
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%
testGetAddImage()
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
testGetDefaultImage()
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
testGetDeleteImage()
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
testGetEditableFeatures()
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%
testGetHelpImage()
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
testGetHelper()
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
testGetValidationErrorImage()
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
testHandleContentValidation()
M: 0 C: 20
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
testHandleValidationErrorOnlyEObject()
M: 0 C: 25
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
testHandleValidationErrorTwoEObject()
M: 0 C: 30
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
testHandleValidationNotErrorWarning()
M: 17 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
testHandleValidationOfControl()
M: 0 C: 85
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 16
100%
M: 0 C: 1
100%
testHandleValidationWithLabel()
M: 0 C: 32
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
testHandleValidationWithLabelOriginalDiagniostic()
M: 0 C: 26
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
testHandleValidationWithoutLabel()
M: 0 C: 27
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
testInit()
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
testReadonlyCustomControl()
M: 0 C: 34
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 11
100%
M: 0 C: 1
100%
testResetValidation()
M: 0 C: 30
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
testSetEditable()
M: 0 C: 62
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 9
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2013 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: * Jonas - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.view.custom.ui.swt.test;
15:
16: import static org.junit.Assert.assertEquals;
17: import static org.junit.Assert.assertFalse;
18: import static org.junit.Assert.assertNotNull;
19: import static org.junit.Assert.assertNull;
20: import static org.junit.Assert.assertSame;
21: import static org.junit.Assert.assertTrue;
22: import static org.junit.Assert.fail;
23:
24: import java.util.Collection;
25: import java.util.Collections;
26: import java.util.Iterator;
27: import java.util.LinkedHashMap;
28: import java.util.LinkedHashSet;
29: import java.util.Map;
30: import java.util.NoSuchElementException;
31: import java.util.Set;
32:
33: import org.eclipse.core.databinding.property.value.IValueProperty;
34: import org.eclipse.emf.common.util.BasicDiagnostic;
35: import org.eclipse.emf.common.util.Diagnostic;
36: import org.eclipse.emf.ecore.EAttribute;
37: import org.eclipse.emf.ecore.EStructuralFeature;
38: import org.eclipse.emf.ecore.EStructuralFeature.Setting;
39: import org.eclipse.emf.ecore.EcorePackage;
40: import org.eclipse.emf.ecore.util.Diagnostician;
41: import org.eclipse.emf.ecp.view.spi.context.ViewModelContextFactory;
42: import org.eclipse.emf.ecp.view.spi.custom.model.VCustomControl;
43: import org.eclipse.emf.ecp.view.spi.custom.model.VCustomDomainModelReference;
44: import org.eclipse.emf.ecp.view.spi.custom.model.VCustomFactory;
45: import org.eclipse.emf.ecp.view.spi.custom.model.VCustomPackage;
46: import org.eclipse.emf.ecp.view.spi.custom.swt.ECPAbstractCustomControlSWT;
47: import org.eclipse.emf.ecp.view.spi.custom.swt.ECPAbstractCustomControlSWT.SWTCustomControlHelper;
48: import org.eclipse.emf.ecp.view.spi.model.VDomainModelReference;
49: import org.eclipse.emf.ecp.view.spi.model.VFeaturePathDomainModelReference;
50: import org.eclipse.emf.ecp.view.spi.model.VViewFactory;
51: import org.eclipse.emf.ecp.view.spi.renderer.NoPropertyDescriptorFoundExeption;
52: import org.eclipse.emf.ecp.view.spi.renderer.NoRendererFoundException;
53: import org.eclipse.emf.ecp.view.test.common.swt.spi.DatabindingClassRunner;
54: import org.eclipse.emf.ecp.view.test.common.swt.spi.SWTViewTestHelper;
55: import org.eclipse.emf.edit.provider.AdapterFactoryItemDelegator;
56: import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
57: import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
58: import org.eclipse.emfforms.spi.core.services.databinding.DatabindingFailedException;
59: import org.eclipse.emfforms.spi.swt.core.EMFFormsNoRendererException;
60: import org.eclipse.emfforms.spi.swt.core.layout.SWTGridCell;
61: import org.eclipse.swt.SWT;
62: import org.eclipse.swt.widgets.Composite;
63: import org.eclipse.swt.widgets.Control;
64: import org.eclipse.swt.widgets.Label;
65: import org.junit.Before;
66: import org.junit.Ignore;
67: import org.junit.Test;
68: import org.junit.runner.RunWith;
69:
70: /**
71: * @author Jonas
72: *
73: */
74: @RunWith(DatabindingClassRunner.class)
75: public class ECPAbstractCustomControlSWT_PTest {
76:
77:         static final String LABELTEXT = "Some Text";
78:         private Set<VDomainModelReference> allFeatures;
79:         private Set<VFeaturePathDomainModelReference> referencedFeatures;
80:         private Set<VFeaturePathDomainModelReference> editableFeaturess;
81:         private ECPAbstractCustomControlSWTStub customControl;
82:         private Composite testComposite;
83:         private VCustomDomainModelReference domainObject;
84:         private VCustomControl controlModel;
85:
86:         @Before
87:         public void init() {
88:                 referencedFeatures = null;
89:                 editableFeaturess = null;
90:                 customControl = new ECPAbstractCustomControlSWTStub();
91:                 domainObject = VCustomFactory.eINSTANCE.createCustomDomainModelReference();
92:                 controlModel = VCustomFactory.eINSTANCE.createCustomControl();
93:                 controlModel.setBundleName("org.eclipse.emf.ecp.view.custom.ui.swt.test");
94:                 controlModel.setClassName("org.eclipse.emf.ecp.view.custom.ui.swt.test.ECPAbstractCustomControlSWTStub");
95:                 final VCustomDomainModelReference domainModelReference = VCustomFactory.eINSTANCE
96:                         .createCustomDomainModelReference();
97:                 domainModelReference.setBundleName("org.eclipse.emf.ecp.view.custom.ui.swt.test");
98:                 domainModelReference
99:                         .setClassName("org.eclipse.emf.ecp.view.custom.ui.swt.test.ECPAbstractCustomControlSWTStub");
100:
101:                 // final VHardcodedDomainModelReference domainModelReference = VCustomFactory.eINSTANCE
102:                 // .createHardcodedDomainModelReference();
103:                 // domainModelReference.setControlId("org.eclipse.emf.ecp.view.custom.ui.swt.test.control.stub");
104:                 domainModelReference.getDomainModelReferences().addAll(createFeatures());
105:                 controlModel.setDomainModelReference(domainModelReference);
106:                 // customControl.init(ViewTestHelper.createECPControlContext(domainObject,
107:                 // SWTViewTestHelper.createShell()), null);
108:                 customControl.init(
109:                         controlModel, ViewModelContextFactory.INSTANCE.createViewModelContext(controlModel, domainObject));
110:                 testComposite = new Composite(SWTViewTestHelper.createShell(), SWT.NONE);
111:
112:                 // for (final VDomainModelReference modelReference : allFeatures) {
113:                 // modelReference.resolve(domainObject);
114:                 // }
115:         }
116:
117:         public Set<VDomainModelReference> createFeatures() {
118:
119:                 allFeatures = new LinkedHashSet<VDomainModelReference>();
120:                 allFeatures.addAll(createEditableFeatures());
121:                 allFeatures.addAll(createReferencedFeatures());
122:
123:                 return allFeatures;
124:         }
125:
126:         /**
127:          * @return a test set of {@link VFeaturePathDomainModelReference}
128:          */
129:         public Set<VFeaturePathDomainModelReference> createReferencedFeatures() {
130:•                if (referencedFeatures == null) {
131:                         // referencedFeatures = new LinkedHashSet<VFeaturePathDomainModelReference>();
132:                         // final EList<EStructuralFeature> eAllStructuralFeatures = VCustomPackage.eINSTANCE
133:                         // .getCustomDomainModelReference()
134:                         // .getEAllStructuralFeatures();
135:                         // for (final EStructuralFeature eStructuralFeature : eAllStructuralFeatures) {
136:                         // // new ECPCustomControlFeature(null, eStructuralFeature, false);
137:                         // final VFeaturePathDomainModelReference domainModelReference = VViewFactory.eINSTANCE
138:                         // .createFeaturePathDomainModelReference();
139:                         // domainModelReference.setDomainModelEFeature(eStructuralFeature);
140:                         // referencedFeatures.add(domainModelReference);
141:                         // }
142:                         final VFeaturePathDomainModelReference domainModelReference = VViewFactory.eINSTANCE
143:                                 .createFeaturePathDomainModelReference();
144:                         domainModelReference.setDomainModelEFeature(VCustomPackage.eINSTANCE
145:                                 .getCustomDomainModelReference_BundleName());
146:                         referencedFeatures = Collections.singleton(domainModelReference);
147:                 }
148:                 return referencedFeatures;
149:         }
150:
151:         /**
152:          * @return a test set of {@link VFeaturePathDomainModelReference}
153:          */
154:         public Set<VFeaturePathDomainModelReference> createEditableFeatures() {
155:•                if (editableFeaturess == null) {
156:                         // editableFeaturess = new LinkedHashSet<VFeaturePathDomainModelReference>();
157:                         // final EList<EStructuralFeature> eAllStructuralFeatures = VCustomPackage.eINSTANCE
158:                         // .getCustomDomainModelReference()
159:                         // .getEAllStructuralFeatures();
160:                         // for (final EStructuralFeature eStructuralFeature : eAllStructuralFeatures) {
161:                         // // new ECPCustomControlFeature(null, eStructuralFeature, true)
162:                         // final VFeaturePathDomainModelReference domainModelReference = VViewFactory.eINSTANCE
163:                         // .createFeaturePathDomainModelReference();
164:                         // domainModelReference.setDomainModelEFeature(eStructuralFeature);
165:                         // editableFeaturess.add(domainModelReference);
166:                         //
167:                         // }
168:
169:                         final VFeaturePathDomainModelReference domainModelReference = VViewFactory.eINSTANCE
170:                                 .createFeaturePathDomainModelReference();
171:                         domainModelReference.setDomainModelEFeature(VCustomPackage.eINSTANCE
172:                                 .getCustomDomainModelReference_BundleName());
173:                         editableFeaturess = Collections.singleton(domainModelReference);
174:
175:                 }
176:                 return editableFeaturess;
177:         }
178:
179:         /**
180:          * Test method for
181:          * {@link org.eclipse.emf.ecp.view.spi.custom.swt.ECPAbstractCustomControlSWT#renderControl(SWTGridCell,org.eclipse.swt.widgets.Composite)}
182:          * .
183:          *
184:          * @throws NoPropertyDescriptorFoundExeption
185:          * @throws NoRendererFoundException
186:          */
187:         @Test
188:         public void testCreateControl() throws NoRendererFoundException, NoPropertyDescriptorFoundExeption {
189:                 // final Composite composite = customControl
190:                 // .createControls(new Composite(SWTViewTestHelper.createShell(), SWT.NONE));
191:
192:                 final Composite composite = new Composite(SWTViewTestHelper.createShell(), SWT.NONE);
193:                 customControl.renderControl(new SWTGridCell(0, 0, null), composite);
194:
195:                 assertTrue(customControl.isRendered());
196:                 final Composite parentCompositeFromView = composite;
197:                 final Control control = getLabelFromComposite(parentCompositeFromView);
198:                 assertTrue("Control is not the one rendered by the custom control", control instanceof Label);
199:                 final Label label = (Label) control;
200:                 assertEquals(LABELTEXT, label.getText());
201:         }
202:
203:         private Control getLabelFromComposite(final Composite parentCompositeFromView) {
204:                 return parentCompositeFromView.getChildren()[0];
205:         }
206:
207:         @Test
208:         public void testCreateValidationLabel() {
209:                 customControl.createValidationLabelInStub(testComposite);
210:                 final Control control = testComposite.getChildren()[0];
211:                 assertTrue(control instanceof Label);
212:                 assertNull(control.getLayoutData());
213:
214:         }
215:
216:         /**
217:          * Test method for
218:          * {@link org.eclipse.emf.ecp.view.spi.custom.swt.ECPAbstractCustomControlSWT#renderControl(SWTGridCell, org.eclipse.swt.widgets.Composite)}
219:          * .
220:          *
221:          * @throws NoPropertyDescriptorFoundExeption
222:          * @throws NoRendererFoundException
223:          */
224:         @Test
225:         public void testCreateContentControl() throws NoRendererFoundException, NoPropertyDescriptorFoundExeption {
226:                 customControl.renderControl(new SWTGridCell(0, 0, null), testComposite);
227:                 assertTrue(testComposite.getChildren()[0] instanceof Label);
228:         }
229:
230:         /**
231:          * Test method for {@link org.eclipse.emf.ecp.view.spi.custom.swt.ECPAbstractCustomControlSWT#applyValidation()} .
232:          */
233:         @Test
234:         public void testHandleValidationWithoutLabel() {
235:                 new Diagnostician().validate(domainObject);
236:                 customControl.applyValidation();
237:                 // Check Label, Check Image
238:                 assertEquals(Diagnostic.ERROR, customControl.getLastValidationSeverity());
239:                 assertSame(VCustomPackage.eINSTANCE.getCustomDomainModelReference_BundleName(),
240:                         customControl.getLastValidationFeature());
241:                 customControl.setValidationReseted(false);
242:                 // customControl.resetValidation();
243:                 // assertTrue(customControl.isValidationReseted());
244:         }
245:
246:         /**
247:          * Test method for {@link org.eclipse.emf.ecp.view.spi.custom.swt.ECPAbstractCustomControlSWT#applyValidation()} .
248:          */
249:         @Test
250:         public void testHandleValidationWithLabel() {
251:                 customControl.createValidationLabelInStub(testComposite);
252:                 new Diagnostician().validate(domainObject);
253:                 customControl.applyValidation();
254:                 // Check Label, Check Image
255:                 assertEquals(Diagnostic.ERROR, customControl.getLastValidationSeverity());
256:
257:                 assertSame(VCustomPackage.eINSTANCE.getCustomDomainModelReference_BundleName(),
258:                         customControl.getLastValidationFeature());
259:
260:                 customControl.setValidationReseted(false);
261:                 // customControl.resetValidation();
262:                 // assertTrue(customControl.isValidationReseted());
263:         }
264:
265:         @Test
266:         public void testHandleValidationWithLabelOriginalDiagniostic() {
267:                 customControl.createValidationLabelInStub(testComposite);
268:                 new Diagnostician().validate(domainObject);
269:                 customControl.applyValidation();
270:                 // Check Label, Check Image
271:                 assertEquals(Diagnostic.ERROR, customControl.getLastValidationSeverity());
272:                 // FIXME should a fitting sub diagnostic have been used?
273:                 // assertSame(CustomPackage.eINSTANCE.getCustomControl_Bundle(), customControl.getLastValidationFeature());
274:                 customControl.setValidationReseted(false);
275:                 // customControl.resetValidation();
276:                 // assertTrue(customControl.isValidationReseted());
277:         }
278:
279:         @Ignore
280:         // Is this a correct behavior?
281:         @Test
282:         public void testHandleValidationNotErrorWarning() {
283:                 // FIXME accept diagnostics without eObject?
284:                 final Diagnostic validate = new BasicDiagnostic(Diagnostic.OK, null, 0, "All right!", null);
285:                 customControl.applyValidation();
286:                 // FIXME correct assumption?
287:                 assertTrue(customControl.isValidationReseted());
288:         }
289:
290:         // @Test
291:         // public void testHandleValidationWarningNoData() {
292:         // // FIXME accept diagnostics without eObject?
293:         // final Diagnostic validate = new BasicDiagnostic(Diagnostic.WARNING, null, 0, "Warning!", null);
294:         // customControl.applyValidation();
295:         // assertEquals(Diagnostic.WARNING, customControl.getLastValidationSeverity());
296:         // }
297:
298:         @Test
299:         public void testHandleValidationErrorOnlyEObject() {
300:                 final Diagnostic validate = new BasicDiagnostic(Diagnostic.ERROR, null, 0, "Error!",
301:                         new Object[] { domainObject });
302:                 customControl.applyValidation();
303:                 assertEquals(Diagnostic.ERROR, customControl.getLastValidationSeverity());
304:         }
305:
306:         @Test
307:         public void testHandleValidationErrorTwoEObject() {
308:                 final Diagnostic validate = new BasicDiagnostic(Diagnostic.ERROR, null, 0, "Error!",
309:                         new Object[] { domainObject, domainObject });
310:                 customControl.applyValidation();
311:                 assertEquals(Diagnostic.ERROR, customControl.getLastValidationSeverity());
312:         }
313:
314:         /**
315:          * Test method for
316:          * {@link org.eclipse.emf.ecp.view.spi.custom.swt.ECPAbstractCustomControlSWT#applyValidation()}
317:          * .
318:          *
319:          * @throws NoPropertyDescriptorFoundExeption
320:          * @throws NoRendererFoundException
321:          */
322:         @Test
323:         public void testHandleValidationOfControl() throws NoRendererFoundException, NoPropertyDescriptorFoundExeption {
324:                 customControl = new ECPAbstractCustomControlSWTStub(true);
325:
326:                 Diagnostic validate = new Diagnostician().validate(domainObject);
327:                 // customControl.init(ViewTestHelper.createECPControlContext(domainObject,
328:                 // SWTViewTestHelper.createShell()), null);
329:                 customControl.init(
330:                         controlModel, ViewModelContextFactory.INSTANCE.createViewModelContext(controlModel, domainObject));
331:                 customControl.renderControl(new SWTGridCell(0, 0, null), testComposite);
332:                 customControl.applyValidation();
333:                 // Check Label, Check Image
334:                 assertEquals(Diagnostic.ERROR, customControl.getLastValidationSeverity());
335:
336:                 assertSame(VCustomPackage.eINSTANCE.getCustomDomainModelReference_BundleName(),
337:                         customControl.getLastValidationFeature());
338:
339:                 customControl.renderControl(new SWTGridCell(0, 0, null), testComposite);
340:                 customControl.applyValidation();
341:
342:                 // assertNotNull(customControl.getValidationLabel().getImage());
343:                 domainObject.setBundleName("not empty");
344:                 customControl.setValidationReseted(false);
345:                 // customControl.resetValidation();
346:                 // assertTrue(customControl.isValidationReseted());
347:                 validate = new Diagnostician().validate(domainObject);
348:                 customControl.applyValidation();
349:                 // assertNull(customControl.getValidationLabel().getImage());
350:         }
351:
352:         /**
353:          * Test method for
354:          * {@link org.eclipse.emf.ecp.view.spi.custom.swt.ECPAbstractCustomControlSWT#handleContentValidation(int, org.eclipse.emf.ecore.EStructuralFeature)}
355:          * .
356:          */
357:         @Test
358:         public void testHandleContentValidation() {
359:
360:                 final EAttribute validationFeature = VCustomPackage.eINSTANCE.getCustomDomainModelReference_BundleName();
361:
362:                 final int severity = 4;
363:                 customControl.handleContentValidation();
364:                 assertEquals(severity, customControl.getLastValidationSeverity());
365:                 assertSame(validationFeature, customControl.getLastValidationFeature());
366:         }
367:
368:         /**
369:          * Test method for {@link org.eclipse.emf.ecp.view.spi.custom.swt.ECPAbstractCustomControlSWT#resetValidation()}.
370:          */
371:         @Test
372:         public void testResetValidation() {
373:                 final Composite composite = new Composite(SWTViewTestHelper.createShell(), SWT.NONE);
374:                 customControl.createValidationLabelInStub(composite);
375:                 final Label validationLabel = (Label) composite.getChildren()[0];
376:                 validationLabel.setImage(customControl.getStubSWTHelper().getImage(
377:                         ECPAbstractCustomControlSWT.VALIDATION_ERROR_IMAGE));
378:
379:                 assertEquals(false, validationLabel.isVisible());
380:         }
381:
382:         @Test
383:         public void testInit() {
384:                 customControl.init(controlModel,
385:                         ViewModelContextFactory.INSTANCE.createViewModelContext(controlModel, domainObject));
386:         }
387:
388:         /**
389:          * Test method for
390:          * {@link org.eclipse.emf.ecp.view.spi.custom.ui.ECPAbstractCustomControl#getECPCustomControlFeatures()} .
391:          */
392:         @Test
393:         public void testGetEditableFeatures() {
394:                 final Set<VDomainModelReference> editableFeatures = customControl.getNeededDomainModelReferences();
395:                 editableFeatures.removeAll(createFeatures());
396:                 assertTrue(editableFeatures.isEmpty());
397:         }
398:
399:         // /**
400:         // * Test method for {@link org.eclipse.emf.ecp.view.spi.custom.ui.ECPAbstractCustomControl#showLabel()}.
401:         // */
402:         // @Test
403:         // public void testShowLabel() {
404:         // assertFalse(customControl.showLabel());
405:         // }
406:
407:         /**
408:          * Test method for {@link org.eclipse.emf.ecp.view.spi.custom.ui.ECPAbstractCustomControl#dispose()}.
409:          */
410:         @Test
411:         public void testDispose() {
412:                 customControl.createValidationLabelInStub(testComposite);
413:                 assertFalse(customControl.isDisposed());
414:                 customControl.dispose();
415:                 assertTrue(customControl.isDisposed());
416:         }
417:
418:         // @Test
419:         // public void testDisposeOnShellDispose() throws NoRendererFoundException, NoPropertyDescriptorFoundExeption {
420:         // final Composite composite = new Composite(SWTViewTestHelper.createShell(), SWT.NONE);
421:         // customControl.renderControl(new SWTGridCell(0, 0, new GridCellDescription()), composite);
422:         // assertFalse(customControl.isDisposed());
423:         // composite.dispose();
424:         // assertTrue(customControl.isDisposed());
425:         // }
426:
427:         /**
428:          * Test method for {@link org.eclipse.emf.ecp.view.spi.custom.ui.ECPAbstractCustomControl#disposeCustomControl()}.
429:          */
430:         @Test
431:         public void testDisposeCustomControl() {
432:                 customControl.disposeCustomControl();
433:         }
434:
435:         /**
436:          * Test method for {@link org.eclipse.emf.ecp.view.spi.custom.ui.ECPAbstractCustomControl#getHelper()}.
437:          */
438:         @Test
439:         public void testGetHelper() {
440:                 final SWTCustomControlHelper stubHelper = customControl.getStubSWTHelper();
441:                 assertNotNull(stubHelper);
442:         }
443:
444:         @Test
445:         public void testGetAddImage() {
446:                 final SWTCustomControlHelper stubHelper = customControl.getStubSWTHelper();
447:                 assertNotNull("Add image not loaded.", stubHelper.getImage(ECPAbstractCustomControlSWT.ADD_IMAGE));
448:         }
449:
450:         @Test
451:         public void testGetDeleteImage() {
452:                 final SWTCustomControlHelper stubHelper = customControl.getStubSWTHelper();
453:                 assertNotNull("Delete image not loaded.", stubHelper.getImage(ECPAbstractCustomControlSWT.DELETE_IMAGE));
454:         }
455:
456:         @Test
457:         public void testGetHelpImage() {
458:                 final SWTCustomControlHelper stubHelper = customControl.getStubSWTHelper();
459:                 assertNotNull("Help image not loaded.", stubHelper.getImage(ECPAbstractCustomControlSWT.HELP_IMAGE));
460:
461:         }
462:
463:         @Test
464:         public void testGetValidationErrorImage() {
465:                 final SWTCustomControlHelper stubHelper = customControl.getStubSWTHelper();
466:                 assertNotNull("ValidationError image not loaded.",
467:                         stubHelper.getImage(ECPAbstractCustomControlSWT.VALIDATION_ERROR_IMAGE));
468:         }
469:
470:         @Test
471:         public void testGetDefaultImage() {
472:                 final SWTCustomControlHelper stubHelper = customControl.getStubSWTHelper();
473:                 assertNull("Found undefined image.",
474:                         stubHelper.getImage(-1));
475:         }
476:
477:         private VDomainModelReference getFeature(Collection<VDomainModelReference> features,
478:                 EStructuralFeature structuralFeature, boolean isEditable) throws DatabindingFailedException {
479:                 final Iterator<VDomainModelReference> iterator = features.iterator();
480:
481:•                while (iterator.hasNext()) {
482:                         final VDomainModelReference feature = iterator.next();
483:                         final IValueProperty valueProperty = Activator.getDefault().getEMFFormsDatabinding()
484:                                 .getValueProperty(feature, domainObject);
485:                         final EStructuralFeature currentStructuralFeature = (EStructuralFeature) valueProperty.getValueType();
486:•                        if (currentStructuralFeature == structuralFeature) { // && feature.isEditable() == isEditable
487:                                 return feature;
488:                         }
489:                 }
490:
491:                 throw new NoSuchElementException();
492:         }
493:
494:         @Test
495:         public void testCustomControlGetHelp() throws DatabindingFailedException {
496:                 final VDomainModelReference feature = getFeature(customControl.getResolvedReferences(),
497:                         VCustomPackage.eINSTANCE.getCustomDomainModelReference_BundleName(), true);
498:                 final String help = customControl.getStubSWTHelper().getHelp(feature);
499:                 final ComposedAdapterFactory caf = new ComposedAdapterFactory(
500:                         ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
501:                 final AdapterFactoryItemDelegator afid = new AdapterFactoryItemDelegator(caf);
502:                 final Setting setting = Activator.getDefault().getEMFFormsDatabinding().getSetting(feature, domainObject);
503:                 final IItemPropertyDescriptor propertyDescriptor = afid.getPropertyDescriptor(setting.getEObject(),
504:                         setting.getEStructuralFeature());
505:                 final String description = propertyDescriptor.getDescription(null);
506:                 assertEquals(description, help);
507:         }
508:
509:         @Test(expected = IllegalArgumentException.class)
510:         public void testCustomControlGetHelpWrongFeature() {
511:                 final VFeaturePathDomainModelReference domainModelReference = VViewFactory.eINSTANCE
512:                         .createFeaturePathDomainModelReference();
513:                 domainModelReference.setDomainModelEFeature(EcorePackage.eINSTANCE.getENamedElement_Name());
514:                 // final ECPCustomControlFeature feature = new ECPCustomControlFeature(null,
515:                 // EcorePackage.eINSTANCE.getENamedElement_Name(), false);
516:                 customControl.getStubSWTHelper().getHelp(domainModelReference);
517:                 fail("No Exception thrown");
518:         }
519:
520:         @Test
521:         public void testCustomControlGetLabel() throws DatabindingFailedException {
522:                 final VDomainModelReference feature = getFeature(customControl.getResolvedReferences(),
523:                         VCustomPackage.eINSTANCE.getCustomDomainModelReference_BundleName(), true);
524:                 final String label = customControl.getStubSWTHelper().getLabel(feature);
525:                 final ComposedAdapterFactory caf = new ComposedAdapterFactory(
526:                         ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
527:                 final AdapterFactoryItemDelegator afid = new AdapterFactoryItemDelegator(caf);
528:                 final Setting setting = Activator.getDefault().getEMFFormsDatabinding().getSetting(feature, domainObject);
529:                 final IItemPropertyDescriptor propertyDescriptor = afid.getPropertyDescriptor(setting.getEObject(),
530:                         setting.getEStructuralFeature());
531:                 final String displayName = propertyDescriptor.getDisplayName(null);
532:                 assertEquals(displayName, label);
533:         }
534:
535:         @Test(expected = IllegalArgumentException.class)
536:         public void testCustomControlGetLabelWrongFeature() {
537:                 // final ECPCustomControlFeature feature = new ECPCustomControlFeature(null,
538:                 // EcorePackage.eINSTANCE.getENamedElement_Name(), false);
539:                 final VFeaturePathDomainModelReference domainModelReference = VViewFactory.eINSTANCE
540:                         .createFeaturePathDomainModelReference();
541:                 domainModelReference.setDomainModelEFeature(EcorePackage.eINSTANCE.getENamedElement_Name());
542:                 customControl.getStubSWTHelper().getLabel(domainModelReference);
543:                 fail("No Exception thrown");
544:         }
545:
546:         // /**
547:         // * Test set value on {@link ECPCustomControlFeature}.
548:         // */
549:         // @Test
550:         // public void testCustomControlFeatureSet() {
551:         // final VDomainModelReference bundleFeature = getFeature(customControl.getResolvedReferences(),
552:         // VCustomPackage.eINSTANCE.getCustomControl_BundleName(), true);
553:         // customControl.setValue(bundleFeature, "test");
554:         // assertEquals(domainObject.eGet(VCustomPackage.eINSTANCE.getCustomControl_BundleName()), "test");
555:         //
556:         // }
557:         //
558:         // /**
559:         // * Test set value on {@link ECPCustomControlFeature} that is not editable.
560:         // */
561:         // @Test(expected = UnsupportedOperationException.class)
562:         // // function not supported anymore
563:         // @Ignore
564:         // public void testCustomControlFeatureSetNotEditable() {
565:         //
566:         // final VDomainModelReference bundleFeature = getFeature(customControl.getNeededDomainModelReferences(),
567:         // VViewPackage.eINSTANCE.getControl_LabelAlignment(), false);
568:         // customControl.setValue(bundleFeature, "test");
569:         //
570:         // }
571:         //
572:         // /**
573:         // * Test get value on {@link ECPCustomControlFeature}.
574:         // */
575:         // @Test
576:         // public void testCustomControlFeatureGet() {
577:         //
578:         // final VDomainModelReference bundleFeature = getFeature(customControl.getResolvedReferences(),
579:         // VCustomPackage.eINSTANCE.getCustomControl_BundleName(), true);
580:         // assertEquals(domainObject.eGet(VCustomPackage.eINSTANCE.getCustomControl_BundleName()),
581:         // customControl.getValue(bundleFeature));
582:         //
583:         // }
584:         //
585:         // /**
586:         // * Test set listener on {@link ECPCustomControlFeature}.
587:         // */
588:         // @Test
589:         // public void testCustomControlFeatureListener() {
590:         //
591:         // final VDomainModelReference bundleFeature = getFeature(customControl.getResolvedReferences(),
592:         // VCustomPackage.eINSTANCE.getCustomControl_BundleName(), true);
593:         //
594:         // final List<Integer> result = new ArrayList<Integer>();
595:         // customControl.registerChangeListener(bundleFeature, new ECPCustomControlChangeListener() {
596:         // public void notifyChanged() {
597:         // result.add(1);
598:         // }
599:         // });
600:         //
601:         // customControl.setValue(bundleFeature, "test");
602:         // assertEquals("Listener should have been called once", 1, result.size());
603:         // }
604:         //
605:         // @Test
606:         // public void testBindTargetToModel() {
607:         //
608:         // final VDomainModelReference bundleFeature = getFeature(customControl.getResolvedReferences(),
609:         // VCustomPackage.eINSTANCE.getCustomControl_BundleName(), true);
610:         //
611:         // customControl.createControls(testComposite);
612:         // final Label label = (Label) testComposite.getChildren()[0];
613:         // final IObservableValue obsValue = SWTObservables.observeText(label);
614:         // customControl.bindTargetToModel(bundleFeature, obsValue, null, null);
615:         // // bundleFeature.bindTargetToModel(obsValue, null, null);
616:         // // bundleFeature.setValue("testtesttest");
617:         // customControl.setValue(bundleFeature, "testtesttest");
618:         // assertEquals("testtesttest", label.getText());
619:         // }
620:
621:         @Test
622:         public void testReadonlyCustomControl() throws NoRendererFoundException, NoPropertyDescriptorFoundExeption,
623:                 EMFFormsNoRendererException {
624:
625:                 controlModel.setReadonly(true);
626:                 controlModel.setBundleName("org.eclipse.emf.ecp.view.custom.ui.swt.test");
627:                 controlModel.setClassName("org.eclipse.emf.ecp.view.custom.ui.swt.test.CustomControlStub");
628:                 // domainObject.setBundle("org.eclipse.emf.ecp.view.custom.ui.swt.test");
629:                 // domainObject
630:                 // .setClassName("org.eclipse.emf.ecp.view.custom.ui.swt.test.CustomControlStub");
631:                 final VCustomDomainModelReference domainModelReference = VCustomFactory.eINSTANCE
632:                         .createCustomDomainModelReference();
633:                 domainModelReference.setBundleName("org.eclipse.emf.ecp.view.custom.ui.swt.test");
634:                 domainModelReference.setClassName("org.eclipse.emf.ecp.view.custom.ui.swt.test.CustomControlStub");
635:                 // domainModelReference.setControlId("org.eclipse.emf.ecp.view.custom.ui.swt.test.CustomControlStub");
636:                 controlModel.setDomainModelReference(domainModelReference);
637:                 final Control control = SWTViewTestHelper.render(controlModel, SWTViewTestHelper.createShell());
638:                 assertFalse(control.getEnabled());
639:         }
640:
641:         private Map<SWTGridCell, Control> createControlMap(Control... controls) {
642:                 final Map<SWTGridCell, Control> result = new LinkedHashMap<SWTGridCell, Control>();
643:•                for (int i = 0; i < controls.length; i++) {
644:                         result.put(new SWTGridCell(0, i, null), controls[i]);
645:                 }
646:                 return result;
647:         }
648:
649:         @Test
650:         public void testSetEditable() throws NoRendererFoundException, NoPropertyDescriptorFoundExeption {
651:                 customControl.renderControl(new SWTGridCell(0, 1, null), testComposite);
652:                 assertTrue(customControl.getButton().isEnabled());
653:                 controlModel.setEnabled(false);
654:                 customControl.applyEnable(createControlMap(customControl.getButton()));
655:                 assertFalse(customControl.getButton().isEnabled());
656:                 controlModel.setEnabled(true);
657:                 customControl.applyEnable(createControlMap(customControl.getButton()));
658:                 assertTrue(customControl.getButton().isEnabled());
659:         }
660: }