summaryrefslogtreecommitdiffstats
blob: ba7497b39a8848c10153c29a847a60eb9e2c1a52 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/***************************************************************************
 * Copyright (c) 2004, 2005, 2006 Eike Stepper, Germany.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *    Eike Stepper - initial API and implementation
 **************************************************************************/
package org.eclipse.emf.cdo.tests.model1;


import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.util.EContentsEList.FeatureListIterator;

import testmodel1.TestModel1Package;
import testmodel1.TreeNode;
import junit.framework.ComparisonFailure;


public class XRefsTest extends AbstractModel1Test
{
  public void testList() throws Exception
  {
    final String RESOURCE1 = "/test/res1";
    final String RESOURCE2 = "/test/res2";
    final String ROOT1 = "root1";
    final String ROOT2 = "root2";
    final String CHILD2 = "child2";

    { // Execution
      TreeNode root1 = createNode(ROOT1);
      saveRoot(root1, RESOURCE1);

      TreeNode root2 = createNode(ROOT2);
      root2.getReferences().add(root1);

      TreeNode child2 = createNode(CHILD2, root2);
      child2.getReferences().add(root1);
      saveRoot(root2, RESOURCE2);
    }

    { // Verification
      TreeNode root1 = (TreeNode) loadRoot(RESOURCE1);
      EList list = root1.eCrossReferences();
      assertNotNull(list);
      assertEquals(2, list.size());

      try
      {
        assertNode(ROOT2, (TreeNode) list.get(0));
        assertNode(CHILD2, (TreeNode) list.get(1));
      }
      catch (ComparisonFailure ex)
      {
        assertNode(ROOT2, (TreeNode) list.get(1));
        assertNode(CHILD2, (TreeNode) list.get(0));
      }
    }
  }

  public void testIterator() throws Exception
  {
    final String RESOURCE1 = "/test/res1";
    final String RESOURCE2 = "/test/res2";
    final String ROOT1 = "root1";
    final String ROOT2 = "root2";
    final String CHILD2 = "child2";

    { // Execution
      TreeNode root1 = createNode(ROOT1);
      saveRoot(root1, RESOURCE1);

      TreeNode root2 = createNode(ROOT2);
      root2.getReferences().add(root1);

      TreeNode child2 = createNode(CHILD2, root2);
      child2.getReferences().add(root1);
      saveRoot(root2, RESOURCE2);
    }

    { // Verification
      TreeNode root1 = (TreeNode) loadRoot(RESOURCE1);
      EList list = root1.eCrossReferences();
      int count = 0;

      for (FeatureListIterator it = (FeatureListIterator) list.iterator(); it.hasNext();)
      {
        count++;
        TreeNode node = (TreeNode) it.next();
        assertTrue(ROOT2.equals(node.getStringFeature()) || CHILD2.equals(node.getStringFeature()));

        EReference reference = (EReference) it.feature();
        assertEquals(TestModel1Package.eINSTANCE.getTreeNode_References(), reference);
      }

      assertEquals(2, count);
    }
  }
}