From cf3b7f5d49ede0743b26d7ab221549d4ff4c74c4 Mon Sep 17 00:00:00 2001 From: "Dr. Martin Goik" Date: Sat, 8 Dec 2018 21:36:01 +0100 Subject: [PATCH] XML unit test alignment to Junit standard --- Klausuren/Sda1/2018Summer/Exam/.gitignore | 29 +- Klausuren/Sda1/2018Summer/Exam/pom.xml | 4 +- .../Exam/src/main/resources/XMLSchema.xsd | 2471 +++++++++++++++++ .../Exam/src/main/resources/xml.xsd | 286 ++ .../mi/sda1/test/ex1/SchemaTest.java | 26 - .../mi/sda1/test/ex1/ShowReachedPoints.java | 22 + .../sda1/test/ex1/Test_SchemaByInstances.java | 153 + Klausuren/Sda1/2018Summer/Solve/.gitignore | 31 +- Klausuren/Sda1/2018Summer/Solve/Doc/exam.xml | 4 +- Klausuren/Sda1/2018Summer/Solve/pom.xml | 4 +- .../Solve/src/main/resources/XMLSchema.xsd | 2471 +++++++++++++++++ .../Solve/src/main/resources/xml.xsd | 286 ++ .../mi/sda1/test/ex1/SchemaTest.java | 26 - .../mi/sda1/test/ex1/ShowReachedPoints.java | 22 + .../sda1/test/ex1/Test_SchemaByInstances.java | 153 + ws/Artifacts/Unitmarking/pom.xml | 9 +- .../exam/unitmarking/xml/XmlTestSupport.java | 263 +- .../mi/unitmarking/xsd/CreateTestClass.java | 103 + .../xsd/GenerateUnitTestClass.java | 14 + .../xsd/InstanceSetEvaluation.java | 58 +- .../mi/unitmarking/xsd/InstanceTest.java | 4 +- 21 files changed, 6193 insertions(+), 246 deletions(-) create mode 100644 Klausuren/Sda1/2018Summer/Exam/src/main/resources/XMLSchema.xsd create mode 100644 Klausuren/Sda1/2018Summer/Exam/src/main/resources/xml.xsd delete mode 100644 Klausuren/Sda1/2018Summer/Exam/src/test/java/de/hdm_stuttgart/mi/sda1/test/ex1/SchemaTest.java create mode 100644 Klausuren/Sda1/2018Summer/Exam/src/test/java/de/hdm_stuttgart/mi/sda1/test/ex1/ShowReachedPoints.java create mode 100644 Klausuren/Sda1/2018Summer/Exam/src/test/java/de/hdm_stuttgart/mi/sda1/test/ex1/Test_SchemaByInstances.java create mode 100644 Klausuren/Sda1/2018Summer/Solve/src/main/resources/XMLSchema.xsd create mode 100644 Klausuren/Sda1/2018Summer/Solve/src/main/resources/xml.xsd delete mode 100644 Klausuren/Sda1/2018Summer/Solve/src/test/java/de/hdm_stuttgart/mi/sda1/test/ex1/SchemaTest.java create mode 100644 Klausuren/Sda1/2018Summer/Solve/src/test/java/de/hdm_stuttgart/mi/sda1/test/ex1/ShowReachedPoints.java create mode 100644 Klausuren/Sda1/2018Summer/Solve/src/test/java/de/hdm_stuttgart/mi/sda1/test/ex1/Test_SchemaByInstances.java create mode 100644 ws/Artifacts/Unitmarking/src/main/java/de/hdm_stuttgart/mi/unitmarking/xsd/CreateTestClass.java create mode 100644 ws/Artifacts/Unitmarking/src/main/java/de/hdm_stuttgart/mi/unitmarking/xsd/GenerateUnitTestClass.java diff --git a/Klausuren/Sda1/2018Summer/Exam/.gitignore b/Klausuren/Sda1/2018Summer/Exam/.gitignore index 9b36bc51..f003c82b 100644 --- a/Klausuren/Sda1/2018Summer/Exam/.gitignore +++ b/Klausuren/Sda1/2018Summer/Exam/.gitignore @@ -1,3 +1,4 @@ +/.idea/ /target/ /.settings/ .classpath @@ -5,34 +6,11 @@ dependency-reduced-pom.xml *.log -# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm -# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 - -# User-specific stuff: -.idea/**/workspace.xml -.idea/**/tasks.xml -.idea/dictionaries - -# Sensitive or high-churn files: -.idea/**/dataSources/ -.idea/**/dataSources.ids -.idea/**/dataSources.xml -.idea/**/dataSources.local.xml -.idea/**/sqlDataSources.xml -.idea/**/dynamic.xml -.idea/**/uiDesigner.xml - -# Gradle: -.idea/**/gradle.xml -.idea/**/libraries - # CMake cmake-build-debug/ -# Mongo Explorer plugin: -.idea/**/mongoSettings.xml - *.iws +*.iml # IntelliJ @@ -44,9 +22,6 @@ out/ # JIRA plugin atlassian-ide-plugin.xml -# Cursive Clojure plugin -.idea/replstate.xml - # Crashlytics plugin (for Android Studio and IntelliJ) com_crashlytics_export_strings.xml crashlytics.properties diff --git a/Klausuren/Sda1/2018Summer/Exam/pom.xml b/Klausuren/Sda1/2018Summer/Exam/pom.xml index ceef14ec..d04dc78e 100644 --- a/Klausuren/Sda1/2018Summer/Exam/pom.xml +++ b/Klausuren/Sda1/2018Summer/Exam/pom.xml @@ -103,7 +103,7 @@ de.hdm_stuttgart.mi.exam unitmarking - 0.9 + 1.0 @@ -153,7 +153,7 @@ - de.hdm_stuttgart.mi.sda1.test.ShowReachedPoints + de.hdm_stuttgart.mi.sda1.test.ex1.ShowReachedPoints diff --git a/Klausuren/Sda1/2018Summer/Exam/src/main/resources/XMLSchema.xsd b/Klausuren/Sda1/2018Summer/Exam/src/main/resources/XMLSchema.xsd new file mode 100644 index 00000000..89829f13 --- /dev/null +++ b/Klausuren/Sda1/2018Summer/Exam/src/main/resources/XMLSchema.xsd @@ -0,0 +1,2471 @@ + + + + + Part 1 version: Id: structures.xsd,v 1.2 2004/01/15 11:34:25 ht Exp + Part 2 version: Id: datatypes.xsd,v 1.3 2004/01/23 18:11:13 ht Exp + + + + + + The schema corresponding to this document is normative, + with respect to the syntactic constraints it expresses in the + XML Schema language. The documentation (within <documentation> elements) + below, is not normative, but rather highlights important aspects of + the W3C Recommendation of which this is a part + + + + + The simpleType element and all of its members are defined + towards the end of this schema document + + + + + + Get access to the xml: attribute groups for xml:lang + as declared on 'schema' and 'documentation' below + + + + + + + + This type is extended by almost all schema types + to allow attributes from other namespaces to be + added to user schemas. + + + + + + + + + + + + + This type is extended by all types which allow annotation + other than <schema> itself + + + + + + + + + + + + + + + + This group is for the + elements which occur freely at the top level of schemas. + All of their types are based on the "annotated" type by extension. + + + + + + + + + + + + + This group is for the + elements which can self-redefine (see <redefine> below). + + + + + + + + + + + + + A utility type, not for public use + + + + + + + + + + + A utility type, not for public use + + + + + + + + + + + A utility type, not for public use + + #all or (possibly empty) subset of {extension, restriction} + + + + + + + + + + + + + + + + + A utility type, not for public use + + + + + + + + + + + + + A utility type, not for public use + + #all or (possibly empty) subset of {extension, restriction, list, union} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + for maxOccurs + + + + + + + + + + + + for all particles + + + + + + + for element, group and attributeGroup, + which both define and reference + + + + + + + + 'complexType' uses this + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + This branch is short for + <complexContent> + <restriction base="xsd:anyType"> + ... + </restriction> + </complexContent> + + + + + + + + + + + + + + + Will be restricted to required or forbidden + + + + + + Not allowed if simpleContent child is chosen. + May be overriden by setting on complexContent child. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + This choice is added simply to + make this a valid restriction per the REC + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Overrides any setting on complexType parent. + + + + + + + + + + + + + + + This choice is added simply to + make this a valid restriction per the REC + + + + + + + + + + + + + + + + + No typeDefParticle group reference + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + A utility type, not for public use + + #all or (possibly empty) subset of {substitution, extension, + restriction} + + + + + + + + + + + + + + + + + + + + + + + + + The element element can be used either + at the top level to define an element-type binding globally, + or within a content model to either reference a globally-defined + element or type or declare an element-type binding locally. + The ref form is not allowed at the top level. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + group type for explicit groups, named top-level groups and + group references + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + group type for the three kinds of group + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + This choice with min/max is here to + avoid a pblm with the Elt:All/Choice/Seq + Particle derivation constraint + + + + + + + + + + restricted max/min + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Only elements allowed inside + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + simple type for the value of the 'namespace' attr of + 'any' and 'anyAttribute' + + + + Value is + ##any - - any non-conflicting WFXML/attribute at all + + ##other - - any non-conflicting WFXML/attribute from + namespace other than targetNS + + ##local - - any unqualified non-conflicting WFXML/attribute + + one or - - any non-conflicting WFXML/attribute from + more URI the listed namespaces + references + (space separated) + + ##targetNamespace or ##local may appear in the above list, to + refer to the targetNamespace of the enclosing + schema or an absent targetNamespace respectively + + + + + + A utility type, not for public use + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + A subset of XPath expressions for use +in selectors + A utility type, not for public +use + + + + The following pattern is intended to allow XPath + expressions per the following EBNF: + Selector ::= Path ( '|' Path )* + Path ::= ('.//')? Step ( '/' Step )* + Step ::= '.' | NameTest + NameTest ::= QName | '*' | NCName ':' '*' + child:: is also allowed + + + + + + + + + + + + + + + + + + + + + + + A subset of XPath expressions for use +in fields + A utility type, not for public +use + + + + The following pattern is intended to allow XPath + expressions per the same EBNF as for selector, + with the following change: + Path ::= ('.//')? ( Step '/' )* ( Step | '@' NameTest ) + + + + + + + + + + + + + + + + + + + + + + + + + + + The three kinds of identity constraints, all with + type of or derived from 'keybase'. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + A utility type, not for public use + + A public identifier, per ISO 8879 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + notations for use within XML Schema schemas + + + + + + + + + Not the real urType, but as close an approximation as we can + get in the XML representation + + + + + + + + + + First the built-in primitive datatypes. These definitions are for + information only, the real built-in definitions are magic. + + + + For each built-in datatype in this schema (both primitive and + derived) can be uniquely addressed via a URI constructed + as follows: + 1) the base URI is the URI of the XML Schema namespace + 2) the fragment identifier is the name of the datatype + + For example, to address the int datatype, the URI is: + + http://www.w3.org/2001/XMLSchema#int + + Additionally, each facet definition element can be uniquely + addressed via a URI constructed as follows: + 1) the base URI is the URI of the XML Schema namespace + 2) the fragment identifier is the name of the facet + + For example, to address the maxInclusive facet, the URI is: + + http://www.w3.org/2001/XMLSchema#maxInclusive + + Additionally, each facet usage in a built-in datatype definition + can be uniquely addressed via a URI constructed as follows: + 1) the base URI is the URI of the XML Schema namespace + 2) the fragment identifier is the name of the datatype, followed + by a period (".") followed by the name of the facet + + For example, to address the usage of the maxInclusive facet in + the definition of int, the URI is: + + http://www.w3.org/2001/XMLSchema#int.maxInclusive + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + NOTATION cannot be used directly in a schema; rather a type + must be derived from it by specifying at least one enumeration + facet whose value is the name of a NOTATION declared in the + schema. + + + + + + + + + + Now the derived primitive types + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + pattern specifies the content of section 2.12 of XML 1.0e2 + and RFC 3066 (Revised version of RFC 1766). + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + pattern matches production 7 from the XML spec + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + pattern matches production 5 from the XML spec + + + + + + + + + + + + + + + pattern matches production 4 from the Namespaces in XML spec + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + A utility type, not for public use + + + + + + + + + + + + + + + + + + + + + + #all or (possibly empty) subset of {restriction, union, list} + + + A utility type, not for public use + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Can be restricted to required or forbidden + + + + + + + + + + + + + + + + + + Required at the top level + + + + + + + + + + + + + + + + + + + Forbidden when nested + + + + + + + + + + + + + + + + + + + We should use a substitution group for facets, but + that's ruled out because it would allow users to + add their own, which we're not ready for yet. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + base attribute and simpleType child are mutually + exclusive, but one or other is required + + + + + + + + + + + + + + + + itemType attribute and simpleType child are mutually + exclusive, but one or other is required + + + + + + + + + + + + + + + + + + memberTypes attribute must be non-empty or there must be + at least one simpleType child + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Klausuren/Sda1/2018Summer/Exam/src/main/resources/xml.xsd b/Klausuren/Sda1/2018Summer/Exam/src/main/resources/xml.xsd new file mode 100644 index 00000000..e60e8c59 --- /dev/null +++ b/Klausuren/Sda1/2018Summer/Exam/src/main/resources/xml.xsd @@ -0,0 +1,286 @@ + + + + + +
+

About the XML namespace

+ +
+

+ This schema document describes the XML namespace, in a form + suitable for import by other schema documents. +

+

+ See + http://www.w3.org/XML/1998/namespace.html and + + http://www.w3.org/TR/REC-xml for information + about this namespace. +

+

+ Note that local names in this namespace are intended to be + defined only by the World Wide Web Consortium or its subgroups. + The names currently defined in this namespace are listed below. + They should not be used with conflicting semantics by any Working + Group, specification, or document instance. +

+

+ See further below in this document for more information about how to refer to this schema document from your own + XSD schema documents and about the + namespace-versioning policy governing this schema document. +

+
+
+
+
+ + + + +
+ +

lang (as an attribute name)

+

+ denotes an attribute whose value + is a language code for the natural language of the content of + any element; its value is inherited. This name is reserved + by virtue of its definition in the XML specification.

+ +
+
+

Notes

+

+ Attempting to install the relevant ISO 2- and 3-letter + codes as the enumerated possible values is probably never + going to be a realistic possibility. +

+

+ See BCP 47 at + http://www.rfc-editor.org/rfc/bcp/bcp47.txt + and the IANA language subtag registry at + + http://www.iana.org/assignments/language-subtag-registry + for further information. +

+

+ The union allows for the 'un-declaration' of xml:lang with + the empty string. +

+
+
+
+ + + + + + + + + +
+ + + + +
+ +

space (as an attribute name)

+

+ denotes an attribute whose + value is a keyword indicating what whitespace processing + discipline is intended for the content of the element; its + value is inherited. This name is reserved by virtue of its + definition in the XML specification.

+ +
+
+
+ + + + + + +
+ + + +
+ +

base (as an attribute name)

+

+ denotes an attribute whose value + provides a URI to be used as the base for interpreting any + relative URIs in the scope of the element on which it + appears; its value is inherited. This name is reserved + by virtue of its definition in the XML Base specification.

+ +

+ See http://www.w3.org/TR/xmlbase/ + for information about this attribute. +

+
+
+
+
+ + + + +
+ +

id (as an attribute name)

+

+ denotes an attribute whose value + should be interpreted as if declared to be of type ID. + This name is reserved by virtue of its definition in the + xml:id specification.

+ +

+ See http://www.w3.org/TR/xml-id/ + for information about this attribute. +

+
+
+
+
+ + + + + + + + + + +
+ +

Father (in any context at all)

+ +
+

+ denotes Jon Bosak, the chair of + the original XML Working Group. This name is reserved by + the following decision of the W3C XML Plenary and + XML Coordination groups: +

+
+

+ In appreciation for his vision, leadership and + dedication the W3C XML Plenary on this 10th day of + February, 2000, reserves for Jon Bosak in perpetuity + the XML name "xml:Father". +

+
+
+
+
+
+ + + +
+

About this schema document

+ +
+

+ This schema defines attributes and an attribute group suitable + for use by schemas wishing to allow xml:base, + xml:lang, xml:space or + xml:id attributes on elements they define. +

+

+ To enable this, such a schema must import this schema for + the XML namespace, e.g. as follows: +

+
+          <schema . . .>
+           . . .
+           <import namespace="http://www.w3.org/XML/1998/namespace"
+                      schemaLocation="http://www.w3.org/2001/xml.xsd"/>
+     
+

+ or +

+
+           <import namespace="http://www.w3.org/XML/1998/namespace"
+                      schemaLocation="http://www.w3.org/2009/01/xml.xsd"/>
+     
+

+ Subsequently, qualified reference to any of the attributes or the + group defined below will have the desired effect, e.g. +

+
+          <type . . .>
+           . . .
+           <attributeGroup ref="xml:specialAttrs"/>
+     
+

+ will define a type which will schema-validate an instance element + with any of those attributes. +

+
+
+
+
+ + + +
+

Versioning policy for this schema document

+
+

+ In keeping with the XML Schema WG's standard versioning + policy, this schema document will persist at + + http://www.w3.org/2009/01/xml.xsd. +

+

+ At the date of issue it can also be found at + + http://www.w3.org/2001/xml.xsd. +

+

+ The schema document at that URI may however change in the future, + in order to remain compatible with the latest version of XML + Schema itself, or with the XML namespace itself. In other words, + if the XML Schema or XML namespaces change, the version of this + document at + http://www.w3.org/2001/xml.xsd + + will change accordingly; the version at + + http://www.w3.org/2009/01/xml.xsd + + will not change. +

+

+ Previous dated (and unchanging) versions of this schema + document are at: +

+ +
+
+
+
+ +
+ diff --git a/Klausuren/Sda1/2018Summer/Exam/src/test/java/de/hdm_stuttgart/mi/sda1/test/ex1/SchemaTest.java b/Klausuren/Sda1/2018Summer/Exam/src/test/java/de/hdm_stuttgart/mi/sda1/test/ex1/SchemaTest.java deleted file mode 100644 index 82e54951..00000000 --- a/Klausuren/Sda1/2018Summer/Exam/src/test/java/de/hdm_stuttgart/mi/sda1/test/ex1/SchemaTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package de.hdm_stuttgart.mi.sda1.test.ex1; - -import de.hdm_stuttgart.mi.unitmarking.xsd.InstanceSetEvaluation; -import org.junit.Assert; -import org.junit.Test; - -/** - * Unit test for an XML instance set. CLI by: - * java -cp target/solvejpa-0.9-fat-tests.jar org.junit.runner.JUnitCore SchemaTest - */ -@SuppressWarnings("static-method") -public class SchemaTest { - /** - * Testing a suite of XML instances. - */ - @Test - public void testXmlInstanceSet() { - - final InstanceSetEvaluation ise = - new InstanceSetEvaluation("SchemaTest", "Schema/bib.xsd"); - - System.out.println(ise.getMessages()); - - Assert.assertTrue(ise.getErrorMessages(), ise.allTestsSucceeded); - } -} \ No newline at end of file diff --git a/Klausuren/Sda1/2018Summer/Exam/src/test/java/de/hdm_stuttgart/mi/sda1/test/ex1/ShowReachedPoints.java b/Klausuren/Sda1/2018Summer/Exam/src/test/java/de/hdm_stuttgart/mi/sda1/test/ex1/ShowReachedPoints.java new file mode 100644 index 00000000..34d916ad --- /dev/null +++ b/Klausuren/Sda1/2018Summer/Exam/src/test/java/de/hdm_stuttgart/mi/sda1/test/ex1/ShowReachedPoints.java @@ -0,0 +1,22 @@ +package de.hdm_stuttgart.mi.sda1.test.ex1; + +import de.hdm_stuttgart.mi.exam.unitmarking.RunTests; + +/** + * Unit test for an XML instance set. CLI by: + * java -cp target/solvejpa-0.9-fat-tests.jar org.junit.runner.JUnitCore ShowReachedPoints + */ +@SuppressWarnings("static-method") +public class ShowReachedPoints { + /** + * Execution reveals the number of reached points. + * + * @param args Unused + */ + public static void main(String[] args) { + RunTests.exec( + "Aufgabe 1", + Test_SchemaByInstances.class + ); + } +} \ No newline at end of file diff --git a/Klausuren/Sda1/2018Summer/Exam/src/test/java/de/hdm_stuttgart/mi/sda1/test/ex1/Test_SchemaByInstances.java b/Klausuren/Sda1/2018Summer/Exam/src/test/java/de/hdm_stuttgart/mi/sda1/test/ex1/Test_SchemaByInstances.java new file mode 100644 index 00000000..7ec681b6 --- /dev/null +++ b/Klausuren/Sda1/2018Summer/Exam/src/test/java/de/hdm_stuttgart/mi/sda1/test/ex1/Test_SchemaByInstances.java @@ -0,0 +1,153 @@ +package de.hdm_stuttgart.mi.sda1.test.ex1; + +import de.hdm_stuttgart.mi.exam.unitmarking.ExaminationTestDefaults; +import de.hdm_stuttgart.mi.exam.unitmarking.Marking; +import de.hdm_stuttgart.mi.exam.unitmarking.xml.XmlTestSupport; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class Test_SchemaByInstances extends ExaminationTestDefaults { + + private final XmlTestSupport xmlTestSupport = new XmlTestSupport("SchemaTest"); + + @Test + @Marking(points = 1) + public void test_0100_valid_minimum() { + xmlTestSupport.assertValid("0100_valid_minimum.xml"); + } + + @Test + @Marking(points = 1) + public void test_0200_valid_noPublisher() { + xmlTestSupport.assertValid("0200_valid_noPublisher.xml"); + } + + @Test + @Marking(points = 1) + public void test_0210_valid_singlePublisher() { + xmlTestSupport.assertValid("0210_valid_singlePublisher.xml"); + } + + @Test + @Marking(points = 1) + public void test_0230_valid_multiplePublisher() { + xmlTestSupport.assertValid("0230_valid_multiplePublisher.xml"); + } + + @Test + @Marking(points = 2) + public void test_0240_invalid_duplicatePublisherId() { + xmlTestSupport.assertInvalid("0240_invalid_duplicatePublisherId.xml"); + xmlTestSupport.assertValid("0230_valid_multiplePublisher.xml"); + } + + @Test + @Marking(points = 2) + public void test_0250_invalid_duplicatePublisherNameCity() { + xmlTestSupport.assertInvalid("0250_invalid_duplicatePublisherNameCity.xml"); + xmlTestSupport.assertValid("0230_valid_multiplePublisher.xml"); + } + + @Test + @Marking(points = 2) + public void test_0260_invalid_publisherLevel() { + xmlTestSupport.assertInvalid("0260_invalid_publisherLevel.xml"); + xmlTestSupport.assertValid("0230_valid_multiplePublisher.xml"); + } + + @Test + @Marking(points = 1) + public void test_0300_valid_books() { + xmlTestSupport.assertValid("0300_valid_books.xml"); + } + + @Test + @Marking(points = 2) + public void test_0310_invalid_bookNoTitle() { + xmlTestSupport.assertInvalid("0310_invalid_bookNoTitle.xml"); + xmlTestSupport.assertValid("0300_valid_books.xml"); + } + + @Test + @Marking(points = 2) + public void test_0320_invalid_bookNoAuthor() { + xmlTestSupport.assertInvalid("0320_invalid_bookNoAuthor.xml"); + xmlTestSupport.assertValid("0300_valid_books.xml"); + } + + @Test + @Marking(points = 1) + public void test_0400_valid_websites() { + xmlTestSupport.assertValid("0400_valid_websites.xml"); + } + + @Test + @Marking(points = 2) + public void test_0410_invalid_websiteDateViolation() { + xmlTestSupport.assertInvalid("0410_invalid_websiteDateViolation.xml"); + xmlTestSupport.assertValid("0400_valid_websites.xml"); + } + + @Test + @Marking(points = 2) + public void test_0420_invalid_websiteMissingAccessDate() { + xmlTestSupport.assertInvalid("0420_invalid_websiteMissingAccessDate.xml"); + xmlTestSupport.assertValid("0400_valid_websites.xml"); + } + + @Test + @Marking(points = 2) + public void test_0430_invalid_websiteMissingUrl() { + xmlTestSupport.assertInvalid("0430_invalid_websiteMissingUrl.xml"); + xmlTestSupport.assertValid("0400_valid_websites.xml"); + } + + @Test + @Marking(points = 2) + public void test_0440_invalid_websiteUrlFormatViolation() { + xmlTestSupport.assertInvalid("0440_invalid_websiteUrlFormatViolation.xml"); + xmlTestSupport.assertValid("0400_valid_websites.xml"); + } + + @Test + @Marking(points = 1) + public void test_0500_valid_booksWebsites() { + xmlTestSupport.assertValid("0500_valid_booksWebsites.xml"); + } + + @Test + @Marking(points = 1) + public void test_0510_invalid_bookDuplicateId() { + xmlTestSupport.assertInvalid("0510_invalid_bookDuplicateId.xml"); + xmlTestSupport.assertValid("0500_valid_booksWebsites.xml"); + } + + @Test + @Marking(points = 1) + public void test_0515_invalid_bookYear() { + xmlTestSupport.assertInvalid("0515_invalid_bookYear.xml"); + xmlTestSupport.assertValid("0500_valid_booksWebsites.xml"); + } + + @Test + @Marking(points = 1) + public void test_0520_invalid_bibDuplicateId() { + xmlTestSupport.assertInvalid("0520_invalid_bibDuplicateId.xml"); + xmlTestSupport.assertValid("0500_valid_booksWebsites.xml"); + } + + @Test + @Marking(points = 1) + public void test_0600_invalid_bookInvalidPublisher() { + xmlTestSupport.assertInvalid("0600_invalid_bookInvalidPublisher.xml"); + xmlTestSupport.assertValid("0300_valid_books.xml"); + } + + @Test + @Marking(points = 1) + public void test_0700_valid_bibPublisherIdCompat() { + xmlTestSupport.assertValid("0700_valid_bibPublisherIdCompat.xml"); + } +} \ No newline at end of file diff --git a/Klausuren/Sda1/2018Summer/Solve/.gitignore b/Klausuren/Sda1/2018Summer/Solve/.gitignore index 9b36bc51..2466dd25 100644 --- a/Klausuren/Sda1/2018Summer/Solve/.gitignore +++ b/Klausuren/Sda1/2018Summer/Solve/.gitignore @@ -5,36 +5,10 @@ dependency-reduced-pom.xml *.log -# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm -# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 - -# User-specific stuff: -.idea/**/workspace.xml -.idea/**/tasks.xml -.idea/dictionaries - -# Sensitive or high-churn files: -.idea/**/dataSources/ -.idea/**/dataSources.ids -.idea/**/dataSources.xml -.idea/**/dataSources.local.xml -.idea/**/sqlDataSources.xml -.idea/**/dynamic.xml -.idea/**/uiDesigner.xml - -# Gradle: -.idea/**/gradle.xml -.idea/**/libraries - -# CMake -cmake-build-debug/ - -# Mongo Explorer plugin: -.idea/**/mongoSettings.xml +/.idea/ *.iws - # IntelliJ out/ @@ -44,9 +18,6 @@ out/ # JIRA plugin atlassian-ide-plugin.xml -# Cursive Clojure plugin -.idea/replstate.xml - # Crashlytics plugin (for Android Studio and IntelliJ) com_crashlytics_export_strings.xml crashlytics.properties diff --git a/Klausuren/Sda1/2018Summer/Solve/Doc/exam.xml b/Klausuren/Sda1/2018Summer/Solve/Doc/exam.xml index 54633021..17ec87bd 100644 --- a/Klausuren/Sda1/2018Summer/Solve/Doc/exam.xml +++ b/Klausuren/Sda1/2018Summer/Solve/Doc/exam.xml @@ -148,7 +148,7 @@ Complete the schema implementation in Schema/bib.xsd. Junit execution of - de.hdm_stuttgart.mi.sda1.test.ex1.SchemaTest + de.hdm_stuttgart.mi.sda1.test.ex1.ShowReachedPoints loads all unit tests based on files residing in your project's folder SchemaTest. In turn you receive your number of points reached so far including detailed hints about failed @@ -170,7 +170,7 @@ Executing - de.hdm_stuttgart.mi.sda1.test.ex1.SchemaTest + de.hdm_stuttgart.mi.sda1.test.ex1.ShowReachedPoints as a Java application indicates which test documents in SchemaTest yet fail the expected outcome being either valid of invalid. You also get diff --git a/Klausuren/Sda1/2018Summer/Solve/pom.xml b/Klausuren/Sda1/2018Summer/Solve/pom.xml index 0ff1239e..00383527 100644 --- a/Klausuren/Sda1/2018Summer/Solve/pom.xml +++ b/Klausuren/Sda1/2018Summer/Solve/pom.xml @@ -103,7 +103,7 @@ de.hdm_stuttgart.mi.exam unitmarking - 0.9 + 1.0 @@ -153,7 +153,7 @@ - de.hdm_stuttgart.mi.sda1.test.ShowReachedPoints + de.hdm_stuttgart.mi.sda1.test.ex1.ShowReachedPoints diff --git a/Klausuren/Sda1/2018Summer/Solve/src/main/resources/XMLSchema.xsd b/Klausuren/Sda1/2018Summer/Solve/src/main/resources/XMLSchema.xsd new file mode 100644 index 00000000..89829f13 --- /dev/null +++ b/Klausuren/Sda1/2018Summer/Solve/src/main/resources/XMLSchema.xsd @@ -0,0 +1,2471 @@ + + + + + Part 1 version: Id: structures.xsd,v 1.2 2004/01/15 11:34:25 ht Exp + Part 2 version: Id: datatypes.xsd,v 1.3 2004/01/23 18:11:13 ht Exp + + + + + + The schema corresponding to this document is normative, + with respect to the syntactic constraints it expresses in the + XML Schema language. The documentation (within <documentation> elements) + below, is not normative, but rather highlights important aspects of + the W3C Recommendation of which this is a part + + + + + The simpleType element and all of its members are defined + towards the end of this schema document + + + + + + Get access to the xml: attribute groups for xml:lang + as declared on 'schema' and 'documentation' below + + + + + + + + This type is extended by almost all schema types + to allow attributes from other namespaces to be + added to user schemas. + + + + + + + + + + + + + This type is extended by all types which allow annotation + other than <schema> itself + + + + + + + + + + + + + + + + This group is for the + elements which occur freely at the top level of schemas. + All of their types are based on the "annotated" type by extension. + + + + + + + + + + + + + This group is for the + elements which can self-redefine (see <redefine> below). + + + + + + + + + + + + + A utility type, not for public use + + + + + + + + + + + A utility type, not for public use + + + + + + + + + + + A utility type, not for public use + + #all or (possibly empty) subset of {extension, restriction} + + + + + + + + + + + + + + + + + A utility type, not for public use + + + + + + + + + + + + + A utility type, not for public use + + #all or (possibly empty) subset of {extension, restriction, list, union} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + for maxOccurs + + + + + + + + + + + + for all particles + + + + + + + for element, group and attributeGroup, + which both define and reference + + + + + + + + 'complexType' uses this + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + This branch is short for + <complexContent> + <restriction base="xsd:anyType"> + ... + </restriction> + </complexContent> + + + + + + + + + + + + + + + Will be restricted to required or forbidden + + + + + + Not allowed if simpleContent child is chosen. + May be overriden by setting on complexContent child. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + This choice is added simply to + make this a valid restriction per the REC + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Overrides any setting on complexType parent. + + + + + + + + + + + + + + + This choice is added simply to + make this a valid restriction per the REC + + + + + + + + + + + + + + + + + No typeDefParticle group reference + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + A utility type, not for public use + + #all or (possibly empty) subset of {substitution, extension, + restriction} + + + + + + + + + + + + + + + + + + + + + + + + + The element element can be used either + at the top level to define an element-type binding globally, + or within a content model to either reference a globally-defined + element or type or declare an element-type binding locally. + The ref form is not allowed at the top level. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + group type for explicit groups, named top-level groups and + group references + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + group type for the three kinds of group + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + This choice with min/max is here to + avoid a pblm with the Elt:All/Choice/Seq + Particle derivation constraint + + + + + + + + + + restricted max/min + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Only elements allowed inside + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + simple type for the value of the 'namespace' attr of + 'any' and 'anyAttribute' + + + + Value is + ##any - - any non-conflicting WFXML/attribute at all + + ##other - - any non-conflicting WFXML/attribute from + namespace other than targetNS + + ##local - - any unqualified non-conflicting WFXML/attribute + + one or - - any non-conflicting WFXML/attribute from + more URI the listed namespaces + references + (space separated) + + ##targetNamespace or ##local may appear in the above list, to + refer to the targetNamespace of the enclosing + schema or an absent targetNamespace respectively + + + + + + A utility type, not for public use + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + A subset of XPath expressions for use +in selectors + A utility type, not for public +use + + + + The following pattern is intended to allow XPath + expressions per the following EBNF: + Selector ::= Path ( '|' Path )* + Path ::= ('.//')? Step ( '/' Step )* + Step ::= '.' | NameTest + NameTest ::= QName | '*' | NCName ':' '*' + child:: is also allowed + + + + + + + + + + + + + + + + + + + + + + + A subset of XPath expressions for use +in fields + A utility type, not for public +use + + + + The following pattern is intended to allow XPath + expressions per the same EBNF as for selector, + with the following change: + Path ::= ('.//')? ( Step '/' )* ( Step | '@' NameTest ) + + + + + + + + + + + + + + + + + + + + + + + + + + + The three kinds of identity constraints, all with + type of or derived from 'keybase'. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + A utility type, not for public use + + A public identifier, per ISO 8879 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + notations for use within XML Schema schemas + + + + + + + + + Not the real urType, but as close an approximation as we can + get in the XML representation + + + + + + + + + + First the built-in primitive datatypes. These definitions are for + information only, the real built-in definitions are magic. + + + + For each built-in datatype in this schema (both primitive and + derived) can be uniquely addressed via a URI constructed + as follows: + 1) the base URI is the URI of the XML Schema namespace + 2) the fragment identifier is the name of the datatype + + For example, to address the int datatype, the URI is: + + http://www.w3.org/2001/XMLSchema#int + + Additionally, each facet definition element can be uniquely + addressed via a URI constructed as follows: + 1) the base URI is the URI of the XML Schema namespace + 2) the fragment identifier is the name of the facet + + For example, to address the maxInclusive facet, the URI is: + + http://www.w3.org/2001/XMLSchema#maxInclusive + + Additionally, each facet usage in a built-in datatype definition + can be uniquely addressed via a URI constructed as follows: + 1) the base URI is the URI of the XML Schema namespace + 2) the fragment identifier is the name of the datatype, followed + by a period (".") followed by the name of the facet + + For example, to address the usage of the maxInclusive facet in + the definition of int, the URI is: + + http://www.w3.org/2001/XMLSchema#int.maxInclusive + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + NOTATION cannot be used directly in a schema; rather a type + must be derived from it by specifying at least one enumeration + facet whose value is the name of a NOTATION declared in the + schema. + + + + + + + + + + Now the derived primitive types + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + pattern specifies the content of section 2.12 of XML 1.0e2 + and RFC 3066 (Revised version of RFC 1766). + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + pattern matches production 7 from the XML spec + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + pattern matches production 5 from the XML spec + + + + + + + + + + + + + + + pattern matches production 4 from the Namespaces in XML spec + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + A utility type, not for public use + + + + + + + + + + + + + + + + + + + + + + #all or (possibly empty) subset of {restriction, union, list} + + + A utility type, not for public use + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Can be restricted to required or forbidden + + + + + + + + + + + + + + + + + + Required at the top level + + + + + + + + + + + + + + + + + + + Forbidden when nested + + + + + + + + + + + + + + + + + + + We should use a substitution group for facets, but + that's ruled out because it would allow users to + add their own, which we're not ready for yet. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + base attribute and simpleType child are mutually + exclusive, but one or other is required + + + + + + + + + + + + + + + + itemType attribute and simpleType child are mutually + exclusive, but one or other is required + + + + + + + + + + + + + + + + + + memberTypes attribute must be non-empty or there must be + at least one simpleType child + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Klausuren/Sda1/2018Summer/Solve/src/main/resources/xml.xsd b/Klausuren/Sda1/2018Summer/Solve/src/main/resources/xml.xsd new file mode 100644 index 00000000..e60e8c59 --- /dev/null +++ b/Klausuren/Sda1/2018Summer/Solve/src/main/resources/xml.xsd @@ -0,0 +1,286 @@ + + + + + +
+

About the XML namespace

+ +
+

+ This schema document describes the XML namespace, in a form + suitable for import by other schema documents. +

+

+ See + http://www.w3.org/XML/1998/namespace.html and + + http://www.w3.org/TR/REC-xml for information + about this namespace. +

+

+ Note that local names in this namespace are intended to be + defined only by the World Wide Web Consortium or its subgroups. + The names currently defined in this namespace are listed below. + They should not be used with conflicting semantics by any Working + Group, specification, or document instance. +

+

+ See further below in this document for more information about how to refer to this schema document from your own + XSD schema documents and about the + namespace-versioning policy governing this schema document. +

+
+
+
+
+ + + + +
+ +

lang (as an attribute name)

+

+ denotes an attribute whose value + is a language code for the natural language of the content of + any element; its value is inherited. This name is reserved + by virtue of its definition in the XML specification.

+ +
+
+

Notes

+

+ Attempting to install the relevant ISO 2- and 3-letter + codes as the enumerated possible values is probably never + going to be a realistic possibility. +

+

+ See BCP 47 at + http://www.rfc-editor.org/rfc/bcp/bcp47.txt + and the IANA language subtag registry at + + http://www.iana.org/assignments/language-subtag-registry + for further information. +

+

+ The union allows for the 'un-declaration' of xml:lang with + the empty string. +

+
+
+
+ + + + + + + + + +
+ + + + +
+ +

space (as an attribute name)

+

+ denotes an attribute whose + value is a keyword indicating what whitespace processing + discipline is intended for the content of the element; its + value is inherited. This name is reserved by virtue of its + definition in the XML specification.

+ +
+
+
+ + + + + + +
+ + + +
+ +

base (as an attribute name)

+

+ denotes an attribute whose value + provides a URI to be used as the base for interpreting any + relative URIs in the scope of the element on which it + appears; its value is inherited. This name is reserved + by virtue of its definition in the XML Base specification.

+ +

+ See http://www.w3.org/TR/xmlbase/ + for information about this attribute. +

+
+
+
+
+ + + + +
+ +

id (as an attribute name)

+

+ denotes an attribute whose value + should be interpreted as if declared to be of type ID. + This name is reserved by virtue of its definition in the + xml:id specification.

+ +

+ See http://www.w3.org/TR/xml-id/ + for information about this attribute. +

+
+
+
+
+ + + + + + + + + + +
+ +

Father (in any context at all)

+ +
+

+ denotes Jon Bosak, the chair of + the original XML Working Group. This name is reserved by + the following decision of the W3C XML Plenary and + XML Coordination groups: +

+
+

+ In appreciation for his vision, leadership and + dedication the W3C XML Plenary on this 10th day of + February, 2000, reserves for Jon Bosak in perpetuity + the XML name "xml:Father". +

+
+
+
+
+
+ + + +
+

About this schema document

+ +
+

+ This schema defines attributes and an attribute group suitable + for use by schemas wishing to allow xml:base, + xml:lang, xml:space or + xml:id attributes on elements they define. +

+

+ To enable this, such a schema must import this schema for + the XML namespace, e.g. as follows: +

+
+          <schema . . .>
+           . . .
+           <import namespace="http://www.w3.org/XML/1998/namespace"
+                      schemaLocation="http://www.w3.org/2001/xml.xsd"/>
+     
+

+ or +

+
+           <import namespace="http://www.w3.org/XML/1998/namespace"
+                      schemaLocation="http://www.w3.org/2009/01/xml.xsd"/>
+     
+

+ Subsequently, qualified reference to any of the attributes or the + group defined below will have the desired effect, e.g. +

+
+          <type . . .>
+           . . .
+           <attributeGroup ref="xml:specialAttrs"/>
+     
+

+ will define a type which will schema-validate an instance element + with any of those attributes. +

+
+
+
+
+ + + +
+

Versioning policy for this schema document

+
+

+ In keeping with the XML Schema WG's standard versioning + policy, this schema document will persist at + + http://www.w3.org/2009/01/xml.xsd. +

+

+ At the date of issue it can also be found at + + http://www.w3.org/2001/xml.xsd. +

+

+ The schema document at that URI may however change in the future, + in order to remain compatible with the latest version of XML + Schema itself, or with the XML namespace itself. In other words, + if the XML Schema or XML namespaces change, the version of this + document at + http://www.w3.org/2001/xml.xsd + + will change accordingly; the version at + + http://www.w3.org/2009/01/xml.xsd + + will not change. +

+

+ Previous dated (and unchanging) versions of this schema + document are at: +

+ +
+
+
+
+ +
+ diff --git a/Klausuren/Sda1/2018Summer/Solve/src/test/java/de/hdm_stuttgart/mi/sda1/test/ex1/SchemaTest.java b/Klausuren/Sda1/2018Summer/Solve/src/test/java/de/hdm_stuttgart/mi/sda1/test/ex1/SchemaTest.java deleted file mode 100644 index 82e54951..00000000 --- a/Klausuren/Sda1/2018Summer/Solve/src/test/java/de/hdm_stuttgart/mi/sda1/test/ex1/SchemaTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package de.hdm_stuttgart.mi.sda1.test.ex1; - -import de.hdm_stuttgart.mi.unitmarking.xsd.InstanceSetEvaluation; -import org.junit.Assert; -import org.junit.Test; - -/** - * Unit test for an XML instance set. CLI by: - * java -cp target/solvejpa-0.9-fat-tests.jar org.junit.runner.JUnitCore SchemaTest - */ -@SuppressWarnings("static-method") -public class SchemaTest { - /** - * Testing a suite of XML instances. - */ - @Test - public void testXmlInstanceSet() { - - final InstanceSetEvaluation ise = - new InstanceSetEvaluation("SchemaTest", "Schema/bib.xsd"); - - System.out.println(ise.getMessages()); - - Assert.assertTrue(ise.getErrorMessages(), ise.allTestsSucceeded); - } -} \ No newline at end of file diff --git a/Klausuren/Sda1/2018Summer/Solve/src/test/java/de/hdm_stuttgart/mi/sda1/test/ex1/ShowReachedPoints.java b/Klausuren/Sda1/2018Summer/Solve/src/test/java/de/hdm_stuttgart/mi/sda1/test/ex1/ShowReachedPoints.java new file mode 100644 index 00000000..34d916ad --- /dev/null +++ b/Klausuren/Sda1/2018Summer/Solve/src/test/java/de/hdm_stuttgart/mi/sda1/test/ex1/ShowReachedPoints.java @@ -0,0 +1,22 @@ +package de.hdm_stuttgart.mi.sda1.test.ex1; + +import de.hdm_stuttgart.mi.exam.unitmarking.RunTests; + +/** + * Unit test for an XML instance set. CLI by: + * java -cp target/solvejpa-0.9-fat-tests.jar org.junit.runner.JUnitCore ShowReachedPoints + */ +@SuppressWarnings("static-method") +public class ShowReachedPoints { + /** + * Execution reveals the number of reached points. + * + * @param args Unused + */ + public static void main(String[] args) { + RunTests.exec( + "Aufgabe 1", + Test_SchemaByInstances.class + ); + } +} \ No newline at end of file diff --git a/Klausuren/Sda1/2018Summer/Solve/src/test/java/de/hdm_stuttgart/mi/sda1/test/ex1/Test_SchemaByInstances.java b/Klausuren/Sda1/2018Summer/Solve/src/test/java/de/hdm_stuttgart/mi/sda1/test/ex1/Test_SchemaByInstances.java new file mode 100644 index 00000000..7ec681b6 --- /dev/null +++ b/Klausuren/Sda1/2018Summer/Solve/src/test/java/de/hdm_stuttgart/mi/sda1/test/ex1/Test_SchemaByInstances.java @@ -0,0 +1,153 @@ +package de.hdm_stuttgart.mi.sda1.test.ex1; + +import de.hdm_stuttgart.mi.exam.unitmarking.ExaminationTestDefaults; +import de.hdm_stuttgart.mi.exam.unitmarking.Marking; +import de.hdm_stuttgart.mi.exam.unitmarking.xml.XmlTestSupport; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class Test_SchemaByInstances extends ExaminationTestDefaults { + + private final XmlTestSupport xmlTestSupport = new XmlTestSupport("SchemaTest"); + + @Test + @Marking(points = 1) + public void test_0100_valid_minimum() { + xmlTestSupport.assertValid("0100_valid_minimum.xml"); + } + + @Test + @Marking(points = 1) + public void test_0200_valid_noPublisher() { + xmlTestSupport.assertValid("0200_valid_noPublisher.xml"); + } + + @Test + @Marking(points = 1) + public void test_0210_valid_singlePublisher() { + xmlTestSupport.assertValid("0210_valid_singlePublisher.xml"); + } + + @Test + @Marking(points = 1) + public void test_0230_valid_multiplePublisher() { + xmlTestSupport.assertValid("0230_valid_multiplePublisher.xml"); + } + + @Test + @Marking(points = 2) + public void test_0240_invalid_duplicatePublisherId() { + xmlTestSupport.assertInvalid("0240_invalid_duplicatePublisherId.xml"); + xmlTestSupport.assertValid("0230_valid_multiplePublisher.xml"); + } + + @Test + @Marking(points = 2) + public void test_0250_invalid_duplicatePublisherNameCity() { + xmlTestSupport.assertInvalid("0250_invalid_duplicatePublisherNameCity.xml"); + xmlTestSupport.assertValid("0230_valid_multiplePublisher.xml"); + } + + @Test + @Marking(points = 2) + public void test_0260_invalid_publisherLevel() { + xmlTestSupport.assertInvalid("0260_invalid_publisherLevel.xml"); + xmlTestSupport.assertValid("0230_valid_multiplePublisher.xml"); + } + + @Test + @Marking(points = 1) + public void test_0300_valid_books() { + xmlTestSupport.assertValid("0300_valid_books.xml"); + } + + @Test + @Marking(points = 2) + public void test_0310_invalid_bookNoTitle() { + xmlTestSupport.assertInvalid("0310_invalid_bookNoTitle.xml"); + xmlTestSupport.assertValid("0300_valid_books.xml"); + } + + @Test + @Marking(points = 2) + public void test_0320_invalid_bookNoAuthor() { + xmlTestSupport.assertInvalid("0320_invalid_bookNoAuthor.xml"); + xmlTestSupport.assertValid("0300_valid_books.xml"); + } + + @Test + @Marking(points = 1) + public void test_0400_valid_websites() { + xmlTestSupport.assertValid("0400_valid_websites.xml"); + } + + @Test + @Marking(points = 2) + public void test_0410_invalid_websiteDateViolation() { + xmlTestSupport.assertInvalid("0410_invalid_websiteDateViolation.xml"); + xmlTestSupport.assertValid("0400_valid_websites.xml"); + } + + @Test + @Marking(points = 2) + public void test_0420_invalid_websiteMissingAccessDate() { + xmlTestSupport.assertInvalid("0420_invalid_websiteMissingAccessDate.xml"); + xmlTestSupport.assertValid("0400_valid_websites.xml"); + } + + @Test + @Marking(points = 2) + public void test_0430_invalid_websiteMissingUrl() { + xmlTestSupport.assertInvalid("0430_invalid_websiteMissingUrl.xml"); + xmlTestSupport.assertValid("0400_valid_websites.xml"); + } + + @Test + @Marking(points = 2) + public void test_0440_invalid_websiteUrlFormatViolation() { + xmlTestSupport.assertInvalid("0440_invalid_websiteUrlFormatViolation.xml"); + xmlTestSupport.assertValid("0400_valid_websites.xml"); + } + + @Test + @Marking(points = 1) + public void test_0500_valid_booksWebsites() { + xmlTestSupport.assertValid("0500_valid_booksWebsites.xml"); + } + + @Test + @Marking(points = 1) + public void test_0510_invalid_bookDuplicateId() { + xmlTestSupport.assertInvalid("0510_invalid_bookDuplicateId.xml"); + xmlTestSupport.assertValid("0500_valid_booksWebsites.xml"); + } + + @Test + @Marking(points = 1) + public void test_0515_invalid_bookYear() { + xmlTestSupport.assertInvalid("0515_invalid_bookYear.xml"); + xmlTestSupport.assertValid("0500_valid_booksWebsites.xml"); + } + + @Test + @Marking(points = 1) + public void test_0520_invalid_bibDuplicateId() { + xmlTestSupport.assertInvalid("0520_invalid_bibDuplicateId.xml"); + xmlTestSupport.assertValid("0500_valid_booksWebsites.xml"); + } + + @Test + @Marking(points = 1) + public void test_0600_invalid_bookInvalidPublisher() { + xmlTestSupport.assertInvalid("0600_invalid_bookInvalidPublisher.xml"); + xmlTestSupport.assertValid("0300_valid_books.xml"); + } + + @Test + @Marking(points = 1) + public void test_0700_valid_bibPublisherIdCompat() { + xmlTestSupport.assertValid("0700_valid_bibPublisherIdCompat.xml"); + } +} \ No newline at end of file diff --git a/ws/Artifacts/Unitmarking/pom.xml b/ws/Artifacts/Unitmarking/pom.xml index 87c0a682..f0c9504c 100644 --- a/ws/Artifacts/Unitmarking/pom.xml +++ b/ws/Artifacts/Unitmarking/pom.xml @@ -4,7 +4,7 @@ de.hdm_stuttgart.mi.exam unitmarking - 0.9 + 1.0 jar unitmarking @@ -52,13 +52,6 @@ 1.1.6 - - org.xmlunit - xmlunit-core - 2.6.2 - - - diff --git a/ws/Artifacts/Unitmarking/src/main/java/de/hdm_stuttgart/mi/exam/unitmarking/xml/XmlTestSupport.java b/ws/Artifacts/Unitmarking/src/main/java/de/hdm_stuttgart/mi/exam/unitmarking/xml/XmlTestSupport.java index 69b1098a..fdfb7027 100644 --- a/ws/Artifacts/Unitmarking/src/main/java/de/hdm_stuttgart/mi/exam/unitmarking/xml/XmlTestSupport.java +++ b/ws/Artifacts/Unitmarking/src/main/java/de/hdm_stuttgart/mi/exam/unitmarking/xml/XmlTestSupport.java @@ -1,122 +1,201 @@ package de.hdm_stuttgart.mi.exam.unitmarking.xml; import org.junit.Assert; +import org.w3c.dom.Attr; +import org.w3c.dom.Element; import org.xml.sax.SAXException; -import org.xmlunit.XMLUnitException; -import org.xmlunit.builder.Input; -import org.xmlunit.validation.Languages; -import org.xmlunit.validation.ValidationResult; -import org.xmlunit.validation.Validator; +import org.xml.sax.SAXParseException; +import org.xml.sax.helpers.DefaultHandler; +import javax.xml.XMLConstants; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; -import javax.xml.transform.Source; import javax.xml.transform.stream.StreamSource; -import java.io.File; +import javax.xml.validation.SchemaFactory; +import javax.xml.validation.Validator; import java.io.IOException; -import java.util.stream.Collectors; -import java.util.stream.StreamSupport; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.Map; public class XmlTestSupport { - static { - final Validator xmlSchemaValidatorTmp = Validator.forLanguage(Languages.W3C_XML_SCHEMA_NS_URI); - xmlSchemaValidatorTmp.setSchemaSource(new StreamSource("src/main/resources/XMLSchema.xsd")); - xmlSchemaValidator = xmlSchemaValidatorTmp; - } - - static final Validator xmlSchemaValidator; - - private SAXParser nonValidatingParser; - private WellformedCheckHandler wch; - - private final String schemaFileName; - private final Validator validator; - public final String schemaInvalidErrorMessages; - - public XmlTestSupport(final String schemaFileName) { - this.schemaFileName = schemaFileName; - - Validator validatorTmp = null; - String schemaInvalidErrorMessagesTmp = null; - wch = new WellformedCheckHandler(); + static public final String + /** + *

The XML Schema namespace as being defined in + * https://www.w3.org/TR/xmlschema-1/#Instance_Document_Constructions.

+ */ + xmlns_xsi = "http://www.w3.org/2001/XMLSchema-instance" + /** + *

The schema reference attribute name, see {@link #xmlns_xsi} for explanation.

+ */ + ,noNamespaceSchemaLocationAttributeName = "noNamespaceSchemaLocation"; + + static private final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); + static private final Map validator2schema = new HashMap<>(); + private final DocumentBuilder nonValidatingBuilder; + + /** + * The directory containing schema unit tests. + */ + public final String testDirectoryPathname; + + + /** + * Unit test support for schema unit tests. + * + * @param testDirectoryPathname see {@link #testDirectoryPathname} + */ + public XmlTestSupport(final String testDirectoryPathname) { + this.testDirectoryPathname = testDirectoryPathname; + final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setNamespaceAware(true); + factory.setValidating(false); + DocumentBuilder nonValidatingBuilderTmp = null; try { - SAXParserFactory spf = SAXParserFactory.newInstance(); - spf.setValidating(false); - spf.setNamespaceAware(true); - - nonValidatingParser = spf.newSAXParser(); - nonValidatingParser.parse(new File(schemaFileName), wch); - - // Document is well-formed, so what about validity? - try { - final Source source = Input.fromFile(schemaFileName).build(); - final ValidationResult r = xmlSchemaValidator.validateInstance(source); - if (r.isValid()) { - validatorTmp = Validator.forLanguage(Languages.W3C_XML_SCHEMA_NS_URI); - validatorTmp.setSchemaSource(new StreamSource(schemaFileName)); - } else { - schemaInvalidErrorMessagesTmp = "Schema " + schemaFileName + " is invalid:" - + formatErrorMessages(r); - } - } catch (final XMLUnitException e) { - final Throwable cause = e.getCause(); - schemaInvalidErrorMessagesTmp = - null == cause? - e.getMessage(): - " Not well-formed?\n " + cause.getMessage(); - } - - } catch (SAXException e) { - schemaInvalidErrorMessagesTmp = " Unable to parse " + schemaFileName + " " + - wch.formatErrorMessages() + "\n schema is possibly not well-formed\n " + - e.getMessage(); - }catch (ParserConfigurationException | IOException e) { - schemaInvalidErrorMessagesTmp = " Unable to parse " + schemaFileName + " " + - e.getMessage() ; + nonValidatingBuilderTmp = factory.newDocumentBuilder(); + nonValidatingBuilderTmp.setErrorHandler(new DefaultHandler()); + } catch (ParserConfigurationException e) { + Assert.fail("Unable to create non-validating parser:" + e); + } finally { + nonValidatingBuilder = nonValidatingBuilderTmp; } + } - validator = validatorTmp; - schemaInvalidErrorMessages = schemaInvalidErrorMessagesTmp; + /** + * Assert whether or not the given instance is valid. + * + * @param instanceFilename The XML instance containing an XML schema reference to be handled. + * @param expectValidInstance A value of true of false will cause the assertion to fail in case the instance is + * invalid or valid respectively. + */ + private void assertExpectedValidationStatus(final String instanceFilename, final boolean expectValidInstance) { + + final Path instancePath = Paths.get(testDirectoryPathname, instanceFilename).normalize(); + + final Attr schemaPathNameAttr = parseWellFormed( // Schema reference found? + instancePath).getAttributeNodeNS(xmlns_xsi, noNamespaceSchemaLocationAttributeName); + + Assert.assertNotNull( // Oops, no schema! + "No schema provided by attribute " + noNamespaceSchemaLocationAttributeName + + " from namespace\n" + xmlns_xsi + " in file " + getClickableFileName(instanceFilename, 1), + schemaPathNameAttr); + + final Path schemaPath = Paths.get( + instancePath.getParent().toString(), // Strip filename from path, + schemaPathNameAttr.getValue()).normalize(); // add relative schema path + + parseWellFormed(schemaPath); // Schema is well-formed? + final Path xmlSchemaPath = Paths.get("src/main/resources/XMLSchema.xsd"); + validate(schemaPath, xmlSchemaPath, true);// Schema valid with respect to XML schema standard ? + validate(instancePath, schemaPath, expectValidInstance); // Instance valid or invalid with respect to given XML schema ? } - public void assertValid(final String instanceFileName) { + /** + *

Assert a given instance to be valid. The following steps will be evaluated:

+ * + *
    + *
  1. + *

    Check instance for well-formedness

    + *

    Possible failure: Instnce may not be well-formed.

    + *
  2. + *
  3. + *

    Get the associated schema using the instance's {@link #noNamespaceSchemaLocationAttributeName} + * * attribute value.

    + *

    Possible failures:

    + *
      + *
    • Missing attribute or wrong namespace
    • + *
    • Missing or wrong attribute value not being resolvable to an XML Schema.
    • + *
    + *
  4. + *
  5. + *

    Check the associated schema to be well-formed.

    + *

    Possible failure: The schema may not be well-formed.

    + *
  6. + *
  7. + *

    Check the associated schema itself to be valid with respect to + * * A Schema for Schemas.

    + *

    Possible failure: The schema may not be well-formed.

    + *
  8. + *
  9. + *

    Check the instance for validity with respect to the associated schema.

    + *

    Possible failure: The instance may not be valid.

    + *
  10. + *
+ * + *

Any negative outcome will result in a test failure.

+ * + * @param instanceFilename The instance to be examined. + */ + public void assertValid(final String instanceFilename) { + assertExpectedValidationStatus(instanceFilename, true); + } - parseWellFormed(instanceFileName); + /** + *

Similar to {@link #assertValid(String)} except for the very last step being + * expected to fail.

+ * + * @param instanceFilename The instance to be examined. + */ + public void assertInvalid(final String instanceFilename) { + assertExpectedValidationStatus(instanceFilename, false); + } - final ValidationResult r = validator.validateInstance(Input.fromFile(instanceFileName).build()); + static void validate(final Path instancePath, final Path schemaPath, final boolean expectValidInstance) { - if (! r.isValid()) { - Assert.fail(instanceFileName + " expected to be valid but:\n " + formatErrorMessages(r) + "\n"); + final String instanceFilename = instancePath.getFileName().toString(); + try { + Validator validator = // Validator already present from + validator2schema.get(schemaPath); // parsing another instance? + if (null == validator) { + validator = schemaFactory.newSchema(schemaPath.toFile()).newValidator(); + validator2schema.put(schemaPath, validator); + } + validator.validate( // Re-do parsing: Starting from DOMSource(root) + new StreamSource(instancePath.toFile())); // conceals line numbers, sigh! + if (!expectValidInstance) { + Assert.fail("Instance " + getClickableFileName(instanceFilename, 1) + " is supposed to be invalid"); + } + } catch (final SAXParseException e) { + if (expectValidInstance) { + Assert.fail("Instance " + getClickableFileName(instanceFilename, e.getLineNumber()) + + " is invalid:\n" + format(e) + "\n"); + } + } catch (final SAXException e) { + if (expectValidInstance) { + Assert.fail("Instance " + instanceFilename + " is NOT valid reason:" + e + "\n"); + } + } catch (final IOException e) { + Assert.fail("Unable to read " + instanceFilename + ": " + e + "\n"); } } - private void parseWellFormed(final String instanceFileName) { - wch.clear(); + private Element parseWellFormed(final Path instancePath) { try { - nonValidatingParser.parse(new File(instanceFileName), wch); - } catch (final SAXException e) { - Assert.fail(instanceFileName + " possibly not well-formed:\n " + - wch.formatErrorMessages()); - }catch (final IOException e) { - Assert.fail(e.getMessage()); + return nonValidatingBuilder.parse( + instancePath.toFile()).getDocumentElement(); + } catch (final SAXParseException e) { + Assert.fail("Unable to parse " + instancePath.toString() + + ":\n " + getClickableFileName(instancePath.getFileName().toString(), e.getLineNumber()) + ")\n" + + format(e) + "\nDocument possibly not well-formed\n"); + } catch (final SAXException e) { + Assert.fail("Unable to parse '" + instancePath + "':\n" + e); + } catch (final IOException e) { + Assert.fail("Unable to read '" + instancePath + "':\n" + e); } + return null; // Runtime unreachable due to previously either returning or assert based test failure. } - public void assertInvalid(final String instanceFileName) { - - parseWellFormed(instanceFileName); - if (validator.validateInstance(Input.fromFile(instanceFileName).build()).isValid()) { - Assert.fail(instanceFileName + "should be invalid\n"); - } + static private String format(final SAXParseException e) { + return "line=" + e.getLineNumber() + ", column=" + e.getColumnNumber() + ":\n" + + e.getMessage(); } - - static public String formatErrorMessages(final ValidationResult r) { - return StreamSupport. - stream(r.getProblems().spliterator(), true). - map(p -> "\n line=" + p.getLine() + ", column=" + p.getColumn() + ":\n " + p.getMessage()). - collect(Collectors.joining("\n ")); + // See + // https://stackoverflow.com/questions/7930844/is-it-possible-to-have-clickable-class-names-in-console-output-in-intellij + static private String getClickableFileName(final String fileName, final int line) { + return ".(" + fileName + ":" + line + ")"; } } \ No newline at end of file diff --git a/ws/Artifacts/Unitmarking/src/main/java/de/hdm_stuttgart/mi/unitmarking/xsd/CreateTestClass.java b/ws/Artifacts/Unitmarking/src/main/java/de/hdm_stuttgart/mi/unitmarking/xsd/CreateTestClass.java new file mode 100644 index 00000000..73ca5527 --- /dev/null +++ b/ws/Artifacts/Unitmarking/src/main/java/de/hdm_stuttgart/mi/unitmarking/xsd/CreateTestClass.java @@ -0,0 +1,103 @@ +package de.hdm_stuttgart.mi.unitmarking.xsd; + +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; + +import java.io.File; +import java.io.IOException; +import java.util.Arrays; +import java.util.Comparator; +import java.util.List; + +/** + * Evaluate a given set of XML document instances + * + */ +class CreateTestClass { + + private static Logger log = LogManager.getLogger(CreateTestClass.class); + private final String xmlTestFileDir; + + /** + * + * @param xmlTestFileDir Directory containing XML instances to be processed. + */ + CreateTestClass(final String xmlTestFileDir) { + + this.xmlTestFileDir = xmlTestFileDir; + + System.out.println("private final XmlTestSupport xmlTestSupport = new XmlTestSupport(\""+ + xmlTestFileDir +"\");\n"); + + Arrays.stream(new File(xmlTestFileDir).listFiles(path -> path.getPath().endsWith(".xml"))). + sorted(Comparator.comparing(File::toString)). + forEach(this::readTestHeader); + + } + + private void readTestHeader(final File instanceFilename) { + + final SAXBuilder metainfoParser = new SAXBuilder(XMLReaders.NONVALIDATING); + try { + final Document doc = metainfoParser.build(instanceFilename); + + final XPathExpression searchHeader = + XPathFactory.instance().compile( + "/processing-instruction('xmlTest')", + Filters.processinginstruction()); + final List xmlTestList = + searchHeader.evaluate(doc); + + switch (xmlTestList.size()) { + case 0: + log.info("No 'xmlTest PI found, possible dependency file"); + break; + case 1: + writeTest(instanceFilename.getName(), xmlTestList.get(0)); + break; + default: + log.info("Found " + xmlTestList.size() + "' annotations in file '" + instanceFilename.getPath() + "'\n"); + } + + } catch (final JDOMException e) { + log.error("Document '" + instanceFilename.getPath() + + "' is invalid:", e); + log.error("Unable to parse document " + instanceFilename.getPath() + ": " + e + "\n"); + } catch (final IOException e) { + log.error("Unable to read document " + instanceFilename.getPath() + ": " + e + "\n"); + } + } + + private void writeTest(final String fileName, final ProcessingInstruction pi) { + + final int points = Integer.parseInt(pi.getPseudoAttributeValue("points")); + final boolean expectedToBeValid = Boolean.parseBoolean(pi.getPseudoAttributeValue("expectedToBeValid")); + + System.out.println("@Test @Marking(points = " + points + ")"); + + final String fileBaseName = fileName.replaceFirst("[.][^.]+$", ""); + System.out.println("public void test_" + fileBaseName + "() {"); + + + if (expectedToBeValid) { + System.out.println(" xmlTestSupport.assertValid(\"" + fileName + "\");"); + } else { + System.out.println(" xmlTestSupport.assertInvalid(\"" + fileName + "\");"); + } + + final String preconditionValidFilename = pi.getPseudoAttributeValue("preconditionValid"); + + if (null != preconditionValidFilename) { + System.out.println(" xmlTestSupport.assertValid(\"" + preconditionValidFilename + "\");"); + } + System.out.println("}\n"); + } +} diff --git a/ws/Artifacts/Unitmarking/src/main/java/de/hdm_stuttgart/mi/unitmarking/xsd/GenerateUnitTestClass.java b/ws/Artifacts/Unitmarking/src/main/java/de/hdm_stuttgart/mi/unitmarking/xsd/GenerateUnitTestClass.java new file mode 100644 index 00000000..d6abbda9 --- /dev/null +++ b/ws/Artifacts/Unitmarking/src/main/java/de/hdm_stuttgart/mi/unitmarking/xsd/GenerateUnitTestClass.java @@ -0,0 +1,14 @@ +package de.hdm_stuttgart.mi.unitmarking.xsd; + + +/** + * Hack: Should be copied avoiding versioning problems. + */ +public class GenerateUnitTestClass { + + public static void main(String[] args) { + + final CreateTestClass create = + new CreateTestClass("SchemaTest"); + } +} diff --git a/ws/Artifacts/Unitmarking/src/main/java/de/hdm_stuttgart/mi/unitmarking/xsd/InstanceSetEvaluation.java b/ws/Artifacts/Unitmarking/src/main/java/de/hdm_stuttgart/mi/unitmarking/xsd/InstanceSetEvaluation.java index 681b2ee7..6ab8111d 100644 --- a/ws/Artifacts/Unitmarking/src/main/java/de/hdm_stuttgart/mi/unitmarking/xsd/InstanceSetEvaluation.java +++ b/ws/Artifacts/Unitmarking/src/main/java/de/hdm_stuttgart/mi/unitmarking/xsd/InstanceSetEvaluation.java @@ -105,34 +105,34 @@ public class InstanceSetEvaluation { void readTestHeader(final File instanceFilename, final String xsdSchemaFilename) { - final SAXBuilder metainfoParser = new SAXBuilder(XMLReaders.NONVALIDATING); - try { - final Document doc = metainfoParser.build(instanceFilename); - - final XPathExpression searchHeader = - XPathFactory.instance().compile( - "/processing-instruction('xmlTest')", - Filters.processinginstruction()); - final List 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, xsdSchemaFilename, instanceFilename)); - break; - default: - warnings.append("Found " + xmlTestList.size() + "' annotations in file '" + instanceFilename.getPath() + "'\n"); - } - - } catch (final JDOMException e) { - log.error("Document '" + instanceFilename.getPath() + - "' is invalid:", e); - warnings.append("Unable to parse document " + instanceFilename.getPath() + ": " + e + "\n"); - } catch (final IOException e) { - warnings.append("Unable to read document " + instanceFilename.getPath() + ": " + e + "\n"); - } +// final SAXBuilder metainfoParser = new SAXBuilder(XMLReaders.NONVALIDATING); +// try { +// final Document doc = metainfoParser.build(instanceFilename); +// +// final XPathExpression searchHeader = +// XPathFactory.instance().compile( +// "/processing-instruction('xmlTest')", +// Filters.processinginstruction()); +// final List 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, xsdSchemaFilename, instanceFilename)); +// break; +// default: +// warnings.append("Found " + xmlTestList.size() + "' annotations in file '" + instanceFilename.getPath() + "'\n"); +// } +// +// } catch (final JDOMException e) { +// log.error("Document '" + instanceFilename.getPath() + +// "' is invalid:", e); +// warnings.append("Unable to parse document " + instanceFilename.getPath() + ": " + e + "\n"); +// } catch (final IOException e) { +// warnings.append("Unable to read document " + instanceFilename.getPath() + ": " + e + "\n"); +// } } } diff --git a/ws/Artifacts/Unitmarking/src/main/java/de/hdm_stuttgart/mi/unitmarking/xsd/InstanceTest.java b/ws/Artifacts/Unitmarking/src/main/java/de/hdm_stuttgart/mi/unitmarking/xsd/InstanceTest.java index 83d4adc4..11e0bf68 100644 --- a/ws/Artifacts/Unitmarking/src/main/java/de/hdm_stuttgart/mi/unitmarking/xsd/InstanceTest.java +++ b/ws/Artifacts/Unitmarking/src/main/java/de/hdm_stuttgart/mi/unitmarking/xsd/InstanceTest.java @@ -75,14 +75,14 @@ public class InstanceTest { * @param xmlTest The PI meta annotation header containing the expected * result, points etc. * @param xmlTestFileDir The directory containing the XML instance files. + * @param xsdSchemaFilename The schema to be used for validation. * @param xmlInstance The current instance to be evaluated. */ public InstanceTest(final ProcessingInstruction xmlTest, final String xmlTestFileDir, final String xsdSchemaFilename, final File xmlInstance) { Validator validator = null; - - SchemaFactory sf = SchemaFactory.newInstance( + final SchemaFactory sf = SchemaFactory.newInstance( "http://www.w3.org/XML/XMLSchema/v1.1"); Schema s; -- GitLab