use of org.mule.runtime.config.api.XmlConfigurationDocumentLoader in project mule by mulesoft.
the class XmlConfigurationDocumentLoaderTestCase method testMalformedXmlCustomGatherer.
@Test
public void testMalformedXmlCustomGatherer() throws XPathExpressionException {
// We will use a custom gathered that stores the errors but returns an empty list when asked
final XmlGathererErrorHandlerTest xmlGathererErrorHandlerTest = new XmlGathererErrorHandlerTest();
final XmlConfigurationDocumentLoader xmlConfigurationDocumentLoader = schemaValidatingDocumentLoader(() -> xmlGathererErrorHandlerTest);
// Validates that the DOM was properly parsed even when it was non-XSD valid
final Document document = getDocument("mule-config-malformed.xml", xmlConfigurationDocumentLoader);
assertThat(document, not(isNull()));
assertThat(document.getDocumentElement().getNodeName(), is("mule"));
assertThat(document.getDocumentElement().getChildNodes().getLength(), is(3));
final Node flow = document.getDocumentElement().getChildNodes().item(1);
assertThat(flow.getNodeName(), is("flow"));
assertThat(flow.getAttributes().getNamedItem("name").getNodeValue(), is("missing-inner-element"));
// Asserts over the gathered errors
assertThat(xmlGathererErrorHandlerTest.errors.size(), is(1));
assertThat(xmlGathererErrorHandlerTest.errors.get(0).getColumnNumber(), is(COLUMN_NUMBER_ERROR));
assertThat(xmlGathererErrorHandlerTest.errors.get(0).getLineNumber(), is(LINE_NUMBER_ERROR));
}
use of org.mule.runtime.config.api.XmlConfigurationDocumentLoader in project mule by mulesoft.
the class XmlExtensionLoaderDelegate method getModuleDocument.
private Document getModuleDocument(ExtensionLoadingContext context, URL resource) {
XmlConfigurationDocumentLoader xmlConfigurationDocumentLoader = validateXml ? schemaValidatingDocumentLoader() : schemaValidatingDocumentLoader(NoOpXmlErrorHandler::new);
try {
final Set<ExtensionModel> extensions = new HashSet<>(context.getDslResolvingContext().getExtensions());
createTnsExtensionModel(resource, extensions).ifPresent(extensions::add);
return xmlConfigurationDocumentLoader.loadDocument(extensions, resource.getFile(), resource.openStream());
} catch (IOException e) {
throw new MuleRuntimeException(createStaticMessage(format("There was an issue reading the stream for the resource %s", resource.getFile())));
}
}
Aggregations