From d22a8a0b5c48858ff5694111c8960e3bfa8d3bc7 Mon Sep 17 00:00:00 2001 From: jstaerk Date: Wed, 26 Jun 2024 10:52:32 +0200 Subject: [PATCH] added a unit test. corrected main --- History.md | 3 +- .../org/mustangproject/commandline/Main.java | 27 +++--- .../ZUGFeRD/PreValidationTest.java | 86 ++++++++++++++++++ .../veraPDFtestsuite6-7-11-t01-fail-a.pdf | Bin 0 -> 3545 bytes 4 files changed, 103 insertions(+), 13 deletions(-) create mode 100644 library/src/test/java/org/mustangproject/ZUGFeRD/PreValidationTest.java create mode 100644 library/src/test/resources/veraPDFtestsuite6-7-11-t01-fail-a.pdf diff --git a/History.md b/History.md index 8c5d03fc..3a37564a 100644 --- a/History.md +++ b/History.md @@ -1,7 +1,8 @@ - support pdf export/visualization to PDF, thanks to Heavenfighter #387 allow embedd fonts from jar-file for pdf creation #388 - Fix #389: ClassCastException: ZUGFeRDExporterFromA3 - +- jakarta support #372 +- Upgrade to PDFBox 3 #373 2.11.0 ======= 2024-05-22 diff --git a/Mustang-CLI/src/main/java/org/mustangproject/commandline/Main.java b/Mustang-CLI/src/main/java/org/mustangproject/commandline/Main.java index e9c9f4a2..60d066b1 100755 --- a/Mustang-CLI/src/main/java/org/mustangproject/commandline/Main.java +++ b/Mustang-CLI/src/main/java/org/mustangproject/commandline/Main.java @@ -331,31 +331,34 @@ public class Main { try { CommandLine cmd; CommandLineParser parser = new BasicParser(); + // create Options object Options options = new Options(); - options.addOption(new Option("h", "help", false, "display usage")); options.addOption(new Option("a", "action", true, "which action to perform")); options.addOption(new Option("f", "format", true, "which format to output")); - options.addOption(new Option("", "version", true, "which version of the standard to use")); - options.addOption(new Option("", "profile", true, "which profile of the standard to use")); - Option attachmentOpt = new Option("", "attachments", true, "File attachments"); + options.addOption(new Option("version", "version", true, "which version of the standard to use")); + options.addOption(new Option("profile", "profile", true, "which profile of the standard to use")); + Option attachmentOpt = new Option("attachments", "attachments", true, "File attachments"); attachmentOpt.setValueSeparator(','); attachmentOpt.setArgs(Option.UNLIMITED_VALUES); + options.addOption(attachmentOpt); - options.addOption(new Option("", "source",true, "which source file to use")); - options.addOption(new Option("", "source-xml",true, "which source file to use")); - options.addOption(new Option("", "language",true, "output language (en, de or fr)")); - options.addOption(new Option("", "out",true, "which output file to write to")); - options.addOption(new Option("", "no-notices",false, "suppress non-fatal errors")); - options.addOption(new Option("", "logAppend",true, "freeform text to be appended to log messages")); - options.addOption(new Option("", "disable-file-logging", false, "suppress logging to file")); + options.addOption(new Option("source", "source",true, "which source file to use")); + options.addOption(new Option("source-xml", "source-xml",true, "which source file to use")); + options.addOption(new Option("language", "language",true, "output language (en, de or fr)")); + options.addOption(new Option("out", "out",true, "which output file to write to")); + options.addOption(new Option("no-notices", "no-notices",false, "suppress non-fatal errors")); + options.addOption(new Option("logAppend", "logAppend",true, "freeform text to be appended to log messages")); + options.addOption(new Option("disable-file-logging", "disable-file-logging", false, "suppress logging to file")); options.addOption(new Option("d", "directory",true, "which directory to operate on")); options.addOption(new Option("i", "ignorefileextension",false, "ignore non-matching file extensions")); options.addOption(new Option("l", "listfromstdin",false, "take list of files from commandline")); + boolean optionsRecognized=false; String action = ""; - Boolean disableFileLogging = false; + + Boolean disableFileLogging = false; try { cmd = parser.parse(options, args); diff --git a/library/src/test/java/org/mustangproject/ZUGFeRD/PreValidationTest.java b/library/src/test/java/org/mustangproject/ZUGFeRD/PreValidationTest.java new file mode 100644 index 00000000..4798a4c0 --- /dev/null +++ b/library/src/test/java/org/mustangproject/ZUGFeRD/PreValidationTest.java @@ -0,0 +1,86 @@ + +/** + * ********************************************************************* + *

+ * Copyright 2019 Jochen Staerk + *

+ * Use is subject to license terms. + *

+ * Licensed 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. + *

+ * ********************************************************************** + */ +package org.mustangproject.ZUGFeRD; + +import junit.framework.TestCase; +import org.junit.FixMethodOrder; +import org.junit.runners.MethodSorters; +import org.mustangproject.*; + +import java.io.IOException; +import java.io.InputStream; +import java.math.BigDecimal; +import java.util.Date; + + + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class PreValidationTest extends TestCase { + final String TARGET_PDF = "./target/testout-Preval.pdf"; + final String SOURCE_PDF = "/veraPDFtestsuite6-7-11-t01-fail-a.pdf"; + + public void testFailIgnore() { + + // the writing part + + + boolean hasEx = false; + try (InputStream source = this.getClass() + .getResourceAsStream(SOURCE_PDF)) { + ZUGFeRDExporterFromA1 ze = new ZUGFeRDExporterFromA1().setProducer("My Application") + .setCreator(System.getProperty("user.name")).setZUGFeRDVersion(2) + .load(source); + ze.setTransaction(createInvoice()); + + ze.export(TARGET_PDF); + } catch (IOException e) { + hasEx = true; + } + assertTrue(hasEx); + hasEx = false; + try (InputStream source = this.getClass() + .getResourceAsStream(SOURCE_PDF)) { + ZUGFeRDExporterFromA1 ze = new ZUGFeRDExporterFromA1().setProducer("My Application").ignorePDFAErrors() + .setCreator(System.getProperty("user.name")).setZUGFeRDVersion(2) + .load(source); + ze.setTransaction(createInvoice()); + ze.export(TARGET_PDF); + } catch (IOException e) { + hasEx = true; + } + assertFalse(hasEx); + } + + private Invoice createInvoice() { + String orgname = "Test company"; + String number = "123"; + String amountStr = "1.00"; + BigDecimal amount = new BigDecimal(amountStr); + return new Invoice().setDueDate(new Date()).setIssueDate(new Date()).setDeliveryDate(new Date()) + .setSender(new TradeParty(orgname, "teststr", "55232", "teststadt", "DE").addTaxID("DE4711").addVATID("DE0815").setEmail("info@example.org").setContact(new Contact("Hans Test", "+49123456789", "test@example.org")).addBankDetails(new BankDetails("DE12500105170648489890", "COBADEFXXX"))) + .setRecipient(new TradeParty("Theodor Est", "Bahnstr. 42", "88802", "Spielkreis", "DE")) + .setReferenceNumber("991-01484-64")//leitweg-id + // not using any VAT, this is also a test of zero-rated goods: + .setNumber(number).addItem(new Item(new Product("Testprodukt", "", "C62", BigDecimal.ZERO), amount, new BigDecimal(1.0))); + } + +} diff --git a/library/src/test/resources/veraPDFtestsuite6-7-11-t01-fail-a.pdf b/library/src/test/resources/veraPDFtestsuite6-7-11-t01-fail-a.pdf new file mode 100644 index 0000000000000000000000000000000000000000..9b8333b203e482c83af897dddb0ab95f2c82c9d0 GIT binary patch literal 3545 zcmai1U2G%89Z&8mM3)|=Uo@z#G#HNLdS}nf+G}TBC*as;noE4=a|}I{gJ!ckc9vW3 zZgyuA=V&V=P73MzonASfgRqh|Sntq9Kw8?s=y)ZkAOk-j8drFfu-5T36zkAtZYnRV<^vjoY z)tJ415o`wKLEr5|3(%l%*?xJjkkKF;R)%M>j5Dwcp^9g8%k6q2-UV+9nJv!UGRC{R zySd$b&hdJfs;Y{KjAc0sJF@5uRwG!s z|?GNHvR$!BSyLrZ0RsgNp z-TSPq_|r>qQvet#1-^h%^5dnza=GO>MxZnA@H!AQ0A)TqtOl4)Lr*i!eh3%{p<&y{ zrg2DcuqwNn2hgDzBzD5P?tmnCea+UPX<8gQ8Yv(h>aXA-JH*?NUclFd+1-#o@EFlA zA+ZpRgv2!`uz~dwZkQentQ66IRXcc&s6AAV11%6LlehsOao7SP1Rd;}7DMxqr%=-7 z+7B+B2vrL<0Hh655Np{0;+S2Nd1$Wcx?mG+TSNH4&f50@{#BYNOXNEexRe|T4NFpp zDglcX(*O-rMSRe}D1D)Xe#%hDTw=I_)+vd1w=@ru5^9L3P-oEEgQc@rJmtac(5Rg55s+Au8+jm8ZN_*Z8-oC*?-6*#}xYv{S3U%Yr@=8hY`oBG_|zxUq!!px12 zlv^5i{P2;l8+X25dF<*77h9bpul;Z8?ek|I-U zZ!-5o{Kl#GSN||~p2&o>+|~Eaoq6ciU!Te?U(Y`L&kt5U#NU1wpESQepf$a~3vV`weOi(P%@B>1C@MJ7rI-o2r3F5V!JkHa$e&>z zA(s==mdADwja4c3!v-!S1sAP8^LaSS783QSzE3n0#jeA*CYaG4#`2{IR$w= zNg=322!em`2Tklsr<*nD{2{0eXP*RJ5s+!2Na*0HheCk_Tp>K1%%`IvEn?A(Vi%(` ziW(iOTHI*vxTcN>9hp^Ho+5vv>X#rO99$e~d~hD~1B;iD5Wf-UX-Y=ULjw6(z5r?y=#T7_|5xd$>kb=*8$7r3z#-wkFGv^VnLx z2(uqsD+p?gtts-PzhVKnKe`VDbHY}pg^8SH_)OT!MHtVRzx-rexd7FV?^BdXf5qZN zy>h8AQ3o7OlWVFB(v;-FJs3Xo!e3FqoApYeA=4UF@~Tp=mg@6rO|4bcYE4}#R@HfV zskVqJRXSf&X?}^4e4_wQjY3Ij$a0~YC#BlFl3xVL41W*Bmw+|%G83~8Pe{0