From 8dac7d2cb3215733068ee189c8c3028127c48191 Mon Sep 17 00:00:00 2001 From: Sebastian Sieber Date: Fri, 14 Apr 2023 07:59:47 +0200 Subject: [PATCH 1/3] Update dependency com.helger.en16931-cii2ubl v1.3.0 -> v1.4.2 Adjust test --- library/pom.xml | 2 +- .../org/mustangproject/ZUGFeRD/UBLTest.java | 37 ++++-- .../ubl-conv-ubl-output-factur-x.xml | 118 +++++++++--------- 3 files changed, 85 insertions(+), 72 deletions(-) diff --git a/library/pom.xml b/library/pom.xml index 882eb324..9aaed089 100644 --- a/library/pom.xml +++ b/library/pom.xml @@ -102,7 +102,7 @@ com.helger en16931-cii2ubl - 1.3.0 + 1.4.2 diff --git a/library/src/test/java/org/mustangproject/ZUGFeRD/UBLTest.java b/library/src/test/java/org/mustangproject/ZUGFeRD/UBLTest.java index 38614e44..13906407 100644 --- a/library/src/test/java/org/mustangproject/ZUGFeRD/UBLTest.java +++ b/library/src/test/java/org/mustangproject/ZUGFeRD/UBLTest.java @@ -24,22 +24,31 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; -import java.io.InputStream; import java.math.BigDecimal; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; import java.util.Date; -import org.junit.FixMethodOrder; -import org.junit.runners.MethodSorters; -import org.mustangproject.*; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.mustangproject.BankDetails; import org.mustangproject.CII.CIIToUBL; +import org.mustangproject.Contact; +import org.mustangproject.Invoice; +import org.mustangproject.Item; +import org.mustangproject.Product; +import org.mustangproject.TradeParty; -@FixMethodOrder(MethodSorters.NAME_ASCENDING) public class UBLTest extends ResourceCase { final String TARGET_XML = "./target/testout-1Lieferschein.xml"; + public UBLTest() { + } + + @Test + @Order(2) public void testUBLBasic() { // the writing part @@ -52,21 +61,23 @@ public void testUBLBasic() { try { final File tempFile = File.createTempFile("ZUGFeRD-UBL-", "-test"); c2u.convert(input, tempFile); - expected = ResourceUtilities.readFile(StandardCharsets.UTF_8, expectedFile.getAbsolutePath()).replaceAll("\r\n", "\n"); - result = ResourceUtilities.readFile(StandardCharsets.UTF_8, tempFile.getAbsolutePath()).replaceAll("\r\n", "\n"); + expected = ResourceUtilities.readFile(StandardCharsets.UTF_8, expectedFile.getAbsolutePath());//.replaceAll("\r\n", "\n"); + result = ResourceUtilities.readFile(StandardCharsets.UTF_8, tempFile.getAbsolutePath());//.replaceAll("\r\n", "\n"); } catch (final IOException e) { fail("Exception should not happen: " + e.getMessage()); } assertNotNull(result); - assertEquals(expected, result); + Assertions.assertThat(result).isXmlEqualTo(expected); } + @Test + @Order(1) public void test1Lieferschein() { - EinLieferscheinExporter oe = new EinLieferscheinExporter(); - Invoice i = new Invoice().setDueDate(new Date()).setIssueDate(new Date()).setDeliveryDate(new Date()) + final EinLieferscheinExporter oe = new EinLieferscheinExporter(); + final Invoice i = new Invoice().setDueDate(new Date()).setIssueDate(new Date()).setDeliveryDate(new Date()) .setSender(new TradeParty("Test company", "teststr", "55232", "teststadt", "DE").addTaxID("DE4711").addVATID("DE0815").setContact(new Contact("Hans Test", "+49123456789", "test@example.org")).addBankDetails(new BankDetails("DE12500105170648489890", "COBADEFXXX"))) .setRecipient(new TradeParty("Franz Müller", "teststr.12", "55232", "Entenhausen", "DE")) .setReferenceNumber("991-01484-64")//leitweg-id @@ -75,13 +86,13 @@ public void test1Lieferschein() { try { oe.setTransaction(i); - ByteArrayOutputStream baos=new ByteArrayOutputStream(); + final ByteArrayOutputStream baos=new ByteArrayOutputStream(); oe.export(baos); - String theXML = baos.toString("UTF-8"); + final String theXML = baos.toString("UTF-8"); assertTrue(theXML.contains(" - - urn:cen.eu:en16931:2017:extended:urn:fdc:peppol.eu:2017:poacc:billing:3.0 + + urn:cen.eu:en16931:2017#compliant#urn:fdc:peppol.eu:2017:poacc:billing:3.0 urn:fdc:peppol.eu:2017:poacc:billing:01:1.0 RE-20201121/508 2020-11-21 @@ -13,21 +15,21 @@ Bei Spiel GmbH - + Ecke 12 - Stadthausen - 12345 - + Stadthausen + 12345 + DE - + DE136695976 - + VAT - + Bei Spiel GmbH @@ -37,18 +39,18 @@ 2 - + Theodor Est - + Bahnstr. 42 - Spielkreis - 88802 - + Spielkreis + 88802 + DE - + Theodor Est @@ -61,24 +63,24 @@ 75.04 - + 160.00 - 11.20 - + 11.20 + S - 7.00 - + 7.00 + VAT - + 336.00 - 63.84 - + 63.84 + S - 19.00 - + 19.00 + VAT @@ -86,71 +88,71 @@ 496.00 - 496.00 - 571.04 - 0.00 - 0.00 - 0.00 - 571.04 + 496.00 + 571.04 + 0.00 + 0.00 + 0.00 + 571.04 1 - 1.0000 - 160.00 - + 1.0000 + 160.00 + Of a sample invoice - Design (hours) - + Design (hours) + S - 7.00 - + 7.00 + VAT - + 160.0000 - 1.0000 + 1.0000 2 - 400.0000 - 316.00 - + 400.0000 + 316.00 + various colors, ~2000ml - Ballons - + Ballons + S - 19.00 - + 19.00 + VAT - + 0.7900 - 1.0000 + 1.0000 3 - 800.0000 - 20.00 - + 800.0000 + 20.00 + - Hot air „heiße Luft“ (litres) - + Hot air „heiße Luft“ (litres) + S - 19.00 - + 19.00 + VAT - + 0.0250 - 1.0000 + 1.0000 \ No newline at end of file From 3c7b41ccb0d6e2b267db54f50fc34ba1c30b20c2 Mon Sep 17 00:00:00 2001 From: Sebastian Sieber Date: Fri, 14 Apr 2023 15:50:16 +0200 Subject: [PATCH 2/3] Update dependency com.helger.en16931-cii2ubl v1.4.2 -> v1.4.10. Add CIIToUBL23Converter to CIIToUBL. Adjust test. --- library/pom.xml | 3 +- .../java/org/mustangproject/CII/CIIToUBL.java | 37 +++++++---- .../org/mustangproject/ZUGFeRD/UBLTest.java | 4 +- .../ubl-conv-ubl-output-factur-x.xml | 62 +++++++++++-------- 4 files changed, 64 insertions(+), 42 deletions(-) diff --git a/library/pom.xml b/library/pom.xml index 9aaed089..f9c8f083 100644 --- a/library/pom.xml +++ b/library/pom.xml @@ -102,7 +102,7 @@ com.helger en16931-cii2ubl - 1.4.2 + 1.4.10 @@ -122,6 +122,7 @@ org.xmlunit xmlunit-assertj 2.9.1 + test diff --git a/library/src/main/java/org/mustangproject/CII/CIIToUBL.java b/library/src/main/java/org/mustangproject/CII/CIIToUBL.java index 8034fe33..733006a1 100644 --- a/library/src/main/java/org/mustangproject/CII/CIIToUBL.java +++ b/library/src/main/java/org/mustangproject/CII/CIIToUBL.java @@ -1,12 +1,14 @@ package org.mustangproject.CII; -import com.helger.commons.error.list.ErrorList; -import com.helger.en16931.cii2ubl.CIIToUBL22Converter; -import com.helger.ubl21.UBL21Writer; -import com.helger.ubl22.UBL22Writer; import java.io.File; import java.io.Serializable; +import com.helger.commons.error.list.ErrorList; +import com.helger.en16931.cii2ubl.CIIToUBL23Converter; +import com.helger.ubl21.UBL21Writer; +import com.helger.ubl22.UBL22Writer; +import com.helger.ubl23.UBL23Writer; + /*** * converts a Cross Industry Invoice XML file to a UBL XML file * thanks to Philip Helger for his library @@ -18,36 +20,45 @@ public class CIIToUBL { * @param output the UBL file to write to */ public void convert(File input, File output) { - ErrorList occurred=new ErrorList(); - CIIToUBL22Converter cc=new CIIToUBL22Converter(); - Serializable aUBL = cc.convertCIItoUBL(input, occurred); + final ErrorList occurred=new ErrorList(); + final CIIToUBL23Converter cc=new CIIToUBL23Converter(); + final Serializable aUBL = cc.convertCIItoUBL(input, occurred); if (aUBL instanceof oasis.names.specification.ubl.schema.xsd.invoice_21.InvoiceType) { UBL21Writer.invoice () .setFormattedOutput (true) .write ((oasis.names.specification.ubl.schema.xsd.invoice_21.InvoiceType) aUBL, output); } - else - if (aUBL instanceof oasis.names.specification.ubl.schema.xsd.creditnote_21.CreditNoteType) + else if (aUBL instanceof oasis.names.specification.ubl.schema.xsd.creditnote_21.CreditNoteType) { UBL21Writer.creditNote () .setFormattedOutput (true) .write ((oasis.names.specification.ubl.schema.xsd.creditnote_21.CreditNoteType) aUBL, output); } - else - if (aUBL instanceof oasis.names.specification.ubl.schema.xsd.invoice_22.InvoiceType) + else if (aUBL instanceof oasis.names.specification.ubl.schema.xsd.invoice_22.InvoiceType) { UBL22Writer.invoice () .setFormattedOutput (true) .write ((oasis.names.specification.ubl.schema.xsd.invoice_22.InvoiceType) aUBL, output); } - else - if (aUBL instanceof oasis.names.specification.ubl.schema.xsd.creditnote_22.CreditNoteType) + else if (aUBL instanceof oasis.names.specification.ubl.schema.xsd.creditnote_22.CreditNoteType) { UBL22Writer.creditNote () .setFormattedOutput (true) .write ((oasis.names.specification.ubl.schema.xsd.creditnote_22.CreditNoteType) aUBL, output); } + else if (aUBL instanceof oasis.names.specification.ubl.schema.xsd.invoice_23.InvoiceType) + { + UBL23Writer.invoice () + .setFormattedOutput (true) + .write ((oasis.names.specification.ubl.schema.xsd.invoice_23.InvoiceType) aUBL, output); + } + else if (aUBL instanceof oasis.names.specification.ubl.schema.xsd.creditnote_23.CreditNoteType) + { + UBL23Writer.creditNote () + .setFormattedOutput (true) + .write ((oasis.names.specification.ubl.schema.xsd.creditnote_23.CreditNoteType) aUBL, output); + } } } diff --git a/library/src/test/java/org/mustangproject/ZUGFeRD/UBLTest.java b/library/src/test/java/org/mustangproject/ZUGFeRD/UBLTest.java index 13906407..12cfed97 100644 --- a/library/src/test/java/org/mustangproject/ZUGFeRD/UBLTest.java +++ b/library/src/test/java/org/mustangproject/ZUGFeRD/UBLTest.java @@ -61,8 +61,8 @@ public void testUBLBasic() { try { final File tempFile = File.createTempFile("ZUGFeRD-UBL-", "-test"); c2u.convert(input, tempFile); - expected = ResourceUtilities.readFile(StandardCharsets.UTF_8, expectedFile.getAbsolutePath());//.replaceAll("\r\n", "\n"); - result = ResourceUtilities.readFile(StandardCharsets.UTF_8, tempFile.getAbsolutePath());//.replaceAll("\r\n", "\n"); + expected = ResourceUtilities.readFile(StandardCharsets.UTF_8, expectedFile.getAbsolutePath()); + result = ResourceUtilities.readFile(StandardCharsets.UTF_8, tempFile.getAbsolutePath()); } catch (final IOException e) { fail("Exception should not happen: " + e.getMessage()); } diff --git a/library/src/test/resources/ubl-conv-ubl-output-factur-x.xml b/library/src/test/resources/ubl-conv-ubl-output-factur-x.xml index 2a1fb4f8..269fbae7 100644 --- a/library/src/test/resources/ubl-conv-ubl-output-factur-x.xml +++ b/library/src/test/resources/ubl-conv-ubl-output-factur-x.xml @@ -58,28 +58,39 @@ 2020-11-10 + + 42 + RE-20201121/508 + + DE88200800000970375700 + Max Mustermann + + COBADEFFXXX + + + Zahlbar ohne Abzug bis 12.12.2020 75.04 - 160.00 - 11.20 + 160 + 11.2 S - 7.00 + 7 VAT - 336.00 + 336 63.84 S - 19.00 + 19 VAT @@ -87,72 +98,71 @@ - 496.00 - 496.00 + 496 + 496 571.04 - 0.00 - 0.00 - 0.00 + 0 + 0 + 0 571.04 1 - 1.0000 - 160.00 + 1 + 160 Of a sample invoice Design (hours) S - 7.00 + 7 VAT - 160.0000 - 1.0000 + 160 + 1 2 - 400.0000 - 316.00 + 400 + 316 various colors, ~2000ml Ballons S - 19.00 + 19 VAT - 0.7900 - 1.0000 + 0.79 + 1 3 - 800.0000 - 20.00 + 800 + 20 - Hot air „heiße Luft“ (litres) S - 19.00 + 19 VAT - 0.0250 - 1.0000 + 0.025 + 1 \ No newline at end of file From 610745a2116133a4b0ec3094c73fc6fbf422f338 Mon Sep 17 00:00:00 2001 From: Sebastian Sieber Date: Tue, 18 Apr 2023 08:10:44 +0200 Subject: [PATCH 3/3] Make file valid --- library/src/test/resources/ubl-conv-ubl-output-factur-x.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/src/test/resources/ubl-conv-ubl-output-factur-x.xml b/library/src/test/resources/ubl-conv-ubl-output-factur-x.xml index 269fbae7..f9daed6d 100644 --- a/library/src/test/resources/ubl-conv-ubl-output-factur-x.xml +++ b/library/src/test/resources/ubl-conv-ubl-output-factur-x.xml @@ -1,5 +1,5 @@ - urn:cen.eu:en16931:2017#compliant#urn:fdc:peppol.eu:2017:poacc:billing:3.0