Prüft XInneres Nachrichten anhand der von uns offiziell herausgegebenen XML Schemata und Beispielen für mögliche weitergehende Prüfungen mit Schematron.
Prüft XInneres Nachrichten anhand der von uns offiziell herausgegebenen XML Schemata und Beispielen für mögliche weitergehende Prüfungen mit Schematron.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Generiert am Beginn eines eingebetteten HTML Dokuments, welches den Prüf- und
- Bewertungsbericht visualisiert und die Handlungsempfehlung begründet, eine Übersicht
- mit Metadaten des geprüften Dokuments.
-
-
-
-
-
-
- Angaben zum geprüften Dokument
-
-
-
Referenz:
-
-
-
-
-
Zeitpunkt der Prüfung:
-
-
-
-
-
Erkannter Dokumenttyp:
-
-
-
-
-
-
- unbekannt
-
-
-
-
-
-
-
-
-
-
-
-
- Generiert am Ende eines eingebetteten HTML Dokuments, welches den Prüf- und
- Bewertungsbericht visualisiert und die Handlungsempfehlung begründet, eine Übersicht
- mit Metadaten zum Prüfmodul.
-
-
-
-
-
- Dieser Prüfbericht wurde erstellt mit
-
- .
-
-
-
-
-
- Generiert in dem eingebetetteten HTML Dokument eine Tabelle mit den während der
- Validierung ausgegebenen Daten.
-
-
-
-
-
Übersicht der Validierungsergebnisse:
-
-
-
-
Prüfschritt
-
Fehler
-
Warnungen
-
Informationen
-
-
-
-
-
-
-
-
- (
-
- )
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Validierungsergebnisse im Detail:
-
-
-
-
Pos
-
Code
-
Adj. Grad (Grad)
-
Text
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Pfad:
-
-
- Zeile:
-
-
- Spalte:
-
-
-
-
-
-
-
-
-
-
- Generiert in dem eingebetteten HTML Dokument eine Aussage zur Konformität des
- geprüften Dokuments zu den formalen Vorgaben.
-
-
-
-
-
-
-
-
-
- Konformitätsprüfung:
- Das geprüfte Dokument enthält
-
-
- weder Fehler noch Warnungen. Es ist konform zu den formalen Vorgaben.
-
-
-
- nicht konform
- zu den formalen Vorgaben.
-
-
-
-
-
-
- Konformitätsprüfung:
- Das geprüfte Dokument entspricht keinen zulässigen Dokumenttyp und ist damit
- nicht konform
- zu den formalen Vorgaben.
-
-
-
-
-
-
-
-
- Generiert in dem eingebetteten HTML Dokument die Aussage zur
- Handlungsempfehlung.
-
-
-
-
-
-
-
-
-
Bewertung: Es wird empfohlen das Dokument zurückzuweisen.
-
-
-
Bewertung: Es wird empfohlen das Dokument anzunehmen und weiter zu verarbeiten.
-
-
-
Bewertung: Es wird empfohlen das Dokument anzunehmen und zu verarbeiten, da die
- vorhandenen Fehler derzeit toleriert werden.
-
-
-
-
Bewertung: Es wird empfohlen das Dokument zurückzuweisen.
-
-
-
-
-
-
-
-
- Inhalt des Rechnungsdokuments:
-
-
-
-
-
-
-
-
- Eine Element wird als eine Zeile in einer Tabelle visualisiert. Die erste Spalte
- enthält die Zeilennummer, die zweite Attribute und Text des Elements
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Ein Textbereich (in der Zeile des Elements)
-
-
-
-
-
-
-
-
-
-
- [ … ]
-
-
-
-
-
-
-
- Ein Attributbereich (in der Zeile des Elements)
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/test/resources/examples/repository/resources/eRechnung/report.xsl b/src/test/resources/examples/repository/resources/eRechnung/report.xsl
deleted file mode 100644
index bf1dafe..0000000
--- a/src/test/resources/examples/repository/resources/eRechnung/report.xsl
+++ /dev/null
@@ -1,607 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Unexpected result from schematron validation - there is no svrl:schematron-output element!
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- error
- warning
- information
- warning
- error
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- step_
-
-
-
-
-
-
-
-
-
- message_
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Dies ist das zentrale Template des Skripts. Angewandt auf ein
- validationReport-Dokument, und unter Nutzung des Parameters wird eine Handlungsempfehlung in Form eines
- accept oder reject Elements erstellt, welches eine
- Begründung der jeweiligen Empfehlung enthalten kann.
- Das Template realisiert eine Funktion f:validationReport, assessment →
- suggestion
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Ermittelt für eine während der Validierung ausgegebene Fehlernachricht deren
- Fehlerlevel (error, warning, information) gemäß der
- benutzerspezifischen Qualifizierung.
- Jede Fehlernachricht hat im Rahmen der Validierung ein solches Fehlerlevel
- erhalten (siehe Attribut @level). Im Regelfall entspricht die
- benutzerspezifische Qualifizierung unverändert diesem Level. Nutzer können jedoch im
- Rahmen der Bewertung eigene Qualifizierungen vereinbaren und in dem als Parameter
- übergebenen assessment
- Element für bestimmte, anhand des Fehlercodes identifizierten Fehlermeldungen eine
- eigene Qualifizierung als customLevel festlegen.
- Dies kann z. B. genutzt werden, um einen error, der ansonsten zur
- Rückweisung der Nachricht führen würde, zumindest zeitweilig als
- warning zu qualifizieren, so dass eine entsprechende
- Dokumenteninstanz trotz einer Warnung angenommen und verarbeitet würde.
- Die Funktion prüft für eine Fehlernachricht, ob deren @code Attribut
- Bestandteil der für ein bestimmtes customLevel des Parameters angegebenen Fehlercodes ist.
- Falls ja, dann gilt das jeweilige customLevel. Andernfalls wird der im
- Rahmen der Validierung ermittelte Fehlerlevel unverändert übernommen.
-
- Eine im Rahmen der Validierung ausgegebene
- Fehlernachricht
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Generiert das head Element eines eingebetteten HTML Dokuments,
- welches den Prüf- und Bewertungsbericht visualisiert und die Handlungsempfehlung
- begründet
-
-
-
-
- Pruefbericht der KoSIT
-
-
-
-
-
-
- Generiert die Überschrift des eines eingebetteten HTML Dokuments, welches den
- Prüf- und Bewertungsbericht visualisiert und die Handlungsempfehlung
- begründet
-
-
-
-
Prüfbericht der KoSIT
-
-
-
-
- Generiert am Beginn eines eingebetteten HTML Dokuments, welches den Prüf- und
- Bewertungsbericht visualisiert und die Handlungsempfehlung begründet, eine Übersicht
- mit Metadaten des geprüften Dokuments.
-
-
-
-
- Angaben zum geprüften Dokument
-
-
-
-
-
Prüfbericht Nr.
-
-
-
-
-
-
-
Dokument:
-
-
-
-
-
-
Szenario:
-
-
-
-
-
-
Zeitpunkt:
-
-
-
-
-
-
Validierungsschritte:
-
Fehler
-
Warnung
-
Information
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Generiert am Ende eines eingebetteten HTML Dokuments, welches den Prüf- und
- Bewertungsbericht visualisiert und die Handlungsempfehlung begründet, eine Übersicht
- mit Metadaten zum Prüfmodul.
-
-
-
-
- Erstellt mit:
-
- für das InstructionSet
-
-
-
- vom
-
- .
-
-
-
-
-
- Generiert in dem eingebetetteten HTML Dokument eine Tabelle mit den während der
- Validierung ausgegebenen Daten.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Generiert in der HTML-Tabelle der Validierungsnachtichten in dem eingebetteten
- HTML Dokument dn Tabellenkopf
-
-
-
-
-
-
Pos
-
Code
-
CustomLevel (Level)
-
Step
-
Text
-
-
-
-
-
-
- Generiert in der HTML-Tabelle der Validierungsnachtichten in dem eingebetteten
- HTML Dokument eine oder mehrere Zeilen pro Validierungsnachricht
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Generiert in dem eingebetteten HTML Dokument eine Aussage zur Konformität des
- geprüften Dokuments zu den formalen Vorgaben.
-
-
-
-
-
-
- Konformitätsprüfung:
- Das geprüfte Dokument enthält
-
-
- weder Fehler noch Warnungen. Es ist konform zu den formalen Vorgaben.
-
-
-
- nicht konform
- zu den formalen Vorgaben.
-
-
-
-
-
-
-
- Generiert in dem eingebetteten HTML Dokument die Aussage zur
- Handlungsempfehlung.
-
-
-
-
-
-
- Bewertung:
-
-
- Es wird empfohlen das Dokument anzunehmen un weiter zu verarbeiten.
-
-
- Es wird empfohlen das Dokument anzunehmen und zu verarbeiten, da die vorhandenen Fehler derzeit toleriert werden.
-
-
- Es wird empfohlen das Dokument zurückzuweisen.
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/test/resources/examples/simple/input/simple.xml b/src/test/resources/examples/simple/input/simple.xml
index 63032b1..4f0df5a 100644
--- a/src/test/resources/examples/simple/input/simple.xml
+++ b/src/test/resources/examples/simple/input/simple.xml
@@ -2,4 +2,14 @@
asldkfj
+
+
+
+
+
+
+
some data
+
+
+
\ No newline at end of file
diff --git a/src/test/resources/examples/simple/repository/simple.xsd b/src/test/resources/examples/simple/repository/simple.xsd
index b7f2b68..30ba1f4 100644
--- a/src/test/resources/examples/simple/repository/simple.xsd
+++ b/src/test/resources/examples/simple/repository/simple.xsd
@@ -1,7 +1,6 @@
+ targetNamespace="http://validator.kosit.de/test-sample" elementFormDefault="qualified">
@@ -9,6 +8,7 @@
+
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/src/test/resources/invalid/scenarios-illformed.xml b/src/test/resources/invalid/scenarios-illformed.xml
deleted file mode 100644
index b7d5569..0000000
--- a/src/test/resources/invalid/scenarios-illformed.xml
+++ /dev/null
@@ -1,90 +0,0 @@
-
-
-
-
- XInneres
- 2017-08-08
-
-
Prüft XInneres Nachrichten anhand der von uns offiziell herausgegebenen XML Schemata und Beispielen für mögliche weitergehende Prüfungen mit Schematron.
Prüft XInneres Nachrichten anhand der von uns offiziell herausgegebenen XML Schemata und Beispielen für
- mögliche weitergehende Prüfungen mit Schematron.
-
Prüft XInneres Nachrichten anhand der von uns offiziell herausgegebenen XML Schemata und Beispielen für mögliche weitergehende Prüfungen mit Schematron.
-
Prüft elektronische Rechnungen im Format UBL 2.1
-
-
-
- XMeld 2.1
- http://www.osci.de/xmeld21
- /xmeld:*
-
-
- XML Schema von XMeld 2.1 (aggregiert)
- resources/xmeld21/xmeld-nachrichten.xsd
-
-
-
-
- XInneres Prüfregeln
- resources/xmeld21/xinneres-pruefregeln.xsl
-
-
-
-
- Default Report
- resources/default/report.xsl
-
-
-
-
-
- UBL 2.1 Invoice
- urn:oasis:names:specification:ubl:schema:xsd:Invoice-2
- /invoice:Invoice
-
-
-
- UBL 2.1 Invoice
- resources/eRechnung/UBL-2.1/xsdrt/maindoc/UBL-Invoice-2.1.xsd
-
-
-
-
- BII Rules for Invoice
- resources/eRechnung/BIS2.0-VA-V3.4.0/XSLT/BIIRULES-UBL-T10.xsl
-
-
-
-
- openPEPPOL Rules for Invoice
- resources/eRechnung/BIS2.0-VA-V3.4.0/XSLT/OPENPEPPOL-UBL-T10.xsl
-
-
-
-
- Report für eRechnung
-
- resources/eRechnung/report-erechnung.xsl
-
- EUGEN-T110-R019
-
-
-
-
-
- default
- resources/eRechnung/report.xsl
-
-
-
-
From 7ec74148753e009a10d582fb879d500fe559359c Mon Sep 17 00:00:00 2001
From: "Andreas Penski (init)"
Date: Wed, 18 Dec 2019 16:38:08 +0100
Subject: [PATCH 003/306] #39 Lazily read inputstream use URI loading where
applicable
---
.../validationtool/api/InputFactory.java | 85 +++++++------------
.../de/kosit/validationtool/cmd/Daemon.java | 7 +-
2 files changed, 36 insertions(+), 56 deletions(-)
diff --git a/src/main/java/de/kosit/validationtool/api/InputFactory.java b/src/main/java/de/kosit/validationtool/api/InputFactory.java
index cac5983..77d99d0 100644
--- a/src/main/java/de/kosit/validationtool/api/InputFactory.java
+++ b/src/main/java/de/kosit/validationtool/api/InputFactory.java
@@ -21,8 +21,6 @@ package de.kosit.validationtool.api;
import static org.apache.commons.lang3.StringUtils.isNotEmpty;
-import java.io.BufferedInputStream;
-import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
@@ -30,13 +28,8 @@ import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.net.URLConnection;
-import java.nio.file.Files;
import java.nio.file.Path;
-import java.security.DigestInputStream;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-import javax.xml.bind.DatatypeConverter;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
@@ -101,11 +94,7 @@ public class InputFactory {
*/
public static Input read(final Path path, final String digestAlgorithm) {
checkNull(path);
- try ( final InputStream stream = Files.newInputStream(path) ) {
- return read(stream, path.toString(), digestAlgorithm);
- } catch (final IOException e) {
- throw new IllegalArgumentException(MESSAGE_OPEN_STREAM_ERROR + path, e);
- }
+ return read(path.toUri(), digestAlgorithm);
}
/**
@@ -119,10 +108,38 @@ public class InputFactory {
return read(file, DEFAULT_ALGORITH);
}
+
+ /**
+ * Liest einen Prüfling von der übergebenen URI. Es wird der Default-Prüfsummenalgorithmus zur Ermittlung der Prüfsumme
+ * genutzt.
+ *
+ * @param uri URI des Prüflings
+ * @return ein Prüf-Eingabe-Objekt
+ */
+ public static Input read(final URI uri) {
+ return read(uri, DEFAULT_ALGORITH);
+ }
+
+ /**
+ * Liest einen Prüfling von der übergebenen URL. Es wird ein definierter Algorithmis zur Ermittlung der Prüfsumme
+ * genutzt.
+ *
+ * @param uri URI des Prüflings
+ * @param digestAlgorithm der Prüfsummenalgorithmus
+ * @return ein Prüf-Eingabe-Objekt
+ */
+ public static Input read(final URI uri, final String digestAlgorithm) {
+ try {
+ return read(uri.toURL(), digestAlgorithm);
+ } catch (final MalformedURLException e) {
+ throw new IllegalArgumentException(String.format("Can not read from uri %s Not a valid uri supplied", uri));
+ }
+ }
+
/**
* Liest einen Prüfling von der übergebenen URL. Es wird der Default-Prüfsummenalgorithmus zur Ermittlung der Prüfsumme
* genutzt.
- *
+ *
* @param url URL des Prüflings
* @return ein Prüf-Eingabe-Objekt
*/
@@ -130,14 +147,6 @@ public class InputFactory {
return read(url, DEFAULT_ALGORITH);
}
- public static Input read(final URI uri) {
- try {
- return read(uri.toURL(), DEFAULT_ALGORITH);
- } catch (final MalformedURLException e) {
- throw new IllegalArgumentException(String.format("Can not read from uri %s Not a valid uri supplied", uri));
- }
- }
-
/**
* Liest einen Prüfling von der übergebenen URL. Es wird ein definierter Algorithmis zur Ermittlung der Prüfsumme
* genutzt.
@@ -152,7 +161,7 @@ public class InputFactory {
try {
final URLConnection urlConnection = url.openConnection();
urlConnection.connect();
- } catch (IOException e) {
+ } catch (final IOException e) {
throw new IllegalArgumentException(MESSAGE_OPEN_STREAM_ERROR + url, e);
}
return new ResourceInput(url, url.getFile(), digestAlgorithm);
@@ -268,36 +277,8 @@ public class InputFactory {
* @return einen Prüfling in eingelesener Form
*/
public static Input read(final InputStream inputStream, final String name, final String digestAlgorithm) {
- return new InputFactory(digestAlgorithm).readStream(inputStream, name);
- }
-
- private Input readStream(final InputStream inputStream, final String name) {
- if (StringUtils.isNotBlank(name)) {
- log.debug("Generating hashcode for {} using {} algorithm", name, getAlgorithm());
- final MessageDigest digest = StreamHelper.createDigest(getAlgorithm());
- final byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
- try ( final BufferedInputStream bis = new BufferedInputStream(inputStream);
- final DigestInputStream dis = new DigestInputStream(bis, digest);
- final ByteArrayOutputStream out = new ByteArrayOutputStream() ) {
-
- // read the file and update the hash calculation
- int n;
- while (EOF != (n = dis.read(buffer))) {
- out.write(buffer, 0, n);
- }
- // get the hash value as byte array
- final byte[] hash = digest.digest();
- log.debug("Generated hashcode for {} is {}", name, DatatypeConverter.printHexBinary(hash));
- out.flush();
- final ByteArrayInput input = new ByteArrayInput(out.toByteArray(), name, digest.getAlgorithm());
- input.setHashCode(hash);
- return input;
- } catch (final IOException e) {
- throw new IllegalArgumentException(MESSAGE_OPEN_STREAM_ERROR + name, e);
- }
- } else {
- throw new IllegalArgumentException("Must supply a valid name/identifier for the input");
- }
+ checkNull(inputStream);
+ return read(new StreamSource(inputStream, name), digestAlgorithm);
}
}
diff --git a/src/main/java/de/kosit/validationtool/cmd/Daemon.java b/src/main/java/de/kosit/validationtool/cmd/Daemon.java
index a3ffe6a..560c039 100644
--- a/src/main/java/de/kosit/validationtool/cmd/Daemon.java
+++ b/src/main/java/de/kosit/validationtool/cmd/Daemon.java
@@ -30,7 +30,7 @@ import de.kosit.validationtool.api.CheckConfiguration;
import de.kosit.validationtool.api.InputFactory;
import de.kosit.validationtool.impl.DefaultCheck;
import de.kosit.validationtool.impl.ObjectFactory;
-import de.kosit.validationtool.impl.input.ByteArrayInput;
+import de.kosit.validationtool.impl.input.SourceInput;
import de.kosit.validationtool.model.scenarios.Scenarios;
/**
@@ -72,10 +72,9 @@ class Daemon {
final String requestMethod = httpExchange.getRequestMethod();
if (requestMethod.equals("POST")) {
final InputStream inputStream = httpExchange.getRequestBody();
- final ByteArrayInput serverInput = (ByteArrayInput) InputFactory.read(inputStream,
- "Prüfling" + counter.incrementAndGet());
+ final SourceInput serverInput = (SourceInput) InputFactory.read(inputStream, "Prüfling" + counter.incrementAndGet());
- if (serverInput.getLength() > 0) {
+ if (inputStream.available() > 0) {
writeOutputstreamArray(httpExchange, this.implemenation.check(serverInput));
} else {
writeError(httpExchange, 400, "XML-Inhalt erforderlich!");
From 8224690b6a76273b9f7d3ae71784a15d2739e507 Mon Sep 17 00:00:00 2001
From: "Andreas Penski (init)"
Date: Mon, 6 Jan 2020 12:09:17 +0100
Subject: [PATCH 004/306] #40 Fix NPE in Result.getReportDocument for malformed
xml input Compute correct Hashcode, when Input is malformed
---
.../impl/input/AbstractInput.java | 14 ++++++-
.../impl/input/SourceInput.java | 2 +-
.../impl/input/StreamHelper.java | 40 +++++++++++++++++++
.../validationtool/api/InputFactoryTest.java | 16 +-------
4 files changed, 55 insertions(+), 17 deletions(-)
diff --git a/src/main/java/de/kosit/validationtool/impl/input/AbstractInput.java b/src/main/java/de/kosit/validationtool/impl/input/AbstractInput.java
index e4e4a8f..c5c30aa 100644
--- a/src/main/java/de/kosit/validationtool/impl/input/AbstractInput.java
+++ b/src/main/java/de/kosit/validationtool/impl/input/AbstractInput.java
@@ -1,5 +1,8 @@
package de.kosit.validationtool.impl.input;
+import static de.kosit.validationtool.impl.input.StreamHelper.drain;
+
+import java.io.IOException;
import java.io.InputStream;
import lombok.Getter;
@@ -25,11 +28,20 @@ public abstract class AbstractInput implements Input, LazyReadInput {
@Override
public byte[] getHashCode() {
if (this.hashCode == null) {
- throw new IllegalStateException("Hashcode is not computed yet");
+ log.warn("Extra calculating hashcode. This is in-efficient in most cases");
+ computeHashcode();
}
return this.hashCode;
}
+ protected void computeHashcode() {
+ try {
+ drain(this);
+ } catch (final IOException e) {
+ log.error("Error extra computing hashcode", e);
+ }
+ }
+
protected InputStream wrap(final InputStream stream) {
InputStream result = stream;
if (!isHashcodeComputed()) {
diff --git a/src/main/java/de/kosit/validationtool/impl/input/SourceInput.java b/src/main/java/de/kosit/validationtool/impl/input/SourceInput.java
index ba27f90..8cc4a3d 100644
--- a/src/main/java/de/kosit/validationtool/impl/input/SourceInput.java
+++ b/src/main/java/de/kosit/validationtool/impl/input/SourceInput.java
@@ -57,7 +57,7 @@ public class SourceInput extends AbstractInput {
return wrap();
}
if (isConsumed()) {
- throw new IllegalStateException("A StreamSource can only read once");
+ throw new IllegalStateException("A SourceInput can only read once");
}
return this.source;
}
diff --git a/src/main/java/de/kosit/validationtool/impl/input/StreamHelper.java b/src/main/java/de/kosit/validationtool/impl/input/StreamHelper.java
index d364384..bd8de8a 100644
--- a/src/main/java/de/kosit/validationtool/impl/input/StreamHelper.java
+++ b/src/main/java/de/kosit/validationtool/impl/input/StreamHelper.java
@@ -7,8 +7,12 @@ import java.security.DigestInputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
+import javax.xml.transform.stream.StreamSource;
+
import org.apache.commons.io.input.CountingInputStream;
+import de.kosit.validationtool.api.Input;
+
/**
* Helper for stream handling.
*
@@ -56,6 +60,10 @@ public class StreamHelper {
}
}
+ private static final int EOF = -1;
+
+ private static final int DEFAULT_BUFFER_SIZE = 4096;
+
private StreamHelper() {
// hide
}
@@ -92,4 +100,36 @@ public class StreamHelper {
public static InputStream wrapDigesting(final LazyReadInput input, final InputStream stream, final String digestAlgorithm) {
return new DigestingInputStream(input, stream, createDigest(digestAlgorithm));
}
+
+ /**
+ * Drains the {@link Input} without further processing. This is useful to computing hashcode etc.
+ *
+ * @param input the input
+ * @return the input drained once
+ * @throws IOException on I/O errors
+ */
+ public static Input drain(final Input input) throws IOException {
+ final StreamSource s = (StreamSource) input.getSource();
+ try ( final InputStream stream = s.getInputStream() ) {
+ drain(stream);
+ }
+ return input;
+
+ }
+
+ /**
+ * Drains the {@link InputStream} without further processing. This is useful to computing hashcode etc.
+ *
+ * @param input the input
+ * @throws IOException on I/O errors
+ */
+ public static void drain(final InputStream input) throws IOException {
+ final byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
+
+ int n;
+ while (EOF != (n = input.read(buffer))) {
+ // nothing
+ }
+
+ }
}
diff --git a/src/test/java/de/kosit/validationtool/api/InputFactoryTest.java b/src/test/java/de/kosit/validationtool/api/InputFactoryTest.java
index 72d5990..3e5474f 100644
--- a/src/test/java/de/kosit/validationtool/api/InputFactoryTest.java
+++ b/src/test/java/de/kosit/validationtool/api/InputFactoryTest.java
@@ -19,6 +19,7 @@
package de.kosit.validationtool.api;
+import static de.kosit.validationtool.impl.input.StreamHelper.drain;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.ByteArrayInputStream;
@@ -51,9 +52,7 @@ public class InputFactoryTest {
private static URL NOT_EXISTING;
- private static final int EOF = -1;
- private static final int DEFAULT_BUFFER_SIZE = 4096;
static {
try {
@@ -83,20 +82,7 @@ public class InputFactoryTest {
assertThat(s1).isNotEqualTo(s3);
}
- private static Input drain(final Input input) throws IOException {
- final byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
- final StreamSource s = (StreamSource) input.getSource();
- try ( final InputStream stream = s.getInputStream() ) {
- int n;
- while (EOF != (n = stream.read(buffer))) {
- // nothing
- }
-
- }
- return input;
-
- }
@Test
public void testWrongAlgorithm() {
From 7786d309e29887d4972a02fd0d42d62b3b715ff5 Mon Sep 17 00:00:00 2001
From: "Andreas Penski (init)"
Date: Mon, 6 Jan 2020 13:38:18 +0100
Subject: [PATCH 005/306] (chore) cleanup after test
---
.../cmd/CommandlineApplicationTest.java | 54 +++++++++++++------
1 file changed, 37 insertions(+), 17 deletions(-)
diff --git a/src/test/java/de/kosit/validationtool/cmd/CommandlineApplicationTest.java b/src/test/java/de/kosit/validationtool/cmd/CommandlineApplicationTest.java
index eea1593..687841d 100644
--- a/src/test/java/de/kosit/validationtool/cmd/CommandlineApplicationTest.java
+++ b/src/test/java/de/kosit/validationtool/cmd/CommandlineApplicationTest.java
@@ -29,9 +29,12 @@ import java.nio.file.Paths;
import java.util.List;
import org.apache.commons.io.FileUtils;
+import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import lombok.extern.slf4j.Slf4j;
+
import de.kosit.validationtool.impl.Helper.Simple;
/**
@@ -39,17 +42,33 @@ import de.kosit.validationtool.impl.Helper.Simple;
*
* @author Andreas Penski
*/
+@Slf4j
public class CommandlineApplicationTest {
public static final String RESULT_OUTPUT = "Processing 1 object(s) completed";
private CommandLine commandLine;
+ private final Path output = Paths.get("target/test-output");
@Before
public void setup() throws IOException {
this.commandLine = new CommandLine();
this.commandLine.activate();
+ if (Files.exists(this.output)) {
+ FileUtils.deleteDirectory(this.output.toFile());
+ }
+ }
+
+ @After
+ public void cleanup() throws IOException {
+ Files.list(Paths.get("")).filter(p -> p.getFileName().toString().endsWith("-report.xml")).forEach(path -> {
+ try {
+ Files.delete(path);
+ } catch (final IOException e) {
+ log.error("Error deleting file", e);
+ }
+ });
}
@Test
@@ -108,30 +127,29 @@ public class CommandlineApplicationTest {
@Test
public void testValidMultipleInput() {
- final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-r", Paths.get(Simple.REPOSITORY).toString(),
- Paths.get(Simple.SIMPLE_VALID).toString(), Paths.get(Simple.FOO).toString() };
+ final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-o", this.output.toString(), "-r",
+ Paths.get(Simple.REPOSITORY).toString(), Paths.get(Simple.SIMPLE_VALID).toString(), Paths.get(Simple.FOO).toString() };
CommandLineApplication.mainProgram(args);
assertThat(this.commandLine.getErrorOutput()).contains("Processing 2 object(s) completed");
}
@Test
public void testValidDirectoryInput() {
- final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-r", Paths.get(Simple.REPOSITORY).toString(),
- Paths.get(Simple.EXAMPLES).toString() };
+ final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-o", this.output.toString(), "-r",
+ Paths.get(Simple.REPOSITORY).toString(), Paths.get(Simple.EXAMPLES).toString() };
CommandLineApplication.mainProgram(args);
assertThat(this.commandLine.getErrorOutput()).contains("Processing 5 object(s) completed");
}
@Test
public void testValidOutputConfiguration() throws IOException {
- final Path output = Paths.get("output");
- FileUtils.deleteDirectory(output.toFile());
- final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-o", output.getFileName().toString(), "-r",
+
+ final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-o", this.output.toString(), "-r",
Paths.get(Simple.REPOSITORY).toString(), Paths.get(Simple.SIMPLE_VALID).toString() };
CommandLineApplication.mainProgram(args);
assertThat(this.commandLine.getErrorOutput()).contains(RESULT_OUTPUT);
- assertThat(output).exists();
- assertThat(Files.list(output)).hasSize(1);
+ assertThat(this.output).exists();
+ assertThat(Files.list(this.output)).hasSize(1);
}
@Test
@@ -146,7 +164,7 @@ public class CommandlineApplicationTest {
public void testPrint() {
final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-p", "-r",
- Paths.get(Simple.REPOSITORY).toString(), Paths.get(Simple.SIMPLE_VALID).toString() };
+ Paths.get(Simple.REPOSITORY).toString(), "-o", this.output.toString(), Paths.get(Simple.SIMPLE_VALID).toString() };
CommandLineApplication.mainProgram(args);
assertThat(this.commandLine.getErrorOutput()).contains(RESULT_OUTPUT);
assertThat(this.commandLine.getOutputLines().get(0)).contains("");
@@ -154,18 +172,19 @@ public class CommandlineApplicationTest {
@Test
public void testHtmlExtraktion() throws IOException {
- final Path output = Files.createTempDirectory("pruef-tool-test");
- final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-h", "-o", output.toAbsolutePath().toString(),
+ final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-h", "-o",
+ this.output.toAbsolutePath().toString(),
"-r", Paths.get(Simple.REPOSITORY).toString(), Paths.get(Simple.SIMPLE_VALID).toString() };
CommandLineApplication.mainProgram(args);
assertThat(this.commandLine.getErrorOutput()).contains(RESULT_OUTPUT);
- assertThat(Files.list(output).filter(f -> f.toString().endsWith(".html")).count()).isGreaterThan(0);
+ assertThat(Files.list(this.output).filter(f -> f.toString().endsWith(".html")).count()).isGreaterThan(0);
}
@Test
- public void testAssertionsExtraktion() throws IOException {
+ public void testAssertionsExtraktion() {
final String[] args = new String[] { "-d", "-s", Paths.get(Simple.SCENARIOS).toString(), "-r",
- Paths.get(Simple.REPOSITORY).toString(), "-c", Paths.get(ASSERTIONS).toString(), Paths.get(Simple.REPOSITORY).toString(),
+ Paths.get(Simple.REPOSITORY).toString(), "-o", this.output.toString(), "-c", Paths.get(ASSERTIONS).toString(),
+ Paths.get(Simple.REPOSITORY).toString(),
Paths.get(Simple.SIMPLE_VALID).toString() };
CommandLineApplication.mainProgram(args);
assertThat(this.commandLine.getErrorOutput()).contains(RESULT_OUTPUT);
@@ -173,8 +192,9 @@ public class CommandlineApplicationTest {
}
@Test
- public void testDebugFlag() throws IOException {
- final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-r", "unknown", "-d",
+ public void testDebugFlag() {
+ final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-r", "unknown", "-o", this.output.toString(),
+ "-d",
Paths.get(ASSERTIONS).toString() };
CommandLineApplication.mainProgram(args);
assertThat(this.commandLine.getErrorOutput()).contains("at de.kosit.validationtool");
From 2bc35389e3d0c78559330f9e65fe5504d4092cbd Mon Sep 17 00:00:00 2001
From: "Andreas Penski (init)"
Date: Tue, 21 Jan 2020 09:02:18 +0100
Subject: [PATCH 006/306] (chore) keep dist zip
---
.gitlab-ci.yml | 1 +
1 file changed, 1 insertion(+)
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index dedc582..49ee7c6 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -86,6 +86,7 @@ build-java-11:
name: java-11
paths:
- target/*.jar
+ - target/*.zip
reports:
junit:
- target/surefire-reports/*.xml
From 0d7aeb5de7ba33ed62ea48ce1f931c737e9d6ee9 Mon Sep 17 00:00:00 2001
From: "Andreas Penski (init)"
Date: Fri, 24 Jan 2020 09:40:41 +0100
Subject: [PATCH 007/306] #41 Testing processing errors while running schema or
schematron validations
---
pom.xml | 8 ++-
.../impl/model/BaseScenario.java | 6 ++
.../impl/tasks/SchemaValidatorActionTest.java | 53 ++++++++---------
.../tasks/SchematronValidationActionTest.java | 58 +++++++++++++++++++
.../impl/tasks/TestBagBuilder.java | 49 ++++++++++++++++
5 files changed, 143 insertions(+), 31 deletions(-)
create mode 100644 src/test/java/de/kosit/validationtool/impl/tasks/SchematronValidationActionTest.java
create mode 100644 src/test/java/de/kosit/validationtool/impl/tasks/TestBagBuilder.java
diff --git a/pom.xml b/pom.xml
index 5667370..eb579b7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,6 +1,6 @@
-
+4.0.0KoSIT XML Prüftool Implementierung
@@ -117,6 +117,12 @@
3.3.0test
+
+ org.mockito
+ mockito-core
+ 3.2.4
+ test
+ de.kosit.validationtoolpackaged-test-scenarios
diff --git a/src/main/java/de/kosit/validationtool/impl/model/BaseScenario.java b/src/main/java/de/kosit/validationtool/impl/model/BaseScenario.java
index 71c723f..510f636 100644
--- a/src/main/java/de/kosit/validationtool/impl/model/BaseScenario.java
+++ b/src/main/java/de/kosit/validationtool/impl/model/BaseScenario.java
@@ -69,9 +69,15 @@ public abstract class BaseScenario {
private XPathExecutable matchExecutable;
private XPathExecutable acceptExecutable;
+
+ @Setter
private Schema schema;
+
+ @Setter
private List schematronValidations;
+
private ContentRepository repository;
+
private Transformation reportTransformation;
/**
diff --git a/src/test/java/de/kosit/validationtool/impl/tasks/SchemaValidatorActionTest.java b/src/test/java/de/kosit/validationtool/impl/tasks/SchemaValidatorActionTest.java
index c41d726..d720475 100644
--- a/src/test/java/de/kosit/validationtool/impl/tasks/SchemaValidatorActionTest.java
+++ b/src/test/java/de/kosit/validationtool/impl/tasks/SchemaValidatorActionTest.java
@@ -19,34 +19,36 @@
package de.kosit.validationtool.impl.tasks;
+import static de.kosit.validationtool.impl.tasks.TestBagBuilder.createBag;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.MalformedURLException;
-import java.net.URI;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
+import javax.xml.validation.Validator;
import org.junit.Before;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.xml.sax.SAXException;
import de.kosit.validationtool.api.Input;
import de.kosit.validationtool.api.InputFactory;
import de.kosit.validationtool.impl.ContentRepository;
-import de.kosit.validationtool.impl.Helper;
import de.kosit.validationtool.impl.Helper.Simple;
import de.kosit.validationtool.impl.ObjectFactory;
import de.kosit.validationtool.impl.input.SourceInput;
-import de.kosit.validationtool.impl.model.Result;
import de.kosit.validationtool.impl.tasks.CheckAction.Bag;
-import de.kosit.validationtool.model.reportInput.CreateReportInput;
-import de.kosit.validationtool.model.scenarios.ResourceType;
import de.kosit.validationtool.model.scenarios.ScenarioType;
-import de.kosit.validationtool.model.scenarios.ValidateWithXmlSchema;
/**
* Tests die {@link SchemaValidationAction}.
@@ -59,15 +61,11 @@ public class SchemaValidatorActionTest {
private SchemaValidationAction service;
- private ContentRepository repository;
-
@Before
public void setup() {
this.service = new SchemaValidationAction();
- this.repository = new ContentRepository(ObjectFactory.createProcessor(), Simple.REPOSITORY);
}
-
@Test
public void testSimple() throws MalformedURLException {
final CheckAction.Bag bag = createBag(InputFactory.read(Simple.SIMPLE_VALID.toURL()));
@@ -83,33 +81,15 @@ public class SchemaValidatorActionTest {
final CheckAction.Bag bag = createBag(input);
this.service.check(bag);
assertThat(bag.getSchemaValidationResult().isValid()).isFalse();
- bag.getSchemaValidationResult().getErrors().forEach(e->{
+ bag.getSchemaValidationResult().getErrors().forEach(e -> {
assertThat(e.getRowNumber()).isGreaterThan(0);
assertThat(e.getColumnNumber()).isGreaterThan(0);
});
}
- private Bag createBag(final Input input) {
- final Bag bag = new Bag(input, new CreateReportInput());
- bag.setScenarioSelectionResult(new Result<>(createScenario(Helper.Simple.getSchemaLocation())));
- return bag;
- }
-
- private ScenarioType createScenario(final URI schemafile) {
- final ScenarioType t = new ScenarioType();
- final ValidateWithXmlSchema v = new ValidateWithXmlSchema();
- final ResourceType r = new ResourceType();
- r.setLocation(schemafile.getRawPath());
- r.setName("invoice");
- v.getResource().add(r);
- t.setValidateWithXmlSchema(v);
- t.initialize(this.repository, true);
- return t;
- }
-
@Test
public void testSchemaReferences() {
- final Schema reportInputSchema = this.repository.getReportInputSchema();
+ final Schema reportInputSchema = new ContentRepository(ObjectFactory.createProcessor(), Simple.REPOSITORY).getReportInputSchema();
assertThat(reportInputSchema).isNotNull();
}
@@ -171,4 +151,17 @@ public class SchemaValidatorActionTest {
}
}
+ @Test
+ public void testProcessingError() throws IOException, SAXException {
+ final CheckAction.Bag bag = createBag(InputFactory.read(Simple.SIMPLE_VALID.toURL()));
+ final ScenarioType scenario = bag.getScenarioSelectionResult().getObject();
+ final Schema schema = mock(Schema.class);
+ final Validator validator = mock(Validator.class);
+ when(schema.newValidator()).thenReturn(validator);
+ doThrow(SAXException.class).when(validator).validate(any());
+ scenario.setSchema(schema);
+ this.service.check(bag);
+ assertThat(bag.getReportInput().getProcessingError().getError()).isNotEmpty();
+ }
+
}
diff --git a/src/test/java/de/kosit/validationtool/impl/tasks/SchematronValidationActionTest.java b/src/test/java/de/kosit/validationtool/impl/tasks/SchematronValidationActionTest.java
new file mode 100644
index 0000000..6a9a868
--- /dev/null
+++ b/src/test/java/de/kosit/validationtool/impl/tasks/SchematronValidationActionTest.java
@@ -0,0 +1,58 @@
+package de.kosit.validationtool.impl.tasks;
+
+import static de.kosit.validationtool.impl.tasks.TestBagBuilder.createBag;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.util.Collections;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import de.kosit.validationtool.api.InputFactory;
+import de.kosit.validationtool.impl.ContentRepository;
+import de.kosit.validationtool.impl.ConversionService;
+import de.kosit.validationtool.impl.Helper.Simple;
+import de.kosit.validationtool.impl.ObjectFactory;
+import de.kosit.validationtool.impl.model.BaseScenario.Transformation;
+import de.kosit.validationtool.model.scenarios.ResourceType;
+import de.kosit.validationtool.model.scenarios.ScenarioType;
+
+import net.sf.saxon.s9api.SaxonApiException;
+import net.sf.saxon.s9api.XsltExecutable;
+import net.sf.saxon.s9api.XsltTransformer;
+
+/**
+ * Tests {@link SchematronValidationAction}.
+ *
+ * @author Andreas Penski
+ */
+public class SchematronValidationActionTest {
+
+ private SchematronValidationAction action;
+
+ @Before
+ public void setup() {
+ final ContentRepository repository = new ContentRepository(ObjectFactory.createProcessor(), Simple.REPOSITORY);
+ this.action = new SchematronValidationAction(repository, new ConversionService());
+ }
+
+ @Test
+ public void testProcessingError() throws IOException, SaxonApiException {
+ final CheckAction.Bag bag = createBag(InputFactory.read(Simple.SIMPLE_VALID.toURL()), true);
+
+ final ScenarioType scenario = bag.getScenarioSelectionResult().getObject();
+ final XsltExecutable exec = mock(XsltExecutable.class);
+ final XsltTransformer transformer = mock(XsltTransformer.class);
+ doThrow(new SaxonApiException("invalid")).when(transformer).transform();
+ when(exec.load()).thenReturn(transformer);
+ final ResourceType resourceType = new ResourceType();
+ resourceType.setName("invalid internal");
+ scenario.setSchematronValidations(Collections.singletonList(new Transformation(exec, resourceType)));
+ this.action.check(bag);
+ assertThat(bag.getReportInput().getProcessingError().getError()).isNotEmpty();
+ }
+}
diff --git a/src/test/java/de/kosit/validationtool/impl/tasks/TestBagBuilder.java b/src/test/java/de/kosit/validationtool/impl/tasks/TestBagBuilder.java
new file mode 100644
index 0000000..2594786
--- /dev/null
+++ b/src/test/java/de/kosit/validationtool/impl/tasks/TestBagBuilder.java
@@ -0,0 +1,49 @@
+package de.kosit.validationtool.impl.tasks;
+
+import java.net.URI;
+
+import de.kosit.validationtool.api.Input;
+import de.kosit.validationtool.impl.ContentRepository;
+import de.kosit.validationtool.impl.Helper;
+import de.kosit.validationtool.impl.Helper.Simple;
+import de.kosit.validationtool.impl.ObjectFactory;
+import de.kosit.validationtool.impl.model.Result;
+import de.kosit.validationtool.impl.tasks.CheckAction.Bag;
+import de.kosit.validationtool.model.reportInput.CreateReportInput;
+import de.kosit.validationtool.model.scenarios.ResourceType;
+import de.kosit.validationtool.model.scenarios.ScenarioType;
+import de.kosit.validationtool.model.scenarios.ValidateWithXmlSchema;
+
+/**
+ * Utilities for creating test objects.
+ *
+ * @author Andreas Penski
+ */
+public class TestBagBuilder {
+
+ public static Bag createBag(final Input input) {
+ return createBag(input, false);
+ }
+
+ public static Bag createBag(final Input input, final boolean parse) {
+ final Bag bag = new Bag(input, new CreateReportInput());
+ if (parse) {
+ bag.setParserResult(DocumentParseAction.parseDocument(bag.getInput()));
+ }
+ bag.setScenarioSelectionResult(new Result<>(createScenario(Helper.Simple.getSchemaLocation())));
+ return bag;
+ }
+
+ private static ScenarioType createScenario(final URI schemafile) {
+ final ContentRepository repository = new ContentRepository(ObjectFactory.createProcessor(), Simple.REPOSITORY);
+ final ScenarioType t = new ScenarioType();
+ final ValidateWithXmlSchema v = new ValidateWithXmlSchema();
+ final ResourceType r = new ResourceType();
+ r.setLocation(schemafile.getRawPath());
+ r.setName("invoice");
+ v.getResource().add(r);
+ t.setValidateWithXmlSchema(v);
+ t.initialize(repository, true);
+ return t;
+ }
+}
From 69372a9d5db0b4ebc2d5ace18fd6a592465069ec Mon Sep 17 00:00:00 2001
From: "Andreas Penski (init)"
Date: Fri, 24 Jan 2020 10:10:24 +0100
Subject: [PATCH 008/306] #41 Testing processing errors while running schema or
schematron validations ignore fields on base class during marshalling
---
.../de/kosit/validationtool/impl/model/BaseScenario.java | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/src/main/java/de/kosit/validationtool/impl/model/BaseScenario.java b/src/main/java/de/kosit/validationtool/impl/model/BaseScenario.java
index 510f636..b3f60c9 100644
--- a/src/main/java/de/kosit/validationtool/impl/model/BaseScenario.java
+++ b/src/main/java/de/kosit/validationtool/impl/model/BaseScenario.java
@@ -25,6 +25,9 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlTransient;
import javax.xml.validation.Schema;
import org.apache.commons.lang3.NotImplementedException;
@@ -51,6 +54,7 @@ import net.sf.saxon.s9api.XsltExecutable;
*
* @author Andreas Penski
*/
+@XmlAccessorType(XmlAccessType.NONE)
public abstract class BaseScenario {
/**
@@ -71,6 +75,7 @@ public abstract class BaseScenario {
private XPathExecutable acceptExecutable;
@Setter
+ @XmlTransient
private Schema schema;
@Setter
From 435c428c5f8a793c44d45e7ac4540d18a9c86ea6 Mon Sep 17 00:00:00 2001
From: "Andreas Penski (init)"
Date: Fri, 24 Jan 2020 10:42:25 +0100
Subject: [PATCH 009/306] (chore) default (invalid) match for fallback scenario
---
.../java/de/kosit/validationtool/impl/ScenarioRepository.java | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/main/java/de/kosit/validationtool/impl/ScenarioRepository.java b/src/main/java/de/kosit/validationtool/impl/ScenarioRepository.java
index 4903976..e360a23 100644
--- a/src/main/java/de/kosit/validationtool/impl/ScenarioRepository.java
+++ b/src/main/java/de/kosit/validationtool/impl/ScenarioRepository.java
@@ -165,6 +165,7 @@ public class ScenarioRepository {
private ScenarioType createFallback() {
final ScenarioType t = new ScenarioType();
t.setName("Fallback-Scenario");
+ t.setMatch("count(/)<0");
final CreateReportType reportType = new CreateReportType();
reportType.setResource(this.scenarios.getNoScenarioReport().getResource());
t.initialize(this.repository, true);
From 3ad1f449faa1799c88eac7427f866ff44e4d68df Mon Sep 17 00:00:00 2001
From: "Andreas Penski (init)"
Date: Mon, 27 Jan 2020 14:52:52 +0100
Subject: [PATCH 010/306] (chore) cleanup test
---
.../validationtool/api/InputFactoryTest.java | 20 ++-----------------
1 file changed, 2 insertions(+), 18 deletions(-)
diff --git a/src/test/java/de/kosit/validationtool/api/InputFactoryTest.java b/src/test/java/de/kosit/validationtool/api/InputFactoryTest.java
index 3e5474f..3fc6122 100644
--- a/src/test/java/de/kosit/validationtool/api/InputFactoryTest.java
+++ b/src/test/java/de/kosit/validationtool/api/InputFactoryTest.java
@@ -27,7 +27,6 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
-import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Paths;
@@ -50,18 +49,6 @@ public class InputFactoryTest {
public static final String SOME_VALUE = "some value";
- private static URL NOT_EXISTING;
-
-
-
- static {
- try {
- NOT_EXISTING = new URL("file://localhost/somefile.text");
- } catch (final MalformedURLException e) {
- // just ignore;
- }
- }
-
@Rule
public ExpectedException expectedException = ExpectedException.none();
@@ -82,8 +69,6 @@ public class InputFactoryTest {
assertThat(s1).isNotEqualTo(s3);
}
-
-
@Test
public void testWrongAlgorithm() {
this.expectedException.expect(IllegalArgumentException.class);
@@ -111,7 +96,7 @@ public class InputFactoryTest {
@Test
public void testNullStream() {
this.expectedException.expect(IllegalArgumentException.class);
- final Input input = InputFactory.read((InputStream)null, SOME_VALUE);
+ final Input input = InputFactory.read((InputStream) null, SOME_VALUE);
}
@Test
@@ -175,8 +160,7 @@ public class InputFactoryTest {
@Test
public void testUnexistingInput() {
this.expectedException.expect(IllegalArgumentException.class);
- InputFactory.read(NOT_EXISTING);
+ InputFactory.read(Simple.NOT_EXISTING);
}
-
}
From f54259e3edef83702f84f5ea8acd25937a81d787 Mon Sep 17 00:00:00 2001
From: "Andreas Penski (init)"
Date: Thu, 20 Feb 2020 15:49:21 +0100
Subject: [PATCH 011/306] [maven-release-plugin] prepare for next development
iteration
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 448b5b8..9ad9dc0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
KoSIT XML Prüftool Implementierungde.kosit
- 1.1.3-SNAPSHOT
+ 1.1.4-SNAPSHOTvalidationtoolKoSIT XML Validator against XSD and Schematron based on defined scenarios.
From 586e2b4c80926359841368c128cf656893204984 Mon Sep 17 00:00:00 2001
From: "Andreas Penski (init)"
Date: Thu, 20 Feb 2020 16:05:34 +0100
Subject: [PATCH 012/306] (chore) changelog for next release corrected
---
CHANGELOG.md | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 28a080a..0645a8a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,13 @@ All notable changes to the Schematron Rules and this project will be documented
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
+### next version
+#Added
+- Support java.xml.transform.Source/java.xml.transform.StreamSource as Input
+
+#Changed
+- Inputs are NOT read into memory (e.g. Byte-Array) prior processing within the validtor. This reduces memory consumption.
+
## 1.1.3
### Fixed
- XXE vulnerability when reading xml documents with Saxon [#44](https://github.com/itplr-kosit/validator/issues/44)
@@ -13,13 +20,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- NPE in Result.getReportDocument for malformed xml input
-#Added
-- Support java.xml.transform.Source/java.xml.transform.StreamSource as Input
-
-
-#Changed
-- Inputs are NOT read into memory (e.g. Byte-Array) prior processing within the validtor. This reduces memory consumption.
-
## 1.1.1
### Added
- Convenience method for accessing information about well-formedness in Result
From c6176d2109d7312a10e9250f9bdc105faee8c416 Mon Sep 17 00:00:00 2001
From: "Andreas Penski (init)"
Date: Mon, 24 Feb 2020 09:59:32 +0100
Subject: [PATCH 013/306] (chore) scope 'test' test-scenario jar
---
pom.xml | 1 +
1 file changed, 1 insertion(+)
diff --git a/pom.xml b/pom.xml
index 9ad9dc0..7f74ebe 100644
--- a/pom.xml
+++ b/pom.xml
@@ -122,6 +122,7 @@
de.kosit.validationtoolpackaged-test-scenarios1.0.0
+ test
From ea3edd8495c34bf99f03912b507bb24a3c26cb01 Mon Sep 17 00:00:00 2001
From: Renzo Kottmann
Date: Thu, 5 Mar 2020 15:23:54 +0100
Subject: [PATCH 014/306] Fixed typos and structure of CHANGELOG.md
---
CHANGELOG.md | 25 ++++++++++++++++++++-----
1 file changed, 20 insertions(+), 5 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0645a8a..195e912 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,34 +1,48 @@
# Changelog
-All notable changes to the Schematron Rules and this project will be documented in this file.
+All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
-### next version
-#Added
+
+## next version (unreleased)
+
+# Added
+
- Support java.xml.transform.Source/java.xml.transform.StreamSource as Input
-#Changed
-- Inputs are NOT read into memory (e.g. Byte-Array) prior processing within the validtor. This reduces memory consumption.
+# Changed
+
+- Inputs are NOT read into memory (e.g. Byte-Array) prior processing within the validator. This reduces memory consumption.
## 1.1.3
+
### Fixed
+
- XXE vulnerability when reading xml documents with Saxon [#44](https://github.com/itplr-kosit/validator/issues/44)
- validator unintentionally stopped when schematron processing has errors. See [#41](https://github.com/itplr-kosit/validator/issues/41).
## 1.1.2
+
### Fixed
+
- NPE in Result.getReportDocument for malformed xml input
## 1.1.1
+
### Added
+
- Convenience method for accessing information about well-formedness in Result
- Convenience method for accessing information about schema validation result in Result
+
### Fixed
+
- NPE when validating non-XML files
## 1.1.0
+
### Added
+
- Enhanced API-Usage e.g. return _Result_ object with processing information
- Support loading scenarios and content from a JAR-File
- Simple Daemon-Mode exposing validation functionality via http
@@ -36,6 +50,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Documentation in `docs` folder
### Changed
+
- Use s9api (e.g. XdmNode) internally for loading and holding xml objects (further memory optimization)
- Builds with java 8 and >= 11
- Packages for java8 and java >= 11 (with jaxb included)
From e8ff6765a4985000342c10d4fc6720e0abe881aa Mon Sep 17 00:00:00 2001
From: Renzo Kottmann
Date: Wed, 18 Mar 2020 15:51:46 +0100
Subject: [PATCH 015/306] Translate to English
---
.../kosit/validationtool/api/AcceptRecommendation.java | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/main/java/de/kosit/validationtool/api/AcceptRecommendation.java b/src/main/java/de/kosit/validationtool/api/AcceptRecommendation.java
index 3d07933..c491201 100644
--- a/src/main/java/de/kosit/validationtool/api/AcceptRecommendation.java
+++ b/src/main/java/de/kosit/validationtool/api/AcceptRecommendation.java
@@ -1,21 +1,21 @@
package de.kosit.validationtool.api;
/**
- * Status der Empfehlung.
+ * Tri-state describtion of a Recommendation.
*/
public enum AcceptRecommendation {
/**
- * Nicht definiert, weil eine Evaluierung nicht durchgeführt wurde, oder nicht durchgeführt werden konnte.
+ * The evaluation of the overall validation could not be computed.
*/
UNDEFINED,
/**
- * Das Dokument ist gemäß Konfiguration valide und kann akzeptiert werden.
+ * Recommendation is to accept input based on the evaluation of the overall validation.
*/
ACCEPTABLE,
/**
- * Das Dokuemnt ist gemäß Konfiguration invalide und sollte NICHT akzeptiert werden.
+ * Recommendation is to reject input based on the evaluation of the overall validation.
*/
REJECT
-}
\ No newline at end of file
+}
From 7999fa179022c2b6730b7ad074e850479c9b99d9 Mon Sep 17 00:00:00 2001
From: Renzo Kottmann
Date: Wed, 18 Mar 2020 15:52:37 +0100
Subject: [PATCH 016/306] Translate getAcceptRecommendation javadoc to English
---
.../java/de/kosit/validationtool/api/Result.java | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/src/main/java/de/kosit/validationtool/api/Result.java b/src/main/java/de/kosit/validationtool/api/Result.java
index 11dfa20..5581e29 100644
--- a/src/main/java/de/kosit/validationtool/api/Result.java
+++ b/src/main/java/de/kosit/validationtool/api/Result.java
@@ -9,7 +9,7 @@ import net.sf.saxon.s9api.XdmNode;
/**
* API Rückgabe Objekt des Ergebnisses des Validierungsprozesses.
- *
+ *
* @author Andreas Penski
*/
public interface Result {
@@ -17,7 +17,7 @@ public interface Result {
/**
* Zeigt an, ob die Verarbeitung durch den Validator erfolgreich durchlaufen wurde. Diese Funktion macht ausdrücklich
* keine Aussage über die zur Akzeptanz.
- *
+ *
* @return true, wenn die Verarbeitung komplett und erfolgreich durchlaufen wurde
* @see #getAcceptRecommendation()
*/
@@ -25,7 +25,7 @@ public interface Result {
/**
* Gibt eine Liste mit Verarbeitungsfehlermeldungen zurück.
- *
+ *
* @return Liste mit Fehlermeldungen
*/
List getProcessingErrors();
@@ -36,7 +36,9 @@ public interface Result {
XdmNode getReport();
/**
- * Das evaluierte Ergebnis.
+ * The Recommendation based on the evaluation of this Result.
+ *
+ * @return AcceptRecommendation
*/
AcceptRecommendation getAcceptRecommendation();
@@ -62,21 +64,21 @@ public interface Result {
/**
* Liefert die Ergebnisse der Schematron-Prüfungen, in der Reihenfolge der Szenario-Konfiguration.
- *
+ *
* @return Liste mit Schematron-Ergebnissen
*/
List getSchematronResult();
/**
* Liefert ein true, wenn keine Schema-Violations vorhanden sind.
- *
+ *
* @return true wenn Schema-valide
*/
boolean isSchemaValid();
/**
* Liefert ein true, wenn der Prüfling eine well-formed XML-Datei ist.
- *
+ *
* @return true wenn well-formed
*/
boolean isWellformed();
From aa53eaea7311078f747055a43a812f759245c54f Mon Sep 17 00:00:00 2001
From: Renzo Kottmann
Date: Wed, 18 Mar 2020 18:07:47 +0100
Subject: [PATCH 017/306] Add a little englisch foc to acceptMatch Element
---
src/main/model/xsd/scenarios.xsd | 81 ++++++++++++++++----------------
1 file changed, 40 insertions(+), 41 deletions(-)
diff --git a/src/main/model/xsd/scenarios.xsd b/src/main/model/xsd/scenarios.xsd
index 1b2f9d9..2f41a1f 100644
--- a/src/main/model/xsd/scenarios.xsd
+++ b/src/main/model/xsd/scenarios.xsd
@@ -1,4 +1,4 @@
-
+
-
+
-
-
-
-
-
-
+
+
+
+
+
+
-
+
-
+
-
+
-
+
-
+
-
+
@@ -68,72 +66,73 @@
-
-
-
+
+
+
-
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
+
+
-
+
-
-
+
+
-
+
-
+
-
+
-
+
-
-
-
-
+
+
+
+
-
+
From fa1dbe75fdfba8ed8e9179a8611ce9a922ecd17c Mon Sep 17 00:00:00 2001
From: Renzo Kottmann
Date: Wed, 18 Mar 2020 18:16:35 +0100
Subject: [PATCH 018/306] Add accept documentation about acceptRecommendation
---
docs/api.md | 18 ++++++++++++++++++
docs/architecture.md | 10 ++++++++--
2 files changed, 26 insertions(+), 2 deletions(-)
diff --git a/docs/api.md b/docs/api.md
index 848741c..e537f83 100644
--- a/docs/api.md
+++ b/docs/api.md
@@ -89,3 +89,21 @@ Initializing all XML artifacts and XSLT-executables is expensive. The `Check` in
The only input `de.kosit.validationtool.api.Input` which can be created by various methods of `de.kosit.validationtool.api.InputFactory`.
The `InputFactory` calculates a hash sum for each Input which is also written to the Report. _SHA-256_ from the JDK is the default algorithm. It can be changed using the `read`-methods of `InputFactory`.
+
+## Accept Recommendation and Accept Match
+
+A tri-state Object `AcceptRecommendation` can be retrieved from the `Result` using `getAcceptRecommendation()`.
+
+The three defined states are:
+
+1. `UNDEFINED` i.e. the evaluation of the overall validation could not be computed.
+2. `ACCEPTABLE` i.e. the recommendation is to accept input based on the evaluation of the overall validation.
+3. `REJECT` i.e. the recommendation is to reject input based on the evaluation of the overall validation.
+
+By default it is `UNDEFINED`.
+
+### Accept Match in Scenario Configuration
+
+For your own configuration you can add an `acceptMatch` element in each scenario. It can contain in XPATH expression over your own defined `Report` to compute a boolean. An XPATH expression evaluating to true will lead to an `ACCEPTABLE` amd otherwise to a `REJECT` recommendation.
+
+This allows to have own control over what validation result is to be considered acceptable for your own application context.
diff --git a/docs/architecture.md b/docs/architecture.md
index fc9b2a2..18eb16c 100644
--- a/docs/architecture.md
+++ b/docs/architecture.md
@@ -13,9 +13,9 @@ the validation and generates a report in XML format. This report is then the inp
The validator reports valid/invalid, a configuration reports acceptance/rejection!
-## General process
+## General default process
-The general process is like this:
+The general process is like this (the default is defined in `DefaultCheck`):
```mermaid
@@ -30,6 +30,7 @@ sequenceDiagram
e->>e: validate Schematron
e->>e: create Validator Report
e->>+c: execute configuration report generator
+ e->>e: Compute Recommendation
```
@@ -50,3 +51,8 @@ sequenceDiagram
6. *execute configuration report generator*
The Validator will search for the XSLT as configured in scenario.xml and execute it with the Validator Report as input
+7. compute Recommendation
+
+ In case a scenario contains an `acceptMatch` element with an XPATH expression, this expression will be executed.
+
+ In case the XPATH returns `true`, the recommendation will be set to `ACCEPT` else to `REJECT`. In case no such XPATH is defined it is `UNDEFINED`.
From bd60ddc41d02caed98883a0ab2c275883926aac3 Mon Sep 17 00:00:00 2001
From: Renzo Kottmann
Date: Wed, 18 Mar 2020 15:51:46 +0100
Subject: [PATCH 019/306] Translate to English
---
.../kosit/validationtool/api/AcceptRecommendation.java | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/main/java/de/kosit/validationtool/api/AcceptRecommendation.java b/src/main/java/de/kosit/validationtool/api/AcceptRecommendation.java
index 3d07933..c491201 100644
--- a/src/main/java/de/kosit/validationtool/api/AcceptRecommendation.java
+++ b/src/main/java/de/kosit/validationtool/api/AcceptRecommendation.java
@@ -1,21 +1,21 @@
package de.kosit.validationtool.api;
/**
- * Status der Empfehlung.
+ * Tri-state describtion of a Recommendation.
*/
public enum AcceptRecommendation {
/**
- * Nicht definiert, weil eine Evaluierung nicht durchgeführt wurde, oder nicht durchgeführt werden konnte.
+ * The evaluation of the overall validation could not be computed.
*/
UNDEFINED,
/**
- * Das Dokument ist gemäß Konfiguration valide und kann akzeptiert werden.
+ * Recommendation is to accept input based on the evaluation of the overall validation.
*/
ACCEPTABLE,
/**
- * Das Dokuemnt ist gemäß Konfiguration invalide und sollte NICHT akzeptiert werden.
+ * Recommendation is to reject input based on the evaluation of the overall validation.
*/
REJECT
-}
\ No newline at end of file
+}
From 13acb9ff7e774aa9caf7449e136423772d5be774 Mon Sep 17 00:00:00 2001
From: Renzo Kottmann
Date: Wed, 18 Mar 2020 15:52:37 +0100
Subject: [PATCH 020/306] Translate getAcceptRecommendation javadoc to English
---
.../java/de/kosit/validationtool/api/Result.java | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/src/main/java/de/kosit/validationtool/api/Result.java b/src/main/java/de/kosit/validationtool/api/Result.java
index 11dfa20..5581e29 100644
--- a/src/main/java/de/kosit/validationtool/api/Result.java
+++ b/src/main/java/de/kosit/validationtool/api/Result.java
@@ -9,7 +9,7 @@ import net.sf.saxon.s9api.XdmNode;
/**
* API Rückgabe Objekt des Ergebnisses des Validierungsprozesses.
- *
+ *
* @author Andreas Penski
*/
public interface Result {
@@ -17,7 +17,7 @@ public interface Result {
/**
* Zeigt an, ob die Verarbeitung durch den Validator erfolgreich durchlaufen wurde. Diese Funktion macht ausdrücklich
* keine Aussage über die zur Akzeptanz.
- *
+ *
* @return true, wenn die Verarbeitung komplett und erfolgreich durchlaufen wurde
* @see #getAcceptRecommendation()
*/
@@ -25,7 +25,7 @@ public interface Result {
/**
* Gibt eine Liste mit Verarbeitungsfehlermeldungen zurück.
- *
+ *
* @return Liste mit Fehlermeldungen
*/
List getProcessingErrors();
@@ -36,7 +36,9 @@ public interface Result {
XdmNode getReport();
/**
- * Das evaluierte Ergebnis.
+ * The Recommendation based on the evaluation of this Result.
+ *
+ * @return AcceptRecommendation
*/
AcceptRecommendation getAcceptRecommendation();
@@ -62,21 +64,21 @@ public interface Result {
/**
* Liefert die Ergebnisse der Schematron-Prüfungen, in der Reihenfolge der Szenario-Konfiguration.
- *
+ *
* @return Liste mit Schematron-Ergebnissen
*/
List getSchematronResult();
/**
* Liefert ein true, wenn keine Schema-Violations vorhanden sind.
- *
+ *
* @return true wenn Schema-valide
*/
boolean isSchemaValid();
/**
* Liefert ein true, wenn der Prüfling eine well-formed XML-Datei ist.
- *
+ *
* @return true wenn well-formed
*/
boolean isWellformed();
From a12ff356d8f6a18571dd2907a12b6dcc2ab338db Mon Sep 17 00:00:00 2001
From: Renzo Kottmann
Date: Wed, 18 Mar 2020 18:07:47 +0100
Subject: [PATCH 021/306] Add a little englisch foc to acceptMatch Element
---
src/main/model/xsd/scenarios.xsd | 81 ++++++++++++++++----------------
1 file changed, 40 insertions(+), 41 deletions(-)
diff --git a/src/main/model/xsd/scenarios.xsd b/src/main/model/xsd/scenarios.xsd
index 1b2f9d9..2f41a1f 100644
--- a/src/main/model/xsd/scenarios.xsd
+++ b/src/main/model/xsd/scenarios.xsd
@@ -1,4 +1,4 @@
-
+
-
+
-
-
-
-
-
-
+
+
+
+
+
+
-
+
-
+
-
+
-
+
-
+
-
+
@@ -68,72 +66,73 @@
-
-
-
+
+
+
-
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
+
+
-
+
-
-
+
+
-
+
-
+
-
+
-
+
-
-
-
-
+
+
+
+
-
+
From 84ef377324aa4414ca6b0ab5e8a27e4d426f6307 Mon Sep 17 00:00:00 2001
From: Renzo Kottmann
Date: Wed, 18 Mar 2020 18:16:35 +0100
Subject: [PATCH 022/306] Add accept documentation about acceptRecommendation
---
docs/api.md | 18 ++++++++++++++++++
docs/architecture.md | 10 ++++++++--
2 files changed, 26 insertions(+), 2 deletions(-)
diff --git a/docs/api.md b/docs/api.md
index 848741c..e537f83 100644
--- a/docs/api.md
+++ b/docs/api.md
@@ -89,3 +89,21 @@ Initializing all XML artifacts and XSLT-executables is expensive. The `Check` in
The only input `de.kosit.validationtool.api.Input` which can be created by various methods of `de.kosit.validationtool.api.InputFactory`.
The `InputFactory` calculates a hash sum for each Input which is also written to the Report. _SHA-256_ from the JDK is the default algorithm. It can be changed using the `read`-methods of `InputFactory`.
+
+## Accept Recommendation and Accept Match
+
+A tri-state Object `AcceptRecommendation` can be retrieved from the `Result` using `getAcceptRecommendation()`.
+
+The three defined states are:
+
+1. `UNDEFINED` i.e. the evaluation of the overall validation could not be computed.
+2. `ACCEPTABLE` i.e. the recommendation is to accept input based on the evaluation of the overall validation.
+3. `REJECT` i.e. the recommendation is to reject input based on the evaluation of the overall validation.
+
+By default it is `UNDEFINED`.
+
+### Accept Match in Scenario Configuration
+
+For your own configuration you can add an `acceptMatch` element in each scenario. It can contain in XPATH expression over your own defined `Report` to compute a boolean. An XPATH expression evaluating to true will lead to an `ACCEPTABLE` amd otherwise to a `REJECT` recommendation.
+
+This allows to have own control over what validation result is to be considered acceptable for your own application context.
diff --git a/docs/architecture.md b/docs/architecture.md
index fc9b2a2..18eb16c 100644
--- a/docs/architecture.md
+++ b/docs/architecture.md
@@ -13,9 +13,9 @@ the validation and generates a report in XML format. This report is then the inp
The validator reports valid/invalid, a configuration reports acceptance/rejection!
-## General process
+## General default process
-The general process is like this:
+The general process is like this (the default is defined in `DefaultCheck`):
```mermaid
@@ -30,6 +30,7 @@ sequenceDiagram
e->>e: validate Schematron
e->>e: create Validator Report
e->>+c: execute configuration report generator
+ e->>e: Compute Recommendation
```
@@ -50,3 +51,8 @@ sequenceDiagram
6. *execute configuration report generator*
The Validator will search for the XSLT as configured in scenario.xml and execute it with the Validator Report as input
+7. compute Recommendation
+
+ In case a scenario contains an `acceptMatch` element with an XPATH expression, this expression will be executed.
+
+ In case the XPATH returns `true`, the recommendation will be set to `ACCEPT` else to `REJECT`. In case no such XPATH is defined it is `UNDEFINED`.
From ab341feece2be9e73b06963d73dc2ce0e7258dd8 Mon Sep 17 00:00:00 2001
From: "Andreas Penski (init)"
Date: Fri, 20 Mar 2020 14:22:33 +0100
Subject: [PATCH 023/306] (fix) Handling acceptMatch correctly, compute the
result based on schema and schematron on absence of "acceptMath"
---
.../impl/model/BaseScenario.java | 4 +
.../impl/tasks/ComputeAcceptanceAction.java | 58 ++++++--
.../tasks/ComputeAcceptanceActionTest.java | 138 ++++++++++++++++++
3 files changed, 186 insertions(+), 14 deletions(-)
create mode 100644 src/test/java/de/kosit/validationtool/impl/tasks/ComputeAcceptanceActionTest.java
diff --git a/src/main/java/de/kosit/validationtool/impl/model/BaseScenario.java b/src/main/java/de/kosit/validationtool/impl/model/BaseScenario.java
index 71c723f..b983c61 100644
--- a/src/main/java/de/kosit/validationtool/impl/model/BaseScenario.java
+++ b/src/main/java/de/kosit/validationtool/impl/model/BaseScenario.java
@@ -69,9 +69,13 @@ public abstract class BaseScenario {
private XPathExecutable matchExecutable;
private XPathExecutable acceptExecutable;
+
private Schema schema;
+
private List schematronValidations;
+
private ContentRepository repository;
+
private Transformation reportTransformation;
/**
diff --git a/src/main/java/de/kosit/validationtool/impl/tasks/ComputeAcceptanceAction.java b/src/main/java/de/kosit/validationtool/impl/tasks/ComputeAcceptanceAction.java
index e24ba4c..f4c5ca2 100644
--- a/src/main/java/de/kosit/validationtool/impl/tasks/ComputeAcceptanceAction.java
+++ b/src/main/java/de/kosit/validationtool/impl/tasks/ComputeAcceptanceAction.java
@@ -2,15 +2,19 @@ package de.kosit.validationtool.impl.tasks;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
+import org.oclc.purl.dsdl.svrl.FailedAssert;
+
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import de.kosit.validationtool.api.AcceptRecommendation;
+import net.sf.saxon.s9api.SaxonApiException;
import net.sf.saxon.s9api.XPathSelector;
/**
- * Berechnet die Akzeptanz-Empfehlung gemäß konfigurierten 'acceptMatch' des aktuellen Szenarios.
+ * Computes a {@link AcceptRecommendation} for this instance. This is either based on an 'acceptMatch'-configuration of
+ * the active scenario or based on overall evaluation about schema and semantic (schematron) correctness of the
*
* @author Andreas Penski
*/
@@ -20,23 +24,49 @@ public class ComputeAcceptanceAction implements CheckAction {
@Override
public void check(final Bag results) {
- final String acceptMatch = results.getScenarioSelectionResult().getObject().getAcceptMatch();
- if (isNotBlank(acceptMatch)) {
-
- try {
-
- final XPathSelector selector = results.getScenarioSelectionResult().getObject().getAcceptSelector();
- selector.setContextItem(results.getReport());
- results.setAcceptStatus(selector.effectiveBooleanValue() ? AcceptRecommendation.ACCEPTABLE : AcceptRecommendation.REJECT);
- } catch (final Exception e) {
- log.error("Fehler bei Evaluierung des Accept-Status: {}", e.getMessage(), e);
+ if (preCondtionsMatch(results)) {
+ final String acceptMatch = results.getScenarioSelectionResult().getObject().getAcceptMatch();
+ if (results.getSchemaValidationResult().isValid() && isNotBlank(acceptMatch)) {
+ evaluateAcceptanceMatch(results);
+ } else {
+ evaluateSchemaAndSchematron(results);
}
+ } else {
+ results.setAcceptStatus(AcceptRecommendation.REJECT);
}
}
- @Override
- public boolean isSkipped(final Bag results) {
- return results.getReport() == null;
+ private void evaluateSchemaAndSchematron(final Bag results) {
+ if (results.getSchemaValidationResult().isValid() && isSchematronValid(results)) {
+ results.setAcceptStatus(AcceptRecommendation.ACCEPTABLE);
+ } else {
+ results.setAcceptStatus(AcceptRecommendation.REJECT);
+ }
+ }
+
+ private boolean isSchematronValid(final Bag results) {
+ return !hasSchematronErrors(results);
+ }
+
+ private boolean hasSchematronErrors(final Bag results) {
+ return results.getReportInput().getValidationResultsSchematron().stream().map(e -> e.getResults().getSchematronOutput())
+ .flatMap(e -> e.getActivePatternAndFiredRuleAndFailedAssert().stream()).anyMatch(FailedAssert.class::isInstance);
+ }
+
+ private static void evaluateAcceptanceMatch(final Bag results) {
+ try {
+ final XPathSelector selector = results.getScenarioSelectionResult().getObject().getAcceptSelector();
+ selector.setContextItem(results.getReport());
+ results.setAcceptStatus(selector.effectiveBooleanValue() ? AcceptRecommendation.ACCEPTABLE : AcceptRecommendation.REJECT);
+ } catch (final SaxonApiException e) {
+ final String msg = "Error evaluating accept recommendation: %s";
+ log.error(msg);
+ results.addProcessingError(msg);
+ }
+ }
+
+ private static boolean preCondtionsMatch(final Bag results) {
+ return results.getReport() != null && results.getSchemaValidationResult() != null && results.getScenarioSelectionResult() != null;
}
}
diff --git a/src/test/java/de/kosit/validationtool/impl/tasks/ComputeAcceptanceActionTest.java b/src/test/java/de/kosit/validationtool/impl/tasks/ComputeAcceptanceActionTest.java
new file mode 100644
index 0000000..5798467
--- /dev/null
+++ b/src/test/java/de/kosit/validationtool/impl/tasks/ComputeAcceptanceActionTest.java
@@ -0,0 +1,138 @@
+package de.kosit.validationtool.impl.tasks;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+import org.junit.Test;
+import org.oclc.purl.dsdl.svrl.FailedAssert;
+import org.oclc.purl.dsdl.svrl.SchematronOutput;
+
+import de.kosit.validationtool.api.AcceptRecommendation;
+import de.kosit.validationtool.api.InputFactory;
+import de.kosit.validationtool.impl.ContentRepository;
+import de.kosit.validationtool.impl.Helper.Simple;
+import de.kosit.validationtool.impl.ObjectFactory;
+import de.kosit.validationtool.impl.model.Result;
+import de.kosit.validationtool.impl.tasks.CheckAction.Bag;
+import de.kosit.validationtool.model.reportInput.CreateReportInput;
+import de.kosit.validationtool.model.reportInput.ValidationResultsSchematron;
+import de.kosit.validationtool.model.reportInput.ValidationResultsSchematron.Results;
+import de.kosit.validationtool.model.reportInput.XMLSyntaxError;
+import de.kosit.validationtool.model.scenarios.ScenarioType;
+
+import net.sf.saxon.s9api.XdmNode;
+
+/**
+ * Tests the 'acceptMatch' functionality.
+ *
+ * @author Andreas Penski
+ */
+public class ComputeAcceptanceActionTest {
+
+ private final ComputeAcceptanceAction action = new ComputeAcceptanceAction();
+
+ @Test
+ public void simpleTest() {
+ final Bag bag = createBag(true, true);
+ assertThat(bag.getAcceptStatus()).isEqualTo(AcceptRecommendation.UNDEFINED);
+ this.action.check(bag);
+ assertThat(bag.getAcceptStatus()).isEqualTo(AcceptRecommendation.ACCEPTABLE);
+ }
+
+ @Test
+ public void testSchemaFailed() {
+ final Bag bag = createBag(false, true);
+ this.action.check(bag);
+ assertThat(bag.getAcceptStatus()).isEqualTo(AcceptRecommendation.REJECT);
+ }
+
+ @Test
+ public void testSchematronFailed() {
+ final Bag bag = createBag(true, false);
+ this.action.check(bag);
+ assertThat(bag.getAcceptStatus()).isEqualTo(AcceptRecommendation.REJECT);
+ }
+
+ @Test
+ public void testValidAcceptMatch() {
+ final Bag bag = createBag(true, true);
+ bag.getScenarioSelectionResult().getObject().setAcceptMatch("count(//doesnotExist) = 0");
+ this.action.check(bag);
+ assertThat(bag.getAcceptStatus()).isEqualTo(AcceptRecommendation.ACCEPTABLE);
+ }
+
+ @Test
+ public void testAcceptMatchNotSatisfied() {
+ final Bag bag = createBag(true, true);
+ bag.getScenarioSelectionResult().getObject().setAcceptMatch("count(//doesnotExist) = 1");
+ this.action.check(bag);
+ assertThat(bag.getAcceptStatus()).isEqualTo(AcceptRecommendation.REJECT);
+ }
+
+ @Test
+ public void testValidAcceptMatchOnSchematronFailed() {
+ final Bag bag = createBag(true, false);
+ bag.getScenarioSelectionResult().getObject().setAcceptMatch("count(//doesnotExist) = 0");
+ this.action.check(bag);
+ assertThat(bag.getAcceptStatus()).isEqualTo(AcceptRecommendation.ACCEPTABLE);
+ }
+
+ @Test
+ public void testValidAcceptMatchOnSchemaFailed() {
+ final Bag bag = createBag(false, true);
+ bag.getScenarioSelectionResult().getObject().setAcceptMatch("count(//doesnotExist) = 0");
+ this.action.check(bag);
+ assertThat(bag.getAcceptStatus()).isEqualTo(AcceptRecommendation.REJECT);
+ }
+
+ @Test
+ public void testMissingSchemaCheck() {
+ final Bag bag = createBag(null, Collections.emptyList());
+ this.action.check(bag);
+ assertThat(bag.getAcceptStatus()).isEqualTo(AcceptRecommendation.REJECT);
+ }
+
+ @Test
+ public void testMissingReport() {
+ final Bag bag = createBag(false, true);
+ bag.setReport(null);
+ this.action.check(bag);
+ assertThat(bag.getAcceptStatus()).isEqualTo(AcceptRecommendation.REJECT);
+ }
+
+ private static Bag createBag(final boolean schemaValid, final boolean schematronValid) {
+ final Result schemaResult = schemaValid ? new Result<>(true)
+ : new Result<>(Collections.singletonList(new XMLSyntaxError()));
+ final List schematronResult = schematronValid ? Collections.emptyList() : createSchematronError();
+ return createBag(schemaResult, schematronResult);
+ }
+
+ private static List createSchematronError() {
+ final ValidationResultsSchematron v = new ValidationResultsSchematron();
+ final SchematronOutput out = new SchematronOutput();
+ final FailedAssert f = new FailedAssert();
+ out.getActivePatternAndFiredRuleAndFailedAssert().add(f);
+ final Results r = new Results();
+ r.setSchematronOutput(out);
+ v.setResults(r);
+ return Collections.singletonList(v);
+ }
+
+ private static Bag createBag(final Result schemaResult,
+ final Collection schematronResult) {
+ final ScenarioType t = new ScenarioType();
+ t.initialize(new ContentRepository(ObjectFactory.createProcessor(), Simple.REPOSITORY), true);
+ final CreateReportInput reportInput = new CreateReportInput();
+ reportInput.getValidationResultsSchematron().addAll(schematronResult);
+ final Bag b = new Bag(InputFactory.read("".getBytes(), "someCheck"), reportInput);
+ final Result parseREsult = DocumentParseAction.parseDocument(b.getInput());
+ b.setReport(parseREsult.getObject());
+ b.setParserResult(parseREsult);
+ b.setSchemaValidationResult(schemaResult);
+ b.setScenarioSelectionResult(new Result<>(t));
+ return b;
+ }
+}
From e313bc6328aecf7ef68f29a729e86696c20db756 Mon Sep 17 00:00:00 2001
From: "Andreas Penski (init)"
Date: Fri, 20 Mar 2020 14:42:03 +0100
Subject: [PATCH 024/306] (fix) tests regarding acceptance computation
---
.../java/de/kosit/validationtool/impl/DefaultCheckTest.java | 3 ++-
...{SimpleScenarioCheck.java => SimpleScenarioCheckTest.java} | 4 ++--
2 files changed, 4 insertions(+), 3 deletions(-)
rename src/test/java/de/kosit/validationtool/impl/{SimpleScenarioCheck.java => SimpleScenarioCheckTest.java} (96%)
diff --git a/src/test/java/de/kosit/validationtool/impl/DefaultCheckTest.java b/src/test/java/de/kosit/validationtool/impl/DefaultCheckTest.java
index 0b6edc6..461c024 100644
--- a/src/test/java/de/kosit/validationtool/impl/DefaultCheckTest.java
+++ b/src/test/java/de/kosit/validationtool/impl/DefaultCheckTest.java
@@ -68,8 +68,9 @@ public class DefaultCheckTest {
final Result doc = this.implementation.checkInput(read(VALID_EXAMPLE));
assertThat(doc).isNotNull();
assertThat(doc.getReport()).isNotNull();
+ // happy case has schematron errors !??
assertThat(doc.isAcceptable()).isFalse();
- assertThat(doc.getAcceptRecommendation()).isEqualTo(AcceptRecommendation.UNDEFINED);
+ assertThat(doc.getAcceptRecommendation()).isEqualTo(AcceptRecommendation.REJECT);
}
@Test
diff --git a/src/test/java/de/kosit/validationtool/impl/SimpleScenarioCheck.java b/src/test/java/de/kosit/validationtool/impl/SimpleScenarioCheckTest.java
similarity index 96%
rename from src/test/java/de/kosit/validationtool/impl/SimpleScenarioCheck.java
rename to src/test/java/de/kosit/validationtool/impl/SimpleScenarioCheckTest.java
index 1444646..3ac63a2 100644
--- a/src/test/java/de/kosit/validationtool/impl/SimpleScenarioCheck.java
+++ b/src/test/java/de/kosit/validationtool/impl/SimpleScenarioCheckTest.java
@@ -19,7 +19,7 @@ import de.kosit.validationtool.impl.Helper.Simple;
*
* @author Andreas Penski
*/
-public class SimpleScenarioCheck {
+public class SimpleScenarioCheckTest {
private DefaultCheck implementation;
@@ -56,7 +56,7 @@ public class SimpleScenarioCheck {
public void testWithoutAcceptMatch() throws MalformedURLException {
final Result result = this.implementation.checkInput(InputFactory.read(Simple.FOO.toURL()));
assertThat(result).isNotNull();
- assertThat(result.getAcceptRecommendation()).isEqualTo(AcceptRecommendation.UNDEFINED);
+ assertThat(result.getAcceptRecommendation()).isEqualTo(AcceptRecommendation.ACCEPTABLE);
}
}
From 2a9cdc551a0834229ea5c1f053c9a51b18926dc2 Mon Sep 17 00:00:00 2001
From: "Andreas Penski (init)"
Date: Fri, 20 Mar 2020 15:13:44 +0100
Subject: [PATCH 025/306] (chore) Extends Result-API, provide more information
about schematron results
---
.../java/de/kosit/validationtool/api/Result.java | 15 +++++++++++++++
.../kosit/validationtool/impl/DefaultResult.java | 9 ++++++++-
2 files changed, 23 insertions(+), 1 deletion(-)
diff --git a/src/main/java/de/kosit/validationtool/api/Result.java b/src/main/java/de/kosit/validationtool/api/Result.java
index 5581e29..dcbe19d 100644
--- a/src/main/java/de/kosit/validationtool/api/Result.java
+++ b/src/main/java/de/kosit/validationtool/api/Result.java
@@ -2,6 +2,7 @@ package de.kosit.validationtool.api;
import java.util.List;
+import org.oclc.purl.dsdl.svrl.FailedAssert;
import org.oclc.purl.dsdl.svrl.SchematronOutput;
import org.w3c.dom.Document;
@@ -69,6 +70,13 @@ public interface Result {
*/
List getSchematronResult();
+ /**
+ * Returns {@link org.oclc.purl.dsdl.svrl.FailedAssert FailedAsserts} of a schematron evaluation.
+ *
+ * @return list of {@link org.oclc.purl.dsdl.svrl.FailedAssert FailedAsserts}, if any, empty list otherwise
+ */
+ List getFailedAsserts();
+
/**
* Liefert ein true, wenn keine Schema-Violations vorhanden sind.
*
@@ -82,4 +90,11 @@ public interface Result {
* @return true wenn well-formed
*/
boolean isWellformed();
+
+ /**
+ * Returns true, if schematron has been checked and the result does not contain any {@link FailedAssert FailedAsserts}.
+ *
+ * @return true, if valid
+ */
+ boolean isSchematronValid();
}
diff --git a/src/main/java/de/kosit/validationtool/impl/DefaultResult.java b/src/main/java/de/kosit/validationtool/impl/DefaultResult.java
index b878cee..e8be8ac 100644
--- a/src/main/java/de/kosit/validationtool/impl/DefaultResult.java
+++ b/src/main/java/de/kosit/validationtool/impl/DefaultResult.java
@@ -127,12 +127,19 @@ public class DefaultResult implements Result {
*
* @return die {@link FailedAssert}
*/
+ @Override
public List getFailedAsserts() {
return filterSchematronResult(FailedAssert.class);
}
private List filterSchematronResult(final Class type) {
- return getSchematronResult().stream().filter(type::isInstance).map(type::cast).collect(Collectors.toList());
+ return getSchematronResult() != null
+ ? getSchematronResult().stream().filter(type::isInstance).map(type::cast).collect(Collectors.toList())
+ : Collections.emptyList();
}
+ @Override
+ public boolean isSchematronValid() {
+ return getSchematronResult() != null && getFailedAsserts().isEmpty();
+ }
}
From 554a6f080ae8e9339cab8f4c9bdb32e16bfbe3d9 Mon Sep 17 00:00:00 2001
From: "Andreas Penski (init)"
Date: Fri, 20 Mar 2020 16:21:49 +0100
Subject: [PATCH 026/306] (chore) changelog documenation of api changes
---
CHANGELOG.md | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e4c211c..cc4fdd3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,17 @@ All notable changes to the Schematron Rules and this project will be documented
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
+## 1.2.0 (unreleased)
+### Added
+- Provide access to schematron result through Result.java
+ - *Result#getFailedAsserts()* returns a list of failed asserts found by schematron
+ - *Result#isSchematronValid()* convinience access to evaluate whether schematron was processed without any *FailedAsserts*
+### Changed
+- *getAcceptRecommendation()* does not _only_ work when _acceptMatch_ is configured in the scenario
+ - schema correct is a precondion, of the checked instance is not valid, this evaluates to _REJECTED_
+ - if _acceptMatch_ is configured, the result is based on the boolean result of the xpath expression evaluated against the generated report
+ - if *no* _acceptMatch_ is configured, the result is based on evaluation of schema and schematron correctnes
+
## 1.1.3
### Fixed
- XXE vulnerability when reading xml documents with Saxon [#44](https://github.com/itplr-kosit/validator/issues/44)
From fc419495e967e6ebd750d39a9b509293203a4ea1 Mon Sep 17 00:00:00 2001
From: "Andreas Penski (init)"
Date: Fri, 20 Mar 2020 16:31:12 +0100
Subject: [PATCH 027/306] (chore) changelog for next release corrected
---
CHANGELOG.md | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index cc4fdd3..7b860f1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -13,7 +13,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- *getAcceptRecommendation()* does not _only_ work when _acceptMatch_ is configured in the scenario
- schema correct is a precondion, of the checked instance is not valid, this evaluates to _REJECTED_
- if _acceptMatch_ is configured, the result is based on the boolean result of the xpath expression evaluated against the generated report
- - if *no* _acceptMatch_ is configured, the result is based on evaluation of schema and schematron correctnes
+ - if *no* _acceptMatch_ is configured, the result is based on evaluation of schema and schematron correctness
+ - _UNDEFINED_ is only returned, when processing is stopped somehow
+- *isAcceptable()* can no evaluate to true, when no _acceptMatch_ is configured (see above)
## 1.1.3
### Fixed
From 1790d301b63e363c3af40582ae83d98ae02e460e Mon Sep 17 00:00:00 2001
From: "Andreas Penski (init)"
Date: Mon, 23 Mar 2020 11:27:17 +0100
Subject: [PATCH 028/306] (fix) acceptMatch tests work with new test
environment
---
.../java/de/kosit/validationtool/impl/DefaultCheckTest.java | 5 ++---
src/test/resources/examples/simple/input/foo.xml | 1 +
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/test/java/de/kosit/validationtool/impl/DefaultCheckTest.java b/src/test/java/de/kosit/validationtool/impl/DefaultCheckTest.java
index 3298176..aa1376b 100644
--- a/src/test/java/de/kosit/validationtool/impl/DefaultCheckTest.java
+++ b/src/test/java/de/kosit/validationtool/impl/DefaultCheckTest.java
@@ -74,9 +74,8 @@ public class DefaultCheckTest {
final Result doc = this.implementation.checkInput(read(Simple.FOO));
assertThat(doc).isNotNull();
assertThat(doc.getReport()).isNotNull();
- // happy case has schematron errors !??
- assertThat(doc.isAcceptable()).isFalse();
- assertThat(doc.getAcceptRecommendation()).isEqualTo(AcceptRecommendation.REJECT);
+ assertThat(doc.isAcceptable()).isTrue();
+ assertThat(doc.getAcceptRecommendation()).isEqualTo(AcceptRecommendation.ACCEPTABLE);
}
@Test
diff --git a/src/test/resources/examples/simple/input/foo.xml b/src/test/resources/examples/simple/input/foo.xml
index b84fe4f..7c22b1f 100644
--- a/src/test/resources/examples/simple/input/foo.xml
+++ b/src/test/resources/examples/simple/input/foo.xml
@@ -2,4 +2,5 @@
asldkfj
+
\ No newline at end of file
From 65ed94560237f9de07ce43a7dd4792f1fbdcf20a Mon Sep 17 00:00:00 2001
From: "Andreas Penski (init)"
Date: Mon, 23 Mar 2020 11:57:52 +0100
Subject: [PATCH 029/306] (chore) adopt new test infrastructure
---
.../tasks/ComputeAcceptanceActionTest.java | 48 +-----------------
.../impl/tasks/TestBagBuilder.java | 50 ++++++++++++++++++-
2 files changed, 50 insertions(+), 48 deletions(-)
diff --git a/src/test/java/de/kosit/validationtool/impl/tasks/ComputeAcceptanceActionTest.java b/src/test/java/de/kosit/validationtool/impl/tasks/ComputeAcceptanceActionTest.java
index 5798467..851b4ed 100644
--- a/src/test/java/de/kosit/validationtool/impl/tasks/ComputeAcceptanceActionTest.java
+++ b/src/test/java/de/kosit/validationtool/impl/tasks/ComputeAcceptanceActionTest.java
@@ -1,29 +1,14 @@
package de.kosit.validationtool.impl.tasks;
+import static de.kosit.validationtool.impl.tasks.TestBagBuilder.createBag;
import static org.assertj.core.api.Assertions.assertThat;
-import java.util.Collection;
import java.util.Collections;
-import java.util.List;
import org.junit.Test;
-import org.oclc.purl.dsdl.svrl.FailedAssert;
-import org.oclc.purl.dsdl.svrl.SchematronOutput;
import de.kosit.validationtool.api.AcceptRecommendation;
-import de.kosit.validationtool.api.InputFactory;
-import de.kosit.validationtool.impl.ContentRepository;
-import de.kosit.validationtool.impl.Helper.Simple;
-import de.kosit.validationtool.impl.ObjectFactory;
-import de.kosit.validationtool.impl.model.Result;
import de.kosit.validationtool.impl.tasks.CheckAction.Bag;
-import de.kosit.validationtool.model.reportInput.CreateReportInput;
-import de.kosit.validationtool.model.reportInput.ValidationResultsSchematron;
-import de.kosit.validationtool.model.reportInput.ValidationResultsSchematron.Results;
-import de.kosit.validationtool.model.reportInput.XMLSyntaxError;
-import de.kosit.validationtool.model.scenarios.ScenarioType;
-
-import net.sf.saxon.s9api.XdmNode;
/**
* Tests the 'acceptMatch' functionality.
@@ -103,36 +88,5 @@ public class ComputeAcceptanceActionTest {
assertThat(bag.getAcceptStatus()).isEqualTo(AcceptRecommendation.REJECT);
}
- private static Bag createBag(final boolean schemaValid, final boolean schematronValid) {
- final Result schemaResult = schemaValid ? new Result<>(true)
- : new Result<>(Collections.singletonList(new XMLSyntaxError()));
- final List schematronResult = schematronValid ? Collections.emptyList() : createSchematronError();
- return createBag(schemaResult, schematronResult);
- }
- private static List createSchematronError() {
- final ValidationResultsSchematron v = new ValidationResultsSchematron();
- final SchematronOutput out = new SchematronOutput();
- final FailedAssert f = new FailedAssert();
- out.getActivePatternAndFiredRuleAndFailedAssert().add(f);
- final Results r = new Results();
- r.setSchematronOutput(out);
- v.setResults(r);
- return Collections.singletonList(v);
- }
-
- private static Bag createBag(final Result schemaResult,
- final Collection schematronResult) {
- final ScenarioType t = new ScenarioType();
- t.initialize(new ContentRepository(ObjectFactory.createProcessor(), Simple.REPOSITORY), true);
- final CreateReportInput reportInput = new CreateReportInput();
- reportInput.getValidationResultsSchematron().addAll(schematronResult);
- final Bag b = new Bag(InputFactory.read("".getBytes(), "someCheck"), reportInput);
- final Result parseREsult = DocumentParseAction.parseDocument(b.getInput());
- b.setReport(parseREsult.getObject());
- b.setParserResult(parseREsult);
- b.setSchemaValidationResult(schemaResult);
- b.setScenarioSelectionResult(new Result<>(t));
- return b;
- }
}
diff --git a/src/test/java/de/kosit/validationtool/impl/tasks/TestBagBuilder.java b/src/test/java/de/kosit/validationtool/impl/tasks/TestBagBuilder.java
index 2594786..0626a66 100644
--- a/src/test/java/de/kosit/validationtool/impl/tasks/TestBagBuilder.java
+++ b/src/test/java/de/kosit/validationtool/impl/tasks/TestBagBuilder.java
@@ -1,8 +1,15 @@
package de.kosit.validationtool.impl.tasks;
import java.net.URI;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+import org.oclc.purl.dsdl.svrl.FailedAssert;
+import org.oclc.purl.dsdl.svrl.SchematronOutput;
import de.kosit.validationtool.api.Input;
+import de.kosit.validationtool.api.InputFactory;
import de.kosit.validationtool.impl.ContentRepository;
import de.kosit.validationtool.impl.Helper;
import de.kosit.validationtool.impl.Helper.Simple;
@@ -10,10 +17,15 @@ import de.kosit.validationtool.impl.ObjectFactory;
import de.kosit.validationtool.impl.model.Result;
import de.kosit.validationtool.impl.tasks.CheckAction.Bag;
import de.kosit.validationtool.model.reportInput.CreateReportInput;
+import de.kosit.validationtool.model.reportInput.ValidationResultsSchematron;
+import de.kosit.validationtool.model.reportInput.ValidationResultsSchematron.Results;
+import de.kosit.validationtool.model.reportInput.XMLSyntaxError;
import de.kosit.validationtool.model.scenarios.ResourceType;
import de.kosit.validationtool.model.scenarios.ScenarioType;
import de.kosit.validationtool.model.scenarios.ValidateWithXmlSchema;
+import net.sf.saxon.s9api.XdmNode;
+
/**
* Utilities for creating test objects.
*
@@ -26,7 +38,11 @@ public class TestBagBuilder {
}
public static Bag createBag(final Input input, final boolean parse) {
- final Bag bag = new Bag(input, new CreateReportInput());
+ return createBag(input, parse, new CreateReportInput());
+ }
+
+ public static Bag createBag(final Input input, final boolean parse, final CreateReportInput reportInput) {
+ final Bag bag = new Bag(input, reportInput);
if (parse) {
bag.setParserResult(DocumentParseAction.parseDocument(bag.getInput()));
}
@@ -46,4 +62,36 @@ public class TestBagBuilder {
t.initialize(repository, true);
return t;
}
+
+ private static XdmNode createReport() {
+ return DocumentParseAction.parseDocument(InputFactory.read("xml".getBytes(), "someXml")).getObject();
+ }
+
+ static Bag createBag(final boolean schemaValid, final boolean schematronValid) {
+ final Result schemaResult = schemaValid ? new Result<>(true)
+ : new Result<>(Collections.singletonList(new XMLSyntaxError()));
+ final List schematronResult = schematronValid ? Collections.emptyList() : createSchematronError();
+ return createBag(schemaResult, schematronResult);
+ }
+
+ private static List createSchematronError() {
+ final ValidationResultsSchematron v = new ValidationResultsSchematron();
+ final SchematronOutput out = new SchematronOutput();
+ final FailedAssert f = new FailedAssert();
+ out.getActivePatternAndFiredRuleAndFailedAssert().add(f);
+ final Results r = new Results();
+ r.setSchematronOutput(out);
+ v.setResults(r);
+ return Collections.singletonList(v);
+ }
+
+ static Bag createBag(final Result schemaResult,
+ final Collection schematronResult) {
+ final CreateReportInput reportInput = new CreateReportInput();
+ reportInput.getValidationResultsSchematron().addAll(schematronResult);
+ final Bag b = createBag(InputFactory.read("".getBytes(), "someCheck"), true, reportInput);
+ b.setSchemaValidationResult(schemaResult);
+ b.setReport(createReport());
+ return b;
+ }
}
From 245d7d4cac64d225c9b3574b2b469b88216cadce Mon Sep 17 00:00:00 2001
From: "Andreas Penski (init)"
Date: Mon, 23 Mar 2020 13:22:38 +0100
Subject: [PATCH 030/306] (chore) Integration Testing acceptMatch functionality
---
.../cmd/CommandlineApplicationTest.java | 2 +-
.../validationtool/impl/DefaultCheckTest.java | 18 +++++++++++++++---
.../de/kosit/validationtool/impl/Helper.java | 2 ++
.../resources/examples/simple/input/foo.xml | 4 +++-
.../examples/simple/input/withManualReject.xml | 8 ++++++++
.../resources/examples/simple/scenarios.xml | 2 +-
6 files changed, 30 insertions(+), 6 deletions(-)
create mode 100644 src/test/resources/examples/simple/input/withManualReject.xml
diff --git a/src/test/java/de/kosit/validationtool/cmd/CommandlineApplicationTest.java b/src/test/java/de/kosit/validationtool/cmd/CommandlineApplicationTest.java
index 687841d..1207a1a 100644
--- a/src/test/java/de/kosit/validationtool/cmd/CommandlineApplicationTest.java
+++ b/src/test/java/de/kosit/validationtool/cmd/CommandlineApplicationTest.java
@@ -138,7 +138,7 @@ public class CommandlineApplicationTest {
final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-o", this.output.toString(), "-r",
Paths.get(Simple.REPOSITORY).toString(), Paths.get(Simple.EXAMPLES).toString() };
CommandLineApplication.mainProgram(args);
- assertThat(this.commandLine.getErrorOutput()).contains("Processing 5 object(s) completed");
+ assertThat(this.commandLine.getErrorOutput()).contains("Processing 6 object(s) completed");
}
@Test
diff --git a/src/test/java/de/kosit/validationtool/impl/DefaultCheckTest.java b/src/test/java/de/kosit/validationtool/impl/DefaultCheckTest.java
index aa1376b..624c8a2 100644
--- a/src/test/java/de/kosit/validationtool/impl/DefaultCheckTest.java
+++ b/src/test/java/de/kosit/validationtool/impl/DefaultCheckTest.java
@@ -22,10 +22,10 @@ package de.kosit.validationtool.impl;
import static de.kosit.validationtool.api.InputFactory.read;
import static de.kosit.validationtool.impl.Helper.Simple.GARBAGE;
import static de.kosit.validationtool.impl.Helper.Simple.NOT_WELLFORMED;
+import static de.kosit.validationtool.impl.Helper.Simple.REJECTED;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.File;
-import java.net.URISyntaxException;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
@@ -54,7 +54,7 @@ public class DefaultCheckTest {
private DefaultCheck implementation;
@Before
- public void setup() throws URISyntaxException {
+ public void setup() {
final CheckConfiguration d = new CheckConfiguration(Simple.SCENARIOS);
d.setScenarioRepository(new File(Simple.REPOSITORY).toURI());
this.implementation = new DefaultCheck(d);
@@ -130,7 +130,19 @@ public class DefaultCheckTest {
assertThat(result.getAcceptRecommendation()).isEqualTo(AcceptRecommendation.REJECT);
assertThat(result.getReport()).isNotNull();
assertThat(result.getReportDocument()).isNotNull();
- System.out.println(Helper.serialize(result.getReportDocument()));
+ }
+
+ @Test
+ public void testRejectAcceptMatch() {
+ final Result result = this.implementation.checkInput(read(REJECTED));
+ assertThat(result).isNotNull();
+ assertThat(result.isWellformed()).isTrue();
+ assertThat(result.isSchemaValid()).isTrue();
+ assertThat(result.isProcessingSuccessful()).isTrue();
+ assertThat(result.getAcceptRecommendation()).isEqualTo(AcceptRecommendation.REJECT);
+ assertThat(result.isAcceptable()).isFalse();
+ assertThat(result.getReport()).isNotNull();
+ assertThat(result.getReportDocument()).isNotNull();
}
}
diff --git a/src/test/java/de/kosit/validationtool/impl/Helper.java b/src/test/java/de/kosit/validationtool/impl/Helper.java
index f0e913d..1d50fc4 100644
--- a/src/test/java/de/kosit/validationtool/impl/Helper.java
+++ b/src/test/java/de/kosit/validationtool/impl/Helper.java
@@ -57,6 +57,8 @@ public class Helper {
public static final URI FOO = Simple.ROOT.resolve("input/foo.xml");
+ public static final URI REJECTED = Simple.ROOT.resolve("input/withManualReject.xml");
+
public static final URI SCENARIOS = ROOT.resolve("scenarios.xml");
public static final URI REPOSITORY = ROOT.resolve("repository/");
diff --git a/src/test/resources/examples/simple/input/foo.xml b/src/test/resources/examples/simple/input/foo.xml
index 7c22b1f..7122648 100644
--- a/src/test/resources/examples/simple/input/foo.xml
+++ b/src/test/resources/examples/simple/input/foo.xml
@@ -2,5 +2,7 @@
asldkfj
-
+
+
+
\ No newline at end of file
diff --git a/src/test/resources/examples/simple/input/withManualReject.xml b/src/test/resources/examples/simple/input/withManualReject.xml
new file mode 100644
index 0000000..ed81f6d
--- /dev/null
+++ b/src/test/resources/examples/simple/input/withManualReject.xml
@@ -0,0 +1,8 @@
+
+
+
+ asldkfj
+
+ directly transferred, so this is part of the report
+
+
\ No newline at end of file
diff --git a/src/test/resources/examples/simple/scenarios.xml b/src/test/resources/examples/simple/scenarios.xml
index 47e5ec8..3a99296 100644
--- a/src/test/resources/examples/simple/scenarios.xml
+++ b/src/test/resources/examples/simple/scenarios.xml
@@ -47,7 +47,7 @@
report.xsl
- count(//cri:xmlSyntaxError) = 0
+ count(//test:rejected) = 0
From 982b8fd79f0c05e9274a2ab1dc3f089f84447ee8 Mon Sep 17 00:00:00 2001
From: "Andreas Penski (init)"
Date: Mon, 23 Mar 2020 13:31:06 +0100
Subject: [PATCH 031/306] (chore) reduce test objects, reuse simple stuff
---
.../cmd/PrintReportActionTest.java | 28 +-
.../resources/examples/results/report.xml | 330 ------------------
2 files changed, 14 insertions(+), 344 deletions(-)
delete mode 100644 src/test/resources/examples/results/report.xml
diff --git a/src/test/java/de/kosit/validationtool/cmd/PrintReportActionTest.java b/src/test/java/de/kosit/validationtool/cmd/PrintReportActionTest.java
index e28b7ab..2235236 100644
--- a/src/test/java/de/kosit/validationtool/cmd/PrintReportActionTest.java
+++ b/src/test/java/de/kosit/validationtool/cmd/PrintReportActionTest.java
@@ -22,7 +22,7 @@ package de.kosit.validationtool.cmd;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.IOException;
-import java.net.URL;
+import java.net.MalformedURLException;
import org.junit.After;
import org.junit.Before;
@@ -30,6 +30,7 @@ import org.junit.Test;
import de.kosit.validationtool.api.InputFactory;
import de.kosit.validationtool.impl.Helper;
+import de.kosit.validationtool.impl.Helper.Simple;
import de.kosit.validationtool.impl.tasks.CheckAction;
/**
@@ -37,7 +38,6 @@ import de.kosit.validationtool.impl.tasks.CheckAction;
*/
public class PrintReportActionTest {
- private static final URL REPORT = SerializeReportActionTest.class.getResource("/examples/results/report.xml");
private CommandLine commandLine;
@@ -45,26 +45,26 @@ public class PrintReportActionTest {
@Before
public void setup() throws IOException {
- commandLine = new CommandLine();
- commandLine.activate();
- action = new PrintReportAction();
+ this.commandLine = new CommandLine();
+ this.commandLine.activate();
+ this.action = new PrintReportAction();
}
@After
public void tearDownd() throws IOException {
- commandLine.deactivate();
+ this.commandLine.deactivate();
}
@Test
- public void testSimpleSerialize() {
- CheckAction.Bag b = new CheckAction.Bag(InputFactory.read(REPORT));
- b.setReport(Helper.load(REPORT));
- assertThat(action.isSkipped(b)).isFalse();
- action.check(b);
+ public void testSimpleSerialize() throws MalformedURLException {
+ final CheckAction.Bag b = new CheckAction.Bag(InputFactory.read(Simple.SIMPLE_VALID));
+ b.setReport(Helper.load(Simple.SIMPLE_VALID.toURL()));
+ assertThat(this.action.isSkipped(b)).isFalse();
+ this.action.check(b);
assertThat(b.isStopped()).isFalse();
- assertThat(commandLine.getOutput()).isNotEmpty();
- // assertThat(commandLine.getOutput()).contains("
-
-
-
-
- KoSIT POC
-
- 2017-09-01T13:13:59.055+02:00
-
-
- SHA-256
- 4exhW9EJxAbhlZLHZ3mYZ3/hWGG5e6mIpiTAlGTpQ7s=
-
-
- /C:/Developer/source/init/eRechnung-Check/src/test/resources/examples/UBLReady/UBLReady_EU_UBL-NL_20170102_FULL.xml
-
-
-
- UBL 2.1 Invoice
- urn:oasis:names:specification:ubl:schema:xsd:Invoice-2
- /invoice:Invoice
-
-
- UBL 2.1 Invoice
- resources/eRechnung/UBL-2.1/xsdrt/maindoc/UBL-Invoice-2.1.xsd
-
-
-
-
- BII Rules for Invoice
- resources/eRechnung/UBL-2.1/xsl/BIIRULES-UBL-T10.xsl
-
-
-
-
- openPEPPOL Rules for Invoice
- resources/eRechnung/UBL-2.1/xsl/OPENPEPPOL-UBL-T10.xsl
-
-
-
-
- Report für eRechnung
- resources/eRechnung/report.xsl
-
-
-
-
-
-
- UBL 2.1 Invoice
- resources/eRechnung/UBL-2.1/xsdrt/maindoc/UBL-Invoice-2.1.xsd
-
-
-
-
- BII Rules for Invoice
- resources/eRechnung/UBL-2.1/xsl/BIIRULES-UBL-T10.xsl
-
-
- [CL-T10-R010]-Coded allowance and charge reasons SHOULD belong to the UNCL 4465 code list BII2 subset
-
-
-
-
- openPEPPOL Rules for Invoice
- resources/eRechnung/UBL-2.1/xsl/OPENPEPPOL-UBL-T10.xsl
-
-
- [EUGEN-T10-R026]-A currency code element MUST have a list identifier attribute 'ISO4217'.
-
-
- [EUGEN-T10-R041]-The VAT identifier for the supplier SHOULD be prefixed with country code for companies
- with VAT registration in EU countries
-
-
- [EUGEN-T10-R054]-A party legal entity company identifier SHOULD have a scheme identifier attribute.
-
-
- [EUGEN-T10-R029]-An allowance charge reason code MUST have a list identifier attribute 'UNCL4465'.
-
-
- [EUGEN-T10-R029]-An allowance charge reason code MUST have a list identifier attribute 'UNCL4465'.
-
-
- [EUGEN-T10-R029]-An allowance charge reason code MUST have a list identifier attribute 'UNCL4465'.
-
-
-
-
-
-
-
-
- Pruefbericht der KoSIT
-
-
-
-
Konformitätsprüfung:Das geprüfte Dokument enthält 4 Fehler / 3
- Warnungen. Es ist nicht konform zu den formalen Vorgaben.
-
-
-
-
-
Pos
-
Code
-
CustomLevel (Level)
-
Step
-
Text
-
-
-
-
-
1
-
CL-T10-R010
-
warning
-
-
[CL-T10-R010]-Coded allowance and charge reasons SHOULD belong to the UNCL 4465
- code list BII2 subset
-
-
-
-
-
-
-
-
2
-
EUGEN-T10-R026
-
error
-
-
[EUGEN-T10-R026]-A currency code element MUST have a list identifier attribute
- 'ISO4217'.
-
-
-
-
-
-
-
-
3
-
EUGEN-T10-R041
-
warning
-
-
[EUGEN-T10-R041]-The VAT identifier for the supplier SHOULD be prefixed with
- country code for companies with VAT registration in EU countries
-
-
-
-
-
-
-
-
4
-
EUGEN-T10-R054
-
warning
-
-
[EUGEN-T10-R054]-A party legal entity company identifier SHOULD have a scheme
- identifier attribute.
-
-
-
-
-
-
-
-
5
-
EUGEN-T10-R029
-
error
-
-
[EUGEN-T10-R029]-An allowance charge reason code MUST have a list identifier
- attribute 'UNCL4465'.
-
-
-
-
-
-
-
-
6
-
EUGEN-T10-R029
-
error
-
-
[EUGEN-T10-R029]-An allowance charge reason code MUST have a list identifier
- attribute 'UNCL4465'.
-
-
-
-
-
-
-
-
7
-
EUGEN-T10-R029
-
error
-
-
[EUGEN-T10-R029]-An allowance charge reason code MUST have a list identifier
- attribute 'UNCL4465'.
-
-
-
-
-
-
-
-
-
Bewertung:Es wird empfohlen das Dokument zurückzuweisen.
-
-
Erstellt mit: KoSIT POC für das InstructionSet
-
- vom .
-
-
-
-
-
-
-
\ No newline at end of file
From d7f4a78fbc3de87e8518c07f7636e5d8bd1f4290 Mon Sep 17 00:00:00 2001
From: "Andreas Penski (init)"
Date: Mon, 23 Mar 2020 13:35:15 +0100
Subject: [PATCH 032/306] (chore) fix typo
---
.../de/kosit/validationtool/cmd/PrintReportActionTest.java | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/src/test/java/de/kosit/validationtool/cmd/PrintReportActionTest.java b/src/test/java/de/kosit/validationtool/cmd/PrintReportActionTest.java
index 2235236..e1b16f4 100644
--- a/src/test/java/de/kosit/validationtool/cmd/PrintReportActionTest.java
+++ b/src/test/java/de/kosit/validationtool/cmd/PrintReportActionTest.java
@@ -21,7 +21,6 @@ package de.kosit.validationtool.cmd;
import static org.assertj.core.api.Assertions.assertThat;
-import java.io.IOException;
import java.net.MalformedURLException;
import org.junit.After;
@@ -44,14 +43,14 @@ public class PrintReportActionTest {
private PrintReportAction action;
@Before
- public void setup() throws IOException {
+ public void setup() {
this.commandLine = new CommandLine();
this.commandLine.activate();
this.action = new PrintReportAction();
}
@After
- public void tearDownd() throws IOException {
+ public void tearDown() {
this.commandLine.deactivate();
}
From b50bed91d18667ac3a5b55f9691bcf4cdcf6ac80 Mon Sep 17 00:00:00 2001
From: "Andreas Penski (init)"
Date: Mon, 23 Mar 2020 13:39:38 +0100
Subject: [PATCH 033/306] (chore) test with no schematron check / results
---
.../impl/tasks/ComputeAcceptanceActionTest.java | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/src/test/java/de/kosit/validationtool/impl/tasks/ComputeAcceptanceActionTest.java b/src/test/java/de/kosit/validationtool/impl/tasks/ComputeAcceptanceActionTest.java
index 5798467..e0f4bcc 100644
--- a/src/test/java/de/kosit/validationtool/impl/tasks/ComputeAcceptanceActionTest.java
+++ b/src/test/java/de/kosit/validationtool/impl/tasks/ComputeAcceptanceActionTest.java
@@ -95,6 +95,15 @@ public class ComputeAcceptanceActionTest {
assertThat(bag.getAcceptStatus()).isEqualTo(AcceptRecommendation.REJECT);
}
+ @Test
+ public void testNoSchematronCheck() {
+ final Bag bag = createBag(true, true);
+ // remove schematron results
+ bag.getReportInput().getValidationResultsSchematron().clear();
+ this.action.check(bag);
+ assertThat(bag.getAcceptStatus()).isEqualTo(AcceptRecommendation.ACCEPTABLE);
+ }
+
@Test
public void testMissingReport() {
final Bag bag = createBag(false, true);
From 515b45bc6e5624dbf2be1d068b4d2acaa4403f73 Mon Sep 17 00:00:00 2001
From: "Andreas Penski (init)"
Date: Mon, 23 Mar 2020 13:45:59 +0100
Subject: [PATCH 034/306] (chore) reduce test objects, reuse simple stuff
---
.../cmd/ExtractHtmlActionTest.java | 23 ++++++++--------
.../cmd/SerializeReportActionTest.java | 26 +++++++++----------
2 files changed, 24 insertions(+), 25 deletions(-)
diff --git a/src/test/java/de/kosit/validationtool/cmd/ExtractHtmlActionTest.java b/src/test/java/de/kosit/validationtool/cmd/ExtractHtmlActionTest.java
index 9c308a1..75c0449 100644
--- a/src/test/java/de/kosit/validationtool/cmd/ExtractHtmlActionTest.java
+++ b/src/test/java/de/kosit/validationtool/cmd/ExtractHtmlActionTest.java
@@ -22,7 +22,6 @@ package de.kosit.validationtool.cmd;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.IOException;
-import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.stream.Collectors;
@@ -34,6 +33,7 @@ import org.junit.Test;
import de.kosit.validationtool.api.InputFactory;
import de.kosit.validationtool.impl.Helper;
+import de.kosit.validationtool.impl.Helper.Simple;
import de.kosit.validationtool.impl.tasks.CheckAction;
/**
@@ -43,7 +43,6 @@ import de.kosit.validationtool.impl.tasks.CheckAction;
*/
public class ExtractHtmlActionTest {
- private static final URL REPORT = SerializeReportActionTest.class.getResource("/examples/results/report.xml");
private ExtractHtmlContentAction action;
@@ -51,24 +50,24 @@ public class ExtractHtmlActionTest {
@Before
public void setup() throws IOException {
- tmpDirectory = Files.createTempDirectory("checktool");
- action = new ExtractHtmlContentAction(Helper.loadTestRepository(), tmpDirectory);
+ this.tmpDirectory = Files.createTempDirectory("checktool");
+ this.action = new ExtractHtmlContentAction(Helper.loadTestRepository(), this.tmpDirectory);
}
@After
public void tearDown() throws IOException {
- FileUtils.deleteDirectory(tmpDirectory.toFile());
+ FileUtils.deleteDirectory(this.tmpDirectory.toFile());
}
@Test
public void testSimple() throws IOException {
- CheckAction.Bag b = new CheckAction.Bag(InputFactory.read(REPORT));
- assertThat(action.isSkipped(b)).isTrue();
- b.setReport(Helper.load(REPORT));
- action.check(b);
- assertThat(action.isSkipped(b)).isFalse();
- action.check(b);
+ final CheckAction.Bag b = new CheckAction.Bag(InputFactory.read(Simple.SIMPLE_VALID));
+ assertThat(this.action.isSkipped(b)).isTrue();
+ b.setReport(Helper.load(Simple.SIMPLE_VALID.toURL()));
+ this.action.check(b);
+ assertThat(this.action.isSkipped(b)).isFalse();
+ this.action.check(b);
assertThat(b.isStopped()).isFalse();
- assertThat(Files.list(tmpDirectory).collect(Collectors.toList())).hasSize(1);
+ assertThat(Files.list(this.tmpDirectory).collect(Collectors.toList())).hasSize(1);
}
}
diff --git a/src/test/java/de/kosit/validationtool/cmd/SerializeReportActionTest.java b/src/test/java/de/kosit/validationtool/cmd/SerializeReportActionTest.java
index 12960c3..d0373f2 100644
--- a/src/test/java/de/kosit/validationtool/cmd/SerializeReportActionTest.java
+++ b/src/test/java/de/kosit/validationtool/cmd/SerializeReportActionTest.java
@@ -22,7 +22,7 @@ package de.kosit.validationtool.cmd;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.IOException;
-import java.net.URL;
+import java.net.MalformedURLException;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -33,6 +33,7 @@ import org.junit.Test;
import de.kosit.validationtool.api.InputFactory;
import de.kosit.validationtool.impl.Helper;
+import de.kosit.validationtool.impl.Helper.Simple;
import de.kosit.validationtool.impl.tasks.CheckAction;
/**
@@ -40,7 +41,6 @@ import de.kosit.validationtool.impl.tasks.CheckAction;
*/
public class SerializeReportActionTest {
- private static final URL REPORT = SerializeReportActionTest.class.getResource("/examples/results/report.xml");
private Path tmpDirectory;
@@ -48,31 +48,31 @@ public class SerializeReportActionTest {
@Before
public void setup() throws IOException {
- tmpDirectory = Files.createTempDirectory("checktool");
- action = new SerializeReportAction(tmpDirectory);
+ this.tmpDirectory = Files.createTempDirectory("checktool");
+ this.action = new SerializeReportAction(this.tmpDirectory);
}
@After
public void tearDown() throws IOException {
- FileUtils.deleteDirectory(tmpDirectory.toFile());
+ FileUtils.deleteDirectory(this.tmpDirectory.toFile());
}
@Test
- public void testSimpleSerialize() {
- CheckAction.Bag b = new CheckAction.Bag(InputFactory.read(REPORT));
- assertThat(action.isSkipped(b)).isTrue();
- b.setReport(Helper.load(REPORT));
- assertThat(action.isSkipped(b)).isFalse();
- action.check(b);
+ public void testSimpleSerialize() throws MalformedURLException {
+ final CheckAction.Bag b = new CheckAction.Bag(InputFactory.read(Simple.SIMPLE_VALID));
+ assertThat(this.action.isSkipped(b)).isTrue();
+ b.setReport(Helper.load(Simple.SIMPLE_VALID.toURL()));
+ assertThat(this.action.isSkipped(b)).isFalse();
+ this.action.check(b);
assertThat(b.isStopped()).isFalse();
- assertThat(tmpDirectory.toFile().listFiles()).hasSize(1);
+ assertThat(this.tmpDirectory.toFile().listFiles()).hasSize(1);
}
//ERPT-83
@Test
public void testName(){
final String name = "some.name.with.dots";
- CheckAction.Bag b = new CheckAction.Bag(InputFactory.read("ega".getBytes(), name + ".xml"));
+ final CheckAction.Bag b = new CheckAction.Bag(InputFactory.read("ega".getBytes(), name + ".xml"));
assertThat(b.getName()).isEqualTo(name);
}
From 03cf40f32837e7b1d437067a767bd874f9babc4b Mon Sep 17 00:00:00 2001
From: "Andreas Penski (init)"
Date: Mon, 23 Mar 2020 14:59:43 +0100
Subject: [PATCH 035/306] (chore) clarify actual test
---
.../validationtool/impl/tasks/ComputeAcceptanceActionTest.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/test/java/de/kosit/validationtool/impl/tasks/ComputeAcceptanceActionTest.java b/src/test/java/de/kosit/validationtool/impl/tasks/ComputeAcceptanceActionTest.java
index e0f4bcc..8c99f6e 100644
--- a/src/test/java/de/kosit/validationtool/impl/tasks/ComputeAcceptanceActionTest.java
+++ b/src/test/java/de/kosit/validationtool/impl/tasks/ComputeAcceptanceActionTest.java
@@ -73,7 +73,7 @@ public class ComputeAcceptanceActionTest {
}
@Test
- public void testValidAcceptMatchOnSchematronFailed() {
+ public void testAcceptMatchOverridesSchematronErrors() {
final Bag bag = createBag(true, false);
bag.getScenarioSelectionResult().getObject().setAcceptMatch("count(//doesnotExist) = 0");
this.action.check(bag);
From 3388eba1d22af5b175b1b483ce25033d7a9760d8 Mon Sep 17 00:00:00 2001
From: "Andreas Penski (init)"
Date: Tue, 24 Mar 2020 08:37:14 +0100
Subject: [PATCH 036/306] (chore) doc enhancements
---
README.md | 6 ++++--
docs/api.md | 40 +++++++++++++++++++++++++++-------------
2 files changed, 31 insertions(+), 15 deletions(-)
diff --git a/README.md b/README.md
index 832ddf6..483ba8b 100644
--- a/README.md
+++ b/README.md
@@ -66,6 +66,10 @@ java -jar validationtool--standalone.jar --help
A concrete example with a specific validator configuration can be found on [GitHub](https://github.com/itplr-kosit/validator-configuration-xrechnung)
+### Application User Interface (API / embedded usage)
+
+The validator can also be used in own Java Applications via the API. Details can be [found here](./docs/api.md).
+
### Daemon-Mode
You can also start the validator as an HTTP-Server. Just start it in _Daemon-Mode_ with the `-D` option.
@@ -86,6 +90,4 @@ You can HTTP-POST to `/` and the response will return the report document as de
Additionally there is the GET `/health` endpoint which can be used by monitoring systems.
-### Application User Interface (embedded usage)
-The validator can also be used in own Java Applications via the API. Details can be [found here](./docs/api.md).
diff --git a/docs/api.md b/docs/api.md
index e537f83..31d05ab 100644
--- a/docs/api.md
+++ b/docs/api.md
@@ -4,7 +4,8 @@ The Validator offers an API which allows you to integrate Validator in your own
## Dependency Management
-Currently, we *do not* deploy to Maven Central or similar. Hence you need to build and optionally deploy the Validator artifacts to your own shared repository (see for example [Maven Documentation](https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html)).
+Currently, we *do not* deploy to Maven Central or similar. Hence you need to build and optionally deploy the Validator artifacts to your own
+shared (or local) repository (see for example [Maven Documentation](https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html)).
### Maven
@@ -28,7 +29,8 @@ dependencies {
## Usage
-Prerequisite for use is a valid [scenario definition](configurations.md) and the a folder with all necessary artifacts for validation (repository) either on the filesystem or on the classpath.
+Prerequisite for use is a valid [scenario definition](configurations.md) and the a folder with all necessary artifacts for validation
+(repository) either on the filesystem or on the classpath.
The following example demonstrates loading scenario.xml and whole configuration from classpath and validating one XML document:
@@ -81,14 +83,19 @@ public class StandardExample {
}
```
-The `Result` interface has more methods to retrieve details about XSD validation errors and Schematron messages.
+The `Result` interface has convenience methods to retrieve details about XSD validation errors and Schematron messages and other processing results. See
+[Result.java](https://github.com/itplr-kosit/validator/blob/master/src/main/java/de/kosit/validationtool/api/Result.java) for details.
-Initializing all XML artifacts and XSLT-executables is expensive. The `Check` instance is *threadsafe* and keeps all artifacts. Therefore, we recommend the re-use of an `Check` instance.
-
-* Batch use is serial and *not parallel*
+Initializing all XML artifacts and XSLT-executables is expensive. The `Check` instance is *threadsafe* and keeps all artifacts. Therefore,
+we recommend the re-use of an `Check` instance.
The only input `de.kosit.validationtool.api.Input` which can be created by various methods of `de.kosit.validationtool.api.InputFactory`.
-The `InputFactory` calculates a hash sum for each Input which is also written to the Report. _SHA-256_ from the JDK is the default algorithm. It can be changed using the `read`-methods of `InputFactory`.
+The `InputFactory` calculates a hash sum for each Input which is also written to the Report. _SHA-256_ from the JDK is the default algorithm.
+It can be changed using the `read`-methods of `InputFactory`.
+
+The main interface [Check.java](https://github.com/itplr-kosit/validator/blob/master/src/main/java/de/kosit/validationtool/api/Check.java)
+allows using a batch interface (processing list of [Inputs](https://github.com/itplr-kosit/validator/blob/master/src/main/java/de/kosit/validationtool/api/Input.java)).
+However, there is no parallel processing implemented at the moment.
## Accept Recommendation and Accept Match
@@ -96,14 +103,21 @@ A tri-state Object `AcceptRecommendation` can be retrieved from the `Result` usi
The three defined states are:
-1. `UNDEFINED` i.e. the evaluation of the overall validation could not be computed.
-2. `ACCEPTABLE` i.e. the recommendation is to accept input based on the evaluation of the overall validation.
-3. `REJECT` i.e. the recommendation is to reject input based on the evaluation of the overall validation.
+1. `ACCEPTABLE` i.e. the recommendation is to accept input based on the evaluation of the overall validation.
+1. `REJECT` i.e. the recommendation is to reject input based on the evaluation of the overall validation.
+1. `UNDEFINED` i.e. the evaluation of the overall validation could not be computed (overall processing is incomplete)
-By default it is `UNDEFINED`.
+The accept recommendation is based on either:
+
+1. schema and schematron validation result
+1. if configured based on _acceptMatch_ configuration of the scenario (see below)
### Accept Match in Scenario Configuration
-For your own configuration you can add an `acceptMatch` element in each scenario. It can contain in XPATH expression over your own defined `Report` to compute a boolean. An XPATH expression evaluating to true will lead to an `ACCEPTABLE` amd otherwise to a `REJECT` recommendation.
+For your own configuration you can add an `acceptMatch` element in each scenario. It can contain in XPATH expression over your own
+defined `Report` to compute a boolean. An XPATH expression evaluating to true will lead to an `ACCEPTABLE` and otherwise to a `REJECT`
+recommendation.
-This allows to have own control over what validation result is to be considered acceptable for your own application context.
+This allows to have control over what validation result is to be considered _acceptable_ for your own application context. E.g. you can
+overrule schematron validation errors with _acceptMatch_ configuration and consider certain errors as _acceptable_. Nevertheless you can *not*
+overrule schema errors with accept match.
From b7376509371bcc57bc62d132168cb83dfbdee107 Mon Sep 17 00:00:00 2001
From: "Andreas Penski (init)"
Date: Tue, 24 Mar 2020 08:39:36 +0100
Subject: [PATCH 037/306] (chore) export zip artefact
---
.gitlab-ci.yml | 1 +
1 file changed, 1 insertion(+)
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index dedc582..49ee7c6 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -86,6 +86,7 @@ build-java-11:
name: java-11
paths:
- target/*.jar
+ - target/*.zip
reports:
junit:
- target/surefire-reports/*.xml
From cba3cdb139bdc9de4b176665aec73558fd48fc32 Mon Sep 17 00:00:00 2001
From: "Andreas Penski (init)"
Date: Tue, 24 Mar 2020 08:41:57 +0100
Subject: [PATCH 038/306] (chore) prepare release version
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 7f74ebe..07bcbfa 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
KoSIT XML Prüftool Implementierungde.kosit
- 1.1.4-SNAPSHOT
+ 1.2.0-SNAPSHOTvalidationtoolKoSIT XML Validator against XSD and Schematron based on defined scenarios.
From 0162433059e78b801ee264733639d4e4be5961f8 Mon Sep 17 00:00:00 2001
From: "Andreas Penski (init)"
Date: Tue, 24 Mar 2020 08:46:11 +0100
Subject: [PATCH 039/306] (chore) config changes
---
.idea/encodings.xml | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
index 67472d0..63fc954 100644
--- a/.idea/encodings.xml
+++ b/.idea/encodings.xml
@@ -1,7 +1,10 @@
-
+
+
+
+
\ No newline at end of file
From 4c9aefaa11739a054e2e414793be9ee940603bcb Mon Sep 17 00:00:00 2001
From: "Andreas Penski (init)"
Date: Tue, 24 Mar 2020 09:15:31 +0100
Subject: [PATCH 040/306] [maven-release-plugin] prepare release v1.2.0
---
pom.xml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/pom.xml b/pom.xml
index 07bcbfa..e7e7bd8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
KoSIT XML Prüftool Implementierungde.kosit
- 1.2.0-SNAPSHOT
+ 1.2.0validationtoolKoSIT XML Validator against XSD and Schematron based on defined scenarios.
@@ -451,7 +451,7 @@
https://github.com/itplr-kosit/validationtool.gitscm:git:https://projekte.kosit.org/kosit/validator.git
- v1.1.1
+ v1.2.0
- org.codehaus.mojo
- build-helper-maven-plugin
- 3.0.0
-
-
- add-source
- generate-sources
-
- add-source
-
-
-
- src/generated/java
-
-
-
-
-
-
org.jvnet.jaxb2.maven2
@@ -316,7 +282,6 @@
truesrc/main/model/xsdsrc/main/model/binding
- src/generated/javafalse-Xinheritance
diff --git a/src/generated/java/de/kosit/validationtool/model/daemon/ObjectFactory.java b/src/generated/java/de/kosit/validationtool/model/daemon/ObjectFactory.java
deleted file mode 100644
index b5a58c5..0000000
--- a/src/generated/java/de/kosit/validationtool/model/daemon/ObjectFactory.java
+++ /dev/null
@@ -1,77 +0,0 @@
-//
-// Diese Datei wurde mit der JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.3.0 generiert
-// Siehe https://javaee.github.io/jaxb-v2/
-// Änderungen an dieser Datei gehen bei einer Neukompilierung des Quellschemas verloren.
-// Generiert: 2020.04.29 um 05:05:04 PM CEST
-//
-
-
-package de.kosit.validationtool.model.daemon;
-
-import javax.xml.bind.JAXBElement;
-import javax.xml.bind.annotation.XmlElementDecl;
-import javax.xml.bind.annotation.XmlRegistry;
-import javax.xml.namespace.QName;
-
-
-/**
- * This object contains factory methods for each Java content interface and Java element interface generated in the
- * de.kosit.validationtool.model.daemon package.
- *
- * An ObjectFactory allows you to programatically construct new instances of the Java representation for XML content.
- * The Java representation of XML content can consist of schema derived interfaces and classes representing the binding
- * of schema type definitions, element declarations and model groups. Factory methods for each of these are provided in
- * this class.
- *
- */
-@XmlRegistry
-public class ObjectFactory {
-
- private final static QName _Health_QNAME = new QName("http://www.xoev.de/de/validator/framework/1/daemon", "health");
-
- /**
- * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package:
- * de.kosit.validationtool.model.daemon
- *
- */
- public ObjectFactory() {
- }
-
- /**
- * Create an instance of {@link HealthType }
- *
- */
- public HealthType createHealthType() {
- return new HealthType();
- }
-
- /**
- * Create an instance of {@link ApplicationType }
- *
- */
- public ApplicationType createApplicationType() {
- return new ApplicationType();
- }
-
- /**
- * Create an instance of {@link MemoryType }
- *
- */
- public MemoryType createMemoryType() {
- return new MemoryType();
- }
-
- /**
- * Create an instance of {@link JAXBElement }{@code <}{@link HealthType }{@code >}
- *
- * @param value
- * Java instance representing xml element's value.
- * @return
- * the new instance of {@link JAXBElement }{@code <}{@link HealthType }{@code >}
- */
- @XmlElementDecl(namespace = "http://www.xoev.de/de/validator/framework/1/daemon", name = "health")
- public JAXBElement createHealth(HealthType value) {
- return new JAXBElement(_Health_QNAME, HealthType.class, null, value);
- }
-
-}
From aca3d2bd04108b9c8a6c3a995b3ebb2c74967dda Mon Sep 17 00:00:00 2001
From: "Andreas Penski (init)"
Date: Wed, 29 Apr 2020 19:48:57 +0200
Subject: [PATCH 055/306] jacoco for the daemon code
---
pom.xml | 44 +++++++++++++++++++++++++++++++++++---------
1 file changed, 35 insertions(+), 9 deletions(-)
diff --git a/pom.xml b/pom.xml
index e3e404d..352ba42 100644
--- a/pom.xml
+++ b/pom.xml
@@ -39,7 +39,7 @@
UTF-8
- 0.8.4
+ 0.8.51.18.89.9.1-31.7.25
@@ -309,14 +309,39 @@
- prepareJacocoJUnitArgLine
+ prepareJacocoSurefireArgLineprepare-agent
- jacocoArgumentsJUnit
+ jacocoSurefire
+
+ prepareJacocoFailsafeArgLine
+
+ prepare-agent
+
+
+ jacocoFailsafe
+
+ localhost
+ 8081
+
+
+
+ dump
+ post-integration-test
+
+ dump
+
+
+
+ localhost
+ 8081
+ true
+
+ generateJacocoReport
@@ -332,7 +357,7 @@
2.22.0
- -Dfile.encoding=UTF-8 ${jacocoArgumentsJUnit}
+ -Dfile.encoding=UTF-8 ${jacocoSurefire}
@@ -364,20 +389,21 @@
exec-maven-plugin1.6.0
-
+ run
- pre-integration-test
-
+ pre-integration-test
+ exec
-
+
-
+ javatruetruetrue
+ ${jacocoFailsafe}-classpathde.kosit.validationtool.cmd.CommandLineApplication
From fcf3ff2bf1236b4f7955000814aeac35720deda5 Mon Sep 17 00:00:00 2001
From: "Andreas Penski (init)"
Date: Thu, 30 Apr 2020 10:32:22 +0200
Subject: [PATCH 056/306] use random ports; tests for the Daemon
---
pom.xml | 32 +++++++++++++++++--
.../kosit/validationtool/daemon/Daemon.java | 2 --
.../xml/StrictRelativeResolvingStrategy.java | 9 ++----
.../kosit/validationtool/daemon/BaseIT.java | 26 +++++++++++++++
.../CheckHandlerIT.java} | 19 ++---------
.../daemon/ConfigHandlerIT.java | 20 ++++++++++++
.../daemon/HealthHandlerIT.java | 20 ++++++++++++
7 files changed, 102 insertions(+), 26 deletions(-)
create mode 100644 src/test/java/de/kosit/validationtool/daemon/BaseIT.java
rename src/test/java/de/kosit/validationtool/{cmd/DaemonIT.java => daemon/CheckHandlerIT.java} (78%)
create mode 100644 src/test/java/de/kosit/validationtool/daemon/ConfigHandlerIT.java
create mode 100644 src/test/java/de/kosit/validationtool/daemon/HealthHandlerIT.java
diff --git a/pom.xml b/pom.xml
index 352ba42..77cb2b6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -145,6 +145,26 @@
+
+ org.codehaus.mojo
+ build-helper-maven-plugin
+ 3.1.0
+
+
+ reserve-network-port
+
+ reserve-network-port
+
+ process-resources
+
+
+ validator.server.port
+ jacoco.tcp.port
+
+
+
+
+ org.apache.maven.pluginsmaven-enforcer-plugin
@@ -319,6 +339,7 @@
prepareJacocoFailsafeArgLine
+ pre-integration-testprepare-agent
@@ -326,7 +347,7 @@
jacocoFailsafe
localhost
- 8081
+ ${jacoco.tcp.port}
@@ -338,7 +359,7 @@
localhost
- 8081
+ ${jacoco.tcp.port}true
@@ -411,6 +432,8 @@
${project.build.testOutputDirectory}/examples/simple/scenarios.xml-r${project.build.testOutputDirectory}/examples/simple/repository
+ --port
+ ${validator.server.port}-D
@@ -425,6 +448,7 @@
+ ${jacoco.tcp.port}
@@ -448,6 +472,10 @@
integration-testverify
+
+
+ -Dfile.encoding=UTF-8 -Ddaemon.port=${validator.server.port}
+
diff --git a/src/main/java/de/kosit/validationtool/daemon/Daemon.java b/src/main/java/de/kosit/validationtool/daemon/Daemon.java
index 6eeda08..9756238 100644
--- a/src/main/java/de/kosit/validationtool/daemon/Daemon.java
+++ b/src/main/java/de/kosit/validationtool/daemon/Daemon.java
@@ -6,7 +6,6 @@ import java.util.concurrent.Executors;
import com.sun.net.httpserver.HttpServer;
-import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
@@ -23,7 +22,6 @@ import de.kosit.validationtool.model.daemon.HealthType;
*/
@RequiredArgsConstructor
@Setter
-@Getter
@Slf4j
public class Daemon {
diff --git a/src/main/java/de/kosit/validationtool/impl/xml/StrictRelativeResolvingStrategy.java b/src/main/java/de/kosit/validationtool/impl/xml/StrictRelativeResolvingStrategy.java
index bb6aa29..2db971c 100644
--- a/src/main/java/de/kosit/validationtool/impl/xml/StrictRelativeResolvingStrategy.java
+++ b/src/main/java/de/kosit/validationtool/impl/xml/StrictRelativeResolvingStrategy.java
@@ -1,7 +1,6 @@
package de.kosit.validationtool.impl.xml;
import java.io.Reader;
-import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
@@ -15,6 +14,7 @@ import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;
import lombok.RequiredArgsConstructor;
+import lombok.SneakyThrows;
import net.sf.saxon.Configuration;
import net.sf.saxon.expr.XPathContext;
@@ -98,12 +98,9 @@ public class StrictRelativeResolvingStrategy extends BaseResolvingStrategy {
return processor;
}
+ @SneakyThrows
private static String encode(final String input) {
- try {
- return URLEncoder.encode(input, StandardCharsets.UTF_8.name());
- } catch (final UnsupportedEncodingException e) {
- throw new IllegalStateException("Error encoding property while initializing saxon", e);
- }
+ return URLEncoder.encode(input, StandardCharsets.UTF_8.name());
}
@Override
diff --git a/src/test/java/de/kosit/validationtool/daemon/BaseIT.java b/src/test/java/de/kosit/validationtool/daemon/BaseIT.java
new file mode 100644
index 0000000..e719345
--- /dev/null
+++ b/src/test/java/de/kosit/validationtool/daemon/BaseIT.java
@@ -0,0 +1,26 @@
+package de.kosit.validationtool.daemon;
+
+import org.junit.Before;
+
+import io.restassured.RestAssured;
+
+/**
+ * Base for integration tests.
+ *
+ * @author Andreas Penski
+ */
+public abstract class BaseIT {
+
+ @Before
+ public void setup() {
+ final String port = System.getProperty("daemon.port");
+ if (port != null) {
+ RestAssured.port = Integer.valueOf(port);
+ }
+ final String baseHost = System.getProperty("daemon.host");
+ if (baseHost != null) {
+ RestAssured.baseURI = baseHost;
+ }
+ RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
+ }
+}
diff --git a/src/test/java/de/kosit/validationtool/cmd/DaemonIT.java b/src/test/java/de/kosit/validationtool/daemon/CheckHandlerIT.java
similarity index 78%
rename from src/test/java/de/kosit/validationtool/cmd/DaemonIT.java
rename to src/test/java/de/kosit/validationtool/daemon/CheckHandlerIT.java
index aa5f7f7..86e74f0 100644
--- a/src/test/java/de/kosit/validationtool/cmd/DaemonIT.java
+++ b/src/test/java/de/kosit/validationtool/daemon/CheckHandlerIT.java
@@ -1,4 +1,4 @@
-package de.kosit.validationtool.cmd;
+package de.kosit.validationtool.daemon;
import static io.restassured.RestAssured.given;
@@ -6,13 +6,11 @@ import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.io.IOUtils;
-import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import de.kosit.validationtool.impl.Helper.Simple;
-import io.restassured.RestAssured;
import io.restassured.http.ContentType;
/**
@@ -20,24 +18,13 @@ import io.restassured.http.ContentType;
*
* @author Roula Antoun
*/
-public class DaemonIT {
+public class CheckHandlerIT extends BaseIT {
private static final String APPLICATION_XML = "application/xml";
- @Before
- public void setup() {
- final String port = System.getProperty("daemon.port");
- if (port != null) {
- RestAssured.port = Integer.valueOf(port);
- }
- final String baseHost = System.getProperty("daemon.host");
- if (baseHost != null) {
- RestAssured.baseURI = baseHost;
- }
- RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
- }
+
@Test
public void makeSureThatSuccessTest() throws IOException {
diff --git a/src/test/java/de/kosit/validationtool/daemon/ConfigHandlerIT.java b/src/test/java/de/kosit/validationtool/daemon/ConfigHandlerIT.java
new file mode 100644
index 0000000..baba2d4
--- /dev/null
+++ b/src/test/java/de/kosit/validationtool/daemon/ConfigHandlerIT.java
@@ -0,0 +1,20 @@
+package de.kosit.validationtool.daemon;
+
+import static io.restassured.RestAssured.given;
+
+import org.junit.Test;
+
+import io.restassured.http.ContentType;
+
+/**
+ * Integration test for the {@link ConfigHandler}.
+ *
+ * @author Andreas Penski
+ */
+public class ConfigHandlerIT extends BaseIT {
+
+ @Test
+ public void checkHealth() {
+ given().when().get("/server/config").then().statusCode(200).and().contentType(ContentType.XML);
+ }
+}
diff --git a/src/test/java/de/kosit/validationtool/daemon/HealthHandlerIT.java b/src/test/java/de/kosit/validationtool/daemon/HealthHandlerIT.java
new file mode 100644
index 0000000..d706624
--- /dev/null
+++ b/src/test/java/de/kosit/validationtool/daemon/HealthHandlerIT.java
@@ -0,0 +1,20 @@
+package de.kosit.validationtool.daemon;
+
+import static io.restassured.RestAssured.given;
+
+import org.junit.Test;
+
+import io.restassured.http.ContentType;
+
+/**
+ * Checks the health endpoint.
+ *
+ * @author Andreas Penski
+ */
+public class HealthHandlerIT extends BaseIT {
+
+ @Test
+ public void checkHealth() {
+ given().when().get("/server/health").then().statusCode(200).and().contentType(ContentType.XML);
+ }
+}
From 16dc45ab46d7c2ba866855f97988038656112f96 Mon Sep 17 00:00:00 2001
From: "Andreas Penski (init)"
Date: Thu, 30 Apr 2020 14:28:51 +0200
Subject: [PATCH 057/306] some more tests
---
.../config/ConfigurationBuilder.java | 28 ++++--
.../de/kosit/validationtool/config/Keys.java | 7 +-
.../validationtool/config/ReportBuilder.java | 2 +-
.../config/ScenarioBuilder.java | 22 +++--
.../validationtool/config/SchemaBuilder.java | 2 +-
.../config/SchematronBuilder.java | 2 +-
.../validationtool/config/XPathBuilder.java | 33 +++++--
.../validationtool/impl/DateFactory.java | 12 +--
.../config/ConfigurationBuilderTest.java | 88 +++++++++++++++++++
.../config/ScenarioBuilderTest.java | 74 ++++++++++++++++
.../config/SimpleConfigTest.java | 33 +++----
11 files changed, 257 insertions(+), 46 deletions(-)
create mode 100644 src/test/java/de/kosit/validationtool/config/ConfigurationBuilderTest.java
create mode 100644 src/test/java/de/kosit/validationtool/config/ScenarioBuilderTest.java
diff --git a/src/main/java/de/kosit/validationtool/config/ConfigurationBuilder.java b/src/main/java/de/kosit/validationtool/config/ConfigurationBuilder.java
index d6e91f5..1e3c8a6 100644
--- a/src/main/java/de/kosit/validationtool/config/ConfigurationBuilder.java
+++ b/src/main/java/de/kosit/validationtool/config/ConfigurationBuilder.java
@@ -16,6 +16,8 @@ import javax.xml.validation.Schema;
import org.apache.commons.lang3.NotImplementedException;
import org.apache.commons.lang3.StringUtils;
+import lombok.AccessLevel;
+import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import de.kosit.validationtool.api.Configuration;
@@ -37,6 +39,7 @@ import net.sf.saxon.s9api.Processor;
* @author Andreas Penski
*/
@Slf4j
+@Getter(AccessLevel.PACKAGE)
public class ConfigurationBuilder {
private final List scenarios = new ArrayList<>();
@@ -66,18 +69,33 @@ public class ConfigurationBuilder {
return this;
}
- public ConfigurationBuilder date(final LocalDate localDate) {
- this.date = localDate.toString();
- return this;
- }
public ConfigurationBuilder name(final String name) {
this.name = name;
return this;
}
+ /**
+ * Sets the date for this configuration.
+ *
+ * @param date the date
+ * @return this
+ */
+ public ConfigurationBuilder date(final LocalDate date) {
+ if (date != null) {
+ this.date = date.toString();
+ }
+ return this;
+ }
+
+ /**
+ * Sets the date for this configuration.
+ *
+ * @param date the date
+ * @return this
+ */
public ConfigurationBuilder date(final Date date) {
- return date(LocalDate.ofEpochDay(date.getTime()));
+ return date(date != null ? LocalDate.ofEpochDay(date.getTime()) : null);
}
public ConfigurationBuilder with(final ScenarioBuilder scenarioBuilder) {
diff --git a/src/main/java/de/kosit/validationtool/config/Keys.java b/src/main/java/de/kosit/validationtool/config/Keys.java
index 6670e71..bd37c5c 100644
--- a/src/main/java/de/kosit/validationtool/config/Keys.java
+++ b/src/main/java/de/kosit/validationtool/config/Keys.java
@@ -5,16 +5,19 @@ package de.kosit.validationtool.config;
*
* @author Andreas Penski
*/
-public class Keys {
+public final class Keys {
/**
* The actual scenarios file location as used with {@link ConfigurationLoader}.
*/
public static final String SCENARIOS_FILE = "scenarios_file";
-
/**
* The actual scenarios configuration represented as serializable tree. This either loaded from file or build manually
* via {@link ConfigurationBuilder}
*/
public static final String SCENARIO_DEFINITION = "scenario_definition";
+
+ private Keys() {
+ // hide
+ }
}
diff --git a/src/main/java/de/kosit/validationtool/config/ReportBuilder.java b/src/main/java/de/kosit/validationtool/config/ReportBuilder.java
index 1c69053..b512877 100644
--- a/src/main/java/de/kosit/validationtool/config/ReportBuilder.java
+++ b/src/main/java/de/kosit/validationtool/config/ReportBuilder.java
@@ -38,7 +38,7 @@ public class ReportBuilder implements Builder, String> build(final ContentRepository repository) {
if (this.executable == null && this.source == null) {
- return createError("Must supply source location and/or executable");
+ return createError(String.format("Must supply source location and/or executable for report '%s'", this.name));
}
final CreateReportType object = createObject();
Result, String> result;
diff --git a/src/main/java/de/kosit/validationtool/config/ScenarioBuilder.java b/src/main/java/de/kosit/validationtool/config/ScenarioBuilder.java
index 18f6536..898f1a9 100644
--- a/src/main/java/de/kosit/validationtool/config/ScenarioBuilder.java
+++ b/src/main/java/de/kosit/validationtool/config/ScenarioBuilder.java
@@ -16,6 +16,7 @@ import org.apache.commons.lang3.tuple.Pair;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
import de.kosit.validationtool.impl.ContentRepository;
import de.kosit.validationtool.impl.Scenario;
@@ -37,6 +38,7 @@ import net.sf.saxon.s9api.XPathExecutable;
* @author Andreas Penski
*/
@RequiredArgsConstructor
+@Slf4j
public class ScenarioBuilder implements Builder {
private static int nameCount = 0;
@@ -45,9 +47,9 @@ public class ScenarioBuilder implements Builder {
private final Map namespaces = new HashMap<>();
- private final XPathBuilder matchConfig = new XPathBuilder();
+ private final XPathBuilder matchConfig = new XPathBuilder("match");
- private final XPathBuilder acceptConfig = new XPathBuilder();
+ private final XPathBuilder acceptConfig = new XPathBuilder("accept");
@Getter(AccessLevel.PACKAGE)
private final String name;
@@ -207,13 +209,17 @@ public class ScenarioBuilder implements Builder {
private void buildAccept(final ContentRepository repository, final List errors, final Scenario scenario) {
this.acceptConfig.setNamespaces(this.namespaces);
- final Result result = this.acceptConfig.build(repository);
- if (result.isValid()) {
- scenario.setAcceptExecutable(result.getObject());
- scenario.getConfiguration().setAcceptMatch(this.acceptConfig.getXPath());
- this.namespaces.putAll(this.acceptConfig.getNamespaces());
+ if (this.acceptConfig.isAvailable()) {
+ final Result result = this.acceptConfig.build(repository);
+ if (result.isValid()) {
+ scenario.setAcceptExecutable(result.getObject());
+ scenario.getConfiguration().setAcceptMatch(this.acceptConfig.getXPath());
+ this.namespaces.putAll(this.acceptConfig.getNamespaces());
+ } else {
+ errors.addAll(result.getErrors());
+ }
} else {
- errors.addAll(result.getErrors());
+ log.debug("No accept configuration available");
}
}
diff --git a/src/main/java/de/kosit/validationtool/config/SchemaBuilder.java b/src/main/java/de/kosit/validationtool/config/SchemaBuilder.java
index 49dd722..ca51060 100644
--- a/src/main/java/de/kosit/validationtool/config/SchemaBuilder.java
+++ b/src/main/java/de/kosit/validationtool/config/SchemaBuilder.java
@@ -37,7 +37,7 @@ public class SchemaBuilder implements Builder, String> build(final ContentRepository repository) {
if (this.schema == null && this.schemaLocation == null) {
- return createError("Must supply schema location and/or schema");
+ return createError(String.format("Must supply source location and/or executable for schema '%s'", this.name));
}
Result, String> result;
try {
diff --git a/src/main/java/de/kosit/validationtool/config/SchematronBuilder.java b/src/main/java/de/kosit/validationtool/config/SchematronBuilder.java
index ad74f43..73c187b 100644
--- a/src/main/java/de/kosit/validationtool/config/SchematronBuilder.java
+++ b/src/main/java/de/kosit/validationtool/config/SchematronBuilder.java
@@ -38,7 +38,7 @@ public class SchematronBuilder implements Builder, String> build(final ContentRepository repository) {
if (this.executable == null && this.source == null) {
- return createError("Must supply source location and/or executable");
+ return createError(String.format("Must supply source location and/or executable for schematron '%s'", this.name));
}
final ValidateWithSchematron object = createObject();
Result, String> result;
diff --git a/src/main/java/de/kosit/validationtool/config/XPathBuilder.java b/src/main/java/de/kosit/validationtool/config/XPathBuilder.java
index 464d745..d8d53b0 100644
--- a/src/main/java/de/kosit/validationtool/config/XPathBuilder.java
+++ b/src/main/java/de/kosit/validationtool/config/XPathBuilder.java
@@ -1,5 +1,7 @@
package de.kosit.validationtool.config;
+import static org.apache.commons.lang3.ObjectUtils.isNotEmpty;
+
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
@@ -11,7 +13,9 @@ import org.apache.commons.lang3.ArrayUtils;
import lombok.AccessLevel;
import lombok.Data;
import lombok.Getter;
+import lombok.RequiredArgsConstructor;
import lombok.Setter;
+import lombok.extern.slf4j.Slf4j;
import de.kosit.validationtool.impl.ContentRepository;
import de.kosit.validationtool.impl.model.Result;
@@ -23,11 +27,15 @@ import net.sf.saxon.s9api.XPathExecutable;
*
* @author Andreas Penski
*/
+@RequiredArgsConstructor
@Data
+@Slf4j
class XPathBuilder implements Builder {
private static final String[] IGNORED_PREFIXES = new String[] { "xsd" };
+ private final String name;
+
private String xpath;
private XPathExecutable executable;
@@ -44,19 +52,30 @@ class XPathBuilder implements Builder {
public String getXPath() {
return this.xpath == null && this.executable != null ? this.executable.getUnderlyingExpression().getInternalExpression().toString()
: this.xpath;
+ }
+ public boolean isAvailable() {
+ return this.executable != null || isNotEmpty(this.xpath);
}
@Override
public Result build(final ContentRepository repository) {
- if (this.executable == null && this.xpath == null) {
- return createError("No configuration for xpath expression found");
+ if (!isAvailable()) {
+ return createError(String.format("No configuration for %s xpath expression found", this.name));
}
- if (this.executable == null) {
- this.executable = repository.createXPath(this.xpath, this.namespaces);
- } else {
- this.xpath = extractExpression();
- this.namespaces = extractNamespaces();
+ try {
+ if (this.executable == null) {
+ this.executable = repository.createXPath(this.xpath, this.namespaces);
+
+ } else {
+ this.xpath = extractExpression();
+ this.namespaces = extractNamespaces();
+ }
+ } catch (final IllegalStateException e) {
+ final String msg = String.format("Error creating %s xpath", this.name, e);
+ log.error(msg, e);
+ return new Result<>(Collections.singletonList(msg));
+
}
return new Result<>(this.executable);
}
diff --git a/src/main/java/de/kosit/validationtool/impl/DateFactory.java b/src/main/java/de/kosit/validationtool/impl/DateFactory.java
index 4665c97..0c9fe9a 100644
--- a/src/main/java/de/kosit/validationtool/impl/DateFactory.java
+++ b/src/main/java/de/kosit/validationtool/impl/DateFactory.java
@@ -3,23 +3,25 @@ package de.kosit.validationtool.impl;
import java.util.Date;
import java.util.GregorianCalendar;
-import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
+import lombok.SneakyThrows;
+
/**
* @author Andreas Penski
*/
public class DateFactory {
+ private DateFactory() {
+ // hide
+ }
+
+ @SneakyThrows
public static XMLGregorianCalendar createTimestamp() {
- try {
final GregorianCalendar cal = new GregorianCalendar();
cal.setTime(new Date());
return DatatypeFactory.newInstance().newXMLGregorianCalendar(cal);
- } catch (final DatatypeConfigurationException e) {
- throw new IllegalStateException("Can not create timestamp", e);
- }
}
}
diff --git a/src/test/java/de/kosit/validationtool/config/ConfigurationBuilderTest.java b/src/test/java/de/kosit/validationtool/config/ConfigurationBuilderTest.java
new file mode 100644
index 0000000..86df9be
--- /dev/null
+++ b/src/test/java/de/kosit/validationtool/config/ConfigurationBuilderTest.java
@@ -0,0 +1,88 @@
+package de.kosit.validationtool.config;
+
+import static de.kosit.validationtool.config.ConfigurationBuilder.report;
+import static de.kosit.validationtool.config.ConfigurationBuilder.schematron;
+import static de.kosit.validationtool.config.SimpleConfigTest.createSimpleConfiguration;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.net.URI;
+import java.time.LocalDate;
+import java.util.Date;
+
+import org.hamcrest.Matchers;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+/**
+ * Test {@link ConfigurationBuilder}.
+ *
+ * @author Andreas Penski
+ */
+public class ConfigurationBuilderTest {
+
+ public static final LocalDate EPOCH = LocalDate.of(1970, 1, 1);
+
+ @Rule
+ public ExpectedException exceptions = ExpectedException.none();
+
+ @Test
+ public void testNoConfiguration() {
+ this.exceptions.expect(IllegalStateException.class);
+ new ConfigurationBuilder().build();
+ }
+
+ @Test
+ public void testNoFallback() {
+ this.exceptions.expect(IllegalStateException.class);
+ this.exceptions.expectMessage(Matchers.containsString("fallback"));
+ final ConfigurationBuilder builder = createSimpleConfiguration();
+ builder.with((FallbackBuilder) null);
+ builder.build();
+ }
+
+ @Test
+ public void testNoSchema() {
+ this.exceptions.expect(IllegalStateException.class);
+ this.exceptions.expectMessage(Matchers.containsString("schema"));
+ final ConfigurationBuilder builder = createSimpleConfiguration();
+ builder.getScenarios().get(0).validate((SchemaBuilder) null);
+ builder.build();
+ }
+
+ @Test
+ public void testInvalidSchematron() {
+ this.exceptions.expect(IllegalStateException.class);
+ this.exceptions.expectMessage(Matchers.containsString("schematron"));
+ final ConfigurationBuilder builder = createSimpleConfiguration();
+ builder.getScenarios().get(0).validate(schematron("invalid").source(URI.create("DoesNotExist")));
+ builder.build();
+ }
+
+ @Test
+ public void testInsufficientSchematron() {
+ this.exceptions.expect(IllegalStateException.class);
+ this.exceptions.expectMessage(Matchers.containsString("schematron"));
+ final ConfigurationBuilder builder = createSimpleConfiguration();
+ builder.getScenarios().get(0).validate(schematron("invalid"));
+ builder.build();
+ }
+
+ @Test
+ public void testNoReport() {
+ this.exceptions.expect(IllegalStateException.class);
+ this.exceptions.expectMessage(Matchers.containsString("report"));
+ final ConfigurationBuilder builder = createSimpleConfiguration();
+ builder.getScenarios().get(0).with(report("invalid"));
+ builder.build();
+ }
+
+ @Test
+ public void testDate() {
+ assertThat(createSimpleConfiguration().date(EPOCH).build().getDate()).isEqualTo("1970-01-01");
+ assertThat(createSimpleConfiguration().date(new Date(EPOCH.toEpochDay())).build().getDate()).isEqualTo("1970-01-01");
+ assertThat(createSimpleConfiguration().date((Date) null).build().getDate()).isEqualTo(LocalDate.now().toString());
+ assertThat(createSimpleConfiguration().date((LocalDate) null).build().getDate()).isEqualTo(LocalDate.now().toString());
+ }
+
+}
diff --git a/src/test/java/de/kosit/validationtool/config/ScenarioBuilderTest.java b/src/test/java/de/kosit/validationtool/config/ScenarioBuilderTest.java
new file mode 100644
index 0000000..e6b9d13
--- /dev/null
+++ b/src/test/java/de/kosit/validationtool/config/ScenarioBuilderTest.java
@@ -0,0 +1,74 @@
+package de.kosit.validationtool.config;
+
+import static de.kosit.validationtool.config.SimpleConfigTest.createScenarioConfiguration;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import de.kosit.validationtool.impl.Helper.Simple;
+import de.kosit.validationtool.impl.Scenario;
+import de.kosit.validationtool.impl.model.Result;
+
+/**
+ * Test {@link ScenarioBuilder}.
+ *
+ * @author Andreas Penski
+ */
+public class ScenarioBuilderTest {
+
+ @Rule
+ public ExpectedException exceptions = ExpectedException.none();
+
+ @Test
+ public void simpleValid() {
+ final Result result = createScenarioConfiguration().build(Simple.createContentRepository());
+ assertThat(result.isValid()).isTrue();
+ assertThat(result.getObject().getConfiguration()).isNotNull();
+ }
+
+ @Test
+ public void testNoSchema() {
+ final ScenarioBuilder builder = createScenarioConfiguration();
+ builder.validate((SchemaBuilder) null);
+ final Result result = builder.build(Simple.createContentRepository());
+ assertThat(result.isValid()).isFalse();
+ assertThat(result.getErrors()).anyMatch(e -> e.contains("schema"));
+ }
+
+ @Test
+ public void testNoMatch() {
+ final ScenarioBuilder builder = createScenarioConfiguration();
+ builder.match((String) null);
+ final Result result = builder.build(Simple.createContentRepository());
+ assertThat(result.isValid()).isFalse();
+ assertThat(result.getErrors()).anyMatch(e -> e.contains("match"));
+ }
+
+ @Test
+ public void testInvalidMatch() {
+ final ScenarioBuilder builder = createScenarioConfiguration();
+ builder.match("/////");
+ final Result result = builder.build(Simple.createContentRepository());
+ assertThat(result.isValid()).isFalse();
+ assertThat(result.getErrors()).anyMatch(e -> e.contains("match"));
+ }
+
+ @Test
+ public void testNoAccept() {
+ final ScenarioBuilder builder = createScenarioConfiguration();
+ builder.acceptWith((String) null);
+ final Result result = builder.build(Simple.createContentRepository());
+ assertThat(result.isValid()).isTrue();
+ }
+
+ @Test
+ public void testInvalidAccept() {
+ final ScenarioBuilder builder = createScenarioConfiguration();
+ builder.acceptWith("/////");
+ final Result result = builder.build(Simple.createContentRepository());
+ assertThat(result.isValid()).isFalse();
+ assertThat(result.getErrors()).anyMatch(e -> e.contains("accept"));
+ }
+}
diff --git a/src/test/java/de/kosit/validationtool/config/SimpleConfigTest.java b/src/test/java/de/kosit/validationtool/config/SimpleConfigTest.java
index 1fadac4..d6f50c2 100644
--- a/src/test/java/de/kosit/validationtool/config/SimpleConfigTest.java
+++ b/src/test/java/de/kosit/validationtool/config/SimpleConfigTest.java
@@ -25,25 +25,26 @@ public class SimpleConfigTest {
@Test
public void testSimpleWithApi() {
//@formatter:off
- final Configuration config =
- Configuration.create().name("Simple-API")
- .with(scenario("simple")
- .validate(schema("Sample Schema").schemaLocation(URI.create("simple.xsd")))
- .with(report("Report für eRechnung").source("report.xsl"))
- .acceptWith("count(//test:rejected) = 0")
- .declareNamespace("cri", "http://www.xoev.de/de/validator/framework/1/createreportinput")
- .declareNamespace("rpt", "http://validator.kosit.de/test-report")
- .declareNamespace("test", "http://validator.kosit.de/test-sample")
- .match("/test:simple")
-// .description("awesome api")
- )
- .with(fallback().name("default").source("report.xsl"))
-
- .resolvingMode(ResolvingMode.STRICT_RELATIVE)
- .useRepository(Simple.REPOSITORY_URI).build();
+ final Configuration config = createSimpleConfiguration().build();
//@formatter:on
final DefaultCheck check = new DefaultCheck(config);
final Result result = check.checkInput(InputFactory.read(Simple.SIMPLE_VALID));
assertThat(result).isNotNull();
}
+
+ static ConfigurationBuilder createSimpleConfiguration() {
+ return Configuration.create().name("Simple-API").with(createScenarioConfiguration()
+ // .description("awesome api")
+ ).with(fallback().name("default").source("report.xsl"))
+
+ .resolvingMode(ResolvingMode.STRICT_RELATIVE).useRepository(Simple.REPOSITORY_URI);
+ }
+
+ static ScenarioBuilder createScenarioConfiguration() {
+ return scenario("simple").validate(schema("Sample Schema").schemaLocation(URI.create("simple.xsd")))
+ .with(report("Report für eRechnung").source("report.xsl")).acceptWith("count(//test:rejected) = 0")
+ .declareNamespace("cri", "http://www.xoev.de/de/validator/framework/1/createreportinput")
+ .declareNamespace("rpt", "http://validator.kosit.de/test-report")
+ .declareNamespace("test", "http://validator.kosit.de/test-sample").match("/test:simple");
+ }
}
From 0bb0f6671da6ead2694f8e75c6b4ea19c07384aa Mon Sep 17 00:00:00 2001
From: "Andreas Penski (init)"
Date: Thu, 30 Apr 2020 15:41:39 +0200
Subject: [PATCH 058/306] some more tests
---
.../config/ConfigurationBuilder.java | 11 ++-
.../config/ScenarioBuilder.java | 8 +-
.../validationtool/config/XPathBuilder.java | 23 +++---
.../kosit/validationtool/daemon/Daemon.java | 29 +++++--
.../config/ScenarioBuilderTest.java | 79 +++++++++++++++++++
5 files changed, 131 insertions(+), 19 deletions(-)
diff --git a/src/main/java/de/kosit/validationtool/config/ConfigurationBuilder.java b/src/main/java/de/kosit/validationtool/config/ConfigurationBuilder.java
index 1e3c8a6..3de8f12 100644
--- a/src/main/java/de/kosit/validationtool/config/ConfigurationBuilder.java
+++ b/src/main/java/de/kosit/validationtool/config/ConfigurationBuilder.java
@@ -186,7 +186,16 @@ public class ConfigurationBuilder {
* @return the scenario configuration builder
*/
public static ScenarioBuilder scenario(final String name) {
- return new ScenarioBuilder(name);
+ return new ScenarioBuilder().name(name);
+ }
+
+ /**
+ * Create a new scenario configuration.
+ *
+ * @return the scenario configuration builder
+ */
+ public static ScenarioBuilder scenario() {
+ return scenario(null);
}
/**
diff --git a/src/main/java/de/kosit/validationtool/config/ScenarioBuilder.java b/src/main/java/de/kosit/validationtool/config/ScenarioBuilder.java
index 898f1a9..cd68369 100644
--- a/src/main/java/de/kosit/validationtool/config/ScenarioBuilder.java
+++ b/src/main/java/de/kosit/validationtool/config/ScenarioBuilder.java
@@ -39,6 +39,7 @@ import net.sf.saxon.s9api.XPathExecutable;
*/
@RequiredArgsConstructor
@Slf4j
+@Getter(AccessLevel.PACKAGE)
public class ScenarioBuilder implements Builder {
private static int nameCount = 0;
@@ -51,8 +52,7 @@ public class ScenarioBuilder implements Builder {
private final XPathBuilder acceptConfig = new XPathBuilder("accept");
- @Getter(AccessLevel.PACKAGE)
- private final String name;
+ private String name;
private SchemaBuilder schemaBuilder;
@@ -273,4 +273,8 @@ public class ScenarioBuilder implements Builder {
return type;
}
+ public ScenarioBuilder name(final String name) {
+ this.name = name;
+ return this;
+ }
}
diff --git a/src/main/java/de/kosit/validationtool/config/XPathBuilder.java b/src/main/java/de/kosit/validationtool/config/XPathBuilder.java
index d8d53b0..c65d0ef 100644
--- a/src/main/java/de/kosit/validationtool/config/XPathBuilder.java
+++ b/src/main/java/de/kosit/validationtool/config/XPathBuilder.java
@@ -9,6 +9,7 @@ import java.util.Map;
import java.util.stream.StreamSupport;
import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.StringUtils;
import lombok.AccessLevel;
import lombok.Data;
@@ -32,7 +33,7 @@ import net.sf.saxon.s9api.XPathExecutable;
@Slf4j
class XPathBuilder implements Builder {
- private static final String[] IGNORED_PREFIXES = new String[] { "xsd" };
+ private static final String[] IGNORED_PREFIXES = new String[] { "xsd", "saxon", "xsl", "xs" };
private final String name;
@@ -66,10 +67,9 @@ class XPathBuilder implements Builder {
try {
if (this.executable == null) {
this.executable = repository.createXPath(this.xpath, this.namespaces);
-
} else {
this.xpath = extractExpression();
- this.namespaces = extractNamespaces();
+ extractNamespaces();
}
} catch (final IllegalStateException e) {
final String msg = String.format("Error creating %s xpath", this.name, e);
@@ -80,16 +80,21 @@ class XPathBuilder implements Builder {
return new Result<>(this.executable);
}
- private Map extractNamespaces() {
+ private void extractNamespaces() {
+ if (this.namespaces == null) {
+ this.namespaces = new HashMap<>();
+ }
final Map ns = new HashMap<>();
final Iterator iterator = this.executable.getUnderlyingExpression().getInternalExpression().getRetainedStaticContext()
.iteratePrefixes();
final Iterable iterable = () -> iterator;
- StreamSupport.stream(iterable.spliterator(), false).filter(e -> !ArrayUtils.contains(IGNORED_PREFIXES, e)).forEach(e -> {
- ns.put(e,
- this.executable.getUnderlyingExpression().getInternalExpression().getRetainedStaticContext().getURIForPrefix(e, false));
- });
- return ns;
+ StreamSupport.stream(iterable.spliterator(), false).filter(e -> !ArrayUtils.contains(IGNORED_PREFIXES, e))
+ .filter(StringUtils::isNotBlank).forEach(e -> {
+ ns.put(e, this.executable.getUnderlyingExpression().getInternalExpression().getRetainedStaticContext()
+ .getURIForPrefix(e, false));
+ });
+ this.namespaces.putAll(ns);
+
}
private String extractExpression() {
diff --git a/src/main/java/de/kosit/validationtool/daemon/Daemon.java b/src/main/java/de/kosit/validationtool/daemon/Daemon.java
index 9756238..19bd42e 100644
--- a/src/main/java/de/kosit/validationtool/daemon/Daemon.java
+++ b/src/main/java/de/kosit/validationtool/daemon/Daemon.java
@@ -1,7 +1,10 @@
package de.kosit.validationtool.daemon;
+import static org.apache.commons.lang3.StringUtils.defaultIfBlank;
+
import java.io.IOException;
import java.net.InetSocketAddress;
+import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import com.sun.net.httpserver.HttpServer;
@@ -13,7 +16,6 @@ import lombok.extern.slf4j.Slf4j;
import de.kosit.validationtool.api.Configuration;
import de.kosit.validationtool.impl.ConversionService;
import de.kosit.validationtool.impl.DefaultCheck;
-import de.kosit.validationtool.model.daemon.HealthType;
/**
* HTTP-Daemon für die Bereitstellung der Prüf-Funktionalität via http.
@@ -25,6 +27,12 @@ import de.kosit.validationtool.model.daemon.HealthType;
@Slf4j
public class Daemon {
+ private static final String DEFAULT_HOST = "localhost";
+
+ private static final int DEFAULT_PORT = 8080;
+
+ private static final int DEFAULT_THREAD_COUNT = Runtime.getRuntime().availableProcessors();
+
private final String hostName;
private final int port;
@@ -40,18 +48,25 @@ public class Daemon {
HttpServer server = null;
try {
final ConversionService converter = new ConversionService();
- converter.initialize(HealthType.class.getPackage());
- server = HttpServer.create(new InetSocketAddress(this.hostName, this.port), 0);
+ server = HttpServer.create(getSocket(), 0);
final DefaultCheck check = new DefaultCheck(config);
server.createContext("/", new CheckHandler(check, config.getContentRepository().getProcessor()));
server.createContext("/server/health", new HealthHandler(config, converter));
- server.createContext("/server/config", new ConfigHandler(config, new ConversionService()));
- server.setExecutor(Executors.newFixedThreadPool(this.threadCount));
+ server.createContext("/server/config", new ConfigHandler(config, converter));
+ server.setExecutor(createExecutor());
server.start();
- log.info("Server unter Port {} ist erfolgreich gestartet", this.port);
+ log.info("Server {} started", server.getAddress());
} catch (final IOException e) {
- log.error("Fehler beim HttpServer erstellen: {}", e.getMessage(), e);
+ log.error("Error starting HttpServer for Valdidator: {}", e.getMessage(), e);
}
}
+
+ private ExecutorService createExecutor() {
+ return Executors.newFixedThreadPool(this.threadCount > 0 ? this.threadCount : DEFAULT_THREAD_COUNT);
+ }
+
+ private InetSocketAddress getSocket() {
+ return new InetSocketAddress(defaultIfBlank(this.hostName, DEFAULT_HOST), this.port > 0 ? this.port : DEFAULT_PORT);
+ }
}
diff --git a/src/test/java/de/kosit/validationtool/config/ScenarioBuilderTest.java b/src/test/java/de/kosit/validationtool/config/ScenarioBuilderTest.java
index e6b9d13..f264f62 100644
--- a/src/test/java/de/kosit/validationtool/config/ScenarioBuilderTest.java
+++ b/src/test/java/de/kosit/validationtool/config/ScenarioBuilderTest.java
@@ -3,13 +3,23 @@ package de.kosit.validationtool.config;
import static de.kosit.validationtool.config.SimpleConfigTest.createScenarioConfiguration;
import static org.assertj.core.api.Assertions.assertThat;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.lang3.RandomStringUtils;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import de.kosit.validationtool.impl.ContentRepository;
import de.kosit.validationtool.impl.Helper.Simple;
import de.kosit.validationtool.impl.Scenario;
import de.kosit.validationtool.impl.model.Result;
+import de.kosit.validationtool.model.scenarios.NamespaceType;
+import de.kosit.validationtool.model.scenarios.ScenarioType;
+
+import net.sf.saxon.s9api.XPathExecutable;
/**
* Test {@link ScenarioBuilder}.
@@ -71,4 +81,73 @@ public class ScenarioBuilderTest {
assertThat(result.isValid()).isFalse();
assertThat(result.getErrors()).anyMatch(e -> e.contains("accept"));
}
+
+ @Test
+ public void testCombinedNamespaces() {
+ final ContentRepository repository = Simple.createContentRepository();
+ final Map ns1 = new HashMap<>();
+ ns1.put("n1", "http://n1.org");
+ final XPathExecutable match = repository.createXPath("//n1:*", ns1);
+
+ final Map ns2 = new HashMap<>();
+ ns2.put("n2", "http://n2.org");
+ final XPathExecutable accept = repository.createXPath("//n2:*", ns2);
+
+ final ScenarioBuilder builder = createScenarioConfiguration();
+ builder.getNamespaces().clear();
+
+ builder.match(match).acceptWith(accept).declareNamespace("n3", "http://n3.org");
+ final Result result = builder.build(repository);
+
+ assertThat(result.isValid()).isTrue();
+ final Scenario scenario = result.getObject();
+ final List namespaces = scenario.getConfiguration().getNamespace();
+ assertThat(namespaces.stream().map(NamespaceType::getPrefix)).containsExactly("n1", "n2", "n3");
+ assertThat(namespaces).hasSize(3);
+ }
+
+ @Test
+ public void testConfigureWithExecutable() {
+ final ContentRepository repository = Simple.createContentRepository();
+ final XPathExecutable match = repository.createXPath("//*", null);
+ final XPathExecutable accept = repository.createXPath("//*", null);
+ final ScenarioBuilder builder = createScenarioConfiguration();
+ builder.getNamespaces().clear();
+
+ builder.match(match);
+ builder.acceptWith(accept);
+ final Result result = builder.build(repository);
+ assertThat(result.isValid()).isTrue();
+ final ScenarioType configuration = result.getObject().getConfiguration();
+ assertThat(configuration.getMatch()).isNotEmpty();
+ assertThat(configuration.getAcceptMatch()).isNotEmpty();
+ assertThat(configuration.getNamespace()).isEmpty();
+ }
+
+ @Test
+ public void testBasicAttributes() {
+ final ContentRepository repository = Simple.createContentRepository();
+ final String random = RandomStringUtils.random(5);
+ final ScenarioBuilder builder = createScenarioConfiguration();
+ builder.name(random).description(random);
+ final Result result = builder.build(repository);
+ assertThat(result.isValid()).isTrue();
+ final ScenarioType config = result.getObject().getConfiguration();
+ assertThat(config.getName()).isEqualTo(random);
+ assertThat(config.getDescription()).isNotNull();
+ assertThat(config.getDescription().getPOrOlOrUl()).isNotEmpty();
+ }
+
+ @Test
+ public void testNoBasicAttributes() {
+ final ContentRepository repository = Simple.createContentRepository();
+ final ScenarioBuilder builder = createScenarioConfiguration();
+ builder.name(null);
+ final Result result = builder.build(repository);
+ assertThat(result.isValid()).isTrue();
+ final ScenarioType config = result.getObject().getConfiguration();
+ assertThat(config.getName()).contains("manually");
+ assertThat(config.getDescription()).isNotNull();
+ assertThat(config.getDescription().getPOrOlOrUl()).isNotEmpty();
+ }
}
From 46ddea57d699b134976487d94415ffa5da129c52 Mon Sep 17 00:00:00 2001
From: "Andreas Penski (init)"
Date: Thu, 30 Apr 2020 15:49:09 +0200
Subject: [PATCH 059/306] some more tests
---
src/main/java/de/kosit/validationtool/daemon/Daemon.java | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/main/java/de/kosit/validationtool/daemon/Daemon.java b/src/main/java/de/kosit/validationtool/daemon/Daemon.java
index 19bd42e..3ff2f57 100644
--- a/src/main/java/de/kosit/validationtool/daemon/Daemon.java
+++ b/src/main/java/de/kosit/validationtool/daemon/Daemon.java
@@ -16,6 +16,7 @@ import lombok.extern.slf4j.Slf4j;
import de.kosit.validationtool.api.Configuration;
import de.kosit.validationtool.impl.ConversionService;
import de.kosit.validationtool.impl.DefaultCheck;
+import de.kosit.validationtool.model.daemon.HealthType;
/**
* HTTP-Daemon für die Bereitstellung der Prüf-Funktionalität via http.
@@ -47,12 +48,14 @@ public class Daemon {
public void startServer(final Configuration config) {
HttpServer server = null;
try {
+ final ConversionService healthConverter = new ConversionService();
+ healthConverter.initialize(HealthType.class.getPackage());
final ConversionService converter = new ConversionService();
server = HttpServer.create(getSocket(), 0);
final DefaultCheck check = new DefaultCheck(config);
server.createContext("/", new CheckHandler(check, config.getContentRepository().getProcessor()));
- server.createContext("/server/health", new HealthHandler(config, converter));
+ server.createContext("/server/health", new HealthHandler(config, healthConverter));
server.createContext("/server/config", new ConfigHandler(config, converter));
server.setExecutor(createExecutor());
server.start();
From 2c479eded509a4fa650c4eb10f519d1245daee08 Mon Sep 17 00:00:00 2001
From: "Andreas Penski (init)"
Date: Thu, 30 Apr 2020 17:44:23 +0200
Subject: [PATCH 060/306] some more tests
---
.../impl/tasks/CreateReportAction.java | 12 ++-
.../config/ScenarioBuilderTest.java | 22 ++---
.../config/SimpleConfigTest.java | 16 +---
.../config/TestScenarioFactory.java | 21 +++++
.../de/kosit/validationtool/impl/Helper.java | 1 +
.../impl/tasks/CreateReportActionTest.java | 86 +++++++++++++++++++
.../{ => tasks}/DocumentParseActionTest.java | 4 +-
.../impl/xml/BaseResolverTest.java | 65 ++++++++++++++
8 files changed, 197 insertions(+), 30 deletions(-)
create mode 100644 src/test/java/de/kosit/validationtool/config/TestScenarioFactory.java
create mode 100644 src/test/java/de/kosit/validationtool/impl/tasks/CreateReportActionTest.java
rename src/test/java/de/kosit/validationtool/impl/{ => tasks}/DocumentParseActionTest.java (96%)
create mode 100644 src/test/java/de/kosit/validationtool/impl/xml/BaseResolverTest.java
diff --git a/src/main/java/de/kosit/validationtool/impl/tasks/CreateReportAction.java b/src/main/java/de/kosit/validationtool/impl/tasks/CreateReportAction.java
index 444aeec..59df0b8 100644
--- a/src/main/java/de/kosit/validationtool/impl/tasks/CreateReportAction.java
+++ b/src/main/java/de/kosit/validationtool/impl/tasks/CreateReportAction.java
@@ -72,6 +72,10 @@ public class CreateReportAction implements CheckAction {
*/
private static class ReaderWrapper implements XMLReader {
+ private static final String SAX_FEATURES_NAMESPACE_PREFIXES = "http://xml.org/sax/features/namespace-prefixes";
+
+ private static final String SAX_FEATURES_NAMESPACES = "http://xml.org/sax/features/namespaces";
+
private final XMLReader delegate;
public ReaderWrapper(final XMLReader xmlReader) {
@@ -80,9 +84,9 @@ public class CreateReportAction implements CheckAction {
@Override
public boolean getFeature(final String name) throws SAXNotRecognizedException, SAXNotSupportedException {
- if (name.equals("http://xml.org/sax/features/namespaces")) {
+ if (SAX_FEATURES_NAMESPACES.equals(name)) {
return true;
- } else if (name.equals("http://xml.org/sax/features/namespace-prefixes")) {
+ } else if (SAX_FEATURES_NAMESPACE_PREFIXES.equals(name)) {
return false;
}
// just return false on unknown properties
@@ -92,10 +96,10 @@ public class CreateReportAction implements CheckAction {
@Override
public void setFeature(final String name, final boolean value) throws SAXNotRecognizedException, SAXNotSupportedException {
// this inverts the logic from JaxbSource pseude parser
- if (name.equals("http://xml.org/sax/features/namespaces") && !value) {
+ if (name.equals(SAX_FEATURES_NAMESPACES) && !value) {
throw new SAXNotRecognizedException(name);
}
- if (name.equals("http://xml.org/sax/features/namespace-prefixes") && value) {
+ if (name.equals(SAX_FEATURES_NAMESPACE_PREFIXES) && value) {
throw new SAXNotRecognizedException(name);
}
}
diff --git a/src/test/java/de/kosit/validationtool/config/ScenarioBuilderTest.java b/src/test/java/de/kosit/validationtool/config/ScenarioBuilderTest.java
index f264f62..3b968c5 100644
--- a/src/test/java/de/kosit/validationtool/config/ScenarioBuilderTest.java
+++ b/src/test/java/de/kosit/validationtool/config/ScenarioBuilderTest.java
@@ -1,6 +1,6 @@
package de.kosit.validationtool.config;
-import static de.kosit.validationtool.config.SimpleConfigTest.createScenarioConfiguration;
+import static de.kosit.validationtool.config.TestScenarioFactory.createScenario;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.HashMap;
@@ -33,14 +33,14 @@ public class ScenarioBuilderTest {
@Test
public void simpleValid() {
- final Result result = createScenarioConfiguration().build(Simple.createContentRepository());
+ final Result result = createScenario().build(Simple.createContentRepository());
assertThat(result.isValid()).isTrue();
assertThat(result.getObject().getConfiguration()).isNotNull();
}
@Test
public void testNoSchema() {
- final ScenarioBuilder builder = createScenarioConfiguration();
+ final ScenarioBuilder builder = createScenario();
builder.validate((SchemaBuilder) null);
final Result result = builder.build(Simple.createContentRepository());
assertThat(result.isValid()).isFalse();
@@ -49,7 +49,7 @@ public class ScenarioBuilderTest {
@Test
public void testNoMatch() {
- final ScenarioBuilder builder = createScenarioConfiguration();
+ final ScenarioBuilder builder = createScenario();
builder.match((String) null);
final Result result = builder.build(Simple.createContentRepository());
assertThat(result.isValid()).isFalse();
@@ -58,7 +58,7 @@ public class ScenarioBuilderTest {
@Test
public void testInvalidMatch() {
- final ScenarioBuilder builder = createScenarioConfiguration();
+ final ScenarioBuilder builder = createScenario();
builder.match("/////");
final Result result = builder.build(Simple.createContentRepository());
assertThat(result.isValid()).isFalse();
@@ -67,7 +67,7 @@ public class ScenarioBuilderTest {
@Test
public void testNoAccept() {
- final ScenarioBuilder builder = createScenarioConfiguration();
+ final ScenarioBuilder builder = createScenario();
builder.acceptWith((String) null);
final Result result = builder.build(Simple.createContentRepository());
assertThat(result.isValid()).isTrue();
@@ -75,7 +75,7 @@ public class ScenarioBuilderTest {
@Test
public void testInvalidAccept() {
- final ScenarioBuilder builder = createScenarioConfiguration();
+ final ScenarioBuilder builder = createScenario();
builder.acceptWith("/////");
final Result result = builder.build(Simple.createContentRepository());
assertThat(result.isValid()).isFalse();
@@ -93,7 +93,7 @@ public class ScenarioBuilderTest {
ns2.put("n2", "http://n2.org");
final XPathExecutable accept = repository.createXPath("//n2:*", ns2);
- final ScenarioBuilder builder = createScenarioConfiguration();
+ final ScenarioBuilder builder = createScenario();
builder.getNamespaces().clear();
builder.match(match).acceptWith(accept).declareNamespace("n3", "http://n3.org");
@@ -111,7 +111,7 @@ public class ScenarioBuilderTest {
final ContentRepository repository = Simple.createContentRepository();
final XPathExecutable match = repository.createXPath("//*", null);
final XPathExecutable accept = repository.createXPath("//*", null);
- final ScenarioBuilder builder = createScenarioConfiguration();
+ final ScenarioBuilder builder = createScenario();
builder.getNamespaces().clear();
builder.match(match);
@@ -128,7 +128,7 @@ public class ScenarioBuilderTest {
public void testBasicAttributes() {
final ContentRepository repository = Simple.createContentRepository();
final String random = RandomStringUtils.random(5);
- final ScenarioBuilder builder = createScenarioConfiguration();
+ final ScenarioBuilder builder = createScenario();
builder.name(random).description(random);
final Result result = builder.build(repository);
assertThat(result.isValid()).isTrue();
@@ -141,7 +141,7 @@ public class ScenarioBuilderTest {
@Test
public void testNoBasicAttributes() {
final ContentRepository repository = Simple.createContentRepository();
- final ScenarioBuilder builder = createScenarioConfiguration();
+ final ScenarioBuilder builder = createScenario();
builder.name(null);
final Result result = builder.build(repository);
assertThat(result.isValid()).isTrue();
diff --git a/src/test/java/de/kosit/validationtool/config/SimpleConfigTest.java b/src/test/java/de/kosit/validationtool/config/SimpleConfigTest.java
index d6f50c2..f4374ec 100644
--- a/src/test/java/de/kosit/validationtool/config/SimpleConfigTest.java
+++ b/src/test/java/de/kosit/validationtool/config/SimpleConfigTest.java
@@ -1,13 +1,9 @@
package de.kosit.validationtool.config;
import static de.kosit.validationtool.config.ConfigurationBuilder.fallback;
-import static de.kosit.validationtool.config.ConfigurationBuilder.report;
-import static de.kosit.validationtool.config.ConfigurationBuilder.scenario;
-import static de.kosit.validationtool.config.ConfigurationBuilder.schema;
+import static de.kosit.validationtool.config.TestScenarioFactory.createScenario;
import static org.assertj.core.api.Assertions.assertThat;
-import java.net.URI;
-
import org.junit.Test;
import de.kosit.validationtool.api.Configuration;
@@ -33,18 +29,12 @@ public class SimpleConfigTest {
}
static ConfigurationBuilder createSimpleConfiguration() {
- return Configuration.create().name("Simple-API").with(createScenarioConfiguration()
+ return Configuration.create().name("Simple-API").with(createScenario()
// .description("awesome api")
).with(fallback().name("default").source("report.xsl"))
.resolvingMode(ResolvingMode.STRICT_RELATIVE).useRepository(Simple.REPOSITORY_URI);
}
- static ScenarioBuilder createScenarioConfiguration() {
- return scenario("simple").validate(schema("Sample Schema").schemaLocation(URI.create("simple.xsd")))
- .with(report("Report für eRechnung").source("report.xsl")).acceptWith("count(//test:rejected) = 0")
- .declareNamespace("cri", "http://www.xoev.de/de/validator/framework/1/createreportinput")
- .declareNamespace("rpt", "http://validator.kosit.de/test-report")
- .declareNamespace("test", "http://validator.kosit.de/test-sample").match("/test:simple");
- }
+
}
diff --git a/src/test/java/de/kosit/validationtool/config/TestScenarioFactory.java b/src/test/java/de/kosit/validationtool/config/TestScenarioFactory.java
new file mode 100644
index 0000000..61772d1
--- /dev/null
+++ b/src/test/java/de/kosit/validationtool/config/TestScenarioFactory.java
@@ -0,0 +1,21 @@
+package de.kosit.validationtool.config;
+
+import static de.kosit.validationtool.config.ConfigurationBuilder.report;
+import static de.kosit.validationtool.config.ConfigurationBuilder.scenario;
+import static de.kosit.validationtool.config.ConfigurationBuilder.schema;
+
+import java.net.URI;
+
+/**
+ * @author Andreas Penski
+ */
+public class TestScenarioFactory {
+
+ public static ScenarioBuilder createScenario() {
+ return scenario("simple").validate(schema("Sample Schema").schemaLocation(URI.create("simple.xsd")))
+ .with(report("Report für eRechnung").source("report.xsl")).acceptWith("count(//test:rejected) = 0")
+ .declareNamespace("cri", "http://www.xoev.de/de/validator/framework/1/createreportinput")
+ .declareNamespace("rpt", "http://validator.kosit.de/test-report")
+ .declareNamespace("test", "http://validator.kosit.de/test-sample").match("/test:simple");
+ }
+}
diff --git a/src/test/java/de/kosit/validationtool/impl/Helper.java b/src/test/java/de/kosit/validationtool/impl/Helper.java
index f06d755..a19a61c 100644
--- a/src/test/java/de/kosit/validationtool/impl/Helper.java
+++ b/src/test/java/de/kosit/validationtool/impl/Helper.java
@@ -82,6 +82,7 @@ public class Helper {
return new ContentRepository(strategy, Simple.REPOSITORY_URI);
}
+
public static URI getSchemaLocation() {
return ROOT.resolve("repository/simple.xsd");
}
diff --git a/src/test/java/de/kosit/validationtool/impl/tasks/CreateReportActionTest.java b/src/test/java/de/kosit/validationtool/impl/tasks/CreateReportActionTest.java
new file mode 100644
index 0000000..fe6acb3
--- /dev/null
+++ b/src/test/java/de/kosit/validationtool/impl/tasks/CreateReportActionTest.java
@@ -0,0 +1,86 @@
+package de.kosit.validationtool.impl.tasks;
+
+import static de.kosit.validationtool.config.TestScenarioFactory.createScenario;
+import static de.kosit.validationtool.impl.Helper.serialize;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import javax.xml.transform.Source;
+
+import org.hamcrest.Matchers;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import de.kosit.validationtool.api.InputFactory;
+import de.kosit.validationtool.impl.ContentRepository;
+import de.kosit.validationtool.impl.ConversionService;
+import de.kosit.validationtool.impl.Helper.Simple;
+import de.kosit.validationtool.impl.Scenario;
+import de.kosit.validationtool.impl.model.Result;
+import de.kosit.validationtool.impl.tasks.CheckAction.Bag;
+
+import net.sf.saxon.s9api.DocumentBuilder;
+import net.sf.saxon.s9api.Processor;
+import net.sf.saxon.s9api.SaxonApiException;
+
+/**
+ * Test for {@link CreateReportAction}.
+ *
+ * @author Andreas Penski
+ */
+public class CreateReportActionTest {
+
+ private CreateReportAction action;
+
+ private ContentRepository repository;
+
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ @Before
+ public void setup() {
+ this.repository = Simple.createContentRepository();
+ this.action = new CreateReportAction(this.repository.getProcessor(), new ConversionService(), this.repository.getResolver());
+ }
+
+ @Test
+ public void testSimpleCreate() {
+ final Bag bag = TestBagBuilder.createBag(true, true);
+ final Scenario scenario = createScenario().build(this.repository).getObject();
+ bag.setScenarioSelectionResult(new Result<>(scenario));
+ bag.setReport(null);
+ this.action.check(bag);
+ assertThat(bag.getReport()).isNotNull();
+ }
+
+ @Test
+ public void testNoValidParseResult() {
+ // e.g. no valid xml file specified
+ final Bag bag = TestBagBuilder.createBag(InputFactory.read("someBytes".getBytes(), "invalid"), true);
+ final Scenario scenario = createScenario().build(this.repository).getObject();
+ bag.setScenarioSelectionResult(new Result<>(scenario));
+ assertThat(bag.getReport()).isNull();
+ this.action.check(bag);
+ assertThat(bag.getReport()).isNotNull();
+ final String reportString = serialize(bag.getReport());
+ assertThat(reportString).contains("SAXParseException");
+ }
+
+ @Test
+ public void testExecutionException() throws SaxonApiException {
+ this.expectedException.expect(IllegalStateException.class);
+ this.expectedException.expectMessage(Matchers.containsString("Can not create final report"));
+ final Processor p = mock(Processor.class);
+ final DocumentBuilder documentBuilder = mock(DocumentBuilder.class);
+ this.action = new CreateReportAction(p, new ConversionService(), null);
+
+ when(p.newDocumentBuilder()).thenReturn(documentBuilder);
+ when(documentBuilder.build(any(Source.class))).thenThrow(new SaxonApiException("mocked"));
+ this.action.check(TestBagBuilder.createBag(InputFactory.read(Simple.SIMPLE_VALID), true));
+
+ }
+}
diff --git a/src/test/java/de/kosit/validationtool/impl/DocumentParseActionTest.java b/src/test/java/de/kosit/validationtool/impl/tasks/DocumentParseActionTest.java
similarity index 96%
rename from src/test/java/de/kosit/validationtool/impl/DocumentParseActionTest.java
rename to src/test/java/de/kosit/validationtool/impl/tasks/DocumentParseActionTest.java
index 5f98181..8e276ad 100644
--- a/src/test/java/de/kosit/validationtool/impl/DocumentParseActionTest.java
+++ b/src/test/java/de/kosit/validationtool/impl/tasks/DocumentParseActionTest.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package de.kosit.validationtool.impl;
+package de.kosit.validationtool.impl.tasks;
import static de.kosit.validationtool.api.InputFactory.read;
import static org.assertj.core.api.Assertions.assertThat;
@@ -27,9 +27,9 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import de.kosit.validationtool.impl.Helper;
import de.kosit.validationtool.impl.Helper.Simple;
import de.kosit.validationtool.impl.model.Result;
-import de.kosit.validationtool.impl.tasks.DocumentParseAction;
import de.kosit.validationtool.model.reportInput.XMLSyntaxError;
import net.sf.saxon.s9api.XdmNode;
diff --git a/src/test/java/de/kosit/validationtool/impl/xml/BaseResolverTest.java b/src/test/java/de/kosit/validationtool/impl/xml/BaseResolverTest.java
new file mode 100644
index 0000000..51a2871
--- /dev/null
+++ b/src/test/java/de/kosit/validationtool/impl/xml/BaseResolverTest.java
@@ -0,0 +1,65 @@
+package de.kosit.validationtool.impl.xml;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import javax.xml.XMLConstants;
+import javax.xml.validation.SchemaFactory;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.xml.sax.SAXNotRecognizedException;
+import org.xml.sax.SAXNotSupportedException;
+
+import lombok.RequiredArgsConstructor;
+
+/**
+ *
+ * Tests the internal functions used to create a secure resolver
+ *
+ * @author Andreas Penski
+ */
+public class BaseResolverTest {
+
+ @RequiredArgsConstructor
+ private class TestResolvingStrategy extends StrictRelativeResolvingStrategy {
+
+ void setInternalProperty(final SchemaFactory factory, final boolean lenient) {
+ allowExternalSchema(factory, lenient, "quatsch");
+ }
+ }
+
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ @Test
+ public void testIgnoreUnsupportedProperty() throws SAXNotRecognizedException, SAXNotSupportedException {
+ final SchemaFactory sf = mock(SchemaFactory.class);
+ final TestResolvingStrategy s = new TestResolvingStrategy();
+ doThrow(new SAXNotRecognizedException("not supported")).when(sf).setProperty(any(), any());
+ s.setInternalProperty(sf, true);
+ }
+
+ @Test
+ public void testFailOnUnsupportedProperty() throws SAXNotRecognizedException, SAXNotSupportedException {
+ this.expectedException.expect(IllegalStateException.class);
+ final SchemaFactory sf = mock(SchemaFactory.class);
+ final TestResolvingStrategy s = new TestResolvingStrategy();
+ doThrow(new SAXNotRecognizedException("not supported")).when(sf).setProperty(any(), any());
+ s.setInternalProperty(sf, false);
+ }
+
+ @Test
+ public void testSimpleSuccess() throws SAXNotRecognizedException, SAXNotSupportedException {
+ final SchemaFactory sf = mock(SchemaFactory.class);
+ final TestResolvingStrategy s = new TestResolvingStrategy();
+ s.setInternalProperty(sf, true);
+ s.setInternalProperty(sf, false);
+ verify(sf, times(2)).setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "quatsch");
+ }
+
+}
From 7abc07291101bf489e80db3d3a70437281b1f279 Mon Sep 17 00:00:00 2001
From: "Andreas Penski (init)"
Date: Thu, 30 Apr 2020 17:57:02 +0200
Subject: [PATCH 061/306] cleanup
---
.../kosit/validationtool/cmd/DemoBuilder.java | 69 -------------------
.../impl/xml/BaseResolvingStrategy.java | 7 +-
2 files changed, 3 insertions(+), 73 deletions(-)
delete mode 100644 src/main/java/de/kosit/validationtool/cmd/DemoBuilder.java
diff --git a/src/main/java/de/kosit/validationtool/cmd/DemoBuilder.java b/src/main/java/de/kosit/validationtool/cmd/DemoBuilder.java
deleted file mode 100644
index 074d08d..0000000
--- a/src/main/java/de/kosit/validationtool/cmd/DemoBuilder.java
+++ /dev/null
@@ -1,69 +0,0 @@
-package de.kosit.validationtool.cmd;
-
-import static de.kosit.validationtool.config.ConfigurationBuilder.defaultFallback;
-import static de.kosit.validationtool.config.ConfigurationBuilder.report;
-import static de.kosit.validationtool.config.ConfigurationBuilder.scenario;
-import static de.kosit.validationtool.config.ConfigurationBuilder.schema;
-import static de.kosit.validationtool.config.ConfigurationBuilder.schematron;
-
-import java.net.URI;
-
-import javax.xml.validation.Schema;
-
-import de.kosit.validationtool.api.Configuration;
-import de.kosit.validationtool.config.FallbackBuilder;
-import de.kosit.validationtool.config.ScenarioBuilder;
-import de.kosit.validationtool.impl.ResolvingMode;
-
-import net.sf.saxon.s9api.XPathExecutable;
-
-/**
- * @author Andreas Penski
- */
-public class DemoBuilder {
-
- public static void main(final String[] args) {
- final XPathExecutable xpath = null;
- // @formatter:off
- Configuration
- .create()
- .name("some config")
- .resolvingMode(ResolvingMode.JDK_SUPPORTED)
- .with(scenario("s1").match("//name").validate(schema("http://some.schema.url")).description("some desc"))
- .with(scenario("s2")
- .match(xpath)
- .acceptWith(xpath)
- .validate(schema(URI.create("http://some.other.schema.url")))
- .validate(schematron("some checks").source("some-schematron.xsl"))
- .with(report("myReport").source(URI.create("some.xsl")))
- .description("some desc"))
- .with(defaultFallback())
-
- .build();
-
- Configuration
- .create()
- .name("xrechnung")
- .resolvingMode(ResolvingMode.STRICT_LOCAL)
- .with( ubl() )
- .with(cii())
- .with( myFallback())
- .build();
- // @formatter:on
- }
-
- private static ScenarioBuilder cii() {
- return null;
- }
-
- private static FallbackBuilder myFallback() {
- return new FallbackBuilder();
- }
-
- private static ScenarioBuilder ubl() {
- final Schema schema = null; // load somehow
- final ScenarioBuilder ubl = scenario("ubl");
- ubl.validate(schema("someSchema", schema));
- return ubl;
- }
-}
diff --git a/src/main/java/de/kosit/validationtool/impl/xml/BaseResolvingStrategy.java b/src/main/java/de/kosit/validationtool/impl/xml/BaseResolvingStrategy.java
index e8ea274..3b548fb 100644
--- a/src/main/java/de/kosit/validationtool/impl/xml/BaseResolvingStrategy.java
+++ b/src/main/java/de/kosit/validationtool/impl/xml/BaseResolvingStrategy.java
@@ -6,8 +6,7 @@ import javax.xml.XMLConstants;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;
-import org.xml.sax.SAXNotRecognizedException;
-import org.xml.sax.SAXNotSupportedException;
+import org.xml.sax.SAXException;
import lombok.extern.slf4j.Slf4j;
@@ -61,7 +60,7 @@ public abstract class BaseResolvingStrategy implements ResolvingConfigurationStr
private void setProperty(final PropertySetter setter, final boolean lenient, final String errorMessage) {
try {
setter.apply();
- } catch (final SAXNotRecognizedException | SAXNotSupportedException e) {
+ } catch (final SAXException e) {
if (lenient) {
log.warn(errorMessage);
@@ -117,6 +116,6 @@ public abstract class BaseResolvingStrategy implements ResolvingConfigurationStr
@FunctionalInterface
private interface PropertySetter {
- void apply() throws SAXNotRecognizedException, SAXNotSupportedException;
+ void apply() throws SAXException;
}
}
From 1a001a1af46addbc91f2854b5351f798f5e16dd6 Mon Sep 17 00:00:00 2001
From: "Andreas Penski (init)"
Date: Fri, 1 May 2020 13:47:40 +0200
Subject: [PATCH 062/306] more tests
---
.../validationtool/config/SchemaBuilder.java | 2 +-
.../impl/xml/RelativeUriResolver.java | 9 +-
.../cmd/CommandlineApplicationTest.java | 9 ++
.../config/SchemaBuilderTest.java | 93 +++++++++++++++++++
.../de/kosit/validationtool/impl/Helper.java | 4 +-
.../impl/RelativeUriResolverTest.java | 2 +-
6 files changed, 115 insertions(+), 4 deletions(-)
create mode 100644 src/test/java/de/kosit/validationtool/config/SchemaBuilderTest.java
diff --git a/src/main/java/de/kosit/validationtool/config/SchemaBuilder.java b/src/main/java/de/kosit/validationtool/config/SchemaBuilder.java
index ca51060..3c7aa1d 100644
--- a/src/main/java/de/kosit/validationtool/config/SchemaBuilder.java
+++ b/src/main/java/de/kosit/validationtool/config/SchemaBuilder.java
@@ -57,7 +57,7 @@ public class SchemaBuilder implements Builder, String> result = builder.build(Simple.createContentRepository());
+ assertThat(result).isNotNull();
+ assertThat(result.isValid()).isTrue();
+ }
+
+ @Test
+ public void testNoConfiguration() {
+ final SchemaBuilder builder = schema("no-config");
+ final Result, String> result = builder.build(Simple.createContentRepository());
+ assertThat(result).isNotNull();
+ assertThat(result.isValid()).isFalse();
+ }
+
+ @Test
+ public void testBuildNamedSchema() {
+ final SchemaBuilder builder = schema("myname").schemaLocation(Simple.SCHEMA);
+ final Result, String> result = builder.build(Simple.createContentRepository());
+ assertThat(result).isNotNull();
+ assertThat(result.isValid()).isTrue();
+ assertThat(result.getObject().getKey().getResource().stream().map(ResourceType::getName).findFirst().get()).isEqualTo("myname");
+ }
+
+ @Test
+ public void testInvalidSchema() {
+ final SchemaBuilder builder = schema("myname").schemaLocation(Simple.INVALID);
+ final Result, String> result = builder.build(Simple.createContentRepository());
+ assertThat(result).isNotNull();
+ assertThat(result.isValid()).isFalse();
+ }
+
+ @Test
+ public void testNonExisting() {
+ final SchemaBuilder builder = schema("myname").schemaLocation(Simple.REPOSITORY_URI.resolve("doesNotExist.xsd"));
+ final Result, String> result = builder.build(Simple.createContentRepository());
+ assertThat(result).isNotNull();
+ assertThat(result.isValid()).isFalse();
+ }
+
+ @Test
+ public void testPath() {
+ final SchemaBuilder builder = schema("myname").schemaLocation(Paths.get(Simple.SCHEMA));
+ final Result, String> result = builder.build(Simple.createContentRepository());
+ assertThat(result).isNotNull();
+ assertThat(result.isValid()).isTrue();
+ }
+
+ @Test
+ public void testStringLocation() {
+ final SchemaBuilder builder = schema("myname").schemaLocation("simple.xsd");
+ final Result, String> result = builder.build(Simple.createContentRepository());
+ assertThat(result).isNotNull();
+ assertThat(result.isValid()).isTrue();
+ }
+
+ @Test
+ public void testPrecompiled() {
+ final ContentRepository repository = Simple.createContentRepository();
+ final Schema schema = repository.createSchema(Simple.SCHEMA);
+
+ final SchemaBuilder builder = schema("myname").schema(schema);
+ final Result, String> result = builder.build(repository);
+ assertThat(result).isNotNull();
+ assertThat(result.isValid()).isTrue();
+ }
+}
diff --git a/src/test/java/de/kosit/validationtool/impl/Helper.java b/src/test/java/de/kosit/validationtool/impl/Helper.java
index a19a61c..d0ca817 100644
--- a/src/test/java/de/kosit/validationtool/impl/Helper.java
+++ b/src/test/java/de/kosit/validationtool/impl/Helper.java
@@ -77,6 +77,8 @@ public class Helper {
public static final URI REPORT_XSL = REPOSITORY_URI.resolve("report.xsl");
+ public static final URI SCHEMA = REPOSITORY_URI.resolve("simple.xsd");
+
public static final ContentRepository createContentRepository() {
final ResolvingConfigurationStrategy strategy = ResolvingMode.STRICT_RELATIVE.getStrategy();
return new ContentRepository(strategy, Simple.REPOSITORY_URI);
@@ -84,7 +86,7 @@ public class Helper {
public static URI getSchemaLocation() {
- return ROOT.resolve("repository/simple.xsd");
+ return SCHEMA;
}
}
diff --git a/src/test/java/de/kosit/validationtool/impl/RelativeUriResolverTest.java b/src/test/java/de/kosit/validationtool/impl/RelativeUriResolverTest.java
index 2106f65..925fa26 100644
--- a/src/test/java/de/kosit/validationtool/impl/RelativeUriResolverTest.java
+++ b/src/test/java/de/kosit/validationtool/impl/RelativeUriResolverTest.java
@@ -58,7 +58,7 @@ public class RelativeUriResolverTest {
private URIResolver resolver = new RelativeUriResolver(BASE);
@Test
- public void testSucces() throws TransformerException {
+ public void testSuccess() throws TransformerException {
final Source resource = this.resolver.resolve("ubl-0001.xml", BASE.toASCIIString());
assertThat(resource).isNotNull();
}
From 7dc62012a6939f3698b6d101fa8f2366584f13a3 Mon Sep 17 00:00:00 2001
From: Andreas Penski <18-andreas.penski@users.noreply.projekte.kosit.org>
Date: Sun, 3 May 2020 16:52:55 +0200
Subject: [PATCH 063/306] some cleanup
---
.idea/compiler.xml | 1 +
.idea/misc.xml | 2 +-
CHANGELOG.md | 11 +++++--
docs/api.md | 2 +-
.../api/AcceptRecommendation.java | 7 ++--
.../validationtool/api/Configuration.java | 28 +++++++++-------
.../api/ResolvingConfigurationStrategy.java | 14 +++++---
.../cmd/CommandLineApplication.java | 1 +
.../config/ConfigurationBuilder.java | 13 +++++++-
.../config/ConfigurationLoader.java | 16 +++++++++
.../config/FallbackBuilder.java | 2 ++
.../validationtool/config/XPathBuilder.java | 2 +-
.../impl/EngineInformation.java | 6 ++++
.../impl/tasks/ComputeAcceptanceAction.java | 2 +-
.../impl/tasks/CreateReportAction.java | 5 ++-
.../impl/xml/RelativeUriResolver.java | 13 +-------
.../impl/xml/RemoteResolvingStrategy.java | 7 ++++
.../xml/StrictLocalResolvingStrategy.java | 19 ++++++++---
.../xml/StrictRelativeResolvingStrategy.java | 1 +
src/main/model/xsd/daemon.xsd | 1 -
.../impl/tasks/CreateReportActionTest.java | 8 ++---
.../resources/examples/simple/assertions.xml | 33 +++++++++++++++++++
22 files changed, 144 insertions(+), 50 deletions(-)
create mode 100644 src/main/java/de/kosit/validationtool/impl/xml/RemoteResolvingStrategy.java
create mode 100644 src/test/resources/examples/simple/assertions.xml
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index 9f64100..bea581f 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -8,6 +8,7 @@
+
diff --git a/.idea/misc.xml b/.idea/misc.xml
index f207c86..3ab06a4 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -79,7 +79,7 @@
-
+
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ec9e2ce..07e06a0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,12 +9,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## next version (unreleased)
### Added
-
-- Support java.xml.transform.Source/java.xml.transform.StreamSource as Input
+- Added a builder style configuration API to configure scenarios
+- Added an option to configure xml security e.g. to load from http sources or not from a specific repository
+(so loading is configurable less restrictive, default strategy is to only load from a local repository)
+- Support java.xml.transform.Source as Input
### Changed
-
- Inputs are NOT read into memory (e.g. Byte-Array) prior processing within the validator. This reduces memory consumption.
+- CheckConfiguration is deprecated now. Use Configuration.load(...) or Configuration.build(...)
+- Overall processing of xml files is based on Saxon s9api. No JAXP or SAX classes are used by
+the validator (this further improves performance and memory consumption)
+-
## UNRELEASED
### Fixed
diff --git a/docs/api.md b/docs/api.md
index 31d05ab..e00f0ea 100644
--- a/docs/api.md
+++ b/docs/api.md
@@ -56,7 +56,7 @@ public class StandardExample {
// Load scenarios.xml from classpath
URL scenarios = this.getClass().getClassLoader().getResource("scenarios.xml");
// Load the rest of the specific Validator configuration from classpath
- CheckConfiguration config = new CheckConfiguration(scenarios.toURI());
+ Configuration config = Configuration.load(scenarios.toURI());
// Use the default validation procedure
Check validator = new DefaultCheck(config);
// Validate a single document
diff --git a/src/main/java/de/kosit/validationtool/api/AcceptRecommendation.java b/src/main/java/de/kosit/validationtool/api/AcceptRecommendation.java
index c491201..479733d 100644
--- a/src/main/java/de/kosit/validationtool/api/AcceptRecommendation.java
+++ b/src/main/java/de/kosit/validationtool/api/AcceptRecommendation.java
@@ -1,21 +1,22 @@
package de.kosit.validationtool.api;
/**
- * Tri-state describtion of a Recommendation.
+ * Tri-state recommendation whether to accept the {@link Input} or not.
*/
public enum AcceptRecommendation {
+
/**
* The evaluation of the overall validation could not be computed.
*/
UNDEFINED,
/**
- * Recommendation is to accept input based on the evaluation of the overall validation.
+ * Recommendation is to accept {@link Input} based on the evaluation of the overall validation.
*/
ACCEPTABLE,
/**
- * Recommendation is to reject input based on the evaluation of the overall validation.
+ * Recommendation is to reject {@link Input} based on the evaluation of the overall validation.
*/
REJECT
}
diff --git a/src/main/java/de/kosit/validationtool/api/Configuration.java b/src/main/java/de/kosit/validationtool/api/Configuration.java
index dbbb53d..9aa6f70 100644
--- a/src/main/java/de/kosit/validationtool/api/Configuration.java
+++ b/src/main/java/de/kosit/validationtool/api/Configuration.java
@@ -12,15 +12,15 @@ import de.kosit.validationtool.impl.Scenario;
/**
* Configuration of the actual {@link Check} instance. This is an interface and can be implemented by custom
* configuration classes. There are two implementations supported out of the box:
- *
+ *
*
*
{@link ConfigurationLoader} implements loading {@link Check} configurations from a scenario.xml file
*
Using a builder style api {@link de.kosit.validationtool.config.ConfigurationBuilder}to configure the
* {@link Check}
*
- *
+ *
* Both methods can be used via convinience methods. See below.
- *
+ *
* @author Andreas Penski
*/
@@ -28,51 +28,57 @@ public interface Configuration {
/**
* Returns a list of configured scenarios.
- *
+ *
* @return the list of scenarios
*/
List getScenarios();
/**
* Returns the configured fallback scenario to use, in case no configured scenario match.
- *
+ *
* @return the fallback scenario
*/
Scenario getFallbackScenario();
/**
* Returns the author of this configuration.
- *
+ *
* @return the author
*/
String getAuthor();
/**
* Returns the name of the specification
- *
+ *
* @return the name
*/
String getName();
/**
* The creation date of the config
- *
+ *
* @return the date
*/
String getDate();
+ /**
+ * Add some additional parameters to the validator configuration. Parameter usage depends on actual implementation of
+ * {@link Check}
+ *
+ * @return
+ */
Map getAdditionalParameters();
/**
* The content repository including resolving strategies.
- *
+ *
* @return the configured {@link ContentRepository}
*/
ContentRepository getContentRepository();
/**
* Loads an XML based scenario definition from the file specified via URI.
- *
+ *
* @param scenarioDefinition the XML file with scenario definition
* @return the loaded configuration
*/
@@ -93,7 +99,7 @@ public interface Configuration {
/**
* Creates a {@link Configuration} based on a builder style API using {@link ConfigurationBuilder}
- *
+ *
* @return the Builder
*/
static ConfigurationBuilder create() {
diff --git a/src/main/java/de/kosit/validationtool/api/ResolvingConfigurationStrategy.java b/src/main/java/de/kosit/validationtool/api/ResolvingConfigurationStrategy.java
index 525499a..86cad76 100644
--- a/src/main/java/de/kosit/validationtool/api/ResolvingConfigurationStrategy.java
+++ b/src/main/java/de/kosit/validationtool/api/ResolvingConfigurationStrategy.java
@@ -10,12 +10,15 @@ import javax.xml.validation.Validator;
import net.sf.saxon.s9api.Processor;
/**
- * Centralized construction and configuration of XML related infrastructore components. The KoSIT Validator provides out
- * of the box implementaions with various security levels.
+ * Centralized construction and configuration of XML related infrastructure components. This interface allows to use
+ * custom implementations and configurations of internal xml related factories and objects.
+ *
+ * The KoSIT Validator provides out of the box implementations with various security levels based on openjdk SAX stack.
*
* If you decide to implement a custom strategy, please be aware of XML security within your stack. The validator
* components beyond this strategy asume secured implementation of the interfaces provided by this strategy. There is no
- * effort to mitigate or prevent xml related security issues such as XXE, loading external sources etc.
+ * effort to mitigate or prevent xml related security issues such as XXE, loading external sources etc. Your would be
+ * responsible for this!
*
* @see de.kosit.validationtool.impl.ResolvingMode
* @author Andreas Penski
@@ -35,12 +38,14 @@ public interface ResolvingConfigurationStrategy {
* leverages the saxon s9api for internal processing e.g. xml reading and writing. So this is the main object to secure
* for reading, transforming and writing xml files.
*
+ * Note: you need exactly one instance for all validator related processing.
+ *
* @return a preconfigured {@link Processor}
*/
Processor getProcessor();
/**
- * Creates a specific implementation for resolving referenced objects in XML files. The URIResolver, it is used for
+ * Creates a specific implementation for resolving referenced objects in XML files. The URIResolver is used for
* dereferencing an absolute URI (after resolution) to return a {@link javax.xml.transform.Source}. It can be
* used for resolving relative URIs against a base URI or restrict access to certain URIs.
*
$');if(i){if("color"===i[2])n.style.background=i[1]+(i[3]||"");else{var a=i[1];A(n,"add","has-mask"),H(i[1])||(a=D(this.router.getBasePath(),i[1])),n.style.backgroundImage="url("+a+")",n.style.backgroundSize="cover",n.style.backgroundPosition="center center"}r=r.replace(i[0],"")}this._renderTo(".cover-main",r),P()}else A(n,"remove","show")},De._updateRender=function(){!function(e){var t=m(".app-name-link"),n=e.config.nameLink,r=e.route.path;if(t)if(c(e.config.nameLink))t.setAttribute("href",n);else if("object"==typeof n){var i=Object.keys(n).filter(function(e){return-1 nav {
+ display: none;
+}
+div#app {
+ font-size: 30px;
+ font-weight: lighter;
+ margin: 40vh auto;
+ text-align: center;
+}
+div#app:empty::before {
+ content: 'Loading...';
+}
+.emoji {
+ height: 1.2rem;
+ vertical-align: middle;
+}
+.progress {
+ background-color: var(--theme-color, #42b983);
+ height: 2px;
+ left: 0px;
+ position: fixed;
+ right: 0px;
+ top: 0px;
+ transition: width 0.2s, opacity 0.4s;
+ width: 0%;
+ z-index: 999999;
+}
+.search a:hover {
+ color: var(--theme-color, #42b983);
+}
+.search .search-keyword {
+ color: var(--theme-color, #42b983);
+ font-style: normal;
+ font-weight: bold;
+}
+html,
+body {
+ height: 100%;
+}
+body {
+ -moz-osx-font-smoothing: grayscale;
+ -webkit-font-smoothing: antialiased;
+ color: #34495e;
+ font-family: 'Source Sans Pro', 'Helvetica Neue', Arial, sans-serif;
+ font-size: 15px;
+ letter-spacing: 0;
+ margin: 0;
+ overflow-x: hidden;
+}
+img {
+ max-width: 100%;
+}
+a[disabled] {
+ cursor: not-allowed;
+ opacity: 0.6;
+}
+kbd {
+ border: solid 1px #ccc;
+ border-radius: 3px;
+ display: inline-block;
+ font-size: 12px !important;
+ line-height: 12px;
+ margin-bottom: 3px;
+ padding: 3px 5px;
+ vertical-align: middle;
+}
+li input[type='checkbox'] {
+ margin: 0 0.2em 0.25em 0;
+ vertical-align: middle;
+}
+.app-nav {
+ margin: 25px 60px 0 0;
+ position: absolute;
+ right: 0;
+ text-align: right;
+ z-index: 10;
+/* navbar dropdown */
+}
+.app-nav.no-badge {
+ margin-right: 25px;
+}
+.app-nav p {
+ margin: 0;
+}
+.app-nav > a {
+ margin: 0 1rem;
+ padding: 5px 0;
+}
+.app-nav ul,
+.app-nav li {
+ display: inline-block;
+ list-style: none;
+ margin: 0;
+}
+.app-nav a {
+ color: inherit;
+ font-size: 16px;
+ text-decoration: none;
+ transition: color 0.3s;
+}
+.app-nav a:hover {
+ color: var(--theme-color, #42b983);
+}
+.app-nav a.active {
+ border-bottom: 2px solid var(--theme-color, #42b983);
+ color: var(--theme-color, #42b983);
+}
+.app-nav li {
+ display: inline-block;
+ margin: 0 1rem;
+ padding: 5px 0;
+ position: relative;
+ cursor: pointer;
+}
+.app-nav li ul {
+ background-color: #fff;
+ border: 1px solid #ddd;
+ border-bottom-color: #ccc;
+ border-radius: 4px;
+ box-sizing: border-box;
+ display: none;
+ max-height: calc(100vh - 61px);
+ overflow-y: auto;
+ padding: 10px 0;
+ position: absolute;
+ right: -15px;
+ text-align: left;
+ top: 100%;
+ white-space: nowrap;
+}
+.app-nav li ul li {
+ display: block;
+ font-size: 14px;
+ line-height: 1rem;
+ margin: 0;
+ margin: 8px 14px;
+ white-space: nowrap;
+}
+.app-nav li ul a {
+ display: block;
+ font-size: inherit;
+ margin: 0;
+ padding: 0;
+}
+.app-nav li ul a.active {
+ border-bottom: 0;
+}
+.app-nav li:hover ul {
+ display: block;
+}
+.github-corner {
+ border-bottom: 0;
+ position: fixed;
+ right: 0;
+ text-decoration: none;
+ top: 0;
+ z-index: 1;
+}
+.github-corner:hover .octo-arm {
+ -webkit-animation: octocat-wave 560ms ease-in-out;
+ animation: octocat-wave 560ms ease-in-out;
+}
+.github-corner svg {
+ color: #fff;
+ fill: var(--theme-color, #42b983);
+ height: 80px;
+ width: 80px;
+}
+main {
+ display: block;
+ position: relative;
+ width: 100vw;
+ height: 100%;
+ z-index: 0;
+}
+main.hidden {
+ display: none;
+}
+.anchor {
+ display: inline-block;
+ text-decoration: none;
+ transition: all 0.3s;
+}
+.anchor span {
+ color: #34495e;
+}
+.anchor:hover {
+ text-decoration: underline;
+}
+.sidebar {
+ border-right: 1px solid rgba(0,0,0,0.07);
+ overflow-y: auto;
+ padding: 40px 0 0;
+ position: absolute;
+ top: 0;
+ bottom: 0;
+ left: 0;
+ transition: transform 250ms ease-out;
+ width: 300px;
+ z-index: 20;
+}
+.sidebar > h1 {
+ margin: 0 auto 1rem;
+ font-size: 1.5rem;
+ font-weight: 300;
+ text-align: center;
+}
+.sidebar > h1 a {
+ color: inherit;
+ text-decoration: none;
+}
+.sidebar > h1 .app-nav {
+ display: block;
+ position: static;
+}
+.sidebar .sidebar-nav {
+ line-height: 2em;
+ padding-bottom: 40px;
+}
+.sidebar li.collapse .app-sub-sidebar {
+ display: none;
+}
+.sidebar ul {
+ margin: 0 0 0 15px;
+ padding: 0;
+}
+.sidebar li > p {
+ font-weight: 700;
+ margin: 0;
+}
+.sidebar ul,
+.sidebar ul li {
+ list-style: none;
+}
+.sidebar ul li a {
+ border-bottom: none;
+ display: block;
+}
+.sidebar ul li ul {
+ padding-left: 20px;
+}
+.sidebar::-webkit-scrollbar {
+ width: 4px;
+}
+.sidebar::-webkit-scrollbar-thumb {
+ background: transparent;
+ border-radius: 4px;
+}
+.sidebar:hover::-webkit-scrollbar-thumb {
+ background: rgba(136,136,136,0.4);
+}
+.sidebar:hover::-webkit-scrollbar-track {
+ background: rgba(136,136,136,0.1);
+}
+.sidebar-toggle {
+ background-color: transparent;
+ background-color: rgba(255,255,255,0.8);
+ border: 0;
+ outline: none;
+ padding: 10px;
+ position: absolute;
+ bottom: 0;
+ left: 0;
+ text-align: center;
+ transition: opacity 0.3s;
+ width: 284px;
+ z-index: 30;
+ cursor: pointer;
+}
+.sidebar-toggle:hover .sidebar-toggle-button {
+ opacity: 0.4;
+}
+.sidebar-toggle span {
+ background-color: var(--theme-color, #42b983);
+ display: block;
+ margin-bottom: 4px;
+ width: 16px;
+ height: 2px;
+}
+body.sticky .sidebar,
+body.sticky .sidebar-toggle {
+ position: fixed;
+}
+.content {
+ padding-top: 60px;
+ position: absolute;
+ top: 0;
+ right: 0;
+ bottom: 0;
+ left: 300px;
+ transition: left 250ms ease;
+}
+.markdown-section {
+ margin: 0 auto;
+ max-width: 80%;
+ padding: 30px 15px 40px 15px;
+ position: relative;
+}
+.markdown-section > * {
+ box-sizing: border-box;
+ font-size: inherit;
+}
+.markdown-section > :first-child {
+ margin-top: 0 !important;
+}
+.markdown-section hr {
+ border: none;
+ border-bottom: 1px solid #eee;
+ margin: 2em 0;
+}
+.markdown-section iframe {
+ border: 1px solid #eee;
+/* fix horizontal overflow on iOS Safari */
+ width: 1px;
+ min-width: 100%;
+}
+.markdown-section table {
+ border-collapse: collapse;
+ border-spacing: 0;
+ display: block;
+ margin-bottom: 1rem;
+ overflow: auto;
+ width: 100%;
+}
+.markdown-section th {
+ border: 1px solid #ddd;
+ font-weight: bold;
+ padding: 6px 13px;
+}
+.markdown-section td {
+ border: 1px solid #ddd;
+ padding: 6px 13px;
+}
+.markdown-section tr {
+ border-top: 1px solid #ccc;
+}
+.markdown-section tr:nth-child(2n) {
+ background-color: #f8f8f8;
+}
+.markdown-section p.tip {
+ background-color: #f8f8f8;
+ border-bottom-right-radius: 2px;
+ border-left: 4px solid #f66;
+ border-top-right-radius: 2px;
+ margin: 2em 0;
+ padding: 12px 24px 12px 30px;
+ position: relative;
+}
+.markdown-section p.tip:before {
+ background-color: #f66;
+ border-radius: 100%;
+ color: #fff;
+ content: '!';
+ font-family: 'Dosis', 'Source Sans Pro', 'Helvetica Neue', Arial, sans-serif;
+ font-size: 14px;
+ font-weight: bold;
+ left: -12px;
+ line-height: 20px;
+ position: absolute;
+ height: 20px;
+ width: 20px;
+ text-align: center;
+ top: 14px;
+}
+.markdown-section p.tip code {
+ background-color: #efefef;
+}
+.markdown-section p.tip em {
+ color: #34495e;
+}
+.markdown-section p.warn {
+ background: rgba(66,185,131,0.1);
+ border-radius: 2px;
+ padding: 1rem;
+}
+.markdown-section ul.task-list > li {
+ list-style-type: none;
+}
+body.close .sidebar {
+ transform: translateX(-300px);
+}
+body.close .sidebar-toggle {
+ width: auto;
+}
+body.close .content {
+ left: 0;
+}
+@media print {
+ .github-corner,
+ .sidebar-toggle,
+ .sidebar,
+ .app-nav {
+ display: none;
+ }
+}
+@media screen and (max-width: 768px) {
+ .github-corner,
+ .sidebar-toggle,
+ .sidebar {
+ position: fixed;
+ }
+ .app-nav {
+ margin-top: 16px;
+ }
+ .app-nav li ul {
+ top: 30px;
+ }
+ main {
+ height: auto;
+ overflow-x: hidden;
+ }
+ .sidebar {
+ left: -300px;
+ transition: transform 250ms ease-out;
+ }
+ .content {
+ left: 0;
+ max-width: 100vw;
+ position: static;
+ padding-top: 20px;
+ transition: transform 250ms ease;
+ }
+ .app-nav,
+ .github-corner {
+ transition: transform 250ms ease-out;
+ }
+ .sidebar-toggle {
+ background-color: transparent;
+ width: auto;
+ padding: 30px 30px 10px 10px;
+ }
+ body.close .sidebar {
+ transform: translateX(300px);
+ }
+ body.close .sidebar-toggle {
+ background-color: rgba(255,255,255,0.8);
+ transition: 1s background-color;
+ width: 284px;
+ padding: 10px;
+ }
+ body.close .content {
+ transform: translateX(300px);
+ }
+ body.close .app-nav,
+ body.close .github-corner {
+ display: none;
+ }
+ .github-corner:hover .octo-arm {
+ -webkit-animation: none;
+ animation: none;
+ }
+ .github-corner .octo-arm {
+ -webkit-animation: octocat-wave 560ms ease-in-out;
+ animation: octocat-wave 560ms ease-in-out;
+ }
+}
+@-webkit-keyframes octocat-wave {
+ 0%, 100% {
+ transform: rotate(0);
+ }
+ 20%, 60% {
+ transform: rotate(-25deg);
+ }
+ 40%, 80% {
+ transform: rotate(10deg);
+ }
+}
+@keyframes octocat-wave {
+ 0%, 100% {
+ transform: rotate(0);
+ }
+ 20%, 60% {
+ transform: rotate(-25deg);
+ }
+ 40%, 80% {
+ transform: rotate(10deg);
+ }
+}
+section.cover {
+ align-items: center;
+ background-position: center center;
+ background-repeat: no-repeat;
+ background-size: cover;
+ height: 100vh;
+ display: none;
+}
+section.cover.show {
+ display: flex;
+}
+section.cover.has-mask .mask {
+ background-color: #fff;
+ opacity: 0.8;
+ position: absolute;
+ top: 0;
+ height: 100%;
+ width: 100%;
+}
+section.cover .cover-main {
+ flex: 1;
+ margin: -20px 16px 0;
+ text-align: center;
+ z-index: 1;
+}
+section.cover a {
+ color: inherit;
+ text-decoration: none;
+}
+section.cover a:hover {
+ text-decoration: none;
+}
+section.cover p {
+ line-height: 1.5rem;
+ margin: 1em 0;
+}
+section.cover h1 {
+ color: inherit;
+ font-size: 2.5rem;
+ font-weight: 300;
+ margin: 0.625rem 0 2.5rem;
+ position: relative;
+ text-align: center;
+}
+section.cover h1 a {
+ display: block;
+}
+section.cover h1 small {
+ bottom: -0.4375rem;
+ font-size: 1rem;
+ position: absolute;
+}
+section.cover blockquote {
+ font-size: 1.5rem;
+ text-align: center;
+}
+section.cover ul {
+ line-height: 1.8;
+ list-style-type: none;
+ margin: 1em auto;
+ max-width: 500px;
+ padding: 0;
+}
+section.cover .cover-main > p:last-child a {
+ border-color: var(--theme-color, #42b983);
+ border-radius: 2rem;
+ border-style: solid;
+ border-width: 1px;
+ box-sizing: border-box;
+ color: var(--theme-color, #42b983);
+ display: inline-block;
+ font-size: 1.05rem;
+ letter-spacing: 0.1rem;
+ margin: 0.5rem 1rem;
+ padding: 0.75em 2rem;
+ text-decoration: none;
+ transition: all 0.15s ease;
+}
+section.cover .cover-main > p:last-child a:last-child {
+ background-color: var(--theme-color, #42b983);
+ color: #fff;
+}
+section.cover .cover-main > p:last-child a:last-child:hover {
+ color: inherit;
+ opacity: 0.8;
+}
+section.cover .cover-main > p:last-child a:hover {
+ color: inherit;
+}
+section.cover blockquote > p > a {
+ border-bottom: 2px solid var(--theme-color, #42b983);
+ transition: color 0.3s;
+}
+section.cover blockquote > p > a:hover {
+ color: var(--theme-color, #42b983);
+}
+body {
+ background-color: #fff;
+}
+/* sidebar */
+.sidebar {
+ background-color: #fff;
+ color: #364149;
+}
+.sidebar li {
+ margin: 6px 0 6px 0;
+}
+.sidebar ul li a {
+ color: #505d6b;
+ font-size: 14px;
+ font-weight: normal;
+ overflow: hidden;
+ text-decoration: none;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+.sidebar ul li a:hover {
+ text-decoration: underline;
+}
+.sidebar ul li ul {
+ padding: 0;
+}
+.sidebar ul li.active > a {
+ border-right: 2px solid;
+ color: var(--theme-color, #42b983);
+ font-weight: 600;
+}
+.app-sub-sidebar li::before {
+ content: '-';
+ padding-right: 4px;
+ float: left;
+}
+/* markdown content found on pages */
+.markdown-section h1,
+.markdown-section h2,
+.markdown-section h3,
+.markdown-section h4,
+.markdown-section strong {
+ color: #2c3e50;
+ font-weight: 600;
+}
+.markdown-section a {
+ color: var(--theme-color, #42b983);
+ font-weight: 600;
+}
+.markdown-section h1 {
+ font-size: 2rem;
+ margin: 0 0 1rem;
+}
+.markdown-section h2 {
+ font-size: 1.75rem;
+ margin: 45px 0 0.8rem;
+}
+.markdown-section h3 {
+ font-size: 1.5rem;
+ margin: 40px 0 0.6rem;
+}
+.markdown-section h4 {
+ font-size: 1.25rem;
+}
+.markdown-section h5 {
+ font-size: 1rem;
+}
+.markdown-section h6 {
+ color: #777;
+ font-size: 1rem;
+}
+.markdown-section figure,
+.markdown-section p {
+ margin: 1.2em 0;
+}
+.markdown-section p,
+.markdown-section ul,
+.markdown-section ol {
+ line-height: 1.6rem;
+ word-spacing: 0.05rem;
+}
+.markdown-section ul,
+.markdown-section ol {
+ padding-left: 1.5rem;
+}
+.markdown-section blockquote {
+ border-left: 4px solid var(--theme-color, #42b983);
+ color: #858585;
+ margin: 2em 0;
+ padding-left: 20px;
+}
+.markdown-section blockquote p {
+ font-weight: 600;
+ margin-left: 0;
+}
+.markdown-section iframe {
+ margin: 1em 0;
+}
+.markdown-section em {
+ color: #7f8c8d;
+}
+.markdown-section code {
+ background-color: #f8f8f8;
+ border-radius: 2px;
+ color: #e96900;
+ font-family: 'Roboto Mono', Monaco, courier, monospace;
+ font-size: 0.8rem;
+ margin: 0 2px;
+ padding: 3px 5px;
+ white-space: pre-wrap;
+}
+.markdown-section pre {
+ -moz-osx-font-smoothing: initial;
+ -webkit-font-smoothing: initial;
+ background-color: #f8f8f8;
+ font-family: 'Roboto Mono', Monaco, courier, monospace;
+ line-height: 1.5rem;
+ margin: 1.2em 0;
+ overflow: auto;
+ padding: 0 1.4rem;
+ position: relative;
+ word-wrap: normal;
+}
+/* code highlight */
+.token.comment,
+.token.prolog,
+.token.doctype,
+.token.cdata {
+ color: #8e908c;
+}
+.token.namespace {
+ opacity: 0.7;
+}
+.token.boolean,
+.token.number {
+ color: #c76b29;
+}
+.token.punctuation {
+ color: #525252;
+}
+.token.property {
+ color: #c08b30;
+}
+.token.tag {
+ color: #2973b7;
+}
+.token.string {
+ color: var(--theme-color, #42b983);
+}
+.token.selector {
+ color: #6679cc;
+}
+.token.attr-name {
+ color: #2973b7;
+}
+.token.entity,
+.token.url,
+.language-css .token.string,
+.style .token.string {
+ color: #22a2c9;
+}
+.token.attr-value,
+.token.control,
+.token.directive,
+.token.unit {
+ color: var(--theme-color, #42b983);
+}
+.token.keyword,
+.token.function {
+ color: #e96900;
+}
+.token.statement,
+.token.regex,
+.token.atrule {
+ color: #22a2c9;
+}
+.token.placeholder,
+.token.variable {
+ color: #3d8fd1;
+}
+.token.deleted {
+ text-decoration: line-through;
+}
+.token.inserted {
+ border-bottom: 1px dotted #202746;
+ text-decoration: none;
+}
+.token.italic {
+ font-style: italic;
+}
+.token.important,
+.token.bold {
+ font-weight: bold;
+}
+.token.important {
+ color: #c94922;
+}
+.token.entity {
+ cursor: help;
+}
+.markdown-section pre > code {
+ -moz-osx-font-smoothing: initial;
+ -webkit-font-smoothing: initial;
+ background-color: #f8f8f8;
+ border-radius: 2px;
+ color: #525252;
+ display: block;
+ font-family: 'Roboto Mono', Monaco, courier, monospace;
+ font-size: 0.8rem;
+ line-height: inherit;
+ margin: 0 2px;
+ max-width: inherit;
+ overflow: inherit;
+ padding: 2.2em 5px;
+ white-space: inherit;
+}
+.markdown-section code::after,
+.markdown-section code::before {
+ letter-spacing: 0.05rem;
+}
+code .token {
+ -moz-osx-font-smoothing: initial;
+ -webkit-font-smoothing: initial;
+ min-height: 1.5rem;
+ position: relative;
+ left: auto;
+}
+pre::after {
+ color: #ccc;
+ content: attr(data-lang);
+ font-size: 0.6rem;
+ font-weight: 600;
+ height: 15px;
+ line-height: 15px;
+ padding: 5px 10px 0;
+ position: absolute;
+ right: 0;
+ text-align: right;
+ top: 0;
+}
diff --git a/src/test/java/de/kosit/validationtool/daemon/CheckHandlerIT.java b/src/test/java/de/kosit/validationtool/daemon/CheckHandlerIT.java
index 86e74f0..9aef88b 100644
--- a/src/test/java/de/kosit/validationtool/daemon/CheckHandlerIT.java
+++ b/src/test/java/de/kosit/validationtool/daemon/CheckHandlerIT.java
@@ -17,15 +17,12 @@ import io.restassured.http.ContentType;
* Testet the Daemon-Mode input , Methoden , Output Content-Type and the success case
*
* @author Roula Antoun
+ * @author Andreas Penski
*/
public class CheckHandlerIT extends BaseIT {
-
private static final String APPLICATION_XML = "application/xml";
-
-
-
@Test
public void makeSureThatSuccessTest() throws IOException {
try ( final InputStream io = Simple.SIMPLE_VALID.toURL().openStream() ) {
@@ -50,15 +47,7 @@ public class CheckHandlerIT extends BaseIT {
return IOUtils.toByteArray(io);
}
- @Test
- public void methodNotAllowedTest() {
- given().when().get("/").then().statusCode(405);
- given().when().put("/").then().statusCode(405);
- given().when().patch("/").then().statusCode(405);
- given().when().delete("/").then().statusCode(405);
- given().when().head("/").then().statusCode(405);
- given().when().options("/").then().statusCode(405);
- }
+
@Test
public void xmlResultTest() throws IOException {
From b02126c1ccbd29232818742c4dce931e87a21dd3 Mon Sep 17 00:00:00 2001
From: Andreas Penski <18-andreas.penski@users.noreply.projekte.kosit.org>
Date: Wed, 6 May 2020 17:11:35 +0200
Subject: [PATCH 070/306] documentation for the daemon
---
README.md | 5 +-
docs/daemon.md | 87 +++++++++++++++++++
pom.xml | 6 ++
.../kosit/validationtool/daemon/Daemon.java | 25 ++++--
.../validationtool/daemon/RoutingHandler.java | 5 +-
5 files changed, 114 insertions(+), 14 deletions(-)
create mode 100644 docs/daemon.md
diff --git a/README.md b/README.md
index ee08010..c4672f7 100644
--- a/README.md
+++ b/README.md
@@ -97,8 +97,5 @@ You can configure it with `-H` for IP Adress and `-P` for port number:
java -jar validationtool--standalone.jar -s -D -H 192.168.1.x -P 8081
```
-You can HTTP-POST to `/` and the response will return the report document as defined in your validator configuration.
-
-Additionally there is the GET `/health` endpoint which can be used by monitoring systems.
-
+Details and further configuration options can be [found here](./docs/daemon.md).
diff --git a/docs/daemon.md b/docs/daemon.md
new file mode 100644
index 0000000..577a4c8
--- /dev/null
+++ b/docs/daemon.md
@@ -0,0 +1,87 @@
+# Validator daemon
+You can also start the validator as a HTTP-Server. This is based JDK http server functionality. Keep that mind, if you want to deploy this
+in production scenarios with heavy load.
+
+## Basic usage
+To just use the validator daemon as is, start the _Daemon-Mode_ with the `-D` option.
+
+```shell
+java -jar validationtool--standalone.jar -s -D
+```
+
+Per default the HTTP-Server listens on _localhost_ at Port 8080.
+
+You can configure it with `-H` for IP Adress and `-P` for port number:
+
+```shell
+java -jar validationtool--standalone.jar -s -D -H 192.168.1.x -P 8081
+```
+
+## Customized usage
+You can also leverage the API to create a customized version of the Daemon. Just instantiate, configure and start the daemon like this:
+
+````java
+Configuration config = Configuration.load(...);
+
+Daemon daemon = new Daemon();
+daemon.setPort("8090");
+// further config goes here
+daemon.startServer(config);
+````
+
+The possible customizations are:
+
+* `bindAddress` - the interface to bind the daemon to
+* `port` - the port to expose
+* `threadCount` - number of worker threads to handle results
+* `guiEnabled` - enable or disable the basic gui with usage information
+
+## Access the http interface
+The validation service listens to `POST`-requests to any server uri. You need to supply the xml/object to validate in the post body.
+The service expects a single plain input in the post body, e.g. `multipart/form-data` is not supported.
+
+Examples:
+
+* `cURL`
+```shell script
+curl --location --request POST 'http://localhost:8080' \
+--header 'Content-Type: application/xml' \
+--data-binary '@/target.xml'
+```
+
+* `java` (Apache HttpClient)
+```java
+HttpClient httpClient = HttpClientBuilder.create().build();
+HttpPost postRequest = new HttpPost("http://localhost:8080/");
+FileEntity entity = new FileEntity(Paths.get("some.xml").toFile(), ContentType.APPLICATION_XML);
+postRequest.setEntity(entity);
+HttpResponse response = httpClient.execute(postRequest);
+System.out.println(IOUtils.toString(response.getEntity().getContent()));
+```
+
+* `javascript`
+```javascript
+var myHeaders = new Headers();
+myHeaders.append("Content-Type", "application/xml");
+
+var file = "";
+
+var requestOptions = {
+ method: 'POST',
+ headers: myHeaders,
+ body: file,
+ redirect: 'follow'
+};
+
+fetch("http://localhost:8080", requestOptions)
+ .then(response => response.text())
+ .then(result => console.log(result))
+ .catch(error => console.log('error', error));
+```
+## Authorization
+There is no mechanism to check, whether client is allowed to consume the service or not. The user is responsible to secure access to the service
+This can be done using infrastructural service like a forwarding proxy (e.g. `nginx` or `apache http server`) or by implementing a custom solution
+
+## Monitoring and administration
+The validation service can be integrated in monitoring solutions like `Icinga` or `Nagios`. There is a `health` endpoint exposed under `/server/health` wich returns
+some basic information about the service like memory consumption, general information about the version and a status `UP` as an XML file.
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 34e62a2..694557a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -129,6 +129,12 @@
1.0.0test
+
+org.apache.httpcomponents
+httpclient
+ 4.5.8
+
+
diff --git a/src/main/java/de/kosit/validationtool/daemon/Daemon.java b/src/main/java/de/kosit/validationtool/daemon/Daemon.java
index 6dde8c6..fa0dcbe 100644
--- a/src/main/java/de/kosit/validationtool/daemon/Daemon.java
+++ b/src/main/java/de/kosit/validationtool/daemon/Daemon.java
@@ -34,17 +34,24 @@ public class Daemon {
private static final int DEFAULT_PORT = 8080;
- private final String hostName;
+ private String bindAddress;
- private final int port;
+ private int port;
- private final int threadCount;
+ private int threadCount;
- @Setter(AccessLevel.PRIVATE)
- private boolean guiDisabled = false;
+ private boolean guiEnabled = true;
- public void disableGui() {
- guiDisabled = true;
+ /**
+ * Create a new daemon.
+ * @param hostname the interface to bind to
+ * @param port the port to expose
+ * @param threadCount the number of working threads
+ */
+ public Daemon(String hostname, int port, int threadCount) {
+ this.bindAddress = hostname;
+ this.port = port;
+ this.threadCount = threadCount;
}
/**
@@ -75,7 +82,7 @@ public class Daemon {
HttpHandler rootHandler;
final DefaultCheck check = new DefaultCheck(config);
final CheckHandler checkHandler = new CheckHandler(check, config.getContentRepository().getProcessor());
- if (!guiDisabled) {
+ if (guiEnabled) {
GuiHandler gui = new GuiHandler();
rootHandler = new RoutingHandler(checkHandler, gui);
} else {
@@ -89,6 +96,6 @@ public class Daemon {
}
private InetSocketAddress getSocket() {
- return new InetSocketAddress(defaultIfBlank(this.hostName, DEFAULT_HOST), this.port > 0 ? this.port : DEFAULT_PORT);
+ return new InetSocketAddress(defaultIfBlank(this.bindAddress, DEFAULT_HOST), this.port > 0 ? this.port : DEFAULT_PORT);
}
}
diff --git a/src/main/java/de/kosit/validationtool/daemon/RoutingHandler.java b/src/main/java/de/kosit/validationtool/daemon/RoutingHandler.java
index d1a7675..d15a39c 100644
--- a/src/main/java/de/kosit/validationtool/daemon/RoutingHandler.java
+++ b/src/main/java/de/kosit/validationtool/daemon/RoutingHandler.java
@@ -6,8 +6,11 @@ import lombok.RequiredArgsConstructor;
import java.io.IOException;
+/**
+ * A simple handler which routes between the {@link CheckHandler} and the {@link GuiHandler} depending on the request.
+ */
@RequiredArgsConstructor
-public class RoutingHandler extends BaseHandler {
+class RoutingHandler extends BaseHandler {
private final CheckHandler checkHandler;
From 9e3b12685b7f6735a4056c0544fa17aa4158ed33 Mon Sep 17 00:00:00 2001
From: "Andreas Penski (init)"
Date: Thu, 7 May 2020 17:10:33 +0200
Subject: [PATCH 071/306] Support for DOMSource and other Sources
---
docs/api.md | 2 +-
.../validationtool/api/InputFactory.java | 9 +++-
.../impl/input/SourceInput.java | 50 +++++++++++--------
.../validationtool/api/InputFactoryTest.java | 34 +++++++++++++
4 files changed, 72 insertions(+), 23 deletions(-)
diff --git a/docs/api.md b/docs/api.md
index c59bc23..14add56 100644
--- a/docs/api.md
+++ b/docs/api.md
@@ -4,7 +4,7 @@ The Validator offers an API which allows you to integrate Validator in your own
## Dependency Management
-Currently, we *do not* deploy to Maven Central or similar. Hence you need to build and optionally deploy the Validator artifacts to your own
+Currently, we *do not* deploy to Maven Central or similar. Hence, you need to build and optionally deploy the Validator artifacts to your own
shared (or local) repository (see for example [Maven Documentation](https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html)).
### Maven
diff --git a/src/main/java/de/kosit/validationtool/api/InputFactory.java b/src/main/java/de/kosit/validationtool/api/InputFactory.java
index 8cf380f..b491cb2 100644
--- a/src/main/java/de/kosit/validationtool/api/InputFactory.java
+++ b/src/main/java/de/kosit/validationtool/api/InputFactory.java
@@ -164,8 +164,10 @@ public class InputFactory {
}
/**
- * Reads a test document from a {@link Source}.
- *
+ * Reads a test document from a {@link Source}.
+ * Note: computing the hashcode is only supported for {@link StreamSource}. You can not directly use other {@link Source
+ * Soures}. You need to supply the hashcode for identification then.
+ *
* @param source source
* @return an {@link Input}
*/
@@ -175,6 +177,9 @@ public class InputFactory {
/**
* Reads a test document from a {@link Source} using a specified digest algorithm.
+ *
+ * Note: computing the hashcode is only supported for {@link StreamSource}. You can not directly use other {@link Source
+ * Soures}. You need to supply the hashcode for identification then.
*
* @param source source
* @param digestAlgorithm the digest algorithm
diff --git a/src/main/java/de/kosit/validationtool/impl/input/SourceInput.java b/src/main/java/de/kosit/validationtool/impl/input/SourceInput.java
index f11e65f..cb9f929 100644
--- a/src/main/java/de/kosit/validationtool/impl/input/SourceInput.java
+++ b/src/main/java/de/kosit/validationtool/impl/input/SourceInput.java
@@ -7,13 +7,25 @@ import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import org.apache.commons.io.input.ReaderInputStream;
-import org.apache.commons.lang3.NotImplementedException;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
/**
- * A validator {@link de.kosit.validationtool.api.Input} based an on a {@link Source}.
+ * A validator {@link de.kosit.validationtool.api.Input} based on a {@link Source}.
+ *
+ * Note: The various implementations of {@link Source} varies wether the can be read twice or no. This implementation
+ * tries to handle this with respect document identification (hashcode).
+ *
+ * This class is know to work with:
+ *
+ *
{@link StreamSource} - both {@link java.io.InputStream} based and {@link java.io.Reader} based
+ *
{@link javax.xml.transform.dom.DOMSource}
+ *
{@link javax.xml.bind.util.JAXBSource}
+ *
+ *
+ * Other {@link Source Sources} may work as well, please try and let us know.
+ *
*
* @author Andreas Penski
*/
@@ -40,26 +52,23 @@ public class SourceInput extends AbstractInput {
}
private void validate() {
- if (!isSupported()) {
+ if (!isHashcodeComputed() && !isSupported()) {
throw new IllegalStateException("Unsupported source. Only StreamSource supported yet");
}
- if (((StreamSource) this.source).getInputStream() == null && !isHashcodeComputed()) {
+ if (!isHashcodeComputed() && ((StreamSource) this.source).getInputStream() == null) {
log.warn("No hashcode supplied, will wrap the reader using system default charset");
}
}
@Override
public Source getSource() throws IOException {
- if (!isSupported()) {
+ if (!isHashcodeComputed() && !isSupported()) {
throw new IllegalStateException("Unsupported source. Only InputStream-based StreamSource supported yet");
}
- if (isWrappingRequired()) {
- return wrap();
- }
if (isConsumed()) {
throw new IllegalStateException("A SourceInput can only read once");
}
- return this.source;
+ return isHashcodeComputed() ? this.source : wrappedSource();
}
private boolean isSupported() {
@@ -67,24 +76,25 @@ public class SourceInput extends AbstractInput {
}
private boolean isConsumed() throws IOException {
- if (!isStreamSource()) {
- throw new NotImplementedException("Supports only StreamSource yet");
- }
- final StreamSource ss = (StreamSource) this.source;
- try {
- return (ss.getInputStream() != null && ss.getInputStream().available() == 0)
- || (ss.getReader() != null && !ss.getReader().ready());
- } catch (final IOException e) {
- log.error("Error checking consumed state", e);
- return true;
+ if (isStreamSource()) {
+
+ final StreamSource ss = (StreamSource) this.source;
+ try {
+ return (ss.getInputStream() != null && ss.getInputStream().available() == 0)
+ || (ss.getReader() != null && !ss.getReader().ready());
+ } catch (final IOException e) {
+ log.error("Error checking consumed state", e);
+ return true;
+ }
}
+ return false;
}
private boolean isStreamSource() {
return this.source instanceof StreamSource;
}
- private Source wrap() {
+ private Source wrappedSource() {
Source result = this.source;
if (isStreamSource()) {
final StreamSource ss = (StreamSource) this.source;
diff --git a/src/test/java/de/kosit/validationtool/api/InputFactoryTest.java b/src/test/java/de/kosit/validationtool/api/InputFactoryTest.java
index 3fc6122..aa8e6e3 100644
--- a/src/test/java/de/kosit/validationtool/api/InputFactoryTest.java
+++ b/src/test/java/de/kosit/validationtool/api/InputFactoryTest.java
@@ -31,14 +31,29 @@ import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Paths;
+import javax.xml.transform.Source;
+import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamSource;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.w3c.dom.Document;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.AttributesImpl;
+import de.kosit.validationtool.impl.Helper;
import de.kosit.validationtool.impl.Helper.Simple;
+import de.kosit.validationtool.impl.TestObjectFactory;
import de.kosit.validationtool.impl.input.SourceInput;
+import de.kosit.validationtool.impl.model.Result;
+import de.kosit.validationtool.model.reportInput.XMLSyntaxError;
+
+import net.sf.saxon.dom.NodeOverNodeInfo;
+import net.sf.saxon.s9api.BuildingContentHandler;
+import net.sf.saxon.s9api.DocumentBuilder;
+import net.sf.saxon.s9api.SaxonApiException;
+import net.sf.saxon.s9api.XdmNode;
/**
* Testet den Hashcode-Service.
@@ -163,4 +178,23 @@ public class InputFactoryTest {
InputFactory.read(Simple.NOT_EXISTING);
}
+ @Test
+ public void testDomSource() throws SaxonApiException, SAXException, IOException {
+ final DocumentBuilder builder = TestObjectFactory.createProcessor().newDocumentBuilder();
+
+ final BuildingContentHandler handler = builder.newBuildingContentHandler();
+ handler.startDocument();
+ handler.startElement("http://some.ns", "mynode", "mynode", new AttributesImpl());
+ final Document dom = NodeOverNodeInfo.wrap(handler.getDocumentNode().getUnderlyingNode()).getOwnerDocument();
+ final Input domInput = InputFactory.read(new DOMSource(dom), "MD5", "id".getBytes());
+ assertThat(domInput).isNotNull();
+ final Source source = domInput.getSource();
+ assertThat(source).isNotNull();
+ final Result parsed = Helper.parseDocument(domInput);
+ assertThat(parsed.isValid()).isTrue();
+
+ // read twice
+ assertThat(Helper.parseDocument(domInput).getObject()).isNotNull();
+ }
+
}
From b164d711994b45c0bf29800fa9abe6f2767a0cd7 Mon Sep 17 00:00:00 2001
From: Andreas Penski <18-andreas.penski@users.noreply.projekte.kosit.org>
Date: Mon, 11 May 2020 09:07:40 +0200
Subject: [PATCH 072/306] test for gui handler
---
.../kosit/validationtool/daemon/BaseHandler.java | 7 ++++---
.../validationtool/daemon/GuiHandlerIT.java | 16 ++++++++++++++++
2 files changed, 20 insertions(+), 3 deletions(-)
create mode 100644 src/test/java/de/kosit/validationtool/daemon/GuiHandlerIT.java
diff --git a/src/main/java/de/kosit/validationtool/daemon/BaseHandler.java b/src/main/java/de/kosit/validationtool/daemon/BaseHandler.java
index 4a7fe54..9aaae1c 100644
--- a/src/main/java/de/kosit/validationtool/daemon/BaseHandler.java
+++ b/src/main/java/de/kosit/validationtool/daemon/BaseHandler.java
@@ -29,10 +29,11 @@ abstract class BaseHandler implements HttpHandler {
os.close();
}
- protected static void error(final HttpExchange httpExchange, final int statusCode, final String message) throws IOException {
+ protected static void error(final HttpExchange exchange, final int statusCode, final String message) throws IOException {
final byte[] bytes = message.getBytes();
- httpExchange.sendResponseHeaders(statusCode, bytes.length);
- final OutputStream os = httpExchange.getResponseBody();
+ exchange.getResponseHeaders().add("Content-Type", "text/plain");
+ exchange.sendResponseHeaders(statusCode, bytes.length);
+ final OutputStream os = exchange.getResponseBody();
os.write(bytes);
os.close();
}
diff --git a/src/test/java/de/kosit/validationtool/daemon/GuiHandlerIT.java b/src/test/java/de/kosit/validationtool/daemon/GuiHandlerIT.java
new file mode 100644
index 0000000..bd62201
--- /dev/null
+++ b/src/test/java/de/kosit/validationtool/daemon/GuiHandlerIT.java
@@ -0,0 +1,16 @@
+package de.kosit.validationtool.daemon;
+
+import io.restassured.http.ContentType;
+import org.junit.Test;
+
+import static io.restassured.RestAssured.given;
+
+public class GuiHandlerIT extends BaseIT {
+
+ @Test
+ public void checkGui() {
+ given().when().get("/").then().statusCode(200).and().contentType(ContentType.HTML);
+ given().when().get("/README.md").then().statusCode(200).and().contentType("text/markdown");
+ given().when().get("/unknown.md").then().statusCode(404).and().contentType(ContentType.TEXT);
+ }
+}
From 06a88848db923779ee682a4dac6bbc6de4e65ce5 Mon Sep 17 00:00:00 2001
From: "Andreas Penski (init)"
Date: Fri, 15 May 2020 10:01:07 +0200
Subject: [PATCH 073/306] prepare docs for release 1.3.0
---
CHANGELOG.md | 7 +++--
README.md | 19 +++++---------
docs/contribute.md | 11 ++++++++
src/main/resources/gui/docs/api.md | 42 +++++++++++++++++++++++++++++-
4 files changed, 61 insertions(+), 18 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 07e06a0..7e1c78f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,7 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
-## next version (unreleased)
+## 1.3.0
### Added
- Added a builder style configuration API to configure scenarios
@@ -19,11 +19,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- CheckConfiguration is deprecated now. Use Configuration.load(...) or Configuration.build(...)
- Overall processing of xml files is based on Saxon s9api. No JAXP or SAX classes are used by
the validator (this further improves performance and memory consumption)
--
-## UNRELEASED
### Fixed
-- Validator was creating invalid createReportInput xml in case of no scenrio match
+- Validator was creating invalid createReportInput xml in case of no scenrio match
+
## 1.2.0
### Added
diff --git a/README.md b/README.md
index c4672f7..d02d2d5 100644
--- a/README.md
+++ b/README.md
@@ -3,6 +3,8 @@
The validator is an XML validation-engine. It validates XML documents against XML Schema and Schematron Rules depending on self defined [scenarios](docs/configurations.md) which are used to fully configure the validation process.
The validator always outputs a [validation report in XML](docs/configurations.md#validators-report) including all validation errors and data about the validation.
+See [architecture](docs/architecture.md) for informations about the actual validation process.
+
## Packages
The validator distribution contains the following artifacts:
@@ -12,16 +14,6 @@ The validator distribution contains the following artifacts:
1. **validationtool-`-java8-standalone.jar**: Uber-JAR for standalone usage with Java JDK 8 containing all dependencies in one jar file. This file file *does not* contain JAXB and depends on the bundled version of the JDK.
1. **libs/***: directory containing all (incl. optional) dependencies of the validator
-## Build
-
-### Requirements
-
-* Maven > 3.0.0
-* Java > 8 update 111
-
-### Procedure
-
- `mvn install` generates two different packages in the `dist` directory:
## Validation Configurations
@@ -29,7 +21,7 @@ The validator is just an engine and does not know anything about XML Documents a
Validation rules and details are defined in [validation scenarios](docs/configurations.md) which are used to fully configure the validation process.
-All configurations are self-contained modules and deployed on their own.
+All configurations are self-contained modules and deployed and developed on their own.
### Third Party Validation Configurations
@@ -64,7 +56,8 @@ You can see more CLI options with
java -jar validationtool--standalone.jar --help
```
-A concrete example with a specific validator configuration can be found on [GitHub](https://github.com/itplr-kosit/validator-configuration-xrechnung)
+A concrete example with a specific validator configuration can be found on
+[GitHub](https://github.com/itplr-kosit/validator-configuration-xrechnung)
### Application User Interface (API / embedded usage)
@@ -97,5 +90,5 @@ You can configure it with `-H` for IP Adress and `-P` for port number:
java -jar validationtool--standalone.jar -s -D -H 192.168.1.x -P 8081
```
-Details and further configuration options can be [found here](./docs/daemon.md).
+Usage details and further configuration options can be [found here](./docs/daemon.md).
diff --git a/docs/contribute.md b/docs/contribute.md
index 191f2e4..76d0d95 100644
--- a/docs/contribute.md
+++ b/docs/contribute.md
@@ -25,3 +25,14 @@ due to historical reasons. This not only works in Eclipse but also in IntelliJ (
The configuration can be found in `.settings`-directory. For IntelliJ this is all set up. Additionally this should work in Eclipse out of the box.
Another potential usage scenario would be to integrate the formatter via git hooks into the commit-pipeline (e.g [Example Hook](https://gist.github.com/ktoso/708972) ).
For other IDEs you are on your own.
+
+## Build
+
+### Requirements
+
+* Maven > 3.0.0
+* Java > 8 update 111
+
+### Procedure
+
+ `mvn install` generates two different packages in the `dist` directory:
\ No newline at end of file
diff --git a/src/main/resources/gui/docs/api.md b/src/main/resources/gui/docs/api.md
index dfd790e..dc84852 100644
--- a/src/main/resources/gui/docs/api.md
+++ b/src/main/resources/gui/docs/api.md
@@ -1 +1,41 @@
-Put content here ;)
\ No newline at end of file
+The validation service listens to `POST`-requests to any server uri. You need to supply the xml/object to validate in the post body.
+The service expects a single plain input in the post body, e.g. `multipart/form-data` is not supported.
+
+Examples:
+
+* `cURL`
+```shell script
+curl --location --request POST 'http://localhost:8080' \
+--header 'Content-Type: application/xml' \
+--data-binary '@/target.xml'
+```
+
+* `java` (Apache HttpClient)
+```java
+HttpClient httpClient = HttpClientBuilder.create().build();
+HttpPost postRequest = new HttpPost("http://localhost:8080/");
+FileEntity entity = new FileEntity(Paths.get("some.xml").toFile(), ContentType.APPLICATION_XML);
+postRequest.setEntity(entity);
+HttpResponse response = httpClient.execute(postRequest);
+System.out.println(IOUtils.toString(response.getEntity().getContent()));
+```
+
+* `javascript`
+```javascript
+var myHeaders = new Headers();
+myHeaders.append("Content-Type", "application/xml");
+
+var file = "";
+
+var requestOptions = {
+ method: 'POST',
+ headers: myHeaders,
+ body: file,
+ redirect: 'follow'
+};
+
+fetch("http://localhost:8080", requestOptions)
+ .then(response => response.text())
+ .then(result => console.log(result))
+ .catch(error => console.log('error', error));
+```
\ No newline at end of file
From 997f5073fea819071a52c39fbdfadf3b97f91e61 Mon Sep 17 00:00:00 2001
From: "Andreas Penski (init)"
Date: Mon, 18 May 2020 09:22:35 +0200
Subject: [PATCH 074/306] further doc
---
README.md | 19 +++---------
docs/api.md | 31 ++++++++++---------
docs/daemon.md | 25 ++++++++++++---
.../cmd/CommandLineApplication.java | 8 ++++-
4 files changed, 49 insertions(+), 34 deletions(-)
diff --git a/README.md b/README.md
index d02d2d5..4168738 100644
--- a/README.md
+++ b/README.md
@@ -18,19 +18,17 @@ The validator distribution contains the following artifacts:
## Validation Configurations
The validator is just an engine and does not know anything about XML Documents and has no own validation rules.
-
Validation rules and details are defined in [validation scenarios](docs/configurations.md) which are used to fully configure the validation process.
-
All configurations are self-contained modules and deployed and developed on their own.
### Third Party Validation Configurations
Currently, there are two public third party validation configurations available.
-* Validation Configuration for [XRechnung](http://www.xoev.de/de/xrechnung) is available on
+* Validation Configuration for [XRechnung](http://www.xoev.de/de/xrechnung):
* Source code is available on [GitHub](https://github.com/itplr-kosit/validator-configuration-xrechnung)
* [Releases](https://github.com/itplr-kosit/validator-configuration-xrechnung/releases) can also be downloaded
-* Validation Configuration for XGewerbeanzeige
+* Validation Configuration for [XGewerbeanzeige](https://xgewerbeanzeige.de/)
* Source code is available on [GitHub](https://github.com/itplr-kosit/validator-configuration-xgewerbeanzeige)
* [Releases](https://github.com/itplr-kosit/validator-configuration-xgewerbeanzeige/releases) can also be downloaded
@@ -50,7 +48,7 @@ The general way using the CLI is:
java -jar validationtool--standalone.jar -s [OPTIONS] [FILE] [FILE] [FILE] ...
```
-You can see more CLI options with
+The help option displays further CLI options to customize the process:
```shell
java -jar validationtool--standalone.jar --help
@@ -72,7 +70,7 @@ Result validationResult = validator.checkInput(document);
// examine the result here
```
-Details and further configuration options can be [found here](./docs/api.md).
+The [API documentation](./docs/api.md) shows further configuration options.
### Daemon-Mode
@@ -82,13 +80,6 @@ You can also start the validator as an HTTP-Server. Just start it in _Daemon-Mod
java -jar validationtool--standalone.jar -s -D
```
-Per default the HTTP-Server listens on _localhost_ at Port 8080.
-You can configure it with `-H` for IP Adress and `-P` for port number:
-
-```shell
-java -jar validationtool--standalone.jar -s -D -H 192.168.1.x -P 8081
-```
-
-Usage details and further configuration options can be [found here](./docs/daemon.md).
+The [daemon documentation](./docs/daemon.md) shows more usage details and further configuration options.
diff --git a/docs/api.md b/docs/api.md
index 14add56..bea4a12 100644
--- a/docs/api.md
+++ b/docs/api.md
@@ -1,6 +1,6 @@
# Validator API
-The Validator offers an API which allows you to integrate Validator in your own applications.
+The Validator offers an API which allows you to integrate the Validator in your own applications.
## Dependency Management
@@ -87,11 +87,13 @@ The `Result` interface has convenience methods to retrieve details about XSD val
[Result.java](https://github.com/itplr-kosit/validator/blob/master/src/main/java/de/kosit/validationtool/api/Result.java) for details.
Initializing all XML artifacts and XSLT-executables is expensive. The `Check` instance is *threadsafe* and keeps all artifacts. Therefore,
-we recommend the re-use of an `Check` instance.
+we recommend the re-use of a `Check` instance.
-The only input `de.kosit.validationtool.api.Input` which can be created by various methods of `de.kosit.validationtool.api.InputFactory`.
-The `InputFactory` calculates a hash sum for each Input which is also written to the Report. _SHA-256_ from the JDK is the default algorithm.
-It can be changed using the `read`-methods of `InputFactory`.
+Beside the validator's configuration the only input are instances of [Input](https://github.com/itplr-kosit/validator/blob/master/src/main/java/de/kosit/validationtool/api/Input.java)
+which can be created by various methods of the [InputFactory](https://github.com/itplr-kosit/validator/blob/master/src/main/java/de/kosit/validationtool/api/InputFactory.java).
+The [InputFactory](https://github.com/itplr-kosit/validator/blob/master/src/main/java/de/kosit/validationtool/api/InputFactory.java)
+ calculates a hash sum for each Input which is also written to the Report. _SHA-256_ from the JDK is the default algorithm.
+It can be changed using other `read`-methods of [InputFactory](https://github.com/itplr-kosit/validator/blob/master/src/main/java/de/kosit/validationtool/api/InputFactory.java).
The main interface [Check.java](https://github.com/itplr-kosit/validator/blob/master/src/main/java/de/kosit/validationtool/api/Check.java)
allows using a batch interface (processing list of [Inputs](https://github.com/itplr-kosit/validator/blob/master/src/main/java/de/kosit/validationtool/api/Input.java)).
@@ -99,7 +101,8 @@ However, there is no parallel processing implemented at the moment.
## Accept Recommendation and Accept Match
-A tri-state Object `AcceptRecommendation` can be retrieved from the `Result` using `getAcceptRecommendation()`.
+A tri-state object [AcceptRecommendation](https://github.com/itplr-kosit/validator/blob/master/src/main/java/de/kosit/validationtool/api/AcceptRecommendation.java)
+can be retrieved from the [Result](https://github.com/itplr-kosit/validator/blob/master/src/main/java/de/kosit/validationtool/api/Result.java) using `getAcceptRecommendation()`.
The three defined states are:
@@ -112,7 +115,7 @@ The accept recommendation is based on either:
1. schema and schematron validation result
1. if configured based on _acceptMatch_ configuration of the scenario (see below)
-### Accept Match in Scenario Configuration
+### Accept match in scenario configuration
For your own configuration you can add an `acceptMatch` element in each scenario. It can contain in XPATH expression over your own
defined `Report` to compute a boolean. An XPATH expression evaluating to true will lead to an `ACCEPTABLE` and otherwise to a `REJECT`
@@ -132,7 +135,7 @@ a builder API. A valid configuration consists of the following:
* a valid report transformation configuration
* valid schematron validation configurations (optional)
* a valid accept match configuration to compute acceptance information (optional)
-* valid a fallback scenario configuration
+* a valid fallback scenario configuration
A simple configuration looks like this:
@@ -160,10 +163,10 @@ public class MyValidator {
}
```
-There a various methods provided by the builder API to configure your scenarios and the validation process.
-
+There are various methods provided by the builder API to configure your scenarios and the validation process.
It is also possible to provide runtime artifacts like `XsltExecutable`, `XPathExecutalbe` or `Schema` to configure the validator.
This gives you complete control how to load these artifacts.
+
---
**Note:** Creating this objects requires usage of the same instance of the saxon `Processor` as used during validation later. So you
need to supply a custom `ResolvingConfigurationStrategy` or use the internal one to create these objects. See below.
@@ -187,11 +190,11 @@ There are 3 implemenations available out of the box:
1. [StrictRelativeResolvingStrategy.java](https://github.com/itplr-kosit/validator/tree/master/src/main/java/de/kosit/validationtool/impl/xml/StrictRelativeResolvingStrategy.java)
which is the **default**, prevents known XML attacks and only allows loading from a specific local repository location
1. [StrictLocalResolvingStrategy.java](https://github.com/itplr-kosit/validator/tree/master/src/main/java/de/kosit/validationtool/impl/xml/StrictLocalResolvingStrategy.java)
-which opens the first to load resource from local location
+which opens the first to load resource from local locations
1. [RemoteResolvingStrategy.java](https://github.com/itplr-kosit/validator/tree/master/src/main/java/de/kosit/validationtool/impl/xml/RemoteResolvingStrategy.java)
-which opens the first to load resource also from remote locations via http and https
+which further opens the second to load resources also from remote locations via http and https
-You can configure usage of one of this implemenations via
+You can configure usage of one of this implemenations using the `ResolvingMode` via
````java
Conifuguration config = Configuration.load(URI.create("myscenarios.xml"))
@@ -208,7 +211,7 @@ Conifuguration config = Configuration.load(URI.create("myscenarios.xml"))
````
---
-**Attention:** If you decide to implement a custom strategy you need to handle xml security risk. Please make sure, that you prevent XXE attacks and
+:warning: **Attention:** If you decide to implement a custom strategy you need to handle xml security risk. Please make sure, that you prevent XXE attacks and
other kind of attacks. Consider using [BaseResolvingStrategy.java](https://github.com/itplr-kosit/validator/tree/master/src/main/java/de/kosit/validationtool/impl/xml/BaseResolvingStrategy.java)
and the protected methods within to disable certain features.
diff --git a/docs/daemon.md b/docs/daemon.md
index 577a4c8..5be8c75 100644
--- a/docs/daemon.md
+++ b/docs/daemon.md
@@ -1,9 +1,11 @@
# Validator daemon
-You can also start the validator as a HTTP-Server. This is based JDK http server functionality. Keep that mind, if you want to deploy this
+You can also start the validator as a HTTP-Server. This is based [JDK http server](https://docs.oracle.com/javase/8/docs/jre/api/net/httpserver/spec/com/sun/net/httpserver/HttpServer.html) functionality
+and should work with OpenJDK based Java distributions. Keep that mind, if you want to deploy this
in production scenarios with heavy load.
## Basic usage
-To just use the validator daemon as is, start the _Daemon-Mode_ with the `-D` option.
+To just use the validator daemon as is, start the _Daemon-Mode_ with the `-D` option and supply a suitable
+ [validator configuration](configurations.md)
```shell
java -jar validationtool--standalone.jar -s -D
@@ -11,7 +13,7 @@ java -jar validationtool--standalone.jar -s -D
Per default the HTTP-Server listens on _localhost_ at Port 8080.
-You can configure it with `-H` for IP Adress and `-P` for port number:
+You can configure the daemon with `-H` for IP Adress and `-P` for port number:
```shell
java -jar validationtool--standalone.jar -s -D -H 192.168.1.x -P 8081
@@ -38,7 +40,7 @@ The possible customizations are:
## Access the http interface
The validation service listens to `POST`-requests to any server uri. You need to supply the xml/object to validate in the post body.
-The service expects a single plain input in the post body, e.g. `multipart/form-data` is not supported.
+The service expects a single xml input in the post body, e.g. `multipart/form-data` is not supported.
Examples:
@@ -84,4 +86,17 @@ This can be done using infrastructural service like a forwarding proxy (e.g. `ng
## Monitoring and administration
The validation service can be integrated in monitoring solutions like `Icinga` or `Nagios`. There is a `health` endpoint exposed under `/server/health` wich returns
-some basic information about the service like memory consumption, general information about the version and a status `UP` as an XML file.
\ No newline at end of file
+some basic information about the service like memory consumption, general information about the version and a status `UP` as an XML file.
+
+## GUI
+The daemon provides a simple GUI when issuing `GET` requests providing the following:
+
+ 1. usage information
+ 1. information about the actual [validator configuration](configurations.md) used by this daemon
+ 1. a simple form to test the daemon with custom inputs
+
+ The GUI can be disabled with using the API (see above) or via CLI
+
+ ```shell script
+java -jar validationtool--standalone.jar -s -D --disable-gui
+```
\ No newline at end of file
diff --git a/src/main/java/de/kosit/validationtool/cmd/CommandLineApplication.java b/src/main/java/de/kosit/validationtool/cmd/CommandLineApplication.java
index ba0e9aa..2e254aa 100644
--- a/src/main/java/de/kosit/validationtool/cmd/CommandLineApplication.java
+++ b/src/main/java/de/kosit/validationtool/cmd/CommandLineApplication.java
@@ -29,7 +29,6 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.stream.Collectors;
-import java.util.stream.StreamSupport;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
@@ -97,6 +96,9 @@ public class CommandLineApplication {
private static final Option WORKER_COUNT = Option.builder("T").longOpt("threads").hasArg()
.desc("Number of threads processing validation requests").build();
+ private static final Option DISABLE_GUI = Option.builder("G").longOpt("disable-gui").desc("Disables the GUI of the daemon mode")
+ .build();
+
public static final int DAEMON_SIGNAL = 100;
private static final Option PRINT_MEM_STATS = Option.builder("m").longOpt("memory-stats").desc("Prints some memory stats").build();
@@ -175,6 +177,9 @@ public class CommandLineApplication {
warnUnusedOptions(cmd, unavailable, true);
final ConfigurationLoader config = Configuration.load(determineDefinition(cmd), determineRepository(cmd));
final Daemon validDaemon = new Daemon(determineHost(cmd), determinePort(cmd), determineThreads(cmd));
+ if (cmd.hasOption(DISABLE_GUI.getOpt())) {
+ validDaemon.setGuiEnabled(false);
+ }
validDaemon.startServer(config.build());
return DAEMON_SIGNAL;
}
@@ -379,6 +384,7 @@ public class CommandLineApplication {
options.addOption(CHECK_ASSERTIONS);
options.addOption(PRINT_MEM_STATS);
options.addOption(WORKER_COUNT);
+ options.addOption(DISABLE_GUI);
return options;
}
}
From e01976e7aeb454f33e580e743535471b8c4f022f Mon Sep 17 00:00:00 2001
From: "Andreas Penski (init)"
Date: Thu, 28 May 2020 15:38:43 +0200
Subject: [PATCH 075/306] fix some typos
---
README.md | 2 +-
docs/api.md | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index 4168738..60de6b9 100644
--- a/README.md
+++ b/README.md
@@ -74,7 +74,7 @@ The [API documentation](./docs/api.md) shows further configuration options.
### Daemon-Mode
-You can also start the validator as an HTTP-Server. Just start it in _Daemon-Mode_ with the `-D` option.
+You can also start the validator as a HTTP-Server. Just start it in _Daemon-Mode_ with the `-D` option.
```shell
java -jar validationtool--standalone.jar -s -D
diff --git a/docs/api.md b/docs/api.md
index bea4a12..66e77cc 100644
--- a/docs/api.md
+++ b/docs/api.md
@@ -190,7 +190,7 @@ There are 3 implemenations available out of the box:
1. [StrictRelativeResolvingStrategy.java](https://github.com/itplr-kosit/validator/tree/master/src/main/java/de/kosit/validationtool/impl/xml/StrictRelativeResolvingStrategy.java)
which is the **default**, prevents known XML attacks and only allows loading from a specific local repository location
1. [StrictLocalResolvingStrategy.java](https://github.com/itplr-kosit/validator/tree/master/src/main/java/de/kosit/validationtool/impl/xml/StrictLocalResolvingStrategy.java)
-which opens the first to load resource from local locations
+which opens the first strategy to load resources from local locations
1. [RemoteResolvingStrategy.java](https://github.com/itplr-kosit/validator/tree/master/src/main/java/de/kosit/validationtool/impl/xml/RemoteResolvingStrategy.java)
which further opens the second to load resources also from remote locations via http and https
From 3e4aa9f957d78eddb5d13743b9fce97454706483 Mon Sep 17 00:00:00 2001
From: "Andreas Penski (init)"
Date: Fri, 29 May 2020 09:03:16 +0200
Subject: [PATCH 076/306] (chore) daemon documentation and license
clarification for docsify
---
src/main/resources/gui/README.md | 2 +
src/main/resources/gui/docs/api.md | 1 +
src/main/resources/gui/docs/configurations.md | 15 +++++
src/main/resources/gui/index.html | 56 +++++++++++--------
src/main/resources/gui/lib/License | 23 ++++++++
5 files changed, 75 insertions(+), 22 deletions(-)
create mode 100644 src/main/resources/gui/docs/configurations.md
create mode 100644 src/main/resources/gui/lib/License
diff --git a/src/main/resources/gui/README.md b/src/main/resources/gui/README.md
index 7c3955f..40aad58 100644
--- a/src/main/resources/gui/README.md
+++ b/src/main/resources/gui/README.md
@@ -2,6 +2,8 @@
[API usage](docs/api)
+[configurations](docs/configurations)
+
# Server information
View [validator configuration](/server/config) or health information
diff --git a/src/main/resources/gui/docs/api.md b/src/main/resources/gui/docs/api.md
index dc84852..34d0c71 100644
--- a/src/main/resources/gui/docs/api.md
+++ b/src/main/resources/gui/docs/api.md
@@ -1,3 +1,4 @@
+# API Usage
The validation service listens to `POST`-requests to any server uri. You need to supply the xml/object to validate in the post body.
The service expects a single plain input in the post body, e.g. `multipart/form-data` is not supported.
diff --git a/src/main/resources/gui/docs/configurations.md b/src/main/resources/gui/docs/configurations.md
new file mode 100644
index 0000000..3e8678d
--- /dev/null
+++ b/src/main/resources/gui/docs/configurations.md
@@ -0,0 +1,15 @@
+# Configurations
+
+The validator needs a scenario configuration for working properly.
+
+Currently, there are two public third party validation configurations available.
+
+* Validation Configuration for [XRechnung](http://www.xoev.de/de/xrechnung):
+ * Source code is available on [GitHub](https://github.com/itplr-kosit/validator-configuration-xrechnung)
+ * [Releases](https://github.com/itplr-kosit/validator-configuration-xrechnung/releases) can also be downloaded
+* Validation Configuration for [XGewerbeanzeige](https://xgewerbeanzeige.de/)
+ * Source code is available on [GitHub](https://github.com/itplr-kosit/validator-configuration-xgewerbeanzeige)
+ * [Releases](https://github.com/itplr-kosit/validator-configuration-xgewerbeanzeige/releases) can also be downloaded
+
+For creating custom configurations see [configaration documentation](https://github.com/itplr-kosit/validator/blob/master/docs/configurations.md)
+for details
\ No newline at end of file
diff --git a/src/main/resources/gui/index.html b/src/main/resources/gui/index.html
index 4919302..1eb48c4 100644
--- a/src/main/resources/gui/index.html
+++ b/src/main/resources/gui/index.html
@@ -3,36 +3,48 @@
Validator
-
-
-
+
+
+
+
+
diff --git a/src/main/resources/gui/lib/License b/src/main/resources/gui/lib/License
new file mode 100644
index 0000000..4a5b531
--- /dev/null
+++ b/src/main/resources/gui/lib/License
@@ -0,0 +1,23 @@
+Sources in this diretory are based on https://github.com/docsifyjs/docsify/
+
+MIT License
+
+Copyright (c) 2016 - present cinwell.li
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
\ No newline at end of file
From e26cbc9613226e4bb9ad654356916d83c2fcce32 Mon Sep 17 00:00:00 2001
From: "Andreas Penski (init)"
Date: Fri, 29 May 2020 09:58:04 +0200
Subject: [PATCH 077/306] make java snippet explicit
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 60de6b9..385e94f 100644
--- a/README.md
+++ b/README.md
@@ -60,7 +60,7 @@ A concrete example with a specific validator configuration can be found on
### Application User Interface (API / embedded usage)
The validator can also be used in own Java Applications via the API. Usage would be something like this:
-```
+```java
Path scenarios = Paths.get("scenarios.xml");
Configuration config = Configuration.load(scenarios.toUri());
Input document = InputFactory.read(testDocument);
From b04aa344bc23075d89b585cf22191f01e20ce814 Mon Sep 17 00:00:00 2001
From: Renzo Kottmann
Date: Sat, 20 Jun 2020 16:41:19 +0000
Subject: [PATCH 078/306] Minor typos and grammer
---
README.md | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index 385e94f..be743c4 100644
--- a/README.md
+++ b/README.md
@@ -19,7 +19,7 @@ The validator distribution contains the following artifacts:
The validator is just an engine and does not know anything about XML Documents and has no own validation rules.
Validation rules and details are defined in [validation scenarios](docs/configurations.md) which are used to fully configure the validation process.
-All configurations are self-contained modules and deployed and developed on their own.
+All configurations are self-contained modules which are deployed and developed on their own.
### Third Party Validation Configurations
@@ -59,7 +59,8 @@ A concrete example with a specific validator configuration can be found on
### Application User Interface (API / embedded usage)
-The validator can also be used in own Java Applications via the API. Usage would be something like this:
+The validator can also be used in own Java Applications via the API. An example use of the API as follows:
+
```java
Path scenarios = Paths.get("scenarios.xml");
Configuration config = Configuration.load(scenarios.toUri());
@@ -70,6 +71,7 @@ Result validationResult = validator.checkInput(document);
// examine the result here
```
+
The [API documentation](./docs/api.md) shows further configuration options.
### Daemon-Mode
From 6219eb6f4141946b3b6e085ad051228c6b5da2fa Mon Sep 17 00:00:00 2001
From: Renzo Kottmann
Date: Sat, 20 Jun 2020 16:51:05 +0000
Subject: [PATCH 079/306] Typos and Grammar on daemon.md
---
docs/daemon.md | 38 ++++++++++++++++++++++----------------
1 file changed, 22 insertions(+), 16 deletions(-)
diff --git a/docs/daemon.md b/docs/daemon.md
index 5be8c75..8702caa 100644
--- a/docs/daemon.md
+++ b/docs/daemon.md
@@ -1,11 +1,12 @@
-# Validator daemon
-You can also start the validator as a HTTP-Server. This is based [JDK http server](https://docs.oracle.com/javase/8/docs/jre/api/net/httpserver/spec/com/sun/net/httpserver/HttpServer.html) functionality
-and should work with OpenJDK based Java distributions. Keep that mind, if you want to deploy this
-in production scenarios with heavy load.
+# Validator HTTP Daemon
+
+You can start the validator as an HTTP-Server. This server is based on the [JDK HTTP server](https://docs.oracle.com/javase/8/docs/jre/api/net/httpserver/spec/com/sun/net/httpserver/HttpServer.html) functionality
+and should work with OpenJDK based distributions. Keep this in mind, if you want to deploy this in production scenarios with heavy load.
## Basic usage
-To just use the validator daemon as is, start the _Daemon-Mode_ with the `-D` option and supply a suitable
- [validator configuration](configurations.md)
+
+To use the validator daemon as is, start the _Daemon-Mode_ with the `-D` option and supply a suitable
+ [validator configuration](configurations.md).
```shell
java -jar validationtool--standalone.jar -s -D
@@ -20,7 +21,8 @@ java -jar validationtool--standalone.jar -s -D
```
## Customized usage
-You can also leverage the API to create a customized version of the Daemon. Just instantiate, configure and start the daemon like this:
+
+You can also leverage the API to create a customized version of the daemon. Just instantiate, configure and start the daemon like this:
````java
Configuration config = Configuration.load(...);
@@ -36,11 +38,13 @@ The possible customizations are:
* `bindAddress` - the interface to bind the daemon to
* `port` - the port to expose
* `threadCount` - number of worker threads to handle results
-* `guiEnabled` - enable or disable the basic gui with usage information
+* `guiEnabled` - enable or disable the basic GUI with usage information
-## Access the http interface
-The validation service listens to `POST`-requests to any server uri. You need to supply the xml/object to validate in the post body.
-The service expects a single xml input in the post body, e.g. `multipart/form-data` is not supported.
+## Access the HTTP interface
+
+The validation service listens to `POST`-requests on any server URL. You need to supply the xml/object to validate in the HTTP body.
+
+The service expects a single XML input in the HTTP body, e.g. `multipart/form-data` is not supported.
Examples:
@@ -80,15 +84,17 @@ fetch("http://localhost:8080", requestOptions)
.then(result => console.log(result))
.catch(error => console.log('error', error));
```
+
## Authorization
-There is no mechanism to check, whether client is allowed to consume the service or not. The user is responsible to secure access to the service
-This can be done using infrastructural service like a forwarding proxy (e.g. `nginx` or `apache http server`) or by implementing a custom solution
+There is no mechanism to check, whether client is allowed to consume the service or not. The user is responsible to secure access to the service.
+This can be done using infrastructural service like a forwarding proxies (e.g. `nginx` or `Apache http server`) or by implementing a custom solution.
## Monitoring and administration
-The validation service can be integrated in monitoring solutions like `Icinga` or `Nagios`. There is a `health` endpoint exposed under `/server/health` wich returns
-some basic information about the service like memory consumption, general information about the version and a status `UP` as an XML file.
+
+The validation service can be integrated in monitoring solutions like `Icinga` or `Nagios`. There is a `health` endpoint exposed under `/server/health` wich returns some basic information about the service like memory consumption, general information about the version and a status `UP` as an XML file.
## GUI
+
The daemon provides a simple GUI when issuing `GET` requests providing the following:
1. usage information
@@ -99,4 +105,4 @@ The daemon provides a simple GUI when issuing `GET` requests providing the follo
```shell script
java -jar validationtool--standalone.jar -s -D --disable-gui
-```
\ No newline at end of file
+```
From 5ef290c18780c8e90bcc6bc3ad2653114f3e07b7 Mon Sep 17 00:00:00 2001
From: "Andreas Penski (init)"
Date: Wed, 24 Jun 2020 13:10:24 +0200
Subject: [PATCH 080/306] (chore) config changes
---
.idea/encodings.xml | 1 -
.idea/misc.xml | 2 +-
2 files changed, 1 insertion(+), 2 deletions(-)
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
index ecaea3d..63fc954 100644
--- a/.idea/encodings.xml
+++ b/.idea/encodings.xml
@@ -2,7 +2,6 @@
-
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 3ab06a4..c874577 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -79,7 +79,7 @@
-
+
From beac5dd4f7397bb97cac91ed8e9375073bf8de4a Mon Sep 17 00:00:00 2001
From: "Andreas Penski (init)"
Date: Wed, 24 Jun 2020 13:12:06 +0200
Subject: [PATCH 081/306] (chore) Release prepare: Set correct version in
CHANGELOG.md
---
CHANGELOG.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b0a2481..5ed5421 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,7 +5,7 @@ All notable changes to the Schematron Rules and this project will be documented
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
-## UNRELEASED
+## 1.2.1
### Fixed
- Validator was creating invalid createReportInput xml in case of no scenrio match
From 3231c66c37546c8a2b8a2a866a0c598eddcf163c Mon Sep 17 00:00:00 2001
From: "Andreas Penski (init)"
Date: Wed, 24 Jun 2020 13:13:25 +0200
Subject: [PATCH 082/306] [maven-release-plugin] prepare release v1.2.1
---
pom.xml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/pom.xml b/pom.xml
index 32e5859..a8fd5e3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
KoSIT XML Prüftool Implementierungde.kosit
- 1.2.1-SNAPSHOT
+ 1.2.1validationtoolKoSIT XML Validator against XSD and Schematron based on defined scenarios.
@@ -451,7 +451,7 @@
https://github.com/itplr-kosit/validationtool.gitscm:git:https://projekte.kosit.org/kosit/validator.git
- v1.1.1
+ v1.2.1
-
+4.0.0KoSIT XML Prüftool Implementierungde.kosit
- 1.3.0-SNAPSHOT
+ 1.3.0validationtoolKoSIT XML Validator against XSD and Schematron based on defined scenarios.
@@ -493,7 +493,7 @@
https://github.com/itplr-kosit/validationtool.gitscm:git:https://projekte.kosit.org/kosit/validator.git
- v1.1.0
+ v1.3.0
+
+
+