Skip to content

Package: AbstractMultiDmrStrategyProviderTest

AbstractMultiDmrStrategyProviderTest

nameinstructionbranchcomplexitylinemethod
AbstractMultiDmrStrategyProviderTest()
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%
getStrategyProvider()
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%
getTableControl()
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%
getTestEClass()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
handles_generationDisabled()
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%
handles_generationEnabled_incorrectBoth()
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
handles_generationEnabled_incorrectParent()
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
handles_generationEnabled_incorrectReference()
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%
handles_generationEnabled_true()
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%
lambda$1()
M: 14 C: 11
44%
M: 5 C: 1
17%
M: 3 C: 1
25%
M: 2 C: 3
60%
M: 0 C: 1
100%
setStrategyProvider(ReferenceServiceCustomizationVendor)
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%
setTableControl(VTableControl)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
setTestEClass(EClass)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
setUp()
M: 0 C: 98
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 23
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%

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.internal.view.multisegment.tooling;
15:
16: import static org.junit.Assert.assertFalse;
17: import static org.junit.Assert.assertTrue;
18:
19: import org.eclipse.emf.common.command.BasicCommandStack;
20: import org.eclipse.emf.common.notify.AdapterFactory;
21: import org.eclipse.emf.common.util.URI;
22: import org.eclipse.emf.ecore.EClass;
23: import org.eclipse.emf.ecore.EObject;
24: import org.eclipse.emf.ecore.EReference;
25: import org.eclipse.emf.ecore.EcoreFactory;
26: import org.eclipse.emf.ecore.EcorePackage;
27: import org.eclipse.emf.ecore.resource.Resource;
28: import org.eclipse.emf.ecore.resource.ResourceSet;
29: import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
30: import org.eclipse.emf.ecp.ui.view.swt.reference.ReferenceServiceCustomizationVendor;
31: import org.eclipse.emf.ecp.view.spi.model.VView;
32: import org.eclipse.emf.ecp.view.spi.model.VViewFactory;
33: import org.eclipse.emf.ecp.view.spi.model.VViewPackage;
34: import org.eclipse.emf.ecp.view.spi.table.model.VTableControl;
35: import org.eclipse.emf.ecp.view.spi.table.model.VTableFactory;
36: import org.eclipse.emf.ecp.view.spi.table.model.VTablePackage;
37: import org.eclipse.emf.ecp.view.test.common.swt.spi.SWTTestUtil;
38: import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
39: import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
40: import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory;
41: import org.eclipse.swt.widgets.Display;
42: import org.eclipse.swt.widgets.Shell;
43: import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
44: import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
45: import org.junit.After;
46: import org.junit.Before;
47: import org.junit.Test;
48: import org.junit.runner.RunWith;
49:
50: /**
51: * Abstract base class for unit tests for multi segment dmr reference strategy providers.
52: *
53: * @author Lucas Koehler
54: *
55: */
56: @RunWith(SWTBotJunit4ClassRunner.class)
57: public abstract class AbstractMultiDmrStrategyProviderTest<T extends ReferenceServiceCustomizationVendor<?> & TestableStrategyProvider> {
58:
59:         private T strategyProvider;
60:         private VTableControl tableControl;
61:         private EClass testEClass;
62:
63:         /** @return the tested strategy provider */
64:         protected T getStrategyProvider() {
65:                 return strategyProvider;
66:         }
67:
68:         /** @see #getStrategyProvider() */
69:         protected void setStrategyProvider(T strategyProvider) {
70:                 this.strategyProvider = strategyProvider;
71:         }
72:
73:         /** @return the table control containing the multi dmr */
74:         protected VTableControl getTableControl() {
75:                 return tableControl;
76:         }
77:
78:         /** @see #getTableControl() */
79:         protected void setTableControl(VTableControl tableControl) {
80:                 this.tableControl = tableControl;
81:         }
82:
83:         /** @return The root EClass for the VView (indirectly) containing the multi dmr. */
84:         protected EClass getTestEClass() {
85:                 return testEClass;
86:         }
87:
88:         /** @see #getTestEClass() */
89:         protected void setTestEClass(EClass testEClass) {
90:                 this.testEClass = testEClass;
91:         }
92:
93:         @Before
94:         public void setUp() {
95:                 testEClass = EcoreFactory.eINSTANCE.createEClass();
96:                 testEClass.setName("TestClass"); //$NON-NLS-1$
97:                 // ePackage.getEClassifiers().add(eClass);
98:                 final EReference eReference = EcoreFactory.eINSTANCE.createEReference();
99:                 eReference.setUpperBound(-1);
100:                 eReference.setName("TestReference"); //$NON-NLS-1$
101:                 eReference.setEType(EcorePackage.Literals.ECLASS);
102:                 testEClass.getEStructuralFeatures().add(eReference);
103:
104:                 // Create view model with a multi segment
105:                 final VView view = VViewFactory.eINSTANCE.createView();
106:                 view.setRootEClass(testEClass);
107:                 tableControl = VTableFactory.eINSTANCE.createTableControl();
108:                 view.getChildren().add(tableControl);
109:
110:                 // Add the view to a resource with editing domain
111:                 final ResourceSet rs = new ResourceSetImpl();
112:                 final ComposedAdapterFactory adapterFactory = new ComposedAdapterFactory(new AdapterFactory[] {
113:                         new ReflectiveItemProviderAdapterFactory(),
114:                         new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE) });
115:                 final AdapterFactoryEditingDomain editingDomain = new AdapterFactoryEditingDomain(
116:                         adapterFactory, new BasicCommandStack(), rs);
117:                 rs.eAdapters().add(new AdapterFactoryEditingDomain.EditingDomainProvider(editingDomain));
118:                 final Resource resource = rs.createResource(URI.createURI("VIRTUAL_URI")); //$NON-NLS-1$
119:                 resource.getContents().add(view);
120:
121:                 initStrategyProvider();
122:
123:                 // Wait for the UI harness to be ready before starting the test execution
124:                 UIThreadRunnable.syncExec(SWTTestUtil::waitForUIThread);
125:         }
126:
127:         @After
128:         public void tearDown() {
129:                 // Shell 0 and 1 must not be disposed. They belong to the UI harness around the tests
130:                 UIThreadRunnable.syncExec(Display.getDefault(), () -> {
131:                         final Shell[] shells = Display.getDefault().getShells();
132:•                        for (int i = 2; i < shells.length; i++) {
133:•                                if (shells[i] != null && !shells[i].isDisposed()) {
134:                                         shells[i].dispose();
135:                                 }
136:                         }
137:                 });
138:         }
139:
140:         protected abstract void initStrategyProvider();
141:
142:         protected abstract boolean executeHandles(EObject owner, EReference reference);
143:
144:         @Test
145:         public void handles_generationEnabled_true() {
146:                 strategyProvider.setSegmentToolingEnabled(true);
147:                 assertTrue(executeHandles(tableControl, VViewPackage.Literals.CONTROL__DOMAIN_MODEL_REFERENCE));
148:         }
149:
150:         @Test
151:         public void handles_generationEnabled_incorrectReference() {
152:                 strategyProvider.setSegmentToolingEnabled(true);
153:                 assertFalse(executeHandles(tableControl, VTablePackage.Literals.TABLE_CONTROL__COLUMN_CONFIGURATIONS));
154:         }
155:
156:         @Test
157:         public void handles_generationEnabled_incorrectParent() {
158:                 strategyProvider.setSegmentToolingEnabled(true);
159:                 assertFalse(executeHandles(VViewFactory.eINSTANCE.createControl(),
160:                         VViewPackage.Literals.CONTROL__DOMAIN_MODEL_REFERENCE));
161:         }
162:
163:         @Test
164:         public void handles_generationEnabled_incorrectBoth() {
165:                 strategyProvider.setSegmentToolingEnabled(true);
166:                 assertFalse(
167:                         executeHandles(VViewFactory.eINSTANCE.createControl(), EcorePackage.Literals.ECLASS__ESTRUCTURAL_FEATURES));
168:         }
169:
170:         @Test
171:         public void handles_generationDisabled() {
172:                 strategyProvider.setSegmentToolingEnabled(false);
173:                 assertFalse(executeHandles(tableControl, VViewPackage.Literals.CONTROL__DOMAIN_MODEL_REFERENCE));
174:         }
175:
176: }