Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 440dc9120195a3fd1c637cc5994de7e175b9338d (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
/*
 * Copyright (c) 2011, 2012 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.config.IModelConfig;
import org.eclipse.emf.cdo.tests.model1.Category;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
import org.eclipse.emf.cdo.util.CommitException;

import org.eclipse.emf.ecore.EObject;

import java.util.HashSet;
import java.util.Set;

/**
 * @author Caspar De Groot
 */
public class Bugzilla_343471_Test extends AbstractCDOTest
{
  @Skips(IModelConfig.CAPABILITY_LEGACY)
  public void test() throws CommitException
  {
    CDOSession session = openSession();
    CDOTransaction tx = session.openTransaction();

    CDOResource resource1 = tx.createResource(getResourcePath("test1"));
    CDOResource resource2 = tx.createResource(getResourcePath("test2"));

    Category c1 = getModel1Factory().createCategory();
    resource1.getContents().add(c1);

    Category c2 = getModel1Factory().createCategory();
    c1.getCategories().add(c2);

    // c3 serves only to make the later commit partial
    Category c3 = getModel1Factory().createCategory();
    resource2.getContents().add(c3);

    tx.commit();

    msg("c1 = " + c1);
    msg("c2 = " + c2);
    msg("c3 = " + c3);

    msg("resource1 = " + resource1);
    msg("resource2 = " + resource2);

    msg("");
    msg("c1's container? " + c1.eContainer());
    msg("c2 contained in c1? " + c1.getCategories().contains(c2));
    msg("c2 contained in c1? " + (c2.eContainer() == c1));
    msg("c2's resource is r2? " + (c2.eResource() == resource2));

    // Move c2 from resource1 to resource2
    resource2.getContents().add(c2);

    // assertSame(c1, c2.eContainer());

    msg("");
    msg("c1's container? " + c1.eContainer());
    msg("c2 contained in c1? " + c1.getCategories().contains(c2));
    msg("c2 contained in c1? " + (c2.eContainer() == c1));
    msg("c2's resource is r2? " + (c2.eResource() == resource2));

    // Make c3 dirty so that we can create a partial commit
    c3.setName("X");

    Set<EObject> committables = new HashSet<EObject>();
    committables.add(c2);
    committables.add(resource2);

    tx.setCommittables(committables);
    tx.commit();

    session.close();
  }
}

Back to the top