attempt for new tests(which compile but do not yet even fail)

This commit is contained in:
jstaerk
2020-09-03 21:16:07 +02:00
parent 70d110ef6d
commit d8824a15e5
6 changed files with 138 additions and 40 deletions

View File

@@ -0,0 +1,12 @@
package org.mustangproject;
import org.mustangproject.ZUGFeRD.IZUGFeRDAllowanceCharge;
import java.math.BigDecimal;
public class Allowance extends Charge {
public Allowance(BigDecimal totalAmount, BigDecimal taxPercent, String categoryCode, String reason) {
super(totalAmount, taxPercent, categoryCode, reason);
}
}

View File

@@ -0,0 +1,60 @@
package org.mustangproject;
import org.mustangproject.ZUGFeRD.IZUGFeRDAllowanceCharge;
import org.mustangproject.ZUGFeRD.IZUGFeRDExportableContact;
import java.math.BigDecimal;
public class Charge implements IZUGFeRDAllowanceCharge {
protected String reason;
protected BigDecimal totalAmount;
protected BigDecimal taxPercent;
protected String categoryCode;
public Charge(BigDecimal totalAmount, BigDecimal taxPercent, String categoryCode, String reason) {
this.totalAmount=totalAmount;
this.taxPercent=taxPercent;
this.categoryCode=categoryCode;
this.reason=reason;
}
@Override
public String getReason() {
return reason;
}
public Charge setReason(String reason) {
this.reason = reason;
return this;
}
@Override
public BigDecimal getTotalAmount() {
return totalAmount;
}
public Charge setTotalAmount(BigDecimal totalAmount) {
this.totalAmount = totalAmount;
return this;
}
@Override
public BigDecimal getTaxPercent() {
return taxPercent;
}
public Charge setTaxPercent(BigDecimal taxPercent) {
this.taxPercent = taxPercent;
return this;
}
@Override
public String getCategoryCode() {
return categoryCode;
}
public Charge setCategoryCode(String categoryCode) {
this.categoryCode = categoryCode;
return this;
}
}

View File

@@ -34,7 +34,8 @@ public class Invoice implements IExportableTransaction {
protected IZUGFeRDExportableContact ownContact = null, recipient = null, deliveryAddress = null;
protected ArrayList<IZUGFeRDExportableItem> ZFItems = null;
protected IZUGFeRDAllowanceCharge[] ZFAllowances = null, ZFCharges = null, ZFLogisticsServiceCharges = null;
protected ArrayList<IZUGFeRDAllowanceCharge> Allowances = new ArrayList<IZUGFeRDAllowanceCharge>(),
Charges = new ArrayList<IZUGFeRDAllowanceCharge>(), LogisticsServiceCharges = new ArrayList<IZUGFeRDAllowanceCharge>();
protected IZUGFeRDTradeSettlement[] getTradeSettlement = null;
protected IZUGFeRDPaymentTerms paymentTerms = null;
@@ -334,33 +335,30 @@ public class Invoice implements IExportableTransaction {
@Override
public IZUGFeRDAllowanceCharge[] getZFAllowances() {
return ZFAllowances;
if (Allowances.isEmpty()) {
return null;
} else
return Allowances.toArray(new IZUGFeRDAllowanceCharge[0]);
}
public Invoice setZFAllowances(IZUGFeRDAllowanceCharge[] ZFAllowances) {
this.ZFAllowances = ZFAllowances;
return this;
}
@Override
public IZUGFeRDAllowanceCharge[] getZFCharges() {
return ZFCharges;
if (Charges.isEmpty()) {
return null;
} else
return Charges.toArray(new IZUGFeRDAllowanceCharge[0]);
}
public Invoice setZFCharges(IZUGFeRDAllowanceCharge[] ZFCharges) {
this.ZFCharges = ZFCharges;
return this;
}
@Override
public IZUGFeRDAllowanceCharge[] getZFLogisticsServiceCharges() {
return ZFLogisticsServiceCharges;
if (LogisticsServiceCharges.isEmpty()) {
return null;
} else
return LogisticsServiceCharges.toArray(new IZUGFeRDAllowanceCharge[0]);
}
public Invoice setZFLogisticsServiceCharges(IZUGFeRDAllowanceCharge[] ZFLogisticsServiceCharges) {
this.ZFLogisticsServiceCharges = ZFLogisticsServiceCharges;
return this;
}
public IZUGFeRDTradeSettlement[] getGetTradeSettlement() {
return getTradeSettlement;
@@ -413,4 +411,12 @@ public class Invoice implements IExportableTransaction {
// this.country = country;
}
public Invoice addCharge(IZUGFeRDAllowanceCharge izac) {
Charges.add(izac);
return this;
}
public Invoice addAllowance(IZUGFeRDAllowanceCharge izac) {
Allowances.add(izac);
return this;
}
}

View File

@@ -4,11 +4,14 @@ import org.mustangproject.ZUGFeRD.IZUGFeRDAllowanceCharge;
import org.mustangproject.ZUGFeRD.IZUGFeRDExportableItem;
import java.math.BigDecimal;
import java.util.ArrayList;
public class Item implements IZUGFeRDExportableItem {
protected BigDecimal price, quantity, tax, grossPrice, lineTotalAmount;
protected String id;
protected Product product;
protected ArrayList<IZUGFeRDAllowanceCharge> Allowances = new ArrayList<IZUGFeRDAllowanceCharge>(),
Charges = new ArrayList<IZUGFeRDAllowanceCharge>();
public Item(Product product, BigDecimal price, BigDecimal quantity) {
this.price = price;
@@ -81,16 +84,32 @@ public class Item implements IZUGFeRDExportableItem {
@Override
public IZUGFeRDAllowanceCharge[] getItemAllowances() {
return null;
if (Allowances.isEmpty()) {
return null;
} else
return Allowances.toArray(new IZUGFeRDAllowanceCharge[0]);
}
@Override
public IZUGFeRDAllowanceCharge[] getItemCharges() {
return null;
if (Charges.isEmpty()) {
return null;
} else
return Charges.toArray(new IZUGFeRDAllowanceCharge[0]);
}
public Item setProduct(Product product) {
this.product = product;
return this;
}
public Item addCharge(IZUGFeRDAllowanceCharge izac) {
Charges.add(izac);
return this;
}
public Item addAllowance(IZUGFeRDAllowanceCharge izac) {
Allowances.add(izac);
return this;
}
}

View File

@@ -208,6 +208,9 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte
ensurePDFisUpgraded = false;
}
public void attachFile(String filename, byte[] data, String mimetype, String relation) {
//throw new RuntimeException("Not implemented");
}
/***
* Perform the final export to a now ZUGFeRD-enriched PDF file

View File

@@ -24,10 +24,7 @@ import java.io.InputStream;
import java.math.BigDecimal;
import java.util.Date;
import org.mustangproject.Contact;
import org.mustangproject.Invoice;
import org.mustangproject.Item;
import org.mustangproject.Product;
import org.mustangproject.*;
import org.junit.FixMethodOrder;
import org.junit.runners.MethodSorters;
@@ -78,7 +75,7 @@ public class ZF2PushTest extends TestCase {
}
}
/*
public void testAttachmentsExport() {
String orgname = "Test company";
@@ -93,10 +90,11 @@ public class ZF2PushTest extends TestCase {
.load(SOURCE_PDF)) {
ze.setTransaction(new Invoice().setDueDate(new Date()).setIssueDate(new Date()).setDeliveryDate(new Date()).setOwnOrganisationName(orgname).setOwnStreet("teststr").setOwnZIP("55232").setOwnLocation("teststadt").setOwnCountry("DE").setOwnTaxID("4711").setOwnVATID("0815").setRecipient(new Contact("Franz Müller", "0177123456", "fmueller@test.com", "teststr.12", "55232", "Entenhausen", "DE")).setNumber(number).addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(0)), amount, new BigDecimal(1.0)))
.set
);
ze.attachFile("one.pdf");
ze.attachFile("two.pdf");
byte[] b={12,13};
ze.attachFile("one.pdf", b, "Application/PDF", "Alternative");
ze.attachFile("two.pdf", b, "Application/PDF", "Alternative");
String theXML = new String(ze.getProvider().getXML());
assertTrue(theXML.contains("<rsm:CrossIndustryInvoice"));
ze.export(TARGET_PDF);
@@ -107,7 +105,7 @@ public class ZF2PushTest extends TestCase {
// now check the contents (like MustangReaderTest)
ZUGFeRDImporter zi = new ZUGFeRDImporter(TARGET_PDF);
assertFalse(zi.getUTF8().contains("EUR"));
assertTrue(zi.getUTF8().contains("EUR"));
// Reading ZUGFeRD
assertEquals(amountStr, zi.getAmount());
@@ -126,7 +124,7 @@ public class ZF2PushTest extends TestCase {
String orgname = "Test company";
String number = "123";
String amountStr = "1.00";
String amountStr = "3.00";
BigDecimal amount = new BigDecimal(amountStr);
try (InputStream SOURCE_PDF = this.getClass()
.getResourceAsStream("/MustangGnuaccountingBeispielRE-20170509_505.pdf");
@@ -136,9 +134,9 @@ public class ZF2PushTest extends TestCase {
.load(SOURCE_PDF)) {
ze.setTransaction(new Invoice().setDueDate(new Date()).setIssueDate(new Date()).setDeliveryDate(new Date()).setOwnOrganisationName(orgname).setOwnStreet("teststr").setOwnZIP("55232").setOwnLocation("teststadt").setOwnCountry("DE").setOwnTaxID("4711").setOwnVATID("0815").setRecipient(new Contact("Franz Müller", "0177123456", "fmueller@test.com", "teststr.12", "55232", "Entenhausen", "DE")).setNumber(number)
.addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(0)), amount, new BigDecimal(1.0)).addCharge(new BigDecimal(0.1)))
.addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(0)), amount, new BigDecimal(1.0)).addAllowance(new BigDecimal(0.07)))
.addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(0)), amount, new BigDecimal(1.0)).addAllowance(new BigDecimal(0.07)).addCharge(new BigDecimal(0.1)))
.addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(0)), amount, new BigDecimal(1.0)).addCharge(new Charge(new BigDecimal(100), new BigDecimal(19), "categoryCode", "String ")))
.addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(0)), amount, new BigDecimal(1.0)).addAllowance(new Allowance(new BigDecimal(100), new BigDecimal(19), "categoryCode", "String ")))
.addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(0)), amount, new BigDecimal(1.0)).addAllowance(new Allowance(new BigDecimal(100), new BigDecimal(19), "categoryCode", "String ")))
);
String theXML = new String(ze.getProvider().getXML());
@@ -151,10 +149,10 @@ public class ZF2PushTest extends TestCase {
// now check the contents (like MustangReaderTest)
ZUGFeRDImporter zi = new ZUGFeRDImporter(TARGET_PDF);
assertFalse(zi.getUTF8().contains("EUR"));
assertTrue(zi.getUTF8().contains("EUR"));
// Reading ZUGFeRD
assertEquals(amountStr, zi.getAmount());
assertEquals("9.00", zi.getAmount());
assertEquals(zi.getHolder(), orgname);
assertEquals(zi.getForeignReference(), number);
try {
@@ -166,11 +164,11 @@ public class ZF2PushTest extends TestCase {
}
public void testItemChargesAllowancesExport() {
public void testGlobalChargesAllowancesExport() {
String orgname = "Test company";
String number = "123";
String amountStr = "1.00";
String amountStr = "3.00";
BigDecimal amount = new BigDecimal(amountStr);
try (InputStream SOURCE_PDF = this.getClass()
.getResourceAsStream("/MustangGnuaccountingBeispielRE-20170509_505.pdf");
@@ -179,12 +177,12 @@ public class ZF2PushTest extends TestCase {
.setCreator(System.getProperty("user.name")).setZUGFeRDVersion(2).ignorePDFAErrors()
.load(SOURCE_PDF)) {
ze.setTransaction(new Invoice().setDueDate(new Date()).setIssueDate(new Date()).setDeliveryDate(new Date()).setOwnOrganisationName(orgname).setOwnStreet("teststr").setOwnZIP("55232").setOwnLocation("teststadt").setOwnCountry("DE").setOwnTaxID("4711").setOwnVATID("0815").setRecipient(new Contact("Franz Müller", "0177123456", "fmueller@test.com", "teststr.12", "55232", "Entenhausen", "DE")).setNumber(number)
ze.setTransaction(new Invoice().setCurrency("CHF").setDueDate(new Date()).setIssueDate(new Date()).setDeliveryDate(new Date()).setOwnOrganisationName(orgname).setOwnStreet("teststr").setOwnZIP("55232").setOwnLocation("teststadt").setOwnCountry("DE").setOwnTaxID("4711").setOwnVATID("0815").setRecipient(new Contact("Franz Müller", "0177123456", "fmueller@test.com", "teststr.12", "55232", "Entenhausen", "DE")).setNumber(number)
.addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(0)), amount, new BigDecimal(1.0)))
.addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(0)), amount, new BigDecimal(1.0)))
.addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(0)), amount, new BigDecimal(1.0)))
.addCharge(new BigDecimal(0.5))
.addAllowance(new BigDecimal(0.7))
.addCharge(new Charge(new BigDecimal(100), new BigDecimal(19), "categoryCode", "String "))
.addAllowance(new Allowance(new BigDecimal(100), new BigDecimal(19), "categoryCode", "String "))
);
String theXML = new String(ze.getProvider().getXML());
@@ -200,7 +198,7 @@ public class ZF2PushTest extends TestCase {
assertFalse(zi.getUTF8().contains("EUR"));
// Reading ZUGFeRD
assertEquals(amountStr, zi.getAmount());
assertEquals("9.00", zi.getAmount());
assertEquals(zi.getHolder(), orgname);
assertEquals(zi.getForeignReference(), number);
try {
@@ -212,7 +210,7 @@ public class ZF2PushTest extends TestCase {
}
*/
public void testCorrectionExport() {
String orgname = "Test company";