Merge pull request #114 from swsch/master
add failing unit test to prove that the wrong profile is written and then fix it
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
*********************************************************************** */
|
||||
package org.mustangproject.ZUGFeRD;
|
||||
|
||||
public class CustomXMLProvider implements IXMLProvider {
|
||||
public class CustomXMLProvider implements IXMLProvider, IProfileProvider {
|
||||
|
||||
protected byte[] zugferdData;
|
||||
|
||||
@@ -48,4 +48,14 @@ public class CustomXMLProvider implements IXMLProvider {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProfile() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProfile(ZUGFeRDConformanceLevel level) {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,5 +21,7 @@ package org.mustangproject.ZUGFeRD;
|
||||
public interface IProfileProvider {
|
||||
|
||||
public String getProfile();
|
||||
|
||||
public void setProfile(ZUGFeRDConformanceLevel level);
|
||||
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
package org.mustangproject.ZUGFeRD;
|
||||
|
||||
import org.mustangproject.ZUGFeRD.model.CrossIndustryDocumentType;
|
||||
import org.mustangproject.ZUGFeRD.model.DocumentContextParameterTypeConstants;
|
||||
import org.mustangproject.ZUGFeRD.model.ZFNamespacePrefixMapper;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
@@ -27,13 +28,27 @@ import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Marshaller;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
||||
public class ZUGFeRD1PullProvider implements IXMLProvider {
|
||||
public class ZUGFeRD1PullProvider implements IXMLProvider, IProfileProvider {
|
||||
|
||||
|
||||
protected byte[] zugferdData;
|
||||
private Marshaller marshaller;
|
||||
|
||||
private boolean isTest;
|
||||
private ZUGFeRDConformanceLevel level;
|
||||
|
||||
|
||||
public void setProfile(ZUGFeRDConformanceLevel level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
public String getProfile() {
|
||||
switch (level) {
|
||||
case BASIC: return DocumentContextParameterTypeConstants.BASIC;
|
||||
case COMFORT: return DocumentContextParameterTypeConstants.COMFORT;
|
||||
default: return DocumentContextParameterTypeConstants.EXTENDED;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -59,7 +74,7 @@ public class ZUGFeRD1PullProvider implements IXMLProvider {
|
||||
private String createZugferdXMLForTransaction(IZUGFeRDExportableTransaction trans) {
|
||||
|
||||
JAXBElement<CrossIndustryDocumentType> jaxElement =
|
||||
new ZUGFeRDTransactionModelConverter(trans).withTest(isTest).convertToModel();
|
||||
new ZUGFeRDTransactionModelConverter(trans).withTest(isTest).withProfile(getProfile()).convertToModel();
|
||||
|
||||
try {
|
||||
return marshalJaxToXMLString(jaxElement);
|
||||
|
||||
@@ -71,6 +71,11 @@ public class ZUGFeRD2PullProvider implements IXMLProvider, IProfileProvider {
|
||||
|
||||
protected byte[] zugferdData;
|
||||
private IZUGFeRDExportableTransaction trans;
|
||||
private ZUGFeRDConformanceLevel level;
|
||||
|
||||
public void setProfile(ZUGFeRDConformanceLevel level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
/**
|
||||
* enables the flag to indicate a test invoice in the XML structure
|
||||
|
||||
@@ -367,7 +367,7 @@ public class ZUGFeRDExporter implements Closeable {
|
||||
*/
|
||||
public void PDFattachZugferdFile(IZUGFeRDExportableTransaction trans) throws IOException {
|
||||
prepareDocument();
|
||||
|
||||
((IProfileProvider) xmlProvider).setProfile(profile);
|
||||
xmlProvider.generateXML(trans);
|
||||
String filename = getFilenameForVersion(ZFVersion);
|
||||
PDFAttachGenericFile(doc, filename, "Alternative",
|
||||
|
||||
@@ -85,6 +85,7 @@ class ZUGFeRDTransactionModelConverter {
|
||||
private final Totals totals;
|
||||
private boolean isTest;
|
||||
private String currency = "EUR";
|
||||
private String profile;
|
||||
|
||||
|
||||
ZUGFeRDTransactionModelConverter(IZUGFeRDExportableTransaction trans) {
|
||||
@@ -114,7 +115,7 @@ class ZUGFeRDTransactionModelConverter {
|
||||
DocumentContextParameterType contextParameter = xmlFactory
|
||||
.createDocumentContextParameterType();
|
||||
IDType idType = xmlFactory.createIDType();
|
||||
idType.setValue(DocumentContextParameterTypeConstants.EXTENDED);
|
||||
idType.setValue(profile);
|
||||
contextParameter.setID(idType);
|
||||
context.getGuidelineSpecifiedDocumentContextParameter().add(
|
||||
contextParameter);
|
||||
@@ -955,6 +956,11 @@ class ZUGFeRDTransactionModelConverter {
|
||||
return this;
|
||||
}
|
||||
|
||||
public ZUGFeRDTransactionModelConverter withProfile(String profile) {
|
||||
this.profile = profile;
|
||||
return this;
|
||||
}
|
||||
|
||||
private class LineCalc {
|
||||
|
||||
private BigDecimal totalGross;
|
||||
|
||||
@@ -30,6 +30,7 @@ import org.apache.xmpbox.xml.DomXmpParser;
|
||||
import org.apache.xmpbox.xml.XmpParsingException;
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.runners.MethodSorters;
|
||||
import org.mustangproject.ZUGFeRD.model.DocumentContextParameterTypeConstants;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
@@ -349,7 +350,7 @@ public class MustangReaderWriterTest extends MustangReaderTestCase {
|
||||
|
||||
// the writing part
|
||||
try (InputStream SOURCE_PDF = this.getClass()
|
||||
.getResourceAsStream("/MustangGnuaccountingBeispielRE-20190610_507blanko.pdf");
|
||||
.getResourceAsStream("/MustangGnuaccountingBeispielRE-20190610_507blanko.pdf");
|
||||
|
||||
ZUGFeRDExporter ze = new ZUGFeRDExporterFromA1Factory().setZUGFeRDVersion(2).setZUGFeRDConformanceLevel(ZUGFeRDConformanceLevel.EN16931).load(SOURCE_PDF)) {
|
||||
|
||||
@@ -366,7 +367,7 @@ public class MustangReaderWriterTest extends MustangReaderTestCase {
|
||||
// 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);
|
||||
|
||||
|
||||
} catch (IOException e) {
|
||||
fail("IOException should not happen in testZExport");
|
||||
}
|
||||
@@ -384,6 +385,37 @@ public class MustangReaderWriterTest extends MustangReaderTestCase {
|
||||
assertEquals(zi.getForeignReference(), getNumber());
|
||||
}
|
||||
|
||||
/**
|
||||
* Quick and dirty copy of testZExport to check if v1 files contain
|
||||
* the correct profile string when the comfort profile is selected.
|
||||
*/
|
||||
public void testZExportv1Profile() {
|
||||
|
||||
final String TARGET_PDF = "./target/testout-MustangGnuaccountingBeispielRE-20171118_506new.pdf";
|
||||
|
||||
// the writing part
|
||||
try (InputStream SOURCE_PDF = this.getClass()
|
||||
.getResourceAsStream("/MustangGnuaccountingBeispielRE-20190610_507blanko.pdf");
|
||||
|
||||
ZUGFeRDExporter ze = new ZUGFeRDExporterFromA1Factory().setZUGFeRDVersion(1).setZUGFeRDConformanceLevel(ZUGFeRDConformanceLevel.COMFORT).load(SOURCE_PDF)) {
|
||||
|
||||
ze.PDFattachZugferdFile(this);
|
||||
ze.disableAutoClose(true);
|
||||
ze.export(TARGET_PDF);
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ze.export(baos);
|
||||
ze.close();
|
||||
String pdfContent = baos.toString("UTF-8");
|
||||
assertFalse(pdfContent.indexOf(DocumentContextParameterTypeConstants.BASIC) >= 0);
|
||||
assertFalse(pdfContent.indexOf(DocumentContextParameterTypeConstants.EXTENDED) >= 0);
|
||||
assertTrue(pdfContent.indexOf(DocumentContextParameterTypeConstants.COMFORT) >= 0);
|
||||
|
||||
} catch (IOException e) {
|
||||
fail("IOException should not happen in testZExport");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void testFXExport() throws Exception {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user