From 8d8540ce309cfe700521ebb7ed88b75a5f6811ce Mon Sep 17 00:00:00 2001 From: Matthias Kilian Date: Mon, 9 Sep 2024 14:31:30 +0200 Subject: [PATCH] Enable EN16931 schema validation for XRechnung. Add a test case with an invalid XR (elements in wrong order). --- .../validator/XMLValidator.java | 2 +- .../validator/XMLValidatorTest.java | 19 ++ .../src/test/resources/invalidXRSchemav2.xml | 202 ++++++++++++++++++ 3 files changed, 222 insertions(+), 1 deletion(-) create mode 100644 validator/src/test/resources/invalidXRSchemav2.xml diff --git a/validator/src/main/java/org/mustangproject/validator/XMLValidator.java b/validator/src/main/java/org/mustangproject/validator/XMLValidator.java index f4caab88..d8855aea 100644 --- a/validator/src/main/java/org/mustangproject/validator/XMLValidator.java +++ b/validator/src/main/java/org/mustangproject/validator/XMLValidator.java @@ -254,7 +254,7 @@ public class XMLValidator extends Validator { the validation against the XRechnung Schematron will happen below but a XRechnung is a EN16931 subset so the validation vis a vis FACTUR-X_EN16931.xslt=schematron also has to pass * */ - //validateSchema(zfXML.getBytes(StandardCharsets.UTF_8), "ZF_211/EN16931/FACTUR-X_EN16931.xsd", 18, EPart.fx); + validateSchema(zfXML.getBytes(StandardCharsets.UTF_8), currentZFVersionDir + "/EN16931/FACTUR-X_EN16931.xsd", 18, EPart.fx); XrechnungSeverity = ESeverity.error; } else if (isExtended) { diff --git a/validator/src/test/java/org/mustangproject/validator/XMLValidatorTest.java b/validator/src/test/java/org/mustangproject/validator/XMLValidatorTest.java index 285fc77b..8b6022f5 100644 --- a/validator/src/test/java/org/mustangproject/validator/XMLValidatorTest.java +++ b/validator/src/test/java/org/mustangproject/validator/XMLValidatorTest.java @@ -226,6 +226,25 @@ public class XMLValidatorTest extends ResourceCase { content = xpath.evaluate("/validation/summary/@status", source); assertEquals("invalid", content); + } catch (final IrrecoverableValidationError e) { + // ignore, will be in XML output anyway + } + + } + + public void testXRSchemaValidation() { + final ValidationContext ctx = new ValidationContext(null); + final XMLValidator xv = new XMLValidator(ctx); + final XPathEngine xpath = new JAXPXPathEngine(); + + File tempFile = getResourceAsFile("invalidXRSchemav2.xml"); + try { + xv.setFilename(tempFile.getAbsolutePath()); + xv.validate(); + + Source source = Input.fromString("" + xv.getXMLResult() + "").build(); + String content = xpath.evaluate("/validation/summary/@status", source); + assertEquals("invalid", content); } catch (final IrrecoverableValidationError e) { // ignore, will be in XML output anyway diff --git a/validator/src/test/resources/invalidXRSchemav2.xml b/validator/src/test/resources/invalidXRSchemav2.xml new file mode 100644 index 00000000..4e623c3d --- /dev/null +++ b/validator/src/test/resources/invalidXRSchemav2.xml @@ -0,0 +1,202 @@ + + + + + urn:cen.eu:en16931:2017#compliant#urn:xoev-de:kosit:standard:xrechnung_2.0 + + + + 1234567 + 380 + + Invoice Note Description + AAC + + + 20180413 + + + + + + 1 + + + Beratung + + + + 143.75 + + + + 30 + + + + VAT + S + 19 + + + 4743.75 + + + + + + 2 + + + Beratung + + + + 143.75 + + + + 42 + + + + VAT + S + 19 + + + 6037.5 + + + + + 90000000-03083-12 + + [Seller name] + + GmbH + + + Tim Tester + + 012 3456789 + + + tim.tester@test.com + + + + 12345 + [Seller city] + DE + + + ATU123456789 + + + + 138 + [Buyer name] + + GmbH + + + Tina Tester + + 0800 123456 + + + tester@test.de + + + + 98765 + [Buyer city] + DE + + + DE12345ABC + + + + [Seller tax representative name] + + DE + + + DE124567 + + + + ABC123456789 + + + 65002278 + + + + + 68 + [Deliver to party name] + + 98765 + [Deliver to street] + 4. OG + [Deliver to city] + DE + Bayern + + + + + 20180413 + + + + + Deb. 12345 / Fact. 9876543 + EUR + + 74 + [Payee name] + + + 30 + + DE12100200000123456878 + + + + 2048.44 + VAT + 10781.25 + S + 19 + + + + 20180413 + + + 20180413 + + + + + 20180413 + + + + 10781.25 + 10781.25 + 2048.44 + 12829.69 + 12829.69 + + + +