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());
}
}
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);
}
}
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;
}
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);
}
}
Aggregations