- Fixed an error validation UBL files

- unknown root elements will now throw type 3 errors
- added some tests
This commit is contained in:
jstaerk
2021-11-13 17:34:24 +01:00
parent b2b3001b30
commit f56e37bda9
7 changed files with 512 additions and 92 deletions

View File

@@ -30,6 +30,8 @@ import org.xml.sax.SAXException;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPathExpressionException;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.StringReader;
import java.math.BigDecimal;
@@ -126,4 +128,42 @@ public class ZF2ZInvoiceImporterTest extends ResourceCase {
}
public void testItemReferencedDocumentsImport() {
ZUGFeRDInvoiceImporter zii=new ZUGFeRDInvoiceImporter();
DocumentBuilderFactory db = DocumentBuilderFactory.newInstance();
boolean hasExceptions=false;
Invoice invoice=null;
try {
zii.doRecalculateItemPricesFromLineTotals();
zii.doIgnoreCalculationErrors();
zii.fromXML(new String(Files.readAllBytes(Paths.get(getResourceAsFile("factur-x-testImport-corrected.xml").getAbsolutePath())), StandardCharsets.UTF_8));
invoice=zii.extractInvoice();
} catch (XPathExpressionException | ParseException | IOException e) {
hasExceptions=true;
}
assertFalse(hasExceptions);
assertNotNull(invoice.getZFItems()[0].getReferencedDocuments());
assertEquals(2, invoice.getZFItems()[0].getReferencedDocuments().length);
assertEquals("33807818630-5", invoice.getZFItems()[0].getReferencedDocuments()[0].getIssuerAssignedID());
assertEquals("PL", invoice.getZFItems()[0].getReferencedDocuments()[1].getReferenceTypeCode());
ZUGFeRD2PullProvider zf2p = new ZUGFeRD2PullProvider();
zf2p.setProfile(Profiles.getByName("Extended"));
zf2p.generateXML(invoice);
String theXML = new String(zf2p.getXML());
try {
BufferedWriter writer = new BufferedWriter(new FileWriter("c:\\Users\\jstaerk\\Desktop\\xrechnung-written.xml"));
writer.write(theXML);
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
TransactionCalculator tc=new TransactionCalculator(invoice);
// assertEquals(new BigDecimal("1284.66"),tc.getGrandTotal());
assertEquals(new BigDecimal("1284.40"),tc.getGrandTotal());
}
}