Debian Codegraph @

tests/org.eclipse.emf.test.xml/src/org/eclipse/emf/test/xml/xmi/XMIExtendedMetadataTest.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 static org.junit.Assert.assertEquals;
15 import static org.junit.Assert.assertNotNull;
16
17 import java.util.HashMap;
18
19 import org.eclipse.emf.common.util.EList;
20 import org.eclipse.emf.common.util.URI;
21 import org.eclipse.emf.ecore.EObject;
22 import org.eclipse.emf.ecore.EPackage;
23 import org.eclipse.emf.ecore.EStructuralFeature;
24 import org.eclipse.emf.ecore.InternalEObject;
25 import org.eclipse.emf.ecore.resource.Resource;
26 import org.eclipse.emf.ecore.resource.ResourceSet;
27 import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
28 import org.eclipse.emf.ecore.util.ExtendedMetaData;
29 import org.eclipse.emf.ecore.xmi.XMLResource;
30 import org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl;
31 import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
32 import org.eclipse.emf.test.common.TestUtil;
33 import org.eclipse.emf.test.xml.AllSuites;
34 import org.junit.After;
35 import org.junit.Before;
36 import org.junit.Test;
37
38
39 /**
40 * Test for XMI package:
41 * EAttribute annotated with ExtendedMetaData (kind->simple) does not load correctly at runtime (105746)
42 * XMLHandler.handleFeature Fails to Load Certain EReferences When Using ExtendedMetadata (101877)
43 */
44 public class XMIExtendedMetadataTest
45 {
46 final static String BASE_XML_URI = TestUtil.getPluginDirectory(AllSuites.PLUGIN_ID) + "/data/xmi/";
47
48 final static String BASE_ECORE_URI = TestUtil.getPluginDirectory(AllSuites.PLUGIN_ID) + "/data/ecore/";
49
50 protected ResourceSet resourceSet;
51
52 protected HashMap<String, Object> options;
53
54 @Before
55 public void setUp() throws Exception
56 {
57 resourceSet = new ResourceSetImpl();
58 resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl());
59 resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi", new XMIResourceFactoryImpl());
60 options = new HashMap<String, Object>();
61 options.put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
62
63 Resource ecore = resourceSet.createResource(URI.createFileURI(BASE_ECORE_URI + "profile.ecore"));
64 ecore.load(options);
65 EPackage p = ((EPackage)ecore.getContents().get(0));
66 resourceSet.getPackageRegistry().put(p.getNsURI(), p);
67
68 }
69
70 @After
71 public void tearDown() throws Exception
72 {
73 options = null;
74 resourceSet = null;
75 }
76
77 @Test
78 public void testTopDescription() throws Exception
79 {
80
81 Resource resource = resourceSet.createResource(URI.createFileURI(BASE_XML_URI + "profile.xmi"));
82 options.put(XMLResource.OPTION_EXTENDED_META_DATA, ExtendedMetaData.INSTANCE);
83 resource.load(options);
84 EObject description = resource.getContents().get(0);
85 EStructuralFeature value = description.eClass().getEStructuralFeature("value");
86 assertNotNull("Description value must not be null", description.eGet(value));
87 }
88
89 @Test
90 public void testNestedDescription() throws Exception
91 {
92
93 Resource resource = resourceSet.createResource(URI.createFileURI(BASE_XML_URI + "profileNested.xmi"));
94 options.put(XMLResource.OPTION_EXTENDED_META_DATA, ExtendedMetaData.INSTANCE);
95 resource.load(options);
96 EObject classification = resource.getContents().get(0);
97 EStructuralFeature descriptorGroupFeature = classification.eClass().getEStructuralFeature("descriptorGroup");
98
99 EObject descriptorGroup = (EObject)((EList<?>)classification.eGet(descriptorGroupFeature)).get(0);
100
101 EStructuralFeature descriptionFeature = descriptorGroup.eClass().getEStructuralFeature("description");
102 EObject description = (EObject)descriptorGroup.eGet(descriptionFeature);
103 EStructuralFeature value = description.eClass().getEStructuralFeature("value");
104 assertNotNull("Description value must not be null", description.eGet(value));
105 }
106
107 /**
108 * 101877
109 * @throws Exception
110 */
111 @Test
112 public void testProxy() throws Exception
113 {
114 Resource ecore = resourceSet.createResource(URI.createFileURI(BASE_ECORE_URI + "proxy.ecore"));
115 ecore.load(options);
116 EPackage p = ((EPackage)ecore.getContents().get(0));
117 resourceSet.getPackageRegistry().put(p.getNsURI(), p);
118
119 Resource resource = resourceSet.createResource(URI.createFileURI(BASE_XML_URI + "proxy.xmi"));
120 options.put(XMLResource.OPTION_EXTENDED_META_DATA, ExtendedMetaData.INSTANCE);
121 resource.load(options);
122
123 EObject proxyRoot = resource.getContents().get(0);
124
125 EStructuralFeature contextFeature = proxyRoot.eClass().getEStructuralFeature("context");
126 EObject context = (EObject)proxyRoot.eGet(contextFeature, false);
127 assertEquals(
128 "Not maching expected value of 'http://some-proxy'",
129 URI.createURI("http://some-proxy"),
130 ((InternalEObject)context).eProxyURI());
131
132 }
133
134 }