Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon McDuff2008-10-14 20:15:25 -0400
committerSimon McDuff2008-10-14 20:15:25 -0400
commit6db788fb544ce4e005d89cd42f997ab7a9261c17 (patch)
tree1b44e1fd5c53c167860170c710824545da9aaf0f
parent4624cfa326b8dfc70ab83e3aba7b53587ecdc64c (diff)
downloadcdo-6db788fb544ce4e005d89cd42f997ab7a9261c17.tar.gz
cdo-6db788fb544ce4e005d89cd42f997ab7a9261c17.tar.xz
cdo-6db788fb544ce4e005d89cd42f997ab7a9261c17.zip
[248915] Resources fetched using CDOViewImpl.getResource(CDOID) not added to ResourceSet
https://bugs.eclipse.org/bugs/show_bug.cgi?id=248915
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllTestsAllConfigs.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_248915_Test.java112
2 files changed, 114 insertions, 0 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllTestsAllConfigs.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllTestsAllConfigs.java
index ab999cbe45..2c77ce228b 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllTestsAllConfigs.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllTestsAllConfigs.java
@@ -17,6 +17,7 @@ import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_246442_Test;
import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_246456_Test;
import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_246622_Test;
import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_248124_Test;
+import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_248915_Test;
import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_250036_Test;
import org.eclipse.emf.cdo.tests.config.ConfigTest;
import org.eclipse.emf.cdo.tests.config.ConfigTestSuite;
@@ -80,6 +81,7 @@ public class AllTestsAllConfigs extends ConfigTestSuite
testClasses.add(Bugzilla_246456_Test.class);
testClasses.add(Bugzilla_246622_Test.class);
testClasses.add(Bugzilla_248124_Test.class);
+ testClasses.add(Bugzilla_248915_Test.class);
testClasses.add(Bugzilla_250036_Test.class);
// TODO testClasses.add(NonCDOResourceTest.class);
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_248915_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_248915_Test.java
new file mode 100644
index 0000000000..00a0782047
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_248915_Test.java
@@ -0,0 +1,112 @@
+package org.eclipse.emf.cdo.tests.bugzilla;
+
+import org.eclipse.emf.cdo.CDOSession;
+import org.eclipse.emf.cdo.CDOTransaction;
+import org.eclipse.emf.cdo.common.id.CDOID;
+import org.eclipse.emf.cdo.eresource.CDOResource;
+import org.eclipse.emf.cdo.tests.AbstractCDOTest;
+import org.eclipse.emf.cdo.tests.model1.PurchaseOrder;
+import org.eclipse.emf.cdo.tests.model1.Supplier;
+import org.eclipse.emf.cdo.util.CDOUtil;
+
+/**
+ * Resources fetched using CDOViewImpl.getResource(CDOID) not added to ResourceSet
+ * <p>
+ * See https://bugs.eclipse.org/248915
+ *
+ * @author Simon McDuff
+ */
+public class Bugzilla_248915_Test extends AbstractCDOTest
+{
+ public void testBugzilla_248915_IncompleteResource() throws Exception
+ {
+ /* 1) Open first session ready to populate the CDO Server with the data */
+ CDOSession session1 = openModel1Session();
+ /* 2) Open first transaction ready to populate the CDO server with the data */
+ CDOTransaction transaction1 = session1.openTransaction();
+
+ /*
+ * Session has been established so 3) create the Supplier resource and 4) create the Purchase Order resource.
+ */
+ CDOResource supplierResource = transaction1.createResource("/supplierResource");
+ CDOResource poResource = transaction1.createResource("/poResource");
+
+ /* Create the supplier and add it to its respective resource */
+ Supplier mySupplier = getModel1Factory().createSupplier();
+ supplierResource.getContents().add(mySupplier);
+
+ /* Create the purchase order and add it to its respective resource */
+ PurchaseOrder myPurchaseOrder = getModel1Factory().createPurchaseOrder();
+ poResource.getContents().add(myPurchaseOrder);
+
+ /* 5) Reference the purchase order from the supplier */
+ mySupplier.getPurchaseOrders().add(myPurchaseOrder);
+
+ /* 6) Commit the transaction thereby saving all the data to the CDO server */
+ transaction1.commit();
+
+ /* This transaction and session are now redundent and should be discarded */
+ transaction1.close();
+ session1.close();
+ transaction1 = null;
+ session1 = null;
+ supplierResource = null;
+ poResource = null;
+ mySupplier = null;
+ myPurchaseOrder = null;
+
+ /* #### End first phase of persisting the data in the CDO Server #### */
+
+ /* #### Start of second phase where the data is fetched from the CDO Server #### */
+
+ /* 7) Open a completely new session and transaction onto the persisted data */
+ CDOSession session2 = openModel1Session();
+ CDOTransaction transaction2 = session2.openTransaction();
+
+ /* 8) Load the supplier from transaction2, fetching it into transaction2's empty resourceSet */
+ CDOResource supplierResource2 = transaction2.getResource("/supplierResource");
+ Supplier savedSupplier = (Supplier)supplierResource2.getContents().get(0);
+
+ /* Confirm the presence of supplierResource2 in transaction2's resourceSet */
+ assertEquals(1, transaction2.getResourceSet().getResources().size());
+
+ for (PurchaseOrder po : savedSupplier.getPurchaseOrders())
+ {
+ /* I believe that the Purchase Order's resource will be set but that its URI is null */
+ assertEquals(true, po.eResource().getURI() != null);
+ }
+
+ /*
+ * I believe that only supplierResource2 is in transaction2's resourceSet still despite finding the Purchase Order
+ * and its resource.
+ */
+ assertEquals(2, transaction2.getResourceSet().getResources().size());
+
+ transaction2.close();
+ session2.close();
+ transaction2 = null;
+ session2 = null;
+ }
+
+ public void testBugzilla_248915_DuplicateID() throws Exception
+ {
+
+ CDOSession session1 = openModel1Session();
+ CDOTransaction transaction1 = session1.openTransaction();
+
+ CDOResource supplierResource = transaction1.createResource("/supplierResource");
+
+ transaction1.commit();
+ CDOID resID = CDOUtil.getCDOObject(supplierResource).cdoID();
+ transaction1.close();
+ session1.close();
+
+ CDOSession session2 = openModel1Session();
+ CDOTransaction transaction2 = session2.openTransaction();
+ CDOResource resource = (CDOResource)transaction2.getObject(resID);
+ CDOResource resource1 = transaction2.getResource("/supplierResource");
+ assertSame(resource, resource1);
+ transaction2.close();
+ session2.close();
+ }
+}

Back to the top