You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlbeans.apache.org by ce...@apache.org on 2005/09/30 19:20:53 UTC
svn commit: r292814 - in /xmlbeans/trunk/test:
cases/xbean/dom/ComplexTypeTest.xsd cases/xbean/dom/dumb.xsd
cases/xbean/dom/id.xml cases/xbean/dom/id.xsd
src/dom/checkin/DirtyCacheTests.java src/dom/detailed/IDTest.java
Author: cezar
Date: Fri Sep 30 10:20:46 2005
New Revision: 292814
URL: http://svn.apache.org/viewcvs?rev=292814&view=rev
Log:
Contributed by Rajiv Balachandran. Adding Test cases for DOM fixes including support for getElementById
Added:
xmlbeans/trunk/test/cases/xbean/dom/ComplexTypeTest.xsd
xmlbeans/trunk/test/cases/xbean/dom/dumb.xsd
xmlbeans/trunk/test/cases/xbean/dom/id.xml
xmlbeans/trunk/test/cases/xbean/dom/id.xsd
xmlbeans/trunk/test/src/dom/checkin/DirtyCacheTests.java
xmlbeans/trunk/test/src/dom/detailed/IDTest.java
Added: xmlbeans/trunk/test/cases/xbean/dom/ComplexTypeTest.xsd
URL: http://svn.apache.org/viewcvs/xmlbeans/trunk/test/cases/xbean/dom/ComplexTypeTest.xsd?rev=292814&view=auto
==============================================================================
--- xmlbeans/trunk/test/cases/xbean/dom/ComplexTypeTest.xsd (added)
+++ xmlbeans/trunk/test/cases/xbean/dom/ComplexTypeTest.xsd Fri Sep 30 10:20:46 2005
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+/* Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+-->
+<xsd:schema
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns="http://xbean/dom/ComplexTypeTest"
+ targetNamespace="http://xbean/dom/ComplexTypeTest"
+ >
+ <!--element only-->
+ <xsd:complexType name="elementT">
+ <xsd:sequence>
+ <xsd:element name="child1" type="xsd:integer"/>
+ <xsd:element name="child2" type="xsd:integer"/>
+ <xsd:element name="child3" type="xsd:integer"/>
+ </xsd:sequence>
+ </xsd:complexType>
+ <!--mixed-->
+ <xsd:complexType mixed="true" name="mixedT">
+ <xsd:sequence>
+ <xsd:element name="child1" type="xsd:integer"/>
+ <xsd:element name="child2" type="xsd:integer"/>
+ <xsd:element name="child3" type="xsd:integer"/>
+ </xsd:sequence>
+ </xsd:complexType>
+
+ <xsd:complexType name="emptyT">
+ <xsd:attribute name="emptyAttr" type="xsd:string"/>
+ </xsd:complexType>
+ <xsd:complexType name="emptyMixedT" mixed="true">
+ <xsd:attribute name="emptyAttr" type="xsd:string"/>
+ </xsd:complexType>
+
+ <!--empty-->
+ <xsd:element name="EltType" type="elementT"/>
+ <xsd:element name="MixedType" type="mixedT"/>
+ <xsd:element name="EmptyType" type="emptyT"/>
+ <xsd:element name="EmptyMixedType" type="emptyT"/>
+
+ <xsd:element name="MixedFixedElt" fixed="abc">
+ <xsd:complexType mixed="true">
+ <xsd:sequence minOccurs="0">
+ <xsd:element name="a" type="xsd:string"/>
+ </xsd:sequence>
+ </xsd:complexType>
+ </xsd:element>
+</xsd:schema>
\ No newline at end of file
Added: xmlbeans/trunk/test/cases/xbean/dom/dumb.xsd
URL: http://svn.apache.org/viewcvs/xmlbeans/trunk/test/cases/xbean/dom/dumb.xsd?rev=292814&view=auto
==============================================================================
--- xmlbeans/trunk/test/cases/xbean/dom/dumb.xsd (added)
+++ xmlbeans/trunk/test/cases/xbean/dom/dumb.xsd Fri Sep 30 10:20:46 2005
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+/* Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+-->
+
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns="http://xbean/dom/dumbNS"
+ targetNamespace="http://xbean/dom/dumbNS"
+ elementFormDefault="qualified">
+
+
+ <xs:attribute name="a" type="xs:integer" />
+ <xs:attribute name="b" type="xs:integer" />
+ <xs:attribute name="c" type="xs:integer" />
+
+ <xs:element name="root">
+ <xs:complexType>
+ <xs:attribute ref="b"/>
+ </xs:complexType>
+ </xs:element>
+
+</xs:schema>
Added: xmlbeans/trunk/test/cases/xbean/dom/id.xml
URL: http://svn.apache.org/viewcvs/xmlbeans/trunk/test/cases/xbean/dom/id.xml?rev=292814&view=auto
==============================================================================
--- xmlbeans/trunk/test/cases/xbean/dom/id.xml (added)
+++ xmlbeans/trunk/test/cases/xbean/dom/id.xml Fri Sep 30 10:20:46 2005
@@ -0,0 +1,87 @@
+<?xml version="1.0"?><?TEST-STYLE PIDATA?>
+<!--
+/* Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+-->
+<!-- inline DTD for ID -->
+<!DOCTYPE staff [
+<!ELEMENT emp:employee (emp:employeeId,nm:name,emp:position,emp:salary,emp:gender,emp:address) >
+<!ATTLIST emp:employee xmlns:emp CDATA #IMPLIED>
+<!ATTLIST emp:employee xmlns:nm CDATA #IMPLIED>
+<!ATTLIST emp:employee defaultAttr CDATA 'defaultVal'>
+
+<!ELEMENT emp:employeeId (#PCDATA) >
+
+<!ELEMENT nm:name (#PCDATA) >
+
+<!ELEMENT emp:position (#PCDATA) >
+
+<!ELEMENT emp:salary (#PCDATA) >
+
+<!ELEMENT emp:gender (#PCDATA) >
+
+<!ELEMENT emp:address (#PCDATA) >
+<!ATTLIST emp:address emp:domestic CDATA #IMPLIED>
+<!ATTLIST emp:address street CDATA #IMPLIED>
+<!ATTLIST emp:address emp:zone ID #IMPLIED>
+<!ATTLIST emp:address emp:district CDATA 'DISTRICT'>
+<!ATTLIST emp:address emp:local1 CDATA 'FALSE'>
+]>
+<!-- This is comment number 1.-->
+<staff>
+ <employee xmlns="http://www.nist.gov" xmlns:dmstc="http://www.usa.com">
+ <employeeId>EMP0001</employeeId>
+ <name>Margaret Martin</name>
+ <position>Accountant</position>
+ <salary>56,000</salary>
+ <gender>Female</gender>
+ <address dmstc:domestic="Yes">1230 North Ave. Dallas, Texas 98551</address>
+ </employee>
+ <employee xmlns:dmstc="http://www.usa.com">
+ <employeeId>EMP0002</employeeId>
+ <name>Martha Raynolds
+<![CDATA[This is a CDATASection with EntityReference number 2 &ent2;]]>
+<![CDATA[This is an adjacent CDATASection with a reference to a tab &tab;]]></name>
+ <position>Secretary</position>
+ <salary>35,000</salary>
+ <gender>Female</gender>
+ <address dmstc:domestic="Yes" street="Yes"> Dallas,
+ 98554</address>
+ </employee>
+ <employee xmlns:dmstc="http://www.netzero.com">
+ <employeeId>EMP0003</employeeId>
+ <name>Roger
+ Jones</name>
+ <position>Department Manager</position>
+ <salary>100,000</salary>
+ <gender></gender>
+ <address dmstc:domestic="Yes" street="No">PO Box 27 Irving, texas 98553</address>
+ </employee>
+ <emp:employee xmlns:emp="http://www.nist.gov" xmlns:nm="http://www.altavista.com" > <emp:employeeId>EMP0004</emp:employeeId>
+ <nm:name>Jeny Oconnor</nm:name>
+ <emp:position>Personnel Director</emp:position>
+ <emp:salary>95,000</emp:salary>
+ <emp:gender>Female</emp:gender>
+ <emp:address emp:domestic="Yes" street="Y" emp:zone="CANADA" emp:local1="TRUE">27 South Road. Dallas, texas 98556</emp:address>
+ </emp:employee>
+ <employee xmlns:emp2="http://www.nist.gov">
+ <employeeId>EMP0005</employeeId>
+ <name>Robert Myers</name>
+ <position>Computer Specialist</position>
+ <salary>90,000</salary>
+ <gender>male</gender>
+ <address street="Yes" xmlns="http://www.nist.gov">1821 Nordic. Road, Irving Texas 98558</address>
+ </employee>
+ </staff>
Added: xmlbeans/trunk/test/cases/xbean/dom/id.xsd
URL: http://svn.apache.org/viewcvs/xmlbeans/trunk/test/cases/xbean/dom/id.xsd?rev=292814&view=auto
==============================================================================
--- xmlbeans/trunk/test/cases/xbean/dom/id.xsd (added)
+++ xmlbeans/trunk/test/cases/xbean/dom/id.xsd Fri Sep 30 10:20:46 2005
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+ <!--
+/* Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+-->
+<!DOCTYPE testid [
+<!ELEMENT person (#PCDATA) >
+<!ATTLIST person
+ id ID #REQUIRED
+>
+]>
+<xsd:schema targetNamespace="http://xbean/dom/id"
+xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+xmlns:tns="http://xbean/dom/id"
+elementFormDefault="qualified"
+>
+
+ <xsd:element name="foo">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element ref="tns:person" />
+ </xsd:sequence>
+ <xsd:attribute name="myid" type="xsd:ID" use="required"/>
+ </xsd:complexType>
+ </xsd:element>
+
+ <xsd:element name="person">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="firstname" type="xsd:string" />
+ </xsd:sequence>
+ </xsd:complexType>
+ </xsd:element>
+</xsd:schema>
+
Added: xmlbeans/trunk/test/src/dom/checkin/DirtyCacheTests.java
URL: http://svn.apache.org/viewcvs/xmlbeans/trunk/test/src/dom/checkin/DirtyCacheTests.java?rev=292814&view=auto
==============================================================================
--- xmlbeans/trunk/test/src/dom/checkin/DirtyCacheTests.java (added)
+++ xmlbeans/trunk/test/src/dom/checkin/DirtyCacheTests.java Fri Sep 30 10:20:46 2005
@@ -0,0 +1,83 @@
+/* Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package dom.checkin;
+
+import junit.framework.TestCase;
+import org.apache.xmlbeans.XmlCursor;
+import org.w3c.dom.Node;
+
+import xbean.dom.complexTypeTest.ElementT;
+import xbean.dom.complexTypeTest.EltTypeDocument;
+import xbean.dom.complexTypeTest.MixedT;
+import xbean.dom.complexTypeTest.MixedTypeDocument;
+import xbean.dom.dumbNS.RootDocument;
+
+import java.math.BigInteger;
+
+public class DirtyCacheTests extends TestCase
+{
+
+ public void testDirtyValue()throws Exception{
+ EltTypeDocument o = EltTypeDocument.Factory.newInstance();
+ ElementT t = o.addNewEltType();
+ t.setChild1(new BigInteger("30"));
+ Node n = o.getDomNode();
+ n = n.getFirstChild();
+ n = n.getFirstChild();
+ n = n.getFirstChild();//text
+ String s = n.getNodeValue();
+ System.out.println(n.getNodeName()+" "+ s);
+ t.setChild1(new BigInteger("5"));
+ s = n.getNodeValue();
+ System.out.println(n.getNodeName()+" "+ s);
+ }
+
+ public void testDirtyValue1()throws Exception{
+ MixedTypeDocument o = MixedTypeDocument.Factory.newInstance();
+ MixedT testElt = o.addNewMixedType();
+ assertEquals(null, testElt.getChild1());
+ assertEquals(null, testElt.xgetChild1());
+ testElt.setChild2(new BigInteger("5"));
+ testElt.setChild3(new BigInteger("1"));
+ testElt.setChild1(new BigInteger("0"));
+
+ XmlCursor cur = testElt.newCursor();
+ cur.toFirstContentToken();
+ cur.insertChars("Random mixed content");
+ Node n = o.getDomNode();
+ n = n.getFirstChild();
+ n = n.getFirstChild();
+
+ String s = n.getNodeValue();
+ System.out.println(n.getNodeName()+" "+ s);
+ n=n.getNextSibling();
+ n = n.getFirstChild();
+
+ s = n.getNodeValue();
+ System.out.println(n.getNodeName()+" "+ s);
+ }
+
+ public void testDirtyValue2()throws Exception{
+ RootDocument o = RootDocument.Factory.newInstance();
+ RootDocument.Root testElt = o.addNewRoot();
+ testElt.setB(new BigInteger("5"));
+ Node n = o.getDomNode();
+ n = n.getFirstChild();
+ n = n.getAttributes().getNamedItem("b");
+
+ System.out.println(n.getNodeName()+" "+ n.getNodeValue());
+ }
+}
Added: xmlbeans/trunk/test/src/dom/detailed/IDTest.java
URL: http://svn.apache.org/viewcvs/xmlbeans/trunk/test/src/dom/detailed/IDTest.java?rev=292814&view=auto
==============================================================================
--- xmlbeans/trunk/test/src/dom/detailed/IDTest.java (added)
+++ xmlbeans/trunk/test/src/dom/detailed/IDTest.java Fri Sep 30 10:20:46 2005
@@ -0,0 +1,121 @@
+/* Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package dom.detailed;
+
+import junit.framework.TestCase;
+import org.apache.xmlbeans.*;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import tools.util.JarUtil;
+import xbean.dom.id.FooDocument;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.FileOutputStream;
+import java.io.OutputStreamWriter;
+import java.util.*;
+
+import common.Common;
+
+public class IDTest extends TestCase
+{
+ String P = File.separator;
+
+ // Test the getElementById() DOM API with DTDs , run with jvm arg -Dcases.location
+ public void testGetElemById() throws Exception
+ {
+ Document doc;
+ Element element;
+ String tagname;
+ XmlOptions xmlOptions = new XmlOptions();
+ xmlOptions.setLoadUseDefaultResolver();
+ XmlObject o = XmlObject.Factory.parse(new File(Common.CASEROOT + P + "xbean" + P + "dom" + P + "id.xml"));
+ doc = (Document) o.getDomNode();
+ element = doc.getElementById("CANADA");
+ assertNotNull(element);
+
+ tagname = element.getTagName();
+ assertEquals("throw_Equals", "emp:address", tagname);
+ assertNull(doc.getDoctype());
+ }
+
+ // test getElementById() with schema containing DTD with ID definition for untyped XmlObject
+ public void testIDSchema() throws Exception
+ {
+ XmlObject o = XmlObject.Factory.parse("<!DOCTYPE xs:schema PUBLIC \"-//W3C//DTD XMLSCHEMA 200102//EN\" \"XMLSchema.dtd\" [\n" +
+ "<!ELEMENT first_name (#PCDATA)>\n" +
+ "<!ELEMENT hobby (#PCDATA)>\n" +
+ "<!ELEMENT homepage EMPTY>\n" +
+ "<!ATTLIST homepage href CDATA #REQUIRED>\n" +
+ "<!ELEMENT last_name (#PCDATA)>\n" +
+ "<!ELEMENT middle_initial (#PCDATA)>\n" +
+ "<!ELEMENT name (first_name, middle_initial?, last_name)>\n" +
+ "<!ELEMENT person (name, profession+, homepage?, hobby?)>\n" +
+ "<!ATTLIST person\n" +
+ " born CDATA #REQUIRED\n" +
+ " died CDATA #REQUIRED\n" +
+ " id ID #REQUIRED\n" +
+ ">\n" +
+ "<!ELEMENT profession (#PCDATA)>\n" +
+ "]>" +
+ "<person id=\"25\" born=\"yday\" />");
+ Document n = (Document) o.getDomNode();
+ Element elem = n.getElementById("25");
+ assertNotNull(elem);
+ System.out.println("Elem: " + elem.getNodeName());
+
+ Element elemInvalid = n.getElementById("100");
+ assertNull(elemInvalid);
+ }
+
+ // typed XmlObject
+ public void testSchemaWithDTD() throws Exception
+ {
+ XmlOptions opt = new XmlOptions();
+ List err = new ArrayList();
+ opt.setErrorListener(err);
+
+ String instance = "<foo xmlns='http://xbean/dom/id'>" +
+ " <person id=\"25\"/>" +
+ "</foo>";
+ try
+ {
+ FooDocument fooDoc = FooDocument.Factory.parse(instance, opt);
+
+ Document d = (Document)fooDoc.getDomNode();
+ Element elem = d.getElementById("25");
+ assertNotNull(elem);
+
+ Element elemInvalid = d.getElementById("100");
+ assertNull(elemInvalid);
+ }
+ catch (XmlException xme)
+ {
+ Collection xmlerrs = xme.getErrors();
+ for (Iterator iterator1 = xmlerrs.iterator(); iterator1.hasNext();) {
+ XmlError xerr = (XmlError) iterator1.next();
+ System.out.println("Exception:" + xerr.getMessage());
+ }
+ throw (new XmlException(new Throwable("XmlException occured")));
+ }
+
+ // parse errors
+ for (Iterator iterator = err.iterator(); iterator.hasNext();) {
+ System.out.println("Err:" + iterator.next());
+ }
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: commits-help@xmlbeans.apache.org