From 3f282838788a87526eb45d23929a82b8ef4687de Mon Sep 17 00:00:00 2001 From: jstaerk Date: Mon, 25 Nov 2024 16:51:21 +0100 Subject: [PATCH] closes #581 --- History.md | 2 +- .../ZUGFeRD/DeSerializationTest.java | 35 ++++++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/History.md b/History.md index 57fc4562..7f268e79 100644 --- a/History.md +++ b/History.md @@ -6,7 +6,7 @@ ? be able to access ID in error message ? log error IDs - closes #579 - +- #581 2.15.0 ======= diff --git a/library/src/test/java/org/mustangproject/ZUGFeRD/DeSerializationTest.java b/library/src/test/java/org/mustangproject/ZUGFeRD/DeSerializationTest.java index 7c6d409d..0dbd2dc0 100644 --- a/library/src/test/java/org/mustangproject/ZUGFeRD/DeSerializationTest.java +++ b/library/src/test/java/org/mustangproject/ZUGFeRD/DeSerializationTest.java @@ -28,11 +28,17 @@ import org.junit.FixMethodOrder; import org.junit.runners.MethodSorters; import org.mustangproject.*; +import javax.xml.xpath.XPathExpressionException; +import java.io.File; +import java.io.IOException; import java.math.BigDecimal; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.text.ParseException; import java.util.Date; @FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class DeSerializationTest extends TestCase { +public class DeSerializationTest extends ResourceCase { public void testJackson() throws JsonProcessingException { ObjectMapper mapper = new ObjectMapper(); @@ -50,6 +56,33 @@ public class DeSerializationTest extends TestCase { } + public void testInvoiceLine() throws JsonProcessingException { + File inputCII = getResourceAsFile("factur-x.xml"); + boolean hasExceptions = false; + + ZUGFeRDInvoiceImporter zii = new ZUGFeRDInvoiceImporter(); + try { + zii.fromXML(new String(Files.readAllBytes(inputCII.toPath()), StandardCharsets.UTF_8)); + + } catch (IOException e) { + hasExceptions = true; + } + + CalculatedInvoice ci=new CalculatedInvoice(); + try { + zii.extractInto(ci); + } catch (XPathExpressionException e) { + hasExceptions = true; + } catch (ParseException e) { + hasExceptions = true; + } + ObjectMapper mapper = new ObjectMapper(); + String jsonArray = mapper.writeValueAsString(ci); + assertFalse(hasExceptions); + assertTrue(jsonArray.contains("lineTotalAmount")); + + } + public void testAllowanceRead() throws JsonProcessingException { ObjectMapper mapper = new ObjectMapper();