Skip to content

Commit

Permalink
corrected tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jochen Stärk authored and Jochen Stärk committed May 24, 2020
1 parent b8fa899 commit dbdcdbe
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 34 deletions.
2 changes: 2 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
- javadoc export
- prompt for source file for validation has to be pdf
- be able to disable "source pdf set to timeout"
- automated tests zuv/verapdf validate created library test files
- unify loggers
done
- 2.1 now default
- pushprovider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class ZUGFeRDExporter implements Closeable {

public static final int DefaultZUGFeRDVersion = 2;

private boolean isFacturX = false;
private boolean isFacturX = true;

/**
* To use the ZUGFeRD exporter, implement IZUGFeRDExportableTransaction in
Expand Down Expand Up @@ -210,11 +210,21 @@ private void init() {
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() {
setZUGFeRDVersion(2);
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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,15 +257,14 @@ public void testCustomZF2Export() {
" </rsm:SupplyChainTradeTransaction>\n" +
"</rsm:CrossIndustryInvoice>";
zea1.setZUGFeRDXMLData(ownZUGFeRDXML.getBytes("UTF-8"));

ByteArrayOutputStream baos = new ByteArrayOutputStream();
zea1.disableAutoClose(true);
zea1.export(TARGET_PDF);
zea1.export(baos);
zea1.close();
String pdfContent = baos.toString("UTF-8");
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) {
e.printStackTrace();
Expand Down Expand Up @@ -303,6 +302,7 @@ public void testCustomZF1Export() {
ZUGFeRDExporter zea1 = new ZUGFeRDExporterFromA1Factory()
.setProducer("My Application")
.setCreator("Test")
.setZUGFeRDVersion(1)
.setZUGFeRDConformanceLevel(ZUGFeRDConformanceLevel.BASIC)
.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. */
Expand Down Expand Up @@ -448,7 +448,7 @@ public void testCustomZF1Export() {
zea1.close();
String pdfContent = baos.toString("UTF-8");
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) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,35 +111,6 @@ public void testZF2XMLValidation() {
.contains(
"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();
tempFile = getResourceAsFile("validV2Basic.xml");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,38 @@ public void testPDFValidation() {
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");

}
}

0 comments on commit dbdcdbe

Please sign in to comment.