Skip to main content
summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorpelder2008-09-27 07:08:34 -0400
committerpelder2008-09-27 07:08:34 -0400
commitfb93077879d8e1b21981f74ccf184289d3ebdab7 (patch)
treea88f3b89f61326d72752548cf8dba0ca006f0196 /tests
parente915cd0b4c4b6b5bbe4febb37e783f531d817145 (diff)
downloadorg.eclipse.jet-fb93077879d8e1b21981f74ccf184289d3ebdab7.tar.gz
org.eclipse.jet-fb93077879d8e1b21981f74ccf184289d3ebdab7.tar.xz
org.eclipse.jet-fb93077879d8e1b21981f74ccf184289d3ebdab7.zip
[248713] [Regression] NPE in XPath engine
Diffstat (limited to 'tests')
-rw-r--r--tests/org.eclipse.jet.tests/.settings/org.eclipse.jdt.ui.prefs4
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/inspectors/AbstractCopyElementTests.java82
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/inspectors/AllTests.java14
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/inspectors/EMFXMLCopyELementTests.java28
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/inspectors/XMLDOMCopyElementTests.java28
5 files changed, 156 insertions, 0 deletions
diff --git a/tests/org.eclipse.jet.tests/.settings/org.eclipse.jdt.ui.prefs b/tests/org.eclipse.jet.tests/.settings/org.eclipse.jdt.ui.prefs
new file mode 100644
index 0000000..2e01db6
--- /dev/null
+++ b/tests/org.eclipse.jet.tests/.settings/org.eclipse.jdt.ui.prefs
@@ -0,0 +1,4 @@
+#Thu Sep 25 16:24:39 EDT 2008
+eclipse.preferences.version=1
+org.eclipse.jdt.ui.javadoc=false
+org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8"?><templates><template autoinsert\="true" context\="gettercomment_context" deleted\="false" description\="Comment for getter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name\="gettercomment">/**\r\n * @return the ${bare_field_name}\r\n */</template><template autoinsert\="true" context\="settercomment_context" deleted\="false" description\="Comment for setter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.settercomment" name\="settercomment">/**\r\n * @param ${param} the ${bare_field_name} to set\r\n */</template><template autoinsert\="true" context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment">/**\r\n * ${tags}\r\n */</template><template autoinsert\="false" context\="filecomment_context" deleted\="false" description\="Comment for created Java files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.filecomment" name\="filecomment">/*******************************************************************************\r\n * Copyright (c) ${year} IBM Corporation and others.\r\n * All rights reserved. This program and the accompanying materials\r\n * are made available under the terms of the Eclipse Public License v1.0\r\n * which accompanies this distribution, and is available at\r\n * http\://www.eclipse.org/legal/epl-v10.html\r\n *\r\n * Contributors\:\r\n * IBM - Initial API and implementation\r\n *\r\n * /\r\n *******************************************************************************/\r\n</template><template autoinsert\="true" context\="typecomment_context" deleted\="false" description\="Comment for created types" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.typecomment" name\="typecomment">/**\r\n * @author ${user}\r\n *\r\n * ${tags}\r\n */</template><template autoinsert\="true" context\="fieldcomment_context" deleted\="false" description\="Comment for fields" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment">/**\r\n * \r\n */</template><template autoinsert\="true" context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name\="methodcomment">/**\r\n * ${tags}\r\n */</template><template autoinsert\="true" context\="overridecomment_context" deleted\="false" description\="Comment for overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name\="overridecomment">/* (non-Javadoc)\r\n * ${see_to_overridden}\r\n */</template><template autoinsert\="true" context\="delegatecomment_context" deleted\="false" description\="Comment for delegate methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name\="delegatecomment">/**\r\n * ${tags}\r\n * ${see_to_target}\r\n */</template><template autoinsert\="true" context\="newtype_context" deleted\="false" description\="Newly created files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.newtype" name\="newtype">${filecomment}\r\n${package_declaration}\r\n\r\n${typecomment}\r\n${type_declaration}</template><template autoinsert\="true" context\="classbody_context" deleted\="false" description\="Code in new class type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.classbody" name\="classbody">\r\n</template><template autoinsert\="true" context\="interfacebody_context" deleted\="false" description\="Code in new interface type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.interfacebody" name\="interfacebody">\r\n</template><template autoinsert\="true" context\="enumbody_context" deleted\="false" description\="Code in new enum type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.enumbody" name\="enumbody">\r\n</template><template autoinsert\="true" context\="annotationbody_context" deleted\="false" description\="Code in new annotation type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.annotationbody" name\="annotationbody">\r\n</template><template autoinsert\="true" context\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.catchblock" name\="catchblock">// ${todo} Auto-generated catch block\r\n${exception_var}.printStackTrace();</template><template autoinsert\="true" context\="methodbody_context" deleted\="false" description\="Code in created method stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodbody" name\="methodbody">// ${todo} Auto-generated method stub\r\n${body_statement}</template><template autoinsert\="true" context\="constructorbody_context" deleted\="false" description\="Code in created constructor stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorbody" name\="constructorbody">${body_statement}\r\n// ${todo} Auto-generated constructor stub</template><template autoinsert\="true" context\="getterbody_context" deleted\="false" description\="Code in created getters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.getterbody" name\="getterbody">return ${field};</template><template autoinsert\="true" context\="setterbody_context" deleted\="false" description\="Code in created setters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.setterbody" name\="setterbody">${field} \= ${param};</template></templates>
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/inspectors/AbstractCopyElementTests.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/inspectors/AbstractCopyElementTests.java
new file mode 100644
index 0000000..1e95dd0
--- /dev/null
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/inspectors/AbstractCopyElementTests.java
@@ -0,0 +1,82 @@
+/*******************************************************************************
+ * Copyright (c) 2008 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * /
+ *******************************************************************************/
+package org.eclipse.jet.tests.xpath.inspectors;
+
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+import org.eclipse.jet.runtime.model.IModelLoader;
+import org.eclipse.jet.xpath.XPath;
+import org.eclipse.jet.xpath.XPathException;
+import org.eclipse.jet.xpath.XPathExpression;
+import org.eclipse.jet.xpath.XPathFactory;
+import org.eclipse.jet.xpath.inspector.CopyElementException;
+import org.eclipse.jet.xpath.inspector.IElementInspector;
+import org.eclipse.jet.xpath.inspector.InspectorManager;
+import org.eclipse.jet.xpath.inspector.INodeInspector.NodeKind;
+
+public abstract class AbstractCopyElementTests extends TestCase {
+
+ private Object loadDocument(String documentPath) throws IOException {
+ IModelLoader loader = getModelLoader();
+ return loader.loadFromString(documentPath, getModelKind());
+ }
+
+ protected String getModelKind() {
+ return "xml";
+ }
+
+ protected abstract IModelLoader getModelLoader();
+
+ public void testCopyDocument() throws IOException, CopyElementException, XPathException {
+ String docAContent = "<rootA><element value=\"A\"/></rootA>";
+ String docBContent = "<rootB><element value=\"B\"/></rootB>";
+ Object docA = loadDocument(docAContent);
+ Object docB = loadDocument(docBContent);
+
+ final InspectorManager im = InspectorManager.getInstance();
+
+ final Object rootElementB = getRootElement(docB, im);
+ final IElementInspector inspector = (IElementInspector) im.getInspector(rootElementB);
+
+ final Object copiedDocA = inspector.copyElement(rootElementB, docA, "copied", true);
+
+ final XPath XPath = XPathFactory.newInstance().newXPath(null);
+ final XPathExpression xRootA_element_value = XPath.compile("rootA/element/@value");
+ final XPathExpression xRootB_element_value = XPath.compile("rootB/element/@value");
+ final XPathExpression xRootB_RootA_element_value = XPath.compile("rootB/copied/rootA/element/@value");
+
+
+ assertEquals("Original A", "A", xRootA_element_value.evaluateAsString(docA));
+ assertEquals("Original B", "B", xRootB_element_value.evaluateAsString(docB));
+ assertEquals("Copied A", "A", xRootA_element_value.evaluateAsString(copiedDocA));
+ assertEquals("Copied A, within B", "A", xRootB_RootA_element_value.evaluateAsString(docB));
+
+
+
+ }
+
+ private Object getRootElement(Object docA, final InspectorManager im) {
+ final Object[] children = im.getInspector(docA).getChildren(docA);
+
+ for (int i = 0; i < children.length; i++) {
+ if(im.getInspector(children[i]).getNodeKind(children[i]) == NodeKind.ELEMENT) {
+ return children[i];
+ }
+ }
+ return null;
+ }
+
+
+}
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/inspectors/AllTests.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/inspectors/AllTests.java
index 7cb6e9c..754efb3 100644
--- a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/inspectors/AllTests.java
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/inspectors/AllTests.java
@@ -1,3 +1,15 @@
+/*******************************************************************************
+ * Copyright (c) 2008 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * /
+ *******************************************************************************/
package org.eclipse.jet.tests.xpath.inspectors;
import junit.framework.Test;
@@ -9,6 +21,8 @@ public class AllTests {
TestSuite suite = new TestSuite(
"Test for org.eclipse.jet.tests.xpath.inspectors");
//$JUnit-BEGIN$
+ suite.addTestSuite(XMLDOMCopyElementTests.class);
+ suite.addTestSuite(EMFXMLCopyELementTests.class);
suite.addTestSuite(EMFXML24SubstitutionGroupTests.class);
suite.addTestSuite(LegacyEMFXMLSubstitutionGroupTests.class);
//$JUnit-END$
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/inspectors/EMFXMLCopyELementTests.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/inspectors/EMFXMLCopyELementTests.java
new file mode 100644
index 0000000..968f03a
--- /dev/null
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/inspectors/EMFXMLCopyELementTests.java
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * Copyright (c) 2008 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * /
+ *******************************************************************************/
+package org.eclipse.jet.tests.xpath.inspectors;
+
+import org.eclipse.jet.internal.runtime.model.EMFXMLModelLoader;
+import org.eclipse.jet.runtime.model.IModelLoader;
+
+/**
+ * Perform CopyElementTests using the EMF XML Model loader
+ *
+ */
+public class EMFXMLCopyELementTests extends AbstractCopyElementTests {
+
+ protected IModelLoader getModelLoader() {
+ return new EMFXMLModelLoader();
+ }
+
+}
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/inspectors/XMLDOMCopyElementTests.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/inspectors/XMLDOMCopyElementTests.java
new file mode 100644
index 0000000..674acd3
--- /dev/null
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/inspectors/XMLDOMCopyElementTests.java
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * Copyright (c) 2008 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * /
+ *******************************************************************************/
+package org.eclipse.jet.tests.xpath.inspectors;
+
+import org.eclipse.jet.internal.runtime.model.XMLDOMLoader;
+import org.eclipse.jet.runtime.model.IModelLoader;
+
+/**
+ * Perform CopyElementTests using the XML DOM Model loader
+ *
+ */
+public class XMLDOMCopyElementTests extends AbstractCopyElementTests {
+
+ protected IModelLoader getModelLoader() {
+ return new XMLDOMLoader();
+ }
+
+}

Back to the top