Fix tests

This commit is contained in:
Thomas Chojecki
2015-02-21 18:09:36 +01:00
parent 5329fd378b
commit b66a404212
4 changed files with 712 additions and 602 deletions

View File

@@ -1,8 +1,7 @@
package org.mustangproject.ZUGFeRD; package org.mustangproject.ZUGFeRD;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
@@ -15,155 +14,174 @@ import junit.framework.TestCase;
import junit.framework.TestSuite; import junit.framework.TestSuite;
import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.jempbox.xmp.*; import org.junit.FixMethodOrder;
import org.junit.*;
import org.junit.runners.MethodSorters; import org.junit.runners.MethodSorters;
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class MustangReaderWriterEdgeTest extends TestCase implements IZUGFeRDExportableTransaction { public class MustangReaderWriterEdgeTest extends TestCase implements IZUGFeRDExportableTransaction
{
@Override @Override
public Date getDeliveryDate() { public Date getDeliveryDate()
{
return new GregorianCalendar(2014, Calendar.JULY, 3).getTime(); return new GregorianCalendar(2014, Calendar.JULY, 3).getTime();
} }
@Override @Override
public Date getDueDate() { public Date getDueDate()
{
return new GregorianCalendar(2014, Calendar.JULY, 24).getTime(); return new GregorianCalendar(2014, Calendar.JULY, 24).getTime();
} }
@Override @Override
public Date getIssueDate() { public Date getIssueDate()
{
return new GregorianCalendar(2014, Calendar.JULY, 3).getTime(); return new GregorianCalendar(2014, Calendar.JULY, 3).getTime();
} }
@Override @Override
public String getNumber() { public String getNumber()
{
return "RE-20140703/502"; return "RE-20140703/502";
} }
@Override @Override
public String getOwnBIC() { public String getOwnBIC()
{
return "COBADEFXXX"; return "COBADEFXXX";
} }
@Override @Override
public String getOwnBankName() { public String getOwnBankName()
{
return "Commerzbank"; return "Commerzbank";
} }
@Override @Override
public String getOwnCountry() { public String getOwnCountry()
{
return "DE"; return "DE";
} }
@Override @Override
public String getOwnIBAN() { public String getOwnIBAN()
{
return "DE88 2008 0000 0970 3757 00"; return "DE88 2008 0000 0970 3757 00";
} }
@Override @Override
public String getOwnLocation() { public String getOwnLocation()
{
return "Stadthausen"; return "Stadthausen";
} }
@Override @Override
public String getOwnOrganisationName() { public String getOwnOrganisationName()
return "Öäüß'\"<em>test"; {
return "Bei Spiel GmbH";
} }
@Override @Override
public String getOwnStreet() { public String getOwnStreet()
{
return "Ecke 12"; return "Ecke 12";
} }
@Override @Override
public String getOwnTaxID() { public String getOwnTaxID()
{
return "22/815/0815/4"; return "22/815/0815/4";
} }
@Override @Override
public String getOwnVATID() { public String getOwnVATID()
{
return "DE136695976"; return "DE136695976";
} }
@Override @Override
public String getOwnZIP() { public String getOwnZIP()
{
return "12345"; return "12345";
} }
@Override @Override
public IZUGFeRDExportableContact getRecipient() { public IZUGFeRDExportableContact getRecipient()
{
return new Contact(); return new Contact();
} }
@Override @Override
public BigDecimal getTotal() { public BigDecimal getTotal()
{
return new BigDecimal("496.00"); return new BigDecimal("496.00");
} }
@Override @Override
public BigDecimal getTotalGross() { public BigDecimal getTotalGross()
{
return new BigDecimal("571.04"); return new BigDecimal("571.04");
} }
@Override @Override
public IZUGFeRDExportableItem[] getZFItems() { public IZUGFeRDExportableItem[] getZFItems()
{
Item[] allItems = new Item[3]; Item[] allItems = new Item[3];
Product designProduct = new Product("", Product designProduct = new Product("", "Künstlerische Gestaltung (Stunde): Einer Beispielrechnung", "HUR", new BigDecimal("7.000000"));
"Produkt Öäüß'\"<em>test", "HUR", new BigDecimal( Product balloonProduct = new Product("", "Luftballon: Bunt, ca. 500ml", "C62", new BigDecimal("19.000000"));
"7.000000")); Product airProduct = new Product("", "Heiße Luft pro Liter", "LTR", new BigDecimal("19.000000"));
Product balloonProduct = new Product("", "Luftballon", "C62",
new BigDecimal("19.000000"));
Product airProduct = new Product("", "Heiße Luft pro Liter", "LTR",
new BigDecimal("19.000000"));
allItems[0] = new Item(new BigDecimal("160"), new BigDecimal("171.20"), allItems[0] = new Item(new BigDecimal("160"), new BigDecimal("171.20"), new BigDecimal("1"), new BigDecimal("171.20"), designProduct);
new BigDecimal("1"), new BigDecimal("171.20"), designProduct); allItems[1] = new Item(new BigDecimal("0.79"), new BigDecimal("0.94"), new BigDecimal("400"), new BigDecimal("376.04"), balloonProduct);
allItems[1] = new Item(new BigDecimal("0.79"), new BigDecimal("0.94"), allItems[2] = new Item(new BigDecimal("0.10"), new BigDecimal("0.12"), new BigDecimal("200"), new BigDecimal("23.80"), airProduct);
new BigDecimal("400"), new BigDecimal("376.04"), balloonProduct);
allItems[2] = new Item(new BigDecimal("0.10"), new BigDecimal("0.12"),
new BigDecimal("200"), new BigDecimal("23.80"), airProduct);
return allItems; return allItems;
} }
class Contact implements IZUGFeRDExportableContact { class Contact implements IZUGFeRDExportableContact
{
@Override @Override
public String getCountry() { public String getCountry()
{
return "DE"; return "DE";
} }
@Override @Override
public String getLocation() { public String getLocation()
{
return "Spielkreis"; return "Spielkreis";
} }
@Override @Override
public String getName() { public String getName()
{
return "Theodor Est"; return "Theodor Est";
} }
@Override @Override
public String getStreet() { public String getStreet()
{
return "Bahnstr. 42"; return "Bahnstr. 42";
} }
@Override @Override
public String getVATID() { public String getVATID()
{
return "DE999999999"; return "DE999999999";
} }
@Override @Override
public String getZIP() { public String getZIP()
{
return "88802"; return "88802";
} }
} }
class Item implements IZUGFeRDExportableItem { class Item implements IZUGFeRDExportableItem
{
public Item(BigDecimal price, BigDecimal priceGross, public Item(BigDecimal price, BigDecimal priceGross, BigDecimal quantity, BigDecimal totalGross, Product product)
BigDecimal quantity, BigDecimal totalGross, Product product) { {
super(); super();
this.price = price; this.price = price;
this.priceGross = priceGross; this.priceGross = priceGross;
@@ -175,54 +193,70 @@ public class MustangReaderWriterEdgeTest extends TestCase implements IZUGFeRDExp
private BigDecimal price, priceGross, quantity, totalGross; private BigDecimal price, priceGross, quantity, totalGross;
private Product product; private Product product;
public BigDecimal getPrice() { @Override
public BigDecimal getPrice()
{
return price; return price;
} }
public void setPrice(BigDecimal price) { public void setPrice(BigDecimal price)
{
this.price = price; this.price = price;
} }
public BigDecimal getPriceGross() { @Override
public BigDecimal getPriceGross()
{
return priceGross; return priceGross;
} }
public void setPriceGross(BigDecimal priceGross) { public void setPriceGross(BigDecimal priceGross)
{
this.priceGross = priceGross; this.priceGross = priceGross;
} }
public BigDecimal getQuantity() { @Override
public BigDecimal getQuantity()
{
return quantity; return quantity;
} }
public void setQuantity(BigDecimal quantity) { public void setQuantity(BigDecimal quantity)
{
this.quantity = quantity; this.quantity = quantity;
} }
public BigDecimal getTotalGross() { @Override
public BigDecimal getTotalGross()
{
return totalGross; return totalGross;
} }
public void setTotalGross(BigDecimal totalGross) { public void setTotalGross(BigDecimal totalGross)
{
this.totalGross = totalGross; this.totalGross = totalGross;
} }
public Product getProduct() { @Override
public Product getProduct()
{
return product; return product;
} }
public void setProduct(Product product) { public void setProduct(Product product)
{
this.product = product; this.product = product;
} }
} }
class Product implements IZUGFeRDExportableProduct { class Product implements IZUGFeRDExportableProduct
{
private String description, name, unit; private String description, name, unit;
private BigDecimal VATPercent; private BigDecimal VATPercent;
public Product(String description, String name, String unit, public Product(String description, String name, String unit, BigDecimal VATPercent)
BigDecimal VATPercent) { {
super(); super();
this.description = description; this.description = description;
this.name = name; this.name = name;
@@ -230,155 +264,176 @@ public class MustangReaderWriterEdgeTest extends TestCase implements IZUGFeRDExp
this.VATPercent = VATPercent; this.VATPercent = VATPercent;
} }
public String getDescription() { @Override
public String getDescription()
{
return description; return description;
} }
public void setDescription(String description) { public void setDescription(String description)
{
this.description = description; this.description = description;
} }
public String getName() { @Override
public String getName()
{
return name; return name;
} }
public void setName(String name) { public void setName(String name)
{
this.name = name; this.name = name;
} }
public String getUnit() { @Override
public String getUnit()
{
return unit; return unit;
} }
public void setUnit(String unit) { public void setUnit(String unit)
{
this.unit = unit; this.unit = unit;
} }
public BigDecimal getVATPercent() { @Override
public BigDecimal getVATPercent()
{
return VATPercent; return VATPercent;
} }
public void setVATPercent(BigDecimal vATPercent) { public void setVATPercent(BigDecimal vATPercent)
{
VATPercent = vATPercent; VATPercent = vATPercent;
} }
} }
/** /**
* Create the test case * Create the test case
* *
* @param testName * @param testName
* name of the test case * name of the test case
*/ */
public MustangReaderWriterEdgeTest(String testName) { public MustangReaderWriterEdgeTest(String testName)
{
super(testName); super(testName);
} }
/** /**
* @return the suite of tests being tested * @return the suite of tests being tested
*/ */
public static Test suite() { public static Test suite()
{
return new TestSuite(MustangReaderWriterEdgeTest.class); return new TestSuite(MustangReaderWriterEdgeTest.class);
} }
////////// TESTS ////////////////////////////////////////////////////////////////////////////////////////// // //////// TESTS //////////////////////////////////////////////////////////////////////////////////////////
/** /**
* The importer test imports from ./src/test/MustangGnuaccountingBeispielRE-20140703_502.pdf to check the values. * The importer test imports from ./src/test/MustangGnuaccountingBeispielRE-20140703_502.pdf to check the values.
* --> as only Name Ascending is supported for Test Unit sequence, I renamed the this test-A-Export to run before
* testZExport
* *
* --> as only Name Ascending is supported for Test Unit sequence, I renamed the this test-A-Export to run before testZExport * @throws IOException
*/ */
public void testAImport() { public void testAImport() throws IOException
{
ZUGFeRDImporter zi = new ZUGFeRDImporter(); ZUGFeRDImporter zi = new ZUGFeRDImporter();
zi.extract("./src/test/MustangGnuaccountingBeispielRE-20140703_502.pdf"); zi.extractLowLevel(this.getClass().getResourceAsStream("/MustangGnuaccountingBeispielRE-20140703_502.pdf"));
// Reading ZUGFeRD // Reading ZUGFeRD
String amount=null; String amount = null;
String bic=null; String bic = null;
String iban=null; String iban = null;
String holder=null; String holder = null;
String ref=null; String ref = null;
if (zi.canParse()) { if (zi.canParse())
{
zi.parse(); zi.parse();
amount=zi.getAmount(); amount = zi.getAmount();
bic=zi.getBIC(); bic = zi.getBIC();
iban=zi.getIBAN(); iban = zi.getIBAN();
holder=zi.getHolder(); holder = zi.getHolder();
ref=zi.getForeignReference(); ref = zi.getForeignReference();
} }
assertEquals(amount, getTotalGross().toString());
assertEquals(amount, getTotalGross());
assertEquals(bic, getOwnBIC()); assertEquals(bic, getOwnBIC());
assertEquals(iban, getOwnIBAN()); assertEquals(iban, getOwnIBAN());
assertEquals(holder, getOwnOrganisationName()); assertEquals(holder, getOwnOrganisationName());
assertEquals(ref, getNumber()); assertEquals(ref, getNumber());
} }
/** /**
* The exporter test bases on @{code ./src/test/MustangGnuaccountingBeispielRE-20140703_502blanko.pdf}, adds metadata, writes * The exporter test bases on @{code ./src/test/MustangGnuaccountingBeispielRE-20140703_502blanko.pdf}, adds metadata,
* writes
* to @{code ./target/testout-*} and then imports to check the values. * to @{code ./target/testout-*} and then imports to check the values.
*
* It would not make sense to have it run before the less complex importer test (which is probably redundant) * It would not make sense to have it run before the less complex importer test (which is probably redundant)
* --> as only Name Ascending is supported for Test Unit sequence, I renamed the Exporter Test test-Z-Export * --> as only Name Ascending is supported for Test Unit sequence, I renamed the Exporter Test test-Z-Export
*/ */
public void testZExport() { public void testZExport()
final String SOURCE_PDF = "./src/test/MustangGnuaccountingBeispielRE-20140703_502blanko.pdf"; {
final InputStream SOURCE_PDF = this.getClass().getResourceAsStream("/MustangGnuaccountingBeispielRE-20140703_502blanko.pdf");
final String TARGET_PDF = "./target/testout-MustangGnuaccountingBeispielRE-20140703_502newEdge.pdf"; final String TARGET_PDF = "./target/testout-MustangGnuaccountingBeispielRE-20140703_502newEdge.pdf";
// the writing part // the writing part
PDDocument doc; PDDocument doc;
try { try
{
doc = PDDocument.load(SOURCE_PDF); doc = PDDocument.load(SOURCE_PDF);
// automatically add Zugferd to all outgoing invoices // automatically add Zugferd to all outgoing invoices
ZUGFeRDExporter ze = new ZUGFeRDExporter(); ZUGFeRDExporter ze = new ZUGFeRDExporter();
ze.PDFmakeA3compliant(doc, "My Application", ze.PDFmakeA3compliant(doc, "My Application", System.getProperty("user.name"), true);
System.getProperty("user.name"), true);
ze.PDFattachZugferdFile(doc, this); ze.PDFattachZugferdFile(doc, this);
doc.save(TARGET_PDF); doc.save(TARGET_PDF);
} catch (IOException e) { doc.close();
e.printStackTrace(); }
} catch (TransformerException e) { catch (IOException e)
e.printStackTrace(); {
} catch (Exception e) { e.printStackTrace();
}
catch (TransformerException e)
{
e.printStackTrace();
}
catch (Exception e)
{
e.printStackTrace(); e.printStackTrace();
} }
// now check the contents (like MustangReaderTest) // now check the contents (like MustangReaderTest)
ZUGFeRDImporter zi = new ZUGFeRDImporter(); ZUGFeRDImporter zi = new ZUGFeRDImporter();
zi.extract(TARGET_PDF); zi.extract(TARGET_PDF);
// Reading ZUGFeRD // Reading ZUGFeRD
String amount=null; String amount = null;
String bic=null; String bic = null;
String iban=null; String iban = null;
String holder=null; String holder = null;
String ref=null; String ref = null;
if (zi.canParse()) { if (zi.canParse())
{
zi.parse(); zi.parse();
amount=zi.getAmount(); amount = zi.getAmount();
bic=zi.getBIC(); bic = zi.getBIC();
iban=zi.getIBAN(); iban = zi.getIBAN();
holder=zi.getHolder(); holder = zi.getHolder();
ref=zi.getForeignReference(); ref = zi.getForeignReference();
} }
assertEquals(amount, getTotalGross().toString());
assertEquals(amount, getTotalGross());
assertEquals(bic, getOwnBIC()); assertEquals(bic, getOwnBIC());
assertEquals(iban, getOwnIBAN()); assertEquals(iban, getOwnIBAN());
assertEquals(holder, getOwnOrganisationName()); assertEquals(holder, getOwnOrganisationName());
assertEquals(ref, getNumber()); assertEquals(ref, getNumber());
} }
} }

View File

@@ -1,8 +1,7 @@
package org.mustangproject.ZUGFeRD; package org.mustangproject.ZUGFeRD;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
@@ -15,155 +14,174 @@ import junit.framework.TestCase;
import junit.framework.TestSuite; import junit.framework.TestSuite;
import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.jempbox.xmp.*; import org.junit.FixMethodOrder;
import org.junit.*;
import org.junit.runners.MethodSorters; import org.junit.runners.MethodSorters;
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class MustangReaderWriterTest extends TestCase implements IZUGFeRDExportableTransaction { public class MustangReaderWriterTest extends TestCase implements IZUGFeRDExportableTransaction
{
@Override @Override
public Date getDeliveryDate() { public Date getDeliveryDate()
{
return new GregorianCalendar(2014, Calendar.JULY, 3).getTime(); return new GregorianCalendar(2014, Calendar.JULY, 3).getTime();
} }
@Override @Override
public Date getDueDate() { public Date getDueDate()
{
return new GregorianCalendar(2014, Calendar.JULY, 24).getTime(); return new GregorianCalendar(2014, Calendar.JULY, 24).getTime();
} }
@Override @Override
public Date getIssueDate() { public Date getIssueDate()
{
return new GregorianCalendar(2014, Calendar.JULY, 3).getTime(); return new GregorianCalendar(2014, Calendar.JULY, 3).getTime();
} }
@Override @Override
public String getNumber() { public String getNumber()
{
return "RE-20140703/502"; return "RE-20140703/502";
} }
@Override @Override
public String getOwnBIC() { public String getOwnBIC()
{
return "COBADEFXXX"; return "COBADEFXXX";
} }
@Override @Override
public String getOwnBankName() { public String getOwnBankName()
{
return "Commerzbank"; return "Commerzbank";
} }
@Override @Override
public String getOwnCountry() { public String getOwnCountry()
{
return "DE"; return "DE";
} }
@Override @Override
public String getOwnIBAN() { public String getOwnIBAN()
{
return "DE88 2008 0000 0970 3757 00"; return "DE88 2008 0000 0970 3757 00";
} }
@Override @Override
public String getOwnLocation() { public String getOwnLocation()
{
return "Stadthausen"; return "Stadthausen";
} }
@Override @Override
public String getOwnOrganisationName() { public String getOwnOrganisationName()
{
return "Bei Spiel GmbH"; return "Bei Spiel GmbH";
} }
@Override @Override
public String getOwnStreet() { public String getOwnStreet()
{
return "Ecke 12"; return "Ecke 12";
} }
@Override @Override
public String getOwnTaxID() { public String getOwnTaxID()
{
return "22/815/0815/4"; return "22/815/0815/4";
} }
@Override @Override
public String getOwnVATID() { public String getOwnVATID()
{
return "DE136695976"; return "DE136695976";
} }
@Override @Override
public String getOwnZIP() { public String getOwnZIP()
{
return "12345"; return "12345";
} }
@Override @Override
public IZUGFeRDExportableContact getRecipient() { public IZUGFeRDExportableContact getRecipient()
{
return new Contact(); return new Contact();
} }
@Override @Override
public BigDecimal getTotal() { public BigDecimal getTotal()
{
return new BigDecimal("496.00"); return new BigDecimal("496.00");
} }
@Override @Override
public BigDecimal getTotalGross() { public BigDecimal getTotalGross()
{
return new BigDecimal("571.04"); return new BigDecimal("571.04");
} }
@Override @Override
public IZUGFeRDExportableItem[] getZFItems() { public IZUGFeRDExportableItem[] getZFItems()
{
Item[] allItems = new Item[3]; Item[] allItems = new Item[3];
Product designProduct = new Product("", Product designProduct = new Product("", "Künstlerische Gestaltung (Stunde)", "HUR", new BigDecimal("7.000000"));
"Künstlerische Gestaltung (Stunde)", "HUR", new BigDecimal( Product balloonProduct = new Product("", "Luftballon", "C62", new BigDecimal("19.000000"));
"7.000000")); Product airProduct = new Product("", "Heiße Luft pro Liter", "LTR", new BigDecimal("19.000000"));
Product balloonProduct = new Product("", "Luftballon", "C62",
new BigDecimal("19.000000"));
Product airProduct = new Product("", "Heiße Luft pro Liter", "LTR",
new BigDecimal("19.000000"));
allItems[0] = new Item(new BigDecimal("160"), new BigDecimal("171.20"), allItems[0] = new Item(new BigDecimal("160"), new BigDecimal("171.20"), new BigDecimal("1"), new BigDecimal("171.20"), designProduct);
new BigDecimal("1"), new BigDecimal("171.20"), designProduct); allItems[1] = new Item(new BigDecimal("0.79"), new BigDecimal("0.94"), new BigDecimal("400"), new BigDecimal("376.04"), balloonProduct);
allItems[1] = new Item(new BigDecimal("0.79"), new BigDecimal("0.94"), allItems[2] = new Item(new BigDecimal("0.10"), new BigDecimal("0.12"), new BigDecimal("200"), new BigDecimal("23.80"), airProduct);
new BigDecimal("400"), new BigDecimal("376.04"), balloonProduct);
allItems[2] = new Item(new BigDecimal("0.10"), new BigDecimal("0.12"),
new BigDecimal("200"), new BigDecimal("23.80"), airProduct);
return allItems; return allItems;
} }
class Contact implements IZUGFeRDExportableContact { class Contact implements IZUGFeRDExportableContact
{
@Override @Override
public String getCountry() { public String getCountry()
{
return "DE"; return "DE";
} }
@Override @Override
public String getLocation() { public String getLocation()
{
return "Spielkreis"; return "Spielkreis";
} }
@Override @Override
public String getName() { public String getName()
{
return "Theodor Est"; return "Theodor Est";
} }
@Override @Override
public String getStreet() { public String getStreet()
{
return "Bahnstr. 42"; return "Bahnstr. 42";
} }
@Override @Override
public String getVATID() { public String getVATID()
{
return "DE999999999"; return "DE999999999";
} }
@Override @Override
public String getZIP() { public String getZIP()
{
return "88802"; return "88802";
} }
} }
class Item implements IZUGFeRDExportableItem { class Item implements IZUGFeRDExportableItem
{
public Item(BigDecimal price, BigDecimal priceGross, public Item(BigDecimal price, BigDecimal priceGross, BigDecimal quantity, BigDecimal totalGross, Product product)
BigDecimal quantity, BigDecimal totalGross, Product product) { {
super(); super();
this.price = price; this.price = price;
this.priceGross = priceGross; this.priceGross = priceGross;
@@ -175,54 +193,70 @@ public class MustangReaderWriterTest extends TestCase implements IZUGFeRDExporta
private BigDecimal price, priceGross, quantity, totalGross; private BigDecimal price, priceGross, quantity, totalGross;
private Product product; private Product product;
public BigDecimal getPrice() { @Override
public BigDecimal getPrice()
{
return price; return price;
} }
public void setPrice(BigDecimal price) { public void setPrice(BigDecimal price)
{
this.price = price; this.price = price;
} }
public BigDecimal getPriceGross() { @Override
public BigDecimal getPriceGross()
{
return priceGross; return priceGross;
} }
public void setPriceGross(BigDecimal priceGross) { public void setPriceGross(BigDecimal priceGross)
{
this.priceGross = priceGross; this.priceGross = priceGross;
} }
public BigDecimal getQuantity() { @Override
public BigDecimal getQuantity()
{
return quantity; return quantity;
} }
public void setQuantity(BigDecimal quantity) { public void setQuantity(BigDecimal quantity)
{
this.quantity = quantity; this.quantity = quantity;
} }
public BigDecimal getTotalGross() { @Override
public BigDecimal getTotalGross()
{
return totalGross; return totalGross;
} }
public void setTotalGross(BigDecimal totalGross) { public void setTotalGross(BigDecimal totalGross)
{
this.totalGross = totalGross; this.totalGross = totalGross;
} }
public Product getProduct() { @Override
public Product getProduct()
{
return product; return product;
} }
public void setProduct(Product product) { public void setProduct(Product product)
{
this.product = product; this.product = product;
} }
} }
class Product implements IZUGFeRDExportableProduct { class Product implements IZUGFeRDExportableProduct
{
private String description, name, unit; private String description, name, unit;
private BigDecimal VATPercent; private BigDecimal VATPercent;
public Product(String description, String name, String unit, public Product(String description, String name, String unit, BigDecimal VATPercent)
BigDecimal VATPercent) { {
super(); super();
this.description = description; this.description = description;
this.name = name; this.name = name;
@@ -230,155 +264,176 @@ public class MustangReaderWriterTest extends TestCase implements IZUGFeRDExporta
this.VATPercent = VATPercent; this.VATPercent = VATPercent;
} }
public String getDescription() { @Override
public String getDescription()
{
return description; return description;
} }
public void setDescription(String description) { public void setDescription(String description)
{
this.description = description; this.description = description;
} }
public String getName() { @Override
public String getName()
{
return name; return name;
} }
public void setName(String name) { public void setName(String name)
{
this.name = name; this.name = name;
} }
public String getUnit() { @Override
public String getUnit()
{
return unit; return unit;
} }
public void setUnit(String unit) { public void setUnit(String unit)
{
this.unit = unit; this.unit = unit;
} }
public BigDecimal getVATPercent() { @Override
public BigDecimal getVATPercent()
{
return VATPercent; return VATPercent;
} }
public void setVATPercent(BigDecimal vATPercent) { public void setVATPercent(BigDecimal vATPercent)
{
VATPercent = vATPercent; VATPercent = vATPercent;
} }
} }
/** /**
* Create the test case * Create the test case
* *
* @param testName * @param testName
* name of the test case * name of the test case
*/ */
public MustangReaderWriterTest(String testName) { public MustangReaderWriterTest(String testName)
{
super(testName); super(testName);
} }
/** /**
* @return the suite of tests being tested * @return the suite of tests being tested
*/ */
public static Test suite() { public static Test suite()
{
return new TestSuite(MustangReaderWriterTest.class); return new TestSuite(MustangReaderWriterTest.class);
} }
////////// TESTS ////////////////////////////////////////////////////////////////////////////////////////// // //////// TESTS //////////////////////////////////////////////////////////////////////////////////////////
/** /**
* The importer test imports from ./src/test/MustangGnuaccountingBeispielRE-20140703_502.pdf to check the values. * The importer test imports from ./src/test/MustangGnuaccountingBeispielRE-20140703_502.pdf to check the values.
* --> as only Name Ascending is supported for Test Unit sequence, I renamed the this test-A-Export to run before
* testZExport
* *
* --> as only Name Ascending is supported for Test Unit sequence, I renamed the this test-A-Export to run before testZExport * @throws IOException
*/ */
public void testAImport() { public void testAImport() throws IOException
{
ZUGFeRDImporter zi = new ZUGFeRDImporter(); ZUGFeRDImporter zi = new ZUGFeRDImporter();
zi.extract("./src/test/MustangGnuaccountingBeispielRE-20140703_502.pdf"); InputStream inputStream = this.getClass().getResourceAsStream("/MustangGnuaccountingBeispielRE-20140703_502.pdf");
zi.extractLowLevel(inputStream);
// Reading ZUGFeRD // Reading ZUGFeRD
String amount=null; String amount = null;
String bic=null; String bic = null;
String iban=null; String iban = null;
String holder=null; String holder = null;
String ref=null; String ref = null;
if (zi.canParse()) { if (zi.canParse())
{
zi.parse(); zi.parse();
amount=zi.getAmount(); amount = zi.getAmount();
bic=zi.getBIC(); bic = zi.getBIC();
iban=zi.getIBAN(); iban = zi.getIBAN();
holder=zi.getHolder(); holder = zi.getHolder();
ref=zi.getForeignReference(); ref = zi.getForeignReference();
} }
assertEquals(amount, getTotalGross().toString());
assertEquals(amount, getTotalGross());
assertEquals(bic, getOwnBIC()); assertEquals(bic, getOwnBIC());
assertEquals(iban, getOwnIBAN()); assertEquals(iban, getOwnIBAN());
assertEquals(holder, getOwnOrganisationName()); assertEquals(holder, getOwnOrganisationName());
assertEquals(ref, getNumber()); assertEquals(ref, getNumber());
} }
/** /**
* The exporter test bases on @{code ./src/test/MustangGnuaccountingBeispielRE-20140703_502blanko.pdf}, adds metadata, writes * The exporter test bases on @{code ./src/test/MustangGnuaccountingBeispielRE-20140703_502blanko.pdf}, adds metadata,
* writes
* to @{code ./target/testout-*} and then imports to check the values. * to @{code ./target/testout-*} and then imports to check the values.
*
* It would not make sense to have it run before the less complex importer test (which is probably redundant) * It would not make sense to have it run before the less complex importer test (which is probably redundant)
* --> as only Name Ascending is supported for Test Unit sequence, I renamed the Exporter Test test-Z-Export * --> as only Name Ascending is supported for Test Unit sequence, I renamed the Exporter Test test-Z-Export
*/ */
public void testZExport() { public void testZExport()
final String SOURCE_PDF = "./src/test/MustangGnuaccountingBeispielRE-20140703_502blanko.pdf"; {
final InputStream SOURCE_PDF = this.getClass().getResourceAsStream("/MustangGnuaccountingBeispielRE-20140703_502blanko.pdf");
final String TARGET_PDF = "./target/testout-MustangGnuaccountingBeispielRE-20140703_502new.pdf"; final String TARGET_PDF = "./target/testout-MustangGnuaccountingBeispielRE-20140703_502new.pdf";
// the writing part // the writing part
PDDocument doc; PDDocument doc;
try { try
{
doc = PDDocument.load(SOURCE_PDF); doc = PDDocument.load(SOURCE_PDF);
// automatically add Zugferd to all outgoing invoices // automatically add Zugferd to all outgoing invoices
ZUGFeRDExporter ze = new ZUGFeRDExporter(); ZUGFeRDExporter ze = new ZUGFeRDExporter();
ze.PDFmakeA3compliant(doc, "My Application", ze.PDFmakeA3compliant(doc, "My Application", System.getProperty("user.name"), true);
System.getProperty("user.name"), true);
ze.PDFattachZugferdFile(doc, this); ze.PDFattachZugferdFile(doc, this);
doc.save(TARGET_PDF); doc.save(TARGET_PDF);
} catch (IOException e) { doc.close();
e.printStackTrace(); }
} catch (TransformerException e) { catch (IOException e)
e.printStackTrace(); {
} catch (Exception e) { e.printStackTrace();
}
catch (TransformerException e)
{
e.printStackTrace();
}
catch (Exception e)
{
e.printStackTrace(); e.printStackTrace();
} }
// now check the contents (like MustangReaderTest) // now check the contents (like MustangReaderTest)
ZUGFeRDImporter zi = new ZUGFeRDImporter(); ZUGFeRDImporter zi = new ZUGFeRDImporter();
zi.extract(TARGET_PDF); zi.extract(TARGET_PDF);
// Reading ZUGFeRD // Reading ZUGFeRD
String amount=null; String amount = null;
String bic=null; String bic = null;
String iban=null; String iban = null;
String holder=null; String holder = null;
String ref=null; String ref = null;
if (zi.canParse()) { if (zi.canParse())
{
zi.parse(); zi.parse();
amount=zi.getAmount(); amount = zi.getAmount();
bic=zi.getBIC(); bic = zi.getBIC();
iban=zi.getIBAN(); iban = zi.getIBAN();
holder=zi.getHolder(); holder = zi.getHolder();
ref=zi.getForeignReference(); ref = zi.getForeignReference();
} }
assertEquals(amount, getTotalGross().toString());
assertEquals(amount, getTotalGross());
assertEquals(bic, getOwnBIC()); assertEquals(bic, getOwnBIC());
assertEquals(iban, getOwnIBAN()); assertEquals(iban, getOwnIBAN());
assertEquals(holder, getOwnOrganisationName()); assertEquals(holder, getOwnOrganisationName());
assertEquals(ref, getNumber()); assertEquals(ref, getNumber());
} }
} }