blob: 28c1e28eb32b6aed851a23f0e281a78ebbe9f154 (
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
|
/*
* Copyright (c) 2004 - 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:
* Victor Roldan Betancort - initial API and implementation
*/
package org.eclipse.emf.cdo.tests.bugzilla;
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.Model1Package;
import org.eclipse.emf.cdo.tests.model1.OrderDetail;
import org.eclipse.emf.cdo.tests.model1.Product1;
import org.eclipse.emf.cdo.tests.util.TestEMFUtil;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.EcoreUtil;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
* Export resource miss all of the oneToMany references
* <p>
* See bug 273758
*
* @author Victor Roldan Betancort
*/
public class Bugzilla_273758_Test extends AbstractCDOTest
{
public void test_export_resource_contents() throws Exception
{
{
// Create 3 root objects: 1 Product1, 2 OrderDetails.
// Product1 will reference both OrderDetails
Product1 product = getModel1Factory().createProduct1();
product.setName("product");
OrderDetail detail1 = getModel1Factory().createOrderDetail();
detail1.setPrice(1.99f);
OrderDetail detail2 = getModel1Factory().createOrderDetail();
detail2.setPrice(9.99f);
product.getOrderDetails().add(detail1);
product.getOrderDetails().add(detail2);
CDOSession session = openSession();
CDOTransaction transaction = session.openTransaction();
CDOResource resource = transaction.createResource(getResourcePath("/test1"));
resource.getContents().add(product);
resource.getContents().add(detail1);
resource.getContents().add(detail2);
transaction.commit();
session.close();
}
{
CDOSession session = openSession();
CDOTransaction transaction = session.openTransaction();
CDOResource resource = transaction.getResource(getResourcePath("/test1"));
Product1 product2 = (Product1)resource.getContents().get(0);
// Check in memory Product1 EObject reference integrity
assertEquals(2, product2.getOrderDetails().size());
Collection<EObject> collection = EcoreUtil.copyAll(resource.getContents());
List<EObject> sourceContents = new ArrayList<EObject>(collection);
// Target Resource
File file = createTempFile("exportModel1", null);
String tempFileURI = file.toURI().toString();
TestEMFUtil.saveXMI(tempFileURI, sourceContents);
List<EObject> list = TestEMFUtil.loadXMIMultiple(tempFileURI, Model1Package.eINSTANCE);
Product1 product3 = (Product1)list.get(0);
assertEquals(2, product3.getOrderDetails().size());
}
}
}
|