use of oasis.names.specification.ubl.schema.xsd.invoice_21.InvoiceType in project en16931-cii2ubl by phax.
the class CIIToUBL22ConverterTest method testConvertAndValidateAll.
@Test
public void testConvertAndValidateAll() {
final String sBasePath = MockSettings.getBaseDir().getAbsolutePath();
for (final File aFile : MockSettings.getAllTestFiles()) {
LOGGER.info("Converting " + aFile.toString() + " to UBL 2.2");
// Main conversion
final ErrorList aErrorList = new ErrorList();
final Serializable aInvoice = new CIIToUBL22Converter().convertCIItoUBL(aFile, aErrorList);
assertTrue("Errors: " + aErrorList.toString(), aErrorList.isEmpty());
assertNotNull(aInvoice);
final File aDestFile = new File("toubl22/" + aFile.getParentFile().getAbsolutePath().substring(sBasePath.length()), FilenameHelper.getBaseName(aFile.getName()) + "-ubl.xml");
final ValidationResultList aResultList;
if (aInvoice instanceof InvoiceType) {
final InvoiceType aUBLInvoice = (InvoiceType) aInvoice;
// Check UBL XSD scheme
final UBL22WriterBuilder<InvoiceType> aWriter = UBL22Writer.invoice().setFormattedOutput(true);
aWriter.write(aUBLInvoice, aDestFile);
// Validate against EN16931 validation rules
aResultList = ValidationExecutionManager.executeValidation(MockSettings.VES_REGISTRY.getOfID(EN16931Validation.VID_UBL_INVOICE_137), ValidationSourceXML.create(new FileSystemResource(aDestFile)));
} else {
final CreditNoteType aUBLInvoice = (CreditNoteType) aInvoice;
// Check UBL XSD scheme
final UBL22WriterBuilder<CreditNoteType> aWriter = UBL22Writer.creditNote().setFormattedOutput(true);
aWriter.write(aUBLInvoice, aDestFile);
// Validate against EN16931 validation rules
aResultList = ValidationExecutionManager.executeValidation(MockSettings.VES_REGISTRY.getOfID(EN16931Validation.VID_UBL_CREDIT_NOTE_137), ValidationSourceXML.create(new FileSystemResource(aDestFile)));
}
assertNotNull(aResultList);
// Check that no errors (but maybe warnings) are contained
for (final ValidationResult aResult : aResultList) {
assertTrue("Errors: " + aResult.getErrorList().toString(), aResult.getErrorList().isEmpty());
}
}
}
Aggregations