Merge branch 'master' of github.com:ZUGFeRD/mustangproject

This commit is contained in:
Andre Kemper
2019-04-09 23:32:55 +02:00
2 changed files with 66 additions and 11 deletions

View File

@@ -134,32 +134,31 @@ public class ZUGFeRDExporter implements Closeable {
} }
public static String getNamespaceForVersion(int ver) { public static String getNamespaceForVersion(int ver) {
if (ver == 1) { if (isFacturX) {
return "urn:factur-x:pdfa:CrossIndustryDocument:invoice:1p0#";
} else if (ver == 1) {
return "urn:ferd:pdfa:CrossIndustryDocument:invoice:1p0#"; return "urn:ferd:pdfa:CrossIndustryDocument:invoice:1p0#";
} else if (ver == 2) { } else if (ver == 2) {
return "urn:factur-x:pdfa:CrossIndustryDocument:invoice:1p0#"; return "urn:zugferd:pdfa:CrossIndustryDocument:invoice:2p0#";
} else { } else {
throw new IllegalArgumentException("Version not supported"); throw new IllegalArgumentException("Version not supported");
} }
} }
public static String getPrefixForVersion(int ver) { public static String getPrefixForVersion(int ver) {
if (ver == 1) { if (isFacturX) {
return "zf";
} else if (ver == 2) {
return "fx"; return "fx";
} else { } else {
throw new IllegalArgumentException("Version not supported"); return "zf";
} }
} }
public static String getFilenameForVersion(int ver) { public static String getFilenameForVersion(int ver) {
if (ver == 1) { if (isFacturX) {
return "ZUGFeRD-invoice.xml";
} else if ((ver == 2) || (isFacturX)) {
return "factur-x.xml"; return "factur-x.xml";
} else { } else {
throw new IllegalArgumentException("Version not supported"); return "ZUGFeRD-invoice.xml";
} }
} }

View File

@@ -501,6 +501,62 @@ public class MustangReaderWriterTest extends TestCase implements IZUGFeRDExporta
ze.disableAutoClose(true); ze.disableAutoClose(true);
ze.export(TARGET_PDF); ze.export(TARGET_PDF);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ze.export(baos);
ze.close();
String pdfContent = baos.toString("UTF-8");
assertFalse(pdfContent.indexOf("(via mustangproject.org") == -1);
// check for pdf-a schema extension
assertFalse(pdfContent.indexOf("<zf:ConformanceLevel>EN 16931</zf:ConformanceLevel>") == -1);
assertFalse(pdfContent.indexOf("<pdfaSchema:prefix>zf</pdfaSchema:prefix>") == -1);
assertFalse(pdfContent.indexOf("urn:zugferd:pdfa:CrossIndustryDocument:invoice:2p0#") == -1);
}
// now check the contents (like MustangReaderTest)
ZUGFeRDImporter zi = new ZUGFeRDImporter();
zi.extract(TARGET_PDF);
// Reading ZUGFeRD
String amount = null;
String bic = null;
String iban = null;
String kto = null;
String holder = null;
String ref = null;
if (zi.canParse()) {
zi.parse();
amount = zi.getAmount();
bic = zi.getBIC();
iban = zi.getIBAN();
kto = zi.getKTO();
holder = zi.getHolder();
ref = zi.getForeignReference();
}
assertEquals(amount, "571.04");
assertEquals(bic, getOwnBIC());
assertEquals(iban, getOwnIBAN());
assertEquals(kto, getOwnKto());
assertEquals(holder, getOwnOrganisationName());
assertEquals(ref, getNumber());
}
/*
public void testFXExport() throws Exception {
final String TARGET_PDF = "./target/testout-MustangGnuaccountingBeispielRE-20171118_506fx.pdf";
// the writing part
try (InputStream SOURCE_PDF = this.getClass()
.getResourceAsStream("/MustangGnuaccountingBeispielRE-20171118_506blanko.pdf");
ZUGFeRDExporter ze = new ZUGFeRDExporterFromA1Factory().setZUGFeRDVersion(2).setZUGFeRDConformanceLevel(ZUGFeRDConformanceLevel.EN16931).load(SOURCE_PDF)) {
ze.setFacturX();
ze.PDFattachZugferdFile(this);
ze.disableAutoClose(true);
ze.export(TARGET_PDF);
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
ze.export(baos); ze.export(baos);
ze.close(); ze.close();
@@ -523,7 +579,7 @@ public class MustangReaderWriterTest extends TestCase implements IZUGFeRDExporta
assertEquals(zi.getHolder(), getOwnOrganisationName()); assertEquals(zi.getHolder(), getOwnOrganisationName());
assertEquals(zi.getForeignReference(), getNumber()); assertEquals(zi.getForeignReference(), getNumber());
} }
*/
/** /**
* @throws Exception * @throws Exception
* @Test(expected = IndexOutOfBoundsException.class) * @Test(expected = IndexOutOfBoundsException.class)