Skip to content

Commit

Permalink
checking generated PDF/As
Browse files Browse the repository at this point in the history
  • Loading branch information
jstaerk committed Nov 25, 2023
1 parent 53ae1ec commit 23650e6
Show file tree
Hide file tree
Showing 3 changed files with 159 additions and 2 deletions.
116 changes: 116 additions & 0 deletions library/src/test/java/org/mustangproject/ZUGFeRD/PDFAWriteTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@

/**
* *********************************************************************
* <p>
* Copyright 2019 Jochen Staerk
* <p>
* Use is subject to license terms.
* <p>
* 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.
* <p>
* 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.
* <p>
* See the License for the specific language governing permissions and
* limitations under the License.
* <p>
* **********************************************************************
*/
package org.mustangproject.ZUGFeRD;

import org.junit.FixMethodOrder;
import org.junit.runners.MethodSorters;
import org.mustangproject.*;

import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.Date;


@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class PDFAWriteTest extends ResourceCase {
final String TARGET_PDF_FROM_A3 = "./target/testout-PDFA3FromA3.pdf";
final String TARGET_PDF_FROM_A3_UNKNOWN = "./target/testout-PDFA3FromUnkownA3.pdf";
final String TARGET_PDF_FROM_A1_UNKNOWN = "./target/testout-PDFA3FromUnkownA1.pdf";
public void testA3KnownExport() {
// test creating factur-x invoices to french authorities, i.e. with SIRET number
// the writing part
TradeParty recipient = new TradeParty("Franz Müller", "teststr.12", "55232", "Entenhausen", "DE");
Invoice i = createInvoice(recipient);
File tempFile = getResourceAsFile("MustangGnuaccountingBeispielRE-20201121_508blankoA3.pdf");//a3
int exceptions=0;
try {
ZUGFeRDExporterFromA3 zea3 = new ZUGFeRDExporterFromA3().load(tempFile.getAbsolutePath());

zea3.setTransaction(new Invoice().setDueDate(new Date()).setIssueDate(new Date()).setDeliveryDate(new Date())
.setSender(new TradeParty("Test", "teststr", "55232", "teststadt", "DE").addBankDetails(new BankDetails("777666555", "DE4321"))).setOwnTaxID("4711").setOwnVATID("DE19990815")
.setRecipient(new TradeParty("Franz Müller", "teststr.12", "55232", "Entenhausen", "DE")
.setContact(new Contact("nameRep", "phoneRep", "[email protected]"))).setNumber("X12")
.addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(19)), new BigDecimal(2.5), new BigDecimal(1.0))));

zea3.export(TARGET_PDF_FROM_A3);

} catch (IOException e) {
exceptions++;
}
assertTrue(exceptions==0);

}
public void testA3UnknownExport() {
// test creating factur-x invoices to french authorities, i.e. with SIRET number
// the writing part
TradeParty recipient = new TradeParty("Franz Müller", "teststr.12", "55232", "Entenhausen", "DE");
Invoice i = createInvoice(recipient);

File tempFile = getResourceAsFile("MustangGnuaccountingBeispielRE-20201121_508blankoA3.pdf");
int exceptions=0;
try {
ZUGFeRDExporterFromA1 zea3 = new ZUGFeRDExporterFromA1().load(tempFile.getAbsolutePath());
zea3.setTransaction(i);
zea3.export(TARGET_PDF_FROM_A3_UNKNOWN);

} catch (IOException e) {
exceptions++;
}
assertTrue(exceptions==0);

}

public void testA3UnknownExportFromA1() {
// test creating factur-x invoices to french authorities, i.e. with SIRET number
// the writing part
TradeParty recipient = new TradeParty("Franz Müller", "teststr.12", "55232", "Entenhausen", "DE");
Invoice i = createInvoice(recipient);
File tempFile = getResourceAsFile("MustangGnuaccountingBeispielRE-20201121_508blanko.pdf");
int exceptions=0;
try {
IZUGFeRDExporter zea3 = new ZUGFeRDExporterFromPDFA().load(tempFile.getAbsolutePath());
zea3.setTransaction(i);
zea3.setProfile(Profiles.getByName("EN16931"));
zea3.export(TARGET_PDF_FROM_A1_UNKNOWN);

} catch (IOException e) {
exceptions++;
}
assertTrue(exceptions==0);

}

private Invoice createInvoice(TradeParty recipient) {
String orgname = "Test company";
String number = "123";
String amountStr = "1.00";
BigDecimal amount = new BigDecimal(amountStr);
return new Invoice().setDueDate(new Date()).setIssueDate(new Date()).setDeliveryDate(new Date())
.setSender(new TradeParty(orgname,"teststr","55232","teststadt","DE").addTaxID("DE4711").addVATID("DE0815").setContact(new Contact("Hans Test","+49123456789","[email protected]")).addBankDetails(new BankDetails("DE12500105170648489890","COBADEFXXX")))
.setRecipient(recipient)
.setReferenceNumber("991-01484-64")//leitweg-id
// not using any VAT, this is also a test of zero-rated goods:
.setNumber(number).addItem(new Item(new Product("Testprodukt", "", "C62", BigDecimal.ZERO), amount, new BigDecimal(1.0)));
}

}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,47 @@
public class PDFValidatorTest extends ResourceCase {
private static final Logger LOGGER = LoggerFactory.getLogger(ZUGFeRDValidator.class.getCanonicalName()); // log

public void testPDFPotentialA3SourceValidation() {
final ValidationContext vc = new ValidationContext(null);
final PDFValidator pv = new PDFValidator(vc);

try {

File tempFile = new File("../library/target/testout-PDFA3FromA3.pdf");
assertTrue(tempFile.exists());

pv.setFilename(tempFile.getAbsolutePath());
pv.validate();
String actual = pv.getXMLResult();
assertEquals(true, actual.contains("summary status=\"valid"));
assertEquals(false, actual.contains("summary status=\"invalid"));


tempFile = new File("../library/target/testout-PDFA3FromUnkownA3.pdf");
assertTrue(tempFile.exists());

pv.setFilename(tempFile.getAbsolutePath());
vc.clear();
pv.validate();
actual = pv.getXMLResult();
assertEquals(true, actual.contains("summary status=\"valid"));
assertEquals(false, actual.contains("summary status=\"invalid"));

tempFile = new File("../library/target/testout-PDFA3FromUnkownA1.pdf");
assertTrue(tempFile.exists());

pv.setFilename(tempFile.getAbsolutePath());
vc.clear();
pv.validate();
actual = pv.getXMLResult();
assertEquals(true, actual.contains("summary status=\"valid"));
assertEquals(false, actual.contains("summary status=\"invalid"));

} catch (final IrrecoverableValidationError e) {
// ignore, will be in XML output anyway
}

}
public void testPDFValidation() {
final ValidationContext vc = new ValidationContext(null);
final PDFValidator pv = new PDFValidator(vc);
Expand Down Expand Up @@ -36,7 +77,7 @@ public void testPDFValidation() {
assertEquals(true, actual.contains("validationReport profileName=\"PDF/A-3"));
assertEquals(true, actual.contains("batchSummary totalJobs=\"1\" failedToParse=\"0\" encrypted=\"0\""));
assertEquals(true,
actual.contains("validationReports compliant=\"1\" nonCompliant=\"0\" failedJobs=\"0\">"));
actual.contains("validationReports compliant=\"1\" nonCompliant=\"0\" failedJobs=\"0\">"));
// test some xml
// assertEquals(true, actual.contains("<error
// location=\"/*:CrossIndustryInvoice[namespace-uri()='urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100'][1]/*:SupplyChainTradeTransaction[namespace-uri()='urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100'][1]/*:ApplicableHeaderTradeSettlement[namespace-uri()='urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100'][1]/*:SpecifiedTradeSettlementHeaderMonetarySummation[namespace-uri()='urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100'][1]/*:DuePayableAmount[namespace-uri()='urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100'][1]\"
Expand All @@ -55,7 +96,7 @@ public void testPDFValidation() {
assertEquals(true, actual.contains("validationReport profileName=\"PDF/A-3"));
assertEquals(true, actual.contains("batchSummary totalJobs=\"1\" failedToParse=\"0\" encrypted=\"0\""));
assertEquals(true,
actual.contains("validationReports compliant=\"1\" nonCompliant=\"0\" failedJobs=\"0\">"));
actual.contains("validationReports compliant=\"1\" nonCompliant=\"0\" failedJobs=\"0\">"));

assertEquals(false, actual.contains("<error"));
} catch (final IrrecoverableValidationError e) {
Expand Down

0 comments on commit 23650e6

Please sign in to comment.