Extract class ZUGFeRDTransactionModelConverter from ZUGFeRDExporter so that it can be tested separately and improve readability

This commit is contained in:
Yannik Hampe
2017-05-31 16:10:50 +02:00
parent a771b1e769
commit 446ccf7718
11 changed files with 26753 additions and 1012 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,39 @@
package org.mustangproject.ZUGFeRD;
import java.math.BigDecimal;
public class IZUGFeRDAllowanceChargeImpl implements IZUGFeRDAllowanceCharge {
private BigDecimal totalAmount;
private String reason;
private BigDecimal taxPercent;
@Override
public BigDecimal getTotalAmount() {
return totalAmount;
}
@Override
public String getReason() {
return reason;
}
@Override
public BigDecimal getTaxPercent() {
return taxPercent;
}
public IZUGFeRDAllowanceChargeImpl setTotalAmount(BigDecimal totalAmount) {
this.totalAmount = totalAmount;
return this;
}
public IZUGFeRDAllowanceChargeImpl setReason(String reason) {
this.reason = reason;
return this;
}
public IZUGFeRDAllowanceChargeImpl setTaxPercent(BigDecimal taxPercent) {
this.taxPercent = taxPercent;
return this;
}
}

View File

@@ -0,0 +1,70 @@
package org.mustangproject.ZUGFeRD;
public class IZUGFeRDExportableContactImpl implements IZUGFeRDExportableContact {
private String name;
private String zIP;
private String vATID;
private String country;
private String location;
private String street;
@Override
public String getName() {
return name;
}
@Override
public String getZIP() {
return zIP;
}
@Override
public String getVATID() {
return vATID;
}
@Override
public String getCountry() {
return country;
}
@Override
public String getLocation() {
return location;
}
@Override
public String getStreet() {
return street;
}
public IZUGFeRDExportableContactImpl setName(String name) {
this.name = name;
return this;
}
public IZUGFeRDExportableContactImpl setZIP(String zIP) {
this.zIP = zIP;
return this;
}
public IZUGFeRDExportableContactImpl setVATID(String vATID) {
this.vATID = vATID;
return this;
}
public IZUGFeRDExportableContactImpl setCountry(String country) {
this.country = country;
return this;
}
public IZUGFeRDExportableContactImpl setLocation(String location) {
this.location = location;
return this;
}
public IZUGFeRDExportableContactImpl setStreet(String street) {
this.street = street;
return this;
}
}

View File

@@ -0,0 +1,61 @@
package org.mustangproject.ZUGFeRD;
import java.math.BigDecimal;
public class IZUGFeRDExportableItemImpl implements IZUGFeRDExportableItem {
private IZUGFeRDExportableProduct product;
private IZUGFeRDAllowanceCharge[] itemAllowances;
private IZUGFeRDAllowanceCharge[] itemCharges;
private BigDecimal price;
private BigDecimal quantity;
@Override
public IZUGFeRDExportableProduct getProduct() {
return product;
}
@Override
public IZUGFeRDAllowanceCharge[] getItemAllowances() {
return itemAllowances;
}
@Override
public IZUGFeRDAllowanceCharge[] getItemCharges() {
return itemCharges;
}
@Override
public BigDecimal getPrice() {
return price;
}
@Override
public BigDecimal getQuantity() {
return quantity;
}
public IZUGFeRDExportableItemImpl setProduct(IZUGFeRDExportableProduct product) {
this.product = product;
return this;
}
public IZUGFeRDExportableItemImpl setItemAllowances(IZUGFeRDAllowanceCharge[] itemAllowances) {
this.itemAllowances = itemAllowances;
return this;
}
public IZUGFeRDExportableItemImpl setItemCharges(IZUGFeRDAllowanceCharge[] itemCharges) {
this.itemCharges = itemCharges;
return this;
}
public IZUGFeRDExportableItemImpl setPrice(BigDecimal price) {
this.price = price;
return this;
}
public IZUGFeRDExportableItemImpl setQuantity(BigDecimal quantity) {
this.quantity = quantity;
return this;
}
}

View File

@@ -0,0 +1,50 @@
package org.mustangproject.ZUGFeRD;
import java.math.BigDecimal;
public class IZUGFeRDExportableProductImpl implements IZUGFeRDExportableProduct {
private String unit;
private String name;
private String description;
private BigDecimal vatPercent;
@Override
public String getUnit() {
return unit;
}
@Override
public String getName() {
return name;
}
@Override
public String getDescription() {
return description;
}
@Override
public BigDecimal getVATPercent() {
return vatPercent;
}
public IZUGFeRDExportableProductImpl setUnit(String unit) {
this.unit = unit;
return this;
}
public IZUGFeRDExportableProductImpl setName(String name) {
this.name = name;
return this;
}
public IZUGFeRDExportableProductImpl setDescription(String description) {
this.description = description;
return this;
}
public IZUGFeRDExportableProductImpl setVatPercent(BigDecimal vatPercent) {
this.vatPercent = vatPercent;
return this;
}
}

View File

@@ -0,0 +1,270 @@
package org.mustangproject.ZUGFeRD;
import java.util.Date;
public class IZUGFeRDExportableTransactionImpl implements IZUGFeRDExportableTransaction {
private String number;
private Date issueDate;
private String ownOrganisationFullPlaintextInfo;
private Date dueDate;
private IZUGFeRDAllowanceCharge[] zFAllowances;
private IZUGFeRDAllowanceCharge[] zFCharges;
private IZUGFeRDAllowanceCharge[] zFLogisticsServiceCharges;
private IZUGFeRDExportableItem[] zFItems;
private IZUGFeRDExportableContact recipient;
private String ownBIC;
private String ownBankName;
private String ownIBAN;
private String ownTaxID;
private String ownVATID;
private String ownOrganisationName;
private String ownStreet;
private String ownZIP;
private String ownLocation;
private String ownCountry;
private Date deliveryDate;
private String currency;
private String ownPaymentInfoText;
private String paymentTermDescription;
private String referenceNumber;
@Override
public String getNumber() {
return number;
}
@Override
public Date getIssueDate() {
return issueDate;
}
@Override
public String getOwnOrganisationFullPlaintextInfo() {
return ownOrganisationFullPlaintextInfo;
}
@Override
public Date getDueDate() {
return dueDate;
}
@Override
public IZUGFeRDAllowanceCharge[] getZFAllowances() {
return zFAllowances;
}
@Override
public IZUGFeRDAllowanceCharge[] getZFCharges() {
return zFCharges;
}
@Override
public IZUGFeRDAllowanceCharge[] getZFLogisticsServiceCharges() {
return zFLogisticsServiceCharges;
}
@Override
public IZUGFeRDExportableItem[] getZFItems() {
return zFItems;
}
@Override
public IZUGFeRDExportableContact getRecipient() {
return recipient;
}
@Override
public String getOwnBIC() {
return ownBIC;
}
@Override
public String getOwnBankName() {
return ownBankName;
}
@Override
public String getOwnIBAN() {
return ownIBAN;
}
@Override
public String getOwnTaxID() {
return ownTaxID;
}
@Override
public String getOwnVATID() {
return ownVATID;
}
@Override
public String getOwnOrganisationName() {
return ownOrganisationName;
}
@Override
public String getOwnStreet() {
return ownStreet;
}
@Override
public String getOwnZIP() {
return ownZIP;
}
@Override
public String getOwnLocation() {
return ownLocation;
}
@Override
public String getOwnCountry() {
return ownCountry;
}
@Override
public Date getDeliveryDate() {
return deliveryDate;
}
@Override
public String getCurrency() {
return currency;
}
@Override
public String getOwnPaymentInfoText() {
return ownPaymentInfoText;
}
@Override
public String getPaymentTermDescription() {
return paymentTermDescription;
}
@Override
public String getReferenceNumber() {
return referenceNumber;
}
public IZUGFeRDExportableTransactionImpl setNumber(String number) {
this.number = number;
return this;
}
public IZUGFeRDExportableTransactionImpl setIssueDate(Date issueDate) {
this.issueDate = issueDate;
return this;
}
public IZUGFeRDExportableTransactionImpl setOwnOrganisationFullPlaintextInfo(String ownOrganisationFullPlaintextInfo) {
this.ownOrganisationFullPlaintextInfo = ownOrganisationFullPlaintextInfo;
return this;
}
public IZUGFeRDExportableTransactionImpl setDueDate(Date dueDate) {
this.dueDate = dueDate;
return this;
}
public IZUGFeRDExportableTransactionImpl setZFAllowances(IZUGFeRDAllowanceCharge... zFAllowances) {
this.zFAllowances = zFAllowances;
return this;
}
public IZUGFeRDExportableTransactionImpl setZFCharges(IZUGFeRDAllowanceCharge... zFCharges) {
this.zFCharges = zFCharges;
return this;
}
public IZUGFeRDExportableTransactionImpl setZFLogisticsServiceCharges(IZUGFeRDAllowanceCharge... zFLogisticsServiceCharges) {
this.zFLogisticsServiceCharges = zFLogisticsServiceCharges;
return this;
}
public IZUGFeRDExportableTransactionImpl setZFItems(IZUGFeRDExportableItem... zFItems) {
this.zFItems = zFItems;
return this;
}
public IZUGFeRDExportableTransactionImpl setRecipient(IZUGFeRDExportableContact recipient) {
this.recipient = recipient;
return this;
}
public IZUGFeRDExportableTransactionImpl setOwnBIC(String ownBIC) {
this.ownBIC = ownBIC;
return this;
}
public IZUGFeRDExportableTransactionImpl setOwnBankName(String ownBankName) {
this.ownBankName = ownBankName;
return this;
}
public IZUGFeRDExportableTransactionImpl setOwnIBAN(String ownIBAN) {
this.ownIBAN = ownIBAN;
return this;
}
public IZUGFeRDExportableTransactionImpl setOwnTaxID(String ownTaxID) {
this.ownTaxID = ownTaxID;
return this;
}
public IZUGFeRDExportableTransactionImpl setOwnVATID(String ownVATID) {
this.ownVATID = ownVATID;
return this;
}
public IZUGFeRDExportableTransactionImpl setOwnOrganisationName(String ownOrganisationName) {
this.ownOrganisationName = ownOrganisationName;
return this;
}
public IZUGFeRDExportableTransactionImpl setOwnStreet(String ownStreet) {
this.ownStreet = ownStreet;
return this;
}
public IZUGFeRDExportableTransactionImpl setOwnZIP(String ownZIP) {
this.ownZIP = ownZIP;
return this;
}
public IZUGFeRDExportableTransactionImpl setOwnLocation(String ownLocation) {
this.ownLocation = ownLocation;
return this;
}
public IZUGFeRDExportableTransactionImpl setOwnCountry(String ownCountry) {
this.ownCountry = ownCountry;
return this;
}
public IZUGFeRDExportableTransactionImpl setDeliveryDate(Date deliveryDate) {
this.deliveryDate = deliveryDate;
return this;
}
public IZUGFeRDExportableTransactionImpl setCurrency(String currency) {
this.currency = currency;
return this;
}
public IZUGFeRDExportableTransactionImpl setOwnPaymentInfoText(String ownPaymentInfoText) {
this.ownPaymentInfoText = ownPaymentInfoText;
return this;
}
public IZUGFeRDExportableTransactionImpl setPaymentTermDescription(String paymentTermDescription) {
this.paymentTermDescription = paymentTermDescription;
return this;
}
public IZUGFeRDExportableTransactionImpl setReferenceNumber(String referenceNumber) {
this.referenceNumber = referenceNumber;
return this;
}
}

View File

@@ -0,0 +1,56 @@
package org.mustangproject.ZUGFeRD;
import org.junit.Test;
import org.mustangproject.ZUGFeRD.model.CrossIndustryDocumentType;
import javax.xml.bind.JAXBElement;
import java.math.BigDecimal;
import java.util.Date;
import java.util.GregorianCalendar;
public class ZUGFeRDTransactionModelConverterTest {
@Test
public void convertToModel_convertsMinimalTransactionToValidXml() throws Exception {
// setup
IZUGFeRDExportableTransaction transaction = new IZUGFeRDExportableTransactionImpl()
.setIssueDate(createDate(2000, 1, 1))
.setDeliveryDate(createDate(2000, 1, 2))
.setDueDate(createDate(2000, 1, 3))
.setNumber("num")
.setRecipient(new IZUGFeRDExportableContactImpl()
.setName("recipient name")
.setStreet("recipient street")
.setLocation("recipient city")
.setCountry("recipient country")
)
.setOwnOrganisationName("own org")
.setOwnStreet("own street")
.setOwnCountry("own country")
.setOwnLocation("own city")
.setOwnBankName("own bank")
.setZFItems(
new IZUGFeRDExportableItemImpl()
.setProduct(new IZUGFeRDExportableProductImpl()
.setVatPercent(new BigDecimal("1.19"))
.setName("product name")
.setDescription("product description")
.setUnit("product unit")
)
.setQuantity(BigDecimal.ONE)
.setPrice(BigDecimal.TEN)
);
// execution
final JAXBElement<CrossIndustryDocumentType> actual =
new ZUGFeRDTransactionModelConverter(transaction).convertToModel();
// evaluation
ZUGFeRDXMLAssert.assertValidZugferd(actual);
}
private static Date createDate(int year, int month, int day) {
final GregorianCalendar calendar = new GregorianCalendar();
calendar.set(year, month-1, day);
return calendar.getTime();
}
}

View File

@@ -0,0 +1,38 @@
package org.mustangproject.ZUGFeRD;
import com.helger.schematron.ISchematronResource;
import com.helger.schematron.pure.SchematronResourcePure;
import org.junit.Assert;
import org.mustangproject.ZUGFeRD.model.CrossIndustryDocumentType;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.parsers.DocumentBuilderFactory;
public class ZUGFeRDXMLAssert {
private static final ISchematronResource SCHEMATRON = loadSchematron();
public static void assertValidZugferd(JAXBElement<CrossIndustryDocumentType> xml) throws Exception {
assertValidZugferd(toDocument(xml));
}
public static void assertValidZugferd(Node xml) throws Exception {
Assert.assertTrue("schema valid", SCHEMATRON.getSchematronValidity(xml).isValid());
}
private static Document toDocument(Object jaxbElement) throws Exception {
final Document result = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
JAXBContext.newInstance("org.mustangproject.ZUGFeRD.model").createMarshaller().marshal(jaxbElement, result);
return result;
}
private static SchematronResourcePure loadSchematron() {
final SchematronResourcePure result = SchematronResourcePure.fromClassPath("/ZUGFeRD_1p0.scmt");
if (!result.isValidSchematron ()) {
throw new IllegalArgumentException("Invalid Schematron!");
}
return result;
}
}

File diff suppressed because it is too large Load Diff