Added test for issue #68 and UTF8 BOM reading

This commit is contained in:
Jochen Stärk
2018-10-22 19:45:44 +02:00
parent a1dbde7869
commit d40cc4acb0

View File

@@ -49,7 +49,252 @@ public class MustangReaderWriterCustomXMLTest extends TestCase {
// //////// TESTS
// //////////////////////////////////////////////////////////////////////////////////////////
public void testCustomZF2Export() throws Exception {
final String TARGET_PDF = "./target/testout-MustangGnuaccountingBeispielRE-20171118_506custom.pdf";
// the writing part
try {
InputStream SOURCE_PDF = this.getClass()
.getResourceAsStream("/MustangGnuaccountingBeispielRE-20170509_505blanko.pdf");
ZUGFeRDExporter zea1 = new ZUGFeRDExporterFromA1Factory().setProducer("My Application").setCreator("Test").setZUGFeRDConformanceLevel(ZUGFeRDConformanceLevel.EN16931)
.load(SOURCE_PDF);
final byte[] UTF8ByteOrderMark = new byte[] { (byte)0xef, (byte)0xbb,
(byte)0xbf };
/* we have much more information than just in the basic profile (comfort or extended) but it's perfectly valid to provide more information, just not less. */
String ownZUGFeRDXML = new String(UTF8ByteOrderMark)+"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<rsm:CrossIndustryInvoice xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:rsm=\"urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100\" xmlns:ram=\"urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100\" xmlns:udt=\"urn:un:unece:uncefact:data:standard:UnqualifiedDataType:100\">\n" +
" <rsm:ExchangedDocumentContext>\n" +
" <ram:TestIndicator><udt:Indicator>false</udt:Indicator></ram:TestIndicator>\n" +
" <ram:GuidelineSpecifiedDocumentContextParameter>\n" +
" <ram:ID>urn:cen.eu:en16931:2017:compliant:factur-x.eu:1p0:extended</ram:ID>\n" +
" </ram:GuidelineSpecifiedDocumentContextParameter>\n" +
" </rsm:ExchangedDocumentContext>\n" +
" <rsm:ExchangedDocument>\n" +
" <ram:ID>RE-20171118/506</ram:ID>\n" +
" <ram:Name>RECHNUNG</ram:Name>\n" +
" <ram:TypeCode>380</ram:TypeCode>\n" +
" <ram:IssueDateTime><udt:DateTimeString format=\"102\">20171118</udt:DateTimeString></ram:IssueDateTime>\n" +
" </rsm:ExchangedDocument>\n" +
" <rsm:SupplyChainTradeTransaction>\n" +
" <ram:IncludedSupplyChainTradeLineItem>\n" +
" <ram:AssociatedDocumentLineDocument>\n" +
" <ram:LineID>1</ram:LineID>\n" +
" </ram:AssociatedDocumentLineDocument>\n" +
" <ram:SpecifiedTradeProduct>\n" +
" <ram:Name>Künstlerische Gestaltung (Stunde): Einer Beispielrechnung</ram:Name>\n" +
" <ram:Description></ram:Description>\n" +
" </ram:SpecifiedTradeProduct>\n" +
" <ram:SpecifiedLineTradeAgreement>\n" +
" <ram:GrossPriceProductTradePrice>\n" +
" <ram:ChargeAmount currencyID=\"EUR\">160.0000</ram:ChargeAmount>\n" +
" <ram:BasisQuantity unitCode=\"HUR\">1.0000</ram:BasisQuantity>\n" +
" </ram:GrossPriceProductTradePrice>\n" +
" <ram:NetPriceProductTradePrice>\n" +
" <ram:ChargeAmount currencyID=\"EUR\">160.0000</ram:ChargeAmount>\n" +
" <ram:BasisQuantity unitCode=\"HUR\">1.0000</ram:BasisQuantity>\n" +
" </ram:NetPriceProductTradePrice>\n" +
" </ram:SpecifiedLineTradeAgreement>\n" +
" <ram:SpecifiedLineTradeDelivery>\n" +
" <ram:BilledQuantity unitCode=\"HUR\">1.0000</ram:BilledQuantity>\n" +
" </ram:SpecifiedLineTradeDelivery>\n" +
" <ram:SpecifiedLineTradeSettlement>\n" +
" <ram:ApplicableTradeTax>\n" +
" <ram:TypeCode>VAT</ram:TypeCode>\n" +
" <ram:CategoryCode>S</ram:CategoryCode>\n" +
" <ram:RateApplicablePercent>7.00</ram:RateApplicablePercent>\n" +
" </ram:ApplicableTradeTax>\n" +
" <ram:SpecifiedTradeSettlementLineMonetarySummation>\n" +
" <ram:LineTotalAmount currencyID=\"EUR\">160.00</ram:LineTotalAmount>\n" +
" </ram:SpecifiedTradeSettlementLineMonetarySummation>\n" +
" </ram:SpecifiedLineTradeSettlement>\n" +
" </ram:IncludedSupplyChainTradeLineItem>\n" +
" <ram:IncludedSupplyChainTradeLineItem>\n" +
" <ram:AssociatedDocumentLineDocument>\n" +
" <ram:LineID>2</ram:LineID>\n" +
" </ram:AssociatedDocumentLineDocument>\n" +
" <ram:SpecifiedTradeProduct>\n" +
" <ram:Name>Luftballon: Bunt, ca. 500ml</ram:Name>\n" +
" <ram:Description></ram:Description>\n" +
" </ram:SpecifiedTradeProduct>\n" +
" <ram:SpecifiedLineTradeAgreement>\n" +
" <ram:GrossPriceProductTradePrice>\n" +
" <ram:ChargeAmount currencyID=\"EUR\">0.7900</ram:ChargeAmount>\n" +
" <ram:BasisQuantity unitCode=\"C62\">1.0000</ram:BasisQuantity>\n" +
" </ram:GrossPriceProductTradePrice>\n" +
" <ram:NetPriceProductTradePrice>\n" +
" <ram:ChargeAmount currencyID=\"EUR\">0.7900</ram:ChargeAmount>\n" +
" <ram:BasisQuantity unitCode=\"C62\">1.0000</ram:BasisQuantity>\n" +
" </ram:NetPriceProductTradePrice>\n" +
" </ram:SpecifiedLineTradeAgreement>\n" +
" <ram:SpecifiedLineTradeDelivery>\n" +
" <ram:BilledQuantity unitCode=\"C62\">400.0000</ram:BilledQuantity>\n" +
" </ram:SpecifiedLineTradeDelivery>\n" +
" <ram:SpecifiedLineTradeSettlement>\n" +
" <ram:ApplicableTradeTax>\n" +
" <ram:TypeCode>VAT</ram:TypeCode>\n" +
" <ram:CategoryCode>S</ram:CategoryCode>\n" +
" <ram:RateApplicablePercent>19.00</ram:RateApplicablePercent>\n" +
" </ram:ApplicableTradeTax>\n" +
" <ram:SpecifiedTradeSettlementLineMonetarySummation>\n" +
" <ram:LineTotalAmount currencyID=\"EUR\">316.00</ram:LineTotalAmount>\n" +
" </ram:SpecifiedTradeSettlementLineMonetarySummation>\n" +
" </ram:SpecifiedLineTradeSettlement>\n" +
" </ram:IncludedSupplyChainTradeLineItem>\n" +
" <ram:IncludedSupplyChainTradeLineItem>\n" +
" <ram:AssociatedDocumentLineDocument>\n" +
" <ram:LineID>3</ram:LineID>\n" +
" </ram:AssociatedDocumentLineDocument>\n" +
" <ram:SpecifiedTradeProduct>\n" +
" <ram:Name>Heiße Luft pro Liter</ram:Name>\n" +
" <ram:Description></ram:Description>\n" +
" </ram:SpecifiedTradeProduct>\n" +
" <ram:SpecifiedLineTradeAgreement>\n" +
" <ram:GrossPriceProductTradePrice>\n" +
" <ram:ChargeAmount currencyID=\"EUR\">0.1000</ram:ChargeAmount>\n" +
" <ram:BasisQuantity unitCode=\"LTR\">1.0000</ram:BasisQuantity>\n" +
" </ram:GrossPriceProductTradePrice>\n" +
" <ram:NetPriceProductTradePrice>\n" +
" <ram:ChargeAmount currencyID=\"EUR\">0.1000</ram:ChargeAmount>\n" +
" <ram:BasisQuantity unitCode=\"LTR\">1.0000</ram:BasisQuantity>\n" +
" </ram:NetPriceProductTradePrice>\n" +
" </ram:SpecifiedLineTradeAgreement>\n" +
" <ram:SpecifiedLineTradeDelivery>\n" +
" <ram:BilledQuantity unitCode=\"LTR\">200.0000</ram:BilledQuantity>\n" +
" </ram:SpecifiedLineTradeDelivery>\n" +
" <ram:SpecifiedLineTradeSettlement>\n" +
" <ram:ApplicableTradeTax>\n" +
" <ram:TypeCode>VAT</ram:TypeCode>\n" +
" <ram:CategoryCode>S</ram:CategoryCode>\n" +
" <ram:RateApplicablePercent>19.00</ram:RateApplicablePercent>\n" +
" </ram:ApplicableTradeTax>\n" +
" <ram:SpecifiedTradeSettlementLineMonetarySummation>\n" +
" <ram:LineTotalAmount currencyID=\"EUR\">20.00</ram:LineTotalAmount>\n" +
" </ram:SpecifiedTradeSettlementLineMonetarySummation>\n" +
" </ram:SpecifiedLineTradeSettlement>\n" +
" </ram:IncludedSupplyChainTradeLineItem>\n" +
" <ram:ApplicableHeaderTradeAgreement>\n" +
" <ram:SellerTradeParty>\n" +
" <ram:Name>Bei Spiel GmbH</ram:Name>\n" +
" <ram:PostalTradeAddress>\n" +
" <ram:PostcodeCode>12345</ram:PostcodeCode>\n" +
" <ram:LineOne>Ecke 12</ram:LineOne>\n" +
" <ram:CityName>Stadthausen</ram:CityName>\n" +
" <ram:CountryID>DE</ram:CountryID>\n" +
" </ram:PostalTradeAddress>\n" +
" <ram:SpecifiedTaxRegistration>\n" +
" <ram:ID schemeID=\"FC\">22/815/0815/4</ram:ID>\n" +
" </ram:SpecifiedTaxRegistration>\n" +
" <ram:SpecifiedTaxRegistration>\n" +
" <ram:ID schemeID=\"VA\">DE136695976</ram:ID>\n" +
" </ram:SpecifiedTaxRegistration>\n" +
" </ram:SellerTradeParty>\n" +
" <ram:BuyerTradeParty>\n" +
" <ram:Name>Theodor Est</ram:Name>\n" +
" <ram:PostalTradeAddress>\n" +
" <ram:PostcodeCode>88802</ram:PostcodeCode>\n" +
" <ram:LineOne>Bahnstr. 42</ram:LineOne>\n" +
" <ram:CityName>Spielkreis</ram:CityName>\n" +
" <ram:CountryID>DE</ram:CountryID>\n" +
" </ram:PostalTradeAddress>\n" +
" <ram:SpecifiedTaxRegistration>\n" +
" <ram:ID schemeID=\"VA\">DE999999999</ram:ID>\n" +
" </ram:SpecifiedTaxRegistration>\n" +
" </ram:BuyerTradeParty>\n" +
" </ram:ApplicableHeaderTradeAgreement>\n" +
" <ram:ApplicableHeaderTradeDelivery>\n" +
" <ram:ActualDeliverySupplyChainEvent>\n" +
" <ram:OccurrenceDateTime><udt:DateTimeString format=\"102\">20171117</udt:DateTimeString></ram:OccurrenceDateTime>\n" +
" </ram:ActualDeliverySupplyChainEvent>\n" +
" </ram:ApplicableHeaderTradeDelivery>\n" +
" <ram:ApplicableHeaderTradeSettlement>\n" +
" <ram:PaymentReference>RE-20171118/506</ram:PaymentReference>\n" +
" <ram:InvoiceCurrencyCode>EUR</ram:InvoiceCurrencyCode>\n" +
" <ram:SpecifiedTradeSettlementPaymentMeans>\n" +
" <ram:TypeCode>42</ram:TypeCode>\n" +
" <ram:Information>Überweisung</ram:Information>\n" +
" <ram:PayeePartyCreditorFinancialAccount>\n" +
" <ram:IBANID>DE88 2008 0000 0970 3757 00</ram:IBANID>\n" +
" </ram:PayeePartyCreditorFinancialAccount>\n" +
" <ram:PayeeSpecifiedCreditorFinancialInstitution>\n" +
" <ram:BICID>COBADEFFXXX</ram:BICID>\n" +
" <ram:Name>Commerzbank</ram:Name>\n" +
" </ram:PayeeSpecifiedCreditorFinancialInstitution>\n" +
" </ram:SpecifiedTradeSettlementPaymentMeans>\n" +
" <ram:ApplicableTradeTax>\n" +
" <ram:CalculatedAmount currencyID=\"EUR\">11.20</ram:CalculatedAmount>\n" +
" <ram:TypeCode>VAT</ram:TypeCode>\n" +
" <ram:BasisAmount currencyID=\"EUR\">160.00</ram:BasisAmount>\n" +
" <ram:CategoryCode>S</ram:CategoryCode>\n" +
" <ram:RateApplicablePercent>7.00</ram:RateApplicablePercent>\n" +
" </ram:ApplicableTradeTax>\n" +
" <ram:ApplicableTradeTax>\n" +
" <ram:CalculatedAmount currencyID=\"EUR\">63.84</ram:CalculatedAmount>\n" +
" <ram:TypeCode>VAT</ram:TypeCode>\n" +
" <ram:BasisAmount currencyID=\"EUR\">336.00</ram:BasisAmount>\n" +
" <ram:CategoryCode>S</ram:CategoryCode>\n" +
" <ram:RateApplicablePercent>19.00</ram:RateApplicablePercent>\n" +
" </ram:ApplicableTradeTax>\n" +
" <ram:SpecifiedTradePaymentTerms>\n" +
" <ram:Description>Zahlbar ohne Abzug bis 09.12.2017</ram:Description>\n" +
" <ram:DueDateDateTime><udt:DateTimeString format=\"102\">20171209</udt:DateTimeString></ram:DueDateDateTime>\n" +
" </ram:SpecifiedTradePaymentTerms>\n" +
" <ram:SpecifiedTradeSettlementHeaderMonetarySummation>\n" +
" <ram:LineTotalAmount currencyID=\"EUR\">496.00</ram:LineTotalAmount>\n" +
" <ram:ChargeTotalAmount currencyID=\"EUR\">0.00</ram:ChargeTotalAmount>\n" +
" <ram:AllowanceTotalAmount currencyID=\"EUR\">0.00</ram:AllowanceTotalAmount>\n" +
" <ram:TaxBasisTotalAmount currencyID=\"EUR\">496.00</ram:TaxBasisTotalAmount>\n" +
" <ram:TaxTotalAmount currencyID=\"EUR\">75.04</ram:TaxTotalAmount>\n" +
" <ram:GrandTotalAmount currencyID=\"EUR\">571.04</ram:GrandTotalAmount>\n" +
" <ram:DuePayableAmount currencyID=\"EUR\">571.04</ram:DuePayableAmount>\n" +
" </ram:SpecifiedTradeSettlementHeaderMonetarySummation>\n" +
" </ram:ApplicableHeaderTradeSettlement>\n" +
" </rsm:SupplyChainTradeTransaction>\n" +
"</rsm:CrossIndustryInvoice>";
zea1.setZUGFeRDXMLData(ownZUGFeRDXML.getBytes("UTF-8"));
ByteArrayOutputStream baos=new ByteArrayOutputStream();
zea1.disableAutoClose(true);
zea1.export(TARGET_PDF);
zea1.export(baos);
zea1.close();
String pdfContent=baos.toString("UTF-8");
assertFalse(pdfContent.indexOf("(via mustangproject.org")==-1);
assertFalse(pdfContent.indexOf("<zf:ConformanceLevel>EN16931</zf:ConformanceLevel>") == -1);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// now check the contents (like MustangReaderTest)
ZUGFeRDImporter zi = new ZUGFeRDImporter();
zi.extract(TARGET_PDF);
// Reading ZUGFeRD
String amount = null;
String bic = null;
String iban = null;
String holder = null;
String ref = null;
if (zi.canParse()) {
zi.parse();
amount = zi.getAmount();
bic = zi.getBIC();
iban = zi.getIBAN();
holder = zi.getHolder();
ref = zi.getForeignReference();
}
assertEquals(amount, "571.04");
assertEquals(bic, "COBADEFFXXX");
assertEquals(iban, "DE88 2008 0000 0970 3757 00");
assertEquals(holder, "Bei Spiel GmbH");
assertEquals(ref, "RE-20171118/506");
}
/**
* The exporter test bases on @{code
* ./src/test/MustangGnuaccountingBeispielRE-20140703_502blanko.pdf}, adds
@@ -58,7 +303,7 @@ public class MustangReaderWriterCustomXMLTest extends TestCase {
* importer test (which is probably redundant) --> as only Name Ascending is
* supported for Test Unit sequence, I renamed the Exporter Test test-Z-Export
*/
public void testCustomExport() throws Exception {
public void testCustomZF1Export() throws Exception {
final String TARGET_PDF = "./target/testout-MustangGnuaccountingBeispielRE-20170509_505custom.pdf";
// the writing part