diff --git a/Klausuren/Sda1/Ws2015/Exam/Schema/dictionary.xsd b/Klausuren/Sda1/Ws2015/Exam/Schema/dictionary.xsd new file mode 100644 index 0000000000000000000000000000000000000000..d20810c4a4ca337e97fcb39236978d187f31d596 --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Exam/Schema/dictionary.xsd @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="UTF-8"?> +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" + xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning" elementFormDefault="qualified" + vc:minVersion="1.1"> + + <xs:element name="dictionary"> + + </xs:element> + + </xs:schema> diff --git a/Klausuren/Sda1/Ws2015/Exam/Schema/sampledata.xml b/Klausuren/Sda1/Ws2015/Exam/Schema/sampledata.xml new file mode 100644 index 0000000000000000000000000000000000000000..3eeac0ffb45567d14f311128ab8fb10e7ab90734 --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Exam/Schema/sampledata.xml @@ -0,0 +1,50 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<dictionary fromLanguage='en' toLanguage='de' + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="dictionary.xsd"> + + <entry> + <from>concern</from> + <translations> + <to>Sorge</to> + <to>Besorgnis</to> + </translations> + </entry> + + <entry> + <from>compassion</from> + <translations> + <to>Barmherzigkeit</to> + <to>Mitgefühl</to> + <to>Mitleid</to> + <to>Erbarmen</to> + </translations> + <synonyms> + <from>pity</from> + <from>concern</from> + </synonyms> + </entry> + + <entry> + <from>jerk</from> + <translations> + <to>Ruck</to> + <to>Trottel</to> + </translations> + </entry> + + <entry> + <from>pity</from> + <translations> + <to>Mitleid</to> + <to>Erbarmen</to> + <to>Jammer</to> + <to>Mitgefühl</to> + </translations> + <synonyms> + <from>compassion</from> + </synonyms> + </entry> + +</dictionary> diff --git a/Klausuren/Sda1/Ws2015/Exam/Schema/sampledata_target.xhtml b/Klausuren/Sda1/Ws2015/Exam/Schema/sampledata_target.xhtml new file mode 100644 index 0000000000000000000000000000000000000000..790de89452f28d544505a515ea9e8ff1a3916e82 --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Exam/Schema/sampledata_target.xhtml @@ -0,0 +1,46 @@ +<?xml version="1.0" encoding="UTF-8"?> +<html xmlns="http://www.w3.org/1999/xhtml"> + <head> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> + <title>'en' to 'de' translation.</title> + </head> + <body> + <h1>'en' to 'de' translation.</h1> + <dl> + <dt id="concern" style="font-weight: bold;">concern</dt> + <dd> + <ul> + <li>Sorge</li> + <li>Besorgnis</li> + </ul> + </dd> + <dt id="compassion" style="font-weight: bold;">compassion</dt> + <dd> + <ul> + <li>Barmherzigkeit</li> + <li>Mitgefühl</li> + <li>Mitleid</li> + <li>Erbarmen</li> + </ul> + <p>Synonyms: <a href="#pity">pity</a>, <a href="#concern">concern</a></p> + </dd> + <dt id="jerk" style="font-weight: bold;">jerk</dt> + <dd> + <ul> + <li>Ruck</li> + <li>Trottel</li> + </ul> + </dd> + <dt id="pity" style="font-weight: bold;">pity</dt> + <dd> + <ul> + <li>Mitleid</li> + <li>Erbarmen</li> + <li>Jammer</li> + <li>Mitgefühl</li> + </ul> + <p>Synonym: <a href="#compassion">compassion</a></p> + </dd> + </dl> + </body> +</html> \ No newline at end of file diff --git a/Klausuren/Sda1/Ws2015/Exam/SchemaTest/doubleSynonymSection_err.xml b/Klausuren/Sda1/Ws2015/Exam/SchemaTest/doubleSynonymSection_err.xml new file mode 100644 index 0000000000000000000000000000000000000000..bc6a3fd56c86dafee72d5b550e6adc922ba71901 --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Exam/SchemaTest/doubleSynonymSection_err.xml @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<dictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="../Schema/dictionary.xsd" fromLanguage='en' + toLanguage='de'> + <entry> + <from>concern</from> + <translations> + <to>Sorge</to> + <to>Besorgnis</to> + </translations> + </entry> + + <entry> + <from>compassion</from> + <translations> + <to>Barmherzigkeit</to> + <to>Mitgefühl</to> + </translations> + <synonyms> + <from>pity</from> + </synonyms> + <synonyms> + <from>concern</from> + </synonyms> + </entry> + + <entry> + <from>pity</from> + <translations> + <to>Mitleid</to> + <to>Erbarmen</to> + </translations> + <synonyms> + <from>compassion</from> + </synonyms> + </entry> + +</dictionary> + +<!-- Subsequent lines contain only processing instructions irrelevant to instance's validity --> +<?xmlTest + points = "1" + expectedToBeValid = "false" + preconditionValid = "synonym.xml" ?> \ No newline at end of file diff --git a/Klausuren/Sda1/Ws2015/Exam/SchemaTest/duplicateTranslationSection_err.xml b/Klausuren/Sda1/Ws2015/Exam/SchemaTest/duplicateTranslationSection_err.xml new file mode 100644 index 0000000000000000000000000000000000000000..b1db4e4c60ba0912c0b81f8fd5f3aee5bdefba2c --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Exam/SchemaTest/duplicateTranslationSection_err.xml @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<dictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="../Schema/dictionary.xsd" fromLanguage='en' toLanguage='de'> + + <entry> + <from>compassion</from> + <translations> + <to>Barmherzigkeit</to> + <to>Mitgefühl</to> + </translations> + <translations> + <to>Mitleid</to> + <to>Erbarmen</to> + </translations> + </entry> +</dictionary> + +<!-- Subsequent lines contain only processing instructions irrelevant to instance's validity --> +<?xmlTest + points = "1" + expectedToBeValid= "false" + preconditionValid="noTranslationDuplicate.xml" ?> \ No newline at end of file diff --git a/Klausuren/Sda1/Ws2015/Exam/SchemaTest/empty.xml b/Klausuren/Sda1/Ws2015/Exam/SchemaTest/empty.xml new file mode 100644 index 0000000000000000000000000000000000000000..07f98f3bc1b1702701fbe13acf3c8c409f3c6a0f --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Exam/SchemaTest/empty.xml @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<dictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="../Schema/dictionary.xsd" fromLanguage='en' toLanguage='de'/> + + +<!-- Subsequent lines contain only processing instructions irrelevant to instance's validity --> +<?xmlTest + points = "1" + expectedToBeValid= "true" ?> \ No newline at end of file diff --git a/Klausuren/Sda1/Ws2015/Exam/SchemaTest/fromType_err.xml b/Klausuren/Sda1/Ws2015/Exam/SchemaTest/fromType_err.xml new file mode 100644 index 0000000000000000000000000000000000000000..fa9b5afd285bf9e71b5a127ca90426e477b4d563 --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Exam/SchemaTest/fromType_err.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<dictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="../Schema/dictionary.xsd" fromLanguage='en' + toLanguage='de'> + <entry> + <from></from> + <translations> + <to>Sonne</to> + </translations> + </entry> + +</dictionary> + + +<!-- Subsequent lines contain only processing instructions irrelevant to instance's validity --> +<?xmlTest + points = "1" + expectedToBeValid = "false" + preconditionValid = "type.xml" ?> \ No newline at end of file diff --git a/Klausuren/Sda1/Ws2015/Exam/SchemaTest/language_err.xml b/Klausuren/Sda1/Ws2015/Exam/SchemaTest/language_err.xml new file mode 100644 index 0000000000000000000000000000000000000000..38f980e343636dd33bde4d3da2b9d9d615d2ec9d --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Exam/SchemaTest/language_err.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<dictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="../Schema/dictionary.xsd" fromLanguage='en' + toLanguage='fi'/> + + +<!-- Subsequent lines contain only processing instructions irrelevant to instance's validity --> +<?xmlTest + points = "1" + expectedToBeValid = "false" + preconditionValid = "empty.xml" ?> \ No newline at end of file diff --git a/Klausuren/Sda1/Ws2015/Exam/SchemaTest/missingTranslation_err.xml b/Klausuren/Sda1/Ws2015/Exam/SchemaTest/missingTranslation_err.xml new file mode 100644 index 0000000000000000000000000000000000000000..4ce8fef9adf5b692f3b3c9c35fb4ec1baa27da6e --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Exam/SchemaTest/missingTranslation_err.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<dictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="../Schema/dictionary.xsd" fromLanguage='en' toLanguage='de'> + + <entry> + <from>compassion</from> + </entry> +</dictionary> + +<!-- Subsequent lines contain only processing instructions irrelevant to instance's validity --> +<?xmlTest + points = "1" + expectedToBeValid= "false" + preconditionValid="translation.xml" ?> \ No newline at end of file diff --git a/Klausuren/Sda1/Ws2015/Exam/SchemaTest/noTranslationDuplicate.xml b/Klausuren/Sda1/Ws2015/Exam/SchemaTest/noTranslationDuplicate.xml new file mode 100644 index 0000000000000000000000000000000000000000..d94329d0ef333ba47766e4d767282f7934116139 --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Exam/SchemaTest/noTranslationDuplicate.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<dictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="../Schema/dictionary.xsd" fromLanguage='en' toLanguage='de'> + + <entry> + <from>compassion</from> + <translations> + <to>Barmherzigkeit</to> + <to>Mitgefühl</to> + <to>Mitleid</to> + <to>Erbarmen</to> + </translations> + </entry> +</dictionary> \ No newline at end of file diff --git a/Klausuren/Sda1/Ws2015/Exam/SchemaTest/noTranslationDuplicate_err.xml b/Klausuren/Sda1/Ws2015/Exam/SchemaTest/noTranslationDuplicate_err.xml new file mode 100644 index 0000000000000000000000000000000000000000..a96976ca2aa71c9d3aa6efa6f14770f4bd668d67 --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Exam/SchemaTest/noTranslationDuplicate_err.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<dictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="../Schema/dictionary.xsd" fromLanguage='en' toLanguage='de'> + + <entry> + <from>compassion</from> + <translations> + <to>Barmherzigkeit</to> + <to>Mitgefühl</to> + <to>Mitleid</to> + <to>Erbarmen</to> + <to>Mitgefühl</to> + </translations> + </entry> +</dictionary> + +<!-- Subsequent lines contain only processing instructions irrelevant to instance's validity --> +<?xmlTest + points = "1" + expectedToBeValid= "false" + preconditionValid="noTranslationDuplicate.xml" ?> \ No newline at end of file diff --git a/Klausuren/Sda1/Ws2015/Exam/SchemaTest/synonym.xml b/Klausuren/Sda1/Ws2015/Exam/SchemaTest/synonym.xml new file mode 100644 index 0000000000000000000000000000000000000000..7017b0fafc83a0be7a3dbfa8b3a85c2711cf090d --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Exam/SchemaTest/synonym.xml @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<dictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="../Schema/dictionary.xsd" fromLanguage='en' + toLanguage='de'> + <entry> + <from>concern</from> + <translations> + <to>Sorge</to> + <to>Besorgnis</to> + </translations> + </entry> + + <entry> + <from>compassion</from> + <translations> + <to>Barmherzigkeit</to> + <to>Mitgefühl</to> + </translations> + <synonyms> + <from>pity</from> + <from>concern</from> + </synonyms> + </entry> + + <entry> + <from>pity</from> + <translations> + <to>Mitleid</to> + <to>Erbarmen</to> + </translations> + <synonyms> + <from>compassion</from> + </synonyms> + </entry> + +</dictionary> \ No newline at end of file diff --git a/Klausuren/Sda1/Ws2015/Exam/SchemaTest/synonymDuplicate_err.xml b/Klausuren/Sda1/Ws2015/Exam/SchemaTest/synonymDuplicate_err.xml new file mode 100644 index 0000000000000000000000000000000000000000..6a2ad853454c56f14d1b97936b5c74586c7faf85 --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Exam/SchemaTest/synonymDuplicate_err.xml @@ -0,0 +1,47 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<dictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="../Schema/dictionary.xsd" fromLanguage='en' + toLanguage='de'> + <entry> + <from>concern</from> + <translations> + <to>Sorge</to> + <to>Besorgnis</to> + </translations> + </entry> + + <entry> + <from>compassion</from> + <translations> + <to>Barmherzigkeit</to> + <to>Mitgefühl</to> + </translations> + <synonyms> + <from>pity</from> + <from>concern</from> + <from>pity</from> + </synonyms> + </entry> + + <entry> + <from>pity</from> + <translations> + <to>Mitleid</to> + <to>Erbarmen</to> + <to>Jammer</to> + <to>Mitgefühl</to> + </translations> + <synonyms> + <from>compassion</from> + </synonyms> + </entry> + +</dictionary> + + +<!-- Subsequent lines contain only processing instructions irrelevant to instance's validity --> +<?xmlTest + points = "1" + expectedToBeValid = "false" + preconditionValid = "synonym.xml" ?> \ No newline at end of file diff --git a/Klausuren/Sda1/Ws2015/Exam/SchemaTest/synonymRef_err.xml b/Klausuren/Sda1/Ws2015/Exam/SchemaTest/synonymRef_err.xml new file mode 100644 index 0000000000000000000000000000000000000000..4c03d132b1a4dee5980f08da1c57031491919ccd --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Exam/SchemaTest/synonymRef_err.xml @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<dictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="../Schema/dictionary.xsd" fromLanguage='en' + toLanguage='de'> + <entry> + <from>concern</from> + <translations> + <to>Sorge</to> + <to>Besorgnis</to> + </translations> + </entry> + + <entry> + <from>compassion</from> + <translations> + <to>Barmherzigkeit</to> + <to>Mitgefühl</to> + </translations> + <synonyms> + <from>pity</from> + <from>conincidence</from> + </synonyms> + </entry> + + <entry> + <from>pity</from> + <translations> + <to>Mitleid</to> + <to>Erbarmen</to> + <to>Jammer</to> + <to>Mitgefühl</to> + </translations> + <synonyms> + <from>compassion</from> + </synonyms> + </entry> + +</dictionary> + +<!-- Subsequent lines contain only processing instructions irrelevant to instance's validity --> +<?xmlTest + points = "2" + expectedToBeValid = "false" + preconditionValid = "synonym.xml" ?> \ No newline at end of file diff --git a/Klausuren/Sda1/Ws2015/Exam/SchemaTest/toType_err.xml b/Klausuren/Sda1/Ws2015/Exam/SchemaTest/toType_err.xml new file mode 100644 index 0000000000000000000000000000000000000000..d8133ab68c9e245a1d8c248c5f93dc610ae81bb6 --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Exam/SchemaTest/toType_err.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<dictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="../Schema/dictionary.xsd" fromLanguage='en' + toLanguage='de'> + <entry> + <from>Sun</from> + <translations> + <to>Sonne</to> + <to></to> + </translations> + </entry> + +</dictionary> + + +<!-- Subsequent lines contain only processing instructions irrelevant to instance's validity --> +<?xmlTest + points = "1" + expectedToBeValid = "false" + preconditionValid = "type.xml" ?> \ No newline at end of file diff --git a/Klausuren/Sda1/Ws2015/Exam/SchemaTest/translation.xml b/Klausuren/Sda1/Ws2015/Exam/SchemaTest/translation.xml new file mode 100644 index 0000000000000000000000000000000000000000..953956b52a1ea298314bf3311165d1e196b75c06 --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Exam/SchemaTest/translation.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="UTF-8"?> +<dictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="../Schema/dictionary.xsd" fromLanguage='en' toLanguage='de'> + + <entry> + <from>compassion</from> + <translations> + <to>Barmherzigkeit</to> + </translations> + </entry> + +</dictionary> \ No newline at end of file diff --git a/Klausuren/Sda1/Ws2015/Exam/SchemaTest/translationMinimal.xml b/Klausuren/Sda1/Ws2015/Exam/SchemaTest/translationMinimal.xml new file mode 100644 index 0000000000000000000000000000000000000000..934a92abd760f1d86627836275d01f2b2fe0d5bd --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Exam/SchemaTest/translationMinimal.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<dictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="../Schema/dictionary.xsd" fromLanguage='en' toLanguage='de'> + + <entry> + <from>compassion</from> + <translations> + <to>Barmherzigkeit</to> + </translations> + </entry> +</dictionary> \ No newline at end of file diff --git a/Klausuren/Sda1/Ws2015/Exam/SchemaTest/translationMinimal_err.xml b/Klausuren/Sda1/Ws2015/Exam/SchemaTest/translationMinimal_err.xml new file mode 100644 index 0000000000000000000000000000000000000000..0abeffd8df069ba6057e1dfe139eeea9ca75775f --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Exam/SchemaTest/translationMinimal_err.xml @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<dictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="../Schema/dictionary.xsd" fromLanguage='en' toLanguage='de'> + + <entry> + <from>compassion</from> + <translations/> + </entry> +</dictionary> + +<!-- Subsequent lines contain only processing instructions irrelevant to instance's validity --> +<?xmlTest + points = "1" + expectedToBeValid= "false" + preconditionValid="translationMinimal.xml" ?> \ No newline at end of file diff --git a/Klausuren/Sda1/Ws2015/Exam/SchemaTest/twoEntries.xml b/Klausuren/Sda1/Ws2015/Exam/SchemaTest/twoEntries.xml new file mode 100644 index 0000000000000000000000000000000000000000..0a5ffd1d6336b59e5eb8e09330da9a771dd6a871 --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Exam/SchemaTest/twoEntries.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<dictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="../Schema/dictionary.xsd" fromLanguage='en' + toLanguage='de'> + <entry> + <from>Sun</from> + <translations> + <to>Sonne</to> + </translations> + </entry> + + <entry> + <from>Moon</from> + <translations> + <to>Mond</to> + </translations> + </entry> + +</dictionary> \ No newline at end of file diff --git a/Klausuren/Sda1/Ws2015/Exam/SchemaTest/twoEntriesDuplicate_err.xml b/Klausuren/Sda1/Ws2015/Exam/SchemaTest/twoEntriesDuplicate_err.xml new file mode 100644 index 0000000000000000000000000000000000000000..c1eafe78f24218131968a72a1d52bfb20787578c --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Exam/SchemaTest/twoEntriesDuplicate_err.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<dictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="../Schema/dictionary.xsd" fromLanguage='en' + toLanguage='de'> + <entry> + <from>Sun</from> + <translations> + <to>Sonne</to> + </translations> + </entry> + + <entry> + <from>Sun</from> + <translations> + <to>Himmelsstern</to> + </translations> + </entry> + +</dictionary> + +<?xmlTest + points = "1" + expectedToBeValid = "false" + preconditionValid = "twoEntries.xml" ?> \ No newline at end of file diff --git a/Klausuren/Sda1/Ws2015/Exam/SchemaTest/type.xml b/Klausuren/Sda1/Ws2015/Exam/SchemaTest/type.xml new file mode 100644 index 0000000000000000000000000000000000000000..cada5b36429657fb73b4c33ff922f8de900824b4 --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Exam/SchemaTest/type.xml @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<dictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="../Schema/dictionary.xsd" fromLanguage='en' + toLanguage='de'> + <entry> + <from>Sun</from> + <translations> + <to>Sonne</to> + </translations> + </entry> + +</dictionary> \ No newline at end of file diff --git a/Klausuren/Sda1/Ws2015/Exam/dictionary.xspec b/Klausuren/Sda1/Ws2015/Exam/dictionary.xspec new file mode 100644 index 0000000000000000000000000000000000000000..4200290c773770c0ae083c1b7c1fcafcc470fb9a --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Exam/dictionary.xspec @@ -0,0 +1,216 @@ +<?xml version="1.0" encoding="UTF-8"?> +<x:description xmlns:x="http://www.jenitennison.com/xslt/xspec" stylesheet="dictionary2html.xsl"> + + <x:scenario label="An empty '/dictionary'"> + <x:context> + <dictionary fromLanguage='en' toLanguage='de' + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="dictionary.xsd"/> + </x:context> + <x:expect label="Message indicating empty dictionary"> + <html xmlns="http://www.w3.org/1999/xhtml"> + <head> + <title>'en' to 'de' translation.</title> + </head> + <body> + <h1>'en' to 'de' translation.</h1> + <p>No entries in dictionary</p> + </body> + </html> + </x:expect> + </x:scenario> + + <x:scenario label="A single 'entry'"> + <x:context> + <entry> + <from>concern</from> + <translations> + <to>Sorge</to> + </translations> + </entry> + </x:context> + <x:expect label="A dt/dd pair."> + <dt xmlns="http://www.w3.org/1999/xhtml" id="concern" style="font-weight: bold;">concern</dt> + <dd xmlns="http://www.w3.org/1999/xhtml"> + <ul> + <li>Sorge</li> + </ul> + </dd> + </x:expect> + </x:scenario> + + <x:scenario label="'/dictionary' containing one entry"> + <x:context> + <dictionary fromLanguage='en' toLanguage='de' + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="dictionary.xsd"> + + <entry> + <from>concern</from> + <translations> + <to>Sorge</to> + <to>Besorgnis</to> + </translations> + </entry> + </dictionary> + </x:context> + <x:expect label="A dl list containing one entry"> + <html xmlns="http://www.w3.org/1999/xhtml"> + <head> + <title>'en' to 'de' translation.</title> + </head> + <body> + <h1>'en' to 'de' translation.</h1> + <dl> + <dt id="concern" style="font-weight: bold;">concern</dt> + <dd> + <ul> + <li>Sorge</li> + <li>Besorgnis</li> + </ul> + </dd> + </dl> + </body> + </html> + </x:expect> + </x:scenario> + + <x:scenario label="Scenario for testing template with match 'synonyms"> + <x:context select="dictionary/entry/synonyms"> + <dictionary fromLanguage='en' toLanguage='de' + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="dictionary.xsd"> + + <entry> + <from>concern</from> + <translations> + <to>Sorge</to> + <to>Besorgnis</to> + </translations> + </entry> + + <entry> + <from>compassion</from> + <translations> + <to>Barmherzigkeit</to> + <to>Mitgefühl</to> + <to>Mitleid</to> + <to>Erbarmen</to> + </translations> + <synonyms> + <from>pity</from> + <from>concern</from> + </synonyms> + </entry> + </dictionary> + </x:context> + <x:expect label="A coma separated list of all synonyms"> + <p xmlns="http://www.w3.org/1999/xhtml">Synonyms: <a href="#pity">pity</a>, <a href="#concern">concern</a></p> + </x:expect> + </x:scenario> + + <x:scenario label="Complete sample data."> + <x:context> + <dictionary fromLanguage='en' toLanguage='de' + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="dictionary.xsd"> + + <entry> + <from>concern</from> + <translations> + <to>Sorge</to> + <to>Besorgnis</to> + </translations> + </entry> + + <entry> + <from>compassion</from> + <translations> + <to>Barmherzigkeit</to> + <to>Mitgefühl</to> + <to>Mitleid</to> + <to>Erbarmen</to> + </translations> + <synonyms> + <from>pity</from> + <from>concern</from> + </synonyms> + </entry> + + <entry> + <from>jerk</from> + <translations> + <to>Ruck</to> + <to>Trottel</to> + </translations> + </entry> + + <entry> + <from>pity</from> + <translations> + <to>Mitleid</to> + <to>Erbarmen</to> + <to>Jammer</to> + <to>Mitgefühl</to> + </translations> + <synonyms> + <from>compassion</from> + </synonyms> + </entry> + + </dictionary> + + </x:context> + <x:expect label="A coma separated list of all synonyms"> + <html xmlns="http://www.w3.org/1999/xhtml"> + <head> + <title>'en' to 'de' translation.</title> + </head> + <body> + <h1>'en' to 'de' translation.</h1> + <dl> + <dt id="concern" style="font-weight: bold;">concern</dt> + <dd> + <ul> + <li>Sorge</li> + <li>Besorgnis</li> + </ul> + </dd> + <dt id="compassion" style="font-weight: bold;">compassion</dt> + <dd> + <ul> + <li>Barmherzigkeit</li> + <li>Mitgefühl</li> + <li>Mitleid</li> + <li>Erbarmen</li> + </ul> + <p>Synonyms: <a href="#pity">pity</a>, <a href="#concern">concern</a></p> + </dd> + <dt id="jerk" style="font-weight: bold;">jerk</dt> + <dd> + <ul> + <li>Ruck</li> + <li>Trottel</li> + </ul> + </dd> + <dt id="pity" style="font-weight: bold;">pity</dt> + <dd> + <ul> + <li>Mitleid</li> + <li>Erbarmen</li> + <li>Jammer</li> + <li>Mitgefühl</li> + </ul> + <p>Synonym: <a href="#compassion">compassion</a></p> + </dd> + </dl> + </body> + </html> + </x:expect> + </x:scenario> + + + + + +</x:description> diff --git a/Klausuren/Sda1/Ws2015/Exam/dictionary2html.xsl b/Klausuren/Sda1/Ws2015/Exam/dictionary2html.xsl new file mode 100644 index 0000000000000000000000000000000000000000..82b13d12d2c15c79f8fc89305460330da86c61ce --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Exam/dictionary2html.xsl @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="UTF-8"?> +<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + xmlns:xs="http://www.w3.org/2001/XMLSchema" + xmlns="http://www.w3.org/1999/xhtml" + exclude-result-prefixes="xs" + version="2.0"> + + <xsl:output method="xhtml" indent="yes"/> + + <xsl:template match="/dictionary"> + <html> + <head> + </head> + <body> + </body> + </html> + </xsl:template> + +</xsl:stylesheet> \ No newline at end of file diff --git a/Klausuren/Sda1/Ws2015/Exam/pom.xml b/Klausuren/Sda1/Ws2015/Exam/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..117d311bfa58b4928c436e48ea0219b9dcbe6c1b --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Exam/pom.xml @@ -0,0 +1,80 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>de.hdm-stuttgart.mi.sda1</groupId> + <artifactId>exam</artifactId> + <version>1.0</version> + <packaging>jar</packaging> + + <name>exam</name> + + <url>http://freedocs.mi.hdm-stuttgart.de</url> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.11</version> + <scope>test</scope> + <optional>true</optional> + </dependency> + + <dependency> + <groupId>mysql</groupId> + <artifactId>mysql-connector-java</artifactId> + <version>5.1.36</version> + <scope>runtime</scope> + </dependency> + + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-api</artifactId> + <version>2.1</version> + </dependency> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-core</artifactId> + <version>2.1</version> + </dependency> + + <dependency> + <groupId>org.jdom</groupId> + <artifactId>jdom2</artifactId> + <version>2.0.6</version> + </dependency> + + <dependency> + <groupId>jaxen</groupId> + <artifactId>jaxen</artifactId> + <version>1.1.6</version> + </dependency> + + </dependencies> + + <build> + <plugins> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.1</version> + <configuration> + <source>1.8</source> + <target>1.8</target> + </configuration> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-javadoc-plugin</artifactId> + <version>2.10.1</version> + <configuration /> + </plugin> + </plugins> + </build> +</project> diff --git a/Klausuren/Sda1/Ws2015/Exam/src/main/java/de/hdm_stuttgart/mi/sda1/exam/rdbms/DbHandler.java b/Klausuren/Sda1/Ws2015/Exam/src/main/java/de/hdm_stuttgart/mi/sda1/exam/rdbms/DbHandler.java new file mode 100644 index 0000000000000000000000000000000000000000..f97b3313ecc1fb8f2cf4b3d5accfe2808683b4c3 --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Exam/src/main/java/de/hdm_stuttgart/mi/sda1/exam/rdbms/DbHandler.java @@ -0,0 +1,36 @@ +package de.hdm_stuttgart.mi.sda1.exam.rdbms; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + + +/** + * Handling database connections + * + */ +public class DbHandler { + private static Logger log = LogManager.getLogger(DbHandler.class); + + Connection conn = null; + + + /** + * Connecting to our database server + * @throws SQLException Connection failure. + */ + public void connect() throws SQLException { + conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/hdm","hdmuser","XYZ"); + } + + /** + * @throws SQLException Unable to disconnect. + */ + public void disconnect() throws SQLException { + conn.close(); + conn = null; + } +} \ No newline at end of file diff --git a/Klausuren/Sda1/Ws2015/Exam/src/main/java/de/hdm_stuttgart/mi/sda1/exam/rdbms/Xml2Rdbms.java b/Klausuren/Sda1/Ws2015/Exam/src/main/java/de/hdm_stuttgart/mi/sda1/exam/rdbms/Xml2Rdbms.java new file mode 100644 index 0000000000000000000000000000000000000000..d1b50884c608fb85cd1b08f5525b9b51ade5336d --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Exam/src/main/java/de/hdm_stuttgart/mi/sda1/exam/rdbms/Xml2Rdbms.java @@ -0,0 +1,48 @@ +package de.hdm_stuttgart.mi.sda1.exam.rdbms; + +import java.io.IOException; +import java.sql.SQLException; + +import org.jdom2.Element; +import org.jdom2.JDOMException; +import org.jdom2.input.SAXBuilder; + +/** + * Reading XML Data and inserting to relational systems. + * + */ +public class Xml2Rdbms { + + final DbHandler db = new DbHandler(); + + final SAXBuilder builder = new SAXBuilder(); + + /** + * Read XML data for RDBMS transfer. + * + * @param dictionaryFileName XML filename containing dictionary data, + * @throws SQLException Database related error. + * @throws JDOMException Parsing exception + * @throws IOException File access exception. + */ + public void read(final String dictionaryFileName) throws SQLException, JDOMException, IOException { + db.connect(); + + final Element dictionary = builder.build(dictionaryFileName).getRootElement(); + + } + + /** + * + * @param args Unused + * @throws IOException + * @throws JDOMException + * @throws SQLException + */ + public static void main(String[] args) throws JDOMException, IOException, SQLException { + final Xml2Rdbms x2r = new Xml2Rdbms(); + x2r.read("Schema/sampledata.xml"); + + } +} + diff --git a/Klausuren/Sda1/Ws2015/Exam/src/main/resources/log4j2.xml b/Klausuren/Sda1/Ws2015/Exam/src/main/resources/log4j2.xml new file mode 100644 index 0000000000000000000000000000000000000000..49f69dcac991786dd777f31148ce6ddd52f132ea --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Exam/src/main/resources/log4j2.xml @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<Configuration> + <Appenders> + <File name="A1" fileName="A1.log" append="false"> + <PatternLayout pattern="%t %-5p %c{2} - %m%n"/> + </File> + <Console name="STDOUT" target="SYSTEM_OUT"> + <PatternLayout pattern="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/> + </Console> + </Appenders> + <Loggers> + + <!-- You my want to define class or package level per-logger rules --> + <Logger name="de.hdm_stuttgart.mi.sda1.exam.xsd" level="error"> + <AppenderRef ref="A1"/> + </Logger> + + <Logger name="de.hdm_stuttgart.mi.sda1.exam.test.ignore" level="error"> + <AppenderRef ref="A1"/> + </Logger> + + + + <Root level="info"> + <AppenderRef ref="STDOUT"/> + </Root> + </Loggers> +</Configuration> \ No newline at end of file diff --git a/Klausuren/Sda1/Ws2015/Exam/src/test/java/de/hdm_stuttgart/mi/sda1/exam/test/ignore/InstanceSetEvaluation.java b/Klausuren/Sda1/Ws2015/Exam/src/test/java/de/hdm_stuttgart/mi/sda1/exam/test/ignore/InstanceSetEvaluation.java new file mode 100644 index 0000000000000000000000000000000000000000..e2b8edc2ec30187e452c83b4bd6a98434d9c2e7d --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Exam/src/test/java/de/hdm_stuttgart/mi/sda1/exam/test/ignore/InstanceSetEvaluation.java @@ -0,0 +1,144 @@ +package de.hdm_stuttgart.mi.sda1.exam.test.ignore; + +import java.io.File; +import java.io.IOException; +import java.util.List; +import java.util.Vector; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.jdom2.Document; +import org.jdom2.JDOMException; +import org.jdom2.ProcessingInstruction; +import org.jdom2.filter.Filters; +import org.jdom2.input.SAXBuilder; +import org.jdom2.input.sax.XMLReaders; +import org.jdom2.xpath.XPathExpression; +import org.jdom2.xpath.XPathFactory; + +/** + * Evaluate a given set of XML document instances + * + */ +public class InstanceSetEvaluation { + + /** + * Base directory containing xml test file instances. + */ + public final String xmlTestFileDir; + + /** + * true if all tests have been successful. + */ + public final boolean allTestsSucceeded; + + private static Logger log = LogManager.getLogger(InstanceSetEvaluation.class); + + final static List<InstanceTest> tests = new Vector<>(); + + final StringBuffer messages = new StringBuffer(), errorMessages = new StringBuffer(); + + /** + * @param args unused + */ + public static void main(String[] args) { + final InstanceSetEvaluation ise = new InstanceSetEvaluation("SchemaTest"); + System.out.println(ise.getMessages()); + System.out.println("All tests succeeded:" + ise.allTestsSucceeded); + } + + /** + * @return Individual failed test(s) error message(s). + */ + public String getErrorMessages() { + return errorMessages.toString(); + } + + /** + * @return Individual test's and aggregated results. + */ + public String getMessages() { + return messages.toString(); + } + + /** + * + * @param xmlTestFileDir Directory containing XML instances to be processed. + */ + public InstanceSetEvaluation(final String xmlTestFileDir) { + this.xmlTestFileDir = xmlTestFileDir; + + final File rootDirectory = new File(xmlTestFileDir); + + for (final File f: rootDirectory.listFiles( + path -> path.getPath().endsWith(".xml"))) { + readTestHeader(f); + } + + tests.forEach(t -> messages.append(t + "\n")); + tests.stream().filter(t -> !t.testSucceeded).forEach(t -> errorMessages.append(t + "\n")); + + allTestsSucceeded = tests. + stream(). + map(t -> t.testSucceeded). + reduce((a, b) -> a && b). + get(); + + + final int maxPoints = tests. + stream(). + mapToInt(t -> t.reachablePoints). + reduce((a, b) -> a + b). + getAsInt(), + + reachedPoints = tests. + stream(). + filter(t -> t.testSucceeded). + mapToInt(t -> t.reachablePoints). + reduce((a, b) -> a + b). + getAsInt(); + + messages.append(reachedPoints + " of " + maxPoints + + " points have been reached"); + } + + + + void readTestHeader(final File instanceFilename) { + + final SAXBuilder metainfoParser = new SAXBuilder(XMLReaders.NONVALIDATING); + try { + final Document doc = metainfoParser.build(instanceFilename); + + final XPathExpression<ProcessingInstruction> searchHeader = + XPathFactory.instance().compile( + "/processing-instruction('xmlTest')", + Filters.processinginstruction()); + final List<ProcessingInstruction> xmlTestList = + searchHeader.evaluate(doc); + + switch (xmlTestList.size()) { + case 0: + log.info("No 'xmlTest PI found, possible dependency file"); + break; + case 1: + tests.add(new InstanceTest(xmlTestList.get(0), xmlTestFileDir, instanceFilename)); + break; + default: + log.error("Fatal: Found " + xmlTestList.size() + + " <?xmltest ... ?> annotations in file '" + + instanceFilename + "'"); + System.exit(1); + } + + } catch (final JDOMException e) { + log.fatal("Document '" + instanceFilename.getPath() + + "' is invalid:", e); + System.exit(1); + } catch (final IOException e) { + log.fatal("Unable to open '" + instanceFilename.getPath() + + "' for reading:", e); + System.exit(1); + } + } +} diff --git a/Klausuren/Sda1/Ws2015/Exam/src/test/java/de/hdm_stuttgart/mi/sda1/exam/test/ignore/InstanceTest.java b/Klausuren/Sda1/Ws2015/Exam/src/test/java/de/hdm_stuttgart/mi/sda1/exam/test/ignore/InstanceTest.java new file mode 100644 index 0000000000000000000000000000000000000000..46d567455180b5bb1f75994af430f9cfe80ec3e3 --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Exam/src/test/java/de/hdm_stuttgart/mi/sda1/exam/test/ignore/InstanceTest.java @@ -0,0 +1,133 @@ +package de.hdm_stuttgart.mi.sda1.exam.test.ignore; + +import java.io.File; +import java.io.IOException; +import java.util.Optional; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.jdom2.JDOMException; +import org.jdom2.ProcessingInstruction; +import org.jdom2.input.SAXBuilder; +import org.jdom2.input.sax.XMLReaders; + +/** + * Test and evaluate an individual XML instance. + * + */ +public class InstanceTest { + + final SAXBuilder parser = new SAXBuilder(XMLReaders.XSDVALIDATING); + + final File instanceFilename; + + /** + * An examinee may reach this number of point. The value is being defined in + * the corresponding XML instance's PI like e.g.: + * + * <?xmlTest + points = "2" ... ?> + * + */ + public final int reachablePoints; + + /** + * Is this instance expected to be valid or not? The value is being defined in + * the corresponding XML instance's PI like e.g.: + * + * <?xmlTest expectedToBeValid= "false" ... ?> + */ + public final boolean expectedToBeValid; + /** + * Does the current instance test succeed? + */ + public final boolean testSucceeded; + + /** + * Error message in case of unexpected behavior e.g. + * when an invalid instance is supposed to be valid. + */ + public final Optional<String> errMsg; + + private static Logger log = LogManager.getLogger(InstanceTest.class); + + @Override + public String toString() { + if (testSucceeded) { + return instanceFilename + ": " + reachablePoints + " point" + (1 == reachablePoints ? "" : "s") ; + } else { + return instanceFilename + ": " + errMsg.get() + ",\n missing" + reachablePoints +" point(s)"; + } + } + + /** + * Testing an individual instance to be either valid or invalid. + * + * @param xmlTest The PI meta annotation header containing the expected + * result, points etc. + * @param xmlTestFileDir The directory containing the XML instance files. + * @param xmlInstance The current instance to be evaluated. + */ + public InstanceTest(final ProcessingInstruction xmlTest, + final String xmlTestFileDir, final File xmlInstance) { + + this.instanceFilename = xmlInstance; + + if (null == xmlTest.getPseudoAttributeValue("points")) { + log.fatal("Mandatory <?xmlTest points='...' ... ?> is missing in file '" + + xmlInstance + "'"); + System.exit(1); + } + reachablePoints = Integer.parseInt(xmlTest.getPseudoAttributeValue("points")); + + if (null == xmlTest.getPseudoAttributeValue("expectedToBeValid")) { + log.fatal("Mandatory <?xmlTest expectedToBeValid='true|false' ... ?> is missing in file '" + xmlInstance + "'"); + System.exit(1); + } + expectedToBeValid = Boolean.parseBoolean(xmlTest.getPseudoAttributeValue("expectedToBeValid")); + + final Optional<String> preconditionValidFilename; + + boolean preconditionSucceeded = false; + String tmpPreconditionErrMsg = null; + + if (null == xmlTest.getPseudoAttributeValue("preconditionValid")) { + preconditionValidFilename = Optional.empty(); + } else { + preconditionValidFilename = Optional.of(xmlTestFileDir + File.separator + + xmlTest.getPseudoAttributeValue("preconditionValid")); + try { + parser.build(preconditionValidFilename.get()); + log.info("Precondition file '" + preconditionValidFilename.get() + "' is valid"); + preconditionSucceeded = true; + } catch (final JDOMException | IOException e) { + log.info("Precondition file '" + preconditionValidFilename.get() + "' is invalid or missing:", e); + tmpPreconditionErrMsg = "File '" + preconditionValidFilename.get() + "' is either invalid or missing"; + } + } + + if (!preconditionValidFilename.isPresent() || preconditionSucceeded) { + boolean tmpInstanceIsValid = false; + try { + parser.build(xmlInstance); + tmpInstanceIsValid = true; + } catch (final JDOMException | IOException e) { + log.info("Instance file '" + xmlInstance + "' is invalid:", e); + } + testSucceeded = expectedToBeValid == tmpInstanceIsValid; + if (testSucceeded) { + errMsg = Optional.empty(); + } else if (testSucceeded) { + errMsg = Optional.of("Instance '" + xmlInstance + + "' is expected to be invalid!"); + } else { + errMsg = Optional.of("Instance '" + xmlInstance + + "' is expected to be valid!"); + } + } else { + testSucceeded = false; + errMsg = Optional.of(tmpPreconditionErrMsg); + + } + } +} diff --git a/Klausuren/Sda1/Ws2015/Exam/src/test/java/de/hdm_stuttgart/mi/sda1/exam/xsd/SchemaTest.java b/Klausuren/Sda1/Ws2015/Exam/src/test/java/de/hdm_stuttgart/mi/sda1/exam/xsd/SchemaTest.java new file mode 100644 index 0000000000000000000000000000000000000000..c53a95776c867deee2f0463aa76164a32839fabd --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Exam/src/test/java/de/hdm_stuttgart/mi/sda1/exam/xsd/SchemaTest.java @@ -0,0 +1,24 @@ +package de.hdm_stuttgart.mi.sda1.exam.xsd; + +import org.junit.Assert; +import org.junit.Test; + +import de.hdm_stuttgart.mi.sda1.exam.test.ignore.InstanceSetEvaluation; + +/** + * Unit test for an XML instance set. + */ +public class SchemaTest { + /** + * Testing a suite of XML instances. + */ + @Test + public void testXmlInstanceSet() { + + final InstanceSetEvaluation ise = new InstanceSetEvaluation("SchemaTest"); + + Assert.assertTrue(ise.getErrorMessages(), ise.allTestsSucceeded); + + System.out.println(ise.getMessages()); + } +} diff --git a/Klausuren/Sda1/Ws2015/Solution/Doc/a.xhtml b/Klausuren/Sda1/Ws2015/Solution/Doc/a.xhtml new file mode 100644 index 0000000000000000000000000000000000000000..fad2c503376b5e7f2edc9c7f46d2ba1a743d240e --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Solution/Doc/a.xhtml @@ -0,0 +1,122 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE html> +<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml"> + <head> + <title></title> + </head> + + <body><h1>Description</h1><p>Creating a schema to supply an XML store + representing dictionary data.</p><h1 + id="preparations">Preparations</h1><p>Download <a + href="/files/goik/Sda1/mrRw_999TTrq-GdPUgd/exam.zip" + target="_blank">exam.zip</a> and unzip it. Then import the resulting + <code>Exam</code> directory as a <b>Maven Eclipse</b> project into your + workspace. Subsequently mentioned relative file and directory path names + refer to this project's root.</p><h1>Task</h1><p>Start from + <code>Schema/dictionary.xsd</code>. Extend this file thereby providing an + XML schema grammar implementing the constraints being described in the <a + href="#dataModel">Data model description</a> section + below.</p><h1>Hints</h1><ul> + <li>The sample data file <code>Schema/sampledata.xml</code> illustrates + the constraints being described in the <a href="#dataModel">Data model + description</a> section below.</li> + + <li><p>The sub directory <code>SchemaTest</code> contains unit tests + checking your schema for correctness. Some files contained within must + be valid and some must be invalid with respect to your + <code>Schema/dictionary.xsd</code> implementation.</p><p>You may execute + <code>de.hdm_stuttgart.mi.sda1.exam.xsd.SchemaTest</code> from your + project's <code>src/test/java</code> branch as a Junit test. If your + schema is correct you'll read something like:</p><pre>SchemaTest/toType_err.xml: 1 point +SchemaTest/synonymRef_err.xml: 2 points +SchemaTest/translationMinimal_err.xml: 1 point +SchemaTest/fromType_err.xml: 1 point +SchemaTest/noTranslationDuplicate_err.xml: 1 point +SchemaTest/missingTranslation_err.xml: 1 point +SchemaTest/twoEntriesDuplicate_err.xml: 2 points +SchemaTest/empty.xml: 1 point +SchemaTest/synonymDuplicate_err.xml: 1 point +SchemaTest/language_err.xml: 1 point +<b>12 of 12 points have been reached</b></pre></li> + </ul><h1 id="dataModel">Data model description</h1><p>We consider + <code>Schema/sampledata.xml</code> illustrating a data store containing + dictionary data for translation services:</p><pre><dictionary fromLanguage='en' toLanguage='de' + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="dictionary.xsd"> + + <entry> + <from>concern</from> + <translations> + <to>Sorge</to> + <to>Besorgnis</to> + </translations> + </entry> + + <entry> + <from>compassion</from> + <translations> + <to>Barmherzigkeit</to> + <to>Mitgefühl</to> + <to>Mitleid</to> + <to>Erbarmen</to> + </translations> + <synonyms> + <from>pity</from> + <from>concern</from> + </synonyms> + </entry> + ... +</dictionary></pre><p>In this task we will only consider nouns ignoring + other categories like verb, adjective or adverb. The following constraints + shall hold:</p><ol> + <li>Each <code><entry></code> element describes a single word in + an instance wide language being defined by the two letter abbreviation + attribute value in <code><code><dictionary fromLanguage='..' + ...></code></code>. Thus in the given example + <from>concern</from> represents the English noun + ‟<code>concern</code>” due to the value <code><dictionary + fromLanguage=</code><b><code>'en' ... </code></b>.</li> + + <li>Allowed language values are <code>en</code>, <code>de</code>, + <code>fr</code>, <code>it</code> and <code>es</code>.</li> + + <li>The <code><from></code> values below all + <code><entry></code> elements must be unique within the given + <code><dictionary></code>. Each noun to be translated must appear + only once.</li> + + <li>Both <code><from></code> and <code><to></code> values + must not contain spaces. Choose <code>xs:NMTOKEN</code> for their type + definition.</li> + + <li>An <code><entry></code> must contain at least one translation + below the <code><translations></code> section. The translated + language is being defined by e.g. <code><dictionary toLanguage='de' + ...></code>.</li> + + <li>Each <code><translations></code> section must not contain + duplicates.</li> + + <li>Each <code><entry></code> may contain a + <code><synonyms></code> section. Each entry below + <code><synonyms></code> must be unique with respect to all + siblings.</li> + + <li>Each entry below <code><synonyms></code> must refer to an + <code><entry></code> by virtue of its unique + <code><entry><from></code> child value. In the above example + <code><synonyms><from><b>concern</b></from></code> is + a reference to + <code><entry><from><b>concern</b></from></code>.</li> + </ol><h1 style="color: red;">Uploading, caution!</h1><ul> + <li><p>Upon completion zip up your Maven project directory and use the + upload facility below.</p></li> + + <li><p>Mind the remaining time! <b style="color:red;">When the + examination terminates no subsequent uploads will be + possible!</b></p></li> + + <li><p><b style="color:red;">In case of multiple uploads only your last + uploaded zip archive will become subject to marking.</b></p></li> + </ul></body> +</html> diff --git a/Klausuren/Sda1/Ws2015/Solution/Doc/b.xhtml b/Klausuren/Sda1/Ws2015/Solution/Doc/b.xhtml new file mode 100644 index 0000000000000000000000000000000000000000..614b8f673577289451f89dbbd39faaa3064bf236 --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Solution/Doc/b.xhtml @@ -0,0 +1,70 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE html> +<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml"> + <head> + <title></title> + </head> + + <body><h1>Description</h1><p>Transforming dictionary data to Html using + XSL.</p><h1>Preparations</h1><p>See the <b>Preparations</b> section in the + first XSD related task. In case you do not process the XSD task you may + still find valuable hints there.</p><h1>Task</h1><p>Start from + <code>dictionary2html.xsl</code>. Extend this file to generate Html. + Starting from <code><code>sampledata.xml</code></code> you find this + sample's intended target data as + <code>sampledata_target.xhtml</code>:</p><pre><html xmlns="http://www.w3.org/1999/xhtml"> + <head> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> + <title>'en' to 'de' translation.</title> + </head> + <body> + <h1>'en' to 'de' translation.</h1> + <dl> + <dt id="concern" style="font-weight: bold;">concern</dt> + <dd> + <ul> + <li>Sorge</li> + <li>Besorgnis</li> + </ul> + </dd> + <dt id="compassion" style="font-weight: bold;">compassion</dt> +... + </dl> + </body> +</html></pre><p>A <code><dictionary></code> is allowed to be empty + (containing no <code><entry></code> element). In this case the above + <code><dl> ... </dl></code> list shall be replaced by static + text:</p><pre><p>No entries in dictionary</p></pre><h1>Hints</h1><ul> + <li>The file <code>dictionary.xspec</code> contains unit tests to + confirm the expected transformation behaviour of + <code>dictionary2html.xsl</code> by simply hitting the <b>Apply + transformation scenario(s)</b> button.</li> + + <li>Supply <code><xsl:template... ></code> rules for + <code><dictionary></code>, <code><entry></code>, + <code><translations></code> and <code><synonyms></code> + elements to make the Xspec unit tests work. Do not implement separate + templates by (nested) <code><code><xsl:for-each</code> ...></code> + loops. Otherwise tests may fail even if your transformation logic is + correct.</li> + + <li>Examine <code>sampledata_target.xhtml</code> in detail to understand + the HTML implementation of <synonyms> references.</li> + </ul><h1 style="color: red;">Uploading, caution!</h1><ul> + <li><p>Upon completion zip up your Maven project directory and use the + upload facility from the first task even if you don't work on + it.</p></li> + + <li>You may want to check e.g. unit tests from other tasks to avoid the + risk of spoiling features by unintended side effects. As stated + previously <b style="color:red;">only your last uploaded .zip archive + will become subject to marking with respect to all tasks.</b></li> + + <li>Depending on your decision fill in either <b>task processed</b> or + <b>task skipped</b> in the text field below.</li> + + <li><p>Mind the remaining time! <b style="color:red;">When the + examination terminates no subsequent uploads will be + possible!</b></p></li> + </ul></body> +</html> diff --git a/Klausuren/Sda1/Ws2015/Solution/Doc/c.xhtml b/Klausuren/Sda1/Ws2015/Solution/Doc/c.xhtml new file mode 100644 index 0000000000000000000000000000000000000000..367d8d6311464b8879fbc71c3f621316836a4523 --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Solution/Doc/c.xhtml @@ -0,0 +1,77 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE html> +<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml"> + <head> + <title></title> + </head> + + <body><h1>Description</h1><p>Read Xml <code><dictionary ...></code> + data and transfer it to a Mysql server by means of + JDBC.</p><h1>Preparations</h1><p>See the "Preparations" section in the first + XSD related task. In case you do not process the XSD task you may though + find valuable hints there.</p><h1>Task</h1><ol> + <li><p>Create a relational database schema which closely resembles the + constraints being described in the first task ignoring + <code><synonyms></code> sections completely.</p><p>In contrast to + the first task the list of available languages shall be extendable + simply by a suitable <code>INSERT</code> statement. So in case e.g. + Finnish language translation support is desired a simple <code>INSERT + (....,'fi',...)</code> statement in the respective table shall do the + job.</p></li> + + <li><p>Implement a Jdom based Java application which reads XML data e.g. + from <code>Schema/sampledata.xml</code> and writes corresponding records + to your local Mysql server by means of JDBC. Ignore + <code><synonyms></code> sections.</p></li> + + <li><p>Your application shall accept any valid <code><dictionary + ...></code> input. Conflicts with existing data shall be ignored. + Specifically reading from e.g. <code>Schema/sampledata.xml</code> twice + shall be processed without errors. However the second attempt will not + modify any data.</p></li> + + <li>Calling your application repeatedly shall allow for importing + (different) XML instances in sequence. Thus a user might start with + <code><dictionary fromLanguage='en' toLanguage='de' ...></code> + and subsequently import a different translation <code><dictionary + fromLanguage='fr' toLanguage='it' ...></code> combining the + respective translations into the same database.</li> + </ol><p>Note: Even if you did not work on the XML schema + <code>dictionary.xsd</code> you may still provide <code>CREATE TABLE</code> + statements reflecting the constraints in question.</p><h1>Hints</h1><ul> + <li><p>The classes + <code>de.hdm_stuttgart.mi.sda1.exam.rdbms.Xml2Rdbms</code> and + <code>de.hdm_stuttgart.mi.sda1.exam.rdbms.DbHandler</code> contain Jdom + and JDBC related boilerplate code.</p><p>The class + <code>de.hdm_stuttgart.mi.sda1.exam.rdbms.Xml2Rdbms</code> uses an + instance of <code><code>DbHandler</code></code>. You are however free to + ignore this setup and start from scratch as well.</p></li> + + <li><p>Use <code><a + href="https://docs.oracle.com/javase/8/docs/api/java/sql/PreparedStatement.html" + target="_blank">PreparedStatement</a></code> instances both for security + and performance considerations.</p></li> + + <li>Three tables representing available languages, the nouns among with + their corresponding languages and the translations themselves will do + the job.</li> + </ul><h1 style="color: red;">Uploading, caution!</h1><ul> + <li><p>Upon completion zip up your Maven project directory and use the + upload facility from the first task even if you don't work on + it.</p></li> + + <li>You may want to check e.g. unit tests from other tasks to avoid the + risk of spoiling features by unintended side effects. As stated + previously <b style="color:red;">only your last uploaded .zip archive + will become subject to marking with respect to all tasks.</b></li> + + <li>Depending on your decision fill in either <b>task processed</b> or + <b>task skipped</b> in the text field below. If you processed this task + provide a hint to your entry class containing the <code>main(...)</code> + method to start with.</li> + + <li><p>Mind the remaining time! <b style="color:red;">When the + examination terminates no subsequent uploads will be + possible!</b></p></li> + </ul></body> +</html> diff --git a/Klausuren/Sda1/Ws2015/Solution/Schema/dictionary.xsd b/Klausuren/Sda1/Ws2015/Solution/Schema/dictionary.xsd new file mode 100644 index 0000000000000000000000000000000000000000..e40c6000796e85d36a6bb9e44d1e0d7303e5b219 --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Solution/Schema/dictionary.xsd @@ -0,0 +1,71 @@ +<?xml version="1.0" encoding="UTF-8"?> +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" + xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning" elementFormDefault="qualified" + vc:minVersion="1.1"> + + <xs:simpleType name="language"> + <xs:restriction base="xs:token"> + <xs:enumeration value="en"/> + <xs:enumeration value="de"/> + <xs:enumeration value="fr"/> + <xs:enumeration value="it"/> + <xs:enumeration value="es"/> + </xs:restriction> + </xs:simpleType> + + <xs:element name="dictionary"> + <xs:complexType> + <xs:sequence> + <xs:element ref="entry" minOccurs="0" maxOccurs="unbounded"/> + </xs:sequence> + <xs:attribute name="fromLanguage" type="language" use="required"/> + <xs:attribute name="toLanguage" type="language" use="required"/> + </xs:complexType> + + <xs:key name="uniqueVocabularyName"> + <xs:selector xpath="entry"/> + <xs:field xpath="from"/> + </xs:key> + + <xs:keyref name="synonym2entry" refer="uniqueVocabularyName"> + <xs:selector xpath="entry/synonyms/from"/> + <xs:field xpath="."/> + </xs:keyref> + + </xs:element> + + <xs:element name="entry"> + <xs:complexType> + <xs:sequence> + <xs:element name="from" type="xs:NMTOKEN"/> + <xs:element ref="translations"/> + <xs:element ref="synonyms" minOccurs="0" maxOccurs="1"/> + </xs:sequence> + </xs:complexType> + </xs:element> + + <xs:element name="translations"> + <xs:complexType> + <xs:sequence> + <xs:element name="to" type="xs:NMTOKEN" maxOccurs="unbounded"/> + </xs:sequence> + </xs:complexType> + <xs:key name="noDuplicateTo"> + <xs:selector xpath="to"/> + <xs:field xpath="."/> + </xs:key> + </xs:element> + + <xs:element name="synonyms"> + <xs:complexType> + <xs:sequence> + <xs:element name="from" type="xs:string" minOccurs="1" maxOccurs="unbounded"/> + </xs:sequence> + </xs:complexType> + <xs:key name="noDuplicateSynonym"> + <xs:selector xpath="from"/> + <xs:field xpath="."/> + </xs:key> + </xs:element> + +</xs:schema> diff --git a/Klausuren/Sda1/Ws2015/Solution/Schema/sampledata.xml b/Klausuren/Sda1/Ws2015/Solution/Schema/sampledata.xml new file mode 100644 index 0000000000000000000000000000000000000000..3eeac0ffb45567d14f311128ab8fb10e7ab90734 --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Solution/Schema/sampledata.xml @@ -0,0 +1,50 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<dictionary fromLanguage='en' toLanguage='de' + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="dictionary.xsd"> + + <entry> + <from>concern</from> + <translations> + <to>Sorge</to> + <to>Besorgnis</to> + </translations> + </entry> + + <entry> + <from>compassion</from> + <translations> + <to>Barmherzigkeit</to> + <to>Mitgefühl</to> + <to>Mitleid</to> + <to>Erbarmen</to> + </translations> + <synonyms> + <from>pity</from> + <from>concern</from> + </synonyms> + </entry> + + <entry> + <from>jerk</from> + <translations> + <to>Ruck</to> + <to>Trottel</to> + </translations> + </entry> + + <entry> + <from>pity</from> + <translations> + <to>Mitleid</to> + <to>Erbarmen</to> + <to>Jammer</to> + <to>Mitgefühl</to> + </translations> + <synonyms> + <from>compassion</from> + </synonyms> + </entry> + +</dictionary> diff --git a/Klausuren/Sda1/Ws2015/Solution/Schema/sampledata_target.xhtml b/Klausuren/Sda1/Ws2015/Solution/Schema/sampledata_target.xhtml new file mode 100644 index 0000000000000000000000000000000000000000..790de89452f28d544505a515ea9e8ff1a3916e82 --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Solution/Schema/sampledata_target.xhtml @@ -0,0 +1,46 @@ +<?xml version="1.0" encoding="UTF-8"?> +<html xmlns="http://www.w3.org/1999/xhtml"> + <head> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> + <title>'en' to 'de' translation.</title> + </head> + <body> + <h1>'en' to 'de' translation.</h1> + <dl> + <dt id="concern" style="font-weight: bold;">concern</dt> + <dd> + <ul> + <li>Sorge</li> + <li>Besorgnis</li> + </ul> + </dd> + <dt id="compassion" style="font-weight: bold;">compassion</dt> + <dd> + <ul> + <li>Barmherzigkeit</li> + <li>Mitgefühl</li> + <li>Mitleid</li> + <li>Erbarmen</li> + </ul> + <p>Synonyms: <a href="#pity">pity</a>, <a href="#concern">concern</a></p> + </dd> + <dt id="jerk" style="font-weight: bold;">jerk</dt> + <dd> + <ul> + <li>Ruck</li> + <li>Trottel</li> + </ul> + </dd> + <dt id="pity" style="font-weight: bold;">pity</dt> + <dd> + <ul> + <li>Mitleid</li> + <li>Erbarmen</li> + <li>Jammer</li> + <li>Mitgefühl</li> + </ul> + <p>Synonym: <a href="#compassion">compassion</a></p> + </dd> + </dl> + </body> +</html> \ No newline at end of file diff --git a/Klausuren/Sda1/Ws2015/Solution/Schema/schema.sql b/Klausuren/Sda1/Ws2015/Solution/Schema/schema.sql new file mode 100644 index 0000000000000000000000000000000000000000..a991d8c527a7933c313836ff9752fc7d0d9d5423 --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Solution/Schema/schema.sql @@ -0,0 +1,40 @@ +DROP TABLE IF EXISTS Translation; +DROP TABLE IF EXISTS Noun; +DROP TABLE IF EXISTS Language; + +CREATE TABLE Language ( + id INTEGER AUTO_INCREMENT PRIMARY KEY, + lang CHAR(2) NOT NULL UNIQUE +); + +CREATE TABLE Noun ( + id INTEGER AUTO_INCREMENT PRIMARY KEY, + lang INTEGER NOT NULL, + word CHAR(255) NOT NULL, + UNIQUE(lang, word), + FOREIGN KEY (lang) REFERENCES Language(id) +); + +CREATE TABLE Translation( + fromNoun INTEGER, + toNoun INTEGER, + PRIMARY KEY(fromNoun, toNoun), + FOREIGN KEY (fromNoun) REFERENCES Noun(id), + FOREIGN KEY (toNoun) REFERENCES Noun(id) +); + + +SELECT * FROM Translation; +SELECT * FROM Noun; +SELECT * FROM Language; + +SELECT f.word, fLang.lang, t.word, toLang.lang +FROM Language fLang, Noun f, Translation trans, Noun t, Language toLang +WHERE fLang.id = f.lang + AND f.id = trans.fromNoun + AND trans.toNoun = t.id + AND t.lang=toLang.id; + +DELETE FROM Translation; +DELETE FROM Noun; +DELETE FROM Language; diff --git a/Klausuren/Sda1/Ws2015/Solution/SchemaTest/doubleSynonymSection_err.xml b/Klausuren/Sda1/Ws2015/Solution/SchemaTest/doubleSynonymSection_err.xml new file mode 100644 index 0000000000000000000000000000000000000000..bc6a3fd56c86dafee72d5b550e6adc922ba71901 --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Solution/SchemaTest/doubleSynonymSection_err.xml @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<dictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="../Schema/dictionary.xsd" fromLanguage='en' + toLanguage='de'> + <entry> + <from>concern</from> + <translations> + <to>Sorge</to> + <to>Besorgnis</to> + </translations> + </entry> + + <entry> + <from>compassion</from> + <translations> + <to>Barmherzigkeit</to> + <to>Mitgefühl</to> + </translations> + <synonyms> + <from>pity</from> + </synonyms> + <synonyms> + <from>concern</from> + </synonyms> + </entry> + + <entry> + <from>pity</from> + <translations> + <to>Mitleid</to> + <to>Erbarmen</to> + </translations> + <synonyms> + <from>compassion</from> + </synonyms> + </entry> + +</dictionary> + +<!-- Subsequent lines contain only processing instructions irrelevant to instance's validity --> +<?xmlTest + points = "1" + expectedToBeValid = "false" + preconditionValid = "synonym.xml" ?> \ No newline at end of file diff --git a/Klausuren/Sda1/Ws2015/Solution/SchemaTest/duplicateTranslationSection_err.xml b/Klausuren/Sda1/Ws2015/Solution/SchemaTest/duplicateTranslationSection_err.xml new file mode 100644 index 0000000000000000000000000000000000000000..b1db4e4c60ba0912c0b81f8fd5f3aee5bdefba2c --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Solution/SchemaTest/duplicateTranslationSection_err.xml @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<dictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="../Schema/dictionary.xsd" fromLanguage='en' toLanguage='de'> + + <entry> + <from>compassion</from> + <translations> + <to>Barmherzigkeit</to> + <to>Mitgefühl</to> + </translations> + <translations> + <to>Mitleid</to> + <to>Erbarmen</to> + </translations> + </entry> +</dictionary> + +<!-- Subsequent lines contain only processing instructions irrelevant to instance's validity --> +<?xmlTest + points = "1" + expectedToBeValid= "false" + preconditionValid="noTranslationDuplicate.xml" ?> \ No newline at end of file diff --git a/Klausuren/Sda1/Ws2015/Solution/SchemaTest/empty.xml b/Klausuren/Sda1/Ws2015/Solution/SchemaTest/empty.xml new file mode 100644 index 0000000000000000000000000000000000000000..07f98f3bc1b1702701fbe13acf3c8c409f3c6a0f --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Solution/SchemaTest/empty.xml @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<dictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="../Schema/dictionary.xsd" fromLanguage='en' toLanguage='de'/> + + +<!-- Subsequent lines contain only processing instructions irrelevant to instance's validity --> +<?xmlTest + points = "1" + expectedToBeValid= "true" ?> \ No newline at end of file diff --git a/Klausuren/Sda1/Ws2015/Solution/SchemaTest/fromType_err.xml b/Klausuren/Sda1/Ws2015/Solution/SchemaTest/fromType_err.xml new file mode 100644 index 0000000000000000000000000000000000000000..fa9b5afd285bf9e71b5a127ca90426e477b4d563 --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Solution/SchemaTest/fromType_err.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<dictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="../Schema/dictionary.xsd" fromLanguage='en' + toLanguage='de'> + <entry> + <from></from> + <translations> + <to>Sonne</to> + </translations> + </entry> + +</dictionary> + + +<!-- Subsequent lines contain only processing instructions irrelevant to instance's validity --> +<?xmlTest + points = "1" + expectedToBeValid = "false" + preconditionValid = "type.xml" ?> \ No newline at end of file diff --git a/Klausuren/Sda1/Ws2015/Solution/SchemaTest/language_err.xml b/Klausuren/Sda1/Ws2015/Solution/SchemaTest/language_err.xml new file mode 100644 index 0000000000000000000000000000000000000000..38f980e343636dd33bde4d3da2b9d9d615d2ec9d --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Solution/SchemaTest/language_err.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<dictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="../Schema/dictionary.xsd" fromLanguage='en' + toLanguage='fi'/> + + +<!-- Subsequent lines contain only processing instructions irrelevant to instance's validity --> +<?xmlTest + points = "1" + expectedToBeValid = "false" + preconditionValid = "empty.xml" ?> \ No newline at end of file diff --git a/Klausuren/Sda1/Ws2015/Solution/SchemaTest/missingTranslation_err.xml b/Klausuren/Sda1/Ws2015/Solution/SchemaTest/missingTranslation_err.xml new file mode 100644 index 0000000000000000000000000000000000000000..4ce8fef9adf5b692f3b3c9c35fb4ec1baa27da6e --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Solution/SchemaTest/missingTranslation_err.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<dictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="../Schema/dictionary.xsd" fromLanguage='en' toLanguage='de'> + + <entry> + <from>compassion</from> + </entry> +</dictionary> + +<!-- Subsequent lines contain only processing instructions irrelevant to instance's validity --> +<?xmlTest + points = "1" + expectedToBeValid= "false" + preconditionValid="translation.xml" ?> \ No newline at end of file diff --git a/Klausuren/Sda1/Ws2015/Solution/SchemaTest/noTranslationDuplicate.xml b/Klausuren/Sda1/Ws2015/Solution/SchemaTest/noTranslationDuplicate.xml new file mode 100644 index 0000000000000000000000000000000000000000..d94329d0ef333ba47766e4d767282f7934116139 --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Solution/SchemaTest/noTranslationDuplicate.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<dictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="../Schema/dictionary.xsd" fromLanguage='en' toLanguage='de'> + + <entry> + <from>compassion</from> + <translations> + <to>Barmherzigkeit</to> + <to>Mitgefühl</to> + <to>Mitleid</to> + <to>Erbarmen</to> + </translations> + </entry> +</dictionary> \ No newline at end of file diff --git a/Klausuren/Sda1/Ws2015/Solution/SchemaTest/noTranslationDuplicate_err.xml b/Klausuren/Sda1/Ws2015/Solution/SchemaTest/noTranslationDuplicate_err.xml new file mode 100644 index 0000000000000000000000000000000000000000..a96976ca2aa71c9d3aa6efa6f14770f4bd668d67 --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Solution/SchemaTest/noTranslationDuplicate_err.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<dictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="../Schema/dictionary.xsd" fromLanguage='en' toLanguage='de'> + + <entry> + <from>compassion</from> + <translations> + <to>Barmherzigkeit</to> + <to>Mitgefühl</to> + <to>Mitleid</to> + <to>Erbarmen</to> + <to>Mitgefühl</to> + </translations> + </entry> +</dictionary> + +<!-- Subsequent lines contain only processing instructions irrelevant to instance's validity --> +<?xmlTest + points = "1" + expectedToBeValid= "false" + preconditionValid="noTranslationDuplicate.xml" ?> \ No newline at end of file diff --git a/Klausuren/Sda1/Ws2015/Solution/SchemaTest/synonym.xml b/Klausuren/Sda1/Ws2015/Solution/SchemaTest/synonym.xml new file mode 100644 index 0000000000000000000000000000000000000000..7017b0fafc83a0be7a3dbfa8b3a85c2711cf090d --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Solution/SchemaTest/synonym.xml @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<dictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="../Schema/dictionary.xsd" fromLanguage='en' + toLanguage='de'> + <entry> + <from>concern</from> + <translations> + <to>Sorge</to> + <to>Besorgnis</to> + </translations> + </entry> + + <entry> + <from>compassion</from> + <translations> + <to>Barmherzigkeit</to> + <to>Mitgefühl</to> + </translations> + <synonyms> + <from>pity</from> + <from>concern</from> + </synonyms> + </entry> + + <entry> + <from>pity</from> + <translations> + <to>Mitleid</to> + <to>Erbarmen</to> + </translations> + <synonyms> + <from>compassion</from> + </synonyms> + </entry> + +</dictionary> \ No newline at end of file diff --git a/Klausuren/Sda1/Ws2015/Solution/SchemaTest/synonymDuplicate_err.xml b/Klausuren/Sda1/Ws2015/Solution/SchemaTest/synonymDuplicate_err.xml new file mode 100644 index 0000000000000000000000000000000000000000..6a2ad853454c56f14d1b97936b5c74586c7faf85 --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Solution/SchemaTest/synonymDuplicate_err.xml @@ -0,0 +1,47 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<dictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="../Schema/dictionary.xsd" fromLanguage='en' + toLanguage='de'> + <entry> + <from>concern</from> + <translations> + <to>Sorge</to> + <to>Besorgnis</to> + </translations> + </entry> + + <entry> + <from>compassion</from> + <translations> + <to>Barmherzigkeit</to> + <to>Mitgefühl</to> + </translations> + <synonyms> + <from>pity</from> + <from>concern</from> + <from>pity</from> + </synonyms> + </entry> + + <entry> + <from>pity</from> + <translations> + <to>Mitleid</to> + <to>Erbarmen</to> + <to>Jammer</to> + <to>Mitgefühl</to> + </translations> + <synonyms> + <from>compassion</from> + </synonyms> + </entry> + +</dictionary> + + +<!-- Subsequent lines contain only processing instructions irrelevant to instance's validity --> +<?xmlTest + points = "1" + expectedToBeValid = "false" + preconditionValid = "synonym.xml" ?> \ No newline at end of file diff --git a/Klausuren/Sda1/Ws2015/Solution/SchemaTest/synonymRef_err.xml b/Klausuren/Sda1/Ws2015/Solution/SchemaTest/synonymRef_err.xml new file mode 100644 index 0000000000000000000000000000000000000000..4c03d132b1a4dee5980f08da1c57031491919ccd --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Solution/SchemaTest/synonymRef_err.xml @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<dictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="../Schema/dictionary.xsd" fromLanguage='en' + toLanguage='de'> + <entry> + <from>concern</from> + <translations> + <to>Sorge</to> + <to>Besorgnis</to> + </translations> + </entry> + + <entry> + <from>compassion</from> + <translations> + <to>Barmherzigkeit</to> + <to>Mitgefühl</to> + </translations> + <synonyms> + <from>pity</from> + <from>conincidence</from> + </synonyms> + </entry> + + <entry> + <from>pity</from> + <translations> + <to>Mitleid</to> + <to>Erbarmen</to> + <to>Jammer</to> + <to>Mitgefühl</to> + </translations> + <synonyms> + <from>compassion</from> + </synonyms> + </entry> + +</dictionary> + +<!-- Subsequent lines contain only processing instructions irrelevant to instance's validity --> +<?xmlTest + points = "2" + expectedToBeValid = "false" + preconditionValid = "synonym.xml" ?> \ No newline at end of file diff --git a/Klausuren/Sda1/Ws2015/Solution/SchemaTest/toType_err.xml b/Klausuren/Sda1/Ws2015/Solution/SchemaTest/toType_err.xml new file mode 100644 index 0000000000000000000000000000000000000000..d8133ab68c9e245a1d8c248c5f93dc610ae81bb6 --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Solution/SchemaTest/toType_err.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<dictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="../Schema/dictionary.xsd" fromLanguage='en' + toLanguage='de'> + <entry> + <from>Sun</from> + <translations> + <to>Sonne</to> + <to></to> + </translations> + </entry> + +</dictionary> + + +<!-- Subsequent lines contain only processing instructions irrelevant to instance's validity --> +<?xmlTest + points = "1" + expectedToBeValid = "false" + preconditionValid = "type.xml" ?> \ No newline at end of file diff --git a/Klausuren/Sda1/Ws2015/Solution/SchemaTest/translation.xml b/Klausuren/Sda1/Ws2015/Solution/SchemaTest/translation.xml new file mode 100644 index 0000000000000000000000000000000000000000..953956b52a1ea298314bf3311165d1e196b75c06 --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Solution/SchemaTest/translation.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="UTF-8"?> +<dictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="../Schema/dictionary.xsd" fromLanguage='en' toLanguage='de'> + + <entry> + <from>compassion</from> + <translations> + <to>Barmherzigkeit</to> + </translations> + </entry> + +</dictionary> \ No newline at end of file diff --git a/Klausuren/Sda1/Ws2015/Solution/SchemaTest/translationMinimal.xml b/Klausuren/Sda1/Ws2015/Solution/SchemaTest/translationMinimal.xml new file mode 100644 index 0000000000000000000000000000000000000000..934a92abd760f1d86627836275d01f2b2fe0d5bd --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Solution/SchemaTest/translationMinimal.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<dictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="../Schema/dictionary.xsd" fromLanguage='en' toLanguage='de'> + + <entry> + <from>compassion</from> + <translations> + <to>Barmherzigkeit</to> + </translations> + </entry> +</dictionary> \ No newline at end of file diff --git a/Klausuren/Sda1/Ws2015/Solution/SchemaTest/translationMinimal_err.xml b/Klausuren/Sda1/Ws2015/Solution/SchemaTest/translationMinimal_err.xml new file mode 100644 index 0000000000000000000000000000000000000000..0abeffd8df069ba6057e1dfe139eeea9ca75775f --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Solution/SchemaTest/translationMinimal_err.xml @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<dictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="../Schema/dictionary.xsd" fromLanguage='en' toLanguage='de'> + + <entry> + <from>compassion</from> + <translations/> + </entry> +</dictionary> + +<!-- Subsequent lines contain only processing instructions irrelevant to instance's validity --> +<?xmlTest + points = "1" + expectedToBeValid= "false" + preconditionValid="translationMinimal.xml" ?> \ No newline at end of file diff --git a/Klausuren/Sda1/Ws2015/Solution/SchemaTest/twoEntries.xml b/Klausuren/Sda1/Ws2015/Solution/SchemaTest/twoEntries.xml new file mode 100644 index 0000000000000000000000000000000000000000..0a5ffd1d6336b59e5eb8e09330da9a771dd6a871 --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Solution/SchemaTest/twoEntries.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<dictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="../Schema/dictionary.xsd" fromLanguage='en' + toLanguage='de'> + <entry> + <from>Sun</from> + <translations> + <to>Sonne</to> + </translations> + </entry> + + <entry> + <from>Moon</from> + <translations> + <to>Mond</to> + </translations> + </entry> + +</dictionary> \ No newline at end of file diff --git a/Klausuren/Sda1/Ws2015/Solution/SchemaTest/twoEntriesDuplicate_err.xml b/Klausuren/Sda1/Ws2015/Solution/SchemaTest/twoEntriesDuplicate_err.xml new file mode 100644 index 0000000000000000000000000000000000000000..c1eafe78f24218131968a72a1d52bfb20787578c --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Solution/SchemaTest/twoEntriesDuplicate_err.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<dictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="../Schema/dictionary.xsd" fromLanguage='en' + toLanguage='de'> + <entry> + <from>Sun</from> + <translations> + <to>Sonne</to> + </translations> + </entry> + + <entry> + <from>Sun</from> + <translations> + <to>Himmelsstern</to> + </translations> + </entry> + +</dictionary> + +<?xmlTest + points = "1" + expectedToBeValid = "false" + preconditionValid = "twoEntries.xml" ?> \ No newline at end of file diff --git a/Klausuren/Sda1/Ws2015/Solution/SchemaTest/type.xml b/Klausuren/Sda1/Ws2015/Solution/SchemaTest/type.xml new file mode 100644 index 0000000000000000000000000000000000000000..cada5b36429657fb73b4c33ff922f8de900824b4 --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Solution/SchemaTest/type.xml @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<dictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="../Schema/dictionary.xsd" fromLanguage='en' + toLanguage='de'> + <entry> + <from>Sun</from> + <translations> + <to>Sonne</to> + </translations> + </entry> + +</dictionary> \ No newline at end of file diff --git a/Klausuren/Sda1/Ws2015/Solution/dictionary-result.html b/Klausuren/Sda1/Ws2015/Solution/dictionary-result.html new file mode 100644 index 0000000000000000000000000000000000000000..435606ada50a24eeaf24aaca6d709094b3ace646 --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Solution/dictionary-result.html @@ -0,0 +1,151 @@ +<?xml version="1.0" encoding="UTF-8"?><html xmlns:test="http://www.jenitennison.com/xslt/unit-test" xmlns="http://www.w3.org/1999/xhtml"> + <head> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> + <title>Test Report for ma/goik/Klausur/Ws2015/Sda1/Solution/dictionary2html.xsl (passed:5 / pending:0 / failed:0 / total:5)</title> + <link rel="stylesheet" type="text/css" href="file:/usr/share/eclipseMars/dropins/oxygenxml.oxygen_17.1/plugins/com.oxygenxml.editor_17.1.0.v2015111718/frameworks/xspec/src/reporter/test-report.css" /> + </head> + <body> + <h1>Test Report</h1> + <p xmlns:oxy="http://www.oxygenxml.com/xslt/xspec">Stylesheet: <a href="file:/ma/goik/Klausur/Ws2015/Sda1/Solution/dictionary2html.xsl">ma/goik/Klausur/Ws2015/Sda1/Solution/dictionary2html.xsl</a></p> + <p xmlns:oxy="http://www.oxygenxml.com/xslt/xspec">Tested: 11 February 2016 at 08:59</p> + <h2 xmlns:oxy="http://www.oxygenxml.com/xslt/xspec">Contents</h2> + <table xmlns:oxy="http://www.oxygenxml.com/xslt/xspec" class="xspec"> + <col width="80%" /> + <col width="5%" /> + <col width="5%" /> + <col width="5%" /> + <col width="5%" /> + <thead> + <tr> + <th></th> + <th class="result">passed:5</th> + <th class="result">pending:0</th> + <th class="result">failed:0</th> + <th class="result">total:5</th> + </tr> + </thead> + <tbody> + <tr class="successful"> + <th><a href="#d4e4">An empty '/dictionary'</a></th> + <th class="result">1</th> + <th class="result">0</th> + <th class="result">0</th> + <th class="result">1</th> + </tr> + <tr class="successful"> + <th><a href="#d4e63">A single 'entry'</a></th> + <th class="result">1</th> + <th class="result">0</th> + <th class="result">0</th> + <th class="result">1</th> + </tr> + <tr class="successful"> + <th><a href="#d4e120">'/dictionary' containing one entry</a></th> + <th class="result">1</th> + <th class="result">0</th> + <th class="result">0</th> + <th class="result">1</th> + </tr> + <tr class="successful"> + <th><a href="#d4e225">Scenario for testing template with match 'synonyms</a></th> + <th class="result">1</th> + <th class="result">0</th> + <th class="result">0</th> + <th class="result">1</th> + </tr> + <tr class="successful"> + <th><a href="#d4e312">Complete sample data.</a></th> + <th class="result">1</th> + <th class="result">0</th> + <th class="result">0</th> + <th class="result">1</th> + </tr> + </tbody> + </table> + <div xmlns:oxy="http://www.oxygenxml.com/xslt/xspec" id="d4e4"> + <h2 class="successful">An empty '/dictionary'<span class="scenario-totals">passed:1 / pending:0 / failed:0 / total:1</span></h2> + <table class="xspec" id="t-d4e4"> + <col width="80%" /> + <col width="20%" /> + <tbody> + <tr class="successful"> + <th>An empty '/dictionary'</th> + <th>passed:1 / pending:0 / failed:0 / total:1</th> + </tr> + <tr class="successful"> + <td>Message indicating empty dictionary</td> + <td>Success</td> + </tr> + </tbody> + </table> + </div> + <div xmlns:oxy="http://www.oxygenxml.com/xslt/xspec" id="d4e63"> + <h2 class="successful">A single 'entry'<span class="scenario-totals">passed:1 / pending:0 / failed:0 / total:1</span></h2> + <table class="xspec" id="t-d4e63"> + <col width="80%" /> + <col width="20%" /> + <tbody> + <tr class="successful"> + <th>A single 'entry'</th> + <th>passed:1 / pending:0 / failed:0 / total:1</th> + </tr> + <tr class="successful"> + <td>A dt/dd pair.</td> + <td>Success</td> + </tr> + </tbody> + </table> + </div> + <div xmlns:oxy="http://www.oxygenxml.com/xslt/xspec" id="d4e120"> + <h2 class="successful">'/dictionary' containing one entry<span class="scenario-totals">passed:1 / pending:0 / failed:0 / total:1</span></h2> + <table class="xspec" id="t-d4e120"> + <col width="80%" /> + <col width="20%" /> + <tbody> + <tr class="successful"> + <th>'/dictionary' containing one entry</th> + <th>passed:1 / pending:0 / failed:0 / total:1</th> + </tr> + <tr class="successful"> + <td>A dl list containing one entry</td> + <td>Success</td> + </tr> + </tbody> + </table> + </div> + <div xmlns:oxy="http://www.oxygenxml.com/xslt/xspec" id="d4e225"> + <h2 class="successful">Scenario for testing template with match 'synonyms<span class="scenario-totals">passed:1 / pending:0 / failed:0 / total:1</span></h2> + <table class="xspec" id="t-d4e225"> + <col width="80%" /> + <col width="20%" /> + <tbody> + <tr class="successful"> + <th>Scenario for testing template with match 'synonyms</th> + <th>passed:1 / pending:0 / failed:0 / total:1</th> + </tr> + <tr class="successful"> + <td>A coma separated list of all synonyms</td> + <td>Success</td> + </tr> + </tbody> + </table> + </div> + <div xmlns:oxy="http://www.oxygenxml.com/xslt/xspec" id="d4e312"> + <h2 class="successful">Complete sample data.<span class="scenario-totals">passed:1 / pending:0 / failed:0 / total:1</span></h2> + <table class="xspec" id="t-d4e312"> + <col width="80%" /> + <col width="20%" /> + <tbody> + <tr class="successful"> + <th>Complete sample data.</th> + <th>passed:1 / pending:0 / failed:0 / total:1</th> + </tr> + <tr class="successful"> + <td>A coma separated list of all synonyms</td> + <td>Success</td> + </tr> + </tbody> + </table> + </div> + </body> +</html> \ No newline at end of file diff --git a/Klausuren/Sda1/Ws2015/Solution/dictionary.xspec b/Klausuren/Sda1/Ws2015/Solution/dictionary.xspec new file mode 100644 index 0000000000000000000000000000000000000000..4200290c773770c0ae083c1b7c1fcafcc470fb9a --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Solution/dictionary.xspec @@ -0,0 +1,216 @@ +<?xml version="1.0" encoding="UTF-8"?> +<x:description xmlns:x="http://www.jenitennison.com/xslt/xspec" stylesheet="dictionary2html.xsl"> + + <x:scenario label="An empty '/dictionary'"> + <x:context> + <dictionary fromLanguage='en' toLanguage='de' + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="dictionary.xsd"/> + </x:context> + <x:expect label="Message indicating empty dictionary"> + <html xmlns="http://www.w3.org/1999/xhtml"> + <head> + <title>'en' to 'de' translation.</title> + </head> + <body> + <h1>'en' to 'de' translation.</h1> + <p>No entries in dictionary</p> + </body> + </html> + </x:expect> + </x:scenario> + + <x:scenario label="A single 'entry'"> + <x:context> + <entry> + <from>concern</from> + <translations> + <to>Sorge</to> + </translations> + </entry> + </x:context> + <x:expect label="A dt/dd pair."> + <dt xmlns="http://www.w3.org/1999/xhtml" id="concern" style="font-weight: bold;">concern</dt> + <dd xmlns="http://www.w3.org/1999/xhtml"> + <ul> + <li>Sorge</li> + </ul> + </dd> + </x:expect> + </x:scenario> + + <x:scenario label="'/dictionary' containing one entry"> + <x:context> + <dictionary fromLanguage='en' toLanguage='de' + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="dictionary.xsd"> + + <entry> + <from>concern</from> + <translations> + <to>Sorge</to> + <to>Besorgnis</to> + </translations> + </entry> + </dictionary> + </x:context> + <x:expect label="A dl list containing one entry"> + <html xmlns="http://www.w3.org/1999/xhtml"> + <head> + <title>'en' to 'de' translation.</title> + </head> + <body> + <h1>'en' to 'de' translation.</h1> + <dl> + <dt id="concern" style="font-weight: bold;">concern</dt> + <dd> + <ul> + <li>Sorge</li> + <li>Besorgnis</li> + </ul> + </dd> + </dl> + </body> + </html> + </x:expect> + </x:scenario> + + <x:scenario label="Scenario for testing template with match 'synonyms"> + <x:context select="dictionary/entry/synonyms"> + <dictionary fromLanguage='en' toLanguage='de' + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="dictionary.xsd"> + + <entry> + <from>concern</from> + <translations> + <to>Sorge</to> + <to>Besorgnis</to> + </translations> + </entry> + + <entry> + <from>compassion</from> + <translations> + <to>Barmherzigkeit</to> + <to>Mitgefühl</to> + <to>Mitleid</to> + <to>Erbarmen</to> + </translations> + <synonyms> + <from>pity</from> + <from>concern</from> + </synonyms> + </entry> + </dictionary> + </x:context> + <x:expect label="A coma separated list of all synonyms"> + <p xmlns="http://www.w3.org/1999/xhtml">Synonyms: <a href="#pity">pity</a>, <a href="#concern">concern</a></p> + </x:expect> + </x:scenario> + + <x:scenario label="Complete sample data."> + <x:context> + <dictionary fromLanguage='en' toLanguage='de' + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="dictionary.xsd"> + + <entry> + <from>concern</from> + <translations> + <to>Sorge</to> + <to>Besorgnis</to> + </translations> + </entry> + + <entry> + <from>compassion</from> + <translations> + <to>Barmherzigkeit</to> + <to>Mitgefühl</to> + <to>Mitleid</to> + <to>Erbarmen</to> + </translations> + <synonyms> + <from>pity</from> + <from>concern</from> + </synonyms> + </entry> + + <entry> + <from>jerk</from> + <translations> + <to>Ruck</to> + <to>Trottel</to> + </translations> + </entry> + + <entry> + <from>pity</from> + <translations> + <to>Mitleid</to> + <to>Erbarmen</to> + <to>Jammer</to> + <to>Mitgefühl</to> + </translations> + <synonyms> + <from>compassion</from> + </synonyms> + </entry> + + </dictionary> + + </x:context> + <x:expect label="A coma separated list of all synonyms"> + <html xmlns="http://www.w3.org/1999/xhtml"> + <head> + <title>'en' to 'de' translation.</title> + </head> + <body> + <h1>'en' to 'de' translation.</h1> + <dl> + <dt id="concern" style="font-weight: bold;">concern</dt> + <dd> + <ul> + <li>Sorge</li> + <li>Besorgnis</li> + </ul> + </dd> + <dt id="compassion" style="font-weight: bold;">compassion</dt> + <dd> + <ul> + <li>Barmherzigkeit</li> + <li>Mitgefühl</li> + <li>Mitleid</li> + <li>Erbarmen</li> + </ul> + <p>Synonyms: <a href="#pity">pity</a>, <a href="#concern">concern</a></p> + </dd> + <dt id="jerk" style="font-weight: bold;">jerk</dt> + <dd> + <ul> + <li>Ruck</li> + <li>Trottel</li> + </ul> + </dd> + <dt id="pity" style="font-weight: bold;">pity</dt> + <dd> + <ul> + <li>Mitleid</li> + <li>Erbarmen</li> + <li>Jammer</li> + <li>Mitgefühl</li> + </ul> + <p>Synonym: <a href="#compassion">compassion</a></p> + </dd> + </dl> + </body> + </html> + </x:expect> + </x:scenario> + + + + + +</x:description> diff --git a/Klausuren/Sda1/Ws2015/Solution/dictionary2html.xsl b/Klausuren/Sda1/Ws2015/Solution/dictionary2html.xsl new file mode 100644 index 0000000000000000000000000000000000000000..563b76aaf771bb44c2af79d3a121a16222023930 --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Solution/dictionary2html.xsl @@ -0,0 +1,77 @@ +<?xml version="1.0" encoding="UTF-8"?> +<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + xmlns:xs="http://www.w3.org/2001/XMLSchema" + xmlns="http://www.w3.org/1999/xhtml" + exclude-result-prefixes="xs" + version="2.0"> + + <xsl:output method="xhtml" indent="yes"/> + + <xsl:template match="/dictionary"> + <html> + <head> + <title> + <xsl:apply-templates select="." mode="translateDirection"/> + </title> + </head> + <body> + <h1> + <xsl:apply-templates select="." mode="translateDirection"/> + </h1> + <xsl:choose> + <xsl:when test="entry"> + <dl> + <xsl:apply-templates select="entry"/> + </dl> + </xsl:when> + <xsl:otherwise><p>No entries in dictionary</p></xsl:otherwise> + </xsl:choose> + </body> + </html> + </xsl:template> + + <xsl:template match="entry"> + <dt id="{from}" style="font-weight: bold;"> + <xsl:value-of select="from"/> + </dt> + <dd> + <ul> + <xsl:for-each select="translations/to"> + <li> + <xsl:value-of select="."/> + </li> + </xsl:for-each> + </ul> + <xsl:apply-templates select="synonyms"/> + + </dd> + + </xsl:template> + + <xsl:template match="synonyms"> + <p> + <xsl:choose> + <xsl:when test="1=count(from)">Synonym: </xsl:when> + <xsl:otherwise>Synonyms: </xsl:otherwise> + </xsl:choose> + <xsl:for-each select="from"> + <a href="#{.}"> + <xsl:value-of select="."/> + </a> + <xsl:if test="position() < last()"> + <xsl:text>, </xsl:text> + </xsl:if> + </xsl:for-each> + </p> + </xsl:template> + + <xsl:template match="dictionary" mode="translateDirection"> + <xsl:text>'</xsl:text> + <xsl:value-of select="@fromLanguage"/> + <xsl:text>' to '</xsl:text> + <xsl:value-of select="@toLanguage"/> + <xsl:text>' translation.</xsl:text> + </xsl:template> + + +</xsl:stylesheet> \ No newline at end of file diff --git a/Klausuren/Sda1/Ws2015/Solution/pom.xml b/Klausuren/Sda1/Ws2015/Solution/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..48f1a5b2798125f536d42b66dcb50ce20065098a --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Solution/pom.xml @@ -0,0 +1,79 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>de.hdm-stuttgart.mi.sda1</groupId> + <artifactId>exam</artifactId> + <version>1.0</version> + <packaging>jar</packaging> + + <name>exam</name> + + <url>http://freedocs.mi.hdm-stuttgart.de</url> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.11</version> + <scope>test</scope> + <optional>true</optional> + </dependency> + + <dependency> + <groupId>mysql</groupId> + <artifactId>mysql-connector-java</artifactId> + <version>5.1.36</version> + <scope>runtime</scope> + </dependency> + + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-api</artifactId> + <version>2.1</version> + </dependency> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-core</artifactId> + <version>2.1</version> + </dependency> + + <dependency> + <groupId>org.jdom</groupId> + <artifactId>jdom2</artifactId> + <version>2.0.6</version> + </dependency> + + <dependency> + <groupId>jaxen</groupId> + <artifactId>jaxen</artifactId> + <version>1.1.6</version> + </dependency> + + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.1</version> + <configuration> + <source>1.8</source> + <target>1.8</target> + </configuration> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-javadoc-plugin</artifactId> + <version>2.10.1</version> + <configuration /> + </plugin> + </plugins> + </build> +</project> diff --git a/Klausuren/Sda1/Ws2015/Solution/src/main/java/de/hdm_stuttgart/mi/sda1/exam/rdbms/DbHandler.java b/Klausuren/Sda1/Ws2015/Solution/src/main/java/de/hdm_stuttgart/mi/sda1/exam/rdbms/DbHandler.java new file mode 100644 index 0000000000000000000000000000000000000000..d6b6308400923bd0d7b6a3b818eb745065195f43 --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Solution/src/main/java/de/hdm_stuttgart/mi/sda1/exam/rdbms/DbHandler.java @@ -0,0 +1,136 @@ +package de.hdm_stuttgart.mi.sda1.exam.rdbms; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + + +/** + * Handling database connections + * + */ +public class DbHandler { + private static Logger log = LogManager.getLogger(DbHandler.class); + + /** + * Value indicating a given object does not exist. + */ + static public final int MISSING_ID = -1; + Connection conn = null; + + PreparedStatement insertLanguage, selectLanguageId, + insertNoun, selectNounId, + insertTranslation; + + /** + * Connecting to our database server + * @throws SQLException Connection failure. + */ + public void connect() throws SQLException { + conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/hdm","hdmuser","XYZ"); + insertLanguage = conn.prepareStatement("INSERT INTO Language (lang) VALUES (?)", Statement.RETURN_GENERATED_KEYS); + selectLanguageId = conn.prepareStatement("SELECT id FROM Language WHERE (lang=?)"); + insertNoun = conn.prepareStatement("INSERT INTO Noun (word, lang) VALUES (?, ?)", Statement.RETURN_GENERATED_KEYS); + selectNounId = conn.prepareStatement("SELECT id FROM Noun WHERE word = ? AND lang = ?"); + insertTranslation = conn.prepareStatement("INSERT INTO Translation VALUES(?, ?)"); + } + + /** + * @throws SQLException Unable to disconnect. + */ + public void disconnect() throws SQLException { + conn.close(); + conn = null; + } + + /** + * Connection status + * @return true if connected, false otherwise. + */ + public boolean isConnected() { + return null != conn; + } + + private int getLanguageId(final String lang) throws SQLException { + selectLanguageId.setString(1, lang); + selectLanguageId.executeQuery(); + return getDatabaseId(selectLanguageId.getResultSet()); + } + + private int getNounId(final String word, final int languageId) throws SQLException { + selectNounId.setString(1, word); + selectNounId.setInt(2, languageId); + selectNounId.executeQuery(); + return getDatabaseId(selectNounId.getResultSet()); + } + + private static int getDatabaseId(final ResultSet key) throws SQLException { + if (key.next()) { + return key.getInt(1); + } + return MISSING_ID; + } + + /** + * Add a new language like e.g. "de" + * + * @param language The language two character identifier like "en", "de", "fr", ... + * @return The generated primary key id value. + * @throws SQLException Language may possibly exist. + */ + public int addLanguageIfMissing(final String language) throws SQLException { + + final int languageId = getLanguageId(language); + if (MISSING_ID == languageId) { + insertLanguage.setString(1, language); + insertLanguage.executeUpdate(); + return getDatabaseId(insertLanguage.getGeneratedKeys()); + } else { + return languageId; + } + } + + /** + * Add a new noun for a given language like e.g. "winter" and language id = 12 + * + * @param word The word to be inserted + * @param languageId The language to be considered. + * @return The generated primary key id value. + * @throws SQLException Language may possibly exist. + */ + public int addNounIfMissing(final String word, int languageId) throws SQLException { + + final int nounId = getNounId(word, languageId); + if (MISSING_ID == nounId) { + insertNoun.setString(1, word); + insertNoun.setInt(2, languageId); + insertNoun.executeUpdate(); + return getDatabaseId(insertNoun.getGeneratedKeys()); + } else { + return nounId; + } + } + + /** + * Combining two nouns into a translation. + * @param fromId The 'from' word and language + * @param toId The 'to' word and language + * + */ + public void addTranslation(final int fromId, final int toId) { + try { + insertTranslation.setInt(1, fromId); + insertTranslation.setInt(2, toId); + insertTranslation.executeUpdate(); + } catch (SQLException e) { + log.info("Translation (" + fromId + ", " + toId + ") already registered: " + + e.getMessage()); + } + } +} \ No newline at end of file diff --git a/Klausuren/Sda1/Ws2015/Solution/src/main/java/de/hdm_stuttgart/mi/sda1/exam/rdbms/DbhandlerManualTest.java b/Klausuren/Sda1/Ws2015/Solution/src/main/java/de/hdm_stuttgart/mi/sda1/exam/rdbms/DbhandlerManualTest.java new file mode 100644 index 0000000000000000000000000000000000000000..357da43f877ec4b5e5c8bde0e4b7bc3757052d9e --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Solution/src/main/java/de/hdm_stuttgart/mi/sda1/exam/rdbms/DbhandlerManualTest.java @@ -0,0 +1,45 @@ +package de.hdm_stuttgart.mi.sda1.exam.rdbms; + +import java.sql.SQLException; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + + +/** + * Providing some basic DB handling tests. + * + */ +public class DbhandlerManualTest { + + private static Logger log = LogManager.getLogger(DbhandlerManualTest.class); + + /** + * + * @param args Unused + */ + public static void main(String[] args) { + final DbHandler dbh = new DbHandler(); + + try { + dbh.connect(); + + final int enLangId = dbh.addLanguageIfMissing("en"), + deLangId = dbh.addLanguageIfMissing("de"); + + final int nounSummerEnId = dbh.addNounIfMissing("Summer", enLangId); + final int nounSommerDeId = dbh.addNounIfMissing("Sommer", deLangId); + + System.out.println(nounSummerEnId); + System.out.println(nounSommerDeId); + + dbh.addTranslation(4, 5); + + } catch (SQLException e) { + log.error("Unable to open connection", e); + } + + + } + +} diff --git a/Klausuren/Sda1/Ws2015/Solution/src/main/java/de/hdm_stuttgart/mi/sda1/exam/rdbms/Xml2Rdbms.java b/Klausuren/Sda1/Ws2015/Solution/src/main/java/de/hdm_stuttgart/mi/sda1/exam/rdbms/Xml2Rdbms.java new file mode 100644 index 0000000000000000000000000000000000000000..b61778b9592419a792c02b9619001eaa688fa5fc --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Solution/src/main/java/de/hdm_stuttgart/mi/sda1/exam/rdbms/Xml2Rdbms.java @@ -0,0 +1,67 @@ +package de.hdm_stuttgart.mi.sda1.exam.rdbms; + +import java.io.IOException; +import java.sql.SQLException; + +import org.jdom2.Document; +import org.jdom2.Element; +import org.jdom2.JDOMException; +import org.jdom2.input.SAXBuilder; + +/** + * Reading XML Data and inserting to relational systems. + * + */ +public class Xml2Rdbms { + + final DbHandler db = new DbHandler(); + + final SAXBuilder builder = new SAXBuilder(); + + int fromLanguageId, toLanguageId; + + /** + * Read XML data for RDBMS transfer. + * + * @param dictionaryFileName XML filename containing dictionary data, + * @throws SQLException Database related error. + * @throws JDOMException Parsing exception + * @throws IOException File access exception. + */ + public void read(final String dictionaryFileName) throws SQLException, JDOMException, IOException { + db.connect(); + + final Element dictionary = builder.build(dictionaryFileName).getRootElement(); + + fromLanguageId = db.addLanguageIfMissing(dictionary.getAttributeValue("fromLanguage")); + toLanguageId = db.addLanguageIfMissing(dictionary.getAttributeValue("toLanguage")); + + for (final Element entry: dictionary.getChildren("entry")) { + handleEntry(entry); + } + } + + /** + * + * @param args Unused + * @throws IOException + * @throws JDOMException + * @throws SQLException + */ + public static void main(String[] args) throws JDOMException, IOException, SQLException { + final Xml2Rdbms x2r = new Xml2Rdbms(); + x2r.read("Schema/sampledata.xml"); + + } + + + + void handleEntry(final Element entry) throws SQLException { + final int fromNounId = db.addNounIfMissing(entry.getChild("from").getText(), fromLanguageId); + for (final Element to: entry.getChild("translations").getChildren("to")) { + final int toNounId = db.addNounIfMissing(to.getText(), toLanguageId); + db.addTranslation(fromNounId, toNounId); + } + } +} + diff --git a/Klausuren/Sda1/Ws2015/Solution/src/main/resources/log4j2.xml b/Klausuren/Sda1/Ws2015/Solution/src/main/resources/log4j2.xml new file mode 100644 index 0000000000000000000000000000000000000000..49f69dcac991786dd777f31148ce6ddd52f132ea --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Solution/src/main/resources/log4j2.xml @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<Configuration> + <Appenders> + <File name="A1" fileName="A1.log" append="false"> + <PatternLayout pattern="%t %-5p %c{2} - %m%n"/> + </File> + <Console name="STDOUT" target="SYSTEM_OUT"> + <PatternLayout pattern="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/> + </Console> + </Appenders> + <Loggers> + + <!-- You my want to define class or package level per-logger rules --> + <Logger name="de.hdm_stuttgart.mi.sda1.exam.xsd" level="error"> + <AppenderRef ref="A1"/> + </Logger> + + <Logger name="de.hdm_stuttgart.mi.sda1.exam.test.ignore" level="error"> + <AppenderRef ref="A1"/> + </Logger> + + + + <Root level="info"> + <AppenderRef ref="STDOUT"/> + </Root> + </Loggers> +</Configuration> \ No newline at end of file diff --git a/Klausuren/Sda1/Ws2015/Solution/src/test/java/de/hdm_stuttgart/mi/sda1/exam/test/ignore/InstanceSetEvaluation.java b/Klausuren/Sda1/Ws2015/Solution/src/test/java/de/hdm_stuttgart/mi/sda1/exam/test/ignore/InstanceSetEvaluation.java new file mode 100644 index 0000000000000000000000000000000000000000..e2b8edc2ec30187e452c83b4bd6a98434d9c2e7d --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Solution/src/test/java/de/hdm_stuttgart/mi/sda1/exam/test/ignore/InstanceSetEvaluation.java @@ -0,0 +1,144 @@ +package de.hdm_stuttgart.mi.sda1.exam.test.ignore; + +import java.io.File; +import java.io.IOException; +import java.util.List; +import java.util.Vector; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.jdom2.Document; +import org.jdom2.JDOMException; +import org.jdom2.ProcessingInstruction; +import org.jdom2.filter.Filters; +import org.jdom2.input.SAXBuilder; +import org.jdom2.input.sax.XMLReaders; +import org.jdom2.xpath.XPathExpression; +import org.jdom2.xpath.XPathFactory; + +/** + * Evaluate a given set of XML document instances + * + */ +public class InstanceSetEvaluation { + + /** + * Base directory containing xml test file instances. + */ + public final String xmlTestFileDir; + + /** + * true if all tests have been successful. + */ + public final boolean allTestsSucceeded; + + private static Logger log = LogManager.getLogger(InstanceSetEvaluation.class); + + final static List<InstanceTest> tests = new Vector<>(); + + final StringBuffer messages = new StringBuffer(), errorMessages = new StringBuffer(); + + /** + * @param args unused + */ + public static void main(String[] args) { + final InstanceSetEvaluation ise = new InstanceSetEvaluation("SchemaTest"); + System.out.println(ise.getMessages()); + System.out.println("All tests succeeded:" + ise.allTestsSucceeded); + } + + /** + * @return Individual failed test(s) error message(s). + */ + public String getErrorMessages() { + return errorMessages.toString(); + } + + /** + * @return Individual test's and aggregated results. + */ + public String getMessages() { + return messages.toString(); + } + + /** + * + * @param xmlTestFileDir Directory containing XML instances to be processed. + */ + public InstanceSetEvaluation(final String xmlTestFileDir) { + this.xmlTestFileDir = xmlTestFileDir; + + final File rootDirectory = new File(xmlTestFileDir); + + for (final File f: rootDirectory.listFiles( + path -> path.getPath().endsWith(".xml"))) { + readTestHeader(f); + } + + tests.forEach(t -> messages.append(t + "\n")); + tests.stream().filter(t -> !t.testSucceeded).forEach(t -> errorMessages.append(t + "\n")); + + allTestsSucceeded = tests. + stream(). + map(t -> t.testSucceeded). + reduce((a, b) -> a && b). + get(); + + + final int maxPoints = tests. + stream(). + mapToInt(t -> t.reachablePoints). + reduce((a, b) -> a + b). + getAsInt(), + + reachedPoints = tests. + stream(). + filter(t -> t.testSucceeded). + mapToInt(t -> t.reachablePoints). + reduce((a, b) -> a + b). + getAsInt(); + + messages.append(reachedPoints + " of " + maxPoints + + " points have been reached"); + } + + + + void readTestHeader(final File instanceFilename) { + + final SAXBuilder metainfoParser = new SAXBuilder(XMLReaders.NONVALIDATING); + try { + final Document doc = metainfoParser.build(instanceFilename); + + final XPathExpression<ProcessingInstruction> searchHeader = + XPathFactory.instance().compile( + "/processing-instruction('xmlTest')", + Filters.processinginstruction()); + final List<ProcessingInstruction> xmlTestList = + searchHeader.evaluate(doc); + + switch (xmlTestList.size()) { + case 0: + log.info("No 'xmlTest PI found, possible dependency file"); + break; + case 1: + tests.add(new InstanceTest(xmlTestList.get(0), xmlTestFileDir, instanceFilename)); + break; + default: + log.error("Fatal: Found " + xmlTestList.size() + + " <?xmltest ... ?> annotations in file '" + + instanceFilename + "'"); + System.exit(1); + } + + } catch (final JDOMException e) { + log.fatal("Document '" + instanceFilename.getPath() + + "' is invalid:", e); + System.exit(1); + } catch (final IOException e) { + log.fatal("Unable to open '" + instanceFilename.getPath() + + "' for reading:", e); + System.exit(1); + } + } +} diff --git a/Klausuren/Sda1/Ws2015/Solution/src/test/java/de/hdm_stuttgart/mi/sda1/exam/test/ignore/InstanceTest.java b/Klausuren/Sda1/Ws2015/Solution/src/test/java/de/hdm_stuttgart/mi/sda1/exam/test/ignore/InstanceTest.java new file mode 100644 index 0000000000000000000000000000000000000000..46d567455180b5bb1f75994af430f9cfe80ec3e3 --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Solution/src/test/java/de/hdm_stuttgart/mi/sda1/exam/test/ignore/InstanceTest.java @@ -0,0 +1,133 @@ +package de.hdm_stuttgart.mi.sda1.exam.test.ignore; + +import java.io.File; +import java.io.IOException; +import java.util.Optional; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.jdom2.JDOMException; +import org.jdom2.ProcessingInstruction; +import org.jdom2.input.SAXBuilder; +import org.jdom2.input.sax.XMLReaders; + +/** + * Test and evaluate an individual XML instance. + * + */ +public class InstanceTest { + + final SAXBuilder parser = new SAXBuilder(XMLReaders.XSDVALIDATING); + + final File instanceFilename; + + /** + * An examinee may reach this number of point. The value is being defined in + * the corresponding XML instance's PI like e.g.: + * + * <?xmlTest + points = "2" ... ?> + * + */ + public final int reachablePoints; + + /** + * Is this instance expected to be valid or not? The value is being defined in + * the corresponding XML instance's PI like e.g.: + * + * <?xmlTest expectedToBeValid= "false" ... ?> + */ + public final boolean expectedToBeValid; + /** + * Does the current instance test succeed? + */ + public final boolean testSucceeded; + + /** + * Error message in case of unexpected behavior e.g. + * when an invalid instance is supposed to be valid. + */ + public final Optional<String> errMsg; + + private static Logger log = LogManager.getLogger(InstanceTest.class); + + @Override + public String toString() { + if (testSucceeded) { + return instanceFilename + ": " + reachablePoints + " point" + (1 == reachablePoints ? "" : "s") ; + } else { + return instanceFilename + ": " + errMsg.get() + ",\n missing" + reachablePoints +" point(s)"; + } + } + + /** + * Testing an individual instance to be either valid or invalid. + * + * @param xmlTest The PI meta annotation header containing the expected + * result, points etc. + * @param xmlTestFileDir The directory containing the XML instance files. + * @param xmlInstance The current instance to be evaluated. + */ + public InstanceTest(final ProcessingInstruction xmlTest, + final String xmlTestFileDir, final File xmlInstance) { + + this.instanceFilename = xmlInstance; + + if (null == xmlTest.getPseudoAttributeValue("points")) { + log.fatal("Mandatory <?xmlTest points='...' ... ?> is missing in file '" + + xmlInstance + "'"); + System.exit(1); + } + reachablePoints = Integer.parseInt(xmlTest.getPseudoAttributeValue("points")); + + if (null == xmlTest.getPseudoAttributeValue("expectedToBeValid")) { + log.fatal("Mandatory <?xmlTest expectedToBeValid='true|false' ... ?> is missing in file '" + xmlInstance + "'"); + System.exit(1); + } + expectedToBeValid = Boolean.parseBoolean(xmlTest.getPseudoAttributeValue("expectedToBeValid")); + + final Optional<String> preconditionValidFilename; + + boolean preconditionSucceeded = false; + String tmpPreconditionErrMsg = null; + + if (null == xmlTest.getPseudoAttributeValue("preconditionValid")) { + preconditionValidFilename = Optional.empty(); + } else { + preconditionValidFilename = Optional.of(xmlTestFileDir + File.separator + + xmlTest.getPseudoAttributeValue("preconditionValid")); + try { + parser.build(preconditionValidFilename.get()); + log.info("Precondition file '" + preconditionValidFilename.get() + "' is valid"); + preconditionSucceeded = true; + } catch (final JDOMException | IOException e) { + log.info("Precondition file '" + preconditionValidFilename.get() + "' is invalid or missing:", e); + tmpPreconditionErrMsg = "File '" + preconditionValidFilename.get() + "' is either invalid or missing"; + } + } + + if (!preconditionValidFilename.isPresent() || preconditionSucceeded) { + boolean tmpInstanceIsValid = false; + try { + parser.build(xmlInstance); + tmpInstanceIsValid = true; + } catch (final JDOMException | IOException e) { + log.info("Instance file '" + xmlInstance + "' is invalid:", e); + } + testSucceeded = expectedToBeValid == tmpInstanceIsValid; + if (testSucceeded) { + errMsg = Optional.empty(); + } else if (testSucceeded) { + errMsg = Optional.of("Instance '" + xmlInstance + + "' is expected to be invalid!"); + } else { + errMsg = Optional.of("Instance '" + xmlInstance + + "' is expected to be valid!"); + } + } else { + testSucceeded = false; + errMsg = Optional.of(tmpPreconditionErrMsg); + + } + } +} diff --git a/Klausuren/Sda1/Ws2015/Solution/src/test/java/de/hdm_stuttgart/mi/sda1/exam/xsd/SchemaTest.java b/Klausuren/Sda1/Ws2015/Solution/src/test/java/de/hdm_stuttgart/mi/sda1/exam/xsd/SchemaTest.java new file mode 100644 index 0000000000000000000000000000000000000000..c53a95776c867deee2f0463aa76164a32839fabd --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Solution/src/test/java/de/hdm_stuttgart/mi/sda1/exam/xsd/SchemaTest.java @@ -0,0 +1,24 @@ +package de.hdm_stuttgart.mi.sda1.exam.xsd; + +import org.junit.Assert; +import org.junit.Test; + +import de.hdm_stuttgart.mi.sda1.exam.test.ignore.InstanceSetEvaluation; + +/** + * Unit test for an XML instance set. + */ +public class SchemaTest { + /** + * Testing a suite of XML instances. + */ + @Test + public void testXmlInstanceSet() { + + final InstanceSetEvaluation ise = new InstanceSetEvaluation("SchemaTest"); + + Assert.assertTrue(ise.getErrorMessages(), ise.allTestsSucceeded); + + System.out.println(ise.getMessages()); + } +} diff --git a/Klausuren/Sda1/Ws2015/Solution/todo.txt b/Klausuren/Sda1/Ws2015/Solution/todo.txt new file mode 100644 index 0000000000000000000000000000000000000000..86bcc863ef5e571bfa74c34efb19608d4ccfaf89 --- /dev/null +++ b/Klausuren/Sda1/Ws2015/Solution/todo.txt @@ -0,0 +1,10 @@ +Resolving reference to zip skeleton + +Oracle SQL JDeveloper konfigurieren + +Saxon EE validation default? + +Import GoikVorles to ~klausur + +Mysql connection in eclipse konfigurieren. +