Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 8025d5b67e7f7ccf4eabed70810a6998fca38eb2 (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
/*
 * Copyright (c) 2016 Eike Stepper (Loehne, 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.common.commit.CDOCommitInfo;
import org.eclipse.emf.cdo.common.commit.CDOCommitInfoManager;
import org.eclipse.emf.cdo.common.revision.CDORevisionKey;
import org.eclipse.emf.cdo.common.revision.delta.CDORevisionDelta;
import org.eclipse.emf.cdo.common.revision.delta.CDOSetFeatureDelta;
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.Requires;
import org.eclipse.emf.cdo.transaction.CDOTransaction;

import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EcoreFactory;
import org.eclipse.emf.ecore.EcorePackage;

import java.util.List;

/**
 * Bug 395685 - CDORevisionDelta.getOldValue() always returns CDOSetFeatureDelta.UNSPECIFIED
 *
 * @author Eike Stepper
 */
@Requires(IRepositoryConfig.CAPABILITY_AUDITING)
public class Bugzilla_395685_Test extends AbstractCDOTest
{
  private static final EAttribute FEATURE = EcorePackage.Literals.ENAMED_ELEMENT__NAME;

  public void testCorrectOldValue() throws Exception
  {
    CDOSession session1 = openSession();
    CDOTransaction transaction = session1.openTransaction();
    CDOResource resource = transaction.getOrCreateResource(getResourcePath("model1"));

    EClass o = EcoreFactory.eINSTANCE.createEClass();
    o.setName("A");
    resource.getContents().add(o);
    transaction.commit();

    o.setName("B");
    long commitTime = transaction.commit().getTimeStamp();
    transaction.close();

    checkCommitInfo(session1, commitTime);
    session1.close();

    CDOSession session2 = openSession();
    checkCommitInfo(session2, commitTime);
    session2.close();
  }

  private void checkCommitInfo(CDOSession session, long commitTime)
  {
    CDOCommitInfoManager commitInfoManager = session.getCommitInfoManager();
    CDOCommitInfo commitInfo = commitInfoManager.getCommitInfo(commitTime);
    List<CDORevisionKey> revisionDeltas = commitInfo.getChangedObjects();
    assertEquals(1, revisionDeltas.size());

    CDORevisionDelta revisionDelta = (CDORevisionDelta)revisionDeltas.get(0);
    CDOSetFeatureDelta featureDelta = (CDOSetFeatureDelta)revisionDelta.getFeatureDelta(FEATURE);
    assertEquals("B", featureDelta.getValue());
    assertEquals("A", featureDelta.getOldValue());
  }
}

Back to the top