Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 333e6a9f70516e030c5821ca29a92934668d1198 (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
/*
 * Copyright (c) 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:
 *    Eike Stepper - 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.IConfig;
import org.eclipse.emf.cdo.tests.model1.Category;
import org.eclipse.emf.cdo.tests.model1.Company;
import org.eclipse.emf.cdo.transaction.CDOTransaction;

import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;

/**
 * Problem with resource after transaction rollback
 * <p>
 * See bug 383370
 *
 * @author Eike Stepper
 */
public class Bugzilla_383370_Test extends AbstractCDOTest
{
  @Skips(IConfig.EFFORT_MERGING)
  public void testTopLevel() throws Exception
  {
    Category category = getModel1Factory().createCategory();

    CDOSession session = openSession();
    CDOTransaction transaction = session.openTransaction();
    CDOResource resource = transaction.createResource(getResourcePath("test1"));
    transaction.commit();

    EList<EObject> contents = resource.getContents();
    contents.add(category);
    assertEquals(1, contents.size());
    assertEquals(resource, category.eResource());

    transaction.rollback();
    assertEquals(0, contents.size());
    assertEquals(null, category.eResource());

    contents.add(category);
    assertEquals(1, contents.size());
    assertEquals(resource, category.eResource());
  }

  @Skips(IConfig.EFFORT_MERGING)
  public void testTopLevelWithChildren() throws Exception
  {
    Category category = getModel1Factory().createCategory();
    Category child = getModel1Factory().createCategory();
    category.getCategories().add(child);

    CDOSession session = openSession();
    CDOTransaction transaction = session.openTransaction();
    CDOResource resource = transaction.createResource(getResourcePath("test1"));
    transaction.commit();

    EList<EObject> contents = resource.getContents();
    contents.add(category);
    assertEquals(1, contents.size());
    assertEquals(resource, category.eResource());
    assertEquals(category, child.eContainer());

    transaction.rollback();
    assertEquals(0, contents.size());
    assertEquals(null, category.eResource());
    assertEquals(category, child.eContainer());

    contents.add(category);
    assertEquals(1, contents.size());
    assertEquals(resource, category.eResource());
    assertEquals(category, child.eContainer());
  }

  @Skips(IConfig.EFFORT_MERGING)
  public void testSecondLevel() throws Exception
  {
    Company company = getModel1Factory().createCompany();
    Category category = getModel1Factory().createCategory();

    CDOSession session = openSession();
    CDOTransaction transaction = session.openTransaction();
    CDOResource resource = transaction.createResource(getResourcePath("test1"));
    resource.getContents().add(company);
    transaction.commit();

    EList<Category> categories = company.getCategories();
    categories.add(category);
    assertEquals(1, categories.size());
    assertEquals(company, category.eContainer());

    transaction.rollback();
    assertEquals(0, categories.size());
    assertEquals(null, category.eContainer());

    categories.add(category);
    assertEquals(1, categories.size());
    assertEquals(company, category.eContainer());
  }

  @Skips(IConfig.EFFORT_MERGING)
  public void testSecondLevelWithChildren() throws Exception
  {
    Company company = getModel1Factory().createCompany();
    Category category = getModel1Factory().createCategory();
    Category child = getModel1Factory().createCategory();
    category.getCategories().add(child);

    CDOSession session = openSession();
    CDOTransaction transaction = session.openTransaction();
    CDOResource resource = transaction.createResource(getResourcePath("test1"));
    resource.getContents().add(company);
    transaction.commit();

    EList<Category> categories = company.getCategories();
    categories.add(category);
    assertEquals(1, categories.size());
    assertEquals(company, category.eContainer());
    assertEquals(category, child.eContainer());

    transaction.rollback();
    assertEquals(0, categories.size());
    assertEquals(null, category.eContainer());
    assertEquals(category, child.eContainer());

    categories.add(category);
    assertEquals(1, categories.size());
    assertEquals(company, category.eContainer());
    assertEquals(category, child.eContainer());
  }
}

Back to the top