#21 Umsetzung der API Rückgabe, erste version

This commit is contained in:
Andreas Penski (init) 2019-05-17 11:21:22 +02:00 committed by Andreas Penski
parent a424fbbcfe
commit ab31ed71b1
21 changed files with 532 additions and 147 deletions

View file

@ -33,17 +33,17 @@ import org.junit.Before;
import org.junit.Test;
import org.w3c.dom.Document;
import de.kosit.validationtool.api.AcceptRecommendation;
import de.kosit.validationtool.api.CheckConfiguration;
import de.kosit.validationtool.api.Input;
import net.sf.saxon.s9api.XdmNode;
import de.kosit.validationtool.api.Result;
/**
* Test das Check-Interface
*
* @author Andreas Penski
*/
public class DefaultCheckTest {
public class DefaultCheckTest extends CheckTest {
private static final URL SCENARIO_DEFINITION = ScenarioRepositoryTest.class.getResource("/examples/UBLReady/scenarios-2.xml");
@ -62,27 +62,30 @@ public class DefaultCheckTest {
}
@Test
public void testHappyCase() throws Exception {
final XdmNode doc = this.implementation.checkInput(read(VALID_EXAMPLE));
public void testHappyCase() {
final Result doc = this.implementation.checkInput(read(VALID_EXAMPLE));
assertThat(doc).isNotNull();
assertThat(doc.getReport()).isNotNull();
assertThat(doc.isAcceptable()).isFalse();
assertThat(doc.getAcceptRecommendation()).isEqualTo(AcceptRecommendation.UNDEFINED);
}
@Test
public void testHappyCaseDocument() throws Exception {
public void testHappyCaseDocument() {
final Document doc = this.implementation.check(read(VALID_EXAMPLE));
assertThat(doc).isNotNull();
}
@Test
public void testMultipleCase() throws Exception {
public void testMultipleCase() {
final List<Input> input = IntStream.range(0, MULTI_COUNT).mapToObj(i -> read(VALID_EXAMPLE)).collect(Collectors.toList());
final List<XdmNode> docs = this.implementation.checkInput(input);
final List<Result> docs = this.implementation.checkInput(input);
assertThat(docs).isNotNull();
assertThat(docs).hasSize(MULTI_COUNT);
}
@Test
public void testMultipleCaseDocument() throws Exception {
public void testMultipleCaseDocument() {
final List<Input> input = IntStream.range(0, MULTI_COUNT).mapToObj(i -> read(VALID_EXAMPLE)).collect(Collectors.toList());
final List<Document> docs = this.implementation.check(input);
assertThat(docs).isNotNull();

View file

@ -39,6 +39,23 @@ import net.sf.saxon.s9api.XdmNode;
*/
public class Helper {
public static class Simple {
public static final URI ROOT = EXAMPLES_DIR.resolve("simple/");
public static final URI SIMPLE_VALID = Simple.ROOT.resolve("input/simple.xml");
public static final URI FOO = Simple.ROOT.resolve("input/foo.xml");
public static final URI SCENARIOS = ROOT.resolve("scenarios.xml");
public static final URI REPOSITORY = ROOT.resolve("repository/");
public static final URI INVALID = ROOT.resolve("input/simple-invalid.xml");
public static final URI UNKNOWN = ROOT.resolve("input/unknown.xml");
}
public static final URI SOURCE_ROOT = Paths.get("src/main/resources").toUri();
public static final URI MODEL_ROOT = Paths.get("src/main/model").toUri();

View file

@ -0,0 +1,60 @@
package de.kosit.validationtool.impl;
import static org.assertj.core.api.Assertions.assertThat;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import org.junit.Before;
import org.junit.Test;
import de.kosit.validationtool.api.AcceptRecommendation;
import de.kosit.validationtool.api.CheckConfiguration;
import de.kosit.validationtool.api.InputFactory;
import de.kosit.validationtool.api.Result;
import de.kosit.validationtool.impl.Helper.Simple;
/**
* Prüft die Funktionen des Validator auf Basis eines reduzierten Szenarios.
*
* @author Andreas Penski
*/
public class SimpleScenarioCheck {
private DefaultCheck implementation;
@Before
public void setup() throws URISyntaxException {
final CheckConfiguration d = new CheckConfiguration(Simple.SCENARIOS);
d.setScenarioRepository(Simple.REPOSITORY);
this.implementation = new DefaultCheck(d);
}
@Test
public void testSimple() throws MalformedURLException {
final Result result = this.implementation.checkInput(InputFactory.read(Simple.SIMPLE_VALID.toURL()));
assertThat(result).isNotNull();
assertThat(result.getAcceptRecommendation()).isEqualTo(AcceptRecommendation.ACCEPTABLE);
}
@Test
public void testInvalid() throws MalformedURLException {
final Result result = this.implementation.checkInput(InputFactory.read(Simple.INVALID.toURL()));
assertThat(result).isNotNull();
assertThat(result.getAcceptRecommendation()).isEqualTo(AcceptRecommendation.REJECT);
}
@Test
public void testUnknown() throws MalformedURLException {
final Result result = this.implementation.checkInput(InputFactory.read(Simple.UNKNOWN.toURL()));
assertThat(result).isNotNull();
assertThat(result.getAcceptRecommendation()).isEqualTo(AcceptRecommendation.UNDEFINED);
}
@Test
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);
}
}

View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<foo xmlns="http://validator.kosit.de/test-sample">
<inner>asldkfj</inner>
</foo>

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<simple xmlns="http://validator.kosit.de/test-sample">
<inner>asldkfj</inner>
<notAllowed />
</simple>

View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<simple xmlns="http://validator.kosit.de/test-sample">
<inner>asldkfj</inner>
</simple>

View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<existiertNicht xmlns="http://validator.kosit.de/unbekannt">
<inner>asldkfj</inner>
</existiertNicht>

View file

@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Koordinierungsstelle für IT-Standards (KoSIT) under
~ one or more contributor license agreements. See the NOTICE file
~ distributed with this work for additional information
~ regarding copyright ownership. KoSIT licenses this file
~ to you under the Apache License, Version 2.0 (the
~ "License"); you may not use this file except in compliance
~ with the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:in="http://www.xoev.de/de/validator/framework/1/createreportinput"
exclude-result-prefixes="xs"
version="2.0">
<xsl:output method="xml" indent="yes" />
<xsl:param name="input-document" as="document-node(element())" required="yes" />
<xsl:template match="in:createReportInput">
<report xmlns="http://validator.kosit.de/test-report">
<input>
<xsl:copy-of select="$input-document" />
</input>
<result>
<xsl:copy-of select="." />
</result>
</report>
</xsl:template>
</xsl:stylesheet>

View file

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://validator.kosit.de/test-sample" version="1.0" xml:lang="en"
targetNamespace="http://validator.kosit.de/test-sample"
xmlns="http://www.w3.org/1999/xhtml" elementFormDefault="qualified">
<xs:element name="simple" type="tns:SimpleType" />
<xs:element name="foo" type="tns:SimpleType" />
<xs:complexType name="SimpleType">
<xs:sequence>
<xs:element name="inner" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:schema>

View file

@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Koordinierungsstelle für IT-Standards (KoSIT) under
~ one or more contributor license agreements. See the NOTICE file
~ distributed with this work for additional information
~ regarding copyright ownership. KoSIT licenses this file
~ to you under the Apache License, Version 2.0 (the
~ "License"); you may not use this file except in compliance
~ with the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->
<scenarios xmlns="http://www.xoev.de/de/validator/framework/1/scenarios" frameworkVersion="1.1.2">
<name>HTML-TestSuite</name>
<date>2017-08-08</date>
<description>
<p>Szenario für Tests</p>
</description>
<scenario>
<name>Simple</name>
<description>
<p>Nur Schemaprüfung.</p>
</description>
<namespace prefix="cri">http://www.xoev.de/de/validator/framework/1/createreportinput</namespace>
<namespace prefix="test">http://validator.kosit.de/test-sample</namespace>
<namespace prefix="rpt">http://validator.kosit.de/test-report</namespace>
<match>/test:simple</match>
<validateWithXmlSchema>
<resource>
<name>Sample Schema</name>
<location>simple.xsd</location>
</resource>
</validateWithXmlSchema>
<createReport>
<resource>
<name>Report für eRechnung</name>
<location>report.xsl</location>
</resource>
</createReport>
<acceptMatch>count(//cri:xmlSyntaxError) = 0</acceptMatch>
</scenario>
<scenario>
<name>NoAcceptMatch</name>
<description>
<p>Nur Schemaprüfung. Keine AcceptMatch deklaration</p>
<p>Testen, ob auch alte Konfiguration funktionioeren</p>
</description>
<namespace prefix="test">http://validator.kosit.de/test-sample</namespace>
<match>/test:foo</match>
<validateWithXmlSchema>
<resource>
<name>Sample Schema</name>
<location>simple.xsd</location>
</resource>
</validateWithXmlSchema>
<createReport>
<resource>
<name>Report für eRechnung</name>
<location>report.xsl</location>
</resource>
</createReport>
</scenario>
<noScenarioReport>
<resource>
<name>default</name>
<location>report.xsl</location>
</resource>
</noScenarioReport>
</scenarios>