Skip to content

Package: TableRevealProvider_PTest

TableRevealProvider_PTest

nameinstructionbranchcomplexitylinemethod
TableRevealProvider_PTest()
M: 0 C: 15
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
createDomainModel()
M: 0 C: 77
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 12
100%
M: 0 C: 1
100%
createShell()
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%
createViewModel()
M: 0 C: 23
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
destroyShell()
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%
render()
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
revealInTable()
M: 0 C: 41
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) 2019 Christian W. Damus 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: * Christian W. Damus - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.view.internal.table.swt;
15:
16: import static org.hamcrest.CoreMatchers.is;
17: import static org.junit.Assert.assertThat;
18: import static org.mockito.Matchers.anyBoolean;
19: import static org.mockito.Mockito.mock;
20: import static org.mockito.Mockito.verify;
21: import static org.mockito.Mockito.when;
22:
23: import org.eclipse.emf.common.util.ECollections;
24: import org.eclipse.emf.common.util.EList;
25: import org.eclipse.emf.ecore.EAttribute;
26: import org.eclipse.emf.ecore.EClass;
27: import org.eclipse.emf.ecore.EObject;
28: import org.eclipse.emf.ecore.EReference;
29: import org.eclipse.emf.ecore.EStructuralFeature;
30: import org.eclipse.emf.ecore.EcorePackage;
31: import org.eclipse.emf.ecore.InternalEObject;
32: import org.eclipse.emf.ecp.test.common.DefaultRealm;
33: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
34: import org.eclipse.emf.ecp.view.spi.model.VView;
35: import org.eclipse.emf.ecp.view.spi.model.VViewFactory;
36: import org.eclipse.emf.ecp.view.spi.table.model.VTableControl;
37: import org.eclipse.emf.ecp.view.table.test.common.TableControlHandle;
38: import org.eclipse.emf.ecp.view.table.test.common.TableTestUtil;
39: import org.eclipse.emf.ecp.view.test.common.spi.EMFFormsRevealServiceFixture;
40: import org.eclipse.emf.ecp.view.test.common.spi.EMFFormsViewContextFixture.DomainModel;
41: import org.eclipse.emf.ecp.view.test.common.spi.EMFFormsViewContextFixture.ViewModel;
42: import org.eclipse.emf.ecp.view.test.common.spi.EMFMockingRunner;
43: import org.eclipse.emf.ecp.view.test.common.spi.EMock;
44: import org.eclipse.emf.ecp.view.test.common.swt.spi.SWTTestUtil;
45: import org.eclipse.emf.ecp.view.test.common.swt.spi.SWTViewTestHelper;
46: import org.eclipse.emfforms.bazaar.Bid;
47: import org.eclipse.emfforms.bazaar.Create;
48: import org.eclipse.emfforms.spi.core.services.reveal.EMFFormsRevealProvider;
49: import org.eclipse.emfforms.spi.core.services.reveal.Reveal;
50: import org.eclipse.emfforms.spi.core.services.reveal.RevealHelper;
51: import org.eclipse.emfforms.spi.core.services.reveal.RevealStep;
52: import org.eclipse.swt.widgets.Shell;
53: import org.eclipse.swt.widgets.Table;
54: import org.junit.After;
55: import org.junit.Before;
56: import org.junit.Rule;
57: import org.junit.Test;
58: import org.junit.rules.TestRule;
59: import org.junit.runner.RunWith;
60:
61: /**
62: * Tests covering the {@link TableRevealProvider} class.
63: */
64: @RunWith(EMFMockingRunner.class)
65: public class TableRevealProvider_PTest {
66:
67:         @ViewModel
68:         private final VView viewModel = VViewFactory.eINSTANCE.createView();
69:
70:         @EMock
71:         @DomainModel
72:         private EClass rootObject;
73:
74:         @EMock
75:         private EReference obj1;
76:
77:         @EMock
78:         private EAttribute obj2;
79:
80:         private VTableControl table;
81:
82:         @Rule
83:         public final TestRule realm = DefaultRealm.rule();
84:
85:         @Rule
86:         public final EMFFormsRevealServiceFixture<ViewModelContext> fixture = EMFFormsRevealServiceFixture.create(
87:                 ViewModelContext.class, this);
88:
89:         private Shell shell;
90:
91:         /**
92:          * Initializes me.
93:          */
94:         public TableRevealProvider_PTest() {
95:                 super();
96:         }
97:
98:         @Test
99:         public void revealInTable() {
100:                 final Runnable reveal = mock(Runnable.class);
101:
102:                 fixture.addRevealProvider(new ViewRevealer(reveal));
103:
104:                 render();
105:
106:                 fixture.reveal(obj2);
107:
108:                 SWTTestUtil.waitForUIThread();
109:
110:                 verify(reveal).run();
111:
112:                 final Table table = SWTTestUtil.findControl(shell, 0, Table.class);
113:                 assertThat("Table selection incorrect", table.getSelectionIndex(), is(1));
114:         }
115:
116:         //
117:         // Test framework
118:         //
119:
120:         @Before
121:         public void createViewModel() {
122:                 final TableControlHandle handle = TableTestUtil
123:                         .createInitializedTableWithoutTableColumns(EcorePackage.Literals.ECLASS__ESTRUCTURAL_FEATURES);
124:
125:                 handle.addFirstTableColumn(TableTestUtil.createTableColumn(EcorePackage.Literals.ENAMED_ELEMENT__NAME));
126:                 handle.addSecondTableColumn(TableTestUtil.createTableColumn(EcorePackage.Literals.ETYPED_ELEMENT__ETYPE));
127:
128:                 table = handle.getTableControl();
129:                 viewModel.getChildren().add(table);
130:         }
131:
132:         @Before
133:         public void createDomainModel() {
134:                 final EList<EStructuralFeature> features = ECollections.asEList(obj1, obj2);
135:                 when(rootObject.getEStructuralFeatures()).thenReturn(features);
136:                 when(rootObject.eGet(EcorePackage.Literals.ECLASS__ESTRUCTURAL_FEATURES)).thenReturn(features);
137:                 when(obj1.getName()).thenReturn("ref1");
138:                 when(obj2.getName()).thenReturn("att1");
139:
140:                 // This is needed by the data binding service
141:                 final EStructuralFeature.Setting setting = mock(EStructuralFeature.Setting.class);
142:                 when(setting.getEObject()).thenReturn(rootObject);
143:                 when(setting.getEStructuralFeature()).thenReturn(EcorePackage.Literals.ECLASS__ESTRUCTURAL_FEATURES);
144:                 when(setting.get(anyBoolean())).thenReturn(features);
145:                 when(((InternalEObject) rootObject).eSetting(EcorePackage.Literals.ECLASS__ESTRUCTURAL_FEATURES))
146:                         .thenReturn(setting);
147:         }
148:
149:         @Before
150:         public void createShell() {
151:                 shell = new Shell();
152:         }
153:
154:         @After
155:         public void destroyShell() {
156:                 shell.dispose();
157:                 shell = null;
158:         }
159:
160:         void render() {
161:                 SWTViewTestHelper.render(fixture.getViewContext(), shell);
162:         }
163:
164:         //
165:         // Nested types
166:         //
167:
168:         /**
169:          * A high-bidding reveal provider to make sure that we drill into the view
170:          * to find the table, regardless of other possible contributions in the
171:          * current configuration.
172:          */
173:         private final class ViewRevealer implements EMFFormsRevealProvider {
174:
175:                 private final Runnable reveal;
176:
177:                 ViewRevealer(Runnable reveal) {
178:                         super();
179:
180:                         this.reveal = reveal;
181:                 }
182:
183:                 @Bid
184:                 public Double bid(VView view, EObject model) {
185:                         return view == viewModel && model == obj2 ? Double.MAX_VALUE : null;
186:                 }
187:
188:                 @Create
189:                 public RevealStep create(VView view, EObject model, RevealHelper helper) {
190:                         return view == viewModel && model == obj2
191:                                 ? helper.drillDown(this)
192:                                 : RevealStep.fail();
193:                 }
194:
195:                 @Reveal
196:                 private RevealStep drillDown(VView view, EObject model) {
197:                         return RevealStep.reveal(view, model, reveal);
198:                 }
199:         }
200:
201: }