From b74434a54e748752337096bfeff4604edc120507 Mon Sep 17 00:00:00 2001 From: Eike Stepper Date: Fri, 31 Aug 2007 13:12:53 +0000 Subject: [201839] Net4j/CDO Components must comform to incubation rules https://bugs.eclipse.org/bugs/show_bug.cgi?id=201839 --- .../org/eclipse/emf/cdo/tests/AbstractCDOTest.java | 243 ++++++++ .../src/org/eclipse/emf/cdo/tests/Activator.java | 60 ++ .../src/org/eclipse/emf/cdo/tests/AllTests.java | 36 ++ .../org/eclipse/emf/cdo/tests/ContainmentTest.java | 273 +++++++++ .../eclipse/emf/cdo/tests/CrossReferenceTest.java | 263 +++++++++ .../eclipse/emf/cdo/tests/DymamicEcoreTest.java | 80 +++ .../org/eclipse/emf/cdo/tests/DymamicUmlTest.java | 105 ++++ .../src/org/eclipse/emf/cdo/tests/EMFTest.java | 73 +++ .../eclipse/emf/cdo/tests/GeneratedEcoreTest.java | 58 ++ .../src/org/eclipse/emf/cdo/tests/InitialTest.java | 627 +++++++++++++++++++++ .../eclipse/emf/cdo/tests/InvalidationTest.java | 341 +++++++++++ .../eclipse/emf/cdo/tests/PackageRegistryTest.java | 112 ++++ .../src/org/eclipse/emf/cdo/tests/TDD.java | 88 +++ .../emf/cdo/tests/internal/CDOTestPlugin.java | 40 -- 14 files changed, 2359 insertions(+), 40 deletions(-) create mode 100644 plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractCDOTest.java create mode 100644 plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/Activator.java create mode 100644 plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllTests.java create mode 100644 plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ContainmentTest.java create mode 100644 plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/CrossReferenceTest.java create mode 100644 plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/DymamicEcoreTest.java create mode 100644 plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/DymamicUmlTest.java create mode 100644 plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/EMFTest.java create mode 100644 plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/GeneratedEcoreTest.java create mode 100644 plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/InitialTest.java create mode 100644 plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/InvalidationTest.java create mode 100644 plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/PackageRegistryTest.java create mode 100644 plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/TDD.java delete mode 100644 plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/internal/CDOTestPlugin.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/AbstractCDOTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractCDOTest.java new file mode 100644 index 0000000000..53fa8774b1 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractCDOTest.java @@ -0,0 +1,243 @@ +/*************************************************************************** + * Copyright (c) 2004-2007 Eike Stepper, 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.CDOObject; +import org.eclipse.emf.cdo.CDOSession; +import org.eclipse.emf.cdo.CDOState; +import org.eclipse.emf.cdo.eresource.CDOResource; +import org.eclipse.emf.cdo.internal.server.ContainerRepositoryProvider; +import org.eclipse.emf.cdo.internal.server.Repository; +import org.eclipse.emf.cdo.server.CDOServerUtil; +import org.eclipse.emf.cdo.server.db.IMappingStrategy; +import org.eclipse.emf.cdo.server.internal.db.DBStore; +import org.eclipse.emf.cdo.server.internal.db.HorizontalMappingStrategy; +import org.eclipse.emf.cdo.tests.model1.Model1Package; +import org.eclipse.emf.cdo.util.CDOUtil; + +import org.eclipse.net4j.db.ConnectionProvider; +import org.eclipse.net4j.db.DBUtil; +import org.eclipse.net4j.db.IDBAdapter; +import org.eclipse.net4j.db.internal.derby.DerbyAdapter; +import org.eclipse.net4j.tests.AbstractTransportTest; +import org.eclipse.net4j.util.container.IManagedContainer; + +import org.eclipse.emf.internal.cdo.util.FSMUtil; + +import javax.sql.DataSource; + +import java.util.Properties; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.locks.Condition; +import java.util.concurrent.locks.Lock; + +/** + * @author Eike Stepper + */ +public abstract class AbstractCDOTest extends AbstractTransportTest +{ + public static final String REPOSITORY_NAME = "repo1"; + + @Override + protected IManagedContainer createContainer() + { + IManagedContainer container = super.createContainer(); + CDOUtil.prepareContainer(container); + CDOServerUtil.prepareContainer(container, new ContainerRepositoryProvider(container)); + CDOServerUtil.addRepository(container, createRepository()); + return container; + } + + protected Repository createRepository() + { + IMappingStrategy mappingStrategy = new HorizontalMappingStrategy(); + IDBAdapter dbAdapter = new DerbyAdapter(); + + Properties properties = new Properties(); + properties.put("driverClass", "org.apache.derby.jdbc.EmbeddedDataSource"); + properties.put("databaseName", "C:/temp/cdo-repo1"); + properties.put("createDatabase", "create"); + DataSource dataSource = DBUtil.createDataSource(properties); + ConnectionProvider connectionProvider = DBUtil.createConnectionProvider(dataSource); + + DBStore store = new DBStore(mappingStrategy, dbAdapter, connectionProvider); + mappingStrategy.setStore(store); + + Repository repository = new Repository(); + repository.setName(REPOSITORY_NAME); + repository.setStore(store); + + store.setRepository(repository); + return repository; + } + + @Override + protected void doSetUp() throws Exception + { + super.doSetUp(); + startTransport(); + } + + protected CDOSession openModel1Session() + { + CDOSession session = CDOUtil.openSession(getConnector(), REPOSITORY_NAME); + session.getPackageRegistry().putEPackage(Model1Package.eINSTANCE); + return session; + } + + protected void assertTransient(CDOObject object) + { + assertTrue(FSMUtil.isTransient(object)); + assertEquals(null, object.cdoID()); + assertEquals(null, object.cdoRevision()); + assertEquals(null, object.cdoView()); + assertEquals(object.eResource(), object.cdoResource()); + } + + protected void assertNotTransient(CDOObject object) + { + assertFalse(FSMUtil.isTransient(object)); + assertNotNull(object.cdoID()); + assertNotNull(object.cdoRevision()); + assertNotNull(object.cdoView()); + assertNotNull(object.cdoResource()); + assertNotNull(object.eResource()); + assertEquals(object.eResource(), object.cdoResource()); + } + + protected void assertNew(CDOObject object) + { + assertNotTransient(object); + assertEquals(CDOState.NEW, object.cdoState()); + } + + protected void assertDirty(CDOObject object) + { + assertNotTransient(object); + assertEquals(CDOState.DIRTY, object.cdoState()); + } + + protected void assertClean(CDOObject object) + { + assertNotTransient(object); + assertEquals(CDOState.CLEAN, object.cdoState()); + } + + protected void assertProxy(CDOObject object) + { + assertFalse(FSMUtil.isTransient(object)); + assertNotNull(object.cdoID()); + assertNotNull(object.cdoView()); + assertNotNull(object.cdoResource()); + assertNotNull(object.eResource()); + assertEquals(object.eResource(), object.cdoResource()); + assertEquals(CDOState.PROXY, object.cdoState()); + } + + protected void assertContent(CDOObject container, CDOObject contained) + { + assertEquals(container.eResource(), contained.eResource()); + assertEquals(container.cdoResource(), contained.cdoResource()); + assertTrue(container.eContents().contains(contained)); + if (container instanceof CDOResource) + { + assertEquals(null, contained.eContainer()); + assertTrue(((CDOResource)container).getContents().contains(contained)); + } + else + { + assertEquals(container, contained.eContainer()); + } + } + + /** + * @author Eike Stepper + */ + public static interface ITimeOuter + { + public boolean timedOut() throws InterruptedException; + } + + /** + * @author Eike Stepper + */ + public static abstract class PollingTimeOuter implements ITimeOuter + { + private int retries; + + private long interval; + + public PollingTimeOuter(int retries, long interval) + { + this.retries = retries; + this.interval = interval; + } + + public int getRetries() + { + return retries; + } + + public long getInterval() + { + return interval; + } + + public boolean timedOut() throws InterruptedException + { + for (int i = 0; i < retries; i++) + { + if (successful()) + { + return false; + } + + Thread.sleep(interval); + } + + return true; + } + + protected abstract boolean successful(); + } + + /** + * @author Eike Stepper + */ + public static class LockTimeOuter implements ITimeOuter + { + private Lock lock; + + private long millis; + + public LockTimeOuter(Lock lock, long millis) + { + this.lock = lock; + this.millis = millis; + } + + public Lock getLock() + { + return lock; + } + + public long getMillis() + { + return millis; + } + + public boolean timedOut() throws InterruptedException + { + Condition condition = lock.newCondition(); + return !condition.await(millis, TimeUnit.MILLISECONDS); + } + } +} \ No newline at end of file diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/Activator.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/Activator.java new file mode 100644 index 0000000000..1c67941b69 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/Activator.java @@ -0,0 +1,60 @@ +package org.eclipse.emf.cdo.tests; + +import org.eclipse.core.runtime.Plugin; + +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class Activator extends Plugin +{ + + // The plug-in ID + public static final String PLUGIN_ID = "org.eclipse.emf.cdo.tests"; + + // The shared instance + private static Activator plugin; + + /** + * The constructor + */ + public Activator() + { + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext) + */ + @Override + public void start(BundleContext context) throws Exception + { + super.start(context); + plugin = this; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext) + */ + @Override + public void stop(BundleContext context) throws Exception + { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() + { + return plugin; + } + +} diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllTests.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllTests.java new file mode 100644 index 0000000000..ceac314dbb --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllTests.java @@ -0,0 +1,36 @@ +/*************************************************************************** + * Copyright (c) 2004-2007 Eike Stepper, 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 junit.framework.Test; +import junit.framework.TestSuite; + +/** + * @author Eike Stepper + */ +public class AllTests +{ + public static Test suite() + { + TestSuite suite = new TestSuite("Tests for CDO"); + + // $JUnit-BEGIN$ + suite.addTestSuite(InitialTest.class); + suite.addTestSuite(ContainmentTest.class); + suite.addTestSuite(InvalidationTest.class); + suite.addTestSuite(CrossReferenceTest.class); + suite.addTestSuite(PackageRegistryTest.class); + suite.addTestSuite(GeneratedEcoreTest.class); + // $JUnit-END$ + + return suite; + } +} diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ContainmentTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ContainmentTest.java new file mode 100644 index 0000000000..8c7427f1c8 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ContainmentTest.java @@ -0,0 +1,273 @@ +/*************************************************************************** + * Copyright (c) 2004-2007 Eike Stepper, 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.CDOSession; +import org.eclipse.emf.cdo.CDOTransaction; +import org.eclipse.emf.cdo.eresource.CDOResource; +import org.eclipse.emf.cdo.tests.model1.Category; +import org.eclipse.emf.cdo.tests.model1.Company; +import org.eclipse.emf.cdo.tests.model1.Model1Factory; +import org.eclipse.emf.cdo.tests.model1.Supplier; + +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; + +/** + * @author Eike Stepper + */ +public class ContainmentTest extends AbstractCDOTest +{ + public void testTransientContainment() throws Exception + { + msg("Creating supplier"); + Supplier supplier = Model1Factory.eINSTANCE.createSupplier(); + + msg("Setting name"); + supplier.setName("Stepper"); + + msg("Creating company"); + Company company = Model1Factory.eINSTANCE.createCompany(); + + msg("Adding supplier"); + company.getSuppliers().add(supplier); + + assertTransient(company); + assertTransient(supplier); + assertContent(company, supplier); + } + + public void testBasicContainment() throws Exception + { + msg("Creating supplier"); + Supplier supplier = Model1Factory.eINSTANCE.createSupplier(); + + msg("Setting name"); + supplier.setName("Stepper"); + + msg("Creating company"); + Company company = Model1Factory.eINSTANCE.createCompany(); + + msg("Adding supplier"); + company.getSuppliers().add(supplier); + + msg("Opening session"); + CDOSession session = openModel1Session(); + + msg("Opening transaction"); + CDOTransaction transaction = session.openTransaction(new ResourceSetImpl()); + + msg("Creating resource"); + CDOResource resource = transaction.createResource("/test1"); + + msg("Adding company"); + resource.getContents().add(company); + + msg("Committing"); + transaction.commit(); + + assertClean(resource); + assertClean(company); + assertClean(supplier); + assertContent(resource, company); + assertContent(company, supplier); + } + + public void test3Levels() throws Exception + { + msg("Creating category1"); + Category category1 = Model1Factory.eINSTANCE.createCategory(); + category1.setName("category1"); + + msg("Creating category2"); + Category category2 = Model1Factory.eINSTANCE.createCategory(); + category2.setName("category2"); + + msg("Creating category3"); + Category category3 = Model1Factory.eINSTANCE.createCategory(); + category3.setName("category3"); + + msg("Creating company"); + Company company = Model1Factory.eINSTANCE.createCompany(); + + msg("Adding categories"); + company.getCategories().add(category1); + category1.getCategories().add(category2); + category2.getCategories().add(category3); + + msg("Opening session"); + CDOSession session = openModel1Session(); + + msg("Opening transaction"); + CDOTransaction transaction = session.openTransaction(new ResourceSetImpl()); + + msg("Creating resource"); + CDOResource resource = transaction.createResource("/test1"); + + msg("Adding company"); + resource.getContents().add(company); + + msg("Committing"); + transaction.commit(); + + assertClean(resource); + assertClean(company); + assertClean(category1); + assertClean(category2); + assertClean(category3); + assertContent(resource, company); + assertContent(company, category1); + assertContent(category1, category2); + assertContent(category2, category3); + } + + public void testSeparateView() throws Exception + { + msg("Opening session"); + CDOSession session = openModel1Session(); + + { + msg("Creating category1"); + Category category1 = Model1Factory.eINSTANCE.createCategory(); + category1.setName("category1"); + + msg("Creating category2"); + Category category2 = Model1Factory.eINSTANCE.createCategory(); + category2.setName("category2"); + + msg("Creating category3"); + Category category3 = Model1Factory.eINSTANCE.createCategory(); + category3.setName("category3"); + + msg("Creating company"); + Company company = Model1Factory.eINSTANCE.createCompany(); + + msg("Adding categories"); + company.getCategories().add(category1); + category1.getCategories().add(category2); + category2.getCategories().add(category3); + + msg("Opening transaction"); + CDOTransaction transaction = session.openTransaction(new ResourceSetImpl()); + + msg("Creating resource"); + CDOResource resource = transaction.createResource("/test1"); + + msg("Adding company"); + resource.getContents().add(company); + + msg("Committing"); + transaction.commit(); + } + + msg("Opening transaction"); + CDOTransaction transaction = session.openTransaction(new ResourceSetImpl()); + + msg("Loading resource"); + CDOResource resource = transaction.getResource("/test1"); + assertProxy(resource); + + EList contents = resource.getContents(); + Company company = (Company)contents.get(0); + assertClean(company); + assertClean(resource); + assertContent(resource, company); + + Category category1 = company.getCategories().get(0); + assertClean(category1); + assertClean(company); + assertContent(company, category1); + + Category category2 = category1.getCategories().get(0); + assertClean(category2); + assertClean(category1); + assertContent(category1, category2); + + Category category3 = category2.getCategories().get(0); + assertClean(category3); + assertClean(category2); + assertContent(category2, category3); + assertClean(category3); + } + + public void testSeparateSession() throws Exception + { + { + msg("Opening session"); + CDOSession session = openModel1Session(); + + msg("Creating category1"); + Category category1 = Model1Factory.eINSTANCE.createCategory(); + category1.setName("category1"); + + msg("Creating category2"); + Category category2 = Model1Factory.eINSTANCE.createCategory(); + category2.setName("category2"); + + msg("Creating category3"); + Category category3 = Model1Factory.eINSTANCE.createCategory(); + category3.setName("category3"); + + msg("Creating company"); + Company company = Model1Factory.eINSTANCE.createCompany(); + + msg("Adding categories"); + company.getCategories().add(category1); + category1.getCategories().add(category2); + category2.getCategories().add(category3); + + msg("Opening transaction"); + CDOTransaction transaction = session.openTransaction(new ResourceSetImpl()); + + msg("Creating resource"); + CDOResource resource = transaction.createResource("/test1"); + + msg("Adding company"); + resource.getContents().add(company); + + msg("Committing"); + transaction.commit(); + } + + msg("Opening session"); + CDOSession session = openModel1Session(); + + msg("Opening transaction"); + CDOTransaction transaction = session.openTransaction(new ResourceSetImpl()); + + msg("Loading resource"); + CDOResource resource = transaction.getResource("/test1"); + assertProxy(resource); + + EList contents = resource.getContents(); + Company company = (Company)contents.get(0); + assertClean(company); + assertClean(resource); + assertContent(resource, company); + + Category category1 = company.getCategories().get(0); + assertClean(category1); + assertClean(company); + assertContent(company, category1); + + Category category2 = category1.getCategories().get(0); + assertClean(category2); + assertClean(category1); + assertContent(category1, category2); + + Category category3 = category2.getCategories().get(0); + assertClean(category3); + assertClean(category2); + assertContent(category2, category3); + assertClean(category3); + } +} diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/CrossReferenceTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/CrossReferenceTest.java new file mode 100644 index 0000000000..b69d25a1a8 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/CrossReferenceTest.java @@ -0,0 +1,263 @@ +/*************************************************************************** + * Copyright (c) 2004-2007 Eike Stepper, 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.CDOSession; +import org.eclipse.emf.cdo.CDOTransaction; +import org.eclipse.emf.cdo.CDOView; +import org.eclipse.emf.cdo.eresource.CDOResource; +import org.eclipse.emf.cdo.tests.model1.Company; +import org.eclipse.emf.cdo.tests.model1.Customer; +import org.eclipse.emf.cdo.tests.model1.Model1Factory; +import org.eclipse.emf.cdo.tests.model1.SalesOrder; + +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; + +/** + * @author Eike Stepper + */ +public class CrossReferenceTest extends AbstractCDOTest +{ + public void testLoadViaContainment() throws Exception + { + msg("Opening session"); + CDOSession session = openModel1Session(); + + // ************************************************************* // + + msg("Creating customer"); + Customer customerA = Model1Factory.eINSTANCE.createCustomer(); + customerA.setName("customer"); + + msg("Creating salesOrder1"); + SalesOrder salesOrder1A = Model1Factory.eINSTANCE.createSalesOrder(); + salesOrder1A.setId(1); + salesOrder1A.setCustomer(customerA); + + msg("Creating salesOrder2"); + SalesOrder salesOrder2A = Model1Factory.eINSTANCE.createSalesOrder(); + salesOrder2A.setId(2); + salesOrder2A.setCustomer(customerA); + + msg("Creating company"); + Company companyA = Model1Factory.eINSTANCE.createCompany(); + companyA.getCustomers().add(customerA); + companyA.getSalesOrders().add(salesOrder1A); + companyA.getSalesOrders().add(salesOrder2A); + + msg("Attaching transaction"); + CDOTransaction transaction = session.openTransaction(new ResourceSetImpl()); + + msg("Creating resource"); + CDOResource resourceA = transaction.createResource("/test1"); + + msg("Adding company"); + resourceA.getContents().add(companyA); + + msg("Committing"); + transaction.commit(); + + assertEquals(2, customerA.getSalesOrders().size()); + + // ************************************************************* // + + msg("Attaching viewB"); + CDOView viewB = session.openTransaction(new ResourceSetImpl()); + + msg("Loading resource"); + CDOResource resourceB = viewB.getResource("/test1"); + assertProxy(resourceB); + + EList contents = resourceB.getContents(); + Company companyB = (Company)contents.get(0); + assertClean(companyB); + assertClean(resourceB); + assertContent(resourceB, companyB); + + Customer customerB = companyB.getCustomers().get(0); + assertClean(customerB); + assertClean(companyB); + assertContent(companyB, customerB); + + SalesOrder salesOrder1B = companyB.getSalesOrders().get(0); + assertClean(salesOrder1B); + assertClean(companyB); + assertContent(companyB, salesOrder1B); + + SalesOrder salesOrder2B = companyB.getSalesOrders().get(1); + assertClean(salesOrder2B); + assertClean(companyB); + assertContent(companyB, salesOrder2B); + assertClean(salesOrder2B); + + assertEquals(2, customerB.getSalesOrders().size()); + } + + public void testLoadViaXRef() throws Exception + { + msg("Opening session"); + CDOSession session = openModel1Session(); + + // ************************************************************* // + + msg("Creating customer"); + Customer customerA = Model1Factory.eINSTANCE.createCustomer(); + customerA.setName("customer"); + + msg("Creating salesOrder1"); + SalesOrder salesOrder1A = Model1Factory.eINSTANCE.createSalesOrder(); + salesOrder1A.setId(1); + salesOrder1A.setCustomer(customerA); + + msg("Creating salesOrder2"); + SalesOrder salesOrder2A = Model1Factory.eINSTANCE.createSalesOrder(); + salesOrder2A.setId(2); + salesOrder2A.setCustomer(customerA); + + msg("Creating company"); + Company companyA = Model1Factory.eINSTANCE.createCompany(); + companyA.getCustomers().add(customerA); + companyA.getSalesOrders().add(salesOrder1A); + companyA.getSalesOrders().add(salesOrder2A); + + msg("Attaching transaction"); + CDOTransaction transaction = session.openTransaction(new ResourceSetImpl()); + + msg("Creating resource"); + CDOResource resourceA = transaction.createResource("/test1"); + + msg("Adding company"); + resourceA.getContents().add(companyA); + + msg("Committing"); + transaction.commit(); + + assertEquals(2, customerA.getSalesOrders().size()); + + // ************************************************************* // + + msg("Attaching viewB"); + CDOView viewB = session.openTransaction(new ResourceSetImpl()); + + msg("Loading resource"); + CDOResource resourceB = viewB.getResource("/test1"); + assertProxy(resourceB); + + EList contents = resourceB.getContents(); + Company companyB = (Company)contents.get(0); + assertClean(companyB); + assertClean(resourceB); + assertContent(resourceB, companyB); + + Customer customerB = companyB.getCustomers().get(0); + assertClean(customerB); + assertClean(companyB); + assertContent(companyB, customerB); + + SalesOrder salesOrder1B = customerB.getSalesOrders().get(0); + assertClean(salesOrder1B); + assertClean(companyB); + assertContent(companyB, salesOrder1B); + + SalesOrder salesOrder2B = customerB.getSalesOrders().get(1); + assertClean(salesOrder2B); + assertClean(companyB); + assertContent(companyB, salesOrder2B); + assertClean(salesOrder2B); + } + + public void testTwoResources() throws Exception + { + msg("Opening session"); + CDOSession session = openModel1Session(); + + msg("Attaching transaction"); + CDOTransaction transaction = session.openTransaction(new ResourceSetImpl()); + + // ************************************************************* // + + msg("Creating customer"); + Customer customerA = Model1Factory.eINSTANCE.createCustomer(); + customerA.setName("customer"); + + msg("Creating company1"); + Company company1A = Model1Factory.eINSTANCE.createCompany(); + company1A.getCustomers().add(customerA); + + msg("Creating resource1"); + CDOResource resource1A = transaction.createResource("/test1"); + + msg("Adding company1"); + resource1A.getContents().add(company1A); + + // ************************************************************* // + + msg("Creating salesOrder1"); + SalesOrder salesOrder1A = Model1Factory.eINSTANCE.createSalesOrder(); + assertTransient(salesOrder1A); + salesOrder1A.setId(1); + salesOrder1A.setCustomer(customerA); + assertTransient(salesOrder1A); + + msg("Creating salesOrder2"); + SalesOrder salesOrder2A = Model1Factory.eINSTANCE.createSalesOrder(); + assertTransient(salesOrder2A); + salesOrder2A.setId(2); + salesOrder2A.setCustomer(customerA); + assertTransient(salesOrder2A); + + msg("Creating company2"); + Company company2A = Model1Factory.eINSTANCE.createCompany(); + company2A.getSalesOrders().add(salesOrder1A); + company2A.getSalesOrders().add(salesOrder2A); + + msg("Creating resource2"); + CDOResource resource2A = transaction.createResource("/test2"); + + msg("Adding company"); + resource2A.getContents().add(company2A); + + // ************************************************************* // + + msg("Committing"); + transaction.commit(); + + assertEquals(2, customerA.getSalesOrders().size()); + + // ************************************************************* // + + msg("Attaching viewB"); + CDOView viewB = session.openTransaction(new ResourceSetImpl()); + + msg("Loading resource1"); + CDOResource resource1B = viewB.getResource("/test1"); + assertProxy(resource1B); + + EList contents = resource1B.getContents(); + Company company1B = (Company)contents.get(0); + assertClean(company1B); + assertClean(resource1B); + assertContent(resource1B, company1B); + + Customer customerB = company1B.getCustomers().get(0); + assertClean(customerB); + assertClean(company1B); + assertContent(company1B, customerB); + + SalesOrder salesOrder1B = customerB.getSalesOrders().get(0); + assertClean(salesOrder1B); + + SalesOrder salesOrder2B = customerB.getSalesOrders().get(1); + assertClean(salesOrder2B); + } +} diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/DymamicEcoreTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/DymamicEcoreTest.java new file mode 100644 index 0000000000..f01010cbfa --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/DymamicEcoreTest.java @@ -0,0 +1,80 @@ +/*************************************************************************** + * Copyright (c) 2004-2007 Eike Stepper, 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.CDOSession; +import org.eclipse.emf.cdo.CDOTransaction; +import org.eclipse.emf.cdo.eresource.CDOResource; +import org.eclipse.emf.cdo.util.CDOUtil; + +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; + +import java.io.IOException; + +/** + * @author Eike Stepper + */ +public class DymamicEcoreTest extends AbstractCDOTest +{ + public void testDynamicEcore() throws Exception + { + { + // Obtain model + EPackage ecore = (EPackage)loadModel("ecore/Ecore.ecore", EPackage.Registry.INSTANCE); + + // Create resource in session 1 + CDOSession session = CDOUtil.openSession(getConnector(), REPOSITORY_NAME); + session.getPackageRegistry().putEPackage(ecore); + CDOTransaction transaction = session.openTransaction(); + CDOResource res = transaction.createResource("/res"); + + EObject root = loadModel("model1.ecore", session.getPackageRegistry()); + res.getContents().add(root); + transaction.commit(); + } + + { + // Load resource in session 2 + CDOSession session = CDOUtil.openSession(getConnector(), REPOSITORY_NAME); + CDOTransaction transaction = session.openTransaction(); + CDOResource res = transaction.getResource("/res"); + + EObject root = res.getContents().get(0); + saveModel("model1X.ecore", root); + } + } + + private static EObject loadModel(String fileName, EPackage.Registry packageRegistry) throws IOException + { + ResourceSet resourceSet = new ResourceSetImpl(); + resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*", new XMIResourceFactoryImpl()); + resourceSet.setPackageRegistry(packageRegistry); + + Resource resource = resourceSet.getResource(URI.createFileURI(fileName), true); + return resource.getContents().get(0); + } + + private static void saveModel(String fileName, EObject root) throws IOException + { + ResourceSet resourceSet = new ResourceSetImpl(); + resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*", new XMIResourceFactoryImpl()); + Resource resource = resourceSet.getResource(URI.createFileURI(fileName), true); + resource.getContents().add(EcoreUtil.copy(root)); + resource.save(null); + } +} diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/DymamicUmlTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/DymamicUmlTest.java new file mode 100644 index 0000000000..f3594c5825 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/DymamicUmlTest.java @@ -0,0 +1,105 @@ +/*************************************************************************** + * Copyright (c) 2004-2007 Eike Stepper, 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.CDOObject; +import org.eclipse.emf.cdo.CDOSession; +import org.eclipse.emf.cdo.CDOTransaction; +import org.eclipse.emf.cdo.eresource.CDOResource; +import org.eclipse.emf.cdo.tests.model1.Company; +import org.eclipse.emf.cdo.tests.model1.Model1Factory; +import org.eclipse.emf.cdo.tests.model1.Model1Package; +import org.eclipse.emf.cdo.util.CDOUtil; + +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EAttribute; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; +import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; + +import java.io.IOException; + +/** + * @author Eike Stepper + */ +public class DymamicUmlTest extends AbstractCDOTest +{ + public void testGeneratedPackage() throws Exception + { + { + // Create resource in session 1 + CDOSession session = CDOUtil.openSession(getConnector(), REPOSITORY_NAME); + session.getPackageRegistry().putEPackage(Model1Package.eINSTANCE); + CDOTransaction transaction = session.openTransaction(); + CDOResource res = transaction.createResource("/res"); + + Company company = Model1Factory.eINSTANCE.createCompany(); + company.setName("Eike"); + res.getContents().add(company); + transaction.commit(); + } + + { + // Load resource in session 2 + CDOSession session = CDOUtil.openSession(getConnector(), REPOSITORY_NAME); + CDOTransaction transaction = session.openTransaction(); + CDOResource res = transaction.getResource("/res"); + + Company company = (Company)res.getContents().get(0); + assertEquals("Eike", company.getName()); + } + } + + public void testDynamicPackage() throws Exception + { + { + // Obtain model + EPackage model1 = loadModel("model1.ecore"); + EClass companyClass = (EClass)model1.getEClassifier("Company"); + EAttribute nameAttribute = (EAttribute)companyClass.getEStructuralFeature("name"); + + // Create resource in session 1 + CDOSession session = CDOUtil.openSession(getConnector(), REPOSITORY_NAME); + session.getPackageRegistry().putEPackage(model1); + CDOTransaction transaction = session.openTransaction(); + CDOResource res = transaction.createResource("/res"); + + CDOObject company = transaction.newInstance(companyClass); + company.eSet(nameAttribute, "Eike"); + res.getContents().add(company); + transaction.commit(); + } + + { + // Load resource in session 2 + CDOSession session = CDOUtil.openSession(getConnector(), REPOSITORY_NAME); + CDOTransaction transaction = session.openTransaction(); + CDOResource res = transaction.getResource("/res"); + + CDOObject company = (CDOObject)res.getContents().get(0); + EClass companyClass = company.eClass(); + EAttribute nameAttribute = (EAttribute)companyClass.getEStructuralFeature("name"); + String name = (String)company.eGet(nameAttribute); + assertEquals("Eike", name); + } + } + + private static EPackage loadModel(String fileName) throws IOException + { + ResourceSet resourceSet = new ResourceSetImpl(); + resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*", new XMIResourceFactoryImpl()); + Resource resource = resourceSet.getResource(URI.createFileURI(fileName), true); + return (EPackage)resource.getContents().get(0); + } +} diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/EMFTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/EMFTest.java new file mode 100644 index 0000000000..370d417f9b --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/EMFTest.java @@ -0,0 +1,73 @@ +/*************************************************************************** + * Copyright (c) 2004 - 2007 Eike Stepper, 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.util.EMFUtil; + +import org.eclipse.net4j.util.tests.AbstractOMTest; + +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.emf.ecore.InternalEObject; + +/** + * @author Eike Stepper + */ +public class EMFTest extends AbstractOMTest +{ + public EMFTest() + { + } + + public void testProxy() + { + EPackage model2 = (EPackage)EMFUtil.loadXMI("model2.ecore"); + EClass companyProxy = (EClass)model2.getEClassifier("CompanyProxy"); + EReference reference = (EReference)companyProxy.getEStructuralFeature("company"); + + EClass type = (EClass)reference.getEType(); + dumpProxy(type); + System.out.println(type.getName()); + dumpProxy(type); + + System.out.println(); + + if (false) + { + model2.eResource().getResourceSet().getResources().get(1).unload(); + } + else + { + ((InternalEObject)type).eSetProxyURI(URI.createURI("model1.ecore#//Company")); + } + + if (true) + { + type = (EClass)reference.getEType(); + } + + dumpProxy(type); + System.out.println(type.getName()); + dumpProxy(type); + } + + private void dumpProxy(EObject object) + { + InternalEObject eObject = (InternalEObject)object; + String label = eObject.eClass().getName(); + + System.out.println(label + ": " + eObject.eIsProxy()); + System.out.println(label + ": " + eObject.eProxyURI()); + } +} diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/GeneratedEcoreTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/GeneratedEcoreTest.java new file mode 100644 index 0000000000..cb362bd591 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/GeneratedEcoreTest.java @@ -0,0 +1,58 @@ +/*************************************************************************** + * Copyright (c) 2004-2007 Eike Stepper, 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.CDOSession; +import org.eclipse.emf.cdo.CDOTransaction; +import org.eclipse.emf.cdo.eresource.CDOResource; +import org.eclipse.emf.cdo.util.CDOUtil; +import org.eclipse.emf.cdo.util.EMFUtil; + +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.EcorePackage; + +/** + * @author Eike Stepper + */ +public class GeneratedEcoreTest extends AbstractCDOTest +{ + public void testGeneratedEcore() throws Exception + { + // Obtain model + EPackage ecore = EcorePackage.eINSTANCE; + + // Create resource in session 1 + CDOSession session1 = CDOUtil.openSession(getConnector(), REPOSITORY_NAME); + session1.getPackageRegistry().putEPackage(ecore); + CDOTransaction transaction1 = session1.openTransaction(); + CDOResource res1 = transaction1.createResource("/res"); + + EPackage root1 = (EPackage)EMFUtil.loadEcore("model1.ecore", session1.getPackageRegistry()); + res1.getContents().add(root1); + transaction1.commit(); + + // Load resource in session 2 + CDOSession session2 = CDOUtil.openSession(getConnector(), REPOSITORY_NAME); + CDOTransaction transaction2 = session2.openTransaction(); + CDOResource res2 = transaction2.getResource("/res"); + + EList contents = res2.getContents(); + EPackage root2 = (EPackage)contents.get(0); + assertFalse("Unresolved proxy", root2.eIsProxy()); + assertEquals(res2, root2.eResource()); + + CDOUtil.load(root2, transaction2);// FIXME + EMFUtil.saveEcore("model1X.ecore", root2); + // assertTrue("Models differ", EcoreUtil.equals(root1, root2)); + } +} diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/InitialTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/InitialTest.java new file mode 100644 index 0000000000..03591e9564 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/InitialTest.java @@ -0,0 +1,627 @@ +/*************************************************************************** + * Copyright (c) 2004-2007 Eike Stepper, 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.CDOSession; +import org.eclipse.emf.cdo.CDOState; +import org.eclipse.emf.cdo.CDOTransaction; +import org.eclipse.emf.cdo.eresource.CDOResource; +import org.eclipse.emf.cdo.tests.model1.Model1Factory; +import org.eclipse.emf.cdo.tests.model1.PurchaseOrder; +import org.eclipse.emf.cdo.tests.model1.Supplier; +import org.eclipse.emf.cdo.util.CDOUtil; + +import org.eclipse.net4j.IBufferHandler; +import org.eclipse.net4j.IChannel; + +import org.eclipse.emf.common.util.EList; +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 java.util.Date; + +/** + * @author Eike Stepper + */ +public class InitialTest extends AbstractCDOTest +{ + public void testTransientObject() throws Exception + { + final Date date = new Date(); + + msg("Creating supplier"); + Supplier supplier = Model1Factory.eINSTANCE.createSupplier(); + assertTransient(supplier); + + msg("Setting name"); + supplier.setName("Stepper"); + assertTransient(supplier); + + msg("Verifying name"); + assertEquals("Stepper", supplier.getName()); + assertTransient(supplier); + + msg("Creating purchaseOrder"); + PurchaseOrder purchaseOrder = Model1Factory.eINSTANCE.createPurchaseOrder(); + assertTransient(purchaseOrder); + + msg("Setting date"); + purchaseOrder.setDate(date); + assertTransient(purchaseOrder); + + msg("Verifying date"); + assertEquals(date, purchaseOrder.getDate()); + assertTransient(purchaseOrder); + + msg("Setting supplier"); + purchaseOrder.setSupplier(supplier); + assertTransient(supplier); + assertTransient(purchaseOrder); + + msg("Verifying supplier"); + assertEquals(supplier, purchaseOrder.getSupplier()); + assertTransient(supplier); + assertTransient(purchaseOrder); + } + + public void testTransientResource() throws Exception + { + final URI uri = URI.createURI("cdo:/test1"); + + msg("Creating resourceSet"); + ResourceSet resourceSet = new ResourceSetImpl(); + CDOUtil.prepareResourceSet(resourceSet); + + msg("Creating resource"); + CDOResource resource = (CDOResource)resourceSet.createResource(uri); + assertTransient(resource); + + msg("Creating supplier"); + Supplier supplier = Model1Factory.eINSTANCE.createSupplier(); + assertTransient(supplier); + assertEquals(null, supplier.eContainer()); + + msg("Verifying contents"); + EList contents = resource.getContents(); + assertNotNull(contents); + assertTrue(contents.isEmpty()); + assertEquals(0, contents.size()); + assertTransient(resource); + + msg("Adding supplier"); + contents.add(supplier); + assertTransient(resource); + assertTransient(supplier); + assertContent(resource, supplier); + } + + public void testOpenSession() throws Exception + { + msg("Opening session"); + CDOSession session = openModel1Session(); + assertNotNull(session); + + IChannel channel = session.getChannel(); + assertNotNull(channel); + + IBufferHandler receiveHandler = channel.getReceiveHandler(); + assertNotNull(receiveHandler); + } + + public void testStartTransaction() throws Exception + { + msg("Opening session"); + CDOSession session = openModel1Session(); + + msg("Opening transaction"); + CDOTransaction transaction = session.openTransaction(new ResourceSetImpl()); + assertNotNull(transaction); + assertEquals(session, transaction.getSession()); + } + + public void testAttachResource() throws Exception + { + msg("Opening session"); + CDOSession session = openModel1Session(); + + msg("Opening transaction"); + CDOTransaction transaction = session.openTransaction(new ResourceSetImpl()); + + msg("Creating resource"); + CDOResource resource = transaction.createResource("/test1"); + assertNew(resource); + assertEquals(URI.createURI("cdo:/test1"), resource.getURI()); + ResourceSet expected = transaction.getResourceSet(); + ResourceSet actual = resource.getResourceSet(); + assertEquals(expected, actual); + + } + + public void testAttachView() throws Exception + { + final URI uri = URI.createURI("cdo:/test1"); + + msg("Creating resourceSet"); + ResourceSet resourceSet = new ResourceSetImpl(); + CDOUtil.prepareResourceSet(resourceSet); + + msg("Creating resource"); + CDOResource resource = (CDOResource)resourceSet.createResource(uri); + assertTransient(resource); + + msg("Opening session"); + CDOSession session = openModel1Session(); + + msg("Opening transaction"); + CDOTransaction transaction = session.openTransaction(resourceSet); + + msg("Verifying resource"); + assertNew(resource); + assertEquals(uri, resource.getURI()); + assertEquals(transaction.getResourceSet(), resource.getResourceSet()); + } + + public void testAttachViewWithObject() throws Exception + { + final URI uri = URI.createURI("cdo:/test1"); + + msg("Creating resourceSet"); + ResourceSet resourceSet = new ResourceSetImpl(); + CDOUtil.prepareResourceSet(resourceSet); + + msg("Creating resource"); + CDOResource resource = (CDOResource)resourceSet.createResource(uri); + assertTransient(resource); + + msg("Creating supplier"); + Supplier supplier = Model1Factory.eINSTANCE.createSupplier(); + assertTransient(supplier); + + msg("Setting name"); + supplier.setName("Stepper"); + assertTransient(supplier); + + msg("Verifying name"); + assertEquals("Stepper", supplier.getName()); + assertTransient(supplier); + + msg("Adding supplier"); + EList contents = resource.getContents(); + contents.add(supplier); + assertTransient(resource); + assertTransient(supplier); + assertContent(resource, supplier); + + msg("Verifying supplier"); + contents = resource.getContents(); + assertNotNull(contents); + assertEquals(1, contents.size()); + + msg("Opening session"); + CDOSession session = openModel1Session(); + + msg("Opening transaction"); + CDOTransaction transaction = session.openTransaction(resourceSet); + + msg("Verifying resource"); + assertNew(resource); + assertEquals(uri, resource.getURI()); + assertEquals(transaction.getResourceSet(), resource.getResourceSet()); + + msg("Verifying contents"); + contents = resource.getContents(); + assertNotNull(contents); + assertEquals(1, contents.size()); + + msg("Verifying supplier"); + Supplier s = (Supplier)contents.get(0); + assertNew(supplier); + assertNew(resource); + assertEquals(supplier, s); + assertEquals(resource, s.cdoResource()); + assertEquals(null, s.eContainer()); + } + + public void testAttachObject() throws Exception + { + msg("Creating supplier"); + Supplier supplier = Model1Factory.eINSTANCE.createSupplier(); + + msg("Setting name"); + supplier.setName("Stepper"); + + msg("Opening session"); + CDOSession session = openModel1Session(); + + msg("Opening transaction"); + CDOTransaction transaction = session.openTransaction(new ResourceSetImpl()); + + msg("Creating resource"); + CDOResource resource = transaction.createResource("/test1"); + + msg("Getting contents"); + EList contents = resource.getContents(); + + msg("Adding supplier"); + contents.add(supplier); + assertNew(supplier); + assertEquals(transaction, supplier.cdoView()); + assertEquals(resource, supplier.cdoResource()); + assertEquals(resource, supplier.eResource()); + assertEquals(null, supplier.eContainer()); + } + + public void testCommitNew() throws Exception + { + msg("Opening session"); + CDOSession session = openModel1Session(); + + msg("Opening transaction"); + CDOTransaction transaction = session.openTransaction(new ResourceSetImpl()); + + msg("Creating resource"); + CDOResource resource = transaction.createResource("/test1"); + + msg("Creating supplier"); + Supplier supplier = Model1Factory.eINSTANCE.createSupplier(); + + msg("Setting name"); + supplier.setName("Stepper"); + + msg("Adding supplier"); + resource.getContents().add(supplier); + + msg("Committing"); + transaction.commit(); + assertEquals(CDOState.CLEAN, resource.cdoState()); + assertEquals(CDOState.CLEAN, supplier.cdoState()); + } + + public void testReadResourceClean() throws Exception + { + msg("Opening session"); + CDOSession session = openModel1Session(); + + msg("Opening transaction"); + CDOTransaction transaction = session.openTransaction(new ResourceSetImpl()); + + msg("Creating resource"); + CDOResource resource = transaction.createResource("/test1"); + + msg("Creating supplier"); + Supplier supplier = Model1Factory.eINSTANCE.createSupplier(); + + msg("Setting name"); + supplier.setName("Stepper"); + + msg("Adding supplier"); + resource.getContents().add(supplier); + + msg("Committing"); + transaction.commit(); + + msg("Getting supplier"); + EList contents = resource.getContents(); + Supplier s = (Supplier)contents.get(0); + assertEquals(supplier, s); + } + + public void testReadObjectClean() throws Exception + { + msg("Opening session"); + CDOSession session = openModel1Session(); + + msg("Opening transaction"); + CDOTransaction transaction = session.openTransaction(new ResourceSetImpl()); + + msg("Creating resource"); + CDOResource resource = transaction.createResource("/test1"); + + msg("Creating supplier"); + Supplier supplier = Model1Factory.eINSTANCE.createSupplier(); + + msg("Setting name"); + supplier.setName("Stepper"); + + msg("Adding supplier"); + resource.getContents().add(supplier); + + msg("Committing"); + transaction.commit(); + + msg("Getting supplier"); + Supplier s = (Supplier)resource.getContents().get(0); + + msg("Verifying name"); + assertEquals("Stepper", s.getName()); + } + + public void testWriteClean() throws Exception + { + msg("Opening session"); + CDOSession session = openModel1Session(); + + msg("Opening transaction"); + CDOTransaction transaction = session.openTransaction(new ResourceSetImpl()); + + msg("Creating resource"); + CDOResource resource = transaction.createResource("/test1"); + + msg("Creating supplier"); + Supplier supplier = Model1Factory.eINSTANCE.createSupplier(); + + msg("Setting name"); + supplier.setName("Stepper"); + + msg("Adding supplier"); + resource.getContents().add(supplier); + + msg("Committing"); + transaction.commit(); + + msg("Getting supplier"); + Supplier s = (Supplier)resource.getContents().get(0); + + msg("Setting name"); + s.setName("Eike"); + assertEquals("Eike", s.getName()); + assertEquals(CDOState.DIRTY, supplier.cdoState()); + assertEquals(CDOState.CLEAN, resource.cdoState()); + } + + public void testCommitDirty() throws Exception + { + msg("Opening session"); + CDOSession session = openModel1Session(); + + msg("Opening transaction"); + CDOTransaction transaction = session.openTransaction(new ResourceSetImpl()); + + msg("Creating resource"); + CDOResource resource = transaction.createResource("/test1"); + + msg("Creating supplier"); + Supplier supplier = Model1Factory.eINSTANCE.createSupplier(); + + msg("Setting name"); + supplier.setName("Stepper"); + + msg("Adding supplier"); + resource.getContents().add(supplier); + + msg("Committing"); + transaction.commit(); + + msg("Setting name"); + supplier.setName("Eike"); + + msg("Committing"); + transaction.commit(); + assertEquals(CDOState.CLEAN, resource.cdoState()); + assertEquals(CDOState.CLEAN, supplier.cdoState()); + } + + public void testGetResource() throws Exception + { + msg("Opening session"); + CDOSession session = openModel1Session(); + + { + disableConsole(); + msg("Opening transaction"); + CDOTransaction transaction = session.openTransaction(new ResourceSetImpl()); + + msg("Creating resource"); + CDOResource resource = transaction.createResource("/test1"); + + msg("Creating supplier"); + Supplier supplier = Model1Factory.eINSTANCE.createSupplier(); + + msg("Setting name"); + supplier.setName("Stepper"); + + msg("Adding supplier"); + resource.getContents().add(supplier); + + msg("Committing"); + transaction.commit(); + enableConsole(); + } + + msg("Opening transaction"); + CDOTransaction transaction = session.openTransaction(new ResourceSetImpl()); + + msg("Getting resource"); + CDOResource resource = transaction.getResource("/test1"); + assertNotNull(resource); + assertEquals(URI.createURI("cdo:/test1"), resource.getURI()); + assertEquals(transaction.getResourceSet(), resource.getResourceSet()); + assertEquals(CDOState.PROXY, resource.cdoState()); + assertEquals(transaction, resource.cdoView()); + assertNull(resource.cdoRevision()); + } + + public void testGetContents() throws Exception + { + msg("Opening session"); + CDOSession session = openModel1Session(); + + { + disableConsole(); + msg("Opening transaction"); + CDOTransaction transaction = session.openTransaction(new ResourceSetImpl()); + + msg("Creating resource"); + CDOResource resource = transaction.createResource("/test1"); + + msg("Creating supplier"); + Supplier supplier = Model1Factory.eINSTANCE.createSupplier(); + + msg("Setting name"); + supplier.setName("Stepper"); + + msg("Adding supplier"); + resource.getContents().add(supplier); + + msg("Committing"); + transaction.commit(); + enableConsole(); + } + + msg("Opening transaction"); + CDOTransaction transaction = session.openTransaction(new ResourceSetImpl()); + + msg("Getting resource"); + CDOResource resource = transaction.getResource("/test1"); + + msg("Getting contents"); + EList contents = resource.getContents(); + assertNotNull(contents); + } + + public void testReadObjectProxy() throws Exception + { + msg("Opening session"); + CDOSession session = openModel1Session(); + + { + disableConsole(); + msg("Opening transaction"); + CDOTransaction transaction = session.openTransaction(new ResourceSetImpl()); + + msg("Creating resource"); + CDOResource resource = transaction.createResource("/test1"); + + msg("Creating supplier"); + Supplier supplier = Model1Factory.eINSTANCE.createSupplier(); + + msg("Setting name"); + supplier.setName("Stepper"); + + msg("Adding supplier"); + resource.getContents().add(supplier); + + msg("Committing"); + transaction.commit(); + enableConsole(); + } + + msg("Opening transaction"); + CDOTransaction transaction = session.openTransaction(new ResourceSetImpl()); + + msg("Getting resource"); + CDOResource resource = transaction.getResource("/test1"); + + msg("Getting contents"); + EList contents = resource.getContents(); + + msg("Getting supplier"); + Supplier s = (Supplier)contents.get(0); + assertNotNull(s); + + msg("Verifying name"); + assertEquals("Stepper", s.getName()); + } + + public void testLoadResource() throws Exception + { + { + // disableConsole(); + msg("Opening session"); + CDOSession session = openModel1Session(); + + msg("Opening transaction"); + CDOTransaction transaction = session.openTransaction(new ResourceSetImpl()); + + msg("Creating resource"); + CDOResource resource = transaction.createResource("/test1"); + + msg("Creating supplier"); + Supplier supplier = Model1Factory.eINSTANCE.createSupplier(); + + msg("Setting name"); + supplier.setName("Stepper"); + + msg("Adding supplier"); + resource.getContents().add(supplier); + + msg("Committing"); + transaction.commit(); + // XXX session.close(); + // enableConsole(); + } + + msg("Opening session"); + CDOSession session = openModel1Session(); + + msg("Opening transaction"); + CDOTransaction transaction = session.openTransaction(new ResourceSetImpl()); + + msg("Getting resource"); + CDOResource resource = transaction.getResource("/test1"); + assertNotNull(resource); + assertEquals(URI.createURI("cdo:/test1"), resource.getURI()); + assertEquals(transaction.getResourceSet(), resource.getResourceSet()); + assertEquals(CDOState.PROXY, resource.cdoState()); + assertEquals(transaction, resource.cdoView()); + assertNull(resource.cdoRevision()); + } + + public void testLoadObject() throws Exception + { + { + // disableConsole(); + msg("Opening session"); + CDOSession session = openModel1Session(); + + msg("Opening transaction"); + CDOTransaction transaction = session.openTransaction(new ResourceSetImpl()); + + msg("Creating resource"); + CDOResource resource = transaction.createResource("/test1"); + + msg("Creating supplier"); + Supplier supplier = Model1Factory.eINSTANCE.createSupplier(); + + msg("Setting name"); + supplier.setName("Stepper"); + + msg("Adding supplier"); + resource.getContents().add(supplier); + + msg("Committing"); + transaction.commit(); + // XXX session.close(); + enableConsole(); + } + + msg("Opening session"); + CDOSession session = openModel1Session(); + + msg("Opening transaction"); + CDOTransaction transaction = session.openTransaction(new ResourceSetImpl()); + + msg("Getting resource"); + CDOResource resource = transaction.getResource("/test1"); + + msg("Getting contents"); + EList contents = resource.getContents(); + + msg("Getting supplier"); + Supplier s = (Supplier)contents.get(0); + assertNotNull(s); + + msg("Verifying name"); + assertEquals("Stepper", s.getName()); + } +} diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/InvalidationTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/InvalidationTest.java new file mode 100644 index 0000000000..c860c2bfbf --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/InvalidationTest.java @@ -0,0 +1,341 @@ +/*************************************************************************** + * Copyright (c) 2004-2007 Eike Stepper, 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.CDOSession; +import org.eclipse.emf.cdo.CDOSessionInvalidationEvent; +import org.eclipse.emf.cdo.CDOTransaction; +import org.eclipse.emf.cdo.CDOView; +import org.eclipse.emf.cdo.eresource.CDOResource; +import org.eclipse.emf.cdo.tests.model1.Category; +import org.eclipse.emf.cdo.tests.model1.Company; +import org.eclipse.emf.cdo.tests.model1.Model1Factory; + +import org.eclipse.net4j.util.event.IEvent; +import org.eclipse.net4j.util.event.IListener; + +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; + +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; + +/** + * @author Eike Stepper + */ +public class InvalidationTest extends AbstractCDOTest +{ + public void testSeparateView() throws Exception + { + msg("Opening session"); + final CDOSession session = openModel1Session(); + + // ************************************************************* // + + msg("Creating category1"); + final Category category1A = Model1Factory.eINSTANCE.createCategory(); + category1A.setName("category1"); + + msg("Creating category2"); + final Category category2A = Model1Factory.eINSTANCE.createCategory(); + category2A.setName("category2"); + + msg("Creating category3"); + final Category category3A = Model1Factory.eINSTANCE.createCategory(); + category3A.setName("category3"); + + msg("Creating company"); + final Company companyA = Model1Factory.eINSTANCE.createCompany(); + + msg("Adding categories"); + companyA.getCategories().add(category1A); + category1A.getCategories().add(category2A); + category2A.getCategories().add(category3A); + + msg("Attaching transaction"); + final CDOTransaction transaction = session.openTransaction(new ResourceSetImpl()); + + msg("Creating resource"); + final CDOResource resourceA = transaction.createResource("/test1"); + + msg("Adding company"); + resourceA.getContents().add(companyA); + + msg("Committing"); + transaction.commit(); + + // ************************************************************* // + + msg("Attaching viewB"); + final CDOView viewB = session.openTransaction(new ResourceSetImpl()); + + msg("Loading resource"); + final CDOResource resourceB = viewB.getResource("/test1"); + assertProxy(resourceB); + + EList contents = resourceB.getContents(); + final Company companyB = (Company)contents.get(0); + assertClean(companyB); + assertClean(resourceB); + assertContent(resourceB, companyB); + + final Category category1B = companyB.getCategories().get(0); + assertClean(category1B); + assertClean(companyB); + assertContent(companyB, category1B); + + final Category category2B = category1B.getCategories().get(0); + assertClean(category2B); + assertClean(category1B); + assertContent(category1B, category2B); + + final Category category3B = category2B.getCategories().get(0); + assertClean(category3B); + assertClean(category2B); + assertContent(category2B, category3B); + assertClean(category3B); + + // ************************************************************* // + + msg("Changing name"); + category1A.setName("CHANGED NAME"); + Thread.sleep(500); + + msg("Checking before commit"); + assertEquals("category1", category1B.getName()); + + msg("Committing"); + transaction.commit(); + + msg("Checking after commit"); + boolean timedOut = new PollingTimeOuter(4, 100) + { + @Override + protected boolean successful() + { + return "CHANGED NAME".equals(category1B.getName()); + } + }.timedOut(); + + assertEquals(false, timedOut); + } + + public void testSeparateViewNotification() throws Exception + { + msg("Opening session"); + final CDOSession session = openModel1Session(); + + // ************************************************************* // + + msg("Creating category1"); + final Category category1A = Model1Factory.eINSTANCE.createCategory(); + category1A.setName("category1"); + + msg("Creating category2"); + final Category category2A = Model1Factory.eINSTANCE.createCategory(); + category2A.setName("category2"); + + msg("Creating category3"); + final Category category3A = Model1Factory.eINSTANCE.createCategory(); + category3A.setName("category3"); + + msg("Creating company"); + final Company companyA = Model1Factory.eINSTANCE.createCompany(); + + msg("Adding categories"); + companyA.getCategories().add(category1A); + category1A.getCategories().add(category2A); + category2A.getCategories().add(category3A); + + msg("Attaching transaction"); + final CDOTransaction transaction = session.openTransaction(new ResourceSetImpl()); + + msg("Creating resource"); + final CDOResource resourceA = transaction.createResource("/test1"); + + msg("Adding company"); + resourceA.getContents().add(companyA); + + msg("Committing"); + transaction.commit(); + + // ************************************************************* // + + msg("Attaching viewB"); + final CDOView viewB = session.openTransaction(new ResourceSetImpl()); + + msg("Loading resource"); + final CDOResource resourceB = viewB.getResource("/test1"); + assertProxy(resourceB); + + EList contents = resourceB.getContents(); + final Company companyB = (Company)contents.get(0); + assertClean(companyB); + assertClean(resourceB); + assertContent(resourceB, companyB); + + final Category category1B = companyB.getCategories().get(0); + assertClean(category1B); + assertClean(companyB); + assertContent(companyB, category1B); + + final Category category2B = category1B.getCategories().get(0); + assertClean(category2B); + assertClean(category1B); + assertContent(category1B, category2B); + + final Category category3B = category2B.getCategories().get(0); + assertClean(category3B); + assertClean(category2B); + assertContent(category2B, category3B); + assertClean(category3B); + + // ************************************************************* // + + final boolean unlocked[] = { false }; + final Lock lock = new ReentrantLock(); + lock.lock(); + viewB.getSession().addListener(new IListener() + { + public void notifyEvent(IEvent event) + { + if (event instanceof CDOSessionInvalidationEvent) + { + CDOSessionInvalidationEvent e = (CDOSessionInvalidationEvent)event; + if (e.getView() == viewB) + { + msg("CDOSessionInvalidationEvent: " + e); + // TODO This code has no influence + unlocked[0] = true; + lock.unlock(); + } + } + } + }); + + msg("Changing name"); + category1A.setName("CHANGED NAME"); + + msg("Checking before commit"); + LockTimeOuter timeOuter = new LockTimeOuter(lock, 500); + boolean timedOut = timeOuter.timedOut(); + assertEquals(true, timedOut); + assertEquals(false, unlocked[0]); + + msg("Committing"); + transaction.commit(); + + msg("Checking after commit"); + if (!unlocked[0]) + { + timedOut = timeOuter.timedOut(); + assertEquals(true, timedOut); + } + } + + public void testSeparateSession() throws Exception + { + msg("Creating category1"); + final Category category1A = Model1Factory.eINSTANCE.createCategory(); + category1A.setName("category1"); + + msg("Creating category2"); + final Category category2A = Model1Factory.eINSTANCE.createCategory(); + category2A.setName("category2"); + + msg("Creating category3"); + final Category category3A = Model1Factory.eINSTANCE.createCategory(); + category3A.setName("category3"); + + msg("Creating company"); + final Company companyA = Model1Factory.eINSTANCE.createCompany(); + + msg("Adding categories"); + companyA.getCategories().add(category1A); + category1A.getCategories().add(category2A); + category2A.getCategories().add(category3A); + + msg("Opening sessionA"); + final CDOSession sessionA = openModel1Session(); + + msg("Attaching transaction"); + final CDOTransaction transaction = sessionA.openTransaction(new ResourceSetImpl()); + + msg("Creating resource"); + final CDOResource resourceA = transaction.createResource("/test1"); + + msg("Adding company"); + resourceA.getContents().add(companyA); + + msg("Committing"); + transaction.commit(); + + // ************************************************************* // + + msg("Opening sessionB"); + final CDOSession sessionB = openModel1Session(); + + msg("Attaching viewB"); + final CDOView viewB = sessionB.openTransaction(new ResourceSetImpl()); + + msg("Loading resource"); + final CDOResource resourceB = viewB.getResource("/test1"); + assertProxy(resourceB); + + EList contents = resourceB.getContents(); + final Company companyB = (Company)contents.get(0); + assertClean(companyB); + assertClean(resourceB); + assertContent(resourceB, companyB); + + final Category category1B = companyB.getCategories().get(0); + assertClean(category1B); + assertClean(companyB); + assertContent(companyB, category1B); + + final Category category2B = category1B.getCategories().get(0); + assertClean(category2B); + assertClean(category1B); + assertContent(category1B, category2B); + + final Category category3B = category2B.getCategories().get(0); + assertClean(category3B); + assertClean(category2B); + assertContent(category2B, category3B); + assertClean(category3B); + + // ************************************************************* // + + msg("Changing name"); + category1A.setName("CHANGED NAME"); + + ITimeOuter timeOuter = new PollingTimeOuter(4, 100) + { + @Override + protected boolean successful() + { + return "CHANGED NAME".equals(category1B.getName()); + } + }; + + msg("Checking before commit"); + boolean timedOut = timeOuter.timedOut(); + assertEquals(true, timedOut); + + msg("Committing"); + transaction.commit(); + + msg("Checking after commit"); + timedOut = timeOuter.timedOut(); + assertEquals(false, timedOut); + } +} diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/PackageRegistryTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/PackageRegistryTest.java new file mode 100644 index 0000000000..26983e1f25 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/PackageRegistryTest.java @@ -0,0 +1,112 @@ +/*************************************************************************** + * Copyright (c) 2004-2007 Eike Stepper, 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.CDOObject; +import org.eclipse.emf.cdo.CDOSession; +import org.eclipse.emf.cdo.CDOTransaction; +import org.eclipse.emf.cdo.eresource.CDOResource; +import org.eclipse.emf.cdo.tests.model1.Company; +import org.eclipse.emf.cdo.tests.model1.Model1Factory; +import org.eclipse.emf.cdo.tests.model1.Model1Package; +import org.eclipse.emf.cdo.util.CDOUtil; + +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EAttribute; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; +import org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl; + +import java.io.IOException; + +/** + * @author Eike Stepper + */ +public class PackageRegistryTest extends AbstractCDOTest +{ + public void testGeneratedPackage() throws Exception + { + { + // Create resource in session 1 + CDOSession session = CDOUtil.openSession(getConnector(), REPOSITORY_NAME); + session.getPackageRegistry().putEPackage(Model1Package.eINSTANCE); + CDOTransaction transaction = session.openTransaction(); + CDOResource res = transaction.createResource("/res"); + + Company company = Model1Factory.eINSTANCE.createCompany(); + company.setName("Eike"); + res.getContents().add(company); + transaction.commit(); + } + + { + // Load resource in session 2 + CDOSession session = CDOUtil.openSession(getConnector(), REPOSITORY_NAME); + CDOTransaction transaction = session.openTransaction(); + CDOResource res = transaction.getResource("/res"); + + Company company = (Company)res.getContents().get(0); + assertEquals("Eike", company.getName()); + } + } + + /** + * TODO Fix testDynamicPackage() + */ + public void _testDynamicPackage() throws Exception + { + { + // Obtain model + EPackage model1 = loadModel("model1.ecore"); + // EClass supplierClass = (EClass)model1.getEClassifier("Supplier"); + // EStructuralFeature firstFeature = + // supplierClass.getEStructuralFeatures().get(0); + + EClass companyClass = (EClass)model1.getEClassifier("Company"); + EAttribute nameAttribute = (EAttribute)companyClass.getEStructuralFeature("name"); + + // Create resource in session 1 + CDOSession session = CDOUtil.openSession(getConnector(), REPOSITORY_NAME); + session.getPackageRegistry().putEPackage(model1); + CDOTransaction transaction = session.openTransaction(); + CDOResource res = transaction.createResource("/res"); + + CDOObject company = transaction.newInstance(companyClass); + company.eSet(nameAttribute, "Eike"); + res.getContents().add(company); + transaction.commit(); + } + + { + // Load resource in session 2 + CDOSession session = CDOUtil.openSession(getConnector(), REPOSITORY_NAME); + CDOTransaction transaction = session.openTransaction(); + CDOResource res = transaction.getResource("/res"); + + CDOObject company = (CDOObject)res.getContents().get(0); + EClass companyClass = company.eClass(); + EAttribute nameAttribute = (EAttribute)companyClass.getEStructuralFeature("name"); + String name = (String)company.eGet(nameAttribute); + assertEquals("Eike", name); + } + } + + private static EPackage loadModel(String fileName) throws IOException + { + ResourceSet resourceSet = new ResourceSetImpl(); + resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*", new EcoreResourceFactoryImpl()); + Resource resource = resourceSet.getResource(URI.createFileURI(fileName), true); + return (EPackage)resource.getContents().get(0); + } +} diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/TDD.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/TDD.java new file mode 100644 index 0000000000..469d67e684 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/TDD.java @@ -0,0 +1,88 @@ +/*************************************************************************** + * Copyright (c) 2004-2007 Eike Stepper, 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.util.tests.AbstractOMTest; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +/** + * @author Eike Stepper + */ +public class TDD +{ + private static final AbstractOMTest test = new PackageRegistryTest(); + + private static final String METHOD_NAME = "testDynamicPackage"; + + public static void main(String[] args) throws Throwable + { + if (METHOD_NAME != null && METHOD_NAME.length() != 0) + { + runTest(test, METHOD_NAME); + } + else + { + Method[] methods = test.getClass().getMethods(); + for (Method method : methods) + { + + String methodName = method.getName(); + if (methodName.startsWith("test")) + { + runTest(test, methodName); + } + } + } + + System.out.println("******* COMPLETED *******"); + } + + private static void runTest(AbstractOMTest test, String methodName) throws Exception, Throwable + { + test.setName(methodName); + test.setUp(); + callMethod(test, methodName); + test.tearDown(); + } + + private static void callMethod(Object object, String methodName) throws Throwable + { + try + { + Method method = object.getClass().getMethod(methodName, new Class[0]); + method.invoke(object, new Object[0]); + } + catch (InvocationTargetException ex) + { + throw filterException(ex.getTargetException(), object.getClass()); + } + } + + private static Throwable filterException(Throwable t, Class entry) + { + StackTraceElement[] stackTrace = t.getStackTrace(); + int len; + for (len = stackTrace.length - 1; len >= 0; len--) + { + if (stackTrace[len].getClassName().equals(entry.getName())) + { + StackTraceElement[] filtered = new StackTraceElement[++len]; + System.arraycopy(stackTrace, 0, filtered, 0, len); + t.setStackTrace(filtered); + break; + } + } + + return t; + } +} diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/internal/CDOTestPlugin.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/internal/CDOTestPlugin.java deleted file mode 100644 index dceb8de298..0000000000 --- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/internal/CDOTestPlugin.java +++ /dev/null @@ -1,40 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2004, 2005, 2006 Eike Stepper, 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.internal; - - -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; - - -public class CDOTestPlugin implements BundleActivator -{ - private static CDOTestPlugin instance; - - public CDOTestPlugin() - { - super(); - instance = this; - } - - public static CDOTestPlugin getPlugin() - { - return instance; - } - - public void start(BundleContext context) throws Exception - { - } - - public void stop(BundleContext context) throws Exception - { - } -} -- cgit v1.2.3