Skip to main content
summaryrefslogtreecommitdiffstats
blob: 5649557d3b3597f6e0addca657a9d305be988869 (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
149
/*
 * Copyright (c) 2004 - 2011 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.model1.Order;
import org.eclipse.emf.cdo.tests.model1.OrderDetail;
import org.eclipse.emf.cdo.transaction.CDOTransaction;

/**
 * Bugzilla 293283/314387 - Failed writes on CDOObjects leave bad featureDeltas in transaction
 * 
 * @author Caspar De Groot
 */
public class Bugzilla_293283_Test extends AbstractCDOTest
{
  private CDOSession session;

  private CDOTransaction tx;

  private Order order1;

  @Override
  public void setUp() throws Exception
  {
    super.setUp();

    session = openSession();
    tx = session.openTransaction();
    CDOResource r1 = tx.getOrCreateResource(getResourcePath("/r1")); //$NON-NLS-1$
    r1.getContents().clear();

    order1 = getModel1Factory().createPurchaseOrder();
    OrderDetail detail1 = getModel1Factory().createOrderDetail();
    OrderDetail detail2 = getModel1Factory().createOrderDetail();
    order1.getOrderDetails().add(detail1);
    order1.getOrderDetails().add(detail2);
    r1.getContents().add(order1);
    tx.commit();
  }

  @Override
  public void tearDown() throws Exception
  {
    tx.close();
    session.close();

    super.tearDown();
  }

  public void test1()
  {
    test(Action.ADD);
  }

  public void test2()
  {
    test(Action.SET);
  }

  public void test3()
  {
    test(Action.MOVE1);
  }

  public void test4()
  {
    test(Action.MOVE2);
  }

  public void test5()
  {
    test(Action.REMOVE1);
  }

  public void test6()
  {
    test(Action.REMOVE2);
  }

  private void test(Action action)
  {
    try
    {
      switch (action)
      {
      case ADD:
      {
        OrderDetail newDetail = getModel1Factory().createOrderDetail();
        order1.getOrderDetails().add(3, newDetail);
        break;
      }

      case MOVE1:
        order1.getOrderDetails().move(0, 3);
        break;

      case MOVE2:
        order1.getOrderDetails().move(3, 0);
        break;

      case REMOVE1:
        order1.getOrderDetails().remove(3);
        break;

      case REMOVE2:
        order1.getOrderDetails().remove(-1);
        break;

      case SET:
      {
        OrderDetail newDetail = getModel1Factory().createOrderDetail();
        order1.getOrderDetails().set(3, newDetail);
        break;
      }
      }

      fail("Should have thrown " + IndexOutOfBoundsException.class.getSimpleName()); //$NON-NLS-1$
    }
    catch (IndexOutOfBoundsException ex)
    {
      // Good
    }

    try
    {
      tx.commit();
    }
    catch (Exception e)
    {
      fail("Should have committed cleanly, but failed with " + e.getClass().getName() + "\n" + e.getMessage());
    }
  }

  private enum Action
  {
    ADD, MOVE1, MOVE2, REMOVE1, REMOVE2, SET
  }
}

Back to the top