Search in sources :

Example 1 with IEdifactValidationExecutorProviderXML

use of com.helger.phive.engine.vom.VOM1ComplianceSettings.IEdifactValidationExecutorProviderXML in project phive by phax.

the class VOM1MarshallerTest method testReadGoodExamples.

@Test
public void testReadGoodExamples() {
    final VOM1Marshaller m = new VOM1Marshaller();
    for (final File f : new FileSystemIterator(new File("src/test/resources/vom/good")).withFilter(IFileFilter.filenameEndsWith(".xml"))) {
        LOGGER.info("Reading " + f.getName());
        final VOMType aVOM = m.read(f);
        assertNotNull(aVOM);
        final Schema aFakeSchema = XMLSchemaCache.getInstance().getSchema(new ReadableResourceByteArray("<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns=\"urn:1\" targetNamespace=\"urn:a\" version=\"1.0\"><xs:element name=\"a\" type=\"xs:string\" /></xs:schema>".getBytes()));
        final IVOMXmlSchemaResolver aXmlSchemaResolver = new MapBasedVOMXmlSchemaResolver().addMapping("ubl21-invoice", aFakeSchema);
        final IVOMNamespaceContextResolver aNamespaceContextResolver = new MapBasedVOMNamespaceContextResolver().addMapping("ubl21", new MapBasedNamespaceContext().addMapping("a", "urn:a"));
        final IVOMResourceResolver aResourceResolver = new MapBasedVOMResourceResolver().addMapping("cius-pt-200", new ReadableResourceByteArray(ArrayHelper.EMPTY_BYTE_ARRAY)).addMapping("cius-pt-201", new ReadableResourceByteArray(ArrayHelper.EMPTY_BYTE_ARRAY)).addMapping("atnat-invoice-6", new ReadableResourceByteArray(ArrayHelper.EMPTY_BYTE_ARRAY)).addMapping("xrechnung-ublinv-200", new ReadableResourceByteArray(ArrayHelper.EMPTY_BYTE_ARRAY)).addMapping("en16931-ublinv-132", new ReadableResourceByteArray(ArrayHelper.EMPTY_BYTE_ARRAY));
        final IEdifactValidationExecutorProviderXML aEdifactProvider = (sDirectory, sMessage, aOptions) -> null;
        final VOM1ComplianceSettings aSettings = VOM1ComplianceSettings.builder().allowEdifact(true).edifactValidationExecutorProviderXML(aEdifactProvider).build();
        final ErrorList aErrorList = VOM1Validator.validate(aVOM, aXmlSchemaResolver, aNamespaceContextResolver, aResourceResolver, aSettings);
        assertEquals(aErrorList.toString(), 0, aErrorList.getErrorCount());
    }
}
Also used : IEdifactValidationExecutorProviderXML(com.helger.phive.engine.vom.VOM1ComplianceSettings.IEdifactValidationExecutorProviderXML) Logger(org.slf4j.Logger) Assert.assertNotNull(org.junit.Assert.assertNotNull) IError(com.helger.commons.error.IError) ErrorList(com.helger.commons.error.list.ErrorList) MapBasedNamespaceContext(com.helger.xml.namespace.MapBasedNamespaceContext) LoggerFactory(org.slf4j.LoggerFactory) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) FileSystemIterator(com.helger.commons.io.file.FileSystemIterator) File(java.io.File) Schema(javax.xml.validation.Schema) Assert.assertNull(org.junit.Assert.assertNull) IFileFilter(com.helger.commons.io.file.IFileFilter) ReadableResourceByteArray(com.helger.commons.io.resource.inmemory.ReadableResourceByteArray) Locale(java.util.Locale) XMLSchemaCache(com.helger.xml.schema.XMLSchemaCache) VOMType(com.helger.phive.engine.vom.v10.VOMType) Assert.assertEquals(org.junit.Assert.assertEquals) ArrayHelper(com.helger.commons.collection.ArrayHelper) VOMType(com.helger.phive.engine.vom.v10.VOMType) Schema(javax.xml.validation.Schema) ReadableResourceByteArray(com.helger.commons.io.resource.inmemory.ReadableResourceByteArray) IEdifactValidationExecutorProviderXML(com.helger.phive.engine.vom.VOM1ComplianceSettings.IEdifactValidationExecutorProviderXML) MapBasedNamespaceContext(com.helger.xml.namespace.MapBasedNamespaceContext) ErrorList(com.helger.commons.error.list.ErrorList) FileSystemIterator(com.helger.commons.io.file.FileSystemIterator) File(java.io.File) Test(org.junit.Test)

Example 2 with IEdifactValidationExecutorProviderXML

use of com.helger.phive.engine.vom.VOM1ComplianceSettings.IEdifactValidationExecutorProviderXML in project phive by phax.

the class VOM1MarshallerTest method testReadBadExamples.

@Test
public void testReadBadExamples() {
    final VOM1Marshaller m = new VOM1Marshaller();
    for (final File f : new FileSystemIterator(new File("src/test/resources/vom/bad")).withFilter(IFileFilter.filenameEndsWith(".xml"))) {
        LOGGER.info("Reading " + f.getName());
        final VOMType aVOM = m.read(f);
        assertNotNull(aVOM);
        final IVOMXmlSchemaResolver aXmlSchemaResolver = new MapBasedVOMXmlSchemaResolver();
        final IVOMNamespaceContextResolver aNamespaceContextResolver = new MapBasedVOMNamespaceContextResolver();
        final IVOMResourceResolver aResourceResolver = new MapBasedVOMResourceResolver();
        final IEdifactValidationExecutorProviderXML aEdifactProvider = (sDirectory, sMessage, aOptions) -> null;
        final VOM1ComplianceSettings aSettings = VOM1ComplianceSettings.builder().allowEdifact(true).edifactValidationExecutorProviderXML(aEdifactProvider).build();
        final ErrorList aErrorList = VOM1Validator.validate(aVOM, aXmlSchemaResolver, aNamespaceContextResolver, aResourceResolver, aSettings);
        for (final IError e : aErrorList) LOGGER.info("  " + e.getAsString(Locale.ROOT));
        assertTrue(aErrorList.getErrorCount() > 0);
    }
}
Also used : IEdifactValidationExecutorProviderXML(com.helger.phive.engine.vom.VOM1ComplianceSettings.IEdifactValidationExecutorProviderXML) Logger(org.slf4j.Logger) Assert.assertNotNull(org.junit.Assert.assertNotNull) IError(com.helger.commons.error.IError) ErrorList(com.helger.commons.error.list.ErrorList) MapBasedNamespaceContext(com.helger.xml.namespace.MapBasedNamespaceContext) LoggerFactory(org.slf4j.LoggerFactory) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) FileSystemIterator(com.helger.commons.io.file.FileSystemIterator) File(java.io.File) Schema(javax.xml.validation.Schema) Assert.assertNull(org.junit.Assert.assertNull) IFileFilter(com.helger.commons.io.file.IFileFilter) ReadableResourceByteArray(com.helger.commons.io.resource.inmemory.ReadableResourceByteArray) Locale(java.util.Locale) XMLSchemaCache(com.helger.xml.schema.XMLSchemaCache) VOMType(com.helger.phive.engine.vom.v10.VOMType) Assert.assertEquals(org.junit.Assert.assertEquals) ArrayHelper(com.helger.commons.collection.ArrayHelper) VOMType(com.helger.phive.engine.vom.v10.VOMType) IEdifactValidationExecutorProviderXML(com.helger.phive.engine.vom.VOM1ComplianceSettings.IEdifactValidationExecutorProviderXML) IError(com.helger.commons.error.IError) ErrorList(com.helger.commons.error.list.ErrorList) FileSystemIterator(com.helger.commons.io.file.FileSystemIterator) File(java.io.File) Test(org.junit.Test)

Example 3 with IEdifactValidationExecutorProviderXML

use of com.helger.phive.engine.vom.VOM1ComplianceSettings.IEdifactValidationExecutorProviderXML in project phive by phax.

the class VOM1Converter method _createExecutorEdifact.

@Nonnull
private IValidationExecutor<IValidationSourceXML> _createExecutorEdifact(@Nonnull final VOMEdifactType aEdifact) {
    final IEdifactValidationExecutorProviderXML aProvider = m_aComplianceSettings.getEdifactValidationExecutorProviderXML();
    final StringMap aOptions = new StringMap();
    for (final VOMOptionType aOption : aEdifact.getOption()) aOptions.put(aOption.getName(), aOption.getValue());
    LOGGER.info("Trying to resolve Edifact artifact '" + aEdifact.getDirectory() + '/' + aEdifact.getMessage() + "'");
    final IValidationExecutor<IValidationSourceXML> aVES = aProvider.createValidationExecutor(aEdifact.getDirectory(), aEdifact.getMessage(), aOptions);
    if (aVES == null)
        throw new IllegalStateException("Failed to resolve Edifact artifact '" + aEdifact.getDirectory() + '/' + aEdifact.getMessage() + "'");
    return aVES;
}
Also used : StringMap(com.helger.commons.collection.attr.StringMap) VOMOptionType(com.helger.phive.engine.vom.v10.VOMOptionType) IValidationSourceXML(com.helger.phive.engine.source.IValidationSourceXML) IEdifactValidationExecutorProviderXML(com.helger.phive.engine.vom.VOM1ComplianceSettings.IEdifactValidationExecutorProviderXML) Nonnull(javax.annotation.Nonnull)

Example 4 with IEdifactValidationExecutorProviderXML

use of com.helger.phive.engine.vom.VOM1ComplianceSettings.IEdifactValidationExecutorProviderXML in project phive by phax.

the class VOM1ConverterTest method testReadGoodExamples.

@Test
public void testReadGoodExamples() {
    final VOM1Marshaller m = new VOM1Marshaller();
    for (final File f : new FileSystemIterator(new File("src/test/resources/vom/good")).withFilter(IFileFilter.filenameEndsWith(".xml"))) {
        LOGGER.info("Reading " + f.getName());
        final VOMType aVOM = m.read(f);
        assertNotNull(aVOM);
        final IReadableResource aFakeXSD = new ReadableResourceByteArray("<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns=\"urn:1\" targetNamespace=\"urn:a\" version=\"1.0\"><xs:element name=\"a\" type=\"xs:string\" /></xs:schema>".getBytes(StandardCharsets.ISO_8859_1));
        final Schema aFakeSchema = XMLSchemaCache.getInstance().getSchema(aFakeXSD);
        final IVOMXmlSchemaResolver aXmlSchemaResolver = new MapBasedVOMXmlSchemaResolver().addMapping("ubl21-invoice", aFakeSchema);
        final IVOMNamespaceContextResolver aNamespaceContextResolver = new MapBasedVOMNamespaceContextResolver().addMapping("ubl21", new MapBasedNamespaceContext().addMapping("a", "urn:a"));
        final IVOMResourceResolver aResourceResolver = new MapBasedVOMResourceResolver().addMapping("cius-pt-200", new ReadableResourceByteArray(ArrayHelper.EMPTY_BYTE_ARRAY)).addMapping("cius-pt-201", new ReadableResourceByteArray(ArrayHelper.EMPTY_BYTE_ARRAY)).addMapping("atnat-invoice-6", new ReadableResourceByteArray(ArrayHelper.EMPTY_BYTE_ARRAY)).addMapping("xrechnung-ublinv-200", new ReadableResourceByteArray(ArrayHelper.EMPTY_BYTE_ARRAY)).addMapping("en16931-ublinv-132", new ReadableResourceByteArray(ArrayHelper.EMPTY_BYTE_ARRAY));
        final IVOMArtifactResolver aAR = aVESID -> {
            switch(aVESID.getAsSingleID()) {
                case "com.helger:test-special:1.5.678":
                    return new ReadableResourceByteArray("crap".getBytes(StandardCharsets.ISO_8859_1));
            }
            return null;
        };
        final IEdifactValidationExecutorProviderXML aEdifactProvider = (sDirectory, sMessage, aOptions) -> {
            if (sDirectory.equals("d01b") && sMessage.equals("DESADV"))
                return ValidationExecutorXSD.create(aFakeXSD);
            return null;
        };
        final VOM1ComplianceSettings aSettings = VOM1ComplianceSettings.builder().allowEdifact(true).edifactValidationExecutorProviderXML(aEdifactProvider).build();
        final ErrorList aErrorList = new ErrorList();
        final VOM1Converter aConverter1 = new VOM1Converter().xmlSchemaResolver(aXmlSchemaResolver).namespaceContextResolver(aNamespaceContextResolver).resourceResolver(aResourceResolver).complianceSettings(aSettings).artifactResolver(aAR).validationEnabled(true);
        final ValidationExecutorSet<IValidationSourceXML> aVES = aConverter1.convertToVES_XML(aVOM, aErrorList);
        assertNotNull(aErrorList.toString(), aVES);
    }
}
Also used : IEdifactValidationExecutorProviderXML(com.helger.phive.engine.vom.VOM1ComplianceSettings.IEdifactValidationExecutorProviderXML) Logger(org.slf4j.Logger) ValidationExecutorSet(com.helger.phive.api.executorset.ValidationExecutorSet) Assert.assertNotNull(org.junit.Assert.assertNotNull) ErrorList(com.helger.commons.error.list.ErrorList) MapBasedNamespaceContext(com.helger.xml.namespace.MapBasedNamespaceContext) IValidationSourceXML(com.helger.phive.engine.source.IValidationSourceXML) LoggerFactory(org.slf4j.LoggerFactory) IReadableResource(com.helger.commons.io.resource.IReadableResource) Test(org.junit.Test) FileSystemIterator(com.helger.commons.io.file.FileSystemIterator) ValidationExecutorXSD(com.helger.phive.engine.xsd.ValidationExecutorXSD) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) Schema(javax.xml.validation.Schema) IFileFilter(com.helger.commons.io.file.IFileFilter) ReadableResourceByteArray(com.helger.commons.io.resource.inmemory.ReadableResourceByteArray) XMLSchemaCache(com.helger.xml.schema.XMLSchemaCache) VOMType(com.helger.phive.engine.vom.v10.VOMType) ArrayHelper(com.helger.commons.collection.ArrayHelper) VOMType(com.helger.phive.engine.vom.v10.VOMType) Schema(javax.xml.validation.Schema) IReadableResource(com.helger.commons.io.resource.IReadableResource) IValidationSourceXML(com.helger.phive.engine.source.IValidationSourceXML) ReadableResourceByteArray(com.helger.commons.io.resource.inmemory.ReadableResourceByteArray) IEdifactValidationExecutorProviderXML(com.helger.phive.engine.vom.VOM1ComplianceSettings.IEdifactValidationExecutorProviderXML) MapBasedNamespaceContext(com.helger.xml.namespace.MapBasedNamespaceContext) ErrorList(com.helger.commons.error.list.ErrorList) FileSystemIterator(com.helger.commons.io.file.FileSystemIterator) File(java.io.File) Test(org.junit.Test)

Aggregations

IEdifactValidationExecutorProviderXML (com.helger.phive.engine.vom.VOM1ComplianceSettings.IEdifactValidationExecutorProviderXML)4 ArrayHelper (com.helger.commons.collection.ArrayHelper)3 ErrorList (com.helger.commons.error.list.ErrorList)3 FileSystemIterator (com.helger.commons.io.file.FileSystemIterator)3 IFileFilter (com.helger.commons.io.file.IFileFilter)3 ReadableResourceByteArray (com.helger.commons.io.resource.inmemory.ReadableResourceByteArray)3 VOMType (com.helger.phive.engine.vom.v10.VOMType)3 MapBasedNamespaceContext (com.helger.xml.namespace.MapBasedNamespaceContext)3 XMLSchemaCache (com.helger.xml.schema.XMLSchemaCache)3 File (java.io.File)3 Schema (javax.xml.validation.Schema)3 Assert.assertNotNull (org.junit.Assert.assertNotNull)3 Test (org.junit.Test)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 IError (com.helger.commons.error.IError)2 IValidationSourceXML (com.helger.phive.engine.source.IValidationSourceXML)2 Locale (java.util.Locale)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Assert.assertNull (org.junit.Assert.assertNull)2