From 4a53d8d4bbe17736db2ea27961a367002f7c4f97 Mon Sep 17 00:00:00 2001 From: Eike Stepper Date: Sat, 12 Aug 2006 06:56:51 +0000 Subject: *** empty log message *** --- .../eclipse/emf/cdo/tests/AbstractModel1Test.java | 114 -------------- .../eclipse/emf/cdo/tests/AbstractTopology.java | 91 ----------- .../emf/cdo/tests/AbstractTopologyTest.java | 168 --------------------- .../src/org/eclipse/emf/cdo/tests/BasicTest.java | 142 ----------------- .../cdo/tests/ClientSeparatedServerTopology.java | 77 ---------- .../emf/cdo/tests/ClientServerTopology.java | 74 --------- .../org/eclipse/emf/cdo/tests/ClientTopology.java | 35 ----- .../eclipse/emf/cdo/tests/EmbeddedTopology.java | 35 ----- .../src/org/eclipse/emf/cdo/tests/ITopology.java | 30 ---- .../src/org/eclipse/emf/cdo/tests/Model1Test.java | 64 -------- .../cdo/tests/testmodel1/AbstractModel1Test.java | 116 ++++++++++++++ .../emf/cdo/tests/testmodel1/BasicTest.java | 142 +++++++++++++++++ 12 files changed, 258 insertions(+), 830 deletions(-) delete mode 100644 plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractModel1Test.java delete mode 100644 plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractTopology.java delete mode 100644 plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractTopologyTest.java delete mode 100644 plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/BasicTest.java delete mode 100644 plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ClientSeparatedServerTopology.java delete mode 100644 plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ClientServerTopology.java delete mode 100644 plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ClientTopology.java delete mode 100644 plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/EmbeddedTopology.java delete mode 100644 plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ITopology.java delete mode 100644 plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/Model1Test.java create mode 100644 plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/testmodel1/AbstractModel1Test.java create mode 100644 plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/testmodel1/BasicTest.java (limited to 'plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo') 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 deleted file mode 100644 index 1a3f56c060..0000000000 --- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractModel1Test.java +++ /dev/null @@ -1,114 +0,0 @@ -/*************************************************************************** - * 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/AbstractTopology.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractTopology.java deleted file mode 100644 index a164f47ca3..0000000000 --- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractTopology.java +++ /dev/null @@ -1,91 +0,0 @@ -/*************************************************************************** - * 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.cdo.client.ResourceManager; - -import org.eclipse.emf.ecore.resource.ResourceSet; - -import org.eclipse.core.runtime.FileLocator; -import org.eclipse.net4j.spring.Container; -import org.eclipse.net4j.spring.impl.ContainerImpl; - -import org.osgi.framework.Bundle; - -import java.net.URL; - - -public abstract class AbstractTopology implements ITopology -{ - protected static final String NET4J_LOCATION = "META-INF/net4j/net4j.xml"; - - protected static final String NET4J_CLIENT_LOCATION = "META-INF/net4j/client/net4j-client.xml"; - - protected static final String NET4J_SERVER_LOCATION = "META-INF/net4j/server/net4j-server.xml"; - - protected static final String NET4J_EMBEDDED_LOCATION = "META-INF/net4j/embedded/net4j-embedded.xml"; - - protected static final String CDO_CLIENT_LOCATION = "META-INF/cdo/client/cdo-client.xml"; - - protected static final String CDO_SERVER_LOCATION = "META-INF/cdo/server/cdo-server.xml"; - - private String bundleLocation; - - private Container cdoClient; - - protected AbstractTopology() - { - } - - public void start() throws Exception - { - CDOTestPlugin plugin = CDOTestPlugin.getPlugin(); - Bundle bundle = plugin.getBundle(); - URL url = bundle.getEntry("/"); - bundleLocation = FileLocator.toFileURL(url).getFile(); - } - - public void stop() throws Exception - { - cdoClient.stop(); - cdoClient = null; - } - - public ResourceManager createResourceManager(ResourceSet resourceSet) - { - ResourceManager resourceManager = (ResourceManager) cdoClient.getBean("resourceManager"); - resourceManager.setResourceSet(resourceSet); - - try - { - resourceManager.start(); - } - catch (Exception ex) - { - ex.printStackTrace(); - return null; - } - - return resourceManager; - } - - protected void createCDOClient(String name, Container parent) - { - cdoClient = createContainer(name, CDO_CLIENT_LOCATION, parent); - } - - protected ContainerImpl createContainer(String name, String location, Container parent) - { - return new ContainerImpl(bundleLocation, location, name, parent, CDOTestPlugin.class - .getClassLoader()); - } -} 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 deleted file mode 100644 index 0347222e56..0000000000 --- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractTopologyTest.java +++ /dev/null @@ -1,168 +0,0 @@ -/*************************************************************************** - * 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.cdo.client.CDOResource; -import org.eclipse.emf.cdo.client.ResourceManager; -import org.eclipse.emf.cdo.client.impl.CDOResourceFactoryImpl; - -import org.eclipse.emf.common.util.URI; -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; - - -public abstract class AbstractTopologyTest extends TestCase -{ - public static final String CDO_TEST_MODE_KEY = "cdo.test.mode"; - - public static final String CLIENT_SEPARATED_SERVER_MODE = "client-separated-server"; - - public static final String CLIENT_SERVER_MODE = "client-server"; - - public static final String CLIENT_MODE = "client"; - - public static final String EMBEDDED_MODE = "embedded"; - - private ITopology topology; - - @Override - protected void setUp() throws Exception - { - System.out.println("========================================================================="); - System.out.println("TC_START " + getName()); - System.out.println("========================================================================="); - - super.setUp(); - topology = createTopology(); - topology.start(); - } - - @Override - protected void tearDown() throws Exception - { - JdbcTemplate jdbc = getJdbcTemplate(); - wipeDatabase(jdbc); - - topology.stop(); - super.tearDown(); - - System.out.println("========================================================================="); - System.out.println("TC_END " + getName()); - System.out.println("========================================================================="); - 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); - } - - protected ResourceManager createResourceManager() - { - ResourceSet resourceSet = new ResourceSetImpl(); - return topology.createResourceManager(resourceSet); - } - - protected CDOResource createResource(String path) - { - ResourceManager resourceManager = createResourceManager(); - URI uri = CDOResourceFactoryImpl.formatURI(path); - return (CDOResource) resourceManager.createResource(uri); - } - - protected CDOResource getResource(String path) - { - ResourceManager resourceManager = createResourceManager(); - URI uri = CDOResourceFactoryImpl.formatURI(path); - return (CDOResource) resourceManager.getResource(uri, true); - } - - protected EObject loadRoot(String path) throws IOException - { - CDOResource resource = getResource(path); - return (EObject) resource.getContents().get(0); - } - - protected CDOResource saveRoot(EObject root, String path) throws IOException - { - CDOResource resource = createResource(path); - resource.getContents().add(root); - resource.save(null); - return resource; - } - - protected ITopology createTopology() - { - String mode = getMode(); - if (EMBEDDED_MODE.equals(mode)) - { - return new EmbeddedTopology(); - } - - if (CLIENT_MODE.equals(mode)) - { - return new ClientTopology(); - } - - if (CLIENT_SERVER_MODE.equals(mode)) - { - return new ClientServerTopology(); - } - - if (CLIENT_SEPARATED_SERVER_MODE.equals(mode)) - { - return new ClientSeparatedServerTopology(); - } - - return null; - } - - protected String getMode() - { - return System.getProperty(CDO_TEST_MODE_KEY, EMBEDDED_MODE).toLowerCase(); - } -} 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 deleted file mode 100644 index 9e5e7afa9a..0000000000 --- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/BasicTest.java +++ /dev/null @@ -1,142 +0,0 @@ -/*************************************************************************** - * 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 deleted file mode 100644 index 2c3669c3d3..0000000000 --- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ClientSeparatedServerTopology.java +++ /dev/null @@ -1,77 +0,0 @@ -/*************************************************************************** - * 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.net4j.core.Acceptor; -import org.eclipse.net4j.spring.Container; - -import javax.sql.DataSource; - - -public class ClientSeparatedServerTopology extends AbstractTopology -{ - private Container serverNet4j; - - private Container net4jServer; - - private Container cdoServer; - - private Container clientNet4j; - - private Container net4jClient; - - private Acceptor acceptor; - - public ClientSeparatedServerTopology() - { - } - - public void start() throws Exception - { - super.start(); - - // Start server - serverNet4j = createContainer("server", NET4J_LOCATION, null); - net4jServer = createContainer("socket", NET4J_SERVER_LOCATION, serverNet4j); - cdoServer = createContainer("cdo", CDO_SERVER_LOCATION, net4jServer); - - acceptor = (Acceptor) cdoServer.getBean("acceptor", Acceptor.class); - acceptor.start(); - - // Start client - clientNet4j = createContainer("client", NET4J_LOCATION, null); - net4jClient = createContainer("socket", NET4J_CLIENT_LOCATION, clientNet4j); - createCDOClient("cdo", net4jClient); - } - - public void stop() throws Exception - { - super.stop(); - - //Stop client - net4jClient.stop(); - clientNet4j.stop(); - - //Stop server - acceptor.stop(); - acceptor = null; - - cdoServer.stop(); - 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 deleted file mode 100644 index 1259e18487..0000000000 --- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ClientServerTopology.java +++ /dev/null @@ -1,74 +0,0 @@ -/*************************************************************************** - * 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.net4j.core.Acceptor; -import org.eclipse.net4j.spring.Container; - -import javax.sql.DataSource; - - -public class ClientServerTopology extends AbstractTopology -{ - private Container net4j; - - private Container net4jServer; - - private Container cdoServer; - - private Container net4jClient; - - private Acceptor acceptor; - - public ClientServerTopology() - { - } - - public void start() throws Exception - { - super.start(); - net4j = createContainer("net4j", NET4J_LOCATION, null); - - // Start server - net4jServer = createContainer("server", NET4J_SERVER_LOCATION, net4j); - cdoServer = createContainer("cdo", CDO_SERVER_LOCATION, net4jServer); - - acceptor = (Acceptor) cdoServer.getBean("acceptor", Acceptor.class); - acceptor.start(); - - // Start client - net4jClient = createContainer("client", NET4J_CLIENT_LOCATION, net4j); - createCDOClient("cdo", net4jClient); - } - - public void stop() throws Exception - { - super.stop(); - - //Stop client - net4jClient.stop(); - - //Stop server - acceptor.stop(); - acceptor = null; - - cdoServer.stop(); - net4jServer.stop(); - - 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 deleted file mode 100644 index a14f18ec9a..0000000000 --- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ClientTopology.java +++ /dev/null @@ -1,35 +0,0 @@ -/*************************************************************************** - * 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 javax.sql.DataSource; - - -public class ClientTopology extends AbstractTopology -{ - public ClientTopology() - { - } - - public void start() throws Exception - { - } - - 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 deleted file mode 100644 index d240c0361e..0000000000 --- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/EmbeddedTopology.java +++ /dev/null @@ -1,35 +0,0 @@ -/*************************************************************************** - * 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 javax.sql.DataSource; - - -public class EmbeddedTopology extends AbstractTopology -{ - public EmbeddedTopology() - { - } - - public void start() throws Exception - { - } - - 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 deleted file mode 100644 index 9104bd5306..0000000000 --- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ITopology.java +++ /dev/null @@ -1,30 +0,0 @@ -/*************************************************************************** - * 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.cdo.client.ResourceManager; - -import org.eclipse.emf.ecore.resource.ResourceSet; - -import javax.sql.DataSource; - - -public interface ITopology -{ - public void start() throws Exception; - - public void stop() throws Exception; - - public ResourceManager createResourceManager(ResourceSet resourceSet); - - public DataSource getDataSource(); -} diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/Model1Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/Model1Test.java deleted file mode 100644 index 9493eebbe6..0000000000 --- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/Model1Test.java +++ /dev/null @@ -1,64 +0,0 @@ -/*************************************************************************** - * 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.TestModel1Factory; -import testmodel1.TreeNode; - -import java.util.Arrays; - - -public class Model1Test extends AbstractTopologyTest -{ - protected static final String PATH1 = "/test/res1"; - - public void testSimple() throws Exception - { - TreeNode node = createNode("root"); - createNode("node1", node); - createNode("node2", node); - createNode("node3", node); - saveRoot(node, PATH1); - - TreeNode root = (TreeNode) loadRoot(PATH1); - assertNotNull(root); - assertEquals("root", root.getStringFeature()); - - EList children = root.getChildren(); - assertEquals(3, children.size()); - assertEquals("node1", ((TreeNode) children.get(0)).getStringFeature()); - assertEquals("node2", ((TreeNode) children.get(1)).getStringFeature()); - assertEquals("node3", ((TreeNode) children.get(2)).getStringFeature()); - } - - 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; - } -} diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/testmodel1/AbstractModel1Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/testmodel1/AbstractModel1Test.java new file mode 100644 index 0000000000..1f3dcb350f --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/testmodel1/AbstractModel1Test.java @@ -0,0 +1,116 @@ +/*************************************************************************** + * 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.testmodel1; + + +import org.eclipse.emf.cdo.tests.topology.AbstractTopologyTest; + +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/testmodel1/BasicTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/testmodel1/BasicTest.java new file mode 100644 index 0000000000..88d163da58 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/testmodel1/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.testmodel1; + + +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)); + } + } +} -- cgit v1.2.3