Debian Codegraph @

tests/org.eclipse.emf.test.xml/src/org/eclipse/emf/test/xml/xmi/NamespaceTest.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
12 package org.eclipse.emf.test.xml.xmi;
13
14
15 import java.io.ByteArrayInputStream;
16 import java.io.FileInputStream;
17 import java.io.IOException;
18 import java.net.MalformedURLException;
19 import java.util.Collections;
20
21 import org.eclipse.emf.common.util.CommonUtil;
22 import org.eclipse.emf.common.util.URI;
23 import org.eclipse.emf.ecore.resource.Resource;
24 import org.eclipse.emf.ecore.resource.ResourceSet;
25 import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
26 import org.eclipse.emf.test.common.TestUtil;
27 import org.eclipse.emf.test.models.dbitem.DBItemPackage;
28 import org.eclipse.emf.test.models.dbitem.util.DBItemResourceFactoryImpl;
29 import org.eclipse.emf.test.models.dbprice.DBPricePackage;
30 import org.eclipse.emf.test.xml.AllSuites;
31 import org.junit.After;
32 import org.junit.Before;
33 import org.junit.Test;
34
35
36 public class NamespaceTest
37 {
38 private final static String BASE_XML_URI = TestUtil.getPluginDirectory(AllSuites.PLUGIN_ID) + "/data/xml/";
39
40 protected String file;
41 protected ResourceSet resourceSet;
42
43 @Before
44 public void setUp() throws Exception
45 {
46 resourceSet = new ResourceSetImpl();
47 DBPricePackage.eINSTANCE.getName();
48 DBItemPackage.eINSTANCE.getName();
49 resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xml", new DBItemResourceFactoryImpl());
50 file = BASE_XML_URI + "dbitemtest.xml";
51 }
52
53 @After
54 public void tearDown() throws Exception
55 {
56 resourceSet = null;
57 }
58
59 @Test
60 public void fileisLoadXML() throws MalformedURLException, IOException
61 {
62 FileInputStream fi = null;
63 Resource r = resourceSet.createResource(URI.createURI(".xml"));
64
65 fi = new FileInputStream(file);
66 r.load(fi, Collections.EMPTY_MAP);
67 }
68
69 @Test
70 public void byteisLoadXML() throws MalformedURLException, IOException
71 {
72 byte[] bbuffer = new byte [2064];
73 int length = 0;
74
75 java.net.URL u = CommonUtil.newURL("file:///" + file);
76 java.io.InputStream i = u.openStream();
77 length = i.read(bbuffer, 0, 2064);
78 i.close();
79
80 ByteArrayInputStream bi = new ByteArrayInputStream(bbuffer, 0, length);
81 Resource r = resourceSet.createResource(URI.createURI(".xml"));
82
83 r.load(bi, Collections.EMPTY_MAP);
84 }
85 }