blob: 2fdea86564a2e3c498fec06e08bd30523302757b [file] [log] [blame]
/***************************************************************************
* Copyright (c) 2004 - 2008 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:
* Paul Richardson - initial API and implementation
* Simon McDuff - maintenance
**************************************************************************/
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 Paul Richardson
*/
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();
}
}