2
|
1 |
/*
|
|
2 |
* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
package com.nokia.sdt.emf.dm.tests;
|
|
19 |
|
|
20 |
import com.nokia.sdt.component.IComponent;
|
|
21 |
import com.nokia.sdt.component.property.IPropertyInformation;
|
|
22 |
import com.nokia.sdt.component.property.ISequencePropertySource;
|
|
23 |
import com.nokia.sdt.datamodel.IDesignerDataModel;
|
|
24 |
import com.nokia.sdt.datamodel.adapter.IComponentInstance;
|
|
25 |
import com.nokia.sdt.datamodel.adapter.IComponentInstancePropertyListener;
|
|
26 |
import com.nokia.sdt.datamodel.util.ModelUtils;
|
|
27 |
import com.nokia.sdt.emf.dm.IComponentManifest;
|
|
28 |
import com.nokia.sdt.symbian.dm.DesignerDataModel;
|
|
29 |
import com.nokia.sdt.testsupport.TestDataModelHelpers;
|
|
30 |
import com.nokia.cpp.internal.api.utils.core.Logging;
|
|
31 |
|
|
32 |
import org.eclipse.emf.common.command.Command;
|
|
33 |
import org.eclipse.emf.ecore.EObject;
|
|
34 |
import org.eclipse.ui.views.properties.IPropertySource;
|
|
35 |
|
|
36 |
import java.util.Collections;
|
|
37 |
import java.util.List;
|
|
38 |
|
|
39 |
import junit.framework.TestCase;
|
|
40 |
|
|
41 |
/**
|
|
42 |
* Test reference property promotion
|
|
43 |
*
|
|
44 |
*
|
|
45 |
*/
|
|
46 |
public class ReferencePropertyPromotionTest extends TestCase {
|
|
47 |
|
|
48 |
static final String MAIN_COMPONENT = "com.nokia.test.rptMainComponent";
|
|
49 |
static final String SUB_COMPONENT = "com.nokia.test.rptSubComponent";
|
|
50 |
static final String SUB_COMPONENT_CONFLICTS_1 = "com.nokia.test.rptSubComponentConflicts1";
|
|
51 |
static final String SUB_COMPONENT_CONFLICTS_2 = "com.nokia.test.rptSubComponentConflicts2";
|
|
52 |
static final String REFERENCE_PROPERTY = "reference";
|
|
53 |
static final String REFERENCE2_PROPERTY = "reference2";
|
|
54 |
|
|
55 |
DesignerDataModel model;
|
|
56 |
EObject root;
|
|
57 |
IComponentManifest manifest;
|
|
58 |
|
|
59 |
protected void setUp() throws Exception {
|
|
60 |
Logging.alwaysLogToConsole = true;
|
|
61 |
TestDataModelHelpers.setupResourceFactory();
|
|
62 |
TestDataModelHelpers.setupTestComponents();
|
|
63 |
model = (DesignerDataModel) TestDataModelHelpers.createTemporaryModel();
|
|
64 |
TestDataModelHelpers.initDefaultComponentSet(model);
|
|
65 |
|
|
66 |
IComponent component = model.getComponentSet().lookupComponent(MAIN_COMPONENT);
|
|
67 |
root = model.createNewComponentInstance(component);
|
|
68 |
model.getDesignerData().getRootContainers().add(root);
|
|
69 |
|
|
70 |
IPropertySource rootPs = ModelUtils.getPropertySource(root);
|
|
71 |
rootPs.setPropertyValue("name", "root");
|
|
72 |
|
|
73 |
}
|
|
74 |
|
|
75 |
protected EObject addChild(EObject parent, String componentId, String name) {
|
|
76 |
IComponent subComponent = model.getComponentSet().lookupComponent(componentId);
|
|
77 |
EObject sub = model.createNewComponentInstance(subComponent);
|
|
78 |
Command addCommand = model.createAddNewComponentInstanceCommand(parent, sub, IDesignerDataModel.AT_END);
|
|
79 |
assertNotNull(addCommand.canExecute());
|
|
80 |
addCommand.execute();
|
|
81 |
IPropertySource ps = ModelUtils.getPropertySource(sub);
|
|
82 |
ps.setPropertyValue("name", name);
|
|
83 |
return sub;
|
|
84 |
}
|
|
85 |
|
|
86 |
protected EObject addChild(EObject parent, String name) {
|
|
87 |
return addChild(parent, SUB_COMPONENT, name);
|
|
88 |
}
|
|
89 |
|
|
90 |
protected void setReference(EObject from, EObject to) {
|
|
91 |
IPropertySource toPs = ModelUtils.getPropertySource(to);
|
|
92 |
String name = toPs.getPropertyValue("name").toString();
|
|
93 |
IPropertySource ps = ModelUtils.getPropertySource(from);
|
|
94 |
ps.setPropertyValue(REFERENCE_PROPERTY, name);
|
|
95 |
}
|
|
96 |
|
|
97 |
/** No reference from root to sub. */
|
|
98 |
public void testUnconnected() {
|
|
99 |
EObject sub = addChild(root, "child");
|
|
100 |
IPropertySource ps = ModelUtils.getPropertySource(root);
|
|
101 |
assertNull(ps.getPropertyValue("intValue"));
|
|
102 |
assertNull(ps.getPropertyValue("stringValue"));
|
|
103 |
assertNull(ps.getPropertyValue("refValue"));
|
|
104 |
assertNull(ps.getPropertyValue("locationValue"));
|
|
105 |
assertNull(ps.getPropertyValue("arrayValue"));
|
|
106 |
|
|
107 |
ps = ModelUtils.getPropertySource(sub);
|
|
108 |
assertNotNull(ps.getPropertyValue("intValue"));
|
|
109 |
assertNotNull(ps.getPropertyValue("stringValue"));
|
|
110 |
assertNotNull(ps.getPropertyValue("refValue"));
|
|
111 |
assertNotNull(ps.getPropertyValue("locationValue"));
|
|
112 |
assertNotNull(ps.getPropertyValue("arrayValue"));
|
|
113 |
}
|
|
114 |
|
|
115 |
/** Adding a reference from root to sub. */
|
|
116 |
public void testConnected() {
|
|
117 |
EObject sub = addChild(root, "child");
|
|
118 |
IPropertySource rootPs = ModelUtils.getPropertySource(root);
|
|
119 |
rootPs.setPropertyValue(REFERENCE_PROPERTY, "child");
|
|
120 |
|
|
121 |
IPropertySource ps = ModelUtils.getPropertySource(sub);
|
|
122 |
assertNotNull(ps.getPropertyValue("intValue"));
|
|
123 |
assertNotNull(ps.getPropertyValue("stringValue"));
|
|
124 |
assertNotNull(ps.getPropertyValue("refValue"));
|
|
125 |
assertNotNull(ps.getPropertyValue("locationValue"));
|
|
126 |
assertNotNull(ps.getPropertyValue("arrayValue"));
|
|
127 |
|
|
128 |
assertNotNull(rootPs.getPropertyValue("intValue"));
|
|
129 |
assertNotNull(rootPs.getPropertyValue("stringValue"));
|
|
130 |
assertNotNull(rootPs.getPropertyValue("refValue"));
|
|
131 |
assertNotNull(rootPs.getPropertyValue("locationValue"));
|
|
132 |
assertNotNull(rootPs.getPropertyValue("arrayValue"));
|
|
133 |
|
|
134 |
assertEquals("child", rootPs.getPropertyValue(REFERENCE_PROPERTY));
|
|
135 |
|
|
136 |
}
|
|
137 |
|
|
138 |
/** Test that the values are properly promoted */
|
|
139 |
public void testPromotingPropertyValues() {
|
|
140 |
EObject sub = addChild(root, "child");
|
|
141 |
IPropertySource rootPs = ModelUtils.getPropertySource(root);
|
|
142 |
IPropertySource subPs = ModelUtils.getPropertySource(sub);
|
|
143 |
|
|
144 |
assertFalse(rootPs.isPropertySet("intValue"));
|
|
145 |
assertFalse(rootPs.isPropertySet("stringValue"));
|
|
146 |
assertFalse(rootPs.isPropertySet("refValue"));
|
|
147 |
assertFalse(rootPs.isPropertySet("locationValue"));
|
|
148 |
assertFalse(rootPs.isPropertySet("arrayValue"));
|
|
149 |
|
|
150 |
assertFalse(subPs.isPropertySet("intValue"));
|
|
151 |
assertFalse(subPs.isPropertySet("stringValue"));
|
|
152 |
assertFalse(subPs.isPropertySet("refValue"));
|
|
153 |
assertFalse(subPs.isPropertySet("locationValue"));
|
|
154 |
assertFalse(subPs.isPropertySet("arrayValue"));
|
|
155 |
|
|
156 |
// verify info
|
|
157 |
IPropertyInformation info = (IPropertyInformation) rootPs;
|
|
158 |
assertEquals(root, info.getPropertyOwner("name"));
|
|
159 |
assertEquals(root, info.getPropertyOwner(REFERENCE_PROPERTY));
|
|
160 |
assertNull(info.getPropertyOwner("intValue"));
|
|
161 |
assertNull(info.getPropertyOwner("stringValue"));
|
|
162 |
|
|
163 |
info = (IPropertyInformation) subPs;
|
|
164 |
assertEquals(sub, info.getPropertyOwner("name"));
|
|
165 |
assertNull(info.getPropertyOwner(REFERENCE_PROPERTY));
|
|
166 |
assertEquals(sub, info.getPropertyOwner("intValue"));
|
|
167 |
assertEquals(sub, info.getPropertyOwner("stringValue"));
|
|
168 |
|
|
169 |
subPs.setPropertyValue("intValue", 23);
|
|
170 |
subPs.setPropertyValue("stringValue", "flargle");
|
|
171 |
subPs.setPropertyValue("refValue", "child"); // self-ref... so what?
|
|
172 |
IPropertySource compound = (IPropertySource) subPs.getPropertyValue("locationValue");
|
|
173 |
compound.setPropertyValue("x", 1);
|
|
174 |
compound.setPropertyValue("y", 2);
|
|
175 |
ISequencePropertySource seq = (ISequencePropertySource) subPs.getPropertyValue("arrayValue");
|
|
176 |
seq.addSimpleProperty(0, true);
|
|
177 |
seq.addSimpleProperty(1, false);
|
|
178 |
assertEquals("true", seq.get(0));
|
|
179 |
assertEquals("false", seq.get(1));
|
|
180 |
|
|
181 |
|
|
182 |
// ensure they're promoted
|
|
183 |
rootPs.setPropertyValue(REFERENCE_PROPERTY, "child");
|
|
184 |
assertEquals("child", rootPs.getPropertyValue(REFERENCE_PROPERTY));
|
|
185 |
|
|
186 |
assertTrue(rootPs.isPropertySet("intValue"));
|
|
187 |
assertTrue(rootPs.isPropertySet("stringValue"));
|
|
188 |
assertTrue(rootPs.isPropertySet("refValue"));
|
|
189 |
assertTrue(rootPs.isPropertySet("locationValue"));
|
|
190 |
assertTrue(rootPs.isPropertySet("arrayValue"));
|
|
191 |
|
|
192 |
assertTrue(subPs.isPropertySet("intValue"));
|
|
193 |
assertTrue(subPs.isPropertySet("stringValue"));
|
|
194 |
assertTrue(subPs.isPropertySet("refValue"));
|
|
195 |
assertTrue(subPs.isPropertySet("locationValue"));
|
|
196 |
assertTrue(subPs.isPropertySet("arrayValue"));
|
|
197 |
|
|
198 |
// verify info
|
|
199 |
info = (IPropertyInformation) rootPs;
|
|
200 |
assertEquals(root, info.getPropertyOwner("name"));
|
|
201 |
assertEquals(root, info.getPropertyOwner(REFERENCE_PROPERTY));
|
|
202 |
assertEquals(sub, info.getPropertyOwner("intValue"));
|
|
203 |
assertEquals(sub, info.getPropertyOwner("stringValue"));
|
|
204 |
|
|
205 |
info = (IPropertyInformation) subPs;
|
|
206 |
assertEquals(sub, info.getPropertyOwner("name"));
|
|
207 |
assertNull(info.getPropertyOwner(REFERENCE_PROPERTY));
|
|
208 |
assertEquals(sub, info.getPropertyOwner("intValue"));
|
|
209 |
assertEquals(sub, info.getPropertyOwner("stringValue"));
|
|
210 |
|
|
211 |
assertEquals(23, rootPs.getPropertyValue("intValue"));
|
|
212 |
assertEquals("flargle", rootPs.getPropertyValue("stringValue"));
|
|
213 |
assertEquals("child", rootPs.getPropertyValue("refValue"));
|
|
214 |
IPropertySource rootCompound = (IPropertySource) rootPs.getPropertyValue("locationValue");
|
|
215 |
assertEquals(1, rootCompound.getPropertyValue("x"));
|
|
216 |
assertEquals(2, rootCompound.getPropertyValue("y"));
|
|
217 |
ISequencePropertySource rootArray = (ISequencePropertySource) rootPs.getPropertyValue("arrayValue");
|
|
218 |
assertEquals(2, rootArray.size());
|
|
219 |
assertEquals("true", rootArray.get(0));
|
|
220 |
assertEquals("false", rootArray.get(1));
|
|
221 |
}
|
|
222 |
|
|
223 |
|
|
224 |
/** Test that properties from the reference do not alias properties of the instance */
|
|
225 |
public void testAliasedPropertyValues() {
|
|
226 |
EObject sub = addChild(root, "child");
|
|
227 |
IPropertySource rootPs = ModelUtils.getPropertySource(root);
|
|
228 |
IPropertySource subPs = ModelUtils.getPropertySource(sub);
|
|
229 |
|
|
230 |
assertEquals("root", rootPs.getPropertyValue("name"));
|
|
231 |
|
|
232 |
rootPs.setPropertyValue(REFERENCE_PROPERTY, "child");
|
|
233 |
|
|
234 |
assertEquals("root", rootPs.getPropertyValue("name"));
|
|
235 |
|
|
236 |
rootPs.setPropertyValue("name", "rootie");
|
|
237 |
assertEquals("rootie", rootPs.getPropertyValue("name"));
|
|
238 |
assertEquals("child", subPs.getPropertyValue("name"));
|
|
239 |
}
|
|
240 |
|
|
241 |
/** Test that we track promoted values properly */
|
|
242 |
public void testChangingPromotingPropertyValues() {
|
|
243 |
EObject sub = addChild(root, "child");
|
|
244 |
IPropertySource rootPs = ModelUtils.getPropertySource(root);
|
|
245 |
IPropertySource subPs = ModelUtils.getPropertySource(sub);
|
|
246 |
|
|
247 |
subPs.setPropertyValue("intValue", 23);
|
|
248 |
|
|
249 |
// ensure they're promoted
|
|
250 |
rootPs.setPropertyValue(REFERENCE_PROPERTY, "child");
|
|
251 |
|
|
252 |
assertTrue(rootPs.isPropertySet("intValue"));
|
|
253 |
|
|
254 |
assertEquals(23, rootPs.getPropertyValue("intValue"));
|
|
255 |
|
|
256 |
////
|
|
257 |
|
|
258 |
subPs.setPropertyValue("stringValue", "flargle");
|
|
259 |
|
|
260 |
assertEquals("flargle", rootPs.getPropertyValue("stringValue"));
|
|
261 |
|
|
262 |
///
|
|
263 |
|
|
264 |
rootPs.resetPropertyValue(REFERENCE_PROPERTY);
|
|
265 |
|
|
266 |
assertFalse(rootPs.isPropertySet("intValue"));
|
|
267 |
assertFalse(rootPs.isPropertySet("stringValue"));
|
|
268 |
|
|
269 |
///
|
|
270 |
|
|
271 |
rootPs.setPropertyValue(REFERENCE_PROPERTY, "child");
|
|
272 |
|
|
273 |
assertEquals("flargle", rootPs.getPropertyValue("stringValue"));
|
|
274 |
assertEquals(23, rootPs.getPropertyValue("intValue"));
|
|
275 |
|
|
276 |
}
|
|
277 |
|
|
278 |
/** Test that a change to the referenced instance (but not its name) is detected */
|
|
279 |
public void testChangingReferencedInstance() {
|
|
280 |
EObject sub = addChild(root, "child");
|
|
281 |
IPropertySource rootPs = ModelUtils.getPropertySource(root);
|
|
282 |
IPropertySource subPs = ModelUtils.getPropertySource(sub);
|
|
283 |
|
|
284 |
rootPs.setPropertyValue(REFERENCE_PROPERTY, "child");
|
|
285 |
|
|
286 |
subPs.setPropertyValue("intValue", 23);
|
|
287 |
subPs.setPropertyValue("stringValue", "flargle");
|
|
288 |
IPropertySource compound = (IPropertySource) subPs.getPropertyValue("locationValue");
|
|
289 |
compound.setPropertyValue("x", 1);
|
|
290 |
compound.setPropertyValue("y", 2);
|
|
291 |
|
|
292 |
// sanity
|
|
293 |
assertTrue(rootPs.isPropertySet("intValue"));
|
|
294 |
assertEquals(23, rootPs.getPropertyValue("intValue"));
|
|
295 |
IPropertySource rootCompound = (IPropertySource) rootPs.getPropertyValue("locationValue");
|
|
296 |
assertEquals(1, rootCompound.getPropertyValue("x"));
|
|
297 |
assertEquals(2, rootCompound.getPropertyValue("y"));
|
|
298 |
|
|
299 |
////
|
|
300 |
|
|
301 |
// replace the child
|
|
302 |
|
|
303 |
List objectsToRemove = Collections.singletonList(sub);
|
|
304 |
Command command = model.createRemoveComponentInstancesCommand(objectsToRemove);
|
|
305 |
assertTrue(command.canExecute());
|
|
306 |
command.execute();
|
|
307 |
|
|
308 |
assertFalse(rootPs.isPropertySet("reference"));
|
|
309 |
|
|
310 |
|
|
311 |
sub = addChild(root, "child");
|
|
312 |
|
|
313 |
subPs = ModelUtils.getPropertySource(sub);
|
|
314 |
|
|
315 |
// sanity
|
|
316 |
assertFalse(subPs.isPropertySet("intValue"));
|
|
317 |
assertFalse(subPs.isPropertySet("stringValue"));
|
|
318 |
assertFalse(subPs.isPropertySet("refValue"));
|
|
319 |
assertFalse(subPs.isPropertySet("locationValue"));
|
|
320 |
assertFalse(subPs.isPropertySet("arrayValue"));
|
|
321 |
|
|
322 |
// check root again
|
|
323 |
assertFalse(rootPs.isPropertySet("intValue"));
|
|
324 |
assertFalse(rootPs.isPropertySet("stringValue"));
|
|
325 |
assertFalse(rootPs.isPropertySet("refValue"));
|
|
326 |
assertFalse(rootPs.isPropertySet("locationValue"));
|
|
327 |
assertFalse(rootPs.isPropertySet("arrayValue"));
|
|
328 |
|
|
329 |
}
|
|
330 |
|
|
331 |
/** Test that properties are not promoted multiple times */
|
|
332 |
public void testConflictingPropertyPromotion1() {
|
|
333 |
// this one aliases 'another'
|
|
334 |
EObject sub = addChild(root, SUB_COMPONENT_CONFLICTS_1, "child");
|
|
335 |
IPropertySource rootPs = ModelUtils.getPropertySource(root);
|
|
336 |
IPropertySource subPs = ModelUtils.getPropertySource(sub);
|
|
337 |
|
|
338 |
rootPs.setPropertyValue("another", "string");
|
|
339 |
subPs.setPropertyValue("another", 42);
|
|
340 |
|
|
341 |
rootPs.setPropertyValue(REFERENCE_PROPERTY, "child");
|
|
342 |
|
|
343 |
assertEquals("string", rootPs.getPropertyValue("another"));
|
|
344 |
assertEquals(42, subPs.getPropertyValue("another"));
|
|
345 |
|
|
346 |
rootPs.setPropertyValue(REFERENCE_PROPERTY, null);
|
|
347 |
|
|
348 |
assertEquals("string", rootPs.getPropertyValue("another"));
|
|
349 |
|
|
350 |
}
|
|
351 |
|
|
352 |
/** Test that properties are not promoted multiple times */
|
|
353 |
public void testConflictingPropertyPromotion2() {
|
|
354 |
// this one aliases 'another'
|
|
355 |
EObject sub1 = addChild(root, SUB_COMPONENT_CONFLICTS_2, "child1");
|
|
356 |
EObject sub2 = addChild(root, SUB_COMPONENT_CONFLICTS_2, "child2");
|
|
357 |
|
|
358 |
IPropertySource rootPs = ModelUtils.getPropertySource(root);
|
|
359 |
IPropertySource sub1Ps = ModelUtils.getPropertySource(sub1);
|
|
360 |
IPropertySource sub2Ps = ModelUtils.getPropertySource(sub2);
|
|
361 |
|
|
362 |
sub1Ps.setPropertyValue("intValue", 4);
|
|
363 |
sub2Ps.setPropertyValue("intValue", 5);
|
|
364 |
|
|
365 |
rootPs.setPropertyValue(REFERENCE_PROPERTY, "child1");
|
|
366 |
rootPs.setPropertyValue(REFERENCE2_PROPERTY, "child2");
|
|
367 |
|
|
368 |
// we can't be sure what order they're added
|
|
369 |
int val = (Integer) rootPs.getPropertyValue("intValue");
|
|
370 |
assertTrue(val == 4 || val == 5);
|
|
371 |
boolean got4 = (val == 4);
|
|
372 |
|
|
373 |
rootPs.setPropertyValue(got4 ? REFERENCE_PROPERTY : REFERENCE2_PROPERTY, null);
|
|
374 |
|
|
375 |
assertEquals(got4 ? 5 : 4, rootPs.getPropertyValue("intValue"));
|
|
376 |
|
|
377 |
rootPs.setPropertyValue(got4 ? REFERENCE2_PROPERTY : REFERENCE_PROPERTY, null);
|
|
378 |
|
|
379 |
assertNull(rootPs.getPropertyValue("intValue"));
|
|
380 |
|
|
381 |
}
|
|
382 |
|
|
383 |
/** Test that we handle when a reference property's name changes */
|
|
384 |
public void testRenamedReferences() {
|
|
385 |
EObject sub = addChild(root, "child");
|
|
386 |
IPropertySource rootPs = ModelUtils.getPropertySource(root);
|
|
387 |
IPropertySource subPs = ModelUtils.getPropertySource(sub);
|
|
388 |
|
|
389 |
rootPs.setPropertyValue(REFERENCE_PROPERTY, "child");
|
|
390 |
|
|
391 |
subPs.setPropertyValue("intValue", 23);
|
|
392 |
assertEquals(23, rootPs.getPropertyValue("intValue"));
|
|
393 |
|
|
394 |
subPs.setPropertyValue("name", "foo");
|
|
395 |
subPs.setPropertyValue("intValue", 42);
|
|
396 |
|
|
397 |
assertEquals(42, rootPs.getPropertyValue("intValue"));
|
|
398 |
|
|
399 |
|
|
400 |
}
|
|
401 |
|
|
402 |
/** test that promoted references inside compound properties works */
|
|
403 |
public void testPromotionInCompoundProperty() {
|
|
404 |
EObject sub = addChild(root, "child");
|
|
405 |
IPropertySource rootPs = ModelUtils.getPropertySource(root);
|
|
406 |
IPropertySource subPs = ModelUtils.getPropertySource(sub);
|
|
407 |
|
|
408 |
IPropertySource rootCompound = (IPropertySource) rootPs.getPropertyValue("refCompound");
|
|
409 |
rootCompound.setPropertyValue(REFERENCE_PROPERTY, "child");
|
|
410 |
|
|
411 |
subPs.setPropertyValue("intValue", 23);
|
|
412 |
|
|
413 |
// ensure not promoted to root
|
|
414 |
assertNull(rootPs.getPropertyValue("intValue"));
|
|
415 |
|
|
416 |
assertEquals(23, rootCompound.getPropertyValue("intValue"));
|
|
417 |
assertEquals("child", rootCompound.getPropertyValue(REFERENCE_PROPERTY));
|
|
418 |
|
|
419 |
subPs.setPropertyValue("intValue", 23);
|
|
420 |
assertEquals(23, rootCompound.getPropertyValue("intValue"));
|
|
421 |
}
|
|
422 |
|
|
423 |
/** Test sanity if reference is broken */
|
|
424 |
public void testBadReference() {
|
|
425 |
EObject sub = addChild(root, "child");
|
|
426 |
IPropertySource rootPs = ModelUtils.getPropertySource(root);
|
|
427 |
IPropertySource subPs = ModelUtils.getPropertySource(sub);
|
|
428 |
|
|
429 |
rootPs.setPropertyValue(REFERENCE_PROPERTY, "foo");
|
|
430 |
|
|
431 |
subPs.setPropertyValue("intValue", 23);
|
|
432 |
assertNull(rootPs.getPropertyValue("intValue"));
|
|
433 |
}
|
|
434 |
|
|
435 |
/** Test sanity for recursive reference */
|
|
436 |
public void testRecursiveReference() {
|
|
437 |
IPropertySource rootPs = ModelUtils.getPropertySource(root);
|
|
438 |
|
|
439 |
rootPs.setPropertyValue(REFERENCE_PROPERTY, "root");
|
|
440 |
|
|
441 |
rootPs.setPropertyValue("another", "string");
|
|
442 |
assertEquals("string", rootPs.getPropertyValue("another"));
|
|
443 |
}
|
|
444 |
|
|
445 |
class PropertyChangeListener implements IComponentInstancePropertyListener {
|
|
446 |
public EObject firedInstance;
|
|
447 |
public String firedProperty;
|
|
448 |
|
|
449 |
public void propertyChanged(EObject componentInstance,
|
|
450 |
Object propertyId) {
|
|
451 |
firedInstance = componentInstance;
|
|
452 |
firedProperty = propertyId.toString();
|
|
453 |
}
|
|
454 |
|
|
455 |
public void reset() {
|
|
456 |
firedInstance = null;
|
|
457 |
firedProperty = null;
|
|
458 |
}
|
|
459 |
|
|
460 |
}
|
|
461 |
/** Test that property listeners get fired on both the referenced instance
|
|
462 |
* and the referencing instance */
|
|
463 |
public void testPropertyChangeListeners() {
|
|
464 |
|
|
465 |
EObject sub = addChild(root, "child");
|
|
466 |
IPropertySource rootPs = ModelUtils.getPropertySource(root);
|
|
467 |
IPropertySource subPs = ModelUtils.getPropertySource(sub);
|
|
468 |
|
|
469 |
|
|
470 |
IComponentInstance rootInstance = ModelUtils.getComponentInstance(root);
|
|
471 |
PropertyChangeListener rootListener = new PropertyChangeListener();
|
|
472 |
rootInstance.addPropertyListener(rootListener);
|
|
473 |
IComponentInstance subInstance = ModelUtils.getComponentInstance(sub);
|
|
474 |
PropertyChangeListener subListener = new PropertyChangeListener();
|
|
475 |
subInstance.addPropertyListener(subListener);
|
|
476 |
|
|
477 |
// wire them up
|
|
478 |
rootPs.setPropertyValue(REFERENCE_PROPERTY, "child");
|
|
479 |
|
|
480 |
// sanity for listeners
|
|
481 |
assertEquals(root, rootListener.firedInstance);
|
|
482 |
assertEquals(REFERENCE_PROPERTY, rootListener.firedProperty);
|
|
483 |
assertNull(subListener.firedInstance);
|
|
484 |
assertNull(subListener.firedProperty);
|
|
485 |
|
|
486 |
rootListener.reset();
|
|
487 |
|
|
488 |
// set on the root, and sub should know
|
|
489 |
rootPs.setPropertyValue("intValue", 23);
|
|
490 |
assertEquals(root, rootListener.firedInstance);
|
|
491 |
assertEquals(sub, subListener.firedInstance);
|
|
492 |
assertEquals("intValue", rootListener.firedProperty);
|
|
493 |
assertEquals("intValue", subListener.firedProperty);
|
|
494 |
rootListener.reset();
|
|
495 |
subListener.reset();
|
|
496 |
|
|
497 |
// set on sub, and root should know
|
|
498 |
subPs.setPropertyValue("intValue", 23);
|
|
499 |
assertEquals(root, rootListener.firedInstance);
|
|
500 |
assertEquals(sub, subListener.firedInstance);
|
|
501 |
assertEquals("intValue", rootListener.firedProperty);
|
|
502 |
assertEquals("intValue", subListener.firedProperty);
|
|
503 |
|
|
504 |
// remove reference and make sure notifications stop
|
|
505 |
rootPs.setPropertyValue(REFERENCE_PROPERTY, null);
|
|
506 |
|
|
507 |
rootListener.reset();
|
|
508 |
subListener.reset();
|
|
509 |
|
|
510 |
subPs.setPropertyValue("intValue", 0);
|
|
511 |
assertNull(rootListener.firedInstance);
|
|
512 |
assertNull(rootListener.firedProperty);
|
|
513 |
assertEquals(sub, subListener.firedInstance);
|
|
514 |
assertEquals("intValue", subListener.firedProperty);
|
|
515 |
|
|
516 |
|
|
517 |
// add again
|
|
518 |
rootPs.setPropertyValue(REFERENCE_PROPERTY, "child");
|
|
519 |
|
|
520 |
rootListener.reset();
|
|
521 |
subListener.reset();
|
|
522 |
|
|
523 |
// now delete the referent, which implicitly resets the reference
|
|
524 |
List objectsToRemove = Collections.singletonList(sub);
|
|
525 |
Command command = model.createRemoveComponentInstancesCommand(objectsToRemove);
|
|
526 |
assertTrue(command.canExecute());
|
|
527 |
command.execute();
|
|
528 |
|
|
529 |
assertFalse(rootPs.isPropertySet("reference"));
|
|
530 |
|
|
531 |
assertEquals(REFERENCE_PROPERTY, rootListener.firedProperty);
|
|
532 |
rootListener.reset();
|
|
533 |
}
|
|
534 |
|
|
535 |
/** Test that property listeners get fired on both the referenced instance
|
|
536 |
* and the referencing instance, when the name property changes */
|
|
537 |
public void testPropertyChangeListeners2() {
|
|
538 |
|
|
539 |
EObject sub = addChild(root, "child");
|
|
540 |
IPropertySource rootPs = ModelUtils.getPropertySource(root);
|
|
541 |
IPropertySource subPs = ModelUtils.getPropertySource(sub);
|
|
542 |
|
|
543 |
IComponentInstance rootInstance = ModelUtils.getComponentInstance(root);
|
|
544 |
PropertyChangeListener rootListener = new PropertyChangeListener();
|
|
545 |
rootInstance.addPropertyListener(rootListener);
|
|
546 |
IComponentInstance subInstance = ModelUtils.getComponentInstance(sub);
|
|
547 |
PropertyChangeListener subListener = new PropertyChangeListener();
|
|
548 |
subInstance.addPropertyListener(subListener);
|
|
549 |
|
|
550 |
// wire them up
|
|
551 |
rootPs.setPropertyValue(REFERENCE_PROPERTY, "child");
|
|
552 |
|
|
553 |
rootListener.reset();
|
|
554 |
|
|
555 |
// set on the root, and sub should know
|
|
556 |
rootPs.setPropertyValue("intValue", 23);
|
|
557 |
assertEquals(root, rootListener.firedInstance);
|
|
558 |
assertEquals(sub, subListener.firedInstance);
|
|
559 |
|
|
560 |
// rename child
|
|
561 |
subPs.setPropertyValue("name", "child_renamed");
|
|
562 |
|
|
563 |
// sanity
|
|
564 |
assertEquals("child_renamed", rootPs.getPropertyValue(REFERENCE_PROPERTY));
|
|
565 |
|
|
566 |
rootListener.reset();
|
|
567 |
subListener.reset();
|
|
568 |
|
|
569 |
// set on the root, and sub should know
|
|
570 |
rootPs.setPropertyValue("intValue", 23);
|
|
571 |
assertEquals(root, rootListener.firedInstance);
|
|
572 |
assertEquals(sub, subListener.firedInstance);
|
|
573 |
}
|
|
574 |
|
|
575 |
/** Test that property listeners get fired on all references */
|
|
576 |
public void testPropertyChangeListeners3() {
|
|
577 |
|
|
578 |
String promotedName = "child";
|
|
579 |
EObject sub = addChild(root, promotedName);
|
|
580 |
EObject sub2 = addChild(root, MAIN_COMPONENT, "child2");
|
|
581 |
IPropertySource rootPs = ModelUtils.getPropertySource(root);
|
|
582 |
IPropertySource subPs = ModelUtils.getPropertySource(sub);
|
|
583 |
IPropertySource sub2Ps = ModelUtils.getPropertySource(sub2);
|
|
584 |
|
|
585 |
|
|
586 |
IComponentInstance rootInstance = ModelUtils.getComponentInstance(root);
|
|
587 |
PropertyChangeListener rootListener = new PropertyChangeListener();
|
|
588 |
rootInstance.addPropertyListener(rootListener);
|
|
589 |
IComponentInstance subInstance = ModelUtils.getComponentInstance(sub);
|
|
590 |
PropertyChangeListener subListener = new PropertyChangeListener();
|
|
591 |
subInstance.addPropertyListener(subListener);
|
|
592 |
IComponentInstance sub2Instance = ModelUtils.getComponentInstance(sub2);
|
|
593 |
PropertyChangeListener sub2Listener = new PropertyChangeListener();
|
|
594 |
sub2Instance.addPropertyListener(sub2Listener);
|
|
595 |
|
|
596 |
// wire them up
|
|
597 |
rootPs.setPropertyValue(REFERENCE_PROPERTY, promotedName);
|
|
598 |
sub2Ps.setPropertyValue(REFERENCE_PROPERTY, promotedName);
|
|
599 |
|
|
600 |
// sanity for listeners
|
|
601 |
assertEquals(root, rootListener.firedInstance);
|
|
602 |
assertEquals(REFERENCE_PROPERTY, rootListener.firedProperty);
|
|
603 |
assertEquals(sub2, sub2Listener.firedInstance);
|
|
604 |
assertEquals(REFERENCE_PROPERTY, sub2Listener.firedProperty);
|
|
605 |
assertNull(subListener.firedInstance);
|
|
606 |
assertNull(subListener.firedProperty);
|
|
607 |
|
|
608 |
rootListener.reset();
|
|
609 |
sub2Listener.reset();
|
|
610 |
|
|
611 |
// set on the root, and sub and child2 should know
|
|
612 |
rootPs.setPropertyValue("intValue", 23);
|
|
613 |
assertEquals(root, rootListener.firedInstance);
|
|
614 |
assertEquals(sub, subListener.firedInstance);
|
|
615 |
assertEquals(sub2, sub2Listener.firedInstance);
|
|
616 |
assertEquals("intValue", rootListener.firedProperty);
|
|
617 |
assertEquals("intValue", subListener.firedProperty);
|
|
618 |
assertEquals("intValue", sub2Listener.firedProperty);
|
|
619 |
rootListener.reset();
|
|
620 |
subListener.reset();
|
|
621 |
sub2Listener.reset();
|
|
622 |
|
|
623 |
// set on sub, and root and child2 should know
|
|
624 |
subPs.setPropertyValue("intValue", 23);
|
|
625 |
assertEquals(root, rootListener.firedInstance);
|
|
626 |
assertEquals(sub, subListener.firedInstance);
|
|
627 |
assertEquals(sub2, sub2Listener.firedInstance);
|
|
628 |
assertEquals("intValue", rootListener.firedProperty);
|
|
629 |
assertEquals("intValue", subListener.firedProperty);
|
|
630 |
assertEquals("intValue", sub2Listener.firedProperty);
|
|
631 |
|
|
632 |
// remove reference and make sure only one notification stops
|
|
633 |
rootPs.setPropertyValue(REFERENCE_PROPERTY, null);
|
|
634 |
|
|
635 |
rootListener.reset();
|
|
636 |
subListener.reset();
|
|
637 |
sub2Listener.reset();
|
|
638 |
|
|
639 |
subPs.setPropertyValue("intValue", 0);
|
|
640 |
assertNull(rootListener.firedInstance);
|
|
641 |
assertNull(rootListener.firedProperty);
|
|
642 |
assertEquals(sub, subListener.firedInstance);
|
|
643 |
assertEquals("intValue", subListener.firedProperty);
|
|
644 |
assertEquals(sub2, sub2Listener.firedInstance);
|
|
645 |
assertEquals("intValue", sub2Listener.firedProperty);
|
|
646 |
|
|
647 |
|
|
648 |
// and the other
|
|
649 |
sub2Ps.setPropertyValue(REFERENCE_PROPERTY, null);
|
|
650 |
|
|
651 |
rootListener.reset();
|
|
652 |
subListener.reset();
|
|
653 |
sub2Listener.reset();
|
|
654 |
|
|
655 |
subPs.setPropertyValue("intValue", 123);
|
|
656 |
assertNull(rootListener.firedInstance);
|
|
657 |
assertNull(rootListener.firedProperty);
|
|
658 |
assertEquals(sub, subListener.firedInstance);
|
|
659 |
assertEquals("intValue", subListener.firedProperty);
|
|
660 |
assertNull(sub2Listener.firedInstance);
|
|
661 |
assertNull(sub2Listener.firedProperty);
|
|
662 |
|
|
663 |
// and restore one
|
|
664 |
rootPs.setPropertyValue(REFERENCE_PROPERTY, promotedName);
|
|
665 |
|
|
666 |
subPs.setPropertyValue("intValue", 0);
|
|
667 |
assertNull(sub2Listener.firedInstance);
|
|
668 |
assertNull(sub2Listener.firedProperty);
|
|
669 |
assertEquals(sub, subListener.firedInstance);
|
|
670 |
assertEquals("intValue", subListener.firedProperty);
|
|
671 |
assertEquals(root, rootListener.firedInstance);
|
|
672 |
assertEquals("intValue", rootListener.firedProperty);
|
|
673 |
|
|
674 |
rootListener.reset();
|
|
675 |
subListener.reset();
|
|
676 |
sub2Listener.reset();
|
|
677 |
|
|
678 |
// restore the other
|
|
679 |
sub2Ps.setPropertyValue(REFERENCE_PROPERTY, promotedName);
|
|
680 |
|
|
681 |
// now delete the referent, which implicitly resets the references
|
|
682 |
List objectsToRemove = Collections.singletonList(sub);
|
|
683 |
Command command = model.createRemoveComponentInstancesCommand(objectsToRemove);
|
|
684 |
assertTrue(command.canExecute());
|
|
685 |
command.execute();
|
|
686 |
|
|
687 |
assertFalse(rootPs.isPropertySet("reference"));
|
|
688 |
assertFalse(sub2Ps.isPropertySet("reference"));
|
|
689 |
|
|
690 |
assertEquals(REFERENCE_PROPERTY, rootListener.firedProperty);
|
|
691 |
rootListener.reset();
|
|
692 |
}
|
|
693 |
|
|
694 |
/** Ensure that a normal reference property doesn't invoke
|
|
695 |
* property change events
|
|
696 |
*/
|
|
697 |
public void testNoListeningForNonPromotedProperties() {
|
|
698 |
EObject sub = addChild(root, "child");
|
|
699 |
IPropertySource rootPs = ModelUtils.getPropertySource(root);
|
|
700 |
IPropertySource subPs = ModelUtils.getPropertySource(sub);
|
|
701 |
|
|
702 |
IComponentInstance rootInstance = ModelUtils.getComponentInstance(root);
|
|
703 |
PropertyChangeListener rootListener = new PropertyChangeListener();
|
|
704 |
rootInstance.addPropertyListener(rootListener);
|
|
705 |
IComponentInstance subInstance = ModelUtils.getComponentInstance(sub);
|
|
706 |
PropertyChangeListener subListener = new PropertyChangeListener();
|
|
707 |
subInstance.addPropertyListener(subListener);
|
|
708 |
|
|
709 |
// wire them up
|
|
710 |
rootPs.setPropertyValue("plainReference", "child");
|
|
711 |
|
|
712 |
rootListener.reset();
|
|
713 |
|
|
714 |
// set on the root, and no one else should know
|
|
715 |
rootPs.setPropertyValue("another", "lala");
|
|
716 |
assertEquals(root, rootListener.firedInstance);
|
|
717 |
assertEquals("another", rootListener.firedProperty);
|
|
718 |
assertNull(subListener.firedInstance);
|
|
719 |
assertNull(subListener.firedProperty);
|
|
720 |
rootListener.reset();
|
|
721 |
subListener.reset();
|
|
722 |
|
|
723 |
// set on the child, and no one else should know
|
|
724 |
subPs.setPropertyValue("stringValue", "lala");
|
|
725 |
assertEquals(sub, subListener.firedInstance);
|
|
726 |
assertEquals("stringValue", subListener.firedProperty);
|
|
727 |
assertNull(rootListener.firedInstance);
|
|
728 |
assertNull(rootListener.firedProperty);
|
|
729 |
rootListener.reset();
|
|
730 |
subListener.reset();
|
|
731 |
|
|
732 |
|
|
733 |
}
|
|
734 |
}
|