Skip to main content
summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorpelder2007-05-02 17:16:58 -0400
committerpelder2007-05-02 17:16:58 -0400
commitaead3fe5ef17d87f2e59e1459a0ef89fe2c7f3e1 (patch)
treec264474f6553b29fa6e3da18c2cc20621da79ffa /tests
parent8e67ef4fb3949b9c4c899f0d4f0e787e2968fa14 (diff)
downloadorg.eclipse.jet-aead3fe5ef17d87f2e59e1459a0ef89fe2c7f3e1.tar.gz
org.eclipse.jet-aead3fe5ef17d87f2e59e1459a0ef89fe2c7f3e1.tar.xz
org.eclipse.jet-aead3fe5ef17d87f2e59e1459a0ef89fe2c7f3e1.zip
[175036] Use extendedMeta data to determine element and attribute names.
Diffstat (limited to 'tests')
-rw-r--r--tests/org.eclipse.jet.tests/data/DOMInspector.xml2
-rw-r--r--tests/org.eclipse.jet.tests/data/beans.xsd1
-rw-r--r--tests/org.eclipse.jet.tests/data/library.xml2
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/DOMInspectorTests.java3
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/EObjectInspectorTests.java124
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/EStructuralFeatureSettingTests.java21
6 files changed, 123 insertions, 30 deletions
diff --git a/tests/org.eclipse.jet.tests/data/DOMInspector.xml b/tests/org.eclipse.jet.tests/data/DOMInspector.xml
index 9095579..dd08e67 100644
--- a/tests/org.eclipse.jet.tests/data/DOMInspector.xml
+++ b/tests/org.eclipse.jet.tests/data/DOMInspector.xml
@@ -2,7 +2,7 @@
<?eclipse version="3.0"?>
<root rootAttr="test">
<!-- a comment within root -->
- <a name="foo">
+ <a name="foo" name-with_hyphen="hello">
<b>Some foo text.</b>
</a>
<a name="bar">
diff --git a/tests/org.eclipse.jet.tests/data/beans.xsd b/tests/org.eclipse.jet.tests/data/beans.xsd
index 8635462..f886846 100644
--- a/tests/org.eclipse.jet.tests/data/beans.xsd
+++ b/tests/org.eclipse.jet.tests/data/beans.xsd
@@ -35,6 +35,7 @@
<xsd:attribute name="name" type="xsd:string"/>
<xsd:attribute name="type" type="xsd:string"/>
<xsd:attribute name="kind" type="xsd:string"/>
+ <xsd:attribute name="name-with_hyphen" type="xsd:string" use="optional"/>
</xsd:complexType>
<xsd:element name="root" type="root"/>
diff --git a/tests/org.eclipse.jet.tests/data/library.xml b/tests/org.eclipse.jet.tests/data/library.xml
index 51ba39c..12e1c14 100644
--- a/tests/org.eclipse.jet.tests/data/library.xml
+++ b/tests/org.eclipse.jet.tests/data/library.xml
@@ -3,7 +3,7 @@
<project name="test.beans">
<beanModel basePackage="org.example" name="Library">
<bean name="Library">
- <attribute kind="FIELD" name="name" type="String"/>
+ <attribute kind="FIELD" name="name" type="String" name-with_hyphen="hello"/>
<attribute kind="FIELD" name="yearFounded" type="int"/>
<attribute kind="DERIVED" name="yearsOpen" type="int"/>
<attribute kind="LIST" name="books" type="Book"/>
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/DOMInspectorTests.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/DOMInspectorTests.java
index e62fd77..a18bf36 100644
--- a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/DOMInspectorTests.java
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/DOMInspectorTests.java
@@ -83,8 +83,9 @@ public class DOMInspectorTests extends AbstractExprTest {
Object[] aAttributes = inspector.getAttributes(elementA);
assertNotNull(aAttributes);
- assertEquals(1, aAttributes.length);
+ assertEquals(2, aAttributes.length);
assertEquals("name", inspector.expandedNameOf(aAttributes[0]).toString());
+ assertEquals("name-with_hyphen", inspector.expandedNameOf(aAttributes[1]).toString());
assertEquals("foo", inspector.stringValueOf(aAttributes[0]));
}
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/EObjectInspectorTests.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/EObjectInspectorTests.java
index 616fd18..53b05c3 100644
--- a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/EObjectInspectorTests.java
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/EObjectInspectorTests.java
@@ -1,5 +1,6 @@
package org.eclipse.jet.tests.xpath;
+import java.net.URL;
import java.util.Iterator;
import java.util.List;
@@ -14,9 +15,11 @@ import org.eclipse.emf.ecore.util.FeatureMap;
import org.eclipse.emf.ecore.xmi.impl.GenericXMLResourceFactoryImpl;
import org.eclipse.emf.ecore.xml.type.AnyType;
import org.eclipse.emf.ecore.xml.type.XMLTypeDocumentRoot;
+import org.eclipse.jet.internal.runtime.model.EMFXMLModelLoader;
import org.eclipse.jet.internal.xpath.inspectors.AnyAttributeSetting;
import org.eclipse.jet.internal.xpath.inspectors.EMFEAttrAsElementWrapper;
import org.eclipse.jet.internal.xpath.inspectors.EObjectInspector;
+import org.eclipse.jet.internal.xpath.inspectors.EStructuralFeatureSettingInspector;
import org.eclipse.jet.xpath.inspector.AddElementException;
import org.eclipse.jet.xpath.inspector.CopyElementException;
import org.eclipse.jet.xpath.inspector.ExpandedName;
@@ -34,13 +37,12 @@ public class EObjectInspectorTests extends TestCase {
protected void xsdSetUp() throws Exception {
- URI fileURI = URI.createURI("platform:/plugin/org.eclipse.jet.tests/data/library.xml");
- Factory factory = new GenericXMLResourceFactoryImpl();
-
- xsdResource = factory.createResource(fileURI);
- xsdResource.load(null);
+ Object load = new EMFXMLModelLoader().load(new URL("platform:/plugin/org.eclipse.jet.tests/data/library.xml"));
+
+ assertTrue(load instanceof EObject);
- xsdDocumentRoot = (EObject) xsdResource.getContents().get(0);
+ xsdDocumentRoot = (EObject) load;
+ xsdResource = xsdDocumentRoot.eResource();
xsdRootElement = (EObject) xsdDocumentRoot.eContents().get(0);
}
@@ -124,6 +126,31 @@ public class EObjectInspectorTests extends TestCase {
assertEquals("name[" + i + "]", expectedAttributeNames[i], setting.getEStructuralFeature().getName());
assertEquals("value[" + i + "]", expectedAttributeValues[i], setting.get(true).toString());
}
+
+
+ }
+ /*
+ * Test method for 'org.eclipse.jet.internal.xpath.inspectors.EObjectInspector2.getAttributes(Object)'
+ */
+ public void testGetAttributes_hyphens_xml() {
+ Object elementA1 = Bug130552Workaround.getValue(xmlRootElement.getAny(), 0);
+ Object[] attributes = inspector.getAttributes(elementA1);
+
+ assertNotNull(attributes);
+ String[] expectedAttributeNames = new String[] {
+ "name",
+ "name-with_hyphen",
+ };
+ String[] expectedAttributeValues = new String[] {
+ "foo",
+ "hello",
+ };
+ assertEquals(expectedAttributeNames.length, attributes.length);
+ for (int i = 0; i < attributes.length; i++) {
+ EStructuralFeature.Setting setting = (EStructuralFeature.Setting) attributes[i];
+ assertEquals("name[" + i + "]", expectedAttributeNames[i], setting.getEStructuralFeature().getName());
+ assertEquals("value[" + i + "]", expectedAttributeValues[i], setting.get(true).toString());
+ }
}
/*
@@ -150,6 +177,38 @@ public class EObjectInspectorTests extends TestCase {
/*
* Test method for 'org.eclipse.jet.internal.xpath.inspectors.EObjectInspector2.getAttributes(Object)'
*/
+ public void testGetAttributes_xsd_hyphens() {
+ EObject projectElement = (EObject) xsdRootElement.eContents().get(0);
+ EObject beanModelElement = (EObject) projectElement.eContents().get(0);
+ EObject beanElement = (EObject) beanModelElement.eContents().get(0);
+ EObject attrElement = (EObject) beanElement.eContents().get(0);
+ Object[] attributes = inspector.getAttributes(attrElement);
+
+ assertNotNull(attributes);
+ String[] expectedAttributeNames = new String[] {
+ "kind",
+ "name",
+ "nameWithHyphen", // EMF has mangled name-with_hypen this to nameWithHyphen. Figure something out
+ "type",
+
+ };
+ String[] expectedAttributeValues = new String[] {
+ "FIELD",
+ "name",
+ "hello",
+ "String",
+ };
+ assertEquals(expectedAttributeNames.length, attributes.length);
+ for (int i = 0; i < attributes.length; i++) {
+ EStructuralFeature.Setting setting = (EStructuralFeature.Setting) attributes[i];
+ assertEquals("name[" + i + "]", expectedAttributeNames[i], setting.getEStructuralFeature().getName());
+ assertEquals("value[" + i + "]", expectedAttributeValues[i], setting.get(true).toString());
+ }
+ }
+
+ /*
+ * Test method for 'org.eclipse.jet.internal.xpath.inspectors.EObjectInspector2.getAttributes(Object)'
+ */
public void testGetAttributes_xsd_simpleElement() {
// testing the the <doc> element underneath attributeElement DOES NOT
// show up
@@ -157,8 +216,8 @@ public class EObjectInspectorTests extends TestCase {
EObject beanModelElement = (EObject) projectElement.eContents().get(0);
EObject thirdBeanElement = (EObject) beanModelElement.eContents().get(2);
EObject attributeElement = (EObject) thirdBeanElement.eContents().get(0);
- // verify that there is indeed a fourth EAttribute, but that we won't see it.
- assertEquals(4, attributeElement.eClass().getEAttributes().size());
+ // verify that there is indeed a fifth EAttribute, but that we won't see it.
+ assertEquals(5, attributeElement.eClass().getEAttributes().size());
Object[] attributes = inspector.getAttributes(attributeElement);
assertNotNull(attributes);
@@ -227,6 +286,14 @@ public class EObjectInspectorTests extends TestCase {
setting = (EStructuralFeature.Setting)a1Name;
assertEquals("name", setting.getEStructuralFeature().getName());
assertEquals("foo", setting.get(true));
+
+ Object a1HyphenedAttr = inspector.getNamedAttribute(elementA1, new ExpandedName("name-with_hyphen"));
+ assertNotNull(a1HyphenedAttr);
+ assertTrue("instanceof EStructuralFeature.Setting", a1HyphenedAttr instanceof EStructuralFeature.Setting);
+ setting = (EStructuralFeature.Setting)a1HyphenedAttr;
+ assertEquals("name-with_hyphen", setting.getEStructuralFeature().getName());
+ assertEquals("hello", setting.get(true));
+
}
/*
@@ -245,6 +312,25 @@ public class EObjectInspectorTests extends TestCase {
}
/*
+ * Test method for 'org.eclipse.jet.internal.xpath.inspectors.EObjectInspector2.getNamedAttribute(Object, ExpandedName)'
+ */
+ public void testGetNamedAttribute_xsd_hyphen() {
+ EObject projectElement = (EObject) xsdRootElement.eContents().get(0);
+ EObject beanModelElement = (EObject) projectElement.eContents().get(0);
+ EObject beanElement = (EObject) beanModelElement.eContents().get(0);
+ EObject attrElement = (EObject) beanElement.eContents().get(0);
+ Object attribute = inspector.getNamedAttribute(attrElement, new ExpandedName("name-with_hyphen"));
+
+ assertNotNull(attribute);
+ assertTrue("instanceof EStructuralFeature.Setting", attribute instanceof EStructuralFeature.Setting);
+
+ EStructuralFeature.Setting setting = (EStructuralFeature.Setting)attribute;
+ assertEquals("nameWithHyphen", setting.getEStructuralFeature().getName()); // the mangled EMF name
+ assertEquals("name-with_hyphen", new EStructuralFeatureSettingInspector().nameOf(setting));
+ assertEquals("hello", setting.get(true));
+ }
+
+ /*
* Test method for 'org.eclipse.jet.internal.xpath.inspectors.EObjectInspector2.createAttribute(Object, String, String)'
*/
public void testCreateAttribute_emf() {
@@ -374,7 +460,7 @@ public class EObjectInspectorTests extends TestCase {
/*
* Test method for 'org.eclipse.jet.internal.xpath.inspectors.EObjectInspector2.expandedNameOf(Object)'
*/
- public void testExpandedNameOf_xsd() {
+ public void testExpandedNameOf_xsd_rootElement() {
ExpandedName enEmfRoot = inspector.expandedNameOf(xsdRootElement);
assertEquals("http://www.example.org/beans:root", enEmfRoot.toString());
@@ -383,6 +469,26 @@ public class EObjectInspectorTests extends TestCase {
}
/*
+ * Test method for 'org.eclipse.jet.internal.xpath.inspectors.EObjectInspector2.expandedNameOf(Object)'
+ */
+ public void testExpandedNameOf_xsd_childElement() {
+ ExpandedName enProject = inspector.expandedNameOf(xsdRootElement.eContents().get(0));
+ assertEquals("project", enProject.toString());
+ }
+
+ /*
+ * Test method for 'org.eclipse.jet.internal.xpath.inspectors.EObjectInspector2.expandedNameOf(Object)'
+ */
+ public void testExpandedNameOf_xsd_hyphen() {
+ EObject projectElement = (EObject) xsdRootElement.eContents().get(0);
+ EObject beanModelElement = (EObject) projectElement.eContents().get(0);
+ EObject beanElement = (EObject) beanModelElement.eContents().get(0);
+ EObject attrElement = (EObject) beanElement.eContents().get(0);
+ Object attribute = inspector.getNamedAttribute(attrElement, new ExpandedName("name-with_hyphen"));
+ ExpandedName enProject = new EStructuralFeatureSettingInspector().expandedNameOf(attribute);
+ assertEquals("name-with_hyphen", enProject.toString());
+ }
+ /*
* Test method for 'org.eclipse.jet.internal.xpath.inspectors.EObjectInspector2.getDocumentRoot(Object)'
*/
public void testGetDocumentRoot_emf() {
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/EStructuralFeatureSettingTests.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/EStructuralFeatureSettingTests.java
index 47bc12f..fc94897 100644
--- a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/EStructuralFeatureSettingTests.java
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/EStructuralFeatureSettingTests.java
@@ -67,23 +67,7 @@ public class EStructuralFeatureSettingTests extends TestCase {
*/
public void testExpandedNameOf() {
ExpandedName expandedName = inspector.expandedNameOf(root_name_attr);
- assertEquals("http:///dataAccess.ecore:name", expandedName.toString());
- }
-
- /*
- * Test method for 'org.eclipse.jet.internal.xpath.EStructuralFeatureSettingInspector.getAttributes(Object)'
- */
- public void testGetAttributes() {
- Object[] attributes = inspector.getAttributes(root_name_attr);
- assertNull(attributes);
- }
-
- /*
- * Test method for 'org.eclipse.jet.internal.xpath.EStructuralFeatureSettingInspector.getNamedAttribute(Object, ExpandedName)'
- */
- public void testGetNamedAttribute() {
- Object namedAttribute = inspector.getNamedAttribute(root_name_attr, new ExpandedName("foo"));
- assertNull(namedAttribute);
+ assertEquals("name", expandedName.toString());
}
/*
@@ -99,7 +83,8 @@ public class EStructuralFeatureSettingTests extends TestCase {
*/
public void testGetChildren() {
Object[] children = inspector.getChildren(root_name_attr);
- assertNull(children);
+ assertNotNull(children);
+ assertEquals(0, children.length);
}
/*

Back to the top