Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: f0497fce8aad3230b678c1469f37bd6d6f6c1bd6 (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
/*
 * Copyright (c) 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:
 *    Christian W. Damus (CEA LIST) - 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.model5.Child;
import org.eclipse.emf.cdo.tests.model5.Parent;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
import org.eclipse.emf.cdo.view.CDOQuery;
import org.eclipse.emf.cdo.view.CDOView;

import org.eclipse.emf.ecore.EcorePackage;

import java.util.List;

/**
 * Bug 416366: Support implicit root class in OCL queries
 *
 * @author Christian W. Damus (CEA LIST)
 */
public class Bugzilla_416366_Test extends AbstractCDOTest
{
  public void testImplicitEObjectFeatures() throws Exception
  {
    Parent parentA = createParent("A");
    parentA.getChildren().add(createChild("A1"));
    parentA.getChildren().add(createChild("A2"));

    Parent parentB = createParent("B");
    parentB.getChildren().add(createChild("B1"));
    parentB.getChildren().add(createChild("B2"));

    CDOSession session = openSession();
    CDOTransaction transaction = session.openTransaction();
    CDOResource resource = transaction.createResource(getResourcePath("test-resource"));
    resource.getContents().add(parentA);
    resource.getContents().add(parentB);

    transaction.commit();

    CDOView newView = session.openView();
    CDOQuery ocl = newView.createQuery("ocl", "Child.allInstances()->select(c|c.eContainer().oclAsType(Parent).name = 'B')", getModel5Package().getChild());

    // eContainer() is inherited implicitly from EObject
    ocl.setParameter("cdoImplicitRootClass", EcorePackage.Literals.EOBJECT);

    List<Child> results = ocl.getResult(Child.class);
    assertEquals(2, results.size());

    // They are children of B
    assertEquals(true, parentB.getChildren().contains(transaction.getObject(results.get(0))));
    assertEquals(true, parentB.getChildren().contains(transaction.getObject(results.get(1))));
  }

  private Parent createParent(String name)
  {
    Parent result = getModel5Factory().createParent();
    result.setName(name);
    return result;
  }

  private Child createChild(String name)
  {
    Child result = getModel5Factory().createChild();
    result.setName(name);
    return result;
  }
}

Back to the top