Skip to content

Package: DynamicDMR_PTest

DynamicDMR_PTest

nameinstructionbranchcomplexitylinemethod
DynamicDMR_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%
addFavMerchNameControl()
M: 0 C: 21
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
addFavPlayerNameControl()
M: 0 C: 21
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
assertText(String, boolean)
M: 1 C: 22
96%
M: 2 C: 2
50%
M: 2 C: 1
33%
M: 0 C: 4
100%
M: 0 C: 1
100%
before()
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%
changeDomain(Merchandise, Player, Merchandise[])
M: 0 C: 16
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
getText()
M: 0 C: 18
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
initControl(VControl, EStructuralFeature, EReference[])
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%
merchandise(String)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
player(String)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
render()
M: 32 C: 11
26%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 5 C: 3
38%
M: 0 C: 1
100%
testAddMissingContainmentElement()
M: 0 C: 21
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
testAddMissingContainmentElement2Times()
M: 0 C: 33
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 10
100%
M: 0 C: 1
100%
testAddMissingReferencedElement()
M: 0 C: 21
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
testAddRemovedContainmentElement()
M: 39 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%
testInitMissingContainmentElement()
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
testInitMissingReferencedElement()
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
testRemoveContainmentElement()
M: 27 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
testRemoveReferencedElement()
M: 27 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
testReplaceContainmentElement()
M: 0 C: 28
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
testReplaceReferencedElement()
M: 0 C: 28
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
waitForUIThread()
M: 2 C: 13
87%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 1 C: 4
80%
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: * Johannes Faltermeier - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.view.core.swt.tests;
15:
16: import static org.junit.Assert.assertEquals;
17: import static org.junit.Assert.fail;
18:
19: import java.util.Arrays;
20:
21: import org.eclipse.emf.ecore.EReference;
22: import org.eclipse.emf.ecore.EStructuralFeature;
23: import org.eclipse.emf.ecp.view.spi.model.VControl;
24: import org.eclipse.emf.ecp.view.spi.model.VView;
25: import org.eclipse.emf.ecp.view.spi.model.VViewFactory;
26: import org.eclipse.emf.ecp.view.spi.renderer.NoPropertyDescriptorFoundExeption;
27: import org.eclipse.emf.ecp.view.spi.renderer.NoRendererFoundException;
28: import org.eclipse.emf.ecp.view.test.common.swt.spi.DatabindingClassRunner;
29: import org.eclipse.emf.ecp.view.test.common.swt.spi.SWTViewTestHelper;
30: import org.eclipse.emf.emfstore.bowling.BowlingFactory;
31: import org.eclipse.emf.emfstore.bowling.BowlingPackage;
32: import org.eclipse.emf.emfstore.bowling.Fan;
33: import org.eclipse.emf.emfstore.bowling.Merchandise;
34: import org.eclipse.emf.emfstore.bowling.Player;
35: import org.eclipse.emfforms.spi.swt.core.EMFFormsNoRendererException;
36: import org.eclipse.swt.widgets.Composite;
37: import org.eclipse.swt.widgets.Control;
38: import org.eclipse.swt.widgets.Display;
39: import org.eclipse.swt.widgets.Shell;
40: import org.eclipse.swt.widgets.Text;
41: import org.junit.Before;
42: import org.junit.Ignore;
43: import org.junit.Test;
44: import org.junit.runner.RunWith;
45:
46: @RunWith(DatabindingClassRunner.class)
47: public class DynamicDMR_PTest {
48:
49:         private static final String EMPTY = ""; //$NON-NLS-1$
50:         private static final String NAME_INIT = "name"; //$NON-NLS-1$
51:         private static final String NAME_OTHER = "other"; //$NON-NLS-1$
52:
53:         private Shell shell;
54:         private VView view;
55:         private Fan domain;
56:         private Control control;
57:
58:         @Before
59:         public void before() {
60:                 shell = SWTViewTestHelper.createShell();
61:                 view = VViewFactory.eINSTANCE.createView();
62:                 view.setRootEClass(BowlingPackage.eINSTANCE.getFan());
63:                 domain = BowlingFactory.eINSTANCE.createFan();
64:         }
65:
66:         @Test
67:         public void testInitMissingContainmentElement() {
68:                 // setup
69:                 addFavMerchNameControl();
70:                 // act
71:                 render();
72:                 // assert
73:                 waitForUIThread();
74:                 assertText(EMPTY, true);
75:         }
76:
77:         @Test
78:         public void testInitMissingReferencedElement() {
79:                 // setup
80:                 addFavPlayerNameControl();
81:                 // act
82:                 render();
83:                 // assert
84:                 waitForUIThread();
85:                 assertText(EMPTY, true);
86:         }
87:
88:         @Test
89:         @Ignore
90:         // FIXME reactive
91:         public void testRemoveContainmentElement() {
92:                 // setup
93:                 addFavMerchNameControl();
94:                 changeDomain(merchandise(NAME_INIT), null);
95:                 render();
96:                 assertText(NAME_INIT, true);
97:                 // act
98:                 changeDomain(null, null);
99:                 // assert
100:                 waitForUIThread();
101:                 assertText(EMPTY, false);
102:         }
103:
104:         @Test
105:         @Ignore
106:         // FIXME reactive
107:         public void testRemoveReferencedElement() {
108:                 // setup
109:                 addFavPlayerNameControl();
110:                 changeDomain(null, player(NAME_INIT));
111:                 render();
112:                 assertText(NAME_INIT, true);
113:                 // act
114:                 changeDomain(null, null);
115:                 // assert
116:                 waitForUIThread();
117:                 assertText(EMPTY, false);
118:         }
119:
120:         @Test
121:         public void testAddMissingContainmentElement() {
122:                 // setup
123:                 addFavMerchNameControl();
124:                 render();
125:                 assertText(EMPTY, true);
126:                 // act
127:                 changeDomain(merchandise(NAME_INIT), null);
128:                 // assert
129:                 waitForUIThread();
130:                 assertText(NAME_INIT, true);
131:         }
132:
133:         @Test
134:         public void testAddMissingContainmentElement2Times() {
135:                 // setup
136:                 addFavMerchNameControl();
137:                 render();
138:                 assertText(EMPTY, true);
139:                 // act
140:                 changeDomain(merchandise(NAME_INIT), null);
141:                 // assert
142:                 waitForUIThread();
143:                 assertText(NAME_INIT, true);
144:
145:                 changeDomain(merchandise(NAME_INIT + "2"), null); //$NON-NLS-1$
146:                 // assert
147:                 waitForUIThread();
148:                 assertText(NAME_INIT + "2", true); //$NON-NLS-1$
149:         }
150:
151:         @Test
152:         @Ignore
153:         // FIXME reactive
154:         public void testAddRemovedContainmentElement() {
155:                 // setup
156:                 addFavMerchNameControl();
157:                 changeDomain(merchandise(NAME_INIT), null);
158:                 render();
159:                 assertText(NAME_INIT, true);
160:                 // act
161:                 changeDomain(null, null);
162:                 // assert
163:                 waitForUIThread();
164:                 assertText(EMPTY, false);
165:
166:                 // act
167:                 changeDomain(merchandise(NAME_INIT), null);
168:                 // assert
169:                 waitForUIThread();
170:                 assertText(NAME_INIT, true);
171:         }
172:
173:         @Test
174:         public void testAddMissingReferencedElement() {
175:                 // setup
176:                 addFavPlayerNameControl();
177:                 render();
178:                 assertText(EMPTY, true);
179:                 // act
180:                 changeDomain(null, player(NAME_INIT));
181:                 // assert
182:                 waitForUIThread();
183:                 assertText(NAME_INIT, true);
184:         }
185:
186:         @Test
187:         public void testReplaceContainmentElement() {
188:                 // setup
189:                 addFavMerchNameControl();
190:                 changeDomain(merchandise(NAME_INIT), null);
191:                 render();
192:                 assertText(NAME_INIT, true);
193:                 // act
194:                 changeDomain(merchandise(NAME_OTHER), null);
195:                 // assert
196:                 waitForUIThread();
197:                 assertText(NAME_OTHER, true);
198:         }
199:
200:         @Test
201:         public void testReplaceReferencedElement() {
202:                 // setup
203:                 addFavPlayerNameControl();
204:                 changeDomain(null, player(NAME_INIT));
205:                 render();
206:                 assertText(NAME_INIT, true);
207:                 // act
208:                 changeDomain(null, player(NAME_OTHER));
209:                 // assert
210:                 waitForUIThread();
211:                 assertText(NAME_OTHER, true);
212:         }
213:
214:         private void render() {
215:                 try {
216:                         control = SWTViewTestHelper.render(view, domain, shell);
217:                 } catch (final NoRendererFoundException e) {
218:                         fail("Could not render view: " + e.getMessage()); //$NON-NLS-1$
219:                 } catch (final NoPropertyDescriptorFoundExeption e) {
220:                         fail("Could not render view: " + e.getMessage()); //$NON-NLS-1$
221:                 } catch (final EMFFormsNoRendererException e) {
222:                         fail("Could not render view: " + e.getMessage()); //$NON-NLS-1$
223:                 }
224:         }
225:
226:         private void changeDomain(Merchandise favMerchandise, Player favPlayer,
227:                 Merchandise... merchandise) {
228:                 domain.setFavouriteMerchandise(favMerchandise);
229:                 domain.setFavouritePlayer(favPlayer);
230:                 domain.getFanMerchandise().addAll(Arrays.asList(merchandise));
231:         }
232:
233:         private static void waitForUIThread() {
234:                 final long maxTime = System.currentTimeMillis() + 5000;
235:•                while (Display.getDefault().readAndDispatch()) {
236:•                        if (System.currentTimeMillis() > maxTime) {
237:                                 fail("Timeout"); //$NON-NLS-1$
238:                         }
239:                 }
240:         }
241:
242:         private static Merchandise merchandise(String name) {
243:                 final Merchandise merchandise = BowlingFactory.eINSTANCE.createMerchandise();
244:                 merchandise.setName(name);
245:                 return merchandise;
246:         }
247:
248:         private static Player player(String name) {
249:                 final Player player = BowlingFactory.eINSTANCE.createPlayer();
250:                 player.setName(name);
251:                 return player;
252:         }
253:
254:         private void addFavMerchNameControl() {
255:                 final VControl control = VViewFactory.eINSTANCE.createControl();
256:                 initControl(control, BowlingPackage.eINSTANCE.getMerchandise_Name(),
257:                         BowlingPackage.eINSTANCE.getFan_FavouriteMerchandise());
258:                 view.getChildren().add(control);
259:         }
260:
261:         private void addFavPlayerNameControl() {
262:                 final VControl control = VViewFactory.eINSTANCE.createControl();
263:                 initControl(control, BowlingPackage.eINSTANCE.getPlayer_Name(),
264:                         BowlingPackage.eINSTANCE.getFan_FavouritePlayer());
265:                 view.getChildren().add(control);
266:         }
267:
268:         private static void initControl(VControl control, EStructuralFeature feature,
269:                 EReference... references) {
270:                 control.setDomainModelReference(feature, Arrays.asList(references));
271:         }
272:
273:         private Text getText() {
274:                 final Composite composite = (Composite) control;
275:                 final Control text = composite.getChildren()[2];
276:                 return (Text) Composite.class.cast(text).getChildren()[0];
277:         }
278:
279:         private void assertText(String message, boolean enabled) {
280:                 final Text text = getText();
281:•                assertEquals("Enablement of text control: ", enabled, text.isEnabled() && text.getEditable()); //$NON-NLS-1$
282:                 assertEquals("Text of text control: ", message, text.getText()); //$NON-NLS-1$
283:         }
284:
285: }