Debian Codegraph @

tests/org.eclipse.emf.test.xml/src/org/eclipse/emf/test/xml/xmi/UnloadXMIResourceTest.java

raw
1 /**
2 * Copyright (c) 2013 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v2.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v20.html
7 *
8 * Contributors:
9 * IBM - Initial API and implementation
10 */
11 package org.eclipse.emf.test.xml.xmi;
12
13
14 import static org.junit.Assert.assertEquals;
15 import static org.junit.Assert.assertTrue;
16
17 import java.util.HashMap;
18 import java.util.Iterator;
19 import java.util.Map;
20
21 import org.eclipse.emf.common.util.URI;
22 import org.eclipse.emf.ecore.EObject;
23 import org.eclipse.emf.ecore.InternalEObject;
24 import org.eclipse.emf.ecore.resource.Resource;
25 import org.eclipse.emf.ecore.resource.ResourceSet;
26 import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
27 import org.eclipse.emf.ecore.util.EcoreUtil;
28 import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
29 import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl;
30 import org.eclipse.emf.test.models.library.Book;
31 import org.eclipse.emf.test.models.library.Library;
32 import org.eclipse.emf.test.models.library.LibraryFactory;
33 import org.eclipse.emf.test.models.library.LibraryPackage;
34 import org.eclipse.emf.test.models.library.Writer;
35 import org.junit.Test;
36
37
38 /**
39 * XMI tests: unloading preserves XMI IDs in proxy URIs.
40 * @see <a href="data/library.mdl">data/library.mdl</a>
41 * @see <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=412753">Bugzilla 412753</a>
42 */
43 public class UnloadXMIResourceTest
44 {
45 @Test
46 public void testHREF() throws Exception
47 {
48 ResourceSet resourceSet = new ResourceSetImpl();
49 LibraryPackage.eINSTANCE.getName();
50 LibraryFactory libFactory = LibraryFactory.eINSTANCE;
51
52 Library library = libFactory.createLibrary();
53
54 Book book = libFactory.createBook();
55 book.setTitle("Eclipse Modeling Framework");
56
57 Writer writer = libFactory.createWriter();
58 writer.setName("Frank Budinsky");
59
60 book.setAuthor(writer);
61
62 library.getBooks().add(book);
63 library.getWriters().add(writer);
64
65 resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put
66 ("xmi",
67 new XMIResourceFactoryImpl()
68 {
69 @Override
70 public Resource createResource(URI uri)
71 {
72 return
73 new XMIResourceImpl(uri)
74 {
75 @Override
76 protected boolean useUUIDs()
77 {
78 return true;
79 }
80 };
81 }
82 });
83
84 Resource resource = resourceSet.createResource(URI.createURI("library.xmi"));
85 resource.getContents().add(library);
86
87 Map<EObject, URI> proxyURIMap = new HashMap<EObject, URI>();
88 for (Iterator<EObject> i = resource.getAllContents(); i.hasNext(); )
89 {
90 EObject eObject = i.next();
91 URI proxyURI = EcoreUtil.getURI(eObject);
92 assertTrue(proxyURI.fragment().indexOf('/') == -1);
93 proxyURIMap.put(eObject, proxyURI);
94 }
95
96 resource.unload();
97
98 for (Map.Entry<EObject, URI> entry : proxyURIMap.entrySet())
99 {
100 EObject eObject = entry.getKey();
101 URI proxyURI = entry.getValue();
102 assertEquals(proxyURI, ((InternalEObject)eObject).eProxyURI());
103 }
104 }
105 }