Search in sources :

Example 6 with InvoiceType

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());
        }
    }
}
Also used : Serializable(java.io.Serializable) ErrorList(com.helger.commons.error.list.ErrorList) ValidationResultList(com.helger.phive.api.result.ValidationResultList) FileSystemResource(com.helger.commons.io.resource.FileSystemResource) ValidationResult(com.helger.phive.api.result.ValidationResult) File(java.io.File) CreditNoteType(oasis.names.specification.ubl.schema.xsd.creditnote_22.CreditNoteType) CrossIndustryInvoiceType(un.unece.uncefact.data.standard.crossindustryinvoice._100.CrossIndustryInvoiceType) InvoiceType(oasis.names.specification.ubl.schema.xsd.invoice_22.InvoiceType) Test(org.junit.Test)

Aggregations

ErrorList (com.helger.commons.error.list.ErrorList)6 Serializable (java.io.Serializable)6 CrossIndustryInvoiceType (un.unece.uncefact.data.standard.crossindustryinvoice._100.CrossIndustryInvoiceType)6 CGlobal (com.helger.commons.CGlobal)3 ValueEnforcer (com.helger.commons.ValueEnforcer)3 CollectionHelper (com.helger.commons.collection.CollectionHelper)3 EqualsHelper (com.helger.commons.equals.EqualsHelper)3 IErrorList (com.helger.commons.error.list.IErrorList)3 FileSystemResource (com.helger.commons.io.resource.FileSystemResource)3 MathHelper (com.helger.commons.math.MathHelper)3 ETriState (com.helger.commons.state.ETriState)3 StringHelper (com.helger.commons.string.StringHelper)3 ValidationResult (com.helger.phive.api.result.ValidationResult)3 ValidationResultList (com.helger.phive.api.result.ValidationResultList)3 File (java.io.File)3 BigDecimal (java.math.BigDecimal)3 LocalDate (java.time.LocalDate)3 Consumer (java.util.function.Consumer)3 Nonnull (javax.annotation.Nonnull)3 Nullable (javax.annotation.Nullable)3