Merge pull request #626 from Adrian-Devries/fix-minor-java-issues

Fix minor java issues
This commit is contained in:
Jochen Staerk
2024-12-20 08:51:43 +01:00
committed by GitHub
4 changed files with 1143 additions and 1115 deletions

View File

@@ -659,6 +659,7 @@ public class ZUGFeRDImporter extends ZUGFeRDInvoiceImporter {
* *
* @return a List of LineItem instances * @return a List of LineItem instances
*/ */
@Deprecated
public List<Item> getLineItemList() { public List<Item> getLineItemList() {
final List<Node> nodeList = getLineItemNodes(); final List<Node> nodeList = getLineItemNodes();
final List<Item> lineItemList = new ArrayList<>(); final List<Item> lineItemList = new ArrayList<>();

View File

@@ -1036,6 +1036,7 @@ public class ZUGFeRDInvoiceImporter {
* for PDF embedded files in FX use getFileAttachmentsPDF() * for PDF embedded files in FX use getFileAttachmentsPDF()
* @deprecated use invoice.getAdditionalReferencedDocuments * @deprecated use invoice.getAdditionalReferencedDocuments
*/ */
@Deprecated
public List<FileAttachment> getFileAttachmentsXML() { public List<FileAttachment> getFileAttachmentsXML() {
return new ArrayList<>(Arrays.asList(importedInvoice.getAdditionalReferencedDocuments())); return new ArrayList<>(Arrays.asList(importedInvoice.getAdditionalReferencedDocuments()));
} }

View File

@@ -1,289 +1,313 @@
/** /**
* ********************************************************************* * *********************************************************************
* <p> * <p>
* Copyright 2019 Jochen Staerk * Copyright 2019 Jochen Staerk
* <p> * <p>
* Use is subject to license terms. * Use is subject to license terms.
* <p> * <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not * 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 * 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. * of the License at http://www.apache.org/licenses/LICENSE-2.0.
* <p> * <p>
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* <p> * <p>
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
* <p> * <p>
* ********************************************************************** * **********************************************************************
*/ */
package org.mustangproject.ZUGFeRD; package org.mustangproject.ZUGFeRD;
import org.junit.FixMethodOrder; import org.junit.FixMethodOrder;
import org.junit.runners.MethodSorters; import org.junit.runners.MethodSorters;
import org.mustangproject.util.ByteArraySearcher; import org.mustangproject.util.ByteArraySearcher;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerException;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class VisualizationTest extends ResourceCase { public class VisualizationTest extends ResourceCase {
final String TARGET_PDF_CII = "./target/testout-Visualization-cii.pdf"; final String TARGET_PDF_CII = "./target/testout-Visualization-cii.pdf";
final String TARGET_PDF_UBL = "./target/testout-Visualization-cii.pdf"; final String TARGET_PDF_UBL = "./target/testout-Visualization-cii.pdf";
public void testCIIVisualizationBasic() { public void testCIIVisualizationBasic() {
// the writing part // the writing part
String sourceFilename = "factur-x.xml"; String sourceFilename = "factur-x.xml";
File CIIinputFile = getResourceAsFile(sourceFilename); File CIIinputFile = getResourceAsFile(sourceFilename);
String expected = null; String expected = null;
String result = null; String result = null;
try { try {
ZUGFeRDVisualizer zvi = new ZUGFeRDVisualizer(); ZUGFeRDVisualizer zvi = new ZUGFeRDVisualizer();
/* remove file endings so that tests can also pass after checking /* remove file endings so that tests can also pass after checking
out from git with arbitrary options (which may include CSRF changes) out from git with arbitrary options (which may include CSRF changes)
*/ */
result = zvi.visualize(CIIinputFile.getAbsolutePath(), ZUGFeRDVisualizer.Language.FR) result = zvi.visualize(CIIinputFile.getAbsolutePath(), ZUGFeRDVisualizer.Language.FR);
.replace("\r", "") Files.write(Paths.get("./target/testout-factur-x-vis.fr.html"), result.getBytes(StandardCharsets.UTF_8));
.replace("\n", "") result = result
.replace("\t", "") .replace("\r", "")
.replace(" ", ""); .replace("\n", "")
.replace("\t", "")
File expectedResult = getResourceAsFile("factur-x-vis.fr.html"); .replace(" ", "");
expected = new String(Files.readAllBytes(expectedResult.toPath()), StandardCharsets.UTF_8)
.replace("\r", "") File expectedResult = getResourceAsFile("factur-x-vis.fr.html");
.replace("\n", "") expected = new String(Files.readAllBytes(expectedResult.toPath()), StandardCharsets.UTF_8)
.replace("\t", "") .replace("\r", "")
.replace(" ", ""); .replace("\n", "")
// remove linebreaks as well... .replace("\t", "")
.replace(" ", "");
} catch (UnsupportedOperationException e) { // remove linebreaks as well...
fail("UnsupportedOperationException should not happen: " + e.getMessage());
} catch (IllegalArgumentException e) { } catch (UnsupportedOperationException e) {
fail("IllegalArgumentException should not happen: " + e.getMessage()); fail("UnsupportedOperationException should not happen: " + e.getMessage());
} catch (TransformerException e) { } catch (IllegalArgumentException e) {
fail("TransformerException should not happen: " + e.getMessage()); fail("IllegalArgumentException should not happen: " + e.getMessage());
} catch (IOException e) { } catch (TransformerException e) {
fail("IOException should not happen: " + e.getMessage()); fail("TransformerException should not happen: " + e.getMessage());
} catch (ParserConfigurationException e) { } catch (IOException e) {
fail("ParserConfigurationException should not happen: " + e.getMessage()); fail("IOException should not happen: " + e.getMessage());
} catch (SAXException e) { } catch (ParserConfigurationException 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);
// Reading ZUGFeRD
assertEquals(expected, result); assertNotNull(result);
} // Reading ZUGFeRD
assertEquals(expected, result);
public void testCIIVisualizationExtended() { }
// the writing part public void testCIIVisualizationExtended() {
String sourceFilename = "factur-x-extended.xml";
File CIIinputFile = getResourceAsFile(sourceFilename); // the writing part
String sourceFilename = "factur-x-extended.xml";
String expected = null; File CIIinputFile = getResourceAsFile(sourceFilename);
String result = null;
try { String expected = null;
ZUGFeRDVisualizer zvi = new ZUGFeRDVisualizer(); String result = null;
/* remove file endings so that tests can also pass after checking try {
out from git with arbitrary options (which may include CSRF changes) ZUGFeRDVisualizer zvi = new ZUGFeRDVisualizer();
*/ /* remove file endings so that tests can also pass after checking
result = zvi.visualize(CIIinputFile.getAbsolutePath(), ZUGFeRDVisualizer.Language.DE).replace("\r", "").replace("\n", "") out from git with arbitrary options (which may include CSRF changes)
.replace("\t", "") */
.replace(" ", ""); 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));
File expectedResult = getResourceAsFile("factur-x-vis-extended.de.html"); result = result
expected = new String(Files.readAllBytes(expectedResult.toPath()), StandardCharsets.UTF_8).replace("\r", "").replace("\n", "") .replace("\r", "")
.replace("\t", "") .replace("\n", "")
.replace(" ", ""); .replace("\t", "")
// remove linebreaks as well... .replace(" ", "");
} catch (UnsupportedOperationException e) { File expectedResult = getResourceAsFile("factur-x-vis-extended.de.html");
fail("UnsupportedOperationException should not happen: " + e.getMessage()); expected = new String(Files.readAllBytes(expectedResult.toPath()), StandardCharsets.UTF_8)
} catch (IllegalArgumentException e) { .replace("\r", "")
fail("IllegalArgumentException should not happen: " + e.getMessage()); .replace("\n", "")
} catch (TransformerException e) { .replace("\t", "")
fail("TransformerException should not happen: " + e.getMessage()); .replace(" ", "");
} catch (IOException e) { // remove linebreaks as well...
fail("IOException should not happen: " + e.getMessage());
} catch (ParserConfigurationException e) { } catch (UnsupportedOperationException e) {
fail("ParserConfigurationException should not happen: " + e.getMessage()); fail("UnsupportedOperationException should not happen: " + e.getMessage());
} catch (SAXException e) { } catch (IllegalArgumentException e) {
fail("SAXException should not happen: " + e.getMessage()); fail("IllegalArgumentException should not happen: " + e.getMessage());
} } catch (TransformerException e) {
fail("TransformerException should not happen: " + e.getMessage());
} catch (IOException e) {
assertNotNull(result); fail("IOException should not happen: " + e.getMessage());
// Reading ZUGFeRD } catch (ParserConfigurationException e) {
assertEquals(expected, result); fail("ParserConfigurationException should not happen: " + e.getMessage());
} } catch (SAXException e) {
fail("SAXException should not happen: " + e.getMessage());
public void testUBLCreditNoteVisualizationBasic() { }
// the writing part
File UBLinputFile = getResourceAsFile("ubl-creditnote.xml"); assertNotNull(result);
// Reading ZUGFeRD
String expected = null; assertEquals(expected, result);
String result = null; }
try {
ZUGFeRDVisualizer zvi = new ZUGFeRDVisualizer(); public void testUBLCreditNoteVisualizationBasic() {
/* remove file endings so that tests can also pass after checking
out from git with arbitrary options (which may include CSRF changes) // the writing part
*/ File UBLinputFile = getResourceAsFile("ubl-creditnote.xml");
result = zvi.visualize(UBLinputFile.getAbsolutePath(), ZUGFeRDVisualizer.Language.EN).replace("\r", "").replace("\n", "").replace("\t", "").replace(" ", "");
String expected = null;
File expectedResult = getResourceAsFile("factur-x-vis-ubl-creditnote.en.html"); String result = null;
expected = new String(Files.readAllBytes(expectedResult.toPath()), StandardCharsets.UTF_8).replace("\r", "").replace("\n", "").replace("\t", "").replace(" ", ""); try {
// remove linebreaks as well... ZUGFeRDVisualizer zvi = new ZUGFeRDVisualizer();
/* remove file endings so that tests can also pass after checking
} catch (UnsupportedOperationException e) { out from git with arbitrary options (which may include CSRF changes)
fail("UnsupportedOperationException should not happen: " + e.getMessage()); */
} catch (IllegalArgumentException e) { result = zvi.visualize(UBLinputFile.getAbsolutePath(), ZUGFeRDVisualizer.Language.EN);
fail("IllegalArgumentException should not happen: " + e.getMessage()); Files.write(Paths.get("./target/testout-factur-x-vis-ubl-creditnote.en.html"), result.getBytes(StandardCharsets.UTF_8));
} catch (TransformerException e) { result = result
fail("TransformerException should not happen: " + e.getMessage()); .replace("\r", "")
} catch (IOException e) { .replace("\n", "")
fail("IOException should not happen: " + e.getMessage()); .replace("\t", "")
} catch (ParserConfigurationException e) { .replace(" ", "");
fail("ParserConfigurationException should not happen: " + e.getMessage());
} catch (SAXException e) { File expectedResult = getResourceAsFile("factur-x-vis-ubl-creditnote.en.html");
fail("SAXException should not happen: " + e.getMessage()); expected = new String(Files.readAllBytes(expectedResult.toPath()), StandardCharsets.UTF_8)
} .replace("\r", "")
.replace("\n", "")
.replace("\t", "")
assertNotNull(result); .replace(" ", "");
// Reading ZUGFeRD // remove linebreaks as well...
assertEquals(expected, result);
} } catch (UnsupportedOperationException e) {
fail("UnsupportedOperationException should not happen: " + e.getMessage());
} catch (IllegalArgumentException e) {
public void testUBLVisualizationBasic() { fail("IllegalArgumentException should not happen: " + e.getMessage());
} catch (TransformerException e) {
// the writing part fail("TransformerException should not happen: " + e.getMessage());
File UBLinputFile = getResourceAsFile("ubl/01.01a-INVOICE.ubl.xml"); } catch (IOException e) {
fail("IOException should not happen: " + e.getMessage());
String expected = null; } catch (ParserConfigurationException e) {
String result = null; fail("ParserConfigurationException should not happen: " + e.getMessage());
try { } catch (SAXException e) {
ZUGFeRDVisualizer zvi = new ZUGFeRDVisualizer(); fail("SAXException should not happen: " + e.getMessage());
/* 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", "") assertNotNull(result);
.replace("\t", "") // Reading ZUGFeRD
.replace(" ", ""); assertEquals(expected, result);
}
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", "") public void testUBLVisualizationBasic() {
.replace(" ", "");
// remove linebreaks as well... // the writing part
File UBLinputFile = getResourceAsFile("ubl/01.01a-INVOICE.ubl.xml");
} catch (UnsupportedOperationException e) {
fail("UnsupportedOperationException should not happen: " + e.getMessage()); String expected = null;
} catch (IllegalArgumentException e) { String result = null;
fail("IllegalArgumentException should not happen: " + e.getMessage()); try {
} catch (TransformerException e) { ZUGFeRDVisualizer zvi = new ZUGFeRDVisualizer();
fail("TransformerException should not happen: " + e.getMessage()); /* remove file endings so that tests can also pass after checking
} catch (IOException e) { out from git with arbitrary options (which may include CSRF changes)
fail("IOException should not happen: " + e.getMessage()); */
} catch (ParserConfigurationException e) { result = zvi.visualize(UBLinputFile.getAbsolutePath(), ZUGFeRDVisualizer.Language.EN);
fail("ParserConfigurationException should not happen: " + e.getMessage()); Files.write(Paths.get("./target/testout-factur-x-vis-ubl.en.html"), result.getBytes(StandardCharsets.UTF_8));
} catch (SAXException e) { result = result
fail("SAXException should not happen: " + e.getMessage()); .replace("\r", "")
} .replace("\n", "")
.replace("\t", "")
.replace(" ", "");
assertNotNull(result);
// Reading ZUGFeRD File expectedResult = getResourceAsFile("factur-x-vis-ubl.en.html");
assertEquals(expected, result); expected = new String(Files.readAllBytes(expectedResult.toPath()), StandardCharsets.UTF_8)
} .replace("\r", "")
.replace("\n", "")
public void testPDFVisualizationCII() { .replace("\t", "")
.replace(" ", "");
File CIIinputFile = getResourceAsFile("cii/01.01a-INVOICE.cii.xml"); // remove linebreaks as well...
// the writing part } catch (UnsupportedOperationException e) {
fail("UnsupportedOperationException should not happen: " + e.getMessage());
String expected = null; } catch (IllegalArgumentException e) {
String result = null; fail("IllegalArgumentException should not happen: " + e.getMessage());
try { } catch (TransformerException e) {
ZUGFeRDVisualizer zvi = new ZUGFeRDVisualizer(); fail("TransformerException should not happen: " + e.getMessage());
zvi.toPDF(CIIinputFile.getAbsolutePath(), TARGET_PDF_CII); } catch (IOException e) {
} catch (UnsupportedOperationException e) { fail("IOException should not happen: " + e.getMessage());
fail("UnsupportedOperationException should not happen: " + e.getMessage()); } catch (ParserConfigurationException e) {
} catch (IllegalArgumentException e) { fail("ParserConfigurationException should not happen: " + e.getMessage());
fail("IllegalArgumentException should not happen: " + e.getMessage()); } catch (SAXException e) {
} fail("SAXException should not happen: " + e.getMessage());
}
try {
assertTrue(ByteArraySearcher.startsWith(Files.readAllBytes(Paths.get(TARGET_PDF_CII)), new byte[]{'%', 'P', 'D', 'F'}));
} catch (IOException e) { assertNotNull(result);
fail("IOException should not occur"); // Reading ZUGFeRD
} assertEquals(expected, result);
} }
public void testPDFVisualizationUBL() { public void testPDFVisualizationCII() {
File UBLinputFile = getResourceAsFile("ubl/01.01a-INVOICE.ubl.xml"); File CIIinputFile = getResourceAsFile("cii/01.01a-INVOICE.cii.xml");
// the writing part // the writing part
String sourceFilename = "factur-x.xml";
String expected = null;
String expected = null; String result = null;
String result = null; try {
try { ZUGFeRDVisualizer zvi = new ZUGFeRDVisualizer();
ZUGFeRDVisualizer zvi = new ZUGFeRDVisualizer(); zvi.toPDF(CIIinputFile.getAbsolutePath(), TARGET_PDF_CII);
zvi.toPDF(UBLinputFile.getAbsolutePath(), TARGET_PDF_UBL); } catch (UnsupportedOperationException e) {
} catch (UnsupportedOperationException e) { fail("UnsupportedOperationException should not happen: " + e.getMessage());
fail("UnsupportedOperationException should not happen: " + e.getMessage()); } catch (IllegalArgumentException e) {
} catch (IllegalArgumentException e) { fail("IllegalArgumentException should not happen: " + e.getMessage());
fail("IllegalArgumentException should not happen: " + e.getMessage()); }
}
try {
assertTrue(ByteArraySearcher.startsWith(Files.readAllBytes(Paths.get(TARGET_PDF_CII)), new byte[]{'%', 'P', 'D', 'F'}));
try { } catch (IOException e) {
assertTrue(ByteArraySearcher.startsWith(Files.readAllBytes(Paths.get(TARGET_PDF_CII)), new byte[]{'%', 'P', 'D', 'F'})); fail("IOException should not occur");
} catch (IOException e) { }
fail("IOException should not occur"); }
}
} public void testPDFVisualizationUBL() {
public void testPDFVisualizationUBLCreditNote() { File UBLinputFile = getResourceAsFile("ubl/01.01a-INVOICE.ubl.xml");
File UBLinputFile = getResourceAsFile("ubl/UBL-CreditNote-2.1-Example.ubl.xml"); // the writing part
String sourceFilename = "factur-x.xml";
// the writing part
String sourceFilename = "factur-x.xml"; String expected = null;
String result = null;
String expected = null; try {
String result = null; ZUGFeRDVisualizer zvi = new ZUGFeRDVisualizer();
try { zvi.toPDF(UBLinputFile.getAbsolutePath(), TARGET_PDF_UBL);
ZUGFeRDVisualizer zvi = new ZUGFeRDVisualizer(); } catch (UnsupportedOperationException e) {
zvi.toPDF(UBLinputFile.getAbsolutePath(), TARGET_PDF_UBL); fail("UnsupportedOperationException should not happen: " + e.getMessage());
} catch (UnsupportedOperationException e) { } catch (IllegalArgumentException e) {
fail("UnsupportedOperationException should not happen: " + e.getMessage()); fail("IllegalArgumentException 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'}));
try { } catch (IOException e) {
assertTrue(ByteArraySearcher.startsWith(Files.readAllBytes(Paths.get(TARGET_PDF_CII)), new byte[]{'%', 'P', 'D', 'F'})); fail("IOException should not occur");
} 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");
}
}
}