Skip to main content
summaryrefslogtreecommitdiffstats
blob: 87f24090146178b09adcbb4939ac065ada9d646c (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
/*
 * Copyright (c) 2010-2012 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
 */
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.config.IRepositoryConfig;
import org.eclipse.emf.cdo.tests.mango.MangoValue;
import org.eclipse.emf.cdo.tests.mango.MangoValueList;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
import org.eclipse.emf.cdo.util.CommitException;
import org.eclipse.emf.cdo.view.CDOView;

/**
 * @author Martin Fluegge
 * @since 4.0
 */
public class Bugzilla_305527_Test extends AbstractCDOTest
{
  @Requires(IRepositoryConfig.CAPABILITY_AUDITING)
  public void testAvoidReferencingDifferentViews() throws CommitException
  {
    final CDOSession session = openSession();
    long commitTime;

    {
      MangoValue mangoValue = getMangoFactory().createMangoValue();
      mangoValue.setName("1");

      CDOTransaction transaction = session.openTransaction();
      CDOResource resource = transaction.createResource(getResourcePath("/res1")); //$NON-NLS-1$
      resource.getContents().add(mangoValue);
      commitTime = transaction.commit().getTimeStamp();

      mangoValue.setName("2");
      transaction.commit();
      transaction.close();
    }

    CDOView audit = session.openView(commitTime);
    CDOResource auditResource = audit.getResource(getResourcePath("/res1"));
    MangoValue mangoValue = (MangoValue)auditResource.getContents().get(0);
    assertEquals("1", mangoValue.getName());

    MangoValueList mangoList = getMangoFactory().createMangoValueList();
    mangoList.getValues().add(mangoValue);

    CDOTransaction transaction = session.openTransaction();
    CDOResource resource = transaction.getResource(getResourcePath("/res1")); //$NON-NLS-1$

    try
    {
      resource.getContents().add(mangoList);
      fail("IllegalArgumentException expected");
    }
    catch (IllegalArgumentException expected)
    {
      // SUCCESS
      expected.printStackTrace();
    }
  }
}

Back to the top