(chore) Erweiterung des Interface um API-Kompatibilität sicherzustellen

This commit is contained in:
Andreas Penski (init) 2019-02-08 14:57:34 +01:00
parent 77665936ed
commit 5614e99e00
4 changed files with 54 additions and 10 deletions

View file

@ -24,6 +24,7 @@ import java.util.stream.Collectors;
import org.w3c.dom.Document;
import net.sf.saxon.dom.NodeOverNodeInfo;
import net.sf.saxon.s9api.XdmNode;
/**
@ -35,21 +36,46 @@ public interface Check {
/**
* Führt die konfigurierte Prüfung für die übergebene Resource aus.
*
*
* @param input die Resource / XML-Datei, die geprüft werden soll.
* @return ein Ergebnis-{@link Document}
* @deprecated use {@link #checkInput(Input)}
*/
@Deprecated
default Document check(Input input) {
final XdmNode node = checkInput(input);
// readonly view of the document!!!
return (Document) NodeOverNodeInfo.wrap(node.getUnderlyingNode());
}
/**
* Führt die konfigurierte Prüfung für die übergebene Resource aus.
*
* @param input die Resource / XML-Datei, die geprüft werden soll.
* @return ein Ergebnis-{@link Document}
*/
XdmNode check(Input input);
XdmNode checkInput(Input input);
/**
* Führt eine Prüfung im Batch-Mode durch. Die Default-Implementierung führt die Prüfung sequentiell aus.
*
* @param input die Eingabe
* @return Liste mit Ergebnis-Dokumenten
* @deprecated use {@link #checkInput(List)}
*/
default List<XdmNode> check(List<Input> input) {
@Deprecated
default List<Document> check(List<Input> input) {
return input.stream().map(this::check).collect(Collectors.toList());
}
/**
* Führt eine Prüfung im Batch-Mode durch. Die Default-Implementierung führt die Prüfung sequentiell aus.
*
* @param input die Eingabe
* @return Liste mit Ergebnis-Dokumenten
*/
default List<XdmNode> checkInput(List<Input> input) {
return input.stream().map(this::checkInput).collect(Collectors.toList());
}
}

View file

@ -26,6 +26,8 @@ import de.kosit.validationtool.api.Input;
import de.kosit.validationtool.impl.DefaultCheck;
import de.kosit.validationtool.impl.tasks.CheckAction;
import net.sf.saxon.s9api.XdmNode;
/**
* Simple Erweiterung der Klasse {@link DefaultCheck} um das Ergebnis der Assertion-Prüfung auszwerten und auszugeben.
* Diese Klasse stellt keine fachlicher Erweiterung des eigentlichen Prüfvorganges dar!
@ -54,16 +56,17 @@ class InternalCheck extends DefaultCheck {
* @param input die Prüflinge
* @return false wenn es Assertion-Fehler gibt, sonst true
*/
void checkInput(Input input) {
public XdmNode checkInput(Input input) {
CheckAction.Bag bag = new CheckAction.Bag(input, createReport());
runCheckInternal(bag);
XdmNode result = runCheckInternal(bag);
if (bag.getAssertionResult() != null) {
checkAssertions += bag.getAssertionResult().getObject();
failedAssertions += bag.getAssertionResult().getErrors().size();
}
return result;
}
public boolean printAndEvaluate() {
boolean printAndEvaluate() {
if (failedAssertions > 0) {
log.error("Assertion check failed.\n\nAssertions run: {}, Assertions failed: {}\n", checkAssertions, failedAssertions);
} else if (checkAssertions > 0) {

View file

@ -100,7 +100,7 @@ public class DefaultCheck implements Check {
}
@Override
public XdmNode check(Input input) {
public XdmNode checkInput(Input input) {
CheckAction.Bag t = new CheckAction.Bag(input, createReport());
return runCheckInternal(t);
}

View file

@ -31,6 +31,7 @@ import java.util.stream.IntStream;
import org.junit.Before;
import org.junit.Test;
import org.w3c.dom.Document;
import de.kosit.validationtool.api.CheckConfiguration;
import de.kosit.validationtool.api.Input;
@ -62,14 +63,28 @@ public class DefaultCheckTest {
@Test
public void testHappyCase() throws Exception {
final XdmNode doc = implementation.check(read(VALID_EXAMPLE));
final XdmNode doc = implementation.checkInput(read(VALID_EXAMPLE));
assertThat(doc).isNotNull();
}
@Test
public void testHappyCaseDocument() throws Exception {
final Document 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<XdmNode> docs = implementation.check(input);
final List<XdmNode> docs = implementation.checkInput(input);
assertThat(docs).isNotNull();
assertThat(docs).hasSize(MULTI_COUNT);
}
@Test
public void testMultipleCaseDocument() 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);
assertThat(docs).isNotNull();
assertThat(docs).hasSize(MULTI_COUNT);
}