Skip to main content
summaryrefslogtreecommitdiffstats
blob: 6a439e50d667a3e710e15962c5cc0662cf67c593 (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
/*
 * Copyright (c) 2004 - 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:
 *    Eike Stepper - initial API and implementation
 */
package org.eclipse.emf.cdo.tests.bugzilla;

import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.server.IRepository;
import org.eclipse.emf.cdo.session.CDOSession;
import org.eclipse.emf.cdo.tests.AbstractCDOTest;
import org.eclipse.emf.cdo.tests.model4.ContainedElementNoOpposite;
import org.eclipse.emf.cdo.tests.model4.RefMultiContainedNPL;
import org.eclipse.emf.cdo.tests.model4.RefMultiNonContainedNPL;
import org.eclipse.emf.cdo.tests.model4.RefSingleContainedNPL;
import org.eclipse.emf.cdo.tests.model4.RefSingleNonContainedNPL;
import org.eclipse.emf.cdo.transaction.CDOTransaction;

import java.util.Map;

/**
 * @author Eike Stepper
 */
public class Bugzilla_318998_Test extends AbstractCDOTest
{
  @Override
  public synchronized Map<String, Object> getTestProperties()
  {
    Map<String, Object> map = super.getTestProperties();
    map.put(IRepository.Props.ENSURE_REFERENTIAL_INTEGRITY, "true");
    return map;
  }

  public void testQueryXRefSingle() throws Exception
  {
    CDOSession session = openSession();
    CDOTransaction transaction = session.openTransaction();

    msg("Creating test data");
    CDOResource resource = transaction.createResource(getResourcePath("/test"));
    RefSingleContainedNPL container = getModel4Factory().createRefSingleContainedNPL();
    RefSingleNonContainedNPL nonContainer = getModel4Factory().createRefSingleNonContainedNPL();
    ContainedElementNoOpposite contained = getModel4Factory().createContainedElementNoOpposite();
    container.setElement(contained);
    nonContainer.setElement(contained);

    resource.getContents().add(container);
    resource.getContents().add(nonContainer);

    transaction.commit();

    container.setElement(null);

    try
    {
      transaction.commit();
      fail("Exception expected");
    }
    catch (Exception e)
    {
      msg("catched expected ex: " + e.getMessage());
    }
  }

  public void testQueryXRefMany() throws Exception
  {
    CDOSession session = openSession();
    CDOTransaction transaction = session.openTransaction();

    msg("Creating test data");
    CDOResource resource = transaction.createResource(getResourcePath("/test"));
    RefMultiContainedNPL container = getModel4Factory().createRefMultiContainedNPL();
    RefMultiNonContainedNPL nonContainer = getModel4Factory().createRefMultiNonContainedNPL();
    ContainedElementNoOpposite contained = getModel4Factory().createContainedElementNoOpposite();
    container.getElements().add(contained);
    nonContainer.getElements().add(contained);

    resource.getContents().add(container);
    resource.getContents().add(nonContainer);

    transaction.commit();

    container.getElements().remove(0);

    try
    {
      transaction.commit();
      fail("Exception expected");
    }
    catch (Exception e)
    {
      msg("Caught expected exception: " + e.getMessage());
    }
  }
}

Back to the top