use of com.adaptris.core.util.DocumentBuilderFactoryBuilder in project interlok by adaptris.
the class XpathQueryHelperTest method testResolveMultipleTextItems.
@Test
public void testResolveMultipleTextItems() throws Exception {
DocumentBuilderFactoryBuilder builder = DocumentBuilderFactoryBuilder.newInstance();
Document doc = XmlHelper.createDocument(XpathQueryCase.XML, builder);
XPath xpathToUse = XPath.newXPathInstance(builder, null);
assertNotNull(XpathQueryHelper.resolveMultipleTextItems(doc, xpathToUse, "//extra", false, "|"));
assertEquals("one|two|three", XpathQueryHelper.resolveMultipleTextItems(doc, xpathToUse, "//extra", false, "|"));
}
use of com.adaptris.core.util.DocumentBuilderFactoryBuilder in project interlok by adaptris.
the class XpathDocumentCopierTest method testSplit_DocTypeNotAllowed.
@Test
public void testSplit_DocTypeNotAllowed() throws Exception {
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
msg.setContent(XML_WITH_DOCTYPE, msg.getContentEncoding());
XpathDocumentCopier splitter = new XpathDocumentCopier(XPATH_DOCUMENT_COUNT);
DocumentBuilderFactoryBuilder builder = new DocumentBuilderFactoryBuilder();
builder.getFeatures().add(new KeyValuePair("http://apache.org/xml/features/disallow-doctype-decl", "true"));
splitter.setXmlDocumentFactoryConfig(builder);
try {
List<AdaptrisMessage> result = splitToList(splitter, msg);
fail();
} catch (CoreException expected) {
assertTrue(expected.getMessage().contains("DOCTYPE is disallowed"));
}
}
use of com.adaptris.core.util.DocumentBuilderFactoryBuilder in project interlok by adaptris.
the class XpathSplitterTest method testSplit_DocTypeNotAllowed.
@Test
public void testSplit_DocTypeNotAllowed() throws Exception {
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
msg.setContent(XML_WITH_DOCTYPE, msg.getContentEncoding());
XpathMessageSplitter splitter = new XpathMessageSplitter(ENVELOPE_DOCUMENT, ENCODING_UTF8);
DocumentBuilderFactoryBuilder builder = new DocumentBuilderFactoryBuilder();
builder.getFeatures().add(new KeyValuePair("http://apache.org/xml/features/disallow-doctype-decl", "true"));
splitter.setXmlDocumentFactoryConfig(builder);
try {
splitter.splitMessage(msg);
fail();
} catch (CoreException expected) {
assertTrue(expected.getMessage().contains("DOCTYPE is disallowed"));
}
}
use of com.adaptris.core.util.DocumentBuilderFactoryBuilder in project interlok by adaptris.
the class XpathSplitterTest method testXmlSplitter_Namespace.
@Test
public void testXmlSplitter_Namespace() throws Exception {
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XpathMetadataServiceTest.XML_WITH_NAMESPACE);
XpathMessageSplitter splitter = new XpathMessageSplitter("/svrl:schematron-output/svrl:failed-assert", "UTF-8");
splitter.setNamespaceContext(XpathMetadataServiceTest.createContextEntries());
NamespaceContext namespaceCtx = SimpleNamespaceContext.create(XpathMetadataServiceTest.createContextEntries());
DocumentBuilderFactoryBuilder builder = DocumentBuilderFactoryBuilder.newInstance().withNamespaceAware(namespaceCtx);
// Should be 2 splits
int count = 0;
XPath xpath = XPath.newXPathInstance(builder, namespaceCtx);
try (CloseableIterable<AdaptrisMessage> closeable = splitter.splitMessage(msg)) {
for (AdaptrisMessage m : closeable) {
count++;
assertNotNull(xpath.selectSingleNode(XmlHelper.createDocument(m, builder), "/svrl:failed-assert"));
}
}
assertEquals("Number of messages", 2, count);
}
use of com.adaptris.core.util.DocumentBuilderFactoryBuilder in project interlok by adaptris.
the class XmlValidationServiceTest method testSimpleValidator_IsInvalidXml_LessThan.
@Test
public void testSimpleValidator_IsInvalidXml_LessThan() throws Exception {
XmlBasicValidator validator = new XmlBasicValidator(new DocumentBuilderFactoryBuilder());
AdaptrisMessage msg = new DefaultMessageFactory().newMessage("<?xml version=\"1.0\"?><Root><</Root>");
XmlValidationService service = new XmlValidationService(validator);
try {
execute(service, msg);
fail("Success with invalid XML");
} catch (ServiceException e) {
;
}
}
Aggregations