Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: a125d43b7a694f91b56caa955bf655deffdbe58d (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
/*
 * Copyright (c) 2012, 2013 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:
 *    Stefan Winkler - initial API and implementation
 */
package org.eclipse.emf.cdo.tests.bugzilla;

import org.eclipse.emf.cdo.common.branch.CDOBranch;
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.IRepositoryConfig;
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.cdo.util.CDOUtil;
import org.eclipse.emf.cdo.util.CommitException;

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

/**
 * @author Stefan Winkler
 */
public class Bugzilla_370105_Test extends AbstractCDOTest
{
  @Requires(IRepositoryConfig.CAPABILITY_BRANCHING)
  @CleanRepositoriesBefore(reason = "to not be disturb by branches created by other tests")
  public void testInsertInListOf5thSubBranch() throws Throwable
  {
    Company company = initModel();

    CDOTransaction transaction = (CDOTransaction)CDOUtil.getCDOObject(company).cdoView();

    // Create 5 cascading branches
    CDOBranch parent = transaction.getBranch();
    for (int i = 0; i < 3; i++)
    {
      CDOBranch child = parent.createBranch("Branch-" + i);
      parent = child;
    }

    int branchId = parent.getID();

    // touch company in every branch
    CDOBranch branch = transaction.getBranch();
    for (int i = 0; i < 3; i++)
    {
      CDOTransaction tx2 = transaction.getSession().openTransaction(branch);
      CDOResource resource = tx2.getResource(getResourcePath("res"));
      Company c = (Company)resource.getContents().get(0);
      c.setName("Test-" + i);
      tx2.commit();
      tx2.close();
      branch = branch.getBranches()[0];
    }

    clearCache(getRepository().getRevisionManager());

    CDOSession readSession = openSession();
    CDOBranch readBranch = readSession.getBranchManager().getBranch(branchId);

    // add category to each company
    for (int i = 0; i < 3; i++)
    {
      CDOTransaction transaction2 = readSession.openTransaction(readBranch);
      Category c = getModel1Factory().createCategory();
      c.setName("New");

      Company companyTx = transaction2.getObject(company);
      EList<Category> categories = companyTx.getCategories();
      categories.add(0, c);
      transaction2.commit();
      readBranch = readBranch.getBase().getBranch();
      transaction2.close();
    }
  }

  private Company initModel() throws CommitException
  {
    msg("Initializing model ...");
    CDOSession session = openSession();
    CDOTransaction transaction = session.openTransaction();
    CDOResource resource = transaction.createResource(getResourcePath("res"));

    Company company = getModel1Factory().createCompany();
    resource.getContents().add(company);

    for (int i = 0; i < 5; i++)
    {
      Category cat = getModel1Factory().createCategory();
      cat.setName(Integer.toString(i));
      company.getCategories().add(cat);
    }

    transaction.commit();

    return company;
  }
}

Back to the top