mirror of
https://github.com/itplr-kosit/validator.git
synced 2026-05-26 01:05:38 +00:00
(enhance) introduce resolving strategy (configurable xml security); introduce API configuration
This commit is contained in:
parent
7a86f049ac
commit
35c0797898
67 changed files with 2441 additions and 845 deletions
|
|
@ -31,7 +31,7 @@ import org.junit.Test;
|
|||
import de.kosit.validationtool.api.InputFactory;
|
||||
import de.kosit.validationtool.cmd.assertions.Assertions;
|
||||
import de.kosit.validationtool.impl.Helper;
|
||||
import de.kosit.validationtool.impl.ObjectFactory;
|
||||
import de.kosit.validationtool.impl.TestObjectFactory;
|
||||
import de.kosit.validationtool.impl.tasks.CheckAction;
|
||||
import de.kosit.validationtool.model.reportInput.CreateReportInput;
|
||||
|
||||
|
|
@ -52,15 +52,15 @@ public class CheckAssertionActionTest {
|
|||
|
||||
@Before
|
||||
public void setup() throws IOException {
|
||||
commandLine = new CommandLine();
|
||||
commandLine.activate();
|
||||
this.commandLine = new CommandLine();
|
||||
this.commandLine.activate();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyInput() {
|
||||
CheckAssertionAction a = new CheckAssertionAction(new Assertions(), ObjectFactory.createProcessor());
|
||||
final CheckAssertionAction a = new CheckAssertionAction(new Assertions(), TestObjectFactory.createProcessor());
|
||||
a.check(new CheckAction.Bag(InputFactory.read(SAMPLE), new CreateReportInput()));
|
||||
assertThat(commandLine.getErrorOutput()).contains("Can not find assertions for");
|
||||
assertThat(this.commandLine.getErrorOutput()).contains("Can not find assertions for");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -69,9 +69,9 @@ public class CheckAssertionActionTest {
|
|||
bag.setReport(Helper.load(SAMPLE_REPORT));
|
||||
|
||||
final Assertions assertions = Helper.load(SAMPLE_ASSERTIONS, Assertions.class);
|
||||
CheckAssertionAction a = new CheckAssertionAction(assertions, ObjectFactory.createProcessor());
|
||||
final CheckAssertionAction a = new CheckAssertionAction(assertions, TestObjectFactory.createProcessor());
|
||||
a.check(bag);
|
||||
|
||||
assertThat(commandLine.getErrorOutput()).contains("Assertion mismatch");
|
||||
assertThat(this.commandLine.getErrorOutput()).contains("Assertion mismatch");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -105,12 +105,13 @@ public class CommandlineApplicationTest {
|
|||
final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), Paths.get(Simple.NOT_EXISTING).toString() };
|
||||
CommandLineApplication.mainProgram(args);
|
||||
assertThat(this.commandLine.getErrorOutput()).isNotEmpty();
|
||||
assertThat(this.commandLine.getErrorOutput()).contains("Can not load schema from sources");
|
||||
assertThat(this.commandLine.getErrorOutput()).contains("Can not resolve");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotExistingTestTarget() {
|
||||
final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-r", Paths.get(Simple.REPOSITORY).toString(),
|
||||
final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-r",
|
||||
Paths.get(Simple.REPOSITORY_URI).toString(),
|
||||
Paths.get(Simple.NOT_EXISTING).toString() };
|
||||
CommandLineApplication.mainProgram(args);
|
||||
assertThat(this.commandLine.getErrorOutput()).isNotEmpty();
|
||||
|
|
@ -119,7 +120,8 @@ public class CommandlineApplicationTest {
|
|||
|
||||
@Test
|
||||
public void testValidMinimalConfiguration() {
|
||||
final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-r", Paths.get(Simple.REPOSITORY).toString(),
|
||||
final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-r",
|
||||
Paths.get(Simple.REPOSITORY_URI).toString(),
|
||||
Paths.get(Simple.SIMPLE_VALID).toString() };
|
||||
CommandLineApplication.mainProgram(args);
|
||||
assertThat(this.commandLine.getErrorOutput()).contains(RESULT_OUTPUT);
|
||||
|
|
@ -128,7 +130,7 @@ public class CommandlineApplicationTest {
|
|||
@Test
|
||||
public void testValidMultipleInput() {
|
||||
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() };
|
||||
Paths.get(Simple.REPOSITORY_URI).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");
|
||||
}
|
||||
|
|
@ -136,7 +138,7 @@ public class CommandlineApplicationTest {
|
|||
@Test
|
||||
public void testValidDirectoryInput() {
|
||||
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() };
|
||||
Paths.get(Simple.REPOSITORY_URI).toString(), Paths.get(Simple.EXAMPLES).toString() };
|
||||
CommandLineApplication.mainProgram(args);
|
||||
assertThat(this.commandLine.getErrorOutput()).contains("Processing 6 object(s) completed");
|
||||
}
|
||||
|
|
@ -145,7 +147,7 @@ public class CommandlineApplicationTest {
|
|||
public void testValidOutputConfiguration() throws IOException {
|
||||
|
||||
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.REPOSITORY_URI).toString(), Paths.get(Simple.SIMPLE_VALID).toString() };
|
||||
CommandLineApplication.mainProgram(args);
|
||||
assertThat(this.commandLine.getErrorOutput()).contains(RESULT_OUTPUT);
|
||||
assertThat(this.output).exists();
|
||||
|
|
@ -155,7 +157,8 @@ public class CommandlineApplicationTest {
|
|||
@Test
|
||||
public void testNoInput() {
|
||||
// assertThat(output).doesNotExist();
|
||||
final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-r", Paths.get(Simple.REPOSITORY).toString(), };
|
||||
final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-r",
|
||||
Paths.get(Simple.REPOSITORY_URI).toString(), };
|
||||
CommandLineApplication.mainProgram(args);
|
||||
checkForHelp(this.commandLine.getOutputLines());
|
||||
}
|
||||
|
|
@ -164,7 +167,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(), "-o", this.output.toString(), Paths.get(Simple.SIMPLE_VALID).toString() };
|
||||
Paths.get(Simple.REPOSITORY_URI).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("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
|
||||
|
|
@ -174,7 +177,7 @@ public class CommandlineApplicationTest {
|
|||
public void testHtmlExtraktion() throws IOException {
|
||||
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() };
|
||||
"-r", Paths.get(Simple.REPOSITORY_URI).toString(), Paths.get(Simple.SIMPLE_VALID).toString() };
|
||||
CommandLineApplication.mainProgram(args);
|
||||
assertThat(this.commandLine.getErrorOutput()).contains(RESULT_OUTPUT);
|
||||
assertThat(Files.list(this.output).filter(f -> f.toString().endsWith(".html")).count()).isGreaterThan(0);
|
||||
|
|
@ -183,8 +186,8 @@ public class CommandlineApplicationTest {
|
|||
@Test
|
||||
public void testAssertionsExtraktion() {
|
||||
final String[] args = new String[] { "-d", "-s", Paths.get(Simple.SCENARIOS).toString(), "-r",
|
||||
Paths.get(Simple.REPOSITORY).toString(), "-o", this.output.toString(), "-c", Paths.get(ASSERTIONS).toString(),
|
||||
Paths.get(Simple.REPOSITORY).toString(),
|
||||
Paths.get(Simple.REPOSITORY_URI).toString(), "-o", this.output.toString(), "-c", Paths.get(ASSERTIONS).toString(),
|
||||
Paths.get(Simple.REPOSITORY_URI).toString(),
|
||||
Paths.get(Simple.SIMPLE_VALID).toString() };
|
||||
CommandLineApplication.mainProgram(args);
|
||||
assertThat(this.commandLine.getErrorOutput()).contains(RESULT_OUTPUT);
|
||||
|
|
|
|||
|
|
@ -34,6 +34,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.TestObjectFactory;
|
||||
import de.kosit.validationtool.impl.tasks.CheckAction;
|
||||
|
||||
/**
|
||||
|
|
@ -51,7 +52,7 @@ public class ExtractHtmlActionTest {
|
|||
@Before
|
||||
public void setup() throws IOException {
|
||||
this.tmpDirectory = Files.createTempDirectory("checktool");
|
||||
this.action = new ExtractHtmlContentAction(Helper.loadTestRepository(), this.tmpDirectory);
|
||||
this.action = new ExtractHtmlContentAction(TestObjectFactory.createProcessor(), this.tmpDirectory);
|
||||
}
|
||||
|
||||
@After
|
||||
|
|
|
|||
|
|
@ -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.TestObjectFactory;
|
||||
import de.kosit.validationtool.impl.tasks.CheckAction;
|
||||
|
||||
/**
|
||||
|
|
@ -46,7 +47,7 @@ public class PrintReportActionTest {
|
|||
public void setup() {
|
||||
this.commandLine = new CommandLine();
|
||||
this.commandLine.activate();
|
||||
this.action = new PrintReportAction();
|
||||
this.action = new PrintReportAction(TestObjectFactory.createProcessor());
|
||||
}
|
||||
|
||||
@After
|
||||
|
|
|
|||
|
|
@ -34,6 +34,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.TestObjectFactory;
|
||||
import de.kosit.validationtool.impl.tasks.CheckAction;
|
||||
|
||||
/**
|
||||
|
|
@ -49,7 +50,7 @@ public class SerializeReportActionTest {
|
|||
@Before
|
||||
public void setup() throws IOException {
|
||||
this.tmpDirectory = Files.createTempDirectory("checktool");
|
||||
this.action = new SerializeReportAction(this.tmpDirectory);
|
||||
this.action = new SerializeReportAction(this.tmpDirectory, TestObjectFactory.createProcessor());
|
||||
}
|
||||
|
||||
@After
|
||||
|
|
|
|||
|
|
@ -0,0 +1,49 @@
|
|||
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 org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import de.kosit.validationtool.api.Configuration;
|
||||
import de.kosit.validationtool.api.InputFactory;
|
||||
import de.kosit.validationtool.api.Result;
|
||||
import de.kosit.validationtool.impl.DefaultCheck;
|
||||
import de.kosit.validationtool.impl.Helper.Simple;
|
||||
import de.kosit.validationtool.impl.ResolvingMode;
|
||||
|
||||
/**
|
||||
* @author Andreas Penski
|
||||
*/
|
||||
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();
|
||||
//@formatter:on
|
||||
final DefaultCheck check = new DefaultCheck(config);
|
||||
final Result result = check.checkInput(InputFactory.read(Simple.SIMPLE_VALID));
|
||||
assertThat(result).isNotNull();
|
||||
}
|
||||
}
|
||||
|
|
@ -55,7 +55,7 @@ public class ContentRepositoryTest {
|
|||
|
||||
@Before
|
||||
public void setup() {
|
||||
this.repository = new ContentRepository(ObjectFactory.createProcessor(), Simple.REPOSITORY);
|
||||
this.repository = Simple.createContentRepository();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -114,7 +114,7 @@ public class ContentRepositoryTest {
|
|||
|
||||
@Test
|
||||
public void loadFromJar() throws URISyntaxException {
|
||||
this.repository = new ContentRepository(ObjectFactory.createProcessor(), Helper.JAR_REPOSITORY.toURI());
|
||||
this.repository = new ContentRepository(TestObjectFactory.createProcessor(), Helper.JAR_REPOSITORY.toURI(), null);
|
||||
final XsltExecutable xsltExecutable = this.repository.loadXsltScript(URI.create("resources/eRechnung/report.xsl"));
|
||||
assertThat(xsltExecutable).isNotNull();
|
||||
}
|
||||
|
|
@ -136,7 +136,7 @@ public class ContentRepositoryTest {
|
|||
|
||||
// @Test
|
||||
// public void loadFromJar() throws URISyntaxException {
|
||||
// this.content = new ContentRepository(ObjectFactory.createProcessor(), Helper.JAR_REPOSITORY.toURI());
|
||||
// this.content = new ContentRepository(TestObjectFactory.createProcessor(), Helper.JAR_REPOSITORY.toURI());
|
||||
// this.repository = new ScenarioRepository(this.content);
|
||||
// final CheckConfiguration conf = new CheckConfiguration(
|
||||
// ScenarioRepository.class.getClassLoader().getResource("xrechnung/scenarios.xml").toURI());
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ package de.kosit.validationtool.impl;
|
|||
|
||||
import static org.assertj.core.api.Java6Assertions.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.Serializable;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
|
|
@ -54,8 +53,7 @@ public class ConversionServiceTest {
|
|||
@Before
|
||||
public void setup() {
|
||||
this.service = new ConversionService();
|
||||
this.repository = new ContentRepository(ObjectFactory.createProcessor(),
|
||||
new File("src/test/resources/examples/repository").toURI());
|
||||
this.repository = Simple.createContentRepository();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ public class DefaultCheckTest {
|
|||
@Before
|
||||
public void setup() {
|
||||
final CheckConfiguration d = new CheckConfiguration(Simple.SCENARIOS);
|
||||
d.setScenarioRepository(new File(Simple.REPOSITORY).toURI());
|
||||
d.setScenarioRepository(new File(Simple.REPOSITORY_URI).toURI());
|
||||
this.implementation = new DefaultCheck(d);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ import org.junit.rules.ExpectedException;
|
|||
|
||||
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;
|
||||
|
|
@ -45,7 +44,7 @@ public class DocumentParserTest {
|
|||
|
||||
@Test
|
||||
public void testSimple() {
|
||||
final Result<XdmNode, XMLSyntaxError> result = DocumentParseAction.parseDocument(read(Simple.SIMPLE_VALID));
|
||||
final Result<XdmNode, XMLSyntaxError> result = Helper.parseDocument(read(Simple.SIMPLE_VALID));
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getObject()).isNotNull();
|
||||
assertThat(result.getErrors()).isEmpty();
|
||||
|
|
@ -54,7 +53,7 @@ public class DocumentParserTest {
|
|||
|
||||
@Test
|
||||
public void testIllformed() {
|
||||
final Result<XdmNode, XMLSyntaxError> result = DocumentParseAction.parseDocument(read(Simple.NOT_WELLFORMED));
|
||||
final Result<XdmNode, XMLSyntaxError> result = Helper.parseDocument(read(Simple.NOT_WELLFORMED));
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getErrors()).isNotEmpty();
|
||||
assertThat(result.getObject()).isNull();
|
||||
|
|
@ -64,7 +63,7 @@ public class DocumentParserTest {
|
|||
@Test
|
||||
public void testNullInput() {
|
||||
this.exception.expect(IllegalArgumentException.class);
|
||||
DocumentParseAction.parseDocument(null);
|
||||
Helper.parseDocument(null);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -36,6 +36,12 @@ import javax.xml.transform.stream.StreamSource;
|
|||
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import de.kosit.validationtool.api.Input;
|
||||
import de.kosit.validationtool.api.ResolvingConfigurationStrategy;
|
||||
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.dom.NodeOverNodeInfo;
|
||||
import net.sf.saxon.s9api.SaxonApiException;
|
||||
import net.sf.saxon.s9api.XdmNode;
|
||||
|
|
@ -61,7 +67,7 @@ public class Helper {
|
|||
|
||||
public static final URI SCENARIOS = ROOT.resolve("scenarios.xml");
|
||||
|
||||
public static final URI REPOSITORY = ROOT.resolve("repository/");
|
||||
public static final URI REPOSITORY_URI = ROOT.resolve("repository/");
|
||||
|
||||
public static final URI INVALID = ROOT.resolve("input/simple-invalid.xml");
|
||||
|
||||
|
|
@ -73,8 +79,16 @@ public class Helper {
|
|||
|
||||
public static final URI NOT_EXISTING = EXAMPLES_DIR.resolve("doesnotexist");
|
||||
|
||||
public static final URI REPORT_XSL = REPOSITORY.resolve("report.xsl");
|
||||
public static final URI REPORT_XSL = REPOSITORY_URI.resolve("report.xsl");
|
||||
|
||||
public static final ContentRepository createContentRepository() {
|
||||
final ResolvingConfigurationStrategy strategy = ResolvingMode.STRICT_RELATIVE.getStrategy();
|
||||
final ContentRepository rep = new ContentRepository(TestObjectFactory.createProcessor(), Simple.REPOSITORY_URI,
|
||||
strategy.createResolver(Simple.REPOSITORY_URI));
|
||||
rep.setResolvingConfigurationStrategy(strategy);
|
||||
rep.setSchemaFactory(strategy.createSchemaFactory());
|
||||
return rep;
|
||||
}
|
||||
public static URI getSchemaLocation() {
|
||||
return ROOT.resolve("repository/simple.xsd");
|
||||
}
|
||||
|
|
@ -118,7 +132,7 @@ public class Helper {
|
|||
*/
|
||||
public static XdmNode load(final URL url) {
|
||||
try ( final InputStream input = url.openStream() ) {
|
||||
return ObjectFactory.createProcessor().newDocumentBuilder().build(new StreamSource(input));
|
||||
return TestObjectFactory.createProcessor().newDocumentBuilder().build(new StreamSource(input));
|
||||
} catch (final SaxonApiException | IOException e) {
|
||||
throw new IllegalStateException("Fehler beim Laden der XML-Datei", e);
|
||||
|
||||
|
|
@ -140,12 +154,12 @@ public class Helper {
|
|||
* @return ein {@link ContentRepository}
|
||||
*/
|
||||
public static ContentRepository loadTestRepository() {
|
||||
return new ContentRepository(ObjectFactory.createProcessor(), new File("src/test/resources/examples/repository").toURI());
|
||||
return new ContentRepository(TestObjectFactory.createProcessor(), new File("src/test/resources/examples/repository").toURI(), null);
|
||||
}
|
||||
|
||||
public static String serialize(final Document doc) {
|
||||
try ( final StringWriter writer = new StringWriter() ) {
|
||||
final Transformer transformer = ObjectFactory.createTransformer(true);
|
||||
final Transformer transformer = TestObjectFactory.createTransformer(true);
|
||||
transformer.transform(new DOMSource(doc), new StreamResult(writer));
|
||||
return writer.toString();
|
||||
} catch (final IOException | TransformerException e) {
|
||||
|
|
@ -157,4 +171,7 @@ public class Helper {
|
|||
return serialize((Document) NodeOverNodeInfo.wrap(node.getUnderlyingNode()));
|
||||
}
|
||||
|
||||
public static Result<XdmNode, XMLSyntaxError> parseDocument(final Input input) {
|
||||
return new DocumentParseAction(TestObjectFactory.createProcessor()).parseDocument(input);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,6 +33,8 @@ import org.junit.Rule;
|
|||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import de.kosit.validationtool.impl.xml.RelativeUriResolver;
|
||||
|
||||
/**
|
||||
* Testet den Uri-Resolver der relative auflösen soll
|
||||
*
|
||||
|
|
@ -63,13 +65,13 @@ public class RelativeUriResolverTest {
|
|||
|
||||
@Test
|
||||
public void testNotExisting() throws TransformerException {
|
||||
this.exception.expect(IllegalStateException.class);
|
||||
this.exception.expect(TransformerException.class);
|
||||
this.resolver.resolve("ubl-0001", BASE.toASCIIString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOutOfPath() throws TransformerException {
|
||||
this.exception.expect(IllegalStateException.class);
|
||||
this.exception.expect(TransformerException.class);
|
||||
this.resolver.resolve("../results/report.xml", BASE.toASCIIString());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -35,21 +35,19 @@ import org.w3c.dom.Document;
|
|||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import de.kosit.validationtool.api.InputFactory;
|
||||
import de.kosit.validationtool.impl.Helper.Simple;
|
||||
import de.kosit.validationtool.impl.model.Result;
|
||||
import de.kosit.validationtool.impl.xml.RelativeUriResolver;
|
||||
import de.kosit.validationtool.model.reportInput.XMLSyntaxError;
|
||||
|
||||
import net.sf.saxon.s9api.DOMDestination;
|
||||
import net.sf.saxon.s9api.Processor;
|
||||
import net.sf.saxon.s9api.SaxonApiException;
|
||||
import net.sf.saxon.s9api.XdmNode;
|
||||
import net.sf.saxon.s9api.XsltCompiler;
|
||||
import net.sf.saxon.s9api.XsltExecutable;
|
||||
import net.sf.saxon.s9api.XsltTransformer;
|
||||
import de.kosit.validationtool.api.InputFactory;
|
||||
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;
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -62,19 +60,19 @@ public class SaxonSecurityTest {
|
|||
|
||||
@Test
|
||||
public void testEvilStylesheets() throws IOException {
|
||||
final Processor p = ObjectFactory.createProcessor();
|
||||
final Processor p = TestObjectFactory.createProcessor();
|
||||
for (int i = 1; i <= 5; i++) {
|
||||
try {
|
||||
final URL resource = SaxonSecurityTest.class.getResource(String.format("/evil/evil%s.xsl", i));
|
||||
final XsltCompiler compiler = p.newXsltCompiler();
|
||||
final RelativeUriResolver resolver = new RelativeUriResolver(Simple.REPOSITORY);
|
||||
final RelativeUriResolver resolver = new RelativeUriResolver(Simple.REPOSITORY_URI);
|
||||
compiler.setURIResolver(resolver);
|
||||
final XsltExecutable exetuable = compiler.compile(new StreamSource(resource.openStream()));
|
||||
final XsltTransformer transformer = exetuable.load();
|
||||
final Document document = ObjectFactory.createDocumentBuilder(false).newDocument();
|
||||
final Document document = TestObjectFactory.createDocumentBuilder(false).newDocument();
|
||||
document.createElement("root");
|
||||
final Document result = ObjectFactory.createDocumentBuilder(false).newDocument();
|
||||
transformer.getUnderlyingController().setUnparsedTextURIResolver(resolver);
|
||||
final Document result = TestObjectFactory.createDocumentBuilder(false).newDocument();
|
||||
// transformer.getUnderlyingController().setUnparsedTextURIResolver(resolver);
|
||||
transformer.setURIResolver(resolver);
|
||||
transformer.setSource(new DOMSource(document));
|
||||
transformer.setDestination(new DOMDestination(result));
|
||||
|
|
@ -94,7 +92,7 @@ public class SaxonSecurityTest {
|
|||
@Test
|
||||
public void testXxe() {
|
||||
final URL resource = SaxonSecurityTest.class.getResource("/evil/xxe.xml");
|
||||
final Result<XdmNode, XMLSyntaxError> result = DocumentParseAction.parseDocument(InputFactory.read(resource));
|
||||
final Result<XdmNode, XMLSyntaxError> result = Helper.parseDocument(InputFactory.read(resource));
|
||||
assertThat(result.isValid()).isFalse();
|
||||
assertThat(result.getObject()).isNull();
|
||||
assertThat(result.getErrors().stream().map(XMLSyntaxError::getMessage).collect(Collectors.joining()))
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import java.net.URI;
|
|||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
|
|
@ -38,7 +39,6 @@ import lombok.Data;
|
|||
import de.kosit.validationtool.api.Configuration;
|
||||
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.scenarios.ScenarioType;
|
||||
|
||||
import net.sf.saxon.s9api.Processor;
|
||||
|
|
@ -70,10 +70,8 @@ public class ScenarioRepositoryTest {
|
|||
|
||||
private ContentRepository contentRepository;
|
||||
|
||||
@Override
|
||||
public void build() {
|
||||
// nothing
|
||||
}
|
||||
private Map<String, Object> additionalParameters;
|
||||
|
||||
}
|
||||
|
||||
@Rule
|
||||
|
|
@ -137,11 +135,10 @@ public class ScenarioRepositoryTest {
|
|||
}
|
||||
|
||||
private static XdmNode load(final URI uri) throws IOException {
|
||||
final DocumentParseAction p = new DocumentParseAction();
|
||||
return DocumentParseAction.parseDocument(read(uri.toURL())).getObject();
|
||||
return Helper.parseDocument(read(uri.toURL())).getObject();
|
||||
}
|
||||
|
||||
private static XPathExecutable createXpath(final String expression) {
|
||||
return new ContentRepository(ObjectFactory.createProcessor(), null).createXPath(expression, new HashMap<>());
|
||||
return new ContentRepository(TestObjectFactory.createProcessor(), null, null).createXPath(expression, new HashMap<>());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ public class SimpleScenarioCheckTest {
|
|||
@Before
|
||||
public void setup() {
|
||||
final CheckConfiguration d = new CheckConfiguration(Simple.SCENARIOS);
|
||||
d.setScenarioRepository(Simple.REPOSITORY);
|
||||
d.setScenarioRepository(Simple.REPOSITORY_URI);
|
||||
this.implementation = new DefaultCheck(d);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
package de.kosit.validationtool.impl;
|
||||
|
||||
/**
|
||||
* @author Andreas Penski
|
||||
*/
|
||||
public class TestObjectFactory extends ObjectFactory {
|
||||
}
|
||||
|
|
@ -56,7 +56,7 @@ public class VersioningTest {
|
|||
|
||||
@Before
|
||||
public void setup() {
|
||||
this.repository = new ContentRepository(ObjectFactory.createProcessor(), Simple.REPOSITORY);
|
||||
this.repository = Simple.createContentRepository();
|
||||
this.service = new ConversionService();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import org.junit.Test;
|
|||
|
||||
import de.kosit.validationtool.api.AcceptRecommendation;
|
||||
import de.kosit.validationtool.impl.ContentRepository;
|
||||
import de.kosit.validationtool.impl.ObjectFactory;
|
||||
import de.kosit.validationtool.impl.TestObjectFactory;
|
||||
import de.kosit.validationtool.impl.tasks.CheckAction.Bag;
|
||||
|
||||
import net.sf.saxon.s9api.XPathExecutable;
|
||||
|
|
@ -22,6 +22,7 @@ import net.sf.saxon.s9api.XPathExecutable;
|
|||
*/
|
||||
public class ComputeAcceptanceActionTest {
|
||||
|
||||
private static final String DOESNOT_EXIST = "count(//doesnotExist) = 0";
|
||||
private final ComputeAcceptanceAction action = new ComputeAcceptanceAction();
|
||||
|
||||
@Test
|
||||
|
|
@ -49,7 +50,7 @@ public class ComputeAcceptanceActionTest {
|
|||
@Test
|
||||
public void testValidAcceptMatch() {
|
||||
final Bag bag = createBag(true, true);
|
||||
bag.getScenarioSelectionResult().getObject().setAcceptExecutable(createXpath("count(//doesnotExist) = 0"));
|
||||
bag.getScenarioSelectionResult().getObject().setAcceptExecutable(createXpath(DOESNOT_EXIST));
|
||||
this.action.check(bag);
|
||||
assertThat(bag.getAcceptStatus()).isEqualTo(AcceptRecommendation.ACCEPTABLE);
|
||||
}
|
||||
|
|
@ -65,7 +66,7 @@ public class ComputeAcceptanceActionTest {
|
|||
@Test
|
||||
public void testAcceptMatchOverridesSchematronErrors() {
|
||||
final Bag bag = createBag(true, false);
|
||||
bag.getScenarioSelectionResult().getObject().setAcceptExecutable(createXpath("count(//doesnotExist) = 0"));
|
||||
bag.getScenarioSelectionResult().getObject().setAcceptExecutable(createXpath(DOESNOT_EXIST));
|
||||
this.action.check(bag);
|
||||
assertThat(bag.getAcceptStatus()).isEqualTo(AcceptRecommendation.ACCEPTABLE);
|
||||
}
|
||||
|
|
@ -73,7 +74,7 @@ public class ComputeAcceptanceActionTest {
|
|||
@Test
|
||||
public void testValidAcceptMatchOnSchemaFailed() {
|
||||
final Bag bag = createBag(false, true);
|
||||
bag.getScenarioSelectionResult().getObject().setAcceptExecutable(createXpath("count(//doesnotExist) = 0"));
|
||||
bag.getScenarioSelectionResult().getObject().setAcceptExecutable(createXpath(DOESNOT_EXIST));
|
||||
this.action.check(bag);
|
||||
assertThat(bag.getAcceptStatus()).isEqualTo(AcceptRecommendation.REJECT);
|
||||
}
|
||||
|
|
@ -104,6 +105,6 @@ public class ComputeAcceptanceActionTest {
|
|||
|
||||
|
||||
private static XPathExecutable createXpath(final String expression) {
|
||||
return new ContentRepository(ObjectFactory.createProcessor(), null).createXPath(expression, new HashMap<>());
|
||||
return new ContentRepository(TestObjectFactory.createProcessor(), null, null).createXPath(expression, new HashMap<>());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,12 +43,13 @@ 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.Scenario;
|
||||
import de.kosit.validationtool.impl.TestObjectFactory;
|
||||
import de.kosit.validationtool.impl.input.SourceInput;
|
||||
import de.kosit.validationtool.impl.tasks.CheckAction.Bag;
|
||||
import de.kosit.validationtool.impl.xml.StrictRelativeResolvingStrategy;
|
||||
|
||||
/**
|
||||
* Tests die {@link SchemaValidationAction}.
|
||||
|
|
@ -63,7 +64,7 @@ public class SchemaValidatorActionTest {
|
|||
|
||||
@Before
|
||||
public void setup() {
|
||||
this.service = new SchemaValidationAction();
|
||||
this.service = new SchemaValidationAction(new StrictRelativeResolvingStrategy(), TestObjectFactory.createProcessor());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -89,7 +90,7 @@ public class SchemaValidatorActionTest {
|
|||
|
||||
@Test
|
||||
public void testSchemaReferences() {
|
||||
final Schema reportInputSchema = new ContentRepository(ObjectFactory.createProcessor(), Simple.REPOSITORY).getReportInputSchema();
|
||||
final Schema reportInputSchema = Simple.createContentRepository().getReportInputSchema();
|
||||
assertThat(reportInputSchema).isNotNull();
|
||||
}
|
||||
|
||||
|
|
@ -98,7 +99,7 @@ public class SchemaValidatorActionTest {
|
|||
try ( final InputStream inputStream = Simple.SIMPLE_VALID.toURL().openStream() ) {
|
||||
final Bag bag = createBag(InputFactory.read(new StreamSource(inputStream)));
|
||||
// don't read the real inputstream here!
|
||||
bag.setParserResult(DocumentParseAction.parseDocument(InputFactory.read(Simple.SIMPLE_VALID.toURL())));
|
||||
bag.setParserResult(Helper.parseDocument(InputFactory.read(Simple.SIMPLE_VALID.toURL())));
|
||||
this.service.check(bag);
|
||||
assertThat(bag.getSchemaValidationResult()).isNotNull();
|
||||
assertThat(bag.getSchemaValidationResult().isValid()).isTrue();
|
||||
|
|
@ -114,7 +115,7 @@ public class SchemaValidatorActionTest {
|
|||
this.service.setInMemoryLimit(5L);
|
||||
input.setLength(6L);
|
||||
|
||||
bag.setParserResult(DocumentParseAction.parseDocument(InputFactory.read(Simple.SIMPLE_VALID.toURL())));
|
||||
bag.setParserResult(Helper.parseDocument(InputFactory.read(Simple.SIMPLE_VALID.toURL())));
|
||||
this.service.check(bag);
|
||||
assertThat(bag.getSchemaValidationResult()).isNotNull();
|
||||
assertThat(bag.getSchemaValidationResult().isValid()).isTrue();
|
||||
|
|
@ -127,7 +128,7 @@ public class SchemaValidatorActionTest {
|
|||
final Reader reader = new InputStreamReader(inputStream) ) {
|
||||
final SourceInput input = (SourceInput) InputFactory.read(new StreamSource(reader));
|
||||
final Bag bag = createBag(input);
|
||||
bag.setParserResult(DocumentParseAction.parseDocument(InputFactory.read(Simple.SIMPLE_VALID.toURL())));
|
||||
bag.setParserResult(Helper.parseDocument(InputFactory.read(Simple.SIMPLE_VALID.toURL())));
|
||||
this.service.check(bag);
|
||||
this.service.check(bag);
|
||||
assertThat(bag.getSchemaValidationResult()).isNotNull();
|
||||
|
|
@ -143,7 +144,7 @@ public class SchemaValidatorActionTest {
|
|||
final Bag bag = createBag(input);
|
||||
// set limit and length for serialization to 5 bytes
|
||||
this.service.setInMemoryLimit(5L);
|
||||
bag.setParserResult(DocumentParseAction.parseDocument(InputFactory.read(Simple.SIMPLE_VALID.toURL())));
|
||||
bag.setParserResult(Helper.parseDocument(InputFactory.read(Simple.SIMPLE_VALID.toURL())));
|
||||
this.service.check(bag);
|
||||
this.service.check(bag);
|
||||
assertThat(bag.getSchemaValidationResult()).isNotNull();
|
||||
|
|
|
|||
|
|
@ -13,12 +13,11 @@ 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.Scenario;
|
||||
import de.kosit.validationtool.impl.Scenario.Transformation;
|
||||
import de.kosit.validationtool.impl.xml.RelativeUriResolver;
|
||||
import de.kosit.validationtool.model.scenarios.ResourceType;
|
||||
|
||||
import net.sf.saxon.s9api.SaxonApiException;
|
||||
|
|
@ -36,8 +35,7 @@ public class SchematronValidationActionTest {
|
|||
|
||||
@Before
|
||||
public void setup() {
|
||||
final ContentRepository repository = new ContentRepository(ObjectFactory.createProcessor(), Simple.REPOSITORY);
|
||||
this.action = new SchematronValidationAction(repository, new ConversionService());
|
||||
this.action = new SchematronValidationAction(new RelativeUriResolver(Simple.REPOSITORY_URI), new ConversionService());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -16,8 +16,9 @@ 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.ObjectFactory;
|
||||
import de.kosit.validationtool.impl.ResolvingMode;
|
||||
import de.kosit.validationtool.impl.Scenario;
|
||||
import de.kosit.validationtool.impl.TestObjectFactory;
|
||||
import de.kosit.validationtool.impl.model.Result;
|
||||
import de.kosit.validationtool.impl.tasks.CheckAction.Bag;
|
||||
import de.kosit.validationtool.model.reportInput.CreateReportInput;
|
||||
|
|
@ -48,7 +49,7 @@ public class TestBagBuilder {
|
|||
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()));
|
||||
bag.setParserResult(Helper.parseDocument(bag.getInput()));
|
||||
}
|
||||
bag.setScenarioSelectionResult(new Result<>(createScenario(Helper.Simple.getSchemaLocation())));
|
||||
return bag;
|
||||
|
|
@ -73,11 +74,13 @@ public class TestBagBuilder {
|
|||
}
|
||||
|
||||
private static Schema createSchema(final URL toURL) {
|
||||
return new ContentRepository(ObjectFactory.createProcessor(), null).createSchema(toURL);
|
||||
final ContentRepository contentRepository = new ContentRepository(TestObjectFactory.createProcessor(), null, null);
|
||||
contentRepository.setSchemaFactory(ResolvingMode.STRICT_RELATIVE.getStrategy().createSchemaFactory());
|
||||
return contentRepository.createSchema(toURL);
|
||||
}
|
||||
|
||||
private static XdmNode createReport() {
|
||||
return DocumentParseAction.parseDocument(InputFactory.read("<some>xml</some>".getBytes(), "someXml")).getObject();
|
||||
return Helper.parseDocument(InputFactory.read("<some>xml</some>".getBytes(), "someXml")).getObject();
|
||||
}
|
||||
|
||||
static Bag createBag(final boolean schemaValid, final boolean schematronValid) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue