From 28a487ac43133b70175f78ab8f412ebb142e8972 Mon Sep 17 00:00:00 2001
From: Martin Goik <goik@hdm-stuttgart.de>
Date: Tue, 20 Oct 2015 13:54:48 +0200
Subject: [PATCH] Explanatory schema violating tests

---
 Doc/Sda1/xmlschema.xml                        | 80 ++++++++++++++++++-
 .../Xml/Invoice/Tests/customerWithoutId.xml   | 13 +++
 ws/eclipse/Jdbc/Input/Xml/Invoice/invoice.xsd |  2 +-
 3 files changed, 91 insertions(+), 4 deletions(-)
 create mode 100644 ws/eclipse/Jdbc/Input/Xml/Invoice/Tests/customerWithoutId.xml

diff --git a/Doc/Sda1/xmlschema.xml b/Doc/Sda1/xmlschema.xml
index 1f0d40cdc..574a6731a 100644
--- a/Doc/Sda1/xmlschema.xml
+++ b/Doc/Sda1/xmlschema.xml
@@ -793,6 +793,12 @@ public class Memo {
                   <para>Add an <xref linkend="glo_XSD"/> schema file providing
                   all constraints from your relational model.</para>
                 </listitem>
+
+                <listitem>
+                  <para>Provide appropriate tests by XML document instances
+                  violating different aspects of the given schema (data types,
+                  uniqueness,...).</para>
+                </listitem>
               </orderedlist>
             </question>
 
@@ -824,7 +830,7 @@ public class Memo {
         &lt;xs:complexType&gt;
             &lt;xs:sequence&gt;
                 &lt;xs:element ref="customer" maxOccurs="unbounded"/&gt;
-                &lt;xs:element ref="invoice" maxOccurs="unbounded"/&gt;
+                &lt;xs:element ref="invoice" minOccurs="0" maxOccurs="unbounded"/&gt;
             &lt;/xs:sequence&gt;
         &lt;/xs:complexType&gt;
         
@@ -868,8 +874,7 @@ public class Memo {
         &lt;/xs:complexType&gt;
     &lt;/xs:element&gt;
     
-&lt;/xs:schema&gt;
-</programlisting>
+&lt;/xs:schema&gt;</programlisting>
 
               <para>An example data set:</para>
 
@@ -882,6 +887,75 @@ public class Memo {
     
     &lt;invoice customer="5" status="due"&gt;33.12&lt;/invoice&gt;
 &lt;/data&gt;</programlisting>
+
+              <para>Some constraint violating tests among with corresponding
+              XML parser error messages:</para>
+
+              <glosslist>
+                <glossentry>
+                  <glossterm> Attribute 'id' must appear on element
+                  'customer'.</glossterm>
+
+                  <glossdef>
+                    <programlisting language="none">&lt;data ... ="../invoice.xsd"&gt;
+    &lt;customer &gt;
+        &lt;name&gt;Clarke Jefferson&lt;/name&gt;
+    &lt;/customer&gt;
+&lt;/data&gt;</programlisting>
+                  </glossdef>
+                </glossentry>
+
+                <glossentry>
+                  <glossterm>The value 'five' of attribute 'id' on element
+                  'customer' is not valid with respect to its type,
+                  'int'</glossterm>
+
+                  <glossdef>
+                    <programlisting language="none">    &lt;customer id="five"&gt;
+        &lt;name&gt;Clarke Jefferson&lt;/name&gt;
+    &lt;/customer&gt;</programlisting>
+                  </glossdef>
+                </glossentry>
+
+                <glossentry>
+                  <glossterm>'33,12' is not a valid value for
+                  'decimal'</glossterm>
+
+                  <glossdef>
+                    <programlisting language="none">    &lt;customer id="5"&gt;
+  ...
+    &lt;invoice customer="5" status="due"&gt;33,12&lt;/invoice&gt;</programlisting>
+                  </glossdef>
+                </glossentry>
+
+                <glossentry>
+                  <glossterm>Duplicate key value [5] declared for identity
+                  constraint "customerId" of element "data"</glossterm>
+
+                  <glossdef>
+                    <programlisting language="none">    &lt;customer id="5"&gt;
+        &lt;name&gt;Clarke Jefferson&lt;/name&gt;
+    &lt;/customer&gt;
+    
+    &lt;customer id="5"&gt;
+        &lt;name&gt;Jane Austen&lt;/name&gt;
+    &lt;/customer&gt;</programlisting>
+                  </glossdef>
+                </glossentry>
+
+                <glossentry>
+                  <glossterm> Key 'customerToInvoice' with value '6' not found
+                  for identity constraint of element 'data'</glossterm>
+
+                  <glossdef>
+                    <programlisting language="none">    &lt;customer id="5"&gt;
+        &lt;name&gt;Clarke Jefferson&lt;/name&gt;
+    &lt;/customer&gt;
+    
+    &lt;invoice customer="6" status="due"&gt;33.12&lt;/invoice&gt;</programlisting>
+                  </glossdef>
+                </glossentry>
+              </glosslist>
             </answer>
           </qandaentry>
         </qandadiv>
diff --git a/ws/eclipse/Jdbc/Input/Xml/Invoice/Tests/customerWithoutId.xml b/ws/eclipse/Jdbc/Input/Xml/Invoice/Tests/customerWithoutId.xml
new file mode 100644
index 000000000..38cb2c316
--- /dev/null
+++ b/ws/eclipse/Jdbc/Input/Xml/Invoice/Tests/customerWithoutId.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<data xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:noNamespaceSchemaLocation="../invoice.xsd">
+    <customer id="five">
+        <name>Clarke Jefferson</name>
+    </customer>
+    
+    <customer id="5">
+        <name>Clarke Jefferson</name>
+    </customer>
+    
+    <invoice customer="5" status="due">33.12</invoice>
+</data>
\ No newline at end of file
diff --git a/ws/eclipse/Jdbc/Input/Xml/Invoice/invoice.xsd b/ws/eclipse/Jdbc/Input/Xml/Invoice/invoice.xsd
index 3ce6714b5..03bbded1b 100644
--- a/ws/eclipse/Jdbc/Input/Xml/Invoice/invoice.xsd
+++ b/ws/eclipse/Jdbc/Input/Xml/Invoice/invoice.xsd
@@ -23,7 +23,7 @@
         <xs:complexType>
             <xs:sequence>
                 <xs:element ref="customer" maxOccurs="unbounded"/>
-                <xs:element ref="invoice" maxOccurs="unbounded"/>
+                <xs:element ref="invoice" minOccurs="0" maxOccurs="unbounded"/>
             </xs:sequence>
         </xs:complexType>
         
-- 
GitLab