support for XdmNode as Input

cleanup
This commit is contained in:
Andreas Penski (init) 2020-08-13 10:04:34 +02:00
parent f9c6248513
commit a41336e9cf
14 changed files with 227 additions and 38 deletions

View file

@ -19,6 +19,7 @@
package de.kosit.validationtool.api;
import static de.kosit.validationtool.impl.Helper.Simple.SIMPLE_VALID;
import static de.kosit.validationtool.impl.input.StreamHelper.drain;
import static org.assertj.core.api.Assertions.assertThat;
@ -31,7 +32,6 @@ 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;
@ -188,8 +188,7 @@ public class InputFactoryTest {
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();
assertThat(domInput.getSource()).isNotNull();
final Result<XdmNode, XMLSyntaxError> parsed = Helper.parseDocument(domInput);
assertThat(parsed.isValid()).isTrue();
@ -197,4 +196,17 @@ public class InputFactoryTest {
assertThat(Helper.parseDocument(domInput).getObject()).isNotNull();
}
@Test
public void testXdmNode() throws Exception {
final XdmNode node = TestObjectFactory.createProcessor().newDocumentBuilder().build(new StreamSource(SIMPLE_VALID.toASCIIString()));
final Input nodeInput = InputFactory.read(node, "node test");
assertThat(nodeInput).isNotNull();
assertThat(nodeInput.getSource()).isNotNull();
final Result<XdmNode, XMLSyntaxError> parsed = Helper.parseDocument(nodeInput);
assertThat(parsed.isValid()).isTrue();
// read twice
assertThat(Helper.parseDocument(nodeInput).getObject()).isNotNull();
}
}

View file

@ -35,6 +35,8 @@ import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import javax.xml.transform.stream.StreamSource;
import org.junit.Before;
import org.junit.Test;
import org.w3c.dom.Document;
@ -42,9 +44,12 @@ import org.w3c.dom.Document;
import de.kosit.validationtool.api.AcceptRecommendation;
import de.kosit.validationtool.api.Configuration;
import de.kosit.validationtool.api.Input;
import de.kosit.validationtool.api.InputFactory;
import de.kosit.validationtool.api.Result;
import de.kosit.validationtool.impl.Helper.Simple;
import net.sf.saxon.s9api.XdmNode;
/**
* Test das Check-Interface
*
@ -238,4 +243,18 @@ public class DefaultCheckTest {
assertThat(result.getProcessingErrors()).hasSize(1);
}
@Test
public void testXdmNode() throws Exception {
XdmNode node = TestObjectFactory.createProcessor().newDocumentBuilder().build(new StreamSource(SIMPLE_VALID.toASCIIString()));
Input domInput = InputFactory.read(node, "node test");
Result result = this.validCheck.checkInput(domInput);
assertThat(result.isProcessingSuccessful()).isEqualTo(true);
// test compatible configuration
node = this.validCheck.getConfiguration().getContentRepository().getProcessor().newDocumentBuilder()
.build(new StreamSource(SIMPLE_VALID.toASCIIString()));
domInput = InputFactory.read(node, "node test");
result = this.validCheck.checkInput(domInput);
assertThat(result.isProcessingSuccessful()).isEqualTo(true);
}
}