Skip to main content
summaryrefslogtreecommitdiffstats
blob: bd6d6d5bf8801e7ab022da95b16c60477ea864c3 (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
/*
 * Copyright (c) 2004 - 2012 Esteban Dugueperoux (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:
 *    Esteban Dugueperoux - initial API and implementation
 *    Christian W. Damus (CEA) - adapted to ensure clear separation of native and legacy models
 */
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.model6.CanReferenceLegacy;
import org.eclipse.emf.cdo.transaction.CDOTransaction;

import org.eclipse.emf.ecore.EAnnotation;
import org.eclipse.emf.ecore.EcoreFactory;

import java.util.Arrays;

/**
 * Bug 400236.
 *
 * @author Esteban Dugueperoux
 */
public class Bugzilla_400236_Test extends AbstractCDOTest
{
  public void testCommit() throws Exception
  {
    CDOSession session = openSession();
    CDOTransaction transaction = session.openTransaction();
    CDOResource resourceA = transaction.createResource(getResourcePath("test1"));
    CDOResource resourceB = transaction.createResource(getResourcePath("test2"));

    CanReferenceLegacy ref1 = getModel6Factory().createCanReferenceLegacy();
    EAnnotation annot1 = EcoreFactory.eINSTANCE.createEAnnotation(); // Legacy object
    annot1.setSource("annot1");
    ref1.setSingleContainment(annot1);
    EAnnotation annot2 = EcoreFactory.eINSTANCE.createEAnnotation(); // Legacy object
    annot2.setSource("annot2");
    ref1.getMultipleContainment().add(annot2);

    CanReferenceLegacy ref2 = getModel6Factory().createCanReferenceLegacy();
    ref2.setSingleReference(annot1);
    ref2.getMultipleReference().add(annot2);

    resourceA.getContents().add(ref1);
    resourceB.getContents().add(ref2);
    transaction.commit();
    session.close();

    session = openSession();
    transaction = session.openTransaction();
    resourceA = transaction.getResource(getResourcePath("test1"));
    resourceB = transaction.getResource(getResourcePath("test2"));
    ref1 = (CanReferenceLegacy)resourceA.getContents().get(0);
    ref2 = (CanReferenceLegacy)resourceB.getContents().get(0);

    annot1 = transaction.getObject(annot1);
    annot2 = transaction.getObject(annot2);

    EAnnotation annot3 = EcoreFactory.eINSTANCE.createEAnnotation();
    annot3.setSource("annot3");

    ref1.getMultipleContainment().add(annot3);
    ref2.getMultipleReference().add(annot3);

    assertSame(annot1, ref2.getSingleReference());
    assertSame(ref1.getSingleContainment(), ref2.getSingleReference());
    assertEquals(Arrays.asList(annot2, annot3), ref2.getMultipleReference());
    assertEquals(ref1.getMultipleContainment(), ref2.getMultipleReference());
  }
}

Back to the top