new sample file
This commit is contained in:
@@ -8,10 +8,6 @@ import java.text.SimpleDateFormat;
|
|||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
import java.util.logging.LogManager;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import javax.xml.transform.TransformerException;
|
|
||||||
|
|
||||||
import org.junit.FixMethodOrder;
|
import org.junit.FixMethodOrder;
|
||||||
import org.junit.runners.MethodSorters;
|
import org.junit.runners.MethodSorters;
|
||||||
@@ -21,466 +17,421 @@ import junit.framework.TestCase;
|
|||||||
import junit.framework.TestSuite;
|
import junit.framework.TestSuite;
|
||||||
|
|
||||||
@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(2017, Calendar.NOVEMBER, 17).getTime();
|
||||||
{
|
}
|
||||||
return new GregorianCalendar(2017, Calendar.MAY, 7).getTime();
|
|
||||||
}
|
@Override
|
||||||
|
public Date getDueDate() {
|
||||||
@Override
|
return new GregorianCalendar(2017, Calendar.DECEMBER, 9).getTime();
|
||||||
public Date getDueDate()
|
}
|
||||||
{
|
|
||||||
return new GregorianCalendar(2017, Calendar.MAY, 30).getTime();
|
@Override
|
||||||
}
|
public Date getIssueDate() {
|
||||||
|
return new GregorianCalendar(2017, Calendar.NOVEMBER, 18).getTime();
|
||||||
@Override
|
}
|
||||||
public Date getIssueDate()
|
|
||||||
{
|
@Override
|
||||||
return new GregorianCalendar(2017, Calendar.MAY, 9).getTime();
|
public String getNumber() {
|
||||||
}
|
return "RE-20171118/506";
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public String getNumber()
|
@Override
|
||||||
{
|
public String getOwnBIC() {
|
||||||
return "RE-20170509/505";
|
return "COBADEFFXXX";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getOwnBIC()
|
public String getOwnBankName() {
|
||||||
{
|
return "Commerzbank";
|
||||||
return "COBADEFFXXX";
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
@Override
|
public String getOwnCountry() {
|
||||||
public String getOwnBankName()
|
return "DE";
|
||||||
{
|
}
|
||||||
return "Commerzbank";
|
|
||||||
}
|
@Override
|
||||||
|
public String getOwnIBAN() {
|
||||||
@Override
|
return "DE88 2008 0000 0970 3757 00";
|
||||||
public String getOwnCountry()
|
}
|
||||||
{
|
|
||||||
return "DE";
|
@Override
|
||||||
}
|
public String getOwnLocation() {
|
||||||
|
return "Stadthausen";
|
||||||
@Override
|
}
|
||||||
public String getOwnIBAN()
|
|
||||||
{
|
@Override
|
||||||
return "DE88 2008 0000 0970 3757 00";
|
public String getOwnOrganisationName() {
|
||||||
}
|
return "Bei Spiel GmbH";
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public String getOwnLocation()
|
@Override
|
||||||
{
|
public String getOwnStreet() {
|
||||||
return "Stadthausen";
|
return "Ecke 12";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getOwnOrganisationName()
|
public String getOwnTaxID() {
|
||||||
{
|
return "22/815/0815/4";
|
||||||
return "Bei Spiel GmbH";
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
@Override
|
public String getOwnVATID() {
|
||||||
public String getOwnStreet()
|
return "DE136695976";
|
||||||
{
|
}
|
||||||
return "Ecke 12";
|
|
||||||
}
|
@Override
|
||||||
|
public String getOwnZIP() {
|
||||||
@Override
|
return "12345";
|
||||||
public String getOwnTaxID()
|
}
|
||||||
{
|
|
||||||
return "22/815/0815/4";
|
@Override
|
||||||
}
|
public IZUGFeRDExportableContact getRecipient() {
|
||||||
|
return new Contact();
|
||||||
@Override
|
}
|
||||||
public String getOwnVATID()
|
|
||||||
{
|
@Override
|
||||||
return "DE136695976";
|
public String getOwnOrganisationFullPlaintextInfo() {
|
||||||
}
|
return null;
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public String getOwnZIP()
|
@Override
|
||||||
{
|
public String getCurrency() {
|
||||||
return "12345";
|
return "EUR";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IZUGFeRDExportableContact getRecipient()
|
public IZUGFeRDExportableItem[] getZFItems() {
|
||||||
{
|
Item[] allItems = new Item[3];
|
||||||
return new Contact();
|
Product designProduct = new Product("", "Künstlerische Gestaltung (Stunde): Einer Beispielrechnung", "HUR",
|
||||||
}
|
new BigDecimal("7.000000"));
|
||||||
|
Product balloonProduct = new Product("", "Luftballon: Bunt, ca. 500ml", "C62", new BigDecimal("19.000000"));
|
||||||
@Override
|
Product airProduct = new Product("", "Heiße Luft pro Liter", "LTR", new BigDecimal("19.000000"));
|
||||||
public String getOwnOrganisationFullPlaintextInfo()
|
|
||||||
{
|
allItems[0] = new Item(new BigDecimal("160"), new BigDecimal("1"), designProduct);
|
||||||
return null;
|
allItems[1] = new Item(new BigDecimal("0.79"), new BigDecimal("400"), balloonProduct);
|
||||||
}
|
allItems[2] = new Item(new BigDecimal("0.10"), new BigDecimal("200"), airProduct);
|
||||||
|
return allItems;
|
||||||
@Override
|
}
|
||||||
public String getCurrency()
|
|
||||||
{
|
@Override
|
||||||
return "EUR";
|
public String getOwnPaymentInfoText() {
|
||||||
}
|
return "Überweisung";
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public IZUGFeRDExportableItem[] getZFItems()
|
@Override
|
||||||
{
|
public String getPaymentTermDescription() {
|
||||||
Item[] allItems = new Item[3];
|
SimpleDateFormat germanDateFormat = new SimpleDateFormat("dd.MM.yyyy");
|
||||||
Product designProduct = new Product("", "Künstlerische Gestaltung (Stunde): Einer Beispielrechnung", "HUR", new BigDecimal("7.000000"));
|
return "Zahlbar ohne Abzug bis zum " + germanDateFormat.format(getDueDate());
|
||||||
Product balloonProduct = new Product("", "Luftballon: Bunt, ca. 500ml", "C62", new BigDecimal("19.000000"));
|
}
|
||||||
Product airProduct = new Product("", "Heiße Luft pro Liter", "LTR", new BigDecimal("19.000000"));
|
|
||||||
|
@Override
|
||||||
allItems[0] = new Item(new BigDecimal("160"), new BigDecimal("1"), designProduct);
|
public IZUGFeRDAllowanceCharge[] getZFAllowances() {
|
||||||
allItems[1] = new Item(new BigDecimal("0.79"), new BigDecimal("400"), balloonProduct);
|
return null;
|
||||||
allItems[2] = new Item(new BigDecimal("0.10"), new BigDecimal("200"), airProduct);
|
// throw new UnsupportedOperationException("Not supported yet."); //To change
|
||||||
return allItems;
|
// body of generated methods, choose Tools | Templates.
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getOwnPaymentInfoText() {
|
public IZUGFeRDAllowanceCharge[] getZFCharges() {
|
||||||
return "Überweisung";
|
return null;
|
||||||
}
|
// throw new UnsupportedOperationException("Not supported yet."); //To change
|
||||||
|
// body of generated methods, choose Tools | Templates.
|
||||||
@Override
|
}
|
||||||
public String getPaymentTermDescription() {
|
|
||||||
SimpleDateFormat germanDateFormat = new SimpleDateFormat("dd.MM.yyyy");
|
@Override
|
||||||
return "Zahlbar ohne Abzug bis zum " + germanDateFormat.format(getDueDate());
|
public IZUGFeRDAllowanceCharge[] getZFLogisticsServiceCharges() {
|
||||||
}
|
return null;
|
||||||
|
// throw new UnsupportedOperationException("Not supported yet."); //To change
|
||||||
@Override
|
// body of generated methods, choose Tools | Templates.
|
||||||
public IZUGFeRDAllowanceCharge[] getZFAllowances() {
|
}
|
||||||
return null;
|
|
||||||
//throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
@Override
|
||||||
}
|
public String getReferenceNumber() {
|
||||||
|
return null;
|
||||||
@Override
|
}
|
||||||
public IZUGFeRDAllowanceCharge[] getZFCharges() {
|
|
||||||
return null;
|
class Contact implements IZUGFeRDExportableContact {
|
||||||
//throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
|
||||||
}
|
@Override
|
||||||
|
public String getCountry() {
|
||||||
@Override
|
return "DE";
|
||||||
public IZUGFeRDAllowanceCharge[] getZFLogisticsServiceCharges() {
|
}
|
||||||
return null;
|
|
||||||
//throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
@Override
|
||||||
}
|
public String getLocation() {
|
||||||
|
return "Spielkreis";
|
||||||
@Override
|
}
|
||||||
public String getReferenceNumber() {
|
|
||||||
return null;
|
@Override
|
||||||
}
|
public String getName() {
|
||||||
|
return "Theodor Est";
|
||||||
class Contact implements IZUGFeRDExportableContact
|
}
|
||||||
{
|
|
||||||
|
@Override
|
||||||
@Override
|
public String getStreet() {
|
||||||
public String getCountry()
|
return "Bahnstr. 42";
|
||||||
{
|
}
|
||||||
return "DE";
|
|
||||||
}
|
@Override
|
||||||
|
public String getVATID() {
|
||||||
@Override
|
return "DE999999999";
|
||||||
public String getLocation()
|
}
|
||||||
{
|
|
||||||
return "Spielkreis";
|
@Override
|
||||||
}
|
public String getZIP() {
|
||||||
|
return "88802";
|
||||||
@Override
|
}
|
||||||
public String getName()
|
}
|
||||||
{
|
|
||||||
return "Theodor Est";
|
class Item implements IZUGFeRDExportableItem {
|
||||||
}
|
|
||||||
|
public Item(BigDecimal price, BigDecimal quantity, Product product) {
|
||||||
@Override
|
super();
|
||||||
public String getStreet()
|
this.price = price;
|
||||||
{
|
this.quantity = quantity;
|
||||||
return "Bahnstr. 42";
|
this.product = product;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private BigDecimal price, quantity;
|
||||||
public String getVATID()
|
private Product product;
|
||||||
{
|
|
||||||
return "DE999999999";
|
@Override
|
||||||
}
|
public BigDecimal getPrice() {
|
||||||
|
return price;
|
||||||
@Override
|
}
|
||||||
public String getZIP()
|
|
||||||
{
|
public void setPrice(BigDecimal price) {
|
||||||
return "88802";
|
this.price = price;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
class Item implements IZUGFeRDExportableItem
|
public BigDecimal getQuantity() {
|
||||||
{
|
return quantity;
|
||||||
|
}
|
||||||
public Item(BigDecimal price, BigDecimal quantity, Product product)
|
|
||||||
{
|
public void setQuantity(BigDecimal quantity) {
|
||||||
super();
|
this.quantity = quantity;
|
||||||
this.price = price;
|
}
|
||||||
this.quantity = quantity;
|
|
||||||
this.product = product;
|
@Override
|
||||||
}
|
public Product getProduct() {
|
||||||
|
return product;
|
||||||
private BigDecimal price, quantity;
|
}
|
||||||
private Product product;
|
|
||||||
|
public void setProduct(Product product) {
|
||||||
@Override
|
this.product = product;
|
||||||
public BigDecimal getPrice()
|
}
|
||||||
{
|
|
||||||
return price;
|
@Override
|
||||||
}
|
public IZUGFeRDAllowanceCharge[] getItemAllowances() {
|
||||||
|
return null;
|
||||||
public void setPrice(BigDecimal price)
|
}
|
||||||
{
|
|
||||||
this.price = price;
|
@Override
|
||||||
}
|
public IZUGFeRDAllowanceCharge[] getItemCharges() {
|
||||||
|
return null;
|
||||||
@Override
|
}
|
||||||
public BigDecimal getQuantity()
|
|
||||||
{
|
}
|
||||||
return quantity;
|
|
||||||
}
|
class Product implements IZUGFeRDExportableProduct {
|
||||||
|
private String description, name, unit;
|
||||||
public void setQuantity(BigDecimal quantity)
|
private BigDecimal VATPercent;
|
||||||
{
|
|
||||||
this.quantity = quantity;
|
public Product(String description, String name, String unit, BigDecimal VATPercent) {
|
||||||
}
|
super();
|
||||||
|
this.description = description;
|
||||||
@Override
|
this.name = name;
|
||||||
public Product getProduct()
|
this.unit = unit;
|
||||||
{
|
this.VATPercent = VATPercent;
|
||||||
return product;
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
public void setProduct(Product product)
|
public String getDescription() {
|
||||||
{
|
return description;
|
||||||
this.product = product;
|
}
|
||||||
}
|
|
||||||
|
public void setDescription(String description) {
|
||||||
@Override
|
this.description = description;
|
||||||
public IZUGFeRDAllowanceCharge[] getItemAllowances() {
|
}
|
||||||
return null;
|
|
||||||
}
|
@Override
|
||||||
|
public String getName() {
|
||||||
@Override
|
return name;
|
||||||
public IZUGFeRDAllowanceCharge[] getItemCharges() {
|
}
|
||||||
return null;
|
|
||||||
}
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
class Product implements IZUGFeRDExportableProduct
|
@Override
|
||||||
{
|
public String getUnit() {
|
||||||
private String description, name, unit;
|
return unit;
|
||||||
private BigDecimal VATPercent;
|
}
|
||||||
|
|
||||||
public Product(String description, String name, String unit, BigDecimal VATPercent)
|
public void setUnit(String unit) {
|
||||||
{
|
this.unit = unit;
|
||||||
super();
|
}
|
||||||
this.description = description;
|
|
||||||
this.name = name;
|
@Override
|
||||||
this.unit = unit;
|
public BigDecimal getVATPercent() {
|
||||||
this.VATPercent = VATPercent;
|
return VATPercent;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void setVATPercent(BigDecimal VATPercent) {
|
||||||
public String getDescription()
|
this.VATPercent = VATPercent;
|
||||||
{
|
}
|
||||||
return description;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDescription(String description)
|
/**
|
||||||
{
|
* Create the test case
|
||||||
this.description = description;
|
*
|
||||||
}
|
* @param testName
|
||||||
|
* name of the test case
|
||||||
@Override
|
*/
|
||||||
public String getName()
|
public MustangReaderWriterTest(String testName) {
|
||||||
{
|
super(testName);
|
||||||
return name;
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
public void setName(String name)
|
* @return the suite of tests being tested
|
||||||
{
|
*/
|
||||||
this.name = name;
|
public static Test suite() {
|
||||||
}
|
return new TestSuite(MustangReaderWriterTest.class);
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public String getUnit()
|
// //////// TESTS
|
||||||
{
|
// //////////////////////////////////////////////////////////////////////////////////////////
|
||||||
return unit;
|
|
||||||
}
|
/**
|
||||||
|
* The importer test imports from
|
||||||
public void setUnit(String unit)
|
* ./src/test/MustangGnuaccountingBeispielRE-20170509_505.pdf to check the
|
||||||
{
|
* values. --> as only Name Ascending is supported for Test Unit sequence, I
|
||||||
this.unit = unit;
|
* renamed the this test-A-Export to run before testZExport
|
||||||
}
|
*
|
||||||
|
* @throws IOException
|
||||||
@Override
|
*/
|
||||||
public BigDecimal getVATPercent()
|
|
||||||
{
|
public void testAImport() throws IOException {
|
||||||
return VATPercent;
|
ZUGFeRDImporter zi = new ZUGFeRDImporter();
|
||||||
}
|
try (InputStream inputStream = this.getClass()
|
||||||
|
.getResourceAsStream("/MustangGnuaccountingBeispielRE-20170509_505.pdf")) {
|
||||||
public void setVATPercent(BigDecimal VATPercent)
|
zi.extractLowLevel(inputStream);
|
||||||
{
|
}
|
||||||
this.VATPercent = VATPercent;
|
|
||||||
}
|
// Reading ZUGFeRD
|
||||||
|
|
||||||
}
|
String amount = null;
|
||||||
|
String bic = null;
|
||||||
/**
|
String iban = null;
|
||||||
* Create the test case
|
String holder = null;
|
||||||
*
|
String ref = null;
|
||||||
* @param testName
|
|
||||||
* name of the test case
|
if (zi.canParse()) {
|
||||||
*/
|
zi.parse();
|
||||||
public MustangReaderWriterTest(String testName)
|
amount = zi.getAmount();
|
||||||
{
|
bic = zi.getBIC();
|
||||||
super(testName);
|
iban = zi.getIBAN();
|
||||||
}
|
holder = zi.getHolder();
|
||||||
|
ref = zi.getForeignReference();
|
||||||
/**
|
}
|
||||||
* @return the suite of tests being tested
|
// this resembles the data written in MustangReaderWriterCustomXMLTest
|
||||||
*/
|
assertEquals(amount, "571.04");
|
||||||
public static Test suite()
|
assertEquals(bic, "COBADEFFXXX");
|
||||||
{
|
assertEquals(iban, "DE88 2008 0000 0970 3757 00");
|
||||||
return new TestSuite(MustangReaderWriterTest.class);
|
assertEquals(holder, "Bei Spiel GmbH");
|
||||||
}
|
assertEquals(ref, "RE-20170509/505");
|
||||||
|
|
||||||
// //////// TESTS //////////////////////////////////////////////////////////////////////////////////////////
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The importer test imports from ./src/test/MustangGnuaccountingBeispielRE-20170509_505.pdf to check the values.
|
* The exporter test bases on @{code
|
||||||
* --> as only Name Ascending is supported for Test Unit sequence, I renamed the this test-A-Export to run before
|
* ./src/test/MustangGnuaccountingBeispielRE-20140703_502blanko.pdf}, adds
|
||||||
* testZExport
|
* metadata, writes to @{code ./target/testout-*} and then imports to check the
|
||||||
*
|
* values. It would not make sense to have it run before the less complex
|
||||||
* @throws IOException
|
* 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 testAImport() throws IOException
|
public void testZExport() throws Exception {
|
||||||
{
|
|
||||||
ZUGFeRDImporter zi = new ZUGFeRDImporter();
|
final String TARGET_PDF = "./target/testout-MustangGnuaccountingBeispielRE-20171118_506new.pdf";
|
||||||
try (InputStream inputStream = this.getClass().getResourceAsStream("/MustangGnuaccountingBeispielRE-20170509_505.pdf")) {
|
|
||||||
zi.extractLowLevel(inputStream);
|
// the writing part
|
||||||
}
|
try (InputStream SOURCE_PDF = this.getClass()
|
||||||
|
.getResourceAsStream("/MustangGnuaccountingBeispielRE-20171118_506blanko.pdf");
|
||||||
// Reading ZUGFeRD
|
|
||||||
|
ZUGFeRDExporter ze = new ZUGFeRDExporterFromA1Factory().load(SOURCE_PDF)) {
|
||||||
String amount = null;
|
ze.setZUGFeRDVersion(2);
|
||||||
String bic = null;
|
|
||||||
String iban = null;
|
ze.PDFattachZugferdFile(this);
|
||||||
String holder = null;
|
ze.export(TARGET_PDF);
|
||||||
String ref = null;
|
|
||||||
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
if (zi.canParse())
|
ze.export(baos);
|
||||||
{
|
String pdfContent = baos.toString("UTF-8");
|
||||||
zi.parse();
|
assertFalse(pdfContent.indexOf("(via mustangproject.org") == -1);
|
||||||
amount = zi.getAmount();
|
|
||||||
bic = zi.getBIC();
|
}
|
||||||
iban = zi.getIBAN();
|
|
||||||
holder = zi.getHolder();
|
// now check the contents (like MustangReaderTest)
|
||||||
ref = zi.getForeignReference();
|
ZUGFeRDImporter zi = new ZUGFeRDImporter();
|
||||||
}
|
zi.extract(TARGET_PDF);
|
||||||
|
// Reading ZUGFeRD
|
||||||
assertEquals(amount, "571.04");
|
|
||||||
assertEquals(bic, getOwnBIC());
|
String amount = null;
|
||||||
assertEquals(iban, getOwnIBAN());
|
String bic = null;
|
||||||
assertEquals(holder, getOwnOrganisationName());
|
String iban = null;
|
||||||
assertEquals(ref, getNumber());
|
String holder = null;
|
||||||
|
String ref = null;
|
||||||
}
|
if (zi.canParse()) {
|
||||||
|
zi.parse();
|
||||||
/**
|
amount = zi.getAmount();
|
||||||
* The exporter test bases on @{code ./src/test/MustangGnuaccountingBeispielRE-20140703_502blanko.pdf}, adds metadata,
|
bic = zi.getBIC();
|
||||||
* writes
|
iban = zi.getIBAN();
|
||||||
* to @{code ./target/testout-*} and then imports to check the values.
|
holder = zi.getHolder();
|
||||||
* It would not make sense to have it run before the less complex importer test (which is probably redundant)
|
ref = zi.getForeignReference();
|
||||||
* --> as only Name Ascending is supported for Test Unit sequence, I renamed the Exporter Test test-Z-Export
|
}
|
||||||
*/
|
|
||||||
public void testZExport() throws Exception
|
assertEquals(amount, "571.04");
|
||||||
{
|
assertEquals(bic, getOwnBIC());
|
||||||
|
assertEquals(iban, getOwnIBAN());
|
||||||
final String TARGET_PDF = "./target/testout-MustangGnuaccountingBeispielRE-20170509_505new.pdf";
|
assertEquals(holder, getOwnOrganisationName());
|
||||||
|
assertEquals(ref, getNumber());
|
||||||
// the writing part
|
|
||||||
try(InputStream SOURCE_PDF =
|
}
|
||||||
this.getClass().getResourceAsStream("/MustangGnuaccountingBeispielRE-20170509_505blanko.pdf");
|
|
||||||
|
/**
|
||||||
ZUGFeRDExporter ze = new ZUGFeRDExporterFromA1Factory()
|
* @Test(expected = IndexOutOfBoundsException.class)
|
||||||
.load(SOURCE_PDF)) {
|
* @throws Exception
|
||||||
|
*/
|
||||||
ze.PDFattachZugferdFile(this);
|
public void testExceptionOnPDF14() throws Exception {
|
||||||
ze.export(TARGET_PDF);
|
|
||||||
|
final String TARGET_PDF = "./target/testout-MustangGnuaccountingBeispielRE-20170509_505new.pdf";
|
||||||
ByteArrayOutputStream baos=new ByteArrayOutputStream();
|
|
||||||
ze.export(baos);
|
boolean exceptionThrown = false;
|
||||||
String pdfContent=baos.toString("UTF-8");
|
// the writing part
|
||||||
assertFalse(pdfContent.indexOf("(via mustangproject.org")==-1);
|
try (InputStream SOURCE_PDF = this.getClass()
|
||||||
|
.getResourceAsStream("/MustangGnuaccountingBeispielRE-20170509_505PDF14.pdf");
|
||||||
}
|
|
||||||
|
ZUGFeRDExporter ze = new ZUGFeRDExporterFromA1Factory().load(SOURCE_PDF)) {
|
||||||
// now check the contents (like MustangReaderTest)
|
|
||||||
ZUGFeRDImporter zi = new ZUGFeRDImporter();
|
ze.PDFattachZugferdFile(this);
|
||||||
zi.extract(TARGET_PDF);
|
ze.export(TARGET_PDF);
|
||||||
// Reading ZUGFeRD
|
|
||||||
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
String amount = null;
|
ze.export(baos);
|
||||||
String bic = null;
|
} catch (IOException ex) {
|
||||||
String iban = null;
|
// should throw a java.io.IOException: File is not a valid PDF/A-1 input file
|
||||||
String holder = null;
|
exceptionThrown = true;
|
||||||
String ref = null;
|
}
|
||||||
if (zi.canParse())
|
assertTrue(exceptionThrown);
|
||||||
{
|
|
||||||
zi.parse();
|
}
|
||||||
amount = zi.getAmount();
|
|
||||||
bic = zi.getBIC();
|
|
||||||
iban = zi.getIBAN();
|
|
||||||
holder = zi.getHolder();
|
|
||||||
ref = zi.getForeignReference();
|
|
||||||
}
|
|
||||||
|
|
||||||
assertEquals(amount, "571.04");
|
|
||||||
assertEquals(bic, getOwnBIC());
|
|
||||||
assertEquals(iban, getOwnIBAN());
|
|
||||||
assertEquals(holder, getOwnOrganisationName());
|
|
||||||
assertEquals(ref, getNumber());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Test(expected = IndexOutOfBoundsException.class)
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public void testExceptionOnPDF14() throws Exception
|
|
||||||
{
|
|
||||||
|
|
||||||
final String TARGET_PDF = "./target/testout-MustangGnuaccountingBeispielRE-20170509_505new.pdf";
|
|
||||||
|
|
||||||
boolean exceptionThrown=false;
|
|
||||||
// the writing part
|
|
||||||
try(InputStream SOURCE_PDF =
|
|
||||||
this.getClass().getResourceAsStream("/MustangGnuaccountingBeispielRE-20170509_505PDF14.pdf");
|
|
||||||
|
|
||||||
ZUGFeRDExporter ze = new ZUGFeRDExporterFromA1Factory()
|
|
||||||
.load(SOURCE_PDF)) {
|
|
||||||
|
|
||||||
ze.PDFattachZugferdFile(this);
|
|
||||||
ze.export(TARGET_PDF);
|
|
||||||
|
|
||||||
ByteArrayOutputStream baos=new ByteArrayOutputStream();
|
|
||||||
ze.export(baos);
|
|
||||||
} catch (IOException ex) {
|
|
||||||
// should throw a java.io.IOException: File is not a valid PDF/A-1 input file
|
|
||||||
exceptionThrown=true;
|
|
||||||
}
|
|
||||||
assertTrue(exceptionThrown);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user