corrected tests

This commit is contained in:
Jochen Stärk
2020-05-24 19:49:05 +02:00
parent b8fa899f60
commit dbdcdbe75f
5 changed files with 50 additions and 34 deletions

View File

@@ -10,6 +10,8 @@
- javadoc export - javadoc export
- prompt for source file for validation has to be pdf - prompt for source file for validation has to be pdf
- be able to disable "source pdf set to timeout" - be able to disable "source pdf set to timeout"
- automated tests zuv/verapdf validate created library test files
- unify loggers
done done
- 2.1 now default - 2.1 now default
- pushprovider - pushprovider

View File

@@ -56,7 +56,7 @@ public class ZUGFeRDExporter implements Closeable {
public static final int DefaultZUGFeRDVersion = 2; public static final int DefaultZUGFeRDVersion = 2;
private boolean isFacturX = false; private boolean isFacturX = true;
/** /**
* To use the ZUGFeRD exporter, implement IZUGFeRDExportableTransaction in * To use the ZUGFeRD exporter, implement IZUGFeRDExportableTransaction in
@@ -210,11 +210,21 @@ public class ZUGFeRDExporter implements Closeable {
setZUGFeRDVersion(DefaultZUGFeRDVersion); setZUGFeRDVersion(DefaultZUGFeRDVersion);
} }
/**
* Factur-X is now set by default since ZF 2.1, you have to disable it if you dont wont it
* Generate ZF2.1 files with filename factur-x.xml
* @deprecated
* */
public void setFacturX() { public void setFacturX() {
setZUGFeRDVersion(2);
isFacturX = true; isFacturX = true;
} }
/***
* Generate ZF2.0/2.1 files with filename zugferd-invoice.xml instead of factur-x.xml
*/
public void disableFacturX() {
isFacturX = false;
}
/** /**
* All files are PDF/A-3, setConformance refers to the level conformance. * All files are PDF/A-3, setConformance refers to the level conformance.
* *

View File

@@ -257,7 +257,6 @@ public class MustangReaderWriterCustomXMLTest extends TestCase {
" </rsm:SupplyChainTradeTransaction>\n" + " </rsm:SupplyChainTradeTransaction>\n" +
"</rsm:CrossIndustryInvoice>"; "</rsm:CrossIndustryInvoice>";
zea1.setZUGFeRDXMLData(ownZUGFeRDXML.getBytes("UTF-8")); zea1.setZUGFeRDXMLData(ownZUGFeRDXML.getBytes("UTF-8"));
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
zea1.disableAutoClose(true); zea1.disableAutoClose(true);
zea1.export(TARGET_PDF); zea1.export(TARGET_PDF);
@@ -265,7 +264,7 @@ public class MustangReaderWriterCustomXMLTest extends TestCase {
zea1.close(); zea1.close();
String pdfContent = baos.toString("UTF-8"); String pdfContent = baos.toString("UTF-8");
assertFalse(pdfContent.indexOf("(via mustangproject.org") == -1); assertFalse(pdfContent.indexOf("(via mustangproject.org") == -1);
assertFalse(pdfContent.indexOf("<zf:ConformanceLevel>EN 16931</zf:ConformanceLevel>") == -1); assertFalse(pdfContent.indexOf("<fx:ConformanceLevel>EN 16931</fx:ConformanceLevel>") == -1);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
@@ -303,6 +302,7 @@ public class MustangReaderWriterCustomXMLTest extends TestCase {
ZUGFeRDExporter zea1 = new ZUGFeRDExporterFromA1Factory() ZUGFeRDExporter zea1 = new ZUGFeRDExporterFromA1Factory()
.setProducer("My Application") .setProducer("My Application")
.setCreator("Test") .setCreator("Test")
.setZUGFeRDVersion(1)
.setZUGFeRDConformanceLevel(ZUGFeRDConformanceLevel.BASIC) .setZUGFeRDConformanceLevel(ZUGFeRDConformanceLevel.BASIC)
.load(SOURCE_PDF); .load(SOURCE_PDF);
/* we have much more information than just in the basic profile (comfort or extended) but it's perfectly valid to provide more information, just not less. */ /* we have much more information than just in the basic profile (comfort or extended) but it's perfectly valid to provide more information, just not less. */
@@ -448,7 +448,7 @@ public class MustangReaderWriterCustomXMLTest extends TestCase {
zea1.close(); zea1.close();
String pdfContent = baos.toString("UTF-8"); String pdfContent = baos.toString("UTF-8");
assertFalse(pdfContent.indexOf("(via mustangproject.org") == -1); assertFalse(pdfContent.indexOf("(via mustangproject.org") == -1);
assertFalse(pdfContent.indexOf("<zf:ConformanceLevel>BASIC</zf:ConformanceLevel>") == -1); assertFalse(pdfContent.indexOf("<fx:ConformanceLevel>BASIC</fx:ConformanceLevel>") == -1);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();

View File

@@ -111,35 +111,6 @@ public class XMLValidatorTest extends ResourceCase {
.contains( .contains(
"In Deutschland sind die Profile MINIMUM und BASIC WL nur als Buchungshilfe (TypeCode: 751) zugelassen."); "In Deutschland sind die Profile MINIMUM und BASIC WL nur als Buchungshilfe (TypeCode: 751) zugelassen.");
ctx.clear();
try {
tempFile = getResourceAsFile("validv2.xml");
xv.setFilename(tempFile.getAbsolutePath());
xv.validate();
} catch (IrrecoverableValidationError e) {
// ignore, will be in XML output anyway
}
res = xv.getXMLResult();
content = "<validation>" + res + "</validation>";
assertThat(content).valueByXPath("count(//error)")
.asInt()
.isEqualTo(0);
assertThat(content).valueByXPath("count(//notice)")
.asInt()
.isEqualTo(3); // 3 notices RE XRechnung
assertThat(content).valueByXPath("/validation/summary/@status")
.asString()
.isEqualTo("valid");// expect to be valid because XR notices are, well, only notices
assertThat(content).valueByXPath("/validation/xml/@status")
.asString()
.isEqualTo("valid");
ctx.clear(); ctx.clear();
tempFile = getResourceAsFile("validV2Basic.xml"); tempFile = getResourceAsFile("validV2Basic.xml");

View File

@@ -46,5 +46,38 @@ public class ZUGFeRDValidatorTest extends ResourceCase {
assertEquals(true, res.contains("status=\"valid\"")); assertEquals(true, res.contains("status=\"valid\""));
assertEquals(false, res.contains("status=\"invalid\"")); 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");
} }
} }