Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 24061ec32fb757953bf3ba782d06fa84d1ff1a61 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
 * Copyright (c) 2008-2012 Eike Stepper (Berlin, Germany) and others.
 * 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
 *    Eike Stepper - maintenance
 */
package org.eclipse.emf.cdo.tests.bugzilla;

import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.session.CDOSession;
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.transaction.CDOTransaction;
import org.eclipse.emf.cdo.util.CDOUtil;

/**
 * Resources fetched using CDOViewImpl.getResource(getResourcePath(CDOID)) not added to ResourceSet
 * <p>
 * See bug 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 = openSession();
    /* 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(getResourcePath("/supplierResource"));
    CDOResource poResource = transaction1.createResource(getResourcePath("/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 = openSession();
    CDOTransaction transaction2 = session2.openTransaction();

    /* 8) Load the supplier from transaction2, fetching it into transaction2's empty resourceSet */
    CDOResource supplierResource2 = transaction2.getResource(getResourcePath("/supplierResource"));
    Supplier savedSupplier = (Supplier)supplierResource2.getContents().get(0);

    if (!isConfig(LEGACY))
    {
      /* Confirm the presence of supplierResource2 in transaction2's resourceSet */
      assertEquals(1, transaction2.getResourceSet().getResources().size());
    }
    else
    {// legacy mode loads the whole tree. So there will be 3 resources
      assertEquals(2, 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 = openSession();
    CDOTransaction transaction1 = session1.openTransaction();

    CDOResource supplierResource = transaction1.createResource(getResourcePath("/supplierResource"));

    transaction1.commit();
    CDOID resID = CDOUtil.getCDOObject(supplierResource).cdoID();
    transaction1.close();
    session1.close();

    CDOSession session2 = openSession();
    CDOTransaction transaction2 = session2.openTransaction();
    CDOResource resource = (CDOResource)transaction2.getObject(resID);
    CDOResource resource1 = transaction2.getResource(getResourcePath("/supplierResource"));
    assertSame(resource, resource1);
    transaction2.close();
    session2.close();
  }
}

Back to the top