Skip to content

Package: ValidationServiceGC_PTest

ValidationServiceGC_PTest

nameinstructionbranchcomplexitylinemethod
ValidationServiceGC_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%
createComputerView()
M: 0 C: 53
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 12
100%
M: 0 C: 1
100%
createWriterWithNestedColumnsView()
M: 0 C: 55
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 15
100%
M: 0 C: 1
100%
setup()
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%
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%
testDomainObjectIsReferenced()
M: 0 C: 15
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
testRemoveChildOfDomainObject()
M: 39 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
testRemoveChildOfDomainObjectWithCutOffControl()
M: 50 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
testRemoveControlAndReevaluate()
M: 0 C: 70
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 12
100%
M: 0 C: 1
100%
testRemoveRenderable()
M: 0 C: 22
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
testRemoveRenderableHierarchy()
M: 0 C: 62
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 16
100%
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: * Edgar Mueller - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.view.validation.test;
15:
16: import static org.junit.Assert.assertEquals;
17: import static org.junit.Assert.assertFalse;
18: import static org.junit.Assert.assertTrue;
19:
20: import org.eclipse.emf.common.util.Diagnostic;
21: import org.eclipse.emf.ecp.test.common.DefaultRealm;
22: import org.eclipse.emf.ecp.view.spi.context.ViewModelContextFactory;
23: import org.eclipse.emf.ecp.view.spi.model.VControl;
24: import org.eclipse.emf.ecp.view.spi.model.VFeaturePathDomainModelReference;
25: import org.eclipse.emf.ecp.view.spi.model.VView;
26: import org.eclipse.emf.ecp.view.spi.model.VViewFactory;
27: import org.eclipse.emf.ecp.view.spi.vertical.model.VVerticalFactory;
28: import org.eclipse.emf.ecp.view.spi.vertical.model.VVerticalLayout;
29: import org.eclipse.emf.ecp.view.test.common.spi.GCCollectable;
30: import org.eclipse.emf.ecp.view.test.common.spi.Tuple;
31: import org.eclipse.emf.ecp.view.validation.test.model.Computer;
32: import org.eclipse.emf.ecp.view.validation.test.model.TestFactory;
33: import org.eclipse.emf.ecp.view.validation.test.model.TestPackage;
34: import org.eclipse.emf.ecp.view.validation.test.model.Writer;
35: import org.junit.After;
36: import org.junit.Before;
37: import org.junit.Ignore;
38: import org.junit.Test;
39:
40: /**
41: * Tests for checking whether the {@link org.eclipse.emf.ecp.view.spi.validation.ValidationService
42: * ValidationService} correctly behave if domain
43: * objects and/or {@link org.eclipse.emf.ecp.view.spi.model.VElement Renderable}s are removed.
44: *
45: * @author emueller
46: */
47: public class ValidationServiceGC_PTest extends CommonValidationTest {
48:
49:         private DefaultRealm defaultRealm;
50:
51:         @Before
52:         public void setup() {
53:                 defaultRealm = new DefaultRealm();
54:         }
55:
56:         @After
57:         public void tearDown() {
58:                 defaultRealm.dispose();
59:         }
60:
61:         /**
62:          * Creates a basic view with an column that contains a control
63:          * that is bound to the mainboard name feature of a computer.
64:          * Both the computer and the mainboard are also created.
65:          *
66:          * @return a tuple containing the root of the view model
67:          * as well as the root of the domain model
68:          */
69:         protected Tuple<VView, Computer> createComputerView() {
70:
71:                 final Computer computer = TestFactory.eINSTANCE.createComputer();
72:                 final VView view = VViewFactory.eINSTANCE.createView();
73:
74:                 ViewModelContextFactory.INSTANCE.createViewModelContext(view, computer);
75:
76:                 final VControl control = VViewFactory.eINSTANCE.createControl();
77:                 final VVerticalLayout column = VVerticalFactory.eINSTANCE.createVerticalLayout();
78:                 view.getChildren().add(column);
79:
80:                 control.setDomainModelReference(getVFeaturePathDomainModelReference(TestPackage.eINSTANCE.getMainboard_Name(),
81:                         TestPackage.eINSTANCE.getComputer_Mainboard()));
82:                 column.getChildren().add(control);
83:
84:                 // TODO
85:                 // final Mainboard mainboard = TestFactory.eINSTANCE.createMainboard();
86:                 // computer.setMainboard(mainboard);
87:
88:                 assertEquals("Severity of mainboard name must be error", Diagnostic.ERROR, control.getDiagnostic()
89:                         .getHighestSeverity());
90:
91:                 return new Tuple<VView, Computer>(view, computer);
92:         }
93:
94:         /**
95:          * Creates a basic view with an two nested columns.
96:          * The most inner column contains a control
97:          * that is bound to the {@link TestPackage#getWriter_FirstName()} feature of a {@link Writer}.
98:          * The writer will also be created by this method.
99:          *
100:          * @return a tuple containing the root of the view model
101:          * as well as the root of the domain model
102:          */
103:         protected Tuple<VView, Writer> createWriterWithNestedColumnsView() {
104:                 final Writer writer = TestFactory.eINSTANCE.createWriter();
105:                 final VView view = VViewFactory.eINSTANCE.createView();
106:                 view.setRootEClass(writer.eClass());
107:
108:                 final VVerticalLayout parentColumn = VVerticalFactory.eINSTANCE.createVerticalLayout();
109:                 view.getChildren().add(parentColumn);
110:
111:                 final VVerticalLayout column = VVerticalFactory.eINSTANCE.createVerticalLayout();
112:                 parentColumn.getChildren().add(column);
113:
114:                 final VControl controlWriter = VViewFactory.eINSTANCE.createControl();
115:
116:                 final VFeaturePathDomainModelReference domainModelReference = VViewFactory.eINSTANCE
117:                         .createFeaturePathDomainModelReference();
118:                 domainModelReference.setDomainModelEFeature(TestPackage.eINSTANCE.getWriter_FirstName());
119:                 controlWriter.setDomainModelReference(domainModelReference);
120:
121:                 column.getChildren().add(controlWriter);
122:
123:                 ViewModelContextFactory.INSTANCE.createViewModelContext(view, writer);
124:
125:                 return new Tuple<VView, Writer>(view, writer);
126:         }
127:
128:         /**
129:          * Removes the direct column of the view. The nested column as
130:          * well as the control should be removed and thus not referenced
131:          * anymore.
132:          */
133:         @Test
134:         public void testRemoveRenderableHierarchy() {
135:
136:                 final VView view = createWriterWithNestedColumnsView().first();
137:                 final GCCollectable parentColumnCollectable = new GCCollectable(
138:                         view.getChildren().get(0));
139:                 final GCCollectable columnCollectable = new GCCollectable(
140:                         VVerticalLayout.class.cast(view.getChildren().get(0)).getChildren().get(0));
141:                 final GCCollectable controlCollectable = new GCCollectable(
142:                         VVerticalLayout.class.cast(
143:                                 VVerticalLayout.class.cast(view.getChildren().get(0))
144:                                         .getChildren().get(0))
145:                                 .getChildren()
146:                                 .get(0));
147:
148:                 view.getChildren().remove(0);
149:
150:                 assertTrue(parentColumnCollectable.isCollectable());
151:                 assertTrue(columnCollectable.isCollectable());
152:                 assertTrue(controlCollectable.isCollectable());
153:         }
154:
155:         /**
156:          * Removes the direct column of the view. The nested column as
157:          * well as the control should be removed and thus not referenced
158:          * anymore.
159:          */
160:         @Test
161:         public void testRemoveControlAndReevaluate() {
162:
163:                 final VView view = createWriterWithNestedColumnsView().first();
164:
165:                 final GCCollectable controlCollectable = new GCCollectable(
166:                         VVerticalLayout.class.cast(VVerticalLayout.class.cast(
167:                                 view.getChildren().get(0)).getChildren().get(0)).getChildren().get(0));
168:
169:                 assertEquals(Diagnostic.ERROR,
170:                         VVerticalLayout.class.cast(view.getChildren().get(0)).getDiagnostic().getHighestSeverity());
171:
172:                 VVerticalLayout.class.cast(VVerticalLayout.class.cast(
173:                         view.getChildren().get(0)).getChildren().get(0)).getChildren().remove(0);
174:
175:                 assertEquals(Diagnostic.OK,
176:                         VVerticalLayout.class.cast(view.getChildren().get(0)).getDiagnostic().getHighestSeverity());
177:
178:                 assertTrue(controlCollectable.isCollectable());
179:         }
180:
181:         /**
182:          * Make sure child domain object is actually referenced.
183:          */
184:         @Test
185:         public void testDomainObjectIsReferenced() {
186:
187:                 final Tuple<VView, Computer> t = createComputerView();
188:
189:                 final GCCollectable mainboardCollectable = new GCCollectable(
190:                         t.second().getMainboard());
191:
192:                 assertFalse(mainboardCollectable.isCollectable());
193:         }
194:
195:         /**
196:          * Remove the {@link org.eclipse.emf.ecp.view.validation.test.model.Mainboard Mainboard}. It shouldn't be referenced
197:          * anymore
198:          * in contrast to the control.
199:          */
200:         @Ignore
201:         @Test
202:         public void testRemoveChildOfDomainObject() {
203:
204:                 final Tuple<VView, Computer> t = createComputerView();
205:
206:                 final GCCollectable mainboardCollectable = new GCCollectable(
207:                         t.second().getMainboard());
208:                 final GCCollectable controlCollectable = new GCCollectable(
209:                         VVerticalLayout.class.cast(t.first().getChildren().get(0)).getChildren().get(0));
210:                 t.second().setMainboard(null);
211:
212:                 // control for mainboard should be removed from
213:                 assertTrue(mainboardCollectable.isCollectable());
214:                 assertFalse(controlCollectable.isCollectable());
215:         }
216:
217:         /**
218:          * Removes the {@link org.eclipse.emf.ecp.view.validation.test.model.Mainboard Mainboard} from the computer and also
219:          * removes the control
220:          * from the view model containment tree.
221:          * Neither the mainboard nor the control should be referenced afterwards.
222:          */
223:         @Ignore
224:         @Test
225:         public void testRemoveChildOfDomainObjectWithCutOffControl() {
226:
227:                 final Tuple<VView, Computer> t = createComputerView();
228:
229:                 final GCCollectable mainboardCollectable = new GCCollectable(
230:                         t.second().getMainboard());
231:                 final GCCollectable controlCollectable = new GCCollectable(
232:                         VVerticalLayout.class.cast(t.first().getChildren().get(0)).getChildren().get(0));
233:
234:                 t.second().setMainboard(null);
235:
236:                 VVerticalLayout.class.cast(t.first().getChildren().get(0)).getChildren().clear();
237:
238:                 // control for mainboard shouldn't be referenced anymore by validation registry or service
239:                 assertTrue(mainboardCollectable.isCollectable());
240:                 assertTrue(controlCollectable.isCollectable());
241:         }
242:
243:         /**
244:          * Removes the direct column of the computer view.
245:          */
246:         @Test
247:         public void testRemoveRenderable() {
248:
249:                 final VView view = createComputerView().first();
250:                 final GCCollectable collectable = new GCCollectable(view.getChildren().get(0));
251:                 // removes the column
252:                 view.getChildren().remove(0);
253:
254:                 assertTrue(collectable.isCollectable());
255:         }
256: }