Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 867a34f544f279dcae613acacdfdde805627995e (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
/*
 * Copyright (c) 2010-2012, 2016 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:
 *    Martin Fluegge - initial API and implementation
 *    Eike Stepper - maintenance
 */
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.model1.Company;
import org.eclipse.emf.cdo.tests.model1.Order;
import org.eclipse.emf.cdo.tests.model1.OrderDetail;
import org.eclipse.emf.cdo.transaction.CDOTransaction;

import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;

/**
 * unset of CDO does not work correctly
 * <p>
 * See bug 302233
 *
 * @author Martin Fluegge
 */
public class Bugzilla_302233_Test extends AbstractCDOTest
{
  public void testUnset() throws Exception
  {
    Order order = getModel1Factory().createPurchaseOrder();
    EStructuralFeature feature = getModel1Package().getOrder_OrderDetails();
    assertEquals(false, order.eIsSet(feature));

    order.eUnset(feature);

    for (int i = 0; i < 10; i++)
    {
      OrderDetail orderDetail = getModel1Factory().createOrderDetail();
      order.getOrderDetails().add(orderDetail);
    }

    order.eUnset(feature);

    CDOSession session = openSession();
    session.getPackageRegistry().putEPackage(getModel1Package());

    CDOTransaction transaction = session.openTransaction();
    CDOResource resource = transaction.createResource(getResourcePath("/test1"));
    resource.getContents().add(order);

    for (int i = 0; i < 10; i++)
    {
      OrderDetail orderDetail = getModel1Factory().createOrderDetail();
      order.getOrderDetails().add(orderDetail);
    }

    transaction.commit();

    order.eUnset(feature);
    assertEquals(false, order.eIsSet(getModel1Package().getOrder_OrderDetails()));

    session.close();
  }

  public void testUnset2() throws Exception
  {
    EReference feature = getModel1Package().getCompany_Categories();
    Company company = getModel1Factory().createCompany();

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

    company.getCategories().add(getModel1Factory().createCategory());
    company.getCategories().add(getModel1Factory().createCategory());
    company.getCategories().add(getModel1Factory().createCategory());
    company.getCategories().add(getModel1Factory().createCategory());

    company.eUnset(feature);
    assertEquals(false, company.eIsSet(feature));

    transaction.commit();
    session.close();
  }

  public void testRemove() throws Exception
  {
    CDOSession session = openSession();
    CDOTransaction transaction = session.openTransaction();
    CDOResource resource = transaction.createResource(getResourcePath("/test1"));
    resource.getContents().add(getModel1Factory().createCompany());
    resource.getContents().add(getModel1Factory().createCompany());
    resource.getContents().add(getModel1Factory().createCompany());
    resource.getContents().add(getModel1Factory().createCompany());

    resource.getContents().remove(3);
    resource.getContents().remove(2);
    resource.getContents().remove(1);
    resource.getContents().remove(0);

    transaction.commit();
    session.close();
  }
}

Back to the top