mirror of
https://github.com/itplr-kosit/validator.git
synced 2026-05-25 16:55:39 +00:00
Merge remote-tracking branch 'my/#20_memory_effeciency' into mit_s9
This commit is contained in:
commit
1df734ad21
17 changed files with 145 additions and 120 deletions
|
|
@ -24,6 +24,8 @@ import java.util.stream.Collectors;
|
|||
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import net.sf.saxon.s9api.XdmNode;
|
||||
|
||||
/**
|
||||
* Zentrale Schnittstellendefinition für das Prüf-Tool.
|
||||
*
|
||||
|
|
@ -37,7 +39,7 @@ public interface Check {
|
|||
* @param input die Resource / XML-Datei, die geprüft werden soll.
|
||||
* @return ein Ergebnis-{@link Document}
|
||||
*/
|
||||
Document check(Input input);
|
||||
XdmNode check(Input input);
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -46,8 +48,8 @@ public interface Check {
|
|||
* @param input die Eingabe
|
||||
* @return Liste mit Ergebnis-Dokumenten
|
||||
*/
|
||||
default List<Document> check(List<Input> input) {
|
||||
return input.stream().map(i -> check(i)).collect(Collectors.toList());
|
||||
default List<XdmNode> check(List<Input> input) {
|
||||
return input.stream().map(this::check).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,12 @@ package de.kosit.validationtool.api;
|
|||
|
||||
import static org.apache.commons.lang3.StringUtils.isNotEmpty;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
|
@ -51,7 +56,7 @@ public class InputFactory {
|
|||
|
||||
private static final int DEFAULT_BUFFER_SIZE = 4096;
|
||||
|
||||
public static final String MESSAGE_OPEN_STREAM_ERROR = "Can not open stream from";
|
||||
private static final String MESSAGE_OPEN_STREAM_ERROR = "Can not open stream from";
|
||||
|
||||
@Getter
|
||||
private final String algorithm;
|
||||
|
|
|
|||
|
|
@ -19,24 +19,29 @@
|
|||
|
||||
package de.kosit.validationtool.cmd;
|
||||
|
||||
import de.kosit.validationtool.cmd.assertions.AssertionType;
|
||||
import de.kosit.validationtool.cmd.assertions.Assertions;
|
||||
import de.kosit.validationtool.impl.model.Result;
|
||||
import de.kosit.validationtool.impl.tasks.CheckAction;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.sf.saxon.s9api.*;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import de.kosit.validationtool.cmd.assertions.AssertionType;
|
||||
import de.kosit.validationtool.cmd.assertions.Assertions;
|
||||
import de.kosit.validationtool.impl.model.Result;
|
||||
import de.kosit.validationtool.impl.tasks.CheckAction;
|
||||
|
||||
import net.sf.saxon.s9api.Processor;
|
||||
import net.sf.saxon.s9api.SaxonApiException;
|
||||
import net.sf.saxon.s9api.XPathCompiler;
|
||||
import net.sf.saxon.s9api.XPathSelector;
|
||||
import net.sf.saxon.s9api.XdmNode;
|
||||
|
||||
/**
|
||||
* Überprüft den Report mittels bereitgestellter Assertions. Diese {@link CheckAction} dient der Überprüfung der von der
|
||||
* KoSIT bereitgestellten Prüfszenarien und den darin enthaltenen Artefakten.
|
||||
|
|
@ -64,7 +69,7 @@ public class CheckAssertionAction implements CheckAction {
|
|||
final List<AssertionType> toCheck = findAssertions(results.getName());
|
||||
final List<String> errors = new ArrayList<>();
|
||||
if (toCheck != null && !toCheck.isEmpty()) {
|
||||
final XdmNode node = loadDocument(results.getReport());
|
||||
final XdmNode node = results.getReport();
|
||||
toCheck.forEach(a -> {
|
||||
if (!check(node, a)) {
|
||||
log.error("Assertion mismatch: {}", a.getValue());
|
||||
|
|
@ -86,15 +91,6 @@ public class CheckAssertionAction implements CheckAction {
|
|||
return getMapped().entrySet().stream().filter(e -> matches(e.getKey(), name)).map(Map.Entry::getValue).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
private XdmNode loadDocument(Document d) {
|
||||
DocumentBuilder documentBuilder = getProcessor().newDocumentBuilder();
|
||||
try {
|
||||
return documentBuilder.build(new DOMSource(d));
|
||||
} catch (SaxonApiException e) {
|
||||
log.error("Can not load result document. Therefore can not run defined assertions", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean check(XdmNode document, AssertionType assertion) {
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -23,15 +23,19 @@ import java.nio.file.Path;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import de.kosit.validationtool.impl.ContentRepository;
|
||||
import de.kosit.validationtool.impl.tasks.CheckAction;
|
||||
|
||||
import net.sf.saxon.s9api.*;
|
||||
import net.sf.saxon.s9api.QName;
|
||||
import net.sf.saxon.s9api.SaxonApiException;
|
||||
import net.sf.saxon.s9api.Serializer;
|
||||
import net.sf.saxon.s9api.XPathExecutable;
|
||||
import net.sf.saxon.s9api.XPathSelector;
|
||||
import net.sf.saxon.s9api.XdmItem;
|
||||
import net.sf.saxon.s9api.XdmNode;
|
||||
|
||||
/**
|
||||
* Extrahiert HTML-Dokumente aus dem Report und persistiert diese im konfigurierten Ausgabe-Verzeichnis.
|
||||
|
|
@ -54,9 +58,7 @@ public class ExtractHtmlContentAction implements CheckAction {
|
|||
public void check(Bag results) {
|
||||
try {
|
||||
final XPathSelector selector = getSelector();
|
||||
DocumentBuilder documentBuilder = repository.getProcessor().newDocumentBuilder();
|
||||
|
||||
final XdmNode xdmSource = documentBuilder.build(new DOMSource(results.getReport()));
|
||||
final XdmNode xdmSource = results.getReport();
|
||||
selector.setContextItem(xdmSource);
|
||||
selector.forEach(m -> print(results.getName(), m));
|
||||
|
||||
|
|
|
|||
|
|
@ -21,18 +21,14 @@ package de.kosit.validationtool.cmd;
|
|||
|
||||
import java.io.StringWriter;
|
||||
|
||||
import javax.xml.transform.Result;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import de.kosit.validationtool.impl.ObjectFactory;
|
||||
import de.kosit.validationtool.impl.tasks.CheckAction;
|
||||
|
||||
import net.sf.saxon.s9api.SaxonApiException;
|
||||
import net.sf.saxon.s9api.Serializer;
|
||||
|
||||
/**
|
||||
* Gibt das Ergebnis-Document auf std-out aus.
|
||||
*
|
||||
|
|
@ -44,13 +40,11 @@ public class PrintReportAction implements CheckAction {
|
|||
@Override
|
||||
public void check(Bag results) {
|
||||
try {
|
||||
Transformer transformer = ObjectFactory.createTransformer(true);
|
||||
final StringWriter writer = new StringWriter();
|
||||
Result output = new StreamResult(writer);
|
||||
Source input = new DOMSource(results.getReport());
|
||||
transformer.transform(input, output);
|
||||
final Serializer serializer = ObjectFactory.createProcessor().newSerializer(writer);
|
||||
serializer.serializeNode(results.getReport());
|
||||
System.out.print(writer.toString());
|
||||
} catch (TransformerException e) {
|
||||
} catch (SaxonApiException e) {
|
||||
log.error("Error while printing result to stdout", e);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,18 +19,16 @@
|
|||
|
||||
package de.kosit.validationtool.cmd;
|
||||
|
||||
import de.kosit.validationtool.impl.ObjectFactory;
|
||||
import de.kosit.validationtool.impl.tasks.CheckAction;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import javax.xml.transform.Result;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import java.nio.file.Path;
|
||||
import de.kosit.validationtool.impl.ObjectFactory;
|
||||
import de.kosit.validationtool.impl.tasks.CheckAction;
|
||||
|
||||
import net.sf.saxon.s9api.SaxonApiException;
|
||||
import net.sf.saxon.s9api.Serializer;
|
||||
|
||||
/**
|
||||
* Schreibt das Prüfergebnis als XML-Dokument an eine definierte Stelle.
|
||||
|
|
@ -48,11 +46,9 @@ public class SerializeReportAction implements CheckAction {
|
|||
final Path file = outputDirectory.resolve(results.getName() + "-report.xml");
|
||||
try {
|
||||
log.info("Serializing result to {}", file.toAbsolutePath());
|
||||
Transformer transformer = ObjectFactory.createTransformer(true);
|
||||
Result output = new StreamResult(file.toFile());
|
||||
Source input = new DOMSource(results.getReport());
|
||||
transformer.transform(input, output);
|
||||
} catch (TransformerException e) {
|
||||
final Serializer serializer = ObjectFactory.createProcessor().newSerializer(file.toFile());
|
||||
serializer.serializeNode(results.getReport());
|
||||
} catch (SaxonApiException e) {
|
||||
log.error("Can not serialize result report to {}", file.toAbsolutePath(), e);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,21 +24,26 @@ import java.util.Iterator;
|
|||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import de.kosit.validationtool.api.Check;
|
||||
import de.kosit.validationtool.api.CheckConfiguration;
|
||||
import de.kosit.validationtool.api.Input;
|
||||
import de.kosit.validationtool.impl.tasks.*;
|
||||
import de.kosit.validationtool.impl.tasks.CheckAction;
|
||||
import de.kosit.validationtool.impl.tasks.CreateReportAction;
|
||||
import de.kosit.validationtool.impl.tasks.DocumentParseAction;
|
||||
import de.kosit.validationtool.impl.tasks.ScenarioSelectionAction;
|
||||
import de.kosit.validationtool.impl.tasks.SchemaValidationAction;
|
||||
import de.kosit.validationtool.impl.tasks.SchematronValidationAction;
|
||||
import de.kosit.validationtool.impl.tasks.ValidateReportInputAction;
|
||||
import de.kosit.validationtool.model.reportInput.CreateReportInput;
|
||||
import de.kosit.validationtool.model.reportInput.DocumentIdentificationType;
|
||||
import de.kosit.validationtool.model.reportInput.EngineType;
|
||||
import de.kosit.validationtool.model.reportInput.ProcessingError;
|
||||
|
||||
import net.sf.saxon.s9api.Processor;
|
||||
import net.sf.saxon.s9api.XdmNode;
|
||||
|
||||
/**
|
||||
* Die Referenz-Implementierung für den Prüfprozess. Nach initialer Konfiguration ist diese Klasse threadsafe und kann
|
||||
|
|
@ -95,22 +100,24 @@ public class DefaultCheck implements Check {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Document check(Input input) {
|
||||
public XdmNode check(Input input) {
|
||||
CheckAction.Bag t = new CheckAction.Bag(input, createReport());
|
||||
return runCheckInternal(t);
|
||||
}
|
||||
|
||||
protected Document runCheckInternal(CheckAction.Bag t) {
|
||||
protected XdmNode runCheckInternal(CheckAction.Bag t) {
|
||||
long started = System.currentTimeMillis();
|
||||
log.info("Checking content of {}", t.getInput().getName());
|
||||
Iterator<CheckAction> it = checkSteps.iterator();
|
||||
|
||||
|
||||
while (it.hasNext()) {
|
||||
long start = System.currentTimeMillis();
|
||||
final CheckAction action = it.next();
|
||||
if (!action.isSkipped(t)) {
|
||||
action.check(t);
|
||||
}
|
||||
log.info("Step {} finished in {}ms", action.getClass().getSimpleName(), System.currentTimeMillis() - start);
|
||||
if (t.isStopped()) {
|
||||
final ProcessingError processingError = t.getReportInput().getProcessingError();
|
||||
log.error("Error processing input {}: {}", t.getInput().getName(),
|
||||
|
|
|
|||
|
|
@ -19,17 +19,21 @@
|
|||
|
||||
package de.kosit.validationtool.impl.tasks;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import de.kosit.validationtool.api.Input;
|
||||
import de.kosit.validationtool.impl.model.Result;
|
||||
import de.kosit.validationtool.model.reportInput.CreateReportInput;
|
||||
import de.kosit.validationtool.model.reportInput.XMLSyntaxError;
|
||||
import de.kosit.validationtool.model.scenarios.ScenarioType;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import net.sf.saxon.s9api.XdmNode;
|
||||
|
||||
/**
|
||||
* Interface, welches von allen Prüfschritten implementiert wird. Der Parameter vom Typ {@link Bag} dient dabei sowohl
|
||||
|
|
@ -72,7 +76,7 @@ public interface CheckAction {
|
|||
private CreateReportInput reportInput;
|
||||
|
||||
/** Das finale Ergebnis */
|
||||
private Document report;
|
||||
private XdmNode report;
|
||||
|
||||
private boolean finished;
|
||||
|
||||
|
|
|
|||
|
|
@ -27,11 +27,22 @@ import org.w3c.dom.Document;
|
|||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import de.kosit.validationtool.impl.*;
|
||||
import de.kosit.validationtool.impl.CollectingErrorEventHandler;
|
||||
import de.kosit.validationtool.impl.ConversionService;
|
||||
import de.kosit.validationtool.impl.ObjectFactory;
|
||||
import de.kosit.validationtool.impl.RelativeUriResolver;
|
||||
import de.kosit.validationtool.impl.ScenarioRepository;
|
||||
import de.kosit.validationtool.impl.model.Result;
|
||||
import de.kosit.validationtool.model.scenarios.ScenarioType;
|
||||
|
||||
import net.sf.saxon.s9api.*;
|
||||
import net.sf.saxon.s9api.DocumentBuilder;
|
||||
import net.sf.saxon.s9api.Processor;
|
||||
import net.sf.saxon.s9api.QName;
|
||||
import net.sf.saxon.s9api.SaxonApiException;
|
||||
import net.sf.saxon.s9api.XdmDestination;
|
||||
import net.sf.saxon.s9api.XdmNode;
|
||||
import net.sf.saxon.s9api.XsltExecutable;
|
||||
import net.sf.saxon.s9api.XsltTransformer;
|
||||
|
||||
/**
|
||||
* Erzeugt den Report auf Basis der gesammelten Informationen über den Prüfling. Sollte kein Szenario identifiziert
|
||||
|
|
@ -73,10 +84,10 @@ public class CreateReportAction implements CheckAction {
|
|||
transformer.setURIResolver(resolver);
|
||||
transformer.getUnderlyingController().setUnparsedTextURIResolver(resolver);
|
||||
transformer.setParameter(new QName("input-document"), parsedDocument);
|
||||
Document result = ObjectFactory.createDocumentBuilder(false).newDocument();
|
||||
transformer.setDestination(new DOMDestination(result));
|
||||
final XdmDestination destination = new XdmDestination();
|
||||
transformer.setDestination(destination);
|
||||
transformer.transform();
|
||||
results.setReport(result);
|
||||
results.setReport(destination.getXdmNode());
|
||||
|
||||
} catch (SaxonApiException e) {
|
||||
throw new IllegalStateException("Can not create final report", e);
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ public class CheckAssertionActionTest {
|
|||
@Test
|
||||
public void testSimple() throws URISyntaxException {
|
||||
final CheckAction.Bag bag = new CheckAction.Bag(InputFactory.read(SAMPLE), new CreateReportInput());
|
||||
bag.setReport(Helper.load(SAMPLE_REPORT).getObject());
|
||||
bag.setReport(Helper.load(SAMPLE_REPORT));
|
||||
|
||||
final Assertions assertions = Helper.load(SAMPLE_ASSERTIONS, Assertions.class);
|
||||
CheckAssertionAction a = new CheckAssertionAction(assertions, ObjectFactory.createProcessor());
|
||||
|
|
|
|||
|
|
@ -19,8 +19,14 @@
|
|||
|
||||
package de.kosit.validationtool.cmd;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import static de.kosit.validationtool.impl.Helper.ASSERTIONS;
|
||||
import static de.kosit.validationtool.impl.Helper.NOT_EXISTING;
|
||||
import static de.kosit.validationtool.impl.Helper.REPOSITORY;
|
||||
import static de.kosit.validationtool.impl.Helper.SAMPLE;
|
||||
import static de.kosit.validationtool.impl.Helper.SAMPLE2;
|
||||
import static de.kosit.validationtool.impl.Helper.SAMPLE_DIR;
|
||||
import static de.kosit.validationtool.impl.Helper.SCENARIO_FILE;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
|
|
@ -28,8 +34,8 @@ import java.nio.file.Path;
|
|||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
|
||||
import static de.kosit.validationtool.impl.Helper.*;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Testet die Parameter des Kommandozeilen-Tools.
|
||||
|
|
@ -146,7 +152,7 @@ public class CommandlineApplicationTest {
|
|||
Paths.get(SAMPLE).toString() };
|
||||
CommandLineApplication.mainProgram(args);
|
||||
assertThat(commandLine.getErrorOutput()).contains(RESULT_OUTPUT);
|
||||
assertThat(commandLine.getOutputLines()).contains("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
|
||||
assertThat(commandLine.getOutputLines().get(0)).contains("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ public class ExtractHtmlActionTest {
|
|||
public void testSimple() throws IOException {
|
||||
CheckAction.Bag b = new CheckAction.Bag(InputFactory.read(REPORT));
|
||||
assertThat(action.isSkipped(b)).isTrue();
|
||||
b.setReport(Helper.load(REPORT).getObject());
|
||||
b.setReport(Helper.load(REPORT));
|
||||
action.check(b);
|
||||
assertThat(action.isSkipped(b)).isFalse();
|
||||
action.check(b);
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ public class PrintReportActionTest {
|
|||
@Test
|
||||
public void testSimpleSerialize() {
|
||||
CheckAction.Bag b = new CheckAction.Bag(InputFactory.read(REPORT));
|
||||
b.setReport(Helper.load(REPORT).getObject());
|
||||
b.setReport(Helper.load(REPORT));
|
||||
assertThat(action.isSkipped(b)).isFalse();
|
||||
action.check(b);
|
||||
assertThat(b.isStopped()).isFalse();
|
||||
|
|
|
|||
|
|
@ -19,20 +19,21 @@
|
|||
|
||||
package de.kosit.validationtool.cmd;
|
||||
|
||||
import de.kosit.validationtool.api.InputFactory;
|
||||
import de.kosit.validationtool.impl.Helper;
|
||||
import de.kosit.validationtool.impl.tasks.CheckAction;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
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 static org.assertj.core.api.Assertions.assertThat;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import de.kosit.validationtool.api.InputFactory;
|
||||
import de.kosit.validationtool.impl.Helper;
|
||||
import de.kosit.validationtool.impl.tasks.CheckAction;
|
||||
|
||||
/**
|
||||
* @author Andreas Penski
|
||||
|
|
@ -60,7 +61,7 @@ public class SerializeReportActionTest {
|
|||
public void testSimpleSerialize() {
|
||||
CheckAction.Bag b = new CheckAction.Bag(InputFactory.read(REPORT));
|
||||
assertThat(action.isSkipped(b)).isTrue();
|
||||
b.setReport(Helper.load(REPORT).getObject());
|
||||
b.setReport(Helper.load(REPORT));
|
||||
assertThat(action.isSkipped(b)).isFalse();
|
||||
action.check(b);
|
||||
assertThat(b.isStopped()).isFalse();
|
||||
|
|
|
|||
|
|
@ -19,11 +19,8 @@
|
|||
|
||||
package de.kosit.validationtool.impl;
|
||||
|
||||
import de.kosit.validationtool.api.CheckConfiguration;
|
||||
import de.kosit.validationtool.api.Input;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
import static de.kosit.validationtool.api.InputFactory.read;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URISyntaxException;
|
||||
|
|
@ -32,8 +29,13 @@ import java.util.List;
|
|||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import static de.kosit.validationtool.api.InputFactory.read;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import de.kosit.validationtool.api.CheckConfiguration;
|
||||
import de.kosit.validationtool.api.Input;
|
||||
|
||||
import net.sf.saxon.s9api.XdmNode;
|
||||
|
||||
/**
|
||||
* Test das Check-Interface
|
||||
|
|
@ -60,14 +62,14 @@ public class DefaultCheckTest {
|
|||
|
||||
@Test
|
||||
public void testHappyCase() throws Exception {
|
||||
final Document doc = implementation.check(read(VALID_EXAMPLE));
|
||||
final XdmNode doc = implementation.check(read(VALID_EXAMPLE));
|
||||
assertThat(doc).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleCase() throws Exception {
|
||||
final List<Input> input = IntStream.range(0, MULTI_COUNT).mapToObj(i -> read(VALID_EXAMPLE)).collect(Collectors.toList());
|
||||
final List<Document> docs = implementation.check(input);
|
||||
final List<XdmNode> docs = implementation.check(input);
|
||||
assertThat(docs).isNotNull();
|
||||
assertThat(docs).hasSize(MULTI_COUNT);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,18 +20,17 @@
|
|||
package de.kosit.validationtool.impl;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
import de.kosit.validationtool.api.InputFactory;
|
||||
import de.kosit.validationtool.impl.model.Result;
|
||||
import de.kosit.validationtool.impl.tasks.CheckAction;
|
||||
import de.kosit.validationtool.impl.tasks.DocumentParseAction;
|
||||
import de.kosit.validationtool.model.reportInput.XMLSyntaxError;
|
||||
import net.sf.saxon.s9api.SaxonApiException;
|
||||
import net.sf.saxon.s9api.XdmNode;
|
||||
|
||||
/**
|
||||
* Helferlein für Test-Artefakte
|
||||
|
|
@ -50,36 +49,38 @@ public class Helper {
|
|||
|
||||
public static final URI TEST_ROOT = Paths.get("src/test/resources").toUri();
|
||||
|
||||
|
||||
|
||||
public static final URI EXAMPLES_DIR = TEST_ROOT.resolve("examples/");
|
||||
|
||||
public static final URI ASSERTIONS = EXAMPLES_DIR.resolve("assertions/tests-xrechnung.xml");
|
||||
|
||||
public static final URI SCENARIO_FILE = EXAMPLES_DIR.resolve("UBLReady/scenarios-2.xml");
|
||||
|
||||
|
||||
public static final URI REPOSITORY = EXAMPLES_DIR.resolve("repository/");
|
||||
|
||||
public static final URI NOT_EXISTING = EXAMPLES_DIR.resolve("doesnotexist");
|
||||
|
||||
public static final URI SAMPLE_DIR = EXAMPLES_DIR.resolve("UBLReady/");
|
||||
|
||||
public static final URI SAMPLE_XSLT = EXAMPLES_DIR.resolve("repository/resources/eRechnung/report.xsl");
|
||||
|
||||
public static final URI SAMPLE = SAMPLE_DIR.resolve("UBLReady_EU_UBL-NL_20170102_FULL.xml");
|
||||
|
||||
public static final URI SAMPLE2 = SAMPLE_DIR.resolve("UBLReady_EU_UBL-NL_20170102_FULL-invalid.xml");
|
||||
|
||||
|
||||
/**
|
||||
* Lädt ein XML-Dokument von der gegebenen URL
|
||||
*
|
||||
* @param url die url die geladen werden soll
|
||||
* @return ein result objekt mit Dokument
|
||||
*/
|
||||
public static Result<Document, XMLSyntaxError> load(URL url) {
|
||||
DocumentParseAction a = new DocumentParseAction();
|
||||
CheckAction.Bag b = new CheckAction.Bag(InputFactory.read(url));
|
||||
a.check(b);
|
||||
return b.getParserResult();
|
||||
public static XdmNode load(URL url) {
|
||||
try ( InputStream input = url.openStream() ) {
|
||||
return ObjectFactory.createProcessor().newDocumentBuilder().build(new StreamSource(input));
|
||||
} catch (SaxonApiException | IOException e) {
|
||||
throw new IllegalStateException("Fehler beim Laden der XML-Datei", e);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static <T> T load(URL url, Class<T> type) throws URISyntaxException {
|
||||
|
|
@ -98,5 +99,5 @@ public class Helper {
|
|||
public static ContentRepository loadTestRepository() {
|
||||
return new ContentRepository(ObjectFactory.createProcessor(), new File("src/test/resources/examples/repository").toURI());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,7 +69,6 @@ public class SchemaValidatorActionTest {
|
|||
@Test
|
||||
public void testSimple() {
|
||||
CheckAction.Bag bag = new CheckAction.Bag(InputFactory.read(VALID_EXAMPLE), new CreateReportInput());
|
||||
bag.setParserResult(Helper.load(VALID_EXAMPLE));
|
||||
ScenarioType t = new ScenarioType();
|
||||
ValidateWithXmlSchema v = new ValidateWithXmlSchema();
|
||||
ResourceType r = new ResourceType();
|
||||
|
|
@ -88,7 +87,6 @@ public class SchemaValidatorActionTest {
|
|||
@Test
|
||||
public void testValidationFailure() throws MalformedURLException {
|
||||
CheckAction.Bag bag = new CheckAction.Bag(InputFactory.read(INVALID_EXAMPLE.toURL()), new CreateReportInput());
|
||||
bag.setParserResult(Helper.load(INVALID_EXAMPLE.toURL()));
|
||||
ScenarioType t = new ScenarioType();
|
||||
ValidateWithXmlSchema v = new ValidateWithXmlSchema();
|
||||
ResourceType r = new ResourceType();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue