diff --git a/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2PushTest.java b/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2PushTest.java index 0d6f2cb7..48daa626 100644 --- a/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2PushTest.java +++ b/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2PushTest.java @@ -1,826 +1,828 @@ - -/** - * ********************************************************************* - *
- * 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 java.io.ByteArrayInputStream;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.math.BigDecimal;
-import java.nio.charset.StandardCharsets;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.List;
-
-import org.mustangproject.*;
-import org.junit.FixMethodOrder;
-import org.junit.runners.MethodSorters;
-
-import junit.framework.TestCase;
-
-import org.mustangproject.ZUGFeRD.model.DocumentCodeTypeConstants;
-import org.mustangproject.ZUGFeRD.model.EventTimeCodeTypeConstants;
-
-import javax.xml.xpath.XPathExpressionException;
-
-import static org.xmlunit.assertj.XmlAssert.assertThat;
-
-
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-public class ZF2PushTest extends TestCase {
- final String TARGET_PDF = "./target/testout-MustangGnuaccountingBeispielRE-20201121_508.pdf";
- final String TARGET_ALLOWANCESPDF = "./target/testout-ZF2PushAllowances.pdf";
- final String TARGET_CREDITNOTEPDF = "./target/testout-ZF2PushCreditNote.pdf";
- final String TARGET_CORRECTIONPDF = "./target/testout-ZF2PushCorrection.pdf";
- final String TARGET_ITEMCHARGESALLOWANCESPDF = "./target/testout-ZF2PushItemChargesAllowances.pdf";
- final String TARGET_CHARGESALLOWANCESPDF = "./target/testout-ZF2PushChargesAllowances.pdf";
- final String TARGET_RELATIVECHARGESALLOWANCESPDF = "./target/testout-ZF2PushRelativeChargesAllowances.pdf";
- final String TARGET_ATTACHMENTSPDF = "./target/testout-ZF2PushAttachments.pdf";
- final String TARGET_BANKPDF = "./target/testout-ZF2PushBank.pdf";
- final String TARGET_PUSHEDGE = "./target/testout-ZF2PushEdge.pdf";
- final String TARGET_INTRACOMMUNITYSUPPLYMANUALPDF = "./target/testout-ZF2PushIntraCommunitySupplyManual.pdf";
- final String TARGET_INTRACOMMUNITYSUPPLYPDF = "./target/testout-ZF2PushIntraCommunitySupply.pdf";
- final String TARGET_REVERSECHARGEPDF = "./target/testout-ZF2PushReverseCharge.pdf";
-
- public void testPushExport() {
- /***
- * This writes to a filename like an official sample, please consider when changing (probably better not?)
- */
- // the writing part
- String orgname = "Bei Spiel GmbH";
- String number = "RE-20201121/508";
- String priceStr = "160.00";
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
-
- BigDecimal price = new BigDecimal(priceStr);
- try {
- InputStream SOURCE_PDF = this.getClass()
- .getResourceAsStream("/MustangGnuaccountingBeispielRE-20201121_508blanko.pdf");
-
- ZUGFeRDExporterFromA1 ze = new ZUGFeRDExporterFromA1();
- ze.ignorePDFAErrors();
- ze.load(SOURCE_PDF);
- ze.setProducer("My Application").setCreator(System.getProperty("user.name")).setZUGFeRDVersion(2);
- ze.setTransaction(new Invoice().setDueDate(sdf.parse("2020-12-12")).setIssueDate(sdf.parse("2020-11-21")).setDeliveryDate(sdf.parse("2020-11-10"))
- .setSender(new TradeParty(orgname, "Ecke 12", "12345", "Stadthausen", "DE").addBankDetails(new BankDetails("DE88200800000970375700", "COBADEFFXXX").setAccountName("Max Mustermann")).addVATID("DE136695976"))
- .setRecipient(new TradeParty("Theodor Est", "Bahnstr. 42", "88802", "Spielkreis", "DE")
- .setContact(new Contact("Ingmar N. Fo", "(555) 23 78-23", "info@localhost.local")).setID("2"))
- .setNumber(number)
- .setReferenceNumber("AB321")
- .addItem(new Item(new Product("Design (hours)", "Of a sample invoice", "HUR", new BigDecimal(7)), price, new BigDecimal(1.0)))
- .addItem(new Item(new Product("Ballons", "various colors, ~2000ml", "H87", new BigDecimal(19)), new BigDecimal("0.79"), new BigDecimal(400.0)))
- .addItem(new Item(new Product("Hot air „heiße Luft“ (litres)", "", "LTR", new BigDecimal(19)), new BigDecimal("0.025"), new BigDecimal(800.0)))
- .setRoundingAmount(new BigDecimal("1"))
- );
-
- ze.export(TARGET_PDF);
- } catch (IOException | ParseException e) {
- fail("Exception should not be raised");
- }
-
- ZUGFeRDInvoiceImporter zii = new ZUGFeRDInvoiceImporter(TARGET_PDF);
- Invoice i = new Invoice();
- try {
- zii.extractInto(i);
- } catch (XPathExpressionException e) {
- throw new RuntimeException(e);
- } catch (ParseException e) {
- throw new RuntimeException(e);
- }
-
-
- // now check the contents (like MustangReaderTest)
- ZUGFeRDImporter zi = new ZUGFeRDImporter(TARGET_PDF);
- assertTrue(zi.getUTF8().contains("DE88200800000970375700")); //the iban
- assertTrue(zi.getUTF8().contains("Max Mustermann")); //account holder
- assertTrue(zi.getUTF8().contains("DueDateDateTime")); //account holder
- assertTrue(zi.getUTF8().contains("20201212")); //account holder
-
- assertTrue(zi.getUTF8().contains("
+ * 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 java.io.ByteArrayInputStream;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.math.BigDecimal;
+import java.nio.charset.StandardCharsets;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.List;
+
+import org.mustangproject.*;
+import org.junit.FixMethodOrder;
+import org.junit.runners.MethodSorters;
+
+import junit.framework.TestCase;
+
+import org.mustangproject.ZUGFeRD.model.DocumentCodeTypeConstants;
+import org.mustangproject.ZUGFeRD.model.EventTimeCodeTypeConstants;
+
+import javax.xml.xpath.XPathExpressionException;
+
+import static org.xmlunit.assertj.XmlAssert.assertThat;
+
+
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class ZF2PushTest extends TestCase {
+ final String TARGET_PDF = "./target/testout-MustangGnuaccountingBeispielRE-20201121_508.pdf";
+ final String TARGET_ALLOWANCESPDF = "./target/testout-ZF2PushAllowances.pdf";
+ final String TARGET_CREDITNOTEPDF = "./target/testout-ZF2PushCreditNote.pdf";
+ final String TARGET_CORRECTIONPDF = "./target/testout-ZF2PushCorrection.pdf";
+ final String TARGET_ITEMCHARGESALLOWANCESPDF = "./target/testout-ZF2PushItemChargesAllowances.pdf";
+ final String TARGET_CHARGESALLOWANCESPDF = "./target/testout-ZF2PushChargesAllowances.pdf";
+ final String TARGET_RELATIVECHARGESALLOWANCESPDF = "./target/testout-ZF2PushRelativeChargesAllowances.pdf";
+ final String TARGET_ATTACHMENTSPDF = "./target/testout-ZF2PushAttachments.pdf";
+ final String TARGET_BANKPDF = "./target/testout-ZF2PushBank.pdf";
+ final String TARGET_PUSHEDGE = "./target/testout-ZF2PushEdge.pdf";
+ final String TARGET_INTRACOMMUNITYSUPPLYMANUALPDF = "./target/testout-ZF2PushIntraCommunitySupplyManual.pdf";
+ final String TARGET_INTRACOMMUNITYSUPPLYPDF = "./target/testout-ZF2PushIntraCommunitySupply.pdf";
+ final String TARGET_REVERSECHARGEPDF = "./target/testout-ZF2PushReverseCharge.pdf";
+
+ public void testPushExport() {
+ /***
+ * This writes to a filename like an official sample, please consider when changing (probably better not?)
+ */
+ // the writing part
+ String orgname = "Bei Spiel GmbH";
+ String number = "RE-20201121/508";
+ String priceStr = "160.00";
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+
+ BigDecimal price = new BigDecimal(priceStr);
+ try {
+ InputStream SOURCE_PDF = this.getClass()
+ .getResourceAsStream("/MustangGnuaccountingBeispielRE-20201121_508blanko.pdf");
+
+ ZUGFeRDExporterFromA1 ze = new ZUGFeRDExporterFromA1();
+ ze.ignorePDFAErrors();
+ ze.load(SOURCE_PDF);
+ ze.setProducer("My Application").setCreator(System.getProperty("user.name")).setZUGFeRDVersion(2);
+ ze.setTransaction(new Invoice().setDueDate(sdf.parse("2020-12-12")).setIssueDate(sdf.parse("2020-11-21")).setDeliveryDate(sdf.parse("2020-11-10"))
+ .setSender(new TradeParty(orgname, "Ecke 12", "12345", "Stadthausen", "DE").addBankDetails(new BankDetails("DE88200800000970375700", "COBADEFFXXX").setAccountName("Max Mustermann")).addVATID("DE136695976"))
+ .setRecipient(new TradeParty("Theodor Est", "Bahnstr. 42", "88802", "Spielkreis", "DE")
+ .setContact(new Contact("Ingmar N. Fo", "(555) 23 78-23", "info@localhost.local")).setID("2"))
+ .setNumber(number)
+ .setReferenceNumber("AB321")
+ .addItem(new Item(new Product("Design (hours)", "Of a sample invoice", "HUR", new BigDecimal(7)), price, new BigDecimal(1.0)))
+ .addItem(new Item(new Product("Ballons", "various colors, ~2000ml", "H87", new BigDecimal(19)), new BigDecimal("0.79"), new BigDecimal(400.0)))
+ .addItem(new Item(new Product("Hot air „heiße Luft“ (litres)", "", "LTR", new BigDecimal(19)), new BigDecimal("0.025"), new BigDecimal(800.0)))
+ .setRoundingAmount(new BigDecimal("1"))
+ );
+
+ ze.export(TARGET_PDF);
+ } catch (IOException | ParseException e) {
+ fail("Exception should not be raised");
+ }
+
+ ZUGFeRDInvoiceImporter zii = new ZUGFeRDInvoiceImporter(TARGET_PDF);
+ Invoice i = new Invoice();
+ try {
+ zii.extractInto(i);
+ } catch (XPathExpressionException e) {
+ throw new RuntimeException(e);
+ } catch (ParseException e) {
+ throw new RuntimeException(e);
+ }
+
+
+ // now check the contents (like MustangReaderTest)
+ ZUGFeRDImporter zi = new ZUGFeRDImporter(TARGET_PDF);
+ assertTrue(zi.getUTF8().contains("DE88200800000970375700")); //the iban
+ assertTrue(zi.getUTF8().contains("Max Mustermann")); //account holder
+ assertTrue(zi.getUTF8().contains("DueDateDateTime")); //account holder
+ assertTrue(zi.getUTF8().contains("20201212")); //account holder
+
+ assertTrue(zi.getUTF8().contains("