* 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.apache.commons.io.IOUtils; 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.*; -import java.io.*; +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; @@ -51,31 +52,83 @@ public class VisualizationTest extends ResourceCase { /* 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",""); + 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",""); + 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()); + fail("UnsupportedOperationException should not happen: " + e.getMessage()); } catch (IllegalArgumentException e) { - fail("IllegalArgumentException should not happen: "+e.getMessage()); + fail("IllegalArgumentException should not happen: " + e.getMessage()); } catch (TransformerException e) { - fail("TransformerException should not happen: "+e.getMessage()); + fail("TransformerException should not happen: " + e.getMessage()); } catch (IOException e) { - fail("IOException should not happen: "+e.getMessage()); + 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()); - } + fail("ParserConfigurationException should not happen: " + e.getMessage()); + } catch (SAXException e) { + fail("SAXException should not happen: " + e.getMessage()); + } - assertNotNull(result); + 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 @@ -88,31 +141,33 @@ public class VisualizationTest extends ResourceCase { /* 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(" ","").replace("\t",""); + 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(" ","").replace("\t",""); + 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()); + fail("UnsupportedOperationException should not happen: " + e.getMessage()); } catch (IllegalArgumentException e) { - fail("IllegalArgumentException should not happen: "+e.getMessage()); + fail("IllegalArgumentException should not happen: " + e.getMessage()); } catch (TransformerException e) { - fail("TransformerException should not happen: "+e.getMessage()); + fail("TransformerException should not happen: " + e.getMessage()); } catch (IOException e) { - fail("IOException should not happen: "+e.getMessage()); + 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()); + fail("ParserConfigurationException should not happen: " + e.getMessage()); + } catch (SAXException e) { + fail("SAXException should not happen: " + e.getMessage()); } - assertNotNull(result); + assertNotNull(result); // Reading ZUGFeRD assertEquals(expected, result); } + + public void testUBLVisualizationBasic() { // the writing part @@ -125,28 +180,32 @@ public class VisualizationTest extends ResourceCase { /* 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",""); + 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",""); + 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()); + fail("UnsupportedOperationException should not happen: " + e.getMessage()); } catch (IllegalArgumentException e) { - fail("IllegalArgumentException should not happen: "+e.getMessage()); + fail("IllegalArgumentException should not happen: " + e.getMessage()); } catch (TransformerException e) { - fail("TransformerException should not happen: "+e.getMessage()); + fail("TransformerException should not happen: " + e.getMessage()); } catch (IOException e) { - fail("IOException should not happen: "+e.getMessage()); + 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()); - } + fail("ParserConfigurationException should not happen: " + e.getMessage()); + } catch (SAXException e) { + fail("SAXException should not happen: " + e.getMessage()); + } - assertNotNull(result); + assertNotNull(result); // Reading ZUGFeRD assertEquals(expected, result); } @@ -163,9 +222,9 @@ public class VisualizationTest extends ResourceCase { ZUGFeRDVisualizer zvi = new ZUGFeRDVisualizer(); zvi.toPDF(CIIinputFile.getAbsolutePath(), TARGET_PDF_CII); } catch (UnsupportedOperationException e) { - fail("UnsupportedOperationException should not happen: "+e.getMessage()); + fail("UnsupportedOperationException should not happen: " + e.getMessage()); } catch (IllegalArgumentException e) { - fail("IllegalArgumentException should not happen: "+e.getMessage()); + fail("IllegalArgumentException should not happen: " + e.getMessage()); } try { @@ -188,9 +247,9 @@ public class VisualizationTest extends ResourceCase { ZUGFeRDVisualizer zvi = new ZUGFeRDVisualizer(); zvi.toPDF(UBLinputFile.getAbsolutePath(), TARGET_PDF_UBL); } catch (UnsupportedOperationException e) { - fail("UnsupportedOperationException should not happen: "+e.getMessage()); + fail("UnsupportedOperationException should not happen: " + e.getMessage()); } catch (IllegalArgumentException e) { - fail("IllegalArgumentException should not happen: "+e.getMessage()); + fail("IllegalArgumentException should not happen: " + e.getMessage()); } @@ -214,9 +273,9 @@ public class VisualizationTest extends ResourceCase { ZUGFeRDVisualizer zvi = new ZUGFeRDVisualizer(); zvi.toPDF(UBLinputFile.getAbsolutePath(), TARGET_PDF_UBL); } catch (UnsupportedOperationException e) { - fail("UnsupportedOperationException should not happen: "+e.getMessage()); + fail("UnsupportedOperationException should not happen: " + e.getMessage()); } catch (IllegalArgumentException e) { - fail("IllegalArgumentException should not happen: "+e.getMessage()); + fail("IllegalArgumentException should not happen: " + e.getMessage()); } diff --git a/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java b/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java index c5c9bcdb..894fcab8 100644 --- a/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java +++ b/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java @@ -1,4 +1,3 @@ - /** * ********************************************************************* *
@@ -27,7 +26,9 @@ import org.junit.jupiter.api.Test;
import org.mustangproject.*;
import javax.xml.xpath.XPathExpressionException;
-import java.io.*;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
@@ -293,9 +294,9 @@ public class ZF2ZInvoiceImporterTest extends ResourceCase {
assertFalse(hasExceptions);
TransactionCalculator tc = new TransactionCalculator(invoice);
assertEquals(new BigDecimal("1.00"), tc.getGrandTotal());
- assertTrue(invoice.getTradeSettlement().length==1);
+ assertTrue(invoice.getTradeSettlement().length == 1);
assertTrue(invoice.getTradeSettlement()[0] instanceof IZUGFeRDTradeSettlementPayment);
- IZUGFeRDTradeSettlementPayment paym=(IZUGFeRDTradeSettlementPayment)invoice.getTradeSettlement()[0];
+ IZUGFeRDTradeSettlementPayment paym = (IZUGFeRDTradeSettlementPayment) invoice.getTradeSettlement()[0];
assertEquals("DE12500105170648489890", paym.getOwnIBAN());
assertEquals("COBADEFXXX", paym.getOwnBIC());
@@ -306,19 +307,19 @@ public class ZF2ZInvoiceImporterTest extends ResourceCase {
/**
* testing if other files embedded in pdf additionally to the invoice can be read correctly
- * */
+ */
public void testDetach() {
boolean hasExceptions = false;
- byte[] fileA=null;
- byte[] fileB=null;
+ byte[] fileA = null;
+ byte[] fileB = null;
ZUGFeRDInvoiceImporter zii = new ZUGFeRDInvoiceImporter("./target/testout-ZF2PushAttachments.pdf");
- for (FileAttachment fa:zii.getFileAttachmentsPDF()) {
+ for (FileAttachment fa : zii.getFileAttachmentsPDF()) {
if (fa.getFilename().equals("one.pdf")) {
- fileA=fa.getData();
+ fileA = fa.getData();
} else if (fa.getFilename().equals("two.pdf")) {
- fileB=fa.getData();
+ fileB = fa.getData();
}
}
byte[] b = {12, 13}; // the sample data that was used to write the files
@@ -330,19 +331,18 @@ public class ZF2ZInvoiceImporterTest extends ResourceCase {
}
-
public void testImportDebit() {
File CIIinputFile = getResourceAsFile("cii/minimalDebit.xml");
try {
ZUGFeRDInvoiceImporter zii = new ZUGFeRDInvoiceImporter(new FileInputStream(CIIinputFile));
- Invoice i=zii.extractInvoice();
+ Invoice i = zii.extractInvoice();
assertEquals("DE21860000000086001055", i.getSender().getBankDetails().get(0).getIBAN());
ObjectMapper mapper = new ObjectMapper();
String jsonArray = mapper.writeValueAsString(i);
- // assertEquals("",jsonArray);
+ // assertEquals("",jsonArray);
} catch (IOException e) {
fail("IOException not expected");
@@ -354,14 +354,14 @@ public class ZF2ZInvoiceImporterTest extends ResourceCase {
}
-
- public void testImportMinimum() {
+
+ public void testImportMinimum() {
File CIIinputFile = getResourceAsFile("cii/facturFrMinimum.xml");
try {
ZUGFeRDInvoiceImporter zii = new ZUGFeRDInvoiceImporter(new FileInputStream(CIIinputFile));
- CalculatedInvoice i=new CalculatedInvoice();
+ CalculatedInvoice i = new CalculatedInvoice();
zii.extractInto(i);
assertEquals("671.15", i.getGrandTotal().toString());
diff --git a/library/src/test/resources/factur-x-extended.xml b/library/src/test/resources/factur-x-extended.xml
new file mode 100644
index 00000000..cfb77358
--- /dev/null
+++ b/library/src/test/resources/factur-x-extended.xml
@@ -0,0 +1,427 @@
+
+
+
+
+
+
+