Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2006-08-22 11:33:09 -0400
committerEike Stepper2006-08-22 11:33:09 -0400
commit77a5b25e0d96d3ba47bd7c2ecddf7e288a7bf7d8 (patch)
treec3aa4201680b3127e5652109bc977e968f62e5a6 /plugins/org.eclipse.emf.cdo.tests/src
parent295816aeecff3d02f26f4d4ccad67be11ea20fe1 (diff)
downloadcdo-77a5b25e0d96d3ba47bd7c2ecddf7e288a7bf7d8.tar.gz
cdo-77a5b25e0d96d3ba47bd7c2ecddf7e288a7bf7d8.tar.xz
cdo-77a5b25e0d96d3ba47bd7c2ecddf7e288a7bf7d8.zip
[151560] Query Language for CDO
https://bugs.eclipse.org/bugs/show_bug.cgi?id=151560
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.tests/src')
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/ExtentTest.java4
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/OCLTest.java250
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/topology/AbstractTopologyTest.java14
3 files changed, 266 insertions, 2 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/ExtentTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/ExtentTest.java
index 066fad1f80..63d2b2b41d 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/ExtentTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/ExtentTest.java
@@ -36,7 +36,7 @@ public class ExtentTest extends AbstractModel1Test
CDOResource resource = saveRoot(root, RESOURCE);
ResourceManager resourceManager = resource.getResourceManager();
- Set extent = resourceManager.queryExtent(TestModel1Package.eINSTANCE.getTreeNode());
+ Set extent = resourceManager.queryExtent(TestModel1Package.eINSTANCE.getTreeNode(), true);
assertEquals(1 + CHILDREN.length, extent.size());
assertTrue(extent.contains(root));
@@ -62,7 +62,7 @@ public class ExtentTest extends AbstractModel1Test
CDOResource resource = saveRoot(root, RESOURCE);
ResourceManager resourceManager = resource.getResourceManager();
- Set extent = resourceManager.queryExtent(TestModel1Package.eINSTANCE.getTreeNode(), true, null);
+ Set extent = resourceManager.queryExtent(TestModel1Package.eINSTANCE.getTreeNode());
assertEquals(2 + CHILDREN.length, extent.size());
assertTrue(extent.contains(root));
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/OCLTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/OCLTest.java
new file mode 100644
index 0000000000..5cb0a9bf01
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/OCLTest.java
@@ -0,0 +1,250 @@
+/***************************************************************************
+ * Copyright (c) 2004, 2005, 2006 Eike Stepper, Fuggerstr. 39, 10777 Berlin, Germany.
+ * 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.model1;
+
+
+import org.eclipse.emf.cdo.client.ocl.CDOHelperUtil;
+
+import org.eclipse.emf.ocl.helper.IOCLHelper;
+
+import testmodel1.TreeNode;
+
+import java.util.Set;
+
+
+public class OCLTest extends AbstractModel1Test
+{
+ // public void testNotEmpty() throws Exception
+ // {
+ // final String RESOURCE = "/test/res";
+ // final String ROOT = "root";
+ // final String[] CHILDREN = { "a", "b", "c"};
+ // final String EXPR = "self.children->isEmpty()";
+ //
+ // { // Create CDO resource
+ // TreeNode root = createNode(ROOT);
+ // createChildren(CHILDREN, root);
+ // saveRoot(root, RESOURCE);
+ // }
+ //
+ // TreeNode root = (TreeNode) loadRoot(RESOURCE);
+ // IOCLHelper helper = HelperUtil.createOCLHelper();
+ // helper.setContext(root);
+ //
+ // try
+ // {
+ // Object result = helper.evaluate(root, EXPR);
+ // assertFalse(result);
+ // }
+ // catch (Exception ex)
+ // {
+ // ex.printStackTrace();
+ // fail("Parse failed: " + ex.getLocalizedMessage());
+ // }
+ // }
+ //
+ // public void testEmpty() throws Exception
+ // {
+ // final String RESOURCE = "/test/res";
+ // final String ROOT = "root";
+ // final String EXPR = "self.children->isEmpty()";
+ //
+ // { // Create CDO resource
+ // TreeNode root = createNode(ROOT);
+ // saveRoot(root, RESOURCE);
+ // }
+ //
+ // TreeNode root = (TreeNode) loadRoot(RESOURCE);
+ // IOCLHelper helper = HelperUtil.createOCLHelper();
+ // helper.setContext(root);
+ //
+ // try
+ // {
+ // Object result = helper.evaluate(root, EXPR);
+ // assertTrue(result);
+ // }
+ // catch (Exception ex)
+ // {
+ // ex.printStackTrace();
+ // fail("Parse failed: " + ex.getLocalizedMessage());
+ // }
+ // }
+ //
+ // public void testExtendedNodeExtent() throws Exception
+ // {
+ // final String RESOURCE = "/test/res";
+ //
+ // { // Create CDO resource
+ // TreeNode root = createNode("root");
+ // TreeNode a = createNode("a", root);
+ // TreeNode b = createNode("b", root);
+ // TreeNode c = createNode("c", root);
+ // createNode("a1", a);
+ // createNode("b1", b);
+ // createNode("c1", c);
+ // createExtended("a2", a);
+ // createExtended("b2", b);
+ // createExtended("c2", c);
+ // saveRoot(root, RESOURCE);
+ // }
+ //
+ // TreeNode root = (TreeNode) loadRoot(RESOURCE);
+ // // CDOResource resource = root.cdoGetResource();
+ // IOCLHelper helper = CDOHelperUtil.createOCLHelper();
+ // helper.setContext(root);
+ //
+ // try
+ // {
+ // Set result = (Set) helper.evaluate(root, "ExtendedNode.allInstances()");
+ // assertEquals(3, result.size());
+ // }
+ // catch (Exception ex)
+ // {
+ // ex.printStackTrace();
+ // fail("Parse failed: " + ex.getLocalizedMessage());
+ // }
+ // }
+ //
+ // public void testTreeNodeExtent() throws Exception
+ // {
+ // final String RESOURCE = "/test/res";
+ //
+ // { // Create CDO resource
+ // TreeNode root = createNode("root");
+ // TreeNode a = createNode("a", root);
+ // TreeNode b = createNode("b", root);
+ // TreeNode c = createNode("c", root);
+ // createNode("a1", a);
+ // createNode("b1", b);
+ // createNode("c1", c);
+ // createExtended("a2", a);
+ // createExtended("b2", b);
+ // createExtended("c2", c);
+ // saveRoot(root, RESOURCE);
+ // }
+ //
+ // TreeNode root = (TreeNode) loadRoot(RESOURCE);
+ // // CDOResource resource = root.cdoGetResource();
+ // IOCLHelper helper = CDOHelperUtil.createOCLHelper();
+ // helper.setContext(root);
+ //
+ // try
+ // {
+ // Set result = (Set) helper.evaluate(root, "TreeNode.allInstances()");
+ // assertEquals(10, result.size());
+ // }
+ // catch (Exception ex)
+ // {
+ // ex.printStackTrace();
+ // fail("Parse failed: " + ex.getLocalizedMessage());
+ // }
+ // }
+
+ public void testExtentTwoResources() throws Exception
+ {
+ final String RESOURCE1 = "/test/res1";
+ final String RESOURCE2 = "/test/res2";
+
+ { // Create first CDO resource
+ TreeNode root = createNode("root");
+ TreeNode a = createNode("a", root);
+ TreeNode b = createNode("b", root);
+ TreeNode c = createNode("c", root);
+ createNode("a1", a);
+ createNode("b1", b);
+ createNode("c1", c);
+ createExtended("a2", a);
+ createExtended("b2", b);
+ createExtended("c2", c);
+ saveRoot(root, RESOURCE1);
+ }
+
+ { // Create second CDO resource
+ TreeNode root = createNode("root");
+ TreeNode a = createNode("a", root);
+ TreeNode b = createNode("b", root);
+ TreeNode c = createNode("c", root);
+ createNode("a1", a);
+ createNode("b1", b);
+ createNode("c1", c);
+ createExtended("a2", a);
+ createExtended("b2", b);
+ createExtended("c2", c);
+ saveRoot(root, RESOURCE2);
+ }
+
+ TreeNode root = (TreeNode) loadRoot(RESOURCE1);
+ // CDOResource resource = root.cdoGetResource();
+ IOCLHelper helper = CDOHelperUtil.createOCLHelper();
+ helper.setContext(root);
+
+ try
+ {
+ Set result = (Set) helper.evaluate(root, "ExtendedNode.allInstances()");
+ assertEquals(3, result.size());
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ fail("Parse failed: " + ex.getLocalizedMessage());
+ }
+ }
+
+ public void testGlobalExtent() throws Exception
+ {
+ final String RESOURCE1 = "/test/res1";
+ final String RESOURCE2 = "/test/res2";
+
+ { // Create first CDO resource
+ TreeNode root = createNode("root");
+ TreeNode a = createNode("a", root);
+ TreeNode b = createNode("b", root);
+ TreeNode c = createNode("c", root);
+ createNode("a1", a);
+ createNode("b1", b);
+ createNode("c1", c);
+ createExtended("a2", a);
+ createExtended("b2", b);
+ createExtended("c2", c);
+ saveRoot(root, RESOURCE1);
+ }
+
+ { // Create second CDO resource
+ TreeNode root = createNode("root");
+ TreeNode a = createNode("a", root);
+ TreeNode b = createNode("b", root);
+ TreeNode c = createNode("c", root);
+ createNode("a1", a);
+ createNode("b1", b);
+ createNode("c1", c);
+ createExtended("a2", a);
+ createExtended("b2", b);
+ createExtended("c2", c);
+ saveRoot(root, RESOURCE2);
+ }
+
+ TreeNode root = (TreeNode) loadRoot(RESOURCE1);
+ // CDOResource resource = root.cdoGetResource();
+ IOCLHelper helper = CDOHelperUtil.createOCLHelper(true);
+ helper.setContext(root);
+
+ try
+ {
+ Set result = (Set) helper.evaluate(root, "ExtendedNode.allInstances()");
+ assertEquals(6, result.size());
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ fail("Parse failed: " + ex.getLocalizedMessage());
+ }
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/topology/AbstractTopologyTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/topology/AbstractTopologyTest.java
index f91e45d99f..b77c48952a 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/topology/AbstractTopologyTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/topology/AbstractTopologyTest.java
@@ -177,4 +177,18 @@ public abstract class AbstractTopologyTest extends TestCase
{
return System.getProperty(CDO_TEST_MODE_KEY, EMBEDDED_MODE).toLowerCase();
}
+
+ protected void assertTrue(Object object)
+ {
+ assertNotNull(object);
+ assertSame(Boolean.class, object.getClass());
+ assertTrue(((Boolean) object).booleanValue());
+ }
+
+ protected void assertFalse(Object object)
+ {
+ assertNotNull(object);
+ assertSame(Boolean.class, object.getClass());
+ assertFalse(((Boolean) object).booleanValue());
+ }
}

Back to the top