/** **********************************************************************
*
* Copyright 2018 Jochen Staerk
*
* Use is subject to license terms.
*
* 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.
*
* 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.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*
*********************************************************************** */
package org.mustangproject.ZUGFeRD;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.junit.FixMethodOrder;
import org.junit.runners.MethodSorters;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class MustangReaderWriterCustomXMLTest extends TestCase {
/**
* Create the test case
*
* @param testName name of the test case
*/
public MustangReaderWriterCustomXMLTest(String testName) {
super(testName);
}
/**
* @return the suite of tests being tested
*/
public static Test suite() {
return new TestSuite(MustangReaderWriterCustomXMLTest.class);
}
// //////// TESTS
// //////////////////////////////////////////////////////////////////////////////////////////
public void testCustomZF2Export() throws Exception {
final String TARGET_PDF = "./target/testout-MustangGnuaccountingBeispielRE-20171118_506custom.pdf";
// the writing part
try {
InputStream SOURCE_PDF = this.getClass().getResourceAsStream("/MustangGnuaccountingBeispielRE-20170509_505blanko.pdf");
ZUGFeRDExporter zea1 = new ZUGFeRDExporterFromA1Factory().setProducer("My Application").setCreator("Test").setZUGFeRDConformanceLevel(ZUGFeRDConformanceLevel.EN16931)
.load(SOURCE_PDF);
final byte[] UTF8ByteOrderMark = new byte[]{(byte) 0xef, (byte) 0xbb, (byte) 0xbf};
/* we have much more information than just in the basic profile (comfort or extended) but it's perfectly valid to provide more information, just not less. */
String ownZUGFeRDXML = new String(UTF8ByteOrderMark) + "\n" +
"\n" +
" \n" +
" false\n" +
" \n" +
" urn:cen.eu:en16931:2017:compliant:factur-x.eu:1p0:extended\n" +
" \n" +
" \n" +
" \n" +
" RE-20171118/506\n" +
" RECHNUNG\n" +
" 380\n" +
" 20171118\n" +
" \n" +
" \n" +
" \n" +
" \n" +
" 1\n" +
" \n" +
" \n" +
" Künstlerische Gestaltung (Stunde): Einer Beispielrechnung\n" +
" \n" +
" \n" +
" \n" +
" \n" +
" 160.0000\n" +
" 1.0000\n" +
" \n" +
" \n" +
" 160.0000\n" +
" 1.0000\n" +
" \n" +
" \n" +
" \n" +
" 1.0000\n" +
" \n" +
" \n" +
" \n" +
" VAT\n" +
" S\n" +
" 7.00\n" +
" \n" +
" \n" +
" 160.00\n" +
" \n" +
" \n" +
" \n" +
" \n" +
" \n" +
" 2\n" +
" \n" +
" \n" +
" Luftballon: Bunt, ca. 500ml\n" +
" \n" +
" \n" +
" \n" +
" \n" +
" 0.7900\n" +
" 1.0000\n" +
" \n" +
" \n" +
" 0.7900\n" +
" 1.0000\n" +
" \n" +
" \n" +
" \n" +
" 400.0000\n" +
" \n" +
" \n" +
" \n" +
" VAT\n" +
" S\n" +
" 19.00\n" +
" \n" +
" \n" +
" 316.00\n" +
" \n" +
" \n" +
" \n" +
" \n" +
" \n" +
" 3\n" +
" \n" +
" \n" +
" Heiße Luft pro Liter\n" +
" \n" +
" \n" +
" \n" +
" \n" +
" 0.1000\n" +
" 1.0000\n" +
" \n" +
" \n" +
" 0.1000\n" +
" 1.0000\n" +
" \n" +
" \n" +
" \n" +
" 200.0000\n" +
" \n" +
" \n" +
" \n" +
" VAT\n" +
" S\n" +
" 19.00\n" +
" \n" +
" \n" +
" 20.00\n" +
" \n" +
" \n" +
" \n" +
" \n" +
" \n" +
" Bei Spiel GmbH\n" +
" \n" +
" 12345\n" +
" Ecke 12\n" +
" Stadthausen\n" +
" DE\n" +
" \n" +
" \n" +
" 22/815/0815/4\n" +
" \n" +
" \n" +
" DE136695976\n" +
" \n" +
" \n" +
" \n" +
" Theodor Est\n" +
" \n" +
" 88802\n" +
" Bahnstr. 42\n" +
" Spielkreis\n" +
" DE\n" +
" \n" +
" \n" +
" DE999999999\n" +
" \n" +
" \n" +
" \n" +
" \n" +
" \n" +
" 20171117\n" +
" \n" +
" \n" +
" \n" +
" RE-20171118/506\n" +
" EUR\n" +
" \n" +
" 42\n" +
" Überweisung\n" +
" \n" +
" DE88 2008 0000 0970 3757 00\n" +
" 44421800\n" +
" \n" +
" \n" +
" COBADEFFXXX\n" +
" 41441604\n" +
" Commerzbank\n" +
" \n" +
" \n" +
" \n" +
" 11.20\n" +
" VAT\n" +
" 160.00\n" +
" S\n" +
" 7.00\n" +
" \n" +
" \n" +
" 63.84\n" +
" VAT\n" +
" 336.00\n" +
" S\n" +
" 19.00\n" +
" \n" +
" \n" +
" Zahlbar ohne Abzug bis 09.12.2017\n" +
" 20171209\n" +
" \n" +
" \n" +
" 496.00\n" +
" 0.00\n" +
" 0.00\n" +
" 496.00\n" +
" 75.04\n" +
" 571.04\n" +
" 571.04\n" +
" \n" +
" \n" +
" \n" +
"";
zea1.setZUGFeRDXMLData(ownZUGFeRDXML.getBytes("UTF-8"));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
zea1.disableAutoClose(true);
zea1.export(TARGET_PDF);
zea1.export(baos);
zea1.close();
String pdfContent = baos.toString("UTF-8");
assertFalse(pdfContent.indexOf("(via mustangproject.org") == -1);
assertFalse(pdfContent.indexOf("EN 16931") == -1);
} catch (IOException e) {
e.printStackTrace();
}
// now check the contents (like MustangReaderTest)
ZUGFeRDImporter zi = new ZUGFeRDImporter(TARGET_PDF);
// Reading ZUGFeRD
assertEquals(zi.getAmount(), "571.04");
assertEquals(zi.getBLZ(), "41441604");
assertEquals(zi.getBIC(), "COBADEFFXXX");
assertEquals(zi.getIBAN(), "DE88 2008 0000 0970 3757 00");
assertEquals(zi.getKTO(), "44421800");
assertEquals(zi.getHolder(), "Bei Spiel GmbH");
assertEquals(zi.getForeignReference(), "RE-20171118/506");
}
/**
* 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. 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
*/
public void testCustomZF1Export() throws Exception {
final String TARGET_PDF = "./target/testout-MustangGnuaccountingBeispielRE-20170509_505custom.pdf";
// the writing part
try {
InputStream SOURCE_PDF = this.getClass().getResourceAsStream("/MustangGnuaccountingBeispielRE-20170509_505blanko.pdf");
ZUGFeRDExporter zea1 = new ZUGFeRDExporterFromA1Factory().setProducer("My Application").setCreator("Test").setZUGFeRDConformanceLevel(ZUGFeRDConformanceLevel.BASIC)
.load(SOURCE_PDF);
/* we have much more information than just in the basic profile (comfort or extended) but it's perfectly valid to provide more information, just not less. */
String ownZUGFeRDXML = "\n"
+ "\n" + "\n"
+ "false\n" + "\n"
+ "\n" + "\n"
+ "urn:ferd:CrossIndustryDocument:invoice:1p0:basic\n" + "\n"
+ "\n"
+ "\n" + "\n"
+ "RE-20170509/505\n" + "RECHNUNG\n"
+ "380\n" + "\n"
+ "20170509\n" + "\n"
+ "\n" + "\n"
+ "\n" + "\n"
+ "Bei Spiel GmbH\n" + "\n"
+ "12345\n" + "Ecke 12\n"
+ "Stadthausen\n" + "DE\n"
+ "\n" + "\n"
+ "22/815/0815/4\n" + "\n"
+ "\n" + "DE136695976\n"
+ "\n" + "\n" + "\n"
+ "Theodor Est\n" + "\n"
+ "88802\n" + "Bahnstr. 42\n"
+ "Spielkreis\n" + "DE\n"
+ "\n" + "\n"
+ "DE999999999\n" + "\n"
+ "\n" + "\n"
+ "\n" + "\n"
+ "\n"
+ "20170507\n"
+ "\n" + "\n"
+ "\n" + "\n"
+ "RE-20170509/505\n"
+ "EUR\n"
+ "\n" + "42\n"
+ "Überweisung\n" + "\n"
+ "DE88 2008 0000 0970 3757 00\n"
+ "44421800\n"
+ "\n"
+ "\n"
+ "COBADEFFXXX\n"
+ "41441604\n"
+ "Commerzbank\n"
+ "\n"
+ "\n" + "\n"
+ "11.20\n"
+ "VAT\n"
+ "160.00\n"
+ "S\n"
+ "7.00\n" + "\n"
+ "\n"
+ "63.84\n"
+ "VAT\n"
+ "336.00\n"
+ "S\n"
+ "19.00\n" + "\n"
+ "\n"
+ "Zahlbar ohne Abzug bis zum 30.05.2017\n"
+ "\n" + "20170530\n"
+ "\n" + "\n"
+ "\n"
+ "496.00\n"
+ "0.00\n"
+ "0.00\n"
+ "496.00\n"
+ "75.04\n"
+ "571.04\n"
+ "571.04\n"
+ "\n"
+ "\n" + "\n"
+ "\n" + "1\n"
+ "\n" + "\n"
+ "\n"
+ "160.0000\n"
+ "1.0000\n"
+ "\n" + "\n"
+ "160.0000\n"
+ "1.0000\n"
+ "\n" + "\n"
+ "\n"
+ "1.0000\n"
+ "\n" + "\n"
+ "\n" + "VAT\n"
+ "S\n"
+ "7.00\n" + "\n"
+ "\n"
+ "160.00\n"
+ "\n"
+ "\n" + "\n" + "\n"
+ "Künstlerische Gestaltung (Stunde): Einer Beispielrechnung\n" + "\n"
+ "\n" + "\n"
+ "\n" + "\n"
+ "\n" + "2\n"
+ "\n" + "\n"
+ "\n"
+ "0.7900\n"
+ "1.0000\n"
+ "\n" + "\n"
+ "0.7900\n"
+ "1.0000\n"
+ "\n" + "\n"
+ "\n"
+ "400.0000\n"
+ "\n" + "\n"
+ "\n" + "VAT\n"
+ "S\n"
+ "19.00\n" + "\n"
+ "\n"
+ "316.00\n"
+ "\n"
+ "\n" + "\n"
+ "Luftballon: Bunt, ca. 500ml\n" + "\n"
+ "\n" + "\n"
+ "\n" + "\n"
+ "3\n" + "\n"
+ "\n" + "\n"
+ "0.1000\n"
+ "1.0000\n"
+ "\n" + "\n"
+ "0.1000\n"
+ "1.0000\n"
+ "\n" + "\n"
+ "\n"
+ "200.0000\n"
+ "\n" + "\n"
+ "\n" + "VAT\n"
+ "S\n"
+ "19.00\n" + "\n"
+ "\n"
+ "20.00\n"
+ "\n"
+ "\n" + "\n"
+ "Heiße Luft pro Liter\n" + "\n"
+ "\n" + "\n"
+ "\n" + "";
zea1.setZUGFeRDXMLData(ownZUGFeRDXML.getBytes("UTF-8"));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
zea1.disableAutoClose(true);
zea1.export(TARGET_PDF);
zea1.export(baos);
zea1.close();
String pdfContent = baos.toString("UTF-8");
assertFalse(pdfContent.indexOf("(via mustangproject.org") == -1);
assertFalse(pdfContent.indexOf("BASIC") == -1);
} catch (IOException e) {
e.printStackTrace();
}
// now check the contents (like MustangReaderTest)
ZUGFeRDImporter zi = new ZUGFeRDImporter(TARGET_PDF);
// Reading ZUGFeRD
assertEquals(zi.getAmount(), "571.04");
assertEquals(zi.getBIC(), "COBADEFFXXX");
assertEquals(zi.getBLZ(), "41441604");
assertEquals(zi.getIBAN(), "DE88 2008 0000 0970 3757 00");
assertEquals(zi.getKTO(), "44421800");
assertEquals(zi.getHolder(), "Bei Spiel GmbH");
assertEquals(zi.getForeignReference(), "RE-20170509/505");
}
}