Added: webservices/commons/trunk/modules/XmlSchema/test-resources/annotation.xsd
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/test-resources/annotation.xsd?rev=418072&view=auto
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/test-resources/annotation.xsd 
(added)
+++ webservices/commons/trunk/modules/XmlSchema/test-resources/annotation.xsd 
Thu Jun 29 08:23:22 2006
@@ -0,0 +1,64 @@
+<!--
+ * Copyright 2004,2005 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.
+ *
+-->
+<schema xmlns="http://www.w3.org/2001/XMLSchema";
+        xmlns:xsd="http://www.w3.org/2001/XMLSchema";
+        xmlns:tns="http://soapinterop.org/types";
+        xmlns:abc="http://www.abc.com/validation";
+        targetNamespace="http://soapinterop.org/types";>
+
+  <simpleType name="emptyAppinfo">
+    <annotation>
+      <documentation source="http://test/source/doc"; 
xml:lang="en">testing987</documentation>
+      <appinfo/>
+    </annotation>
+    <restriction base="string">
+      <length value="1"/>
+    </restriction>
+  </simpleType>
+  
+  <simpleType name="emptyDocumentation">
+    <annotation>
+      <documentation/>
+      <appinfo source="http://test/source/appinfo";>testing123</appinfo>
+    </annotation>
+    <restriction base="string">
+      <length value="2"/>
+    </restriction>
+  </simpleType>
+
+  <simpleType name="emptyAppinfoDocumentation">
+    <annotation>
+      <documentation/>
+      <appinfo/>
+    </annotation>
+    <restriction base="string">
+      <length value="1"/>
+    </restriction>
+  </simpleType>
+
+  <simpleType name="annotationTest">
+    <annotation>
+      <documentation source="http://test/source/doc"; 
xml:lang="en">testing987</documentation>
+      <appinfo source="http://test/source/appinfo";>testing123</appinfo>
+    </annotation>
+    <restriction base="string">
+      <length value="1"/>
+    </restriction>
+  </simpleType>
+
+</schema>

Added: 
webservices/commons/trunk/modules/XmlSchema/test/tests/AnnotationTest.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/test/tests/AnnotationTest.java?rev=418072&view=auto
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/test/tests/AnnotationTest.java 
(added)
+++ webservices/commons/trunk/modules/XmlSchema/test/tests/AnnotationTest.java 
Thu Jun 29 08:23:22 2006
@@ -0,0 +1,290 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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 tests;
+
+import java.io.FileInputStream;
+import java.io.InputStream;
+
+import java.util.Iterator;
+import java.util.Set;
+import java.util.HashSet;
+
+import javax.xml.namespace.QName;
+import javax.xml.transform.stream.StreamSource;
+
+import junit.framework.TestCase;
+
+import org.w3c.dom.Attr;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Node;
+
+import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.apache.ws.commons.schema.XmlSchemaSimpleType;
+import org.apache.ws.commons.schema.XmlSchemaAnnotation;
+import org.apache.ws.commons.schema.XmlSchemaObject;
+import org.apache.ws.commons.schema.XmlSchemaAppInfo;
+import org.apache.ws.commons.schema.XmlSchemaDocumentation;
+import org.apache.ws.commons.schema.XmlSchemaElement;
+import org.apache.ws.commons.schema.XmlSchemaObjectCollection;
+
+
+public class AnnotationTest extends TestCase {
+
+    /**
+     * This method will test for when the appinfo
+     * element of an annotation doesn't include a
+     * source attribute and doesn't contain any 
+     * content.
+     *
+     * @throws Exception Any exception encountered
+     */
+    public void testEmptyAppInfo() throws Exception {
+
+        /*
+        <simpleType name="emptyAppinfo">
+          <annotation>
+            <documentation source="http://test/source/doc"; 
xml:lang="en">testing987</documentation>
+            <appinfo/>
+          </annotation>
+          <restriction base="string">
+            <length value="1"/>
+          </restriction>
+        </simpleType>
+        */
+
+        QName TYPE_QNAME = new QName("http://soapinterop.org/types";,
+                                     "emptyAppinfo");
+        InputStream is = new FileInputStream("test-resources/annotation.xsd");
+        XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+        XmlSchema schema = schemaCol.read(new StreamSource(is), null);
+
+        XmlSchemaSimpleType simpleType =
+            (XmlSchemaSimpleType)schemaCol.getTypeByQName(TYPE_QNAME);
+        assertNotNull(simpleType);
+
+        XmlSchemaAnnotation xsa = simpleType.getAnnotation();
+        assertNotNull(xsa);
+
+        XmlSchemaObjectCollection col = xsa.getItems();
+        assertEquals(1, col.getCount());
+
+        Set s = new HashSet();
+        s.add(XmlSchemaDocumentation.class.getName());
+        for (int i = 0; i < col.getCount(); i++) {
+            XmlSchemaObject o = col.getItem(i);
+            if (o instanceof XmlSchemaAppInfo) {
+                fail("The appinfo element did not contain a source"
+                     + " attribute or any content, so this element"
+                     + " was not exptected to be found.");
+            } else if (o instanceof XmlSchemaDocumentation) {
+                assertEquals("en",
+                             ((XmlSchemaDocumentation)o).getLanguage());
+                assertEquals("http://test/source/doc";,
+                             ((XmlSchemaDocumentation)o).getSource());
+                NodeList nl = ((XmlSchemaDocumentation)o).getMarkup();
+                for (int j = 0; j < nl.getLength(); j++) {
+                    Node n = nl.item(j);
+                    if (n.getNodeType() == Node.TEXT_NODE) {
+                        assertEquals("testing987", n.getTextContent());
+                    }
+                }
+            }
+            assertTrue(s.remove(o.getClass().getName()));
+        }
+        assertTrue("The set should have been empty, but instead contained: "
+                   + s + ".",
+                   s.isEmpty());
+    }
+
+    /**
+     * This method will test for when the documentation
+     * element of an annotation doesn't include a
+     * source attribute or xml:lang attribute and doesn't
+     * contain any content.
+     *
+     * @throws Exception Any exception encountered
+     */
+    public void testEmptyDocumentation() throws Exception {
+
+        /*
+        <simpleType name="emptyDocumentation">
+          <annotation>
+            <documentation/>
+            <appinfo source="http://test/source/appinfo";>testing123</appinfo>
+          </annotation>
+          <restriction base="string">
+            <length value="2"/>
+          </restriction>
+        </simpleType>
+        */
+
+        QName TYPE_QNAME = new QName("http://soapinterop.org/types";,
+                                     "emptyDocumentation");
+        InputStream is = new FileInputStream("test-resources/annotation.xsd");
+        XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+        XmlSchema schema = schemaCol.read(new StreamSource(is), null);
+
+        XmlSchemaSimpleType simpleType =
+            (XmlSchemaSimpleType)schemaCol.getTypeByQName(TYPE_QNAME);
+        assertNotNull(simpleType);
+
+        XmlSchemaAnnotation xsa = simpleType.getAnnotation();
+        assertNotNull(xsa);
+
+        XmlSchemaObjectCollection col = xsa.getItems();
+        assertEquals(1, col.getCount());
+
+        Set s = new HashSet();
+        s.add(XmlSchemaAppInfo.class.getName());
+        for (int i = 0; i < col.getCount(); i++) {
+            XmlSchemaObject o = col.getItem(i);
+            if (o instanceof XmlSchemaAppInfo) {
+                assertEquals("http://test/source/appinfo";,
+                             ((XmlSchemaAppInfo)o).getSource());
+                NodeList nl = ((XmlSchemaAppInfo)o).getMarkup();
+                for (int j = 0; j < nl.getLength(); j++) {
+                    Node n = nl.item(j);
+                    if (n.getNodeType() == Node.TEXT_NODE) {
+                        assertEquals("testing123", n.getTextContent());
+                    }
+                }
+            } else if (o instanceof XmlSchemaDocumentation) {
+                fail("The documentation element did not contain a source"
+                     + " attribute or any content, so this element"
+                     + " was not exptected to be found.");
+            }
+            assertTrue(s.remove(o.getClass().getName()));
+        }
+        assertTrue("The set should have been empty, but instead contained: "
+                   + s + ".",
+                   s.isEmpty());
+    }
+
+
+    /**
+     * This method will test for when the documentation
+     * and appinfo elements of an annotation don't include
+     * anything.
+     *
+     * @throws Exception Any exception encountered
+     */
+    public void testEmptyAppinfoDocumentation() throws Exception {
+
+        /*
+        <simpleType name="emptyAppinfoDocumentation">
+          <annotation>
+            <documentation/>
+            <appinfo/>
+          </annotation>
+          <restriction base="string">
+            <length value="1"/>
+          </restriction>
+        </simpleType>
+        */
+
+        QName TYPE_QNAME = new QName("http://soapinterop.org/types";,
+                                     "emptyAppinfoDocumentation");
+        InputStream is = new FileInputStream("test-resources/annotation.xsd");
+        XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+        XmlSchema schema = schemaCol.read(new StreamSource(is), null);
+
+        XmlSchemaSimpleType simpleType =
+            (XmlSchemaSimpleType)schemaCol.getTypeByQName(TYPE_QNAME);
+        assertNotNull(simpleType);
+
+        XmlSchemaAnnotation xsa = simpleType.getAnnotation();
+        assertNotNull(xsa);
+
+        XmlSchemaObjectCollection col = xsa.getItems();
+        assertEquals(0, col.getCount());
+
+    }
+
+    /**
+     * This method will test for when the documentation
+     * and appinfo elements contain all the information.
+     *
+     * @throws Exception Any exception encountered
+     */
+    public void testFullDocumentationAppinfo() throws Exception {
+
+        /*
+        <simpleType name="annotationTest">
+          <annotation>
+            <documentation source="http://test/source/doc"; 
xml:lang="en">testing987</documentation>
+            <appinfo source="http://test/source/appinfo";>testing123</appinfo>
+          </annotation>
+          <restriction base="string">
+            <length value="1"/>
+          </restriction>
+        </simpleType>
+        */
+
+        QName TYPE_QNAME = new QName("http://soapinterop.org/types";,
+                                     "annotationTest");
+        InputStream is = new FileInputStream("test-resources/annotation.xsd");
+        XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+        XmlSchema schema = schemaCol.read(new StreamSource(is), null);
+
+        XmlSchemaSimpleType simpleType =
+            (XmlSchemaSimpleType)schemaCol.getTypeByQName(TYPE_QNAME);
+        assertNotNull(simpleType);
+
+        XmlSchemaAnnotation xsa = simpleType.getAnnotation();
+        assertNotNull(xsa);
+
+        XmlSchemaObjectCollection col = xsa.getItems();
+        assertEquals(2, col.getCount());
+
+        Set s = new HashSet();
+        s.add(XmlSchemaAppInfo.class.getName());
+        s.add(XmlSchemaDocumentation.class.getName());
+        for (int i = 0; i < col.getCount(); i++) {
+            XmlSchemaObject o = col.getItem(i);
+            if (o instanceof XmlSchemaAppInfo) {
+                assertEquals("http://test/source/appinfo";,
+                             ((XmlSchemaAppInfo)o).getSource());
+                NodeList nl = ((XmlSchemaAppInfo)o).getMarkup();
+                for (int j = 0; j < nl.getLength(); j++) {
+                    Node n = nl.item(j);
+                    if (n.getNodeType() == Node.TEXT_NODE) {
+                        assertEquals("testing123", n.getTextContent());
+                    }
+                }
+            } else if (o instanceof XmlSchemaDocumentation) {
+                assertEquals("en",
+                             ((XmlSchemaDocumentation)o).getLanguage());
+                assertEquals("http://test/source/doc";,
+                             ((XmlSchemaDocumentation)o).getSource());
+                NodeList nl = ((XmlSchemaDocumentation)o).getMarkup();
+                for (int j = 0; j < nl.getLength(); j++) {
+                    Node n = nl.item(j);
+                    if (n.getNodeType() == Node.TEXT_NODE) {
+                        assertEquals("testing987", n.getTextContent());
+                    }
+                }
+            }
+            assertTrue(s.remove(o.getClass().getName()));
+        }
+        assertTrue("The set should have been empty, but instead contained: "
+                   + s + ".",
+                   s.isEmpty());
+    }
+
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to