From 957900f89ac8bfa40cb5259a00fa9cb58d662b14 Mon Sep 17 00:00:00 2001 From: Adrian-Devries Date: Thu, 19 Dec 2024 18:46:51 +0100 Subject: [PATCH 1/4] Update ZUGFeRDImporter.java Add attribute @Deprecated to method getLineItemList --- .../main/java/org/mustangproject/ZUGFeRD/ZUGFeRDImporter.java | 1 + 1 file changed, 1 insertion(+) diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDImporter.java b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDImporter.java index 5189bee6..6ff0a4b8 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDImporter.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDImporter.java @@ -659,6 +659,7 @@ public class ZUGFeRDImporter extends ZUGFeRDInvoiceImporter { * * @return a List of LineItem instances */ + @Deprecated public List getLineItemList() { final List nodeList = getLineItemNodes(); final List lineItemList = new ArrayList<>(); From 191e06ea48815db80e44864ae2ffdc66ada625d9 Mon Sep 17 00:00:00 2001 From: Adrian-Devries Date: Thu, 19 Dec 2024 18:51:02 +0100 Subject: [PATCH 2/4] Fix minor issues Add creation of additional test output --- .../ZUGFeRD/VisualizationTest.java | 602 +++++++++--------- 1 file changed, 313 insertions(+), 289 deletions(-) diff --git a/library/src/test/java/org/mustangproject/ZUGFeRD/VisualizationTest.java b/library/src/test/java/org/mustangproject/ZUGFeRD/VisualizationTest.java index a59199f4..3ab73e7d 100644 --- a/library/src/test/java/org/mustangproject/ZUGFeRD/VisualizationTest.java +++ b/library/src/test/java/org/mustangproject/ZUGFeRD/VisualizationTest.java @@ -1,289 +1,313 @@ -/** - * ********************************************************************* - *

- * 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 org.junit.FixMethodOrder; -import org.junit.runners.MethodSorters; -import org.mustangproject.util.ByteArraySearcher; -import org.xml.sax.SAXException; - -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.transform.TransformerException; -import java.io.File; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Paths; - -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class VisualizationTest extends ResourceCase { - - final String TARGET_PDF_CII = "./target/testout-Visualization-cii.pdf"; - final String TARGET_PDF_UBL = "./target/testout-Visualization-cii.pdf"; - - public void testCIIVisualizationBasic() { - - // the writing part - String sourceFilename = "factur-x.xml"; - File CIIinputFile = getResourceAsFile(sourceFilename); - - String expected = null; - String result = null; - try { - ZUGFeRDVisualizer zvi = new ZUGFeRDVisualizer(); - /* remove file endings so that tests can also pass after checking - out from git with arbitrary options (which may include CSRF changes) - */ - result = zvi.visualize(CIIinputFile.getAbsolutePath(), ZUGFeRDVisualizer.Language.FR) - .replace("\r", "") - .replace("\n", "") - .replace("\t", "") - .replace(" ", ""); - - File expectedResult = getResourceAsFile("factur-x-vis.fr.html"); - expected = new String(Files.readAllBytes(expectedResult.toPath()), StandardCharsets.UTF_8) - .replace("\r", "") - .replace("\n", "") - .replace("\t", "") - .replace(" ", ""); - // remove linebreaks as well... - - } catch (UnsupportedOperationException e) { - fail("UnsupportedOperationException should not happen: " + e.getMessage()); - } catch (IllegalArgumentException e) { - fail("IllegalArgumentException should not happen: " + e.getMessage()); - } catch (TransformerException e) { - fail("TransformerException should not happen: " + e.getMessage()); - } catch (IOException e) { - fail("IOException should not happen: " + e.getMessage()); - } catch (ParserConfigurationException e) { - fail("ParserConfigurationException should not happen: " + e.getMessage()); - } catch (SAXException e) { - fail("SAXException should not happen: " + e.getMessage()); - } - - - assertNotNull(result); - // Reading ZUGFeRD - assertEquals(expected, result); - } - - public void testCIIVisualizationExtended() { - - // the writing part - String sourceFilename = "factur-x-extended.xml"; - File CIIinputFile = getResourceAsFile(sourceFilename); - - String expected = null; - String result = null; - try { - ZUGFeRDVisualizer zvi = new ZUGFeRDVisualizer(); - /* remove file endings so that tests can also pass after checking - out from git with arbitrary options (which may include CSRF changes) - */ - result = zvi.visualize(CIIinputFile.getAbsolutePath(), ZUGFeRDVisualizer.Language.DE).replace("\r", "").replace("\n", "") - .replace("\t", "") - .replace(" ", ""); - - File expectedResult = getResourceAsFile("factur-x-vis-extended.de.html"); - expected = new String(Files.readAllBytes(expectedResult.toPath()), StandardCharsets.UTF_8).replace("\r", "").replace("\n", "") - .replace("\t", "") - .replace(" ", ""); - // remove linebreaks as well... - - } catch (UnsupportedOperationException e) { - fail("UnsupportedOperationException should not happen: " + e.getMessage()); - } catch (IllegalArgumentException e) { - fail("IllegalArgumentException should not happen: " + e.getMessage()); - } catch (TransformerException e) { - fail("TransformerException should not happen: " + e.getMessage()); - } catch (IOException e) { - fail("IOException should not happen: " + e.getMessage()); - } catch (ParserConfigurationException e) { - fail("ParserConfigurationException should not happen: " + e.getMessage()); - } catch (SAXException e) { - fail("SAXException should not happen: " + e.getMessage()); - } - - - assertNotNull(result); - // Reading ZUGFeRD - assertEquals(expected, result); - } - - public void testUBLCreditNoteVisualizationBasic() { - - // the writing part - File UBLinputFile = getResourceAsFile("ubl-creditnote.xml"); - - String expected = null; - String result = null; - try { - ZUGFeRDVisualizer zvi = new ZUGFeRDVisualizer(); - /* remove file endings so that tests can also pass after checking - out from git with arbitrary options (which may include CSRF changes) - */ - result = zvi.visualize(UBLinputFile.getAbsolutePath(), ZUGFeRDVisualizer.Language.EN).replace("\r", "").replace("\n", "").replace("\t", "").replace(" ", ""); - - File expectedResult = getResourceAsFile("factur-x-vis-ubl-creditnote.en.html"); - expected = new String(Files.readAllBytes(expectedResult.toPath()), StandardCharsets.UTF_8).replace("\r", "").replace("\n", "").replace("\t", "").replace(" ", ""); - // remove linebreaks as well... - - } catch (UnsupportedOperationException e) { - fail("UnsupportedOperationException should not happen: " + e.getMessage()); - } catch (IllegalArgumentException e) { - fail("IllegalArgumentException should not happen: " + e.getMessage()); - } catch (TransformerException e) { - fail("TransformerException should not happen: " + e.getMessage()); - } catch (IOException e) { - fail("IOException should not happen: " + e.getMessage()); - } catch (ParserConfigurationException e) { - fail("ParserConfigurationException should not happen: " + e.getMessage()); - } catch (SAXException e) { - fail("SAXException should not happen: " + e.getMessage()); - } - - - assertNotNull(result); - // Reading ZUGFeRD - assertEquals(expected, result); - } - - - public void testUBLVisualizationBasic() { - - // the writing part - File UBLinputFile = getResourceAsFile("ubl/01.01a-INVOICE.ubl.xml"); - - String expected = null; - String result = null; - try { - ZUGFeRDVisualizer zvi = new ZUGFeRDVisualizer(); - /* remove file endings so that tests can also pass after checking - out from git with arbitrary options (which may include CSRF changes) - */ - result = zvi.visualize(UBLinputFile.getAbsolutePath(), ZUGFeRDVisualizer.Language.EN).replace("\r", "").replace("\n", "") - .replace("\t", "") - .replace(" ", ""); - - File expectedResult = getResourceAsFile("factur-x-vis-ubl.en.html"); - expected = new String(Files.readAllBytes(expectedResult.toPath()), StandardCharsets.UTF_8).replace("\r", "").replace("\n", "") - .replace("\t", "") - .replace(" ", ""); - // remove linebreaks as well... - - } catch (UnsupportedOperationException e) { - fail("UnsupportedOperationException should not happen: " + e.getMessage()); - } catch (IllegalArgumentException e) { - fail("IllegalArgumentException should not happen: " + e.getMessage()); - } catch (TransformerException e) { - fail("TransformerException should not happen: " + e.getMessage()); - } catch (IOException e) { - fail("IOException should not happen: " + e.getMessage()); - } catch (ParserConfigurationException e) { - fail("ParserConfigurationException should not happen: " + e.getMessage()); - } catch (SAXException e) { - fail("SAXException should not happen: " + e.getMessage()); - } - - - assertNotNull(result); - // Reading ZUGFeRD - assertEquals(expected, result); - } - - public void testPDFVisualizationCII() { - - File CIIinputFile = getResourceAsFile("cii/01.01a-INVOICE.cii.xml"); - - // the writing part - - String expected = null; - String result = null; - try { - ZUGFeRDVisualizer zvi = new ZUGFeRDVisualizer(); - zvi.toPDF(CIIinputFile.getAbsolutePath(), TARGET_PDF_CII); - } catch (UnsupportedOperationException e) { - fail("UnsupportedOperationException should not happen: " + e.getMessage()); - } catch (IllegalArgumentException e) { - fail("IllegalArgumentException should not happen: " + e.getMessage()); - } - - try { - assertTrue(ByteArraySearcher.startsWith(Files.readAllBytes(Paths.get(TARGET_PDF_CII)), new byte[]{'%', 'P', 'D', 'F'})); - } catch (IOException e) { - fail("IOException should not occur"); - } - } - - public void testPDFVisualizationUBL() { - - File UBLinputFile = getResourceAsFile("ubl/01.01a-INVOICE.ubl.xml"); - - // the writing part - String sourceFilename = "factur-x.xml"; - - String expected = null; - String result = null; - try { - ZUGFeRDVisualizer zvi = new ZUGFeRDVisualizer(); - zvi.toPDF(UBLinputFile.getAbsolutePath(), TARGET_PDF_UBL); - } catch (UnsupportedOperationException e) { - fail("UnsupportedOperationException should not happen: " + e.getMessage()); - } catch (IllegalArgumentException e) { - fail("IllegalArgumentException should not happen: " + e.getMessage()); - } - - - try { - assertTrue(ByteArraySearcher.startsWith(Files.readAllBytes(Paths.get(TARGET_PDF_CII)), new byte[]{'%', 'P', 'D', 'F'})); - } catch (IOException e) { - fail("IOException should not occur"); - } - } - - public void testPDFVisualizationUBLCreditNote() { - - File UBLinputFile = getResourceAsFile("ubl/UBL-CreditNote-2.1-Example.ubl.xml"); - - // the writing part - String sourceFilename = "factur-x.xml"; - - String expected = null; - String result = null; - try { - ZUGFeRDVisualizer zvi = new ZUGFeRDVisualizer(); - zvi.toPDF(UBLinputFile.getAbsolutePath(), TARGET_PDF_UBL); - } catch (UnsupportedOperationException e) { - fail("UnsupportedOperationException should not happen: " + e.getMessage()); - } catch (IllegalArgumentException e) { - fail("IllegalArgumentException should not happen: " + e.getMessage()); - } - - - try { - assertTrue(ByteArraySearcher.startsWith(Files.readAllBytes(Paths.get(TARGET_PDF_CII)), new byte[]{'%', 'P', 'D', 'F'})); - } catch (IOException e) { - fail("IOException should not occur"); - } - } - -} +/** + * ********************************************************************* + *

+ * 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 org.junit.FixMethodOrder; +import org.junit.runners.MethodSorters; +import org.mustangproject.util.ByteArraySearcher; +import org.xml.sax.SAXException; + +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.TransformerException; +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class VisualizationTest extends ResourceCase { + + final String TARGET_PDF_CII = "./target/testout-Visualization-cii.pdf"; + final String TARGET_PDF_UBL = "./target/testout-Visualization-cii.pdf"; + + public void testCIIVisualizationBasic() { + + // the writing part + String sourceFilename = "factur-x.xml"; + File CIIinputFile = getResourceAsFile(sourceFilename); + + String expected = null; + String result = null; + try { + ZUGFeRDVisualizer zvi = new ZUGFeRDVisualizer(); + /* remove file endings so that tests can also pass after checking + out from git with arbitrary options (which may include CSRF changes) + */ + result = zvi.visualize(CIIinputFile.getAbsolutePath(), ZUGFeRDVisualizer.Language.FR); + Files.write(Paths.get("./target/testout-factur-x-vis.fr.html"), result.getBytes(StandardCharsets.UTF_8)); + result = result + .replace("\r", "") + .replace("\n", "") + .replace("\t", "") + .replace(" ", ""); + + File expectedResult = getResourceAsFile("factur-x-vis.fr.html"); + expected = new String(Files.readAllBytes(expectedResult.toPath()), StandardCharsets.UTF_8) + .replace("\r", "") + .replace("\n", "") + .replace("\t", "") + .replace(" ", ""); + // remove linebreaks as well... + + } catch (UnsupportedOperationException e) { + fail("UnsupportedOperationException should not happen: " + e.getMessage()); + } catch (IllegalArgumentException e) { + fail("IllegalArgumentException should not happen: " + e.getMessage()); + } catch (TransformerException e) { + fail("TransformerException should not happen: " + e.getMessage()); + } catch (IOException e) { + fail("IOException should not happen: " + e.getMessage()); + } catch (ParserConfigurationException e) { + fail("ParserConfigurationException should not happen: " + e.getMessage()); + } catch (SAXException e) { + fail("SAXException should not happen: " + e.getMessage()); + } + + + assertNotNull(result); + // Reading ZUGFeRD + assertEquals(expected, result); + } + + public void testCIIVisualizationExtended() { + + // the writing part + String sourceFilename = "factur-x-extended.xml"; + File CIIinputFile = getResourceAsFile(sourceFilename); + + String expected = null; + String result = null; + try { + ZUGFeRDVisualizer zvi = new ZUGFeRDVisualizer(); + /* remove file endings so that tests can also pass after checking + out from git with arbitrary options (which may include CSRF changes) + */ + result = zvi.visualize(CIIinputFile.getAbsolutePath(), ZUGFeRDVisualizer.Language.DE); + Files.write(Paths.get("./target/testout-factur-x-vis-extended.de.html"), result.getBytes(StandardCharsets.UTF_8)); + result = result + .replace("\r", "") + .replace("\n", "") + .replace("\t", "") + .replace(" ", ""); + + File expectedResult = getResourceAsFile("factur-x-vis-extended.de.html"); + expected = new String(Files.readAllBytes(expectedResult.toPath()), StandardCharsets.UTF_8) + .replace("\r", "") + .replace("\n", "") + .replace("\t", "") + .replace(" ", ""); + // remove linebreaks as well... + + } catch (UnsupportedOperationException e) { + fail("UnsupportedOperationException should not happen: " + e.getMessage()); + } catch (IllegalArgumentException e) { + fail("IllegalArgumentException should not happen: " + e.getMessage()); + } catch (TransformerException e) { + fail("TransformerException should not happen: " + e.getMessage()); + } catch (IOException e) { + fail("IOException should not happen: " + e.getMessage()); + } catch (ParserConfigurationException e) { + fail("ParserConfigurationException should not happen: " + e.getMessage()); + } catch (SAXException e) { + fail("SAXException should not happen: " + e.getMessage()); + } + + + assertNotNull(result); + // Reading ZUGFeRD + assertEquals(expected, result); + } + + public void testUBLCreditNoteVisualizationBasic() { + + // the writing part + File UBLinputFile = getResourceAsFile("ubl-creditnote.xml"); + + String expected = null; + String result = null; + try { + ZUGFeRDVisualizer zvi = new ZUGFeRDVisualizer(); + /* remove file endings so that tests can also pass after checking + out from git with arbitrary options (which may include CSRF changes) + */ + result = zvi.visualize(UBLinputFile.getAbsolutePath(), ZUGFeRDVisualizer.Language.EN); + Files.write(Paths.get("./target/testout-factur-x-vis-ubl-creditnote.en.html"), result.getBytes(StandardCharsets.UTF_8)); + result = result + .replace("\r", "") + .replace("\n", "") + .replace("\t", "") + .replace(" ", ""); + + File expectedResult = getResourceAsFile("factur-x-vis-ubl-creditnote.en.html"); + expected = new String(Files.readAllBytes(expectedResult.toPath()), StandardCharsets.UTF_8) + .replace("\r", "") + .replace("\n", "") + .replace("\t", "") + .replace(" ", ""); + // remove linebreaks as well... + + } catch (UnsupportedOperationException e) { + fail("UnsupportedOperationException should not happen: " + e.getMessage()); + } catch (IllegalArgumentException e) { + fail("IllegalArgumentException should not happen: " + e.getMessage()); + } catch (TransformerException e) { + fail("TransformerException should not happen: " + e.getMessage()); + } catch (IOException e) { + fail("IOException should not happen: " + e.getMessage()); + } catch (ParserConfigurationException e) { + fail("ParserConfigurationException should not happen: " + e.getMessage()); + } catch (SAXException e) { + fail("SAXException should not happen: " + e.getMessage()); + } + + + assertNotNull(result); + // Reading ZUGFeRD + assertEquals(expected, result); + } + + + public void testUBLVisualizationBasic() { + + // the writing part + File UBLinputFile = getResourceAsFile("ubl/01.01a-INVOICE.ubl.xml"); + + String expected = null; + String result = null; + try { + ZUGFeRDVisualizer zvi = new ZUGFeRDVisualizer(); + /* remove file endings so that tests can also pass after checking + out from git with arbitrary options (which may include CSRF changes) + */ + result = zvi.visualize(UBLinputFile.getAbsolutePath(), ZUGFeRDVisualizer.Language.EN); + Files.write(Paths.get("./target/testout-factur-x-vis-ubl.en.html"), result.getBytes(StandardCharsets.UTF_8)); + result = result + .replace("\r", "") + .replace("\n", "") + .replace("\t", "") + .replace(" ", ""); + + File expectedResult = getResourceAsFile("factur-x-vis-ubl.en.html"); + expected = new String(Files.readAllBytes(expectedResult.toPath()), StandardCharsets.UTF_8) + .replace("\r", "") + .replace("\n", "") + .replace("\t", "") + .replace(" ", ""); + // remove linebreaks as well... + + } catch (UnsupportedOperationException e) { + fail("UnsupportedOperationException should not happen: " + e.getMessage()); + } catch (IllegalArgumentException e) { + fail("IllegalArgumentException should not happen: " + e.getMessage()); + } catch (TransformerException e) { + fail("TransformerException should not happen: " + e.getMessage()); + } catch (IOException e) { + fail("IOException should not happen: " + e.getMessage()); + } catch (ParserConfigurationException e) { + fail("ParserConfigurationException should not happen: " + e.getMessage()); + } catch (SAXException e) { + fail("SAXException should not happen: " + e.getMessage()); + } + + + assertNotNull(result); + // Reading ZUGFeRD + assertEquals(expected, result); + } + + public void testPDFVisualizationCII() { + + File CIIinputFile = getResourceAsFile("cii/01.01a-INVOICE.cii.xml"); + + // the writing part + + String expected = null; + String result = null; + try { + ZUGFeRDVisualizer zvi = new ZUGFeRDVisualizer(); + zvi.toPDF(CIIinputFile.getAbsolutePath(), TARGET_PDF_CII); + } catch (UnsupportedOperationException e) { + fail("UnsupportedOperationException should not happen: " + e.getMessage()); + } catch (IllegalArgumentException e) { + fail("IllegalArgumentException should not happen: " + e.getMessage()); + } + + try { + assertTrue(ByteArraySearcher.startsWith(Files.readAllBytes(Paths.get(TARGET_PDF_CII)), new byte[]{'%', 'P', 'D', 'F'})); + } catch (IOException e) { + fail("IOException should not occur"); + } + } + + public void testPDFVisualizationUBL() { + + File UBLinputFile = getResourceAsFile("ubl/01.01a-INVOICE.ubl.xml"); + + // the writing part + String sourceFilename = "factur-x.xml"; + + String expected = null; + String result = null; + try { + ZUGFeRDVisualizer zvi = new ZUGFeRDVisualizer(); + zvi.toPDF(UBLinputFile.getAbsolutePath(), TARGET_PDF_UBL); + } catch (UnsupportedOperationException e) { + fail("UnsupportedOperationException should not happen: " + e.getMessage()); + } catch (IllegalArgumentException e) { + fail("IllegalArgumentException should not happen: " + e.getMessage()); + } + + + try { + assertTrue(ByteArraySearcher.startsWith(Files.readAllBytes(Paths.get(TARGET_PDF_CII)), new byte[]{'%', 'P', 'D', 'F'})); + } catch (IOException e) { + fail("IOException should not occur"); + } + } + + public void testPDFVisualizationUBLCreditNote() { + + File UBLinputFile = getResourceAsFile("ubl/UBL-CreditNote-2.1-Example.ubl.xml"); + + // the writing part + String sourceFilename = "factur-x.xml"; + + String expected = null; + String result = null; + try { + ZUGFeRDVisualizer zvi = new ZUGFeRDVisualizer(); + zvi.toPDF(UBLinputFile.getAbsolutePath(), TARGET_PDF_UBL); + } catch (UnsupportedOperationException e) { + fail("UnsupportedOperationException should not happen: " + e.getMessage()); + } catch (IllegalArgumentException e) { + fail("IllegalArgumentException should not happen: " + e.getMessage()); + } + + + try { + assertTrue(ByteArraySearcher.startsWith(Files.readAllBytes(Paths.get(TARGET_PDF_CII)), new byte[]{'%', 'P', 'D', 'F'})); + } catch (IOException e) { + fail("IOException should not occur"); + } + } + +} From b8d283cef25a7dee7b40f853b5f322e2b13573fb Mon Sep 17 00:00:00 2001 From: Adrian-Devries Date: Thu, 19 Dec 2024 18:53:24 +0100 Subject: [PATCH 3/4] Update ZUGFeRDInvoiceImporter.java Add attribute @Deprecated to method getFileAttachmentsXML --- .../java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java | 1 + 1 file changed, 1 insertion(+) diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java index da10d8dd..ceda9530 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java @@ -1036,6 +1036,7 @@ public class ZUGFeRDInvoiceImporter { * for PDF embedded files in FX use getFileAttachmentsPDF() * @deprecated use invoice.getAdditionalReferencedDocuments */ + @Deprecated public List getFileAttachmentsXML() { return new ArrayList<>(Arrays.asList(importedInvoice.getAdditionalReferencedDocuments())); } From 07758fc26d3a5c4257d8f27a7d39b3b1abe615c7 Mon Sep 17 00:00:00 2001 From: Adrian-Devries Date: Thu, 19 Dec 2024 19:21:28 +0100 Subject: [PATCH 4/4] Fix local path issue Replace local absolute path by resource --- .../mustangproject/ZUGFeRD/ZF2PushTest.java | 1654 +++++++++-------- 1 file changed, 828 insertions(+), 826 deletions(-) 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("")); // maybe add a direct debit mandate to the class in the future then this would fail - assertTrue(zi.getUTF8().contains("Hinterhaus")); - assertThat(zi.getUTF8()).valueByXPath("//*[local-name()='BuyerTradeParty']/*[local-name()='GlobalID'][@schemeID=0088]").asString().isEqualTo("4304171000002"); - assertThat(zi.getUTF8()).valueByXPath("//*[local-name()='SpecifiedTradeProduct']/*[local-name()='GlobalID'][@schemeID=0160]").asString().isEqualTo("2001015001325"); - assertTrue(zi.getUTF8().contains("2001015001325")); - assertTrue(zi.getUTF8().contains("4304171000002")); - assertTrue(zi.getUTF8().contains("0088")); - assertTrue(zi.getUTF8().contains(orgID)); - assertTrue(zi.getUTF8().contains("ram:BuyerOrderReferencedDocument")); - assertTrue(zi.getUTF8().contains(occurrenceFrom)); - assertTrue(zi.getUTF8().contains(occurrenceTo)); - assertTrue(zi.getUTF8().contains(contractID)); - assertEquals(zi.importedInvoice.getZFItems()[0].getId(), "a123"); - assertTrue(zi.getUTF8().contains("20200113")); // to contain item delivery periods - assertTrue(zi.getUTF8().contains("20200115")); // to contain item delivery periods - - assertTrue(zi.getUTF8().contains("item level 1/1")); - assertTrue(zi.getUTF8().contains("DE4711")); // the VAT ID should be there... - assertFalse(zi.getUTF8().contains("DE47110")); // but not the VAT ID of the shiptotradeparty - assertTrue(zi.getUTF8().contains("document level 2/2")); - assertTrue(zi.getUTF8().contains("++49555123456")); - assertTrue(zi.getUTF8().contains("Cash Discount")); // default description for cash discounts - assertThat(zi.getUTF8()).valueByXPath("//*[local-name()='ApplicableTradeTax']/*[local-name()='DueDateTypeCode']").asString().isEqualTo(EventTimeCodeTypeConstants.PAYMENT_DATE); - - ZUGFeRDInvoiceImporter zii = new ZUGFeRDInvoiceImporter(TARGET_PUSHEDGE); - try { - Invoice i = zii.extractInvoice(); - - assertEquals("abc123", i.getInvoiceReferencedDocumentID()); - assertEquals("4304171000002", i.getRecipient().getGlobalID()); - assertEquals("2001015001325", i.getZFItems()[0].getProduct().getGlobalID()); - assertEquals(orgID, i.getSender().getID()); - - } catch (XPathExpressionException e) { - fail("XPathExpressionException should not be raised"); - } catch (ParseException e) { - fail("ParseException should not be raised"); - /* a parseException would also be fired if the calculated grand total does not - match the read grand total */ - } - } - - public void testAllowancesExport() { - - String orgname = "Test company"; - String number = "123"; - BigDecimal qty = new BigDecimal("20"); - try { - InputStream SOURCE_PDF = this.getClass().getResourceAsStream("/MustangGnuaccountingBeispielRE-20170509_505blanko.pdf"); - - ZUGFeRDExporterFromA1 ze = new ZUGFeRDExporterFromA1(); - ze.ignorePDFAErrors().load(SOURCE_PDF); - - ze.setProducer("My Application").setCreator(System.getProperty("user.name")).setZUGFeRDVersion(2).setProfile(Profiles.getByName("en16931")); - - ze.setTransaction(new Invoice().setDueDate(new Date()).setIssueDate(new Date()).setDeliveryDate(new Date()) - .setSender(new TradeParty(orgname, "teststr", "55232", "teststadt", "DE").addTaxID("4711").addVATID("DE0815")) - .setRecipient(new TradeParty("Franz Müller", "teststr.12", "55232", "Entenhausen", "DE")) - .setNumber(number) - .addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(19)), new BigDecimal(500.0), qty).addAllowance(new Allowance(new BigDecimal(300)).setTaxPercent(new BigDecimal(19)))) - .addAllowance(new Allowance(new BigDecimal(600)).setTaxPercent(new BigDecimal(19))) - ); - String theXML = new String(ze.getProvider().getXML()); - assertTrue(theXML.contains(" + * 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("")); // maybe add a direct debit mandate to the class in the future then this would fail + assertTrue(zi.getUTF8().contains("Hinterhaus")); + assertThat(zi.getUTF8()).valueByXPath("//*[local-name()='BuyerTradeParty']/*[local-name()='GlobalID'][@schemeID=0088]").asString().isEqualTo("4304171000002"); + assertThat(zi.getUTF8()).valueByXPath("//*[local-name()='SpecifiedTradeProduct']/*[local-name()='GlobalID'][@schemeID=0160]").asString().isEqualTo("2001015001325"); + assertTrue(zi.getUTF8().contains("2001015001325")); + assertTrue(zi.getUTF8().contains("4304171000002")); + assertTrue(zi.getUTF8().contains("0088")); + assertTrue(zi.getUTF8().contains(orgID)); + assertTrue(zi.getUTF8().contains("ram:BuyerOrderReferencedDocument")); + assertTrue(zi.getUTF8().contains(occurrenceFrom)); + assertTrue(zi.getUTF8().contains(occurrenceTo)); + assertTrue(zi.getUTF8().contains(contractID)); + assertEquals(zi.importedInvoice.getZFItems()[0].getId(), "a123"); + assertTrue(zi.getUTF8().contains("20200113")); // to contain item delivery periods + assertTrue(zi.getUTF8().contains("20200115")); // to contain item delivery periods + + assertTrue(zi.getUTF8().contains("item level 1/1")); + assertTrue(zi.getUTF8().contains("DE4711")); // the VAT ID should be there... + assertFalse(zi.getUTF8().contains("DE47110")); // but not the VAT ID of the shiptotradeparty + assertTrue(zi.getUTF8().contains("document level 2/2")); + assertTrue(zi.getUTF8().contains("++49555123456")); + assertTrue(zi.getUTF8().contains("Cash Discount")); // default description for cash discounts + assertThat(zi.getUTF8()).valueByXPath("//*[local-name()='ApplicableTradeTax']/*[local-name()='DueDateTypeCode']").asString().isEqualTo(EventTimeCodeTypeConstants.PAYMENT_DATE); + + ZUGFeRDInvoiceImporter zii = new ZUGFeRDInvoiceImporter(TARGET_PUSHEDGE); + try { + Invoice i = zii.extractInvoice(); + + assertEquals("abc123", i.getInvoiceReferencedDocumentID()); + assertEquals("4304171000002", i.getRecipient().getGlobalID()); + assertEquals("2001015001325", i.getZFItems()[0].getProduct().getGlobalID()); + assertEquals(orgID, i.getSender().getID()); + + } catch (XPathExpressionException e) { + fail("XPathExpressionException should not be raised"); + } catch (ParseException e) { + fail("ParseException should not be raised"); + /* a parseException would also be fired if the calculated grand total does not + match the read grand total */ + } + } + + public void testAllowancesExport() { + + String orgname = "Test company"; + String number = "123"; + BigDecimal qty = new BigDecimal("20"); + try { + InputStream SOURCE_PDF = this.getClass().getResourceAsStream("/MustangGnuaccountingBeispielRE-20170509_505blanko.pdf"); + + ZUGFeRDExporterFromA1 ze = new ZUGFeRDExporterFromA1(); + ze.ignorePDFAErrors().load(SOURCE_PDF); + + ze.setProducer("My Application").setCreator(System.getProperty("user.name")).setZUGFeRDVersion(2).setProfile(Profiles.getByName("en16931")); + + ze.setTransaction(new Invoice().setDueDate(new Date()).setIssueDate(new Date()).setDeliveryDate(new Date()) + .setSender(new TradeParty(orgname, "teststr", "55232", "teststadt", "DE").addTaxID("4711").addVATID("DE0815")) + .setRecipient(new TradeParty("Franz Müller", "teststr.12", "55232", "Entenhausen", "DE")) + .setNumber(number) + .addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(19)), new BigDecimal(500.0), qty).addAllowance(new Allowance(new BigDecimal(300)).setTaxPercent(new BigDecimal(19)))) + .addAllowance(new Allowance(new BigDecimal(600)).setTaxPercent(new BigDecimal(19))) + ); + String theXML = new String(ze.getProvider().getXML()); + assertTrue(theXML.contains("