Debian Codegraph @

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

raw
1 /**
2 * Copyright (c) 2002-2007 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 java.io.ByteArrayInputStream;
15 import java.io.ByteArrayOutputStream;
16
17 import org.eclipse.emf.common.util.URI;
18 import org.eclipse.emf.ecore.resource.Resource;
19 import org.eclipse.emf.ecore.resource.ResourceSet;
20 import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
21 import org.eclipse.emf.ecore.xmi.impl.XMLResourceFactoryImpl;
22 import org.eclipse.emf.test.models.library.Book;
23 import org.eclipse.emf.test.models.library.LibraryFactory;
24 import org.eclipse.emf.test.models.library.LibraryPackage;
25 import org.eclipse.emf.test.models.library.Writer;
26 import org.junit.Test;
27
28
29 /**
30 * XMI tests: loading and serializing library model with cross resource references
31 * @see <a href="data/library.mdl">data/library.mdl</a>
32 * @see <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=77423">Bugzilla 77423</a>
33 */
34 public class CrossResourceReferencesTest
35 {
36 @Test
37 public void testHREF() throws Exception
38 {
39 ResourceSet rs = new ResourceSetImpl();
40 LibraryPackage.eINSTANCE.getName();
41 LibraryFactory libFactory = LibraryFactory.eINSTANCE;
42
43 Book b = libFactory.createBook();
44 b.setTitle("Eclipse Modeling Framework");
45
46 Writer w = libFactory.createWriter();
47 w.setName("Frank Budinsky");
48
49 b.setAuthor(w);
50
51 rs.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xml", new XMLResourceFactoryImpl());
52
53 Resource r = rs.createResource(URI.createURI("books.xml"));
54 r.getContents().add(b);
55
56 Resource r2 = rs.createResource(URI.createURI("writers.xml"));
57 r2.getContents().add(w);
58
59 ByteArrayOutputStream outputstream1 = new ByteArrayOutputStream(2064);
60 ByteArrayOutputStream outputstream2 = new ByteArrayOutputStream(2064);
61
62 r.save(outputstream1, null);
63 r2.save(outputstream2, null);
64
65 r.unload();
66 r2.unload();
67
68 r.load(new ByteArrayInputStream(outputstream1.toByteArray()), null);
69 r2.load(new ByteArrayInputStream(outputstream2.toByteArray()), null);
70 }
71 }