Skip to main content
summaryrefslogtreecommitdiffstats
blob: a96b9db166894fc3fc69e877cb0844679346c9e1 (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
/*
 * Copyright (c) 2017 Obeo.
 * 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:
 *    Maxime Porhel (Obeo) - 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.config.impl.ConfigTest.CleanRepositoriesBefore;
import org.eclipse.emf.cdo.tests.config.impl.ConfigTest.Requires;
import org.eclipse.emf.cdo.tests.model1.Company;
import org.eclipse.emf.cdo.tests.model1.Supplier;
import org.eclipse.emf.cdo.transaction.CDOTransaction;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EcoreFactory;
import org.eclipse.emf.ecore.util.EContentAdapter;

/**
 * Bug 516824: Multiple revision instances are loaded during branch switch.
 *
 * @author Maxime Porhel (Obeo)
 */
@CleanRepositoriesBefore(reason = "because")
@Requires(IRepositoryConfig.CAPABILITY_BRANCHING)
public class Bugzilla_516824_Test extends AbstractCDOTest
{
  /**
   * Ensure that there is no ClassCastException thrown during the branch switching.
   */
  @Requires(IRepositoryConfig.CAPABILITY_BRANCHING)
  public void testSetBranch() throws Exception
  {
    CDOSession session = openSession();
    CDOTransaction transaction = session.openTransaction();

    Supplier supplier = getModel1Factory().createSupplier();
    supplier.setName("s0");
    // supplier.setPreferred(false); default value

    Company company = getModel1Factory().createCompany();
    company.setName("c0");
    company.getSuppliers().add(supplier);

    CDOResource resource = transaction.createResource("newResource.company");
    resource.getContents().add(company);

    transaction.commit();

    // Make sure invalidation will trigger delta notifications
    resource.eAdapters().add(new EContentAdapter());

    CDOBranch subBranch = transaction.getBranch().createBranch("subBranch");
    transaction.setBranch(subBranch);
  }

  @Requires(IRepositoryConfig.CAPABILITY_BRANCHING)
  public void testSetBranchLegacy() throws Exception
  {
    CDOSession session = openSession();
    CDOTransaction transaction = session.openTransaction();

    CDOResource resource = transaction.createResource("newResource.ecore");
    EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage();
    EClass eClass = EcoreFactory.eINSTANCE.createEClass();

    ePackage.setName("p0");
    eClass.setName("c0");

    resource.getContents().add(ePackage);
    ePackage.getEClassifiers().add(eClass);

    transaction.commit();

    // Make sure invalidation will trigger delta notifications
    resource.eAdapters().add(new EContentAdapter());

    CDOBranch subBranch = transaction.getBranch().createBranch("subBranch");
    transaction.setBranch(subBranch);
  }
}

Back to the top