uidesigner/com.nokia.sdt.emf.dm.tests/src/com/nokia/sdt/emf/dm/tests/INodeTest.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>
cawthron
parents:
diff changeset
     3
 * </copyright>
cawthron
parents:
diff changeset
     4
 *
cawthron
parents:
diff changeset
     5
 * $Id$
cawthron
parents:
diff changeset
     6
 */
cawthron
parents:
diff changeset
     7
package com.nokia.sdt.emf.dm.tests;
cawthron
parents:
diff changeset
     8
cawthron
parents:
diff changeset
     9
import com.nokia.sdt.emf.dm.DmFactory;
cawthron
parents:
diff changeset
    10
import com.nokia.sdt.emf.dm.INode;
cawthron
parents:
diff changeset
    11
cawthron
parents:
diff changeset
    12
import com.nokia.sdt.emf.dm.*;
cawthron
parents:
diff changeset
    13
import com.nokia.sdt.emf.dm.impl.ValidatingEObjectContainmentEList;
cawthron
parents:
diff changeset
    14
cawthron
parents:
diff changeset
    15
import org.eclipse.emf.common.notify.Notification;
cawthron
parents:
diff changeset
    16
import org.eclipse.emf.common.notify.impl.AdapterImpl;
cawthron
parents:
diff changeset
    17
import org.eclipse.emf.common.util.EList;
cawthron
parents:
diff changeset
    18
cawthron
parents:
diff changeset
    19
import junit.framework.TestCase;
cawthron
parents:
diff changeset
    20
import junit.textui.TestRunner;
cawthron
parents:
diff changeset
    21
cawthron
parents:
diff changeset
    22
/**
cawthron
parents:
diff changeset
    23
 * <!-- begin-user-doc -->
cawthron
parents:
diff changeset
    24
 * A test case for the model object '<em><b>INode</b></em>'.
cawthron
parents:
diff changeset
    25
 * <!-- end-user-doc -->
cawthron
parents:
diff changeset
    26
 * @generated
cawthron
parents:
diff changeset
    27
 */
cawthron
parents:
diff changeset
    28
public class INodeTest extends TestCase {
cawthron
parents:
diff changeset
    29
	/**
cawthron
parents:
diff changeset
    30
	 * The fixture for this INode test case.
cawthron
parents:
diff changeset
    31
	 * <!-- begin-user-doc -->
cawthron
parents:
diff changeset
    32
	 * <!-- end-user-doc -->
cawthron
parents:
diff changeset
    33
	 * @generated
cawthron
parents:
diff changeset
    34
	 */
cawthron
parents:
diff changeset
    35
	protected INode fixture = null;
cawthron
parents:
diff changeset
    36
cawthron
parents:
diff changeset
    37
	/**
cawthron
parents:
diff changeset
    38
	 * <!-- begin-user-doc -->
cawthron
parents:
diff changeset
    39
	 * <!-- end-user-doc -->
cawthron
parents:
diff changeset
    40
	 * @generated
cawthron
parents:
diff changeset
    41
	 */
cawthron
parents:
diff changeset
    42
	public static void main(String[] args) {
cawthron
parents:
diff changeset
    43
		TestRunner.run(INodeTest.class);
cawthron
parents:
diff changeset
    44
	}
cawthron
parents:
diff changeset
    45
cawthron
parents:
diff changeset
    46
	/**
cawthron
parents:
diff changeset
    47
	 * Constructs a new INode test case with the given name.
cawthron
parents:
diff changeset
    48
	 * <!-- begin-user-doc -->
cawthron
parents:
diff changeset
    49
	 * <!-- end-user-doc -->
cawthron
parents:
diff changeset
    50
	 * @generated
cawthron
parents:
diff changeset
    51
	 */
cawthron
parents:
diff changeset
    52
	public INodeTest(String name) {
cawthron
parents:
diff changeset
    53
		super(name);
cawthron
parents:
diff changeset
    54
	}
cawthron
parents:
diff changeset
    55
cawthron
parents:
diff changeset
    56
	/**
cawthron
parents:
diff changeset
    57
	 * Sets the fixture for this INode test case.
cawthron
parents:
diff changeset
    58
	 * <!-- begin-user-doc -->
cawthron
parents:
diff changeset
    59
	 * <!-- end-user-doc -->
cawthron
parents:
diff changeset
    60
	 * @generated
cawthron
parents:
diff changeset
    61
	 */
cawthron
parents:
diff changeset
    62
	protected void setFixture(INode fixture) {
cawthron
parents:
diff changeset
    63
		this.fixture = fixture;
cawthron
parents:
diff changeset
    64
	}
cawthron
parents:
diff changeset
    65
cawthron
parents:
diff changeset
    66
	/**
cawthron
parents:
diff changeset
    67
	 * Returns the fixture for this INode test case.
cawthron
parents:
diff changeset
    68
	 * <!-- begin-user-doc -->
cawthron
parents:
diff changeset
    69
	 * <!-- end-user-doc -->
cawthron
parents:
diff changeset
    70
	 * @generated
cawthron
parents:
diff changeset
    71
	 */
cawthron
parents:
diff changeset
    72
	private INode getFixture() {
cawthron
parents:
diff changeset
    73
		return fixture;
cawthron
parents:
diff changeset
    74
	}
cawthron
parents:
diff changeset
    75
cawthron
parents:
diff changeset
    76
	/**
cawthron
parents:
diff changeset
    77
	 * <!-- begin-user-doc -->
cawthron
parents:
diff changeset
    78
	 * <!-- end-user-doc -->
cawthron
parents:
diff changeset
    79
	 * @see junit.framework.TestCase#setUp()
cawthron
parents:
diff changeset
    80
	 * @generated
cawthron
parents:
diff changeset
    81
	 */
cawthron
parents:
diff changeset
    82
	protected void setUp() throws Exception {
cawthron
parents:
diff changeset
    83
		setFixture(DmFactory.eINSTANCE.createINode());
cawthron
parents:
diff changeset
    84
	}
cawthron
parents:
diff changeset
    85
cawthron
parents:
diff changeset
    86
	/**
cawthron
parents:
diff changeset
    87
	 * <!-- begin-user-doc -->
cawthron
parents:
diff changeset
    88
	 * <!-- end-user-doc -->
cawthron
parents:
diff changeset
    89
	 * @see junit.framework.TestCase#tearDown()
cawthron
parents:
diff changeset
    90
	 * @generated
cawthron
parents:
diff changeset
    91
	 */
cawthron
parents:
diff changeset
    92
	protected void tearDown() throws Exception {
cawthron
parents:
diff changeset
    93
		setFixture(null);
cawthron
parents:
diff changeset
    94
	}
cawthron
parents:
diff changeset
    95
cawthron
parents:
diff changeset
    96
	class TestListener extends AdapterImpl {
cawthron
parents:
diff changeset
    97
		
cawthron
parents:
diff changeset
    98
		int changeCount;
cawthron
parents:
diff changeset
    99
cawthron
parents:
diff changeset
   100
		public void notifyChanged(Notification msg) {
cawthron
parents:
diff changeset
   101
			++changeCount;
cawthron
parents:
diff changeset
   102
		}	
cawthron
parents:
diff changeset
   103
	}
cawthron
parents:
diff changeset
   104
	
cawthron
parents:
diff changeset
   105
	public void testGetChildrenList() {
cawthron
parents:
diff changeset
   106
		INode node = getFixture();
cawthron
parents:
diff changeset
   107
		EList children = node.getChildren();
cawthron
parents:
diff changeset
   108
		assertTrue(children instanceof ValidatingEObjectContainmentEList);
cawthron
parents:
diff changeset
   109
	}
cawthron
parents:
diff changeset
   110
	
cawthron
parents:
diff changeset
   111
	public void testNoFireOnGet() {
cawthron
parents:
diff changeset
   112
		// regression test that getting a property does not fire a property changed event
cawthron
parents:
diff changeset
   113
		INode node = getFixture();
cawthron
parents:
diff changeset
   114
		
cawthron
parents:
diff changeset
   115
		StringValue value = new StringValue(StringValue.LITERAL, "foo");
cawthron
parents:
diff changeset
   116
		node.getProperties().set("name", value);
cawthron
parents:
diff changeset
   117
	
cawthron
parents:
diff changeset
   118
		TestListener listener = new TestListener();
cawthron
parents:
diff changeset
   119
		node.eAdapters().add(listener);
cawthron
parents:
diff changeset
   120
		
cawthron
parents:
diff changeset
   121
		Object value2 = node.getProperties().get("name");
cawthron
parents:
diff changeset
   122
		assertEquals(value, value2);
cawthron
parents:
diff changeset
   123
		assertTrue(listener.changeCount == 0);
cawthron
parents:
diff changeset
   124
	}
cawthron
parents:
diff changeset
   125
cawthron
parents:
diff changeset
   126
} //INodeTest