Skip to content

Package: CategorizationTreeRefresh_PTest

CategorizationTreeRefresh_PTest

nameinstructionbranchcomplexitylinemethod
CategorizationTreeRefresh_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%
assertError(Tree)
M: 0 C: 23
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
assertNoError(Tree)
M: 0 C: 23
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
checkData(TreeItem)
M: 2 C: 33
94%
M: 2 C: 4
67%
M: 2 C: 2
50%
M: 1 C: 4
80%
M: 0 C: 1
100%
setUp()
M: 0 C: 94
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 26
100%
M: 0 C: 1
100%
static {...}
M: 3 C: 16
84%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 1 C: 12
92%
M: 0 C: 1
100%
tearDown()
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%
testNoValidationErrorDynamic()
M: 0 C: 33
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
testNoValidationErrorOnInit()
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%
testValidationErrorDynamic()
M: 0 C: 37
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 9
100%
M: 0 C: 1
100%
testValidationErrorOnInit()
M: 0 C: 24
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
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: * Eugen Neufeld - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.view.categorization.swt.test;
15:
16: import static org.junit.Assert.assertFalse;
17: import static org.junit.Assert.assertTrue;
18: import static org.junit.Assert.fail;
19:
20: import java.net.MalformedURLException;
21: import java.net.URL;
22: import java.util.Arrays;
23:
24: import org.eclipse.emf.ecp.ui.view.ECPRendererException;
25: import org.eclipse.emf.ecp.ui.view.swt.ECPSWTView;
26: import org.eclipse.emf.ecp.ui.view.swt.ECPSWTViewRenderer;
27: import org.eclipse.emf.ecp.view.spi.categorization.model.VCategorization;
28: import org.eclipse.emf.ecp.view.spi.categorization.model.VCategorizationElement;
29: import org.eclipse.emf.ecp.view.spi.categorization.model.VCategorizationFactory;
30: import org.eclipse.emf.ecp.view.spi.categorization.model.VCategory;
31: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
32: import org.eclipse.emf.ecp.view.spi.context.ViewModelContextFactory;
33: import org.eclipse.emf.ecp.view.spi.model.VControl;
34: import org.eclipse.emf.ecp.view.spi.model.VFeaturePathDomainModelReference;
35: import org.eclipse.emf.ecp.view.spi.model.VView;
36: import org.eclipse.emf.ecp.view.spi.model.VViewFactory;
37: import org.eclipse.emf.ecp.view.test.common.swt.spi.DatabindingClassRunner;
38: import org.eclipse.emf.emfstore.bowling.BowlingFactory;
39: import org.eclipse.emf.emfstore.bowling.BowlingPackage;
40: import org.eclipse.emf.emfstore.bowling.Player;
41: import org.eclipse.jface.resource.ImageDescriptor;
42: import org.eclipse.swt.graphics.Image;
43: import org.eclipse.swt.layout.FillLayout;
44: import org.eclipse.swt.widgets.Display;
45: import org.eclipse.swt.widgets.Shell;
46: import org.eclipse.swt.widgets.Tree;
47: import org.eclipse.swt.widgets.TreeItem;
48: import org.junit.After;
49: import org.junit.Before;
50: import org.junit.Test;
51: import org.junit.runner.RunWith;
52:
53: /**
54: * @author Eugen Neufeld
55: *
56: */
57: @RunWith(DatabindingClassRunner.class)
58: public class CategorizationTreeRefresh_PTest {
59:
60:         private static Image idCategorization;
61:         private static Image idCategory;
62:
63:         static {
64:                 try {
65:                         idCategorization = ImageDescriptor
66:                                 .createFromURL(
67:                                         new URL(
68:                                                 "platform:/plugin/org.eclipse.emf.ecp.view.categorization.model.edit/icons/full/obj16/Categorization.gif"))
69:                                 .createImage();
70:                         idCategory = ImageDescriptor
71:                                 .createFromURL(
72:                                         new URL(
73:                                                 "platform:/plugin/org.eclipse.emf.ecp.view.categorization.model.edit/icons/full/obj16/Category.gif"))
74:                                 .createImage();
75:                 } catch (final MalformedURLException ex) {
76:                         ex.printStackTrace();
77:                 }
78:         }
79:
80:         private Player player;
81:         private VView view;
82:         private VCategorization categorization;
83:         private VCategory category1;
84:         private VCategory category2;
85:         private ECPSWTView ecpSwtView;
86:         private Shell shell;
87:
88:         /**
89:          * @throws java.lang.Exception
90:          */
91:         @Before
92:         public void setUp() throws Exception {
93:                 view = VViewFactory.eINSTANCE.createView();
94:
95:                 final VCategorizationElement categorizationElement = VCategorizationFactory.eINSTANCE
96:                         .createCategorizationElement();
97:                 categorization = VCategorizationFactory.eINSTANCE.createCategorization();
98:
99:                 category1 = VCategorizationFactory.eINSTANCE.createCategory();
100:                 category2 = VCategorizationFactory.eINSTANCE.createCategory();
101:
102:                 categorization.getCategorizations().add(category1);
103:
104:                 categorizationElement.getCategorizations().add(categorization);
105:                 categorizationElement.getCategorizations().add(category2);
106:
107:                 view.getChildren().add(categorizationElement);
108:
109:                 {
110:                         final VControl control1 = VViewFactory.eINSTANCE.createControl();
111:                         final VFeaturePathDomainModelReference featurePathDomainModelReference = VViewFactory.eINSTANCE
112:                                 .createFeaturePathDomainModelReference();
113:                         featurePathDomainModelReference.setDomainModelEFeature(BowlingPackage.eINSTANCE.getPlayer_EMails());
114:                         control1.setDomainModelReference(featurePathDomainModelReference);
115:                         category1.setComposite(control1);
116:                 }
117:                 {
118:                         final VControl control1 = VViewFactory.eINSTANCE.createControl();
119:                         final VFeaturePathDomainModelReference featurePathDomainModelReference = VViewFactory.eINSTANCE
120:                                 .createFeaturePathDomainModelReference();
121:                         featurePathDomainModelReference.setDomainModelEFeature(BowlingPackage.eINSTANCE.getPlayer_EMails());
122:                         control1.setDomainModelReference(featurePathDomainModelReference);
123:                         category2.setComposite(control1);
124:                 }
125:
126:                 player = BowlingFactory.eINSTANCE.createPlayer();
127:
128:                 shell = new Shell();
129:                 shell.setLayout(new FillLayout());
130:
131:         }
132:
133:         /**
134:          * @throws java.lang.Exception
135:          */
136:         @After
137:         public void tearDown() throws Exception {
138:                 ecpSwtView.dispose();
139:                 shell.dispose();
140:         }
141:
142:         private boolean checkData(TreeItem item) {
143:•                if (item.getData() == categorization) {
144:                         return Arrays.equals(idCategorization.getImageData().data, item.getImage().getImageData().data);
145:•                } else if (item.getData() == category1 || item.getData() == category2) {
146:                         return Arrays.equals(idCategory.getImageData().data, item.getImage().getImageData().data);
147:                 }
148:                 return false;
149:         }
150:
151:         private void assertNoError(Tree tree) {
152:•                for (final TreeItem item : tree.getItems()) {
153:                         assertTrue("there should not be an error icon!", checkData(item));
154:                 }
155:         }
156:
157:         private void assertError(Tree tree) {
158:•                for (final TreeItem item : tree.getItems()) {
159:                         assertFalse("the icon must have an error icon!", checkData(item));
160:                 }
161:         }
162:
163:         @Test
164:         public void testNoValidationErrorOnInit() throws ECPRendererException {
165:                 player.getEMails().add("bla");
166:                 final ViewModelContext vmc = ViewModelContextFactory.INSTANCE.createViewModelContext(view, player);
167:                 ecpSwtView = ECPSWTViewRenderer.INSTANCE.render(shell, vmc);
168:                 final Tree tree = CategoryRendererTestHelper.getTree(ecpSwtView.getSWTControl());
169:
170:                 // assert
171:                 waitForUIThread();
172:                 assertNoError(tree);
173:         }
174:
175:         @Test
176:         public void testValidationErrorOnInit() throws ECPRendererException {
177:                 final ViewModelContext vmc = ViewModelContextFactory.INSTANCE.createViewModelContext(view, player);
178:                 ecpSwtView = ECPSWTViewRenderer.INSTANCE.render(shell, vmc);
179:                 final Tree tree = CategoryRendererTestHelper.getTree(ecpSwtView.getSWTControl());
180:                 // assert
181:                 waitForUIThread();
182:                 assertError(tree);
183:         }
184:
185:         @Test
186:         public void testValidationErrorDynamic() throws ECPRendererException {
187:                 player.getEMails().add("bla");
188:                 final ViewModelContext vmc = ViewModelContextFactory.INSTANCE.createViewModelContext(view, player);
189:                 ecpSwtView = ECPSWTViewRenderer.INSTANCE.render(shell, vmc);
190:                 final Tree tree = CategoryRendererTestHelper.getTree(ecpSwtView.getSWTControl());
191:
192:                 // assert init state
193:                 assertNoError(tree);
194:
195:                 // change state
196:                 player.getEMails().clear();
197:
198:                 // assert
199:                 waitForUIThread();
200:                 assertError(tree);
201:         }
202:
203:         @Test
204:         public void testNoValidationErrorDynamic() throws ECPRendererException {
205:                 final ViewModelContext vmc = ViewModelContextFactory.INSTANCE.createViewModelContext(view, player);
206:                 ecpSwtView = ECPSWTViewRenderer.INSTANCE.render(shell, vmc);
207:                 final Tree tree = CategoryRendererTestHelper.getTree(ecpSwtView.getSWTControl());
208:
209:                 // assert init state
210:                 assertError(tree);
211:
212:                 // change state
213:                 player.getEMails().add("bla");
214:
215:                 // assert
216:                 waitForUIThread();
217:                 assertNoError(tree);
218:         }
219:
220:         private static void waitForUIThread() {
221:                 final long maxTime = System.currentTimeMillis() + 5000;
222:•                while (Display.getDefault().readAndDispatch()) {
223:•                        if (System.currentTimeMillis() > maxTime) {
224:                                 fail("Timeout");
225:                         }
226:                 }
227:         }
228: }