deleted redundant files (had been moved from library/extended to validator). Corrected commandline import.
This commit is contained in:
@@ -1,88 +0,0 @@
|
||||
package org.mustangproject.library.extended;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
public class MiscValidatorTest extends ResourceCase {
|
||||
|
||||
|
||||
public void testInvalidFileValidation() {
|
||||
|
||||
ZUGFeRDValidator zfv=new ZUGFeRDValidator();
|
||||
|
||||
String res=zfv.validate(null);
|
||||
assertTrue(res.matches("<\\?xml version=\"1.0\" encoding=\"UTF-8\"\\?>\n" +
|
||||
"\n" +
|
||||
"<validation filename=\"\" datetime=\".*?\">\n" +
|
||||
" <messages>\n" +
|
||||
" <error type=\"10\">Filename not specified</error> \n" +
|
||||
" </messages>\n" +
|
||||
" <summary status=\"invalid\"/>\n" +
|
||||
"</validation>\n" +
|
||||
""));
|
||||
|
||||
res=zfv.validate("/dhfkbv/sfjkh");
|
||||
assertTrue(res.matches("<\\?xml version=\"1.0\" encoding=\"UTF-8\"\\?>\n" +
|
||||
"\n" +
|
||||
"<validation filename=\"sfjkh\" datetime=\".*?\">\n" +
|
||||
" <messages>\n" +
|
||||
" <error type=\"1\">File not found</error> \n" +
|
||||
" </messages>\n" +
|
||||
" <summary status=\"invalid\"/>\n" +
|
||||
"</validation>\n"));
|
||||
|
||||
boolean noExceptionOccurred=true;
|
||||
File tempFile=null;
|
||||
try {
|
||||
tempFile = File.createTempFile("hello", ".tmp");
|
||||
} catch (IOException e) {
|
||||
noExceptionOccurred=true;
|
||||
}
|
||||
assertTrue(noExceptionOccurred);
|
||||
|
||||
res=zfv.validate(tempFile.getAbsolutePath());
|
||||
assertTrue(res.matches("<\\?xml version=\"1.0\" encoding=\"UTF-8\"\\?>\n" +
|
||||
"\n" +
|
||||
"<validation filename=\".*\" datetime=\".*\">\n" +
|
||||
" <messages>\n" +
|
||||
" <error type=\"5\">File too small</error> \n" +
|
||||
" </messages>\n" +
|
||||
" <summary status=\"invalid\"/>\n" +
|
||||
"</validation>\n" +
|
||||
""));
|
||||
|
||||
|
||||
String fileContent = "ladhvkdbfk wkhfbkhdhkb svbkfsvbksfbvk sdvsdvbksjdvbkfdsv sdvbskdvbsjhkvbfskh dvbskfvbkfsbvke"
|
||||
+ "ladhvkdbfk wkhfbkhdhkb svbkfsvbksfbvk sdvsdvbksjdvbkfdsv sdvbskdvbsjhkvbfskh dvbskfvbkfsbvke";
|
||||
noExceptionOccurred=true;
|
||||
BufferedWriter writer;
|
||||
try {
|
||||
writer = new BufferedWriter(new FileWriter(tempFile));
|
||||
writer.write(fileContent);
|
||||
writer.close();
|
||||
} catch (IOException e) {
|
||||
noExceptionOccurred=false;
|
||||
}
|
||||
assertTrue(noExceptionOccurred);
|
||||
|
||||
|
||||
res=zfv.validate(tempFile.getAbsolutePath());
|
||||
assertTrue(res.matches("<\\?xml version=\"1.0\" encoding=\"UTF-8\"\\?>\n" +
|
||||
"\n" +
|
||||
"<validation filename=\".*\" datetime=\".*\">\n" +
|
||||
" <messages>\n" +
|
||||
" <exception type=\"8\">File does not look like PDF nor XML \\(contains neither %PDF nor <\\?xml\\)</exception> \n" +
|
||||
" </messages>\n" +
|
||||
" <summary status=\"invalid\"/>\n" +
|
||||
"</validation>\n" +
|
||||
""));
|
||||
|
||||
|
||||
// clean up
|
||||
tempFile.delete();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,139 +0,0 @@
|
||||
package org.mustangproject.library.extended;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class PDFValidatorTest extends ResourceCase {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ZUGFeRDValidator.class.getCanonicalName()); // log
|
||||
|
||||
public void testPDFValidation() {
|
||||
ValidationContext vc = new ValidationContext(null);
|
||||
PDFValidator pv = new PDFValidator(vc);
|
||||
|
||||
try {
|
||||
|
||||
File tempFile = getResourceAsFile("XMLinvalidV2PDF.pdf");// need a more invalid file here
|
||||
|
||||
pv.setFilename(tempFile.getAbsolutePath());
|
||||
pv.validate();
|
||||
// assertEquals("", pv.getXMLResult());
|
||||
|
||||
//
|
||||
tempFile = getResourceAsFile("Facture_F20180027.pdf");
|
||||
pv.setFilename(tempFile.getAbsolutePath());
|
||||
pv.validate();
|
||||
String actual = pv.getXMLResult();
|
||||
assertEquals(true, actual.contains("summary status='valid"));
|
||||
assertEquals(false, actual.contains("summary status='invalid"));
|
||||
|
||||
XMLValidator xv = new XMLValidator(vc);
|
||||
xv.setStringContent(pv.getRawXML());
|
||||
xv.validate();
|
||||
actual = vc.getXMLResult();
|
||||
|
||||
assertEquals(true, actual.contains("validationReport profileName=\"PDF/A-3"));
|
||||
assertEquals(true, actual.contains("batchSummary totalJobs=\"1\" failedToParse=\"0\" encrypted=\"0\""));
|
||||
assertEquals(true,
|
||||
actual.contains("validationReports compliant=\"1\" nonCompliant=\"0\" failedJobs=\"0\">"));
|
||||
// test some xml
|
||||
// assertEquals(true, actual.contains("<error
|
||||
// location=\"/*:CrossIndustryInvoice[namespace-uri()='urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100'][1]/*:SupplyChainTradeTransaction[namespace-uri()='urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100'][1]/*:ApplicableHeaderTradeSettlement[namespace-uri()='urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100'][1]/*:SpecifiedTradeSettlementHeaderMonetarySummation[namespace-uri()='urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100'][1]/*:DuePayableAmount[namespace-uri()='urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100'][1]\"
|
||||
// criterion=\"not(@currencyID)\">[CII-DT-031] - currencyID should not be
|
||||
// present</error>"));
|
||||
// test some binary signature recognition
|
||||
assertEquals(true, actual.contains("<version>2</version>"));
|
||||
|
||||
// valid one
|
||||
tempFile = getResourceAsFile("validV2PDF.pdf");
|
||||
|
||||
pv.setFilename(tempFile.getAbsolutePath());
|
||||
vc.clear();
|
||||
pv.validate();
|
||||
actual = pv.getXMLResult();
|
||||
assertEquals(true, actual.contains("validationReport profileName=\"PDF/A-3"));
|
||||
assertEquals(true, actual.contains("batchSummary totalJobs=\"1\" failedToParse=\"0\" encrypted=\"0\""));
|
||||
assertEquals(true,
|
||||
actual.contains("validationReports compliant=\"1\" nonCompliant=\"0\" failedJobs=\"0\">"));
|
||||
|
||||
assertEquals(false, actual.contains("<error"));
|
||||
} catch (IrrecoverableValidationError e) {
|
||||
// ignore, will be in XML output anyway
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void testPDFXMLValidation() {
|
||||
ValidationContext vc = new ValidationContext(null);
|
||||
try {
|
||||
PDFValidator pv = new PDFValidator(vc);
|
||||
|
||||
File tempFile = getResourceAsFile("attributeBasedXMP_zugferd_2p0_EN16931_Einfach.pdf");// need a more
|
||||
// invalid file here
|
||||
|
||||
pv.setFilename(tempFile.getAbsolutePath());
|
||||
pv.validate();
|
||||
String pdfvres = pv.getXMLResult();
|
||||
|
||||
XMLValidator xv = new XMLValidator(vc);
|
||||
|
||||
xv.setStringContent(pv.getRawXML());
|
||||
xv.validate();
|
||||
String xmlvres = xv.getXMLResult();
|
||||
|
||||
assertEquals(true, pdfvres.contains("valid") && !pdfvres.contains("invalid"));
|
||||
assertEquals(true, xmlvres.contains("invalid"));
|
||||
|
||||
vc.clear();
|
||||
tempFile = getResourceAsFile("validV1WithAdditionalData.pdf");// need a more invalid file here
|
||||
|
||||
pv.setFilename(tempFile.getAbsolutePath());
|
||||
pv.validate();
|
||||
pdfvres = pv.getXMLResult();
|
||||
|
||||
xv = new XMLValidator(vc);
|
||||
|
||||
xv.setStringContent(pv.getRawXML());
|
||||
xv.validate();
|
||||
xmlvres = xv.getXMLResult();
|
||||
assertEquals(true, pdfvres.contains("valid") && !pdfvres.contains("invalid"));
|
||||
assertEquals(true, xmlvres.contains("valid") && !xmlvres.contains("invalid"));
|
||||
} catch (IrrecoverableValidationError e) {
|
||||
// ignore, will be in XML output anyway
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void testXMPValidation() {
|
||||
|
||||
ValidationContext vc = new ValidationContext(null);
|
||||
PDFValidator pv = new PDFValidator(vc);
|
||||
try {
|
||||
|
||||
File tempFile = getResourceAsFile("invalidXMP.pdf");
|
||||
|
||||
pv.setFilename(tempFile.getAbsolutePath());
|
||||
vc.clear();
|
||||
pv.validate();
|
||||
String actual = pv.getXMLResult();
|
||||
|
||||
assertEquals(true, actual
|
||||
.contains("<error type=\"12\">XMP Metadata: ConformanceLevel contains invalid value</error>"));
|
||||
|
||||
tempFile = getResourceAsFile("attributeBasedXMP_zugferd_2p0_EN16931_Einfach.pdf");
|
||||
|
||||
pv.setFilename(tempFile.getAbsolutePath());
|
||||
vc.clear();
|
||||
pv.validate();
|
||||
actual = pv.getXMLResult();
|
||||
|
||||
assertEquals(false, actual.contains("<error"));// issue 18: "ConformanceLevel not found" should not be
|
||||
// reported since it's actually there
|
||||
} catch (IrrecoverableValidationError e) {
|
||||
// ignore, will be in XML output anyway
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
package org.mustangproject.library.extended;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
public class ResourceCase extends TestCase {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ResourceCase.class.getCanonicalName()); // log output is
|
||||
|
||||
public static File getResourceAsFile(String resourcePath) {
|
||||
try {
|
||||
InputStream in = ClassLoader.getSystemClassLoader().getResourceAsStream(resourcePath);
|
||||
if (in == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
File tempFile = File.createTempFile(String.valueOf(in.hashCode()), ".tmp");
|
||||
tempFile.deleteOnExit();
|
||||
|
||||
try (FileOutputStream out = new FileOutputStream(tempFile)) {
|
||||
// copy stream
|
||||
byte[] buffer = new byte[1024];
|
||||
int bytesRead;
|
||||
while ((bytesRead = in.read(buffer)) != -1) {
|
||||
out.write(buffer, 0, bytesRead);
|
||||
}
|
||||
}
|
||||
return tempFile;
|
||||
} catch (IOException e) {
|
||||
LOGGER.error(e.getMessage(), e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,195 +0,0 @@
|
||||
package org.mustangproject.library.extended;
|
||||
|
||||
import static org.xmlunit.assertj.XmlAssert.assertThat;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import javax.xml.transform.Source;
|
||||
|
||||
import org.xmlunit.builder.Input;
|
||||
import org.xmlunit.xpath.JAXPXPathEngine;
|
||||
import org.xmlunit.xpath.XPathEngine;
|
||||
|
||||
public class XMLValidatorTest extends ResourceCase {
|
||||
|
||||
public void testZF2XMLValidation() {
|
||||
// ignored for the
|
||||
// time being
|
||||
|
||||
ValidationContext ctx = new ValidationContext(null);
|
||||
XMLValidator xv = new XMLValidator(ctx);
|
||||
XPathEngine xpath = new JAXPXPathEngine();
|
||||
File tempFile = getResourceAsFile("invalidV2.xml");
|
||||
Source source;
|
||||
String content;
|
||||
|
||||
try {
|
||||
xv.setFilename(tempFile.getAbsolutePath());
|
||||
|
||||
xv.validate();
|
||||
|
||||
/*
|
||||
* assertEquals(true, xv.getXMLResult().
|
||||
* contains("<error location=\"/*[local-name()='CrossIndustryInvoice']/*[local-name()='SupplyChainTradeTransaction']/*[local-name()='ApplicableHeaderTradeSettlement']/*[local-name()='SpecifiedTradeSettlementHeaderMonetarySummation']\" criterion=\"(ram:LineTotalAmount)\">\n"
|
||||
* +
|
||||
* " Eine Rechnung (INVOICE) muss die Summe der Rechnungspositionen-Nettobeträge „Sum of Invoice line net amount“ (BT-106) enthalten.</error>\n"
|
||||
* +
|
||||
* "<error location=\"/*[local-name()='CrossIndustryInvoice']/*[local-name()='SupplyChainTradeTransaction']/*[local-name()='ApplicableHeaderTradeSettlement']/*[local-name()='SpecifiedTradeSettlementHeaderMonetarySummation']\" criterion=\"(ram:TaxBasisTotalAmount = ram:LineTotalAmount - ram:AllowanceTotalAmount + ram:ChargeTotalAmount) or ((ram:TaxBasisTotalAmount = ram:LineTotalAmount - ram:AllowanceTotalAmount) and not (ram:ChargeTotalAmount)) or ((ram:TaxBasisTotalAmount = ram:LineTotalAmount + ram:ChargeTotalAmount) and not (ram:AllowanceTotalAmount)) or ((ram:TaxBasisTotalAmount = ram:LineTotalAmount) and not (ram:ChargeTotalAmount) and not (ram:AllowanceTotalAmount))\">\n"
|
||||
* +
|
||||
* " Der Inhalt des Elementes „Invoice total amount without VAT“ (BT-109) entspricht der Summe aller Inhalte der Elemente „Invoice line net amount“ (BT-131) abzüglich der Summe aller in der Rechnung enthaltenen Nachlässe der Dokumentenebene „Sum of allowances on document level“ (BT-107) zuzüglich der Summe aller in der Rechnung enthaltenen Abgaben der Dokumentenebene „Sum of charges on document level“ (BT-108).</error>\n"
|
||||
* +
|
||||
* "<error location=\"/*[local-name()='CrossIndustryInvoice']/*[local-name()='SupplyChainTradeTransaction']/*[local-name()='ApplicableHeaderTradeSettlement']/*[local-name()='SpecifiedTradeSettlementHeaderMonetarySummation']\" criterion=\"(ram:GrandTotalAmount = round(ram:TaxBasisTotalAmount*100 + ram:TaxTotalAmount[@currencyID=/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement/ram:InvoiceCurrencyCode]*100 +0) div 100) or ((ram:GrandTotalAmount = ram:TaxBasisTotalAmount) and not (ram:TaxTotalAmount[@currencyID=/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement/ram:InvoiceCurrencyCode]))\">\n"
|
||||
* +
|
||||
* " Der Inhalt des Elementes „Invoice total amount with VAT“ (BT-112) entspricht der Summe des Inhalts des Elementes „Invoice total amount without VAT“ (BT-109) und des Elementes „Invoice total VAT amount“ (BT-110).</error>\n"
|
||||
* +
|
||||
* "<error location=\"/*[local-name()='CrossIndustryInvoice']/*[local-name()='SupplyChainTradeTransaction']/*[local-name()='ApplicableHeaderTradeSettlement']/*[local-name()='SpecifiedTradeSettlementHeaderMonetarySummation']\" criterion=\"ram:LineTotalAmount = (round(sum(../../ram:IncludedSupplyChainTradeLineItem/ram:SpecifiedLineTradeSettlement/ram:SpecifiedTradeSettlementLineMonetarySummation/ram:LineTotalAmount) * 10 * 10)div 100)\">\n"
|
||||
* +
|
||||
* " Der Inhalt des Elementes „Sum of Invoice line net amount“ (BT-106) entspricht der Summe aller Inhalte der Elemente „Invoice line net amount“ (BT-131).</error>\n"
|
||||
* +
|
||||
* "<error location=\"/*[local-name()='CrossIndustryInvoice']\" criterion=\"(rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeAgreement/ram:BuyerTradeParty/ram:Name!='')\">\n"
|
||||
* +
|
||||
* " Eine Rechnung (INVOICE) muss den Erwerbernamen „Buyer name“ (BT-44) enthalten.</error>\n"
|
||||
* +
|
||||
* "<error location=\"/*[local-name()='CrossIndustryInvoice']/*[local-name()='SupplyChainTradeTransaction']/*[local-name()='ApplicableHeaderTradeAgreement']/*[local-name()='BuyerTradeParty']\" criterion=\"count(ram:Name)=1\">\n"
|
||||
* + " Das Element 'ram:Name' muss genau 1 mal auftreten.</error>\n" +
|
||||
* "<error location=\"/*[local-name()='CrossIndustryInvoice']/*[local-name()='SupplyChainTradeTransaction']/*[local-name()='ApplicableHeaderTradeSettlement']/*[local-name()='SpecifiedTradeSettlementHeaderMonetarySummation']\" criterion=\"count(ram:LineTotalAmount)=1\">\n"
|
||||
* + " Das Element 'ram:LineTotalAmount' muss genau 1 mal auftreten.</error>\n"
|
||||
* +
|
||||
* "<error location=\"/*[local-name()='CrossIndustryInvoice']/*[local-name()='SupplyChainTradeTransaction']/*[local-name()='IncludedSupplyChainTradeLineItem'][2]/*[local-name()='SpecifiedLineTradeDelivery']/*[local-name()='BilledQuantity']\" criterion=\"document('zugferd2p0_extended_codedb.xml')//cl[@id=7]/enumeration[@value=$codeValue7]\">\n"
|
||||
* + " Wert von '@unitCode' ist unzulässig.</error>\n" +
|
||||
* "</messages><summary status='invalid'/>"));
|
||||
*
|
||||
*/
|
||||
|
||||
tempFile = getResourceAsFile("invalidV2Profile.xml");
|
||||
|
||||
xv.setFilename(tempFile.getAbsolutePath());
|
||||
|
||||
xv.validate();
|
||||
} catch (IrrecoverableValidationError e) {
|
||||
// ignore, will be in XML output anyway
|
||||
}
|
||||
assertTrue(xv.getXMLResult().contains("<error type=\"25\""));
|
||||
ctx.clear();
|
||||
|
||||
try {
|
||||
|
||||
tempFile = getResourceAsFile("FAIL_zugferd_2p1_MINIMUM_Rechnung_380.xml");
|
||||
|
||||
xv.setFilename(tempFile.getAbsolutePath());
|
||||
|
||||
xv.validate();
|
||||
} catch (IrrecoverableValidationError e) {
|
||||
// ignore, will be in XML output anyway
|
||||
}
|
||||
String res = xv.getXMLResult();
|
||||
/*OutputStream os = null;
|
||||
try {
|
||||
os = new FileOutputStream(new File("return.xml"));
|
||||
os.write(res.getBytes(), 0, res.length());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
os.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}*/
|
||||
|
||||
content = "<validation>" + res + "</validation>";
|
||||
|
||||
assertThat(content).valueByXPath("count(//error)")
|
||||
.asInt()
|
||||
.isGreaterThan(1); //2 errors are OK because there is a known bug
|
||||
|
||||
|
||||
assertThat(content).valueByXPath("//error[@type=\"4\"]")
|
||||
.asString()
|
||||
.contains(
|
||||
"In Deutschland sind die Profile MINIMUM und BASIC WL nur als Buchungshilfe (TypeCode: 751) zugelassen.");
|
||||
|
||||
|
||||
ctx.clear();
|
||||
tempFile = getResourceAsFile("validV2Basic.xml");
|
||||
try {
|
||||
|
||||
xv.setFilename(tempFile.getAbsolutePath());
|
||||
xv.validate();
|
||||
assertEquals(true, xv.getXMLResult().contains("valid") && !xv.getXMLResult().contains("invalid"));
|
||||
|
||||
ctx.clear();
|
||||
tempFile = getResourceAsFile("ZUGFeRD-invoice_rabatte_3_abschlag_duepayableamount.xml");
|
||||
xv.setFilename(tempFile.getAbsolutePath());
|
||||
xv.validate();
|
||||
assertEquals(true, xv.getXMLResult().contains("valid") && !xv.getXMLResult().contains("invalid"));
|
||||
|
||||
ctx.clear();
|
||||
tempFile = getResourceAsFile("valid_Avoir_FR_type380_minimum_factur-x.xml");
|
||||
xv.setFilename(tempFile.getAbsolutePath());
|
||||
xv.validate();
|
||||
|
||||
source = Input.fromString("<validation>" + xv.getXMLResult() + "</validation>").build();
|
||||
content = xpath.evaluate("/validation/summary/@status", source);
|
||||
assertEquals("invalid", content);
|
||||
|
||||
// assertEquals(true, xv.getXMLResult().contains("valid") &&
|
||||
// !xv.getXMLResult().contains("invalid"));
|
||||
|
||||
/*
|
||||
* this test failure might have to be upstreamed ctx.clear(); tempFile =
|
||||
* getResourceAsFile(
|
||||
* "ZUGFeRD-invoice_rabatte_4_abschlag_taxbasistotalamount.xml");
|
||||
* xv.setFilename(tempFile.getAbsolutePath()); xv.validate(); assertEquals(true,
|
||||
* xv.getXMLResult().contains("valid") &&
|
||||
* !xv.getXMLResult().contains("invalid"));
|
||||
*/
|
||||
ctx.clear();
|
||||
tempFile = getResourceAsFile("attributeBasedXMP_zugferd_2p0_EN16931_Einfach_corrected.xml");
|
||||
xv.setFilename(tempFile.getAbsolutePath());
|
||||
xv.validate();
|
||||
assertEquals(true, xv.getXMLResult().contains("valid") && !xv.getXMLResult().contains("invalid"));
|
||||
|
||||
ctx.clear();
|
||||
tempFile = getResourceAsFile("validZREtestZugferd.xml");
|
||||
xv.setFilename(tempFile.getAbsolutePath());
|
||||
xv.validate();
|
||||
|
||||
source = Input.fromString("<validation>" + xv.getXMLResult() + "</validation>").build();
|
||||
content = xpath.evaluate("/validation/summary/@status", source);
|
||||
assertEquals("invalid", content);
|
||||
|
||||
} catch (IrrecoverableValidationError e) {
|
||||
// ignore, will be in XML output anyway
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void testZF1XMLValidation() {
|
||||
ValidationContext ctx = new ValidationContext(null);
|
||||
XMLValidator xv = new XMLValidator(ctx);
|
||||
File tempFile = getResourceAsFile("validV1.xml");
|
||||
try {
|
||||
xv.setFilename(tempFile.getAbsolutePath());
|
||||
xv.validate();
|
||||
assertEquals(true, xv.getXMLResult().contains("valid") && !xv.getXMLResult().contains("invalid"));
|
||||
|
||||
tempFile = getResourceAsFile("invalidV1ExtraTags.xml");
|
||||
xv.setFilename(tempFile.getAbsolutePath());
|
||||
xv.validate();
|
||||
assertEquals(true, xv.getXMLResult().contains("invalid"));
|
||||
|
||||
tempFile = getResourceAsFile("invalidV1TooMinimal.xml");
|
||||
xv.setFilename(tempFile.getAbsolutePath());
|
||||
xv.validate();
|
||||
assertEquals(true, xv.getXMLResult().contains("<error type=\"26\""));
|
||||
|
||||
} catch (IrrecoverableValidationError e) {
|
||||
// ignore, will be in XML output anyway
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
package org.mustangproject.library.extended;
|
||||
|
||||
import static org.xmlunit.assertj.XmlAssert.assertThat;
|
||||
import java.io.File;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import org.xmlunit.builder.Input;
|
||||
import org.xmlunit.xpath.JAXPXPathEngine;
|
||||
import org.xmlunit.xpath.XPathEngine;
|
||||
|
||||
import static org.xmlunit.assertj.XmlAssert.assertThat;
|
||||
|
||||
public class ZUGFeRDValidatorTest extends ResourceCase {
|
||||
|
||||
public void testPDFValidation() {
|
||||
File tempFile = getResourceAsFile("invalidPDF.pdf");
|
||||
/**used to be Rule Status
|
||||
Specification: ISO 19005-3:2012, Clause: 6.2.11.4, Test number: 4
|
||||
If the FontDescriptor dictionary of an embedded CID font contains a CIDSet stream, then it shall identify all CIDs which are present in the font program, regardless of whether a CID in the font is referenced or used by the PDF or not. Failed
|
||||
2 occurrences Hide
|
||||
PDCIDFont
|
||||
fontFile_size == 0 || fontName.search(/[A-Z]{6}\+/) != 0 || CIDSet_size == 0 || cidSetListsAllGlyphs == true
|
||||
root/document[0]/pages[1](9 0 obj PDPage)/contentStream[0](18 0 obj PDContentStream)/operators[166]/font[0](WIUIIO+CIDFont+F2)/DescendantFonts[0](WIUIIO+CIDFont+F2)
|
||||
root/document[0]/pages[1](9 0 obj PDPage)/contentStream[0](18 0 obj PDContentStream)/operators[192]/font[0](VEXQUA+CIDFont+F1)/DescendantFonts[0](VEXQUA+CIDFont+F1)
|
||||
but new sample since that has been downgraded to warning
|
||||
*/
|
||||
ZUGFeRDValidator zfv = new ZUGFeRDValidator();
|
||||
|
||||
String res = zfv.validate(tempFile.getAbsolutePath());
|
||||
|
||||
|
||||
assertThat(res).valueByXPath("/validation/pdf/summary/@status")
|
||||
.isEqualTo("invalid");
|
||||
|
||||
assertThat(res).valueByXPath("/validation/xml/summary/@status")
|
||||
.isEqualTo("valid");
|
||||
|
||||
assertThat(res).valueByXPath("/validation/summary/@status")
|
||||
.isEqualTo("invalid");
|
||||
|
||||
|
||||
tempFile = getResourceAsFile("validAvoir_FR_type380_BASICWL.pdf");
|
||||
zfv = new ZUGFeRDValidator();
|
||||
|
||||
res = zfv.validate(tempFile.getAbsolutePath());
|
||||
assertEquals(true, res.contains("status=\"valid\""));
|
||||
assertEquals(false, res.contains("status=\"invalid\""));
|
||||
|
||||
tempFile = getResourceAsFile("validAvoir_FR_type380_BASICWL.pdf");
|
||||
zfv = new ZUGFeRDValidator();
|
||||
|
||||
res = zfv.validate(tempFile.getAbsolutePath());
|
||||
assertEquals(true, res.contains("status=\"valid\""));
|
||||
assertEquals(false, res.contains("status=\"invalid\""));
|
||||
|
||||
}
|
||||
|
||||
/***
|
||||
* the XMLValidatorTests only cover the <xml></xml> part, this one includes the root element and
|
||||
* the global <summary></summary> part as well
|
||||
*/
|
||||
public void testXMLValidation() {
|
||||
File tempFile = getResourceAsFile("validV2.xml");
|
||||
ZUGFeRDValidator zfv = new ZUGFeRDValidator();
|
||||
|
||||
String res = zfv.validate(tempFile.getAbsolutePath());
|
||||
|
||||
assertThat(res).valueByXPath("count(//error)")
|
||||
.asInt()
|
||||
.isEqualTo(0);
|
||||
|
||||
assertThat(res).valueByXPath("count(//notice)")
|
||||
.asInt()
|
||||
.isEqualTo(3); // 3 notices RE XRechnung
|
||||
assertThat(res).valueByXPath("/validation/summary/@status")
|
||||
.asString()
|
||||
.isEqualTo("valid");// expect to be valid because XR notices are, well, only notices
|
||||
assertThat(res).valueByXPath("/validation/xml/summary/@status")
|
||||
.asString()
|
||||
.isEqualTo("valid");
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user