summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2006-08-12 02:55:08 (EDT)
committerEike Stepper2006-08-12 02:55:08 (EDT)
commit4e5b0cb838947251e33d37f609245e42de96a976 (patch)
tree5198fc3aae2d0f04b9a3afdaf554d21123e1cc62
parent700856e63e788d877493a5366c526abfcc59ceac (diff)
downloadcdo-4e5b0cb838947251e33d37f609245e42de96a976.zip
cdo-4e5b0cb838947251e33d37f609245e42de96a976.tar.gz
cdo-4e5b0cb838947251e33d37f609245e42de96a976.tar.bz2
*** empty log message ***
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/launches/BasicTest.launch (renamed from plugins/org.eclipse.emf.cdo.tests/launches/Model1Test.launch)2
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractModel1Test.java114
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractTopologyTest.java33
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/BasicTest.java142
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ClientSeparatedServerTopology.java7
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ClientServerTopology.java7
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ClientTopology.java8
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/EmbeddedTopology.java8
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ITopology.java4
9 files changed, 324 insertions, 1 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/launches/Model1Test.launch b/plugins/org.eclipse.emf.cdo.tests/launches/BasicTest.launch
index b9bbf2a..5f52608 100644
--- a/plugins/org.eclipse.emf.cdo.tests/launches/Model1Test.launch
+++ b/plugins/org.eclipse.emf.cdo.tests/launches/BasicTest.launch
@@ -20,7 +20,7 @@
<stringAttribute key="configLocation" value="${workspace_loc}/.metadata/.plugins/org.eclipse.pde.core/pde-junit"/>
<stringAttribute key="application" value="org.eclipse.pde.junit.runtime.coretestapplication"/>
<booleanAttribute key="clearws" value="true"/>
-<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.eclipse.emf.cdo.tests.Model1Test"/>
+<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.eclipse.emf.cdo.tests.BasicTest"/>
<stringAttribute key="pde.version" value="3.2a"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Dcdo.test.mode=client-separated-server"/>
<stringAttribute key="templateConfig" value="${target_home}\configuration\config.ini"/>
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractModel1Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractModel1Test.java
new file mode 100644
index 0000000..1a3f56c
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractModel1Test.java
@@ -0,0 +1,114 @@
+/***************************************************************************
+ * 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;
+
+
+import org.eclipse.emf.common.util.EList;
+
+import org.springframework.jdbc.core.JdbcTemplate;
+
+import testmodel1.TestModel1Factory;
+import testmodel1.TreeNode;
+
+import java.util.Arrays;
+import java.util.Iterator;
+
+
+public class AbstractModel1Test extends AbstractTopologyTest
+{
+ @Override
+ protected void wipeDatabase(JdbcTemplate jdbc)
+ {
+ super.wipeDatabase(jdbc);
+ jdbc.execute("DROP TABLE TREE_NODE");
+ }
+
+ protected TreeNode createNode(String name)
+ {
+ return createNode(name, null);
+ }
+
+ protected TreeNode createNode(String name, TreeNode parent)
+ {
+ TreeNode node = TestModel1Factory.eINSTANCE.createTreeNode();
+ node.setStringFeature(name);
+ node.setParent(parent);
+ return node;
+ }
+
+ protected TreeNode createNode(String name, TreeNode parent, TreeNode[] references)
+ {
+ TreeNode node = createNode(name, parent);
+ node.getReferences().add(Arrays.asList(references));
+ return node;
+ }
+
+ protected void assertNode(String name, TreeNode node)
+ {
+ assertNotNull(node);
+ assertNotNull(name);
+ assertEquals(name, node.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 assertChild(String name, EList nodes)
+ {
+ assertNotNull(nodes);
+ assertNotNull(name);
+ assertEquals(1, nodes.size());
+ assertEquals(name, ((TreeNode) nodes.get(0)).getStringFeature());
+ }
+
+ protected void assertPath(String[] names, TreeNode node)
+ {
+ TreeNode result = findPath(names, node);
+ assertNotNull(result);
+ }
+
+ protected TreeNode findPath(String[] names, TreeNode node)
+ {
+ assertNotNull(names);
+ for (int i = 0; i < names.length; i++)
+ {
+ String name = names[i];
+ TreeNode child = findNode(name, node.getChildren());
+ if (child == null) return null;
+ node = child;
+ }
+
+ return node;
+ }
+
+ protected TreeNode findNode(String name, EList nodes)
+ {
+ assertNotNull(name);
+ for (Iterator it = nodes.iterator(); it.hasNext();)
+ {
+ TreeNode node = (TreeNode) it.next();
+ if (name.equals(node.getStringFeature()))
+ {
+ return node;
+ }
+ }
+
+ return null;
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractTopologyTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractTopologyTest.java
index f4efab9..0347222 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractTopologyTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractTopologyTest.java
@@ -20,8 +20,12 @@ import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.springframework.jdbc.core.JdbcTemplate;
+
import java.io.IOException;
+import javax.sql.DataSource;
+
import junit.framework.TestCase;
@@ -54,6 +58,9 @@ public abstract class AbstractTopologyTest extends TestCase
@Override
protected void tearDown() throws Exception
{
+ JdbcTemplate jdbc = getJdbcTemplate();
+ wipeDatabase(jdbc);
+
topology.stop();
super.tearDown();
@@ -63,6 +70,32 @@ public abstract class AbstractTopologyTest extends TestCase
System.out.println();
}
+ protected void wipeDatabase(JdbcTemplate jdbc)
+ {
+ jdbc.execute("DROP TABLE CDO_ATTRIBUTE");
+ jdbc.execute("DROP TABLE CDO_CLASS");
+ jdbc.execute("DROP TABLE CDO_CONTENT");
+ jdbc.execute("DROP TABLE CDO_OBJECT");
+ jdbc.execute("DROP TABLE CDO_PACKAGE");
+ jdbc.execute("DROP TABLE CDO_REFERENCE");
+ jdbc.execute("DROP TABLE CDO_RESOURCE");
+ }
+
+ protected ITopology getTopology()
+ {
+ return topology;
+ }
+
+ protected DataSource getDataSource()
+ {
+ return topology.getDataSource();
+ }
+
+ protected JdbcTemplate getJdbcTemplate()
+ {
+ return new JdbcTemplate(getDataSource());
+ }
+
protected ResourceManager createResourceManager(ResourceSet resourceSet)
{
return topology.createResourceManager(resourceSet);
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/BasicTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/BasicTest.java
new file mode 100644
index 0000000..9e5e7af
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/BasicTest.java
@@ -0,0 +1,142 @@
+/***************************************************************************
+ * 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;
+
+
+import org.eclipse.emf.common.util.EList;
+
+import testmodel1.TreeNode;
+
+
+@SuppressWarnings("unused")
+public class BasicTest extends AbstractModel1Test
+{
+ public void testSimple() throws Exception
+ {
+ final String RESOURCE = "/test/res";
+ final String ROOT = "root";
+ final String[] CHILDREN = { "a", "b", "c"};
+
+ // Execution
+ {
+ TreeNode root = createNode(ROOT);
+ for (String name : CHILDREN)
+ createNode(name, root);
+
+ saveRoot(root, RESOURCE);
+ }
+
+ // Verification
+ {
+ TreeNode root = (TreeNode) loadRoot(RESOURCE);
+ assertNode(ROOT, root);
+
+ EList children = root.getChildren();
+ assertChildren(CHILDREN, children);
+ }
+ }
+
+ public void testContainment() throws Exception
+ {
+ final String RESOURCE = "/test/res";
+ final String ROOT = "root";
+ final String[] CHILDREN_A = { "a1", "a2", "a3", "a4"};
+ final String[] CHILDREN_B = { "b1", "b2", "b3", "b4"};
+
+ // Execution
+ {
+ TreeNode root = createNode(ROOT);
+ TreeNode a = root;
+ for (String name : CHILDREN_A)
+ a = createNode(name, a);
+
+ TreeNode b = root;
+ for (String name : CHILDREN_B)
+ b = createNode(name, b);
+
+ saveRoot(root, RESOURCE);
+ }
+
+ // Verification
+ {
+ TreeNode root = (TreeNode) loadRoot(RESOURCE);
+ assertNode(ROOT, root);
+ assertPath(CHILDREN_A, root);
+ assertPath(CHILDREN_B, root);
+ }
+ }
+
+ public void testXRefAlreadyLoaded() throws Exception
+ {
+ final String RESOURCE = "/test/res";
+ final String ROOT = "root";
+ final String[] CHILDREN_A = { "a1", "a2", "a3", "a4"};
+ final String[] CHILDREN_B = { "b1", "b2", "b3", "b4"};
+
+ // Execution
+ {
+ TreeNode root = createNode(ROOT);
+ TreeNode a = root;
+ for (String name : CHILDREN_A)
+ a = createNode(name, a);
+
+ TreeNode b = root;
+ for (String name : CHILDREN_B)
+ b = createNode(name, b);
+
+ a.getReferences().add(b);
+ saveRoot(root, RESOURCE);
+ }
+
+ // Verification
+ {
+ TreeNode root = (TreeNode) loadRoot(RESOURCE);
+ assertNode(ROOT, root);
+
+ TreeNode a = findPath(CHILDREN_A, root);
+ TreeNode b = findPath(CHILDREN_B, root); // PRE-LOAD
+ assertNode(CHILDREN_B[3], (TreeNode) a.getReferences().get(0));
+ }
+ }
+
+ public void testXRefNotYetLoaded() throws Exception
+ {
+ final String RESOURCE = "/test/res";
+ final String ROOT = "root";
+ final String[] CHILDREN_A = { "a1", "a2", "a3", "a4"};
+ final String[] CHILDREN_B = { "b1", "b2", "b3", "b4"};
+
+ // Execution
+ {
+ TreeNode root = createNode(ROOT);
+ TreeNode a = root;
+ for (String name : CHILDREN_A)
+ a = createNode(name, a);
+
+ TreeNode b = root;
+ for (String name : CHILDREN_B)
+ b = createNode(name, b);
+
+ a.getReferences().add(b);
+ saveRoot(root, RESOURCE);
+ }
+
+ // Verification
+ {
+ TreeNode root = (TreeNode) loadRoot(RESOURCE);
+ assertNode(ROOT, root);
+
+ TreeNode a = findPath(CHILDREN_A, root);
+ // DO NOT LOAD: TreeNode b = findPath(CHILDREN_B, root);
+ assertNode(CHILDREN_B[3], (TreeNode) a.getReferences().get(0));
+ }
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ClientSeparatedServerTopology.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ClientSeparatedServerTopology.java
index 938728d..2c3669c 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ClientSeparatedServerTopology.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ClientSeparatedServerTopology.java
@@ -14,6 +14,8 @@ package org.eclipse.emf.cdo.tests;
import org.eclipse.net4j.core.Acceptor;
import org.eclipse.net4j.spring.Container;
+import javax.sql.DataSource;
+
public class ClientSeparatedServerTopology extends AbstractTopology
{
@@ -67,4 +69,9 @@ public class ClientSeparatedServerTopology extends AbstractTopology
net4jServer.stop();
serverNet4j.stop();
}
+
+ public DataSource getDataSource()
+ {
+ return (DataSource) cdoServer.getBean("dataSource");
+ }
}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ClientServerTopology.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ClientServerTopology.java
index 67e5bdb..1259e18 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ClientServerTopology.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ClientServerTopology.java
@@ -14,6 +14,8 @@ package org.eclipse.emf.cdo.tests;
import org.eclipse.net4j.core.Acceptor;
import org.eclipse.net4j.spring.Container;
+import javax.sql.DataSource;
+
public class ClientServerTopology extends AbstractTopology
{
@@ -64,4 +66,9 @@ public class ClientServerTopology extends AbstractTopology
net4j.stop();
}
+
+ public DataSource getDataSource()
+ {
+ return (DataSource) cdoServer.getBean("dataSource");
+ }
}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ClientTopology.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ClientTopology.java
index ad0e939..a14f18e 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ClientTopology.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ClientTopology.java
@@ -11,6 +11,9 @@
package org.eclipse.emf.cdo.tests;
+import javax.sql.DataSource;
+
+
public class ClientTopology extends AbstractTopology
{
public ClientTopology()
@@ -24,4 +27,9 @@ public class ClientTopology extends AbstractTopology
public void stop() throws Exception
{
}
+
+ public DataSource getDataSource()
+ {
+ return null;
+ }
}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/EmbeddedTopology.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/EmbeddedTopology.java
index 2ed0a89..d240c03 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/EmbeddedTopology.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/EmbeddedTopology.java
@@ -11,6 +11,9 @@
package org.eclipse.emf.cdo.tests;
+import javax.sql.DataSource;
+
+
public class EmbeddedTopology extends AbstractTopology
{
public EmbeddedTopology()
@@ -24,4 +27,9 @@ public class EmbeddedTopology extends AbstractTopology
public void stop() throws Exception
{
}
+
+ public DataSource getDataSource()
+ {
+ return null;
+ }
}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ITopology.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ITopology.java
index 61b5e7a..9104bd5 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ITopology.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ITopology.java
@@ -15,6 +15,8 @@ import org.eclipse.emf.cdo.client.ResourceManager;
import org.eclipse.emf.ecore.resource.ResourceSet;
+import javax.sql.DataSource;
+
public interface ITopology
{
@@ -23,4 +25,6 @@ public interface ITopology
public void stop() throws Exception;
public ResourceManager createResourceManager(ResourceSet resourceSet);
+
+ public DataSource getDataSource();
}