From 5bd5c9ca6a1f0f916e7b68218db0e492d51ce6e9 Mon Sep 17 00:00:00 2001
From: Martin Goik <goik@hdm-stuttgart.de>
Date: Tue, 25 Nov 2014 23:23:57 +0100
Subject: [PATCH] Nex XSL unit test for introductory XSL examination

---
 Sda1/Etest/Xslt1/Xslt/person2userTest.xspec   | 165 ++++++++++++++++++
 Sda1/Etest/Xslt1/XsltSolution/.gitignore      |   1 +
 Sda1/Etest/Xslt1/XsltSolution/.project        |   2 +-
 Sda1/Etest/Xslt1/XsltSolution/person.xsd      |   4 +-
 .../Xslt1/XsltSolution/person2userTest.xspec  | 165 ++++++++++++++++++
 Sda1/Etest/Xslt1/user.xhtml                   |  47 ++++-
 Sda1/Etest/Xslt2/exercise1.xhtml              |  15 +-
 Sda1/Etest/Xslt2/exercise2.xhtml              |  10 +-
 8 files changed, 386 insertions(+), 23 deletions(-)
 create mode 100644 Sda1/Etest/Xslt1/Xslt/person2userTest.xspec
 create mode 100644 Sda1/Etest/Xslt1/XsltSolution/.gitignore
 create mode 100644 Sda1/Etest/Xslt1/XsltSolution/person2userTest.xspec

diff --git a/Sda1/Etest/Xslt1/Xslt/person2userTest.xspec b/Sda1/Etest/Xslt1/Xslt/person2userTest.xspec
new file mode 100644
index 000000000..1fe04974c
--- /dev/null
+++ b/Sda1/Etest/Xslt1/Xslt/person2userTest.xspec
@@ -0,0 +1,165 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<x:description xmlns:x="http://www.jenitennison.com/xslt/xspec" stylesheet="person2user.xsl">
+    
+    <x:scenario label="'person' entry having no contact information">
+        <x:context>
+            <person id="7">
+                <firstName>Jim</firstName>
+                <lastName>Bone</lastName>
+            </person>
+        </x:context>
+        
+        <x:expect label="'user' entry having no contact information">
+            <user index="1" uid="user_7">
+                <uid>Bone</uid>
+                <fullName>Jim Bone</fullName>
+                <contact type="none"/>
+            </user>
+        </x:expect>
+        
+    </x:scenario>
+    
+    <x:scenario label="'person' entry having only 'email'">
+        
+        <x:context>
+            <person id="7">
+                <firstName>Jim</firstName>
+                <lastName>Bone</lastName>
+                <email>bone@lispy.com</email>
+            </person>
+        </x:context>
+        
+        <x:expect label="'user' entry having only email contact information">
+            <user index="1" uid="user_7">
+                <uid>Bone</uid>
+                <fullName>Jim Bone</fullName>
+                <contact type="email">bone@lispy.com</contact>
+            </user>
+        </x:expect>
+        
+    </x:scenario>
+    
+    <x:scenario label="'person' entry having only 'phone'">
+        <x:context select="person">
+            <person id="7">
+                <firstName>Jim</firstName>
+                <lastName>Bone</lastName>
+                <phone>323-433453</phone>
+            </person>
+        </x:context>
+        
+        <x:expect label="'user' entry having phone contact information">
+            <user index="1" uid="user_7">
+                <uid>Bone</uid>
+                <fullName>Jim Bone</fullName>
+                <contact type="phone">323-433453</contact>
+            </user>
+        </x:expect>
+        
+    </x:scenario>
+    
+    <x:scenario label="'person' entry having 'email' and 'phone'">
+        <x:context select="person">
+            <person id="7">
+                <firstName>Jim</firstName>
+                <lastName>Bone</lastName>
+                <phone>323-433453</phone>
+                <email>bone@lispy.com</email>
+            </person>
+        </x:context>
+        
+        <x:expect label="'user' entry having email contact information">
+            <user index="1" uid="user_7">
+                <uid>Bone</uid>
+                <fullName>Jim Bone</fullName>
+                <contact type="email">bone@lispy.com</contact>
+            </user>
+        </x:expect>
+        
+    </x:scenario>
+    
+    <x:scenario label="One 'person' entry having no id">
+        <x:context >
+            <persons 
+                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+                xsi:noNamespaceSchemaLocation="person.xsd">
+                <person>
+                    <firstName>Jim</firstName>
+                    <lastName>Bone</lastName>
+                </person>
+            </persons>
+        </x:context>
+        
+        <x:expect label="No 'user' entry at all">
+            <users xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+                xsi:noNamespaceSchemaLocation="user.xsd"/>
+        </x:expect>
+        
+    </x:scenario>
+    
+    <x:scenario label="One 'person' entry having an id">
+        <x:context >
+            <persons 
+                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+                xsi:noNamespaceSchemaLocation="person.xsd">
+                <person id='9'>
+                    <firstName>Jim</firstName>
+                    <lastName>Bone</lastName>
+                </person>
+            </persons>
+        </x:context>
+        
+        <x:expect label="No 'user' entry at all">
+            <users xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+                xsi:noNamespaceSchemaLocation="user.xsd">
+                <user index="1" uid="user_9">
+                    <uid>Bone</uid>
+                    <fullName>Jim Bone</fullName>
+                    <contact type="none"/>
+                </user>
+            </users>
+        </x:expect>
+        
+    </x:scenario>
+    
+    <x:scenario label="Three 'person' entries, two having an id">
+        <x:context >
+            <persons 
+                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+                xsi:noNamespaceSchemaLocation="person.xsd">
+                <person id='9'>
+                    <firstName>Jim</firstName>
+                    <lastName>Bone</lastName>
+                </person>
+                <person>
+                    <firstName>Sally</firstName>
+                    <lastName>Jones</lastName>
+                </person>
+                <person id='7'>
+                    <firstName>Linda</firstName>
+                    <lastName>Evans</lastName>
+                </person>
+            </persons>
+        </x:context>
+        
+        <x:expect label="Two 'user' entries (one gets filtered)">
+            <users xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+                xsi:noNamespaceSchemaLocation="user.xsd">
+                <user index="1" uid="user_9">
+                    <uid>Bone</uid>
+                    <fullName>Jim Bone</fullName>
+                    <contact type="none"/>
+                </user>
+                <user index="2" uid="user_7">
+                    <uid>Evans</uid>
+                    <fullName>Linda Evans</fullName>
+                    <contact type="none"/>
+                </user>
+            </users>
+        </x:expect>
+        
+    </x:scenario>
+    
+    
+    
+</x:description>
diff --git a/Sda1/Etest/Xslt1/XsltSolution/.gitignore b/Sda1/Etest/Xslt1/XsltSolution/.gitignore
new file mode 100644
index 000000000..0a5ab4b6b
--- /dev/null
+++ b/Sda1/Etest/Xslt1/XsltSolution/.gitignore
@@ -0,0 +1 @@
+/person2userTest-result.html
diff --git a/Sda1/Etest/Xslt1/XsltSolution/.project b/Sda1/Etest/Xslt1/XsltSolution/.project
index 27046fa53..bf2303232 100644
--- a/Sda1/Etest/Xslt1/XsltSolution/.project
+++ b/Sda1/Etest/Xslt1/XsltSolution/.project
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <projectDescription>
-	<name>Xslt</name>
+	<name>XsltSolution</name>
 	<comment></comment>
 	<projects>
 	</projects>
diff --git a/Sda1/Etest/Xslt1/XsltSolution/person.xsd b/Sda1/Etest/Xslt1/XsltSolution/person.xsd
index 184586142..6d3759cfe 100644
--- a/Sda1/Etest/Xslt1/XsltSolution/person.xsd
+++ b/Sda1/Etest/Xslt1/XsltSolution/person.xsd
@@ -18,8 +18,8 @@
             <xs:sequence>
                 <xs:element name="firstName"/>
                 <xs:element name="lastName"/>
-                <xs:element name="phone" minOccurs="0"/>
-                <xs:element name="email" minOccurs="0"/>
+                <xs:element name="phone" minOccurs="0" maxOccurs="1"/>
+                <xs:element name="email" minOccurs="0" maxOccurs="1"/>
             </xs:sequence>
             <xs:attribute name="id" type="xs:int" use="optional"/>
         </xs:complexType>
diff --git a/Sda1/Etest/Xslt1/XsltSolution/person2userTest.xspec b/Sda1/Etest/Xslt1/XsltSolution/person2userTest.xspec
new file mode 100644
index 000000000..1fe04974c
--- /dev/null
+++ b/Sda1/Etest/Xslt1/XsltSolution/person2userTest.xspec
@@ -0,0 +1,165 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<x:description xmlns:x="http://www.jenitennison.com/xslt/xspec" stylesheet="person2user.xsl">
+    
+    <x:scenario label="'person' entry having no contact information">
+        <x:context>
+            <person id="7">
+                <firstName>Jim</firstName>
+                <lastName>Bone</lastName>
+            </person>
+        </x:context>
+        
+        <x:expect label="'user' entry having no contact information">
+            <user index="1" uid="user_7">
+                <uid>Bone</uid>
+                <fullName>Jim Bone</fullName>
+                <contact type="none"/>
+            </user>
+        </x:expect>
+        
+    </x:scenario>
+    
+    <x:scenario label="'person' entry having only 'email'">
+        
+        <x:context>
+            <person id="7">
+                <firstName>Jim</firstName>
+                <lastName>Bone</lastName>
+                <email>bone@lispy.com</email>
+            </person>
+        </x:context>
+        
+        <x:expect label="'user' entry having only email contact information">
+            <user index="1" uid="user_7">
+                <uid>Bone</uid>
+                <fullName>Jim Bone</fullName>
+                <contact type="email">bone@lispy.com</contact>
+            </user>
+        </x:expect>
+        
+    </x:scenario>
+    
+    <x:scenario label="'person' entry having only 'phone'">
+        <x:context select="person">
+            <person id="7">
+                <firstName>Jim</firstName>
+                <lastName>Bone</lastName>
+                <phone>323-433453</phone>
+            </person>
+        </x:context>
+        
+        <x:expect label="'user' entry having phone contact information">
+            <user index="1" uid="user_7">
+                <uid>Bone</uid>
+                <fullName>Jim Bone</fullName>
+                <contact type="phone">323-433453</contact>
+            </user>
+        </x:expect>
+        
+    </x:scenario>
+    
+    <x:scenario label="'person' entry having 'email' and 'phone'">
+        <x:context select="person">
+            <person id="7">
+                <firstName>Jim</firstName>
+                <lastName>Bone</lastName>
+                <phone>323-433453</phone>
+                <email>bone@lispy.com</email>
+            </person>
+        </x:context>
+        
+        <x:expect label="'user' entry having email contact information">
+            <user index="1" uid="user_7">
+                <uid>Bone</uid>
+                <fullName>Jim Bone</fullName>
+                <contact type="email">bone@lispy.com</contact>
+            </user>
+        </x:expect>
+        
+    </x:scenario>
+    
+    <x:scenario label="One 'person' entry having no id">
+        <x:context >
+            <persons 
+                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+                xsi:noNamespaceSchemaLocation="person.xsd">
+                <person>
+                    <firstName>Jim</firstName>
+                    <lastName>Bone</lastName>
+                </person>
+            </persons>
+        </x:context>
+        
+        <x:expect label="No 'user' entry at all">
+            <users xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+                xsi:noNamespaceSchemaLocation="user.xsd"/>
+        </x:expect>
+        
+    </x:scenario>
+    
+    <x:scenario label="One 'person' entry having an id">
+        <x:context >
+            <persons 
+                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+                xsi:noNamespaceSchemaLocation="person.xsd">
+                <person id='9'>
+                    <firstName>Jim</firstName>
+                    <lastName>Bone</lastName>
+                </person>
+            </persons>
+        </x:context>
+        
+        <x:expect label="No 'user' entry at all">
+            <users xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+                xsi:noNamespaceSchemaLocation="user.xsd">
+                <user index="1" uid="user_9">
+                    <uid>Bone</uid>
+                    <fullName>Jim Bone</fullName>
+                    <contact type="none"/>
+                </user>
+            </users>
+        </x:expect>
+        
+    </x:scenario>
+    
+    <x:scenario label="Three 'person' entries, two having an id">
+        <x:context >
+            <persons 
+                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+                xsi:noNamespaceSchemaLocation="person.xsd">
+                <person id='9'>
+                    <firstName>Jim</firstName>
+                    <lastName>Bone</lastName>
+                </person>
+                <person>
+                    <firstName>Sally</firstName>
+                    <lastName>Jones</lastName>
+                </person>
+                <person id='7'>
+                    <firstName>Linda</firstName>
+                    <lastName>Evans</lastName>
+                </person>
+            </persons>
+        </x:context>
+        
+        <x:expect label="Two 'user' entries (one gets filtered)">
+            <users xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+                xsi:noNamespaceSchemaLocation="user.xsd">
+                <user index="1" uid="user_9">
+                    <uid>Bone</uid>
+                    <fullName>Jim Bone</fullName>
+                    <contact type="none"/>
+                </user>
+                <user index="2" uid="user_7">
+                    <uid>Evans</uid>
+                    <fullName>Linda Evans</fullName>
+                    <contact type="none"/>
+                </user>
+            </users>
+        </x:expect>
+        
+    </x:scenario>
+    
+    
+    
+</x:description>
diff --git a/Sda1/Etest/Xslt1/user.xhtml b/Sda1/Etest/Xslt1/user.xhtml
index 1f2ced1da..83c45756e 100644
--- a/Sda1/Etest/Xslt1/user.xhtml
+++ b/Sda1/Etest/Xslt1/user.xhtml
@@ -13,13 +13,41 @@
       href="https://learn.mi.hdm-stuttgart.de/iliasData/goik/sdfweergdth45n3535nr3rn3Gff/xslt.zip">xslt.zip</a>
       and import it as a project into your Eclipse workspace.</li>
 
-      <li>Your resulting Project named Xslt contains a file
-      <code>personData.xml</code> and an XSLT skeleton file
-      <code>person2user.xsl</code>. Define an Xslt transformation scenario
-      which turns <code>personData.xml</code> into <code>user.xml</code> by
-      means of <code>person2user.xsl</code>. <span style="color: red;">Do not
-      overwrite the intended sample output data file
-      <code>userData.xml</code></span>.</li>
+      <li><p>Your resulting Project named <code>Xslt</code> contains the
+      following files:</p><dl>
+          <dt>person.xsd</dt>
+
+          <dd>An XML schema describing a simple XML database containing
+          <code>&lt;person&gt;</code> records.</dd>
+
+          <dt>personData.xml</dt>
+
+          <dd>A sample instance being valid with respect to the above
+          <code>person.xsd</code> schema.</dd>
+
+          <dt>person2user.xsl</dt>
+
+          <dd>A XSL skeleton setting some transformation related properties
+          and containing a helper template to identify missing rules.</dd>
+
+          <dt>user.xsd</dt>
+
+          <dd>An XML schema describing a simple XML database containing
+          <code>&lt;user&gt;</code> records.</dd>
+
+          <dt>personData.xml</dt>
+
+          <dd>This is the intended output consisting of
+          <code>&lt;user&gt;</code> entries being obtained by transforming
+          <code>personData.xml</code> with (yet incomplete)
+          <code>person2user.xsl</code>. This shall be valid with respect to
+          <code>user.xsd</code>.</dd>
+
+          <dt>person2userTest.xspec</dt>
+
+          <dd>A unit test helping to check <code>person2user.xsl</code> for
+          correctness.</dd>
+        </dl></li>
     </ol><h2>Description</h2><p>The imported Eclipse project contains the
   following sample document instance <code>personData.xml</code>:</p><pre
   style="font-family:monospace;">&lt;persons 
@@ -68,7 +96,10 @@
     </ul><p>The generated output file shall be valid with respect to
   <code>user.xsd</code>.</p><h2>ToDo</h2><p>Start from
   <code>person2user.xsl</code> and implement the previously described
-  transformation. When you are finished upload your final
+  transformation. Open the unit test file <code>person2userTest.xspec</code>
+  and hit <code>Apply transformation scenario(s) Xspec for XSLT</code> in the
+  Eclipse tool bar. This allows to continuously check your progress and
+  reminds you about possible errors. When you are finished upload your final
   <code>person2user.xsl</code> result.</p><h2>Hints</h2><p>The function
   <code>position()</code> returns the index of an element within a given node
   set.</p></body>
diff --git a/Sda1/Etest/Xslt2/exercise1.xhtml b/Sda1/Etest/Xslt2/exercise1.xhtml
index e46275aaf..b7592bac1 100644
--- a/Sda1/Etest/Xslt2/exercise1.xhtml
+++ b/Sda1/Etest/Xslt2/exercise1.xhtml
@@ -11,7 +11,7 @@
       href="/iliasData/goik/i435uoi6FGbn__JJ34/book2html.zip">book2html.zip</a>
       and import it as a project into your Eclipse workspace.</li>
 
-      <li><p>Your resulting Project named <code>Xslt</code> contains a
+      <li><p>Your resulting Project named <code>Book2html</code> contains a
       subfolder <code>Book1</code>. This subfolder in turn contains the
       following files:</p><dl>
           <dt>book.xsd</dt>
@@ -80,12 +80,13 @@
       <li><p><code>chapter/title</code> elements shall be represented by
       <code>&lt;h2&gt;</code> tags</p></li>
     </ul><h2>ToDo</h2><p>Complete the implementation of
-  <code>book2html.xsl</code>. Open the unit test file bookBasicTest.xspec and
-  hit <code>Apply transformation scenario(s) Xspec for XSLT</code> in the
-  Eclipse tool bar. This allows to continuously check your progress and
-  reminds you about possible errors. When you are finished upload your final
-  <code>book2html.xsl</code> result.</p><h2>Hint</h2><p>The XSL unit tests may
-  contain scenarios not present in your sample files <code>work.xml</code> and
+  <code>book2html.xsl</code>. Open the unit test file
+  <code>bookBasicTest.xspec</code> and hit <code>Apply transformation
+  scenario(s) Xspec for XSLT</code> in the Eclipse tool bar. This allows to
+  continuously check your progress and reminds you about possible errors. When
+  you are finished upload your final <code>book2html.xsl</code>
+  result.</p><h2>Hint</h2><p>The XSL unit tests may contain scenarios not
+  present in your sample files <code>work.xml</code> and
   <code>work.reference.html</code>. So even if your output work.html is
   correct for the given sample XML instance your stylesheet may though contain
   errors. You may want to open the unit test definitions to find possible
diff --git a/Sda1/Etest/Xslt2/exercise2.xhtml b/Sda1/Etest/Xslt2/exercise2.xhtml
index c03e261aa..392b6ec3b 100644
--- a/Sda1/Etest/Xslt2/exercise2.xhtml
+++ b/Sda1/Etest/Xslt2/exercise2.xhtml
@@ -73,11 +73,11 @@
   <code>Book2/book2html.xsl</code>. You may want to start from your XSL result
   of the previous exercise by copying relevant content from
   <code>Book1/book2html.xsl</code>.</p><p>Open the unit test file
-  Book2/bookLinkMixedTest.xspec (which imports all tests from the previous
-  exercise file <code>Book1/bookBasicTest.xspec</code>) and hit <code>Apply
-  transformation scenario(s) Xspec for XSLT</code> in the Eclipse tool bar.
-  This allows to continuously check your progress and reminds you about
-  possible errors. When you are finished upload your final
+  <code>Book2/bookLinkMixedTest.xspec</code> (which imports all tests from the
+  previous exercise file <code>Book1/bookBasicTest.xspec</code> as well) and
+  hit <code>Apply transformation scenario(s) Xspec for XSLT</code> in the
+  Eclipse tool bar. This allows to continuously check your progress and
+  reminds you about possible errors. When you are finished upload your final
   <code>Book2/book2html.xsl</code> result.</p><h2>Hints:</h2><ul>
       <li>Use <code>&lt;xsl:attributes&gt;</code> to supply <code>id</code>
       values.</li>
-- 
GitLab