automatic ox tests

This commit is contained in:
jstaerk
2022-05-16 10:37:51 +02:00
parent a97296c402
commit 219ecb892a
4 changed files with 138 additions and 35 deletions

View File

@@ -1,3 +1,5 @@
- OXPullprovider to no longer generate invsalid XML if a duedate is set
2.5.1
=======
2022-05-12

View File

@@ -35,6 +35,7 @@ import java.util.logging.Logger;
import org.mustangproject.EStandard;
import org.mustangproject.FileAttachment;
import org.mustangproject.TradeParty;
import org.mustangproject.XMLTools;
public class OXPullProvider extends ZUGFeRD2PullProvider implements IXMLProvider {
@@ -318,11 +319,13 @@ public class OXPullProvider extends ZUGFeRD2PullProvider implements IXMLProvider
}
xml += "</ram:ApplicableHeaderTradeAgreement>"
+ "<ram:ApplicableHeaderTradeDelivery>";
if (this.trans.getDeliveryAddress() != null) {
xml += "<ram:ShipToTradeParty>" +
getTradePartyAsXML(this.trans.getDeliveryAddress(), false, true) +
"</ram:ShipToTradeParty>";
IZUGFeRDExportableTradeParty deliveryAddress=this.trans.getDeliveryAddress();
if (deliveryAddress == null) {
deliveryAddress = this.trans.getRecipient();
}
xml += "<ram:ShipToTradeParty>" +
getTradePartyAsXML(deliveryAddress, false, true) +
"</ram:ShipToTradeParty>";
/*
xml += "<ram:ActualDeliverySupplyChainEvent>"
+ "<ram:OccurrenceDateTime>";
@@ -459,12 +462,6 @@ public class OXPullProvider extends ZUGFeRD2PullProvider implements IXMLProvider
}
}
if (hasDueDate && (trans.getDueDate() != null)) {
xml += "<ram:DueDateDateTime>" // $NON-NLS-2$
+ DATE.udtFormat(trans.getDueDate())
+ "</ram:DueDateDateTime>";// 20130704
}
xml += "</ram:SpecifiedTradePaymentTerms>";
} else {
xml += buildPaymentTermsXml();
@@ -545,18 +542,7 @@ public class OXPullProvider extends ZUGFeRD2PullProvider implements IXMLProvider
String paymentTermsXml = "<ram:SpecifiedTradePaymentTerms>";
final IZUGFeRDPaymentDiscountTerms discountTerms = paymentTerms.getDiscountTerms();
final Date dueDate = paymentTerms.getDueDate();
if (dueDate != null && discountTerms != null && discountTerms.getBaseDate() != null) {
throw new IllegalStateException(
"if paymentTerms.dueDate is specified, paymentTerms.discountTerms.baseDate has not to be specified");
}
paymentTermsXml += "<ram:Description>" + paymentTerms.getDescription() + "</ram:Description>";
if (dueDate != null) {
paymentTermsXml += "<ram:DueDateDateTime>";
paymentTermsXml += DATE.udtFormat(dueDate);
paymentTermsXml += "</ram:DueDateDateTime>";
}
if (discountTerms != null) {
paymentTermsXml += "<ram:ApplicableTradePaymentDiscountTerms>";
final String currency = trans.getCurrency();

View File

@@ -1,29 +1,31 @@
/** **********************************************************************
*
/**
* *********************************************************************
* <p>
* Copyright 2019 Jochen Staerk
*
* <p>
* Use is subject to license terms.
*
* <p>
* 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
* of the License at http://www.apache.org/licenses/LICENSE-2.0.
*
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* <p>
* See the License for the specific language governing permissions and
* limitations under the License.
*
*********************************************************************** */
* <p>
* **********************************************************************
*/
package org.mustangproject.ZUGFeRD;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.junit.FixMethodOrder;
import org.junit.runners.MethodSorters;
import org.mustangproject.Invoice;
import org.mustangproject.*;
import javax.xml.xpath.XPathExpressionException;
import java.io.ByteArrayOutputStream;
@@ -42,6 +44,7 @@ import java.util.GregorianCalendar;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class OXTest extends MustangReaderTestCase implements IExportableTransaction {
final String TARGET_PDF = "./target/testout-OX.pdf";
final String TARGET_PDF_EDGE = "./target/testout-OX-edge.pdf";
final String TARGET_XML = "./target/testout-OX.xml";
protected class EdgeProduct implements IZUGFeRDExportableProduct {
@@ -199,10 +202,10 @@ public class OXTest extends MustangReaderTestCase implements IExportableTransact
EdgeProduct designProduct = new EdgeProduct("", "Künstlerische Gestaltung (Stunde): Einer Beispielrechnung",
"HUR");
EdgeProduct balloonProduct = new EdgeProduct("", "Bestellerweiterung für E&F Umbau", "C62");// test for issue
// 103
// 103
EdgeProduct airProduct = new EdgeProduct("", "Heiße Luft pro Liter", "LTR");
Item design=new Item(new BigDecimal("160"), new BigDecimal("1"), designProduct);
Item design = new Item(new BigDecimal("160"), new BigDecimal("1"), designProduct);
design.setAddReference("1825");
allItems[0] = design;
allItems[1] = new Item(new BigDecimal("0.79"), new BigDecimal("400"), balloonProduct);
@@ -269,8 +272,8 @@ public class OXTest extends MustangReaderTestCase implements IExportableTransact
.getResourceAsStream("/MustangGnuaccountingBeispielRE-20170509_505blanko.pdf");
OXExporterFromA1 oe = new OXExporterFromA1().setProducer("My Application")
.setCreator(System.getProperty("user.name")).setZUGFeRDVersion(1).ignorePDFAErrors()
.load(SOURCE_PDF)) {
.setCreator(System.getProperty("user.name")).setZUGFeRDVersion(1).ignorePDFAErrors()
.load(SOURCE_PDF)) {
oe.setTransaction(this);
String theXML = new String(oe.getProvider().getXML(), StandardCharsets.UTF_8);
assertTrue(theXML.contains("<rsm:SCRDMCCBDACIOMessageStructure"));
@@ -293,7 +296,7 @@ public class OXTest extends MustangReaderTestCase implements IExportableTransact
assertEquals(zi.getHolder(), getOwnOrganisationName());
ZUGFeRDInvoiceImporter zii = new ZUGFeRDInvoiceImporter(TARGET_PDF);
try {
Invoice i=zii.extractInvoice();
Invoice i = zii.extractInvoice();
assertEquals(new BigDecimal("400.0000"), i.getZFItems()[1].getQuantity());
/* getting the Quantity is more difficult than usual because in OrderX it's
@@ -312,4 +315,58 @@ public class OXTest extends MustangReaderTestCase implements IExportableTransact
}
public void testOXEdgeExport() {
// the writing part
try (InputStream SOURCE_PDF = this.getClass()
.getResourceAsStream("/MustangGnuaccountingBeispielRE-20170509_505blanko.pdf");
OXExporterFromA1 oe = new OXExporterFromA1().setProducer("My Application")
.setCreator(System.getProperty("user.name")).setZUGFeRDVersion(1).ignorePDFAErrors()
.load(SOURCE_PDF)) {
TradeParty rec=new TradeParty("Franz Müller", "teststr.12", "55232", "Entenhausen", "DE");
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(rec)
.setReferenceNumber("991-01484-64")//leitweg-id
.setNumber("123").addItem(new org.mustangproject.Item(new org.mustangproject.Product("Testprodukt", "", "C62", BigDecimal.ZERO), /*price*/ new BigDecimal("1.0"), /*qty*/ new BigDecimal("1.0"))).addItem(new org.mustangproject.Item(new org.mustangproject.Product("Testprodukt", "", "C62", BigDecimal.ZERO), /*price*/ new BigDecimal("1.0"), /*qty*/ new BigDecimal("1.0")));
oe.setTransaction(i);
oe.export(TARGET_PDF_EDGE);
} catch (IOException e) {
fail("IOException should not be raised in testEdgeExport");
}
// now check the contents (like MustangReaderTest)
ZUGFeRDImporter zi = new ZUGFeRDImporter(TARGET_PDF_EDGE);
assertTrue(zi.getUTF8().contains("<ram:TypeCode>220</ram:TypeCode>"));
assertTrue(zi.getUTF8().contains("<ram:ShipToTradeParty>"));
assertTrue(zi.getUTF8().contains("EUR"));
// Now also check the "invoice"Importer
assertEquals("2.00", zi.getAmount());
assertEquals(zi.getHolder(), "Test company");
ZUGFeRDInvoiceImporter zii = new ZUGFeRDInvoiceImporter(TARGET_PDF_EDGE);
try {
Invoice i = zii.extractInvoice();
assertEquals(new BigDecimal("1.0000"), i.getZFItems()[1].getQuantity());
/* getting the Quantity is more difficult than usual because in OrderX it's
called requestedQuantity, not BilledQuantity
*/
} catch (XPathExpressionException e) {
fail("XPathExpressionException should not be raised in testEdgeExport");
} catch (ParseException e) {
fail("ParseException should not be raised in testEdgeExport");
/* a parseException would also be fired if the calculated grand total does not
match the read grand total */
}
}
}

View File

@@ -199,4 +199,62 @@ public class LibraryTest extends ResourceCase {
.isEqualTo(0);
}
/**
* automatically test the xrechnung
*/
public void testOXValidationSimple() {
File tempFile = new File("../library/target/testout-OX.pdf");
ZUGFeRDValidator zfv = new ZUGFeRDValidator();
String res = zfv.validate(tempFile.getAbsolutePath());
assertThat(res).valueByXPath("count(//error)")
.asInt()
.isEqualTo(0);
assertThat(res).valueByXPath("/validation/summary/@status")
.asString()
.isEqualTo("valid");// expect to be valid because XR notices are, well, only notices
assertThat(res).valueByXPath("/validation/xml/summary/@status")
.asString()
.isEqualTo("valid");
/** end of errors due to version mismatch*/
assertThat(res).valueByXPath("count(//notice)")
.asInt()
.isEqualTo(0);
}
/**
* automatically test the xrechnung
*/
public void testOXValidationEdge() {
File tempFile = new File("../library/target/testout-OX-Edge.pdf");
ZUGFeRDValidator zfv = new ZUGFeRDValidator();
String res = zfv.validate(tempFile.getAbsolutePath());
assertThat(res).valueByXPath("count(//error)")
.asInt()
.isEqualTo(0);
assertThat(res).valueByXPath("/validation/summary/@status")
.asString()
.isEqualTo("valid");// expect to be valid because XR notices are, well, only notices
assertThat(res).valueByXPath("/validation/xml/summary/@status")
.asString()
.isEqualTo("valid");
/** end of errors due to version mismatch*/
assertThat(res).valueByXPath("count(//notice)")
.asInt()
.isEqualTo(0);
}
}