Skip to content

Package: Categorization_PTest

Categorization_PTest

nameinstructionbranchcomplexitylinemethod
Categorization_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%
assertCategorizationSubEditor(Composite, String)
M: 0 C: 51
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 10
100%
M: 0 C: 1
100%
assertLabelAndTextControl(Composite, String)
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%
assertLabelText(Composite, String)
M: 0 C: 16
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
assertTreeAndTreeItems(Composite, VAbstractCategorization[])
M: 1 C: 45
98%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 0 C: 7
100%
M: 0 C: 1
100%
checkIfThereIsATextControl(Control)
M: 28 C: 22
44%
M: 2 C: 2
50%
M: 2 C: 1
33%
M: 6 C: 4
40%
M: 0 C: 1
100%
checkTreeItem(TreeItem, VAbstractCategorization)
M: 0 C: 39
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
render()
M: 0 C: 15
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
setUp()
M: 0 C: 28
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
tearDown()
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
testCategorizationWithCategories()
M: 1 C: 87
99%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 23
100%
M: 0 C: 1
100%
testCategorizationWithCategory()
M: 1 C: 68
99%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 17
100%
M: 0 C: 1
100%
testCategorizationWithoutCategory()
M: 1 C: 49
98%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 11
100%
M: 0 C: 1
100%
testCategorizationsAndCategories()
M: 1 C: 133
99%
M: 1 C: 5
83%
M: 1 C: 3
75%
M: 0 C: 30
100%
M: 0 C: 1
100%
testOnlyCategories()
M: 1 C: 102
99%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 24
100%
M: 0 C: 1
100%
testOnlyOneCategory()
M: 2 C: 57
97%
M: 2 C: 2
50%
M: 2 C: 1
33%
M: 0 C: 13
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2014 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: * Eugen - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.view.categorization.swt.test;
15:
16: import static org.junit.Assert.assertEquals;
17: import static org.junit.Assert.assertTrue;
18:
19: import org.eclipse.emf.ecp.ui.view.ECPRendererException;
20: import org.eclipse.emf.ecp.ui.view.swt.ECPSWTView;
21: import org.eclipse.emf.ecp.ui.view.swt.ECPSWTViewRenderer;
22: import org.eclipse.emf.ecp.view.spi.categorization.model.VAbstractCategorization;
23: import org.eclipse.emf.ecp.view.spi.categorization.model.VCategorization;
24: import org.eclipse.emf.ecp.view.spi.categorization.model.VCategorizationElement;
25: import org.eclipse.emf.ecp.view.spi.categorization.model.VCategorizationFactory;
26: import org.eclipse.emf.ecp.view.spi.categorization.model.VCategory;
27: import org.eclipse.emf.ecp.view.spi.model.ModelReferenceHelper;
28: import org.eclipse.emf.ecp.view.spi.model.VControl;
29: import org.eclipse.emf.ecp.view.spi.model.VView;
30: import org.eclipse.emf.ecp.view.spi.model.VViewFactory;
31: import org.eclipse.emf.ecp.view.test.common.swt.spi.DatabindingClassRunner;
32: import org.eclipse.emf.emfstore.bowling.BowlingFactory;
33: import org.eclipse.emf.emfstore.bowling.BowlingPackage;
34: import org.eclipse.emf.emfstore.bowling.Gender;
35: import org.eclipse.emf.emfstore.bowling.Player;
36: import org.eclipse.swt.custom.ScrolledComposite;
37: import org.eclipse.swt.widgets.Composite;
38: import org.eclipse.swt.widgets.Control;
39: import org.eclipse.swt.widgets.Label;
40: import org.eclipse.swt.widgets.Shell;
41: import org.eclipse.swt.widgets.Text;
42: import org.eclipse.swt.widgets.Tree;
43: import org.eclipse.swt.widgets.TreeItem;
44: import org.junit.After;
45: import org.junit.Before;
46: import org.junit.Test;
47: import org.junit.runner.RunWith;
48:
49: @RunWith(DatabindingClassRunner.class)
50: public class Categorization_PTest {
51:
52:         private static final String TESTNAME = "test"; //$NON-NLS-1$
53:         private static final String NAME = "Name"; //$NON-NLS-1$
54:         private static final String PLAYERNAME = "Player"; //$NON-NLS-1$
55:         private Player player;
56:         private VView view;
57:         private VCategorizationElement element;
58:
59:         @Before
60:         public void setUp() throws Exception {
61:
62:                 player = BowlingFactory.eINSTANCE.createPlayer();
63:                 player.setName(PLAYERNAME);
64:                 player.setGender(Gender.MALE);
65:
66:                 view = VViewFactory.eINSTANCE.createView();
67:                 element = VCategorizationFactory.eINSTANCE.createCategorizationElement();
68:                 view.getChildren().add(element);
69:         }
70:
71:         private Control render() throws ECPRendererException {
72:                 final Shell shell = new Shell();
73:
74:                 final ECPSWTView render = ECPSWTViewRenderer.INSTANCE.render(shell, player, view);
75:                 return render.getSWTControl();
76:         }
77:
78:         private static boolean checkIfThereIsATextControl(Control control) {
79:•                if (Text.class.isInstance(control)) {
80:                         return true;
81:                 }
82:
83:                 Composite controlComposite = (Composite) control;
84:•                if (Text.class.isInstance(Composite.class.cast(controlComposite.getChildren()[2]).getChildren()[0])) {
85:                         return true;
86:                 }
87:                 controlComposite = (Composite) controlComposite.getChildren()[2];
88:                 controlComposite = (Composite) controlComposite.getChildren()[0];
89:                 controlComposite = (Composite) controlComposite.getChildren()[0];
90:                 final Control textControl = controlComposite.getChildren()[0];
91:
92:                 return textControl instanceof Text;
93:         }
94:
95:         private static void assertTreeAndTreeItems(Composite composite, VAbstractCategorization... categorizations) {
96:•                assertTrue(composite.getChildren().length == 2);
97:                 assertTrue(Tree.class.isInstance(composite.getChildren()[0]));
98:                 final Tree tree = (Tree) composite.getChildren()[0];
99:                 assertEquals(categorizations.length, tree.getItems().length);
100:•                for (int i = 0; i < categorizations.length; i++) {
101:                         checkTreeItem(tree.getItem(i), categorizations[i]);
102:                 }
103:         }
104:
105:         private static void checkTreeItem(TreeItem treeItem, VAbstractCategorization abstractCategorization) {
106:                 assertEquals(abstractCategorization, treeItem.getData());
107:•                if (VCategorization.class.isInstance(abstractCategorization)) {
108:                         final VCategorization categorization = (VCategorization) abstractCategorization;
109:                         assertEquals(categorization.getCategorizations().size(), treeItem.getItems().length);
110:•                        for (int i = 0; i < categorization.getCategorizations().size(); i++) {
111:                                 checkTreeItem(treeItem.getItem(i), categorization.getCategorizations().get(i));
112:                         }
113:                 }
114:         }
115:
116:         private void assertLabelAndTextControl(Composite composite, String labelText) {
117:                 final Composite composite2 = Composite.class.cast(composite.getChildren()[0]);
118:                 assertLabelText(composite2, labelText);
119:                 assertTrue(checkIfThereIsATextControl(composite2));
120:         }
121:
122:         private void assertLabelText(Composite composite, String labelText) {
123:                 assertTrue(Label.class.isInstance(composite.getChildren()[0]));
124:                 assertEquals(labelText, ((Label) composite.getChildren()[0]).getText());
125:         }
126:
127:         private void assertCategorizationSubEditor(Composite composite, String text) {
128:                 assertTrue(ScrolledComposite.class.isInstance(composite.getChildren()[1]));
129:                 final ScrolledComposite scrolledComposite = (ScrolledComposite) composite.getChildren()[1];
130:                 Control content = scrolledComposite.getContent();
131:                 assertTrue(Composite.class.isInstance(content));
132:                 content = ((Composite) content).getChildren()[0];
133:                 assertTrue(Composite.class.isInstance(content));
134:                 assertEquals(2, ((Composite) content).getChildren().length);
135:                 assertLabelText((Composite) content, text);
136:                 assertTrue(Label.class.isInstance(((Composite) content).getChildren()[1]));
137:         }
138:
139:         @After
140:         public void tearDown() throws Exception {
141:         }
142:
143:         @Test
144:         public void testOnlyOneCategory() throws ECPRendererException {
145:                 final VCategory vCategory1 = VCategorizationFactory.eINSTANCE.createCategory();
146:                 final VControl controlPlayerName = VViewFactory.eINSTANCE.createControl();
147:                 controlPlayerName.setDomainModelReference(ModelReferenceHelper
148:                         .createDomainModelReference(BowlingPackage.eINSTANCE.getPlayer_Name()));
149:                 vCategory1.setComposite(controlPlayerName);
150:                 element.getCategorizations().add(vCategory1);
151:
152:                 final Control render = render();
153:
154:                 assertTrue(Composite.class.isInstance(render));
155:                 final Composite composite = (Composite) render;
156:                 // extra assert due to extra composite
157:•                assertTrue(composite.getChildren().length == 1);
158:                 // composite = (Composite) composite.getChildren()[0];
159:
160:•                assertTrue(Composite.class.cast(composite.getChildren()[0]).getChildren().length == 3);
161:                 assertLabelAndTextControl(composite, NAME);
162:
163:         }
164:
165:         @Test
166:         public void testOnlyCategories() throws ECPRendererException {
167:                 final VCategory vCategory1 = VCategorizationFactory.eINSTANCE.createCategory();
168:                 final VControl controlPlayerName = VViewFactory.eINSTANCE.createControl();
169:                 controlPlayerName.setDomainModelReference(ModelReferenceHelper
170:                         .createDomainModelReference(BowlingPackage.eINSTANCE.getPlayer_Name()));
171:                 vCategory1.setComposite(controlPlayerName);
172:                 element.getCategorizations().add(vCategory1);
173:
174:                 final VCategory vCategory2 = VCategorizationFactory.eINSTANCE.createCategory();
175:                 final VControl controlPlayerHeight = VViewFactory.eINSTANCE.createControl();
176:                 controlPlayerHeight.setDomainModelReference(ModelReferenceHelper
177:                         .createDomainModelReference(BowlingPackage.eINSTANCE.getPlayer_Height()));
178:                 vCategory2.setComposite(controlPlayerHeight);
179:                 element.getCategorizations().add(vCategory2);
180:
181:                 final Control render = render();
182:                 assertTrue(Composite.class.isInstance(render));
183:                 Composite composite = (Composite) render;
184:                 // extra assert due to extra composite
185:•                assertTrue(composite.getChildren().length == 1);
186:                 composite = (Composite) composite.getChildren()[0];
187:
188:                 assertTreeAndTreeItems(composite, vCategory1, vCategory2);
189:
190:                 assertTrue(ScrolledComposite.class.isInstance(composite.getChildren()[1]));
191:                 final ScrolledComposite scrolledComposite = (ScrolledComposite) composite.getChildren()[1];
192:                 final Control content = scrolledComposite.getContent();
193:                 assertTrue(Composite.class.isInstance(content));
194:                 // content = ((Composite) content).getChildren()[0];
195:                 assertLabelAndTextControl((Composite) content, NAME);
196:         }
197:
198:         @Test
199:         public void testCategorizationWithoutCategory() throws ECPRendererException {
200:                 final VCategorization vCategorization = VCategorizationFactory.eINSTANCE.createCategorization();
201:                 vCategorization.setName(TESTNAME);
202:                 element.getCategorizations().add(vCategorization);
203:                 final Control render = render();
204:
205:                 assertTrue(Composite.class.isInstance(render));
206:                 Composite composite = (Composite) render;
207:
208:                 // extra assert due to extra composite
209:•                assertTrue(composite.getChildren().length == 1);
210:                 composite = (Composite) composite.getChildren()[0];
211:
212:                 assertTreeAndTreeItems(composite, vCategorization);
213:
214:                 assertCategorizationSubEditor(composite, TESTNAME);
215:
216:         }
217:
218:         @Test
219:         public void testCategorizationWithCategory() throws ECPRendererException {
220:                 final VCategorization vCategorization = VCategorizationFactory.eINSTANCE.createCategorization();
221:                 vCategorization.setName(TESTNAME);
222:                 element.getCategorizations().add(vCategorization);
223:                 final VCategory vCategory1 = VCategorizationFactory.eINSTANCE.createCategory();
224:                 final VControl controlPlayerName = VViewFactory.eINSTANCE.createControl();
225:                 controlPlayerName.setDomainModelReference(ModelReferenceHelper
226:                         .createDomainModelReference(BowlingPackage.eINSTANCE.getPlayer_Name()));
227:                 vCategory1.setComposite(controlPlayerName);
228:
229:                 vCategorization.getCategorizations().add(vCategory1);
230:
231:                 final Control render = render();
232:
233:                 // asserts
234:                 assertTrue(Composite.class.isInstance(render));
235:                 Composite composite = (Composite) render;
236:                 // extra assert due to extra composite
237:•                assertTrue(composite.getChildren().length == 1);
238:                 composite = (Composite) composite.getChildren()[0];
239:
240:                 assertTreeAndTreeItems(composite, vCategorization);
241:
242:                 assertCategorizationSubEditor(composite, TESTNAME);
243:
244:         }
245:
246:         @Test
247:         public void testCategorizationWithCategories() throws ECPRendererException {
248:                 final VCategorization vCategorization = VCategorizationFactory.eINSTANCE.createCategorization();
249:                 vCategorization.setName(TESTNAME);
250:                 element.getCategorizations().add(vCategorization);
251:                 final VCategory vCategory1 = VCategorizationFactory.eINSTANCE.createCategory();
252:                 final VControl controlPlayerName = VViewFactory.eINSTANCE.createControl();
253:                 controlPlayerName.setDomainModelReference(ModelReferenceHelper
254:                         .createDomainModelReference(BowlingPackage.eINSTANCE.getPlayer_Name()));
255:                 vCategory1.setComposite(controlPlayerName);
256:
257:                 vCategorization.getCategorizations().add(vCategory1);
258:
259:                 final VCategory vCategory2 = VCategorizationFactory.eINSTANCE.createCategory();
260:                 final VControl controlPlayerHeight = VViewFactory.eINSTANCE.createControl();
261:                 controlPlayerHeight.setDomainModelReference(ModelReferenceHelper
262:                         .createDomainModelReference(BowlingPackage.eINSTANCE.getPlayer_Height()));
263:                 vCategory2.setComposite(controlPlayerHeight);
264:                 vCategorization.getCategorizations().add(vCategory2);
265:
266:                 final Control render = render();
267:
268:                 // asserts
269:                 assertTrue(Composite.class.isInstance(render));
270:                 Composite composite = (Composite) render;
271:                 // extra assert due to extra composite
272:•                assertTrue(composite.getChildren().length == 1);
273:                 composite = (Composite) composite.getChildren()[0];
274:
275:                 assertTreeAndTreeItems(composite, vCategorization);
276:
277:                 assertCategorizationSubEditor(composite, TESTNAME);
278:
279:         }
280:
281:         @Test
282:         public void testCategorizationsAndCategories() throws ECPRendererException {
283:                 final VCategorization[] categorizations = new VCategorization[5];
284:•                for (int i = 0; i < 5; i++) {
285:                         final VCategorization vCategorization = VCategorizationFactory.eINSTANCE.createCategorization();
286:                         vCategorization.setName(TESTNAME + i);
287:                         element.getCategorizations().add(vCategorization);
288:                         categorizations[i] = vCategorization;
289:•                        for (int j = 0; j < 5; j++) {
290:                                 final VCategorization vCategorization2 = VCategorizationFactory.eINSTANCE.createCategorization();
291:                                 vCategorization2.setName(TESTNAME + i + "_" + j); //$NON-NLS-1$
292:                                 vCategorization.getCategorizations().add(vCategorization2);
293:
294:                                 final VCategory vCategory1 = VCategorizationFactory.eINSTANCE.createCategory();
295:                                 final VControl controlPlayerName = VViewFactory.eINSTANCE.createControl();
296:                                 controlPlayerName.setDomainModelReference(ModelReferenceHelper
297:                                         .createDomainModelReference(BowlingPackage.eINSTANCE.getPlayer_Name()));
298:                                 vCategory1.setComposite(controlPlayerName);
299:
300:                                 vCategorization2.getCategorizations().add(vCategory1);
301:
302:                                 final VCategory vCategory2 = VCategorizationFactory.eINSTANCE.createCategory();
303:                                 final VControl controlPlayerHeight = VViewFactory.eINSTANCE.createControl();
304:                                 controlPlayerHeight.setDomainModelReference(ModelReferenceHelper
305:                                         .createDomainModelReference(BowlingPackage.eINSTANCE.getPlayer_Height()));
306:                                 vCategory2.setComposite(controlPlayerHeight);
307:                                 vCategorization2.getCategorizations().add(vCategory2);
308:
309:                         }
310:                 }
311:
312:                 final Control render = render();
313:
314:                 // asserts
315:                 assertTrue(Composite.class.isInstance(render));
316:                 Composite composite = (Composite) render;
317:                 // extra assert due to extra composite
318:•                assertTrue(composite.getChildren().length == 1);
319:                 composite = (Composite) composite.getChildren()[0];
320:
321:                 assertTreeAndTreeItems(composite, categorizations);
322:
323:                 assertCategorizationSubEditor(composite, categorizations[0].getName());
324:         }
325:
326: }