Skip to main content
summaryrefslogtreecommitdiffstats
blob: a84afa4d9f1a657ba80e835b400d5d35df06401b (plain) (blame)
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/**
 * Copyright (c) 2004 - 2009 Eike Stepper (Berlin, Germany) and others.
 * 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:
 *    Caspar De Groot - initial API and implementation
 */
package org.eclipse.emf.cdo.tests.bugzilla;

import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.session.CDOSession;
import org.eclipse.emf.cdo.tests.AbstractCDOTest;
import org.eclipse.emf.cdo.tests.model4.MultiNonContainedUnsettableElement;
import org.eclipse.emf.cdo.tests.model4.RefMultiNonContainedUnsettable;
import org.eclipse.emf.cdo.tests.model4.model4Factory;
import org.eclipse.emf.cdo.tests.model4.model4Package;
import org.eclipse.emf.cdo.transaction.CDOTransaction;

/**
 * @author Caspar De Groot
 */
public class Bugzilla_285008_Test extends AbstractCDOTest
{
  private static String RESOURCENAME = "/r1";

  public void testCDO_isSet()
  {
    {
      CDOSession session = openSession();
      model4Package p = model4Package.eINSTANCE;
      session.getPackageRegistry().putEPackage(p);
      session.options().setPassiveUpdateEnabled(false);
      model4Factory f = model4Factory.eINSTANCE;

      // Ensure that model is suitable for this test
      boolean p1 = p.getRefMultiNonContainedUnsettable_Elements().isMany();
      boolean p2 = p.getRefMultiNonContainedUnsettable_Elements().isUnsettable();
      boolean p3 = !p.getMultiNonContainedUnsettableElement_Parent().isMany();
      boolean p4 = p.getMultiNonContainedUnsettableElement_Parent().isUnsettable();
      boolean p5 = p.getRefMultiNonContainedUnsettable_Elements().getEOpposite() == p
          .getMultiNonContainedUnsettableElement_Parent();
      if (!p1 || !p2 || !p3 || !p4 || !p5)
      {
        throw new RuntimeException("Model does not meet the prerequirements for this test");
      }

      CDOTransaction tx = session.openTransaction();
      CDOResource r1 = tx.createResource(RESOURCENAME);
      RefMultiNonContainedUnsettable a = f.createRefMultiNonContainedUnsettable();
      MultiNonContainedUnsettableElement b = f.createMultiNonContainedUnsettableElement();
      r1.getContents().add(a);
      r1.getContents().add(b);
      a.getElements().add(b);

      assertTrue(a.isSetElements());

      tx.commit();

      assertTrue(a.isSetElements());

      tx.close();
      session.close();
    }

    // Same tests on isSetElements, but in a new session
    {
      CDOSession session = openSession();
      model4Package p = model4Package.eINSTANCE;
      session.getPackageRegistry().putEPackage(p);
      session.options().setPassiveUpdateEnabled(false);
      CDOTransaction tx = session.openTransaction();

      CDOResource r1 = tx.getResource(RESOURCENAME);
      RefMultiNonContainedUnsettable a = (RefMultiNonContainedUnsettable)r1.getContents().get(0);

      assertTrue(a.isSetElements());

      tx.close();
      session.close();
    }
  }

  public void testCDO_crossReferences()
  {
    {
      CDOSession session = openSession();
      model4Package p = model4Package.eINSTANCE;
      session.getPackageRegistry().putEPackage(p);
      session.options().setPassiveUpdateEnabled(false);
      model4Factory f = model4Factory.eINSTANCE;

      // Ensure that model is suitable for this test
      boolean p1 = p.getRefMultiNonContainedUnsettable_Elements().isMany();
      boolean p2 = p.getRefMultiNonContainedUnsettable_Elements().isUnsettable();
      boolean p3 = !p.getMultiNonContainedUnsettableElement_Parent().isMany();
      boolean p4 = p.getMultiNonContainedUnsettableElement_Parent().isUnsettable();
      boolean p5 = p.getRefMultiNonContainedUnsettable_Elements().getEOpposite() == p
          .getMultiNonContainedUnsettableElement_Parent();
      if (!p1 || !p2 || !p3 || !p4 || !p5)
      {
        throw new RuntimeException("Model does not meet the prerequirements for this test");
      }

      CDOTransaction tx = session.openTransaction();
      CDOResource r1 = tx.createResource(RESOURCENAME);
      RefMultiNonContainedUnsettable a = f.createRefMultiNonContainedUnsettable();
      MultiNonContainedUnsettableElement b = f.createMultiNonContainedUnsettableElement();
      r1.getContents().add(a);
      r1.getContents().add(b);
      a.getElements().add(b);
      tx.commit();

      assertEquals(1, a.eCrossReferences().size());
      assertSame(b, a.eCrossReferences().get(0));

      assertEquals(1, b.eCrossReferences().size());
      assertSame(a, b.eCrossReferences().get(0));

      tx.close();
      session.close();
    }

    // Same tests on eCrossReferences, but in a new session
    {
      CDOSession session = openSession();
      model4Package p = model4Package.eINSTANCE;
      session.getPackageRegistry().putEPackage(p);
      session.options().setPassiveUpdateEnabled(false);
      CDOTransaction tx = session.openTransaction();

      CDOResource r1 = tx.getResource(RESOURCENAME);
      RefMultiNonContainedUnsettable a = (RefMultiNonContainedUnsettable)r1.getContents().get(0);
      MultiNonContainedUnsettableElement b = (MultiNonContainedUnsettableElement)r1.getContents().get(1);

      assertEquals(1, a.eCrossReferences().size());
      assertSame(b, a.eCrossReferences().get(0));

      assertEquals(1, b.eCrossReferences().size());
      assertSame(a, b.eCrossReferences().get(0));

      tx.close();
      session.close();
    }
  }
}

Back to the top