summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2006-08-14 01:13:20 (EDT)
committerEike Stepper2006-08-14 01:13:20 (EDT)
commit54ce9eea1f94c58a6b4e06d6ae1981e2f5a48cb7 (patch)
treebb078efda983e92e86ac7ea5312e631aaefb3328
parentb26724656a798d040d10cb741a92d3aca942d3d0 (diff)
downloadcdo-54ce9eea1f94c58a6b4e06d6ae1981e2f5a48cb7.zip
cdo-54ce9eea1f94c58a6b4e06d6ae1981e2f5a48cb7.tar.gz
cdo-54ce9eea1f94c58a6b4e06d6ae1981e2f5a48cb7.tar.bz2
*** empty log message ***
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/AbstractModel1Test.java118
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/BasicTest.java75
2 files changed, 125 insertions, 68 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/AbstractModel1Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/AbstractModel1Test.java
index 13257f2..cb6f0e6 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/AbstractModel1Test.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/AbstractModel1Test.java
@@ -20,17 +20,56 @@ import org.springframework.jdbc.core.JdbcTemplate;
import testmodel1.TestModel1Factory;
import testmodel1.TreeNode;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
+import java.util.List;
public abstract class AbstractModel1Test extends AbstractTopologyTest
{
- @Override
- protected void wipeDatabase(JdbcTemplate jdbc)
+ protected void assertChild(String name, EList nodes)
{
- super.wipeDatabase(jdbc);
- dropTable(jdbc, "TREE_NODE");
+ assertNotNull(nodes);
+ assertNotNull(name);
+ assertEquals(1, nodes.size());
+ assertEquals(name, ((TreeNode) nodes.get(0)).getStringFeature());
+ }
+
+ protected void assertChildren(String[] names, EList nodes)
+ {
+ assertNotNull(nodes);
+ assertNotNull(names);
+ assertEquals(names.length, nodes.size());
+ for (int i = 0; i < names.length; i++)
+ {
+ assertEquals(names[i], ((TreeNode) nodes.get(i)).getStringFeature());
+ }
+ }
+
+ protected void assertNode(String name, TreeNode node)
+ {
+ assertNotNull(node);
+ assertNotNull(name);
+ assertEquals(name, node.getStringFeature());
+ }
+
+ protected void assertPath(String[] names, TreeNode node)
+ {
+ TreeNode result = findPath(names, node);
+ assertNotNull(result);
+ }
+
+ protected TreeNode[] createChildren(String[] names, TreeNode parent)
+ {
+ List<TreeNode> result = new ArrayList<TreeNode>();
+ for (String name : names)
+ {
+ TreeNode node = createNode(name, parent);
+ result.add(node);
+ }
+
+ return result.toArray(new TreeNode[result.size()]);
}
protected TreeNode createNode(String name)
@@ -53,36 +92,47 @@ public abstract class AbstractModel1Test extends AbstractTopologyTest
return node;
}
- protected void assertNode(String name, TreeNode node)
- {
- assertNotNull(node);
- assertNotNull(name);
- assertEquals(name, node.getStringFeature());
- }
-
- protected void assertChildren(String[] names, EList nodes)
+ protected TreeNode createPath(String[] names, TreeNode parent, boolean reuseNodes)
{
- assertNotNull(nodes);
- assertNotNull(names);
- assertEquals(names.length, nodes.size());
- for (int i = 0; i < names.length; i++)
+ for (String name : names)
{
- assertEquals(names[i], ((TreeNode) nodes.get(i)).getStringFeature());
+ TreeNode node = null;
+ if (reuseNodes)
+ {
+ node = findNode(name, parent.getChildren());
+ }
+
+ if (node == null)
+ {
+ node = TestModel1Factory.eINSTANCE.createTreeNode();
+ node.setStringFeature(name);
+ node.setParent(parent);
+ }
+
+ parent = node;
}
+
+ return parent;
}
- protected void assertChild(String name, EList nodes)
+ protected TreeNode findChild(String name, TreeNode parent)
{
- assertNotNull(nodes);
- assertNotNull(name);
- assertEquals(1, nodes.size());
- assertEquals(name, ((TreeNode) nodes.get(0)).getStringFeature());
+ return findNode(name, parent.getChildren());
}
- protected void assertPath(String[] names, TreeNode node)
+ protected TreeNode findNode(String name, EList nodes)
{
- TreeNode result = findPath(names, node);
- assertNotNull(result);
+ assertNotNull(name);
+ for (Iterator it = nodes.iterator(); it.hasNext();)
+ {
+ TreeNode node = (TreeNode) it.next();
+ if (name.equals(node.getStringFeature()))
+ {
+ return node;
+ }
+ }
+
+ return null;
}
protected TreeNode findPath(String[] names, TreeNode node)
@@ -91,7 +141,7 @@ public abstract class AbstractModel1Test extends AbstractTopologyTest
for (int i = 0; i < names.length; i++)
{
String name = names[i];
- TreeNode child = findNode(name, node.getChildren());
+ TreeNode child = findChild(name, node);
if (child == null) return null;
node = child;
}
@@ -99,18 +149,10 @@ public abstract class AbstractModel1Test extends AbstractTopologyTest
return node;
}
- protected TreeNode findNode(String name, EList nodes)
+ @Override
+ protected void wipeDatabase(JdbcTemplate jdbc)
{
- assertNotNull(name);
- for (Iterator it = nodes.iterator(); it.hasNext();)
- {
- TreeNode node = (TreeNode) it.next();
- if (name.equals(node.getStringFeature()))
- {
- return node;
- }
- }
-
- return null;
+ super.wipeDatabase(jdbc);
+ dropTable(jdbc, "TREE_NODE");
}
}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/BasicTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/BasicTest.java
index 1ac2d45..60f6108 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/BasicTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/model1/BasicTest.java
@@ -11,7 +11,11 @@
package org.eclipse.emf.cdo.tests.model1;
+import org.eclipse.emf.cdo.client.CDOResource;
+import org.eclipse.emf.cdo.client.impl.CDOPersistentImpl;
+
import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.resource.Resource;
import testmodel1.TreeNode;
@@ -28,9 +32,7 @@ public class BasicTest extends AbstractModel1Test
// Execution
{
TreeNode root = createNode(ROOT);
- for (String name : CHILDREN)
- createNode(name, root);
-
+ createChildren(CHILDREN, root);
saveRoot(root, RESOURCE);
}
@@ -54,15 +56,8 @@ public class BasicTest extends AbstractModel1Test
// Execution
{
TreeNode root = createNode(ROOT);
-
- TreeNode a = root;
- for (String name : PATH_A)
- a = createNode(name, a);
-
- TreeNode b = root;
- for (String name : PATH_B)
- b = createNode(name, b);
-
+ createPath(PATH_A, root, false);
+ createPath(PATH_B, root, false);
saveRoot(root, RESOURCE);
}
@@ -85,15 +80,8 @@ public class BasicTest extends AbstractModel1Test
// Execution
{
TreeNode root = createNode(ROOT);
-
- TreeNode a = root;
- for (String name : PATH_A)
- a = createNode(name, a);
-
- TreeNode b = root;
- for (String name : PATH_B)
- b = createNode(name, b);
-
+ TreeNode a = createPath(PATH_A, root, false);
+ TreeNode b = createPath(PATH_B, root, false);
a.getReferences().add(b);
saveRoot(root, RESOURCE);
}
@@ -119,15 +107,8 @@ public class BasicTest extends AbstractModel1Test
// Execution
{
TreeNode root = createNode(ROOT);
-
- TreeNode a = root;
- for (String name : PATH_A)
- a = createNode(name, a);
-
- TreeNode b = root;
- for (String name : PATH_B)
- b = createNode(name, b);
-
+ TreeNode a = createPath(PATH_A, root, false);
+ TreeNode b = createPath(PATH_B, root, false);
a.getReferences().add(b);
saveRoot(root, RESOURCE);
}
@@ -142,4 +123,38 @@ public class BasicTest extends AbstractModel1Test
assertNode(PATH_B[3], b);
}
}
+
+ public void testGetResource() throws Exception
+ {
+ final String RESOURCE = "/test/res";
+ final String ROOT = "root";
+ final String[] PATH = { "a1", "a2", "a3", "a4"};
+
+ // Execution
+ {
+ TreeNode root = createNode(ROOT);
+ createPath(PATH, root, false);
+ saveRoot(root, RESOURCE);
+ }
+
+ // Verification
+ {
+ TreeNode node = (TreeNode) loadRoot(RESOURCE);
+ CDOResource cdoResource = ((CDOPersistentImpl) node).cdoGetResource();
+ while (node != null)
+ {
+ Resource resource = node.eResource();
+ assertEquals(cdoResource, resource);
+
+ if (node.getChildren().isEmpty())
+ {
+ node = null;
+ }
+ else
+ {
+ node = (TreeNode) node.getChildren().get(0);
+ }
+ }
+ }
+ }
}