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