Search in sources :

Example 1 with DocumentBuilderFactoryBuilder

use of com.adaptris.core.util.DocumentBuilderFactoryBuilder in project interlok by adaptris.

the class XpathMetadataServiceTest method testDoService_DisableDocType.

@Test
public void testDoService_DisableDocType() throws CoreException {
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_WITH_DOCTYPE);
    XpathMetadataService service = new XpathMetadataService();
    // Shouldn't matter what the query actually is.
    service.setXpathQueries(new ArrayList<XpathQuery>(Arrays.asList(new ConfiguredXpathQuery("source", "//source-id"), new ConfiguredXpathQuery("destination", "//destination-id"))));
    DocumentBuilderFactoryBuilder builder = new DocumentBuilderFactoryBuilder();
    builder.getFeatures().add(new KeyValuePair("http://apache.org/xml/features/disallow-doctype-decl", "true"));
    service.setXmlDocumentFactoryConfig(builder);
    try {
        execute(service, msg);
        fail();
    } catch (ServiceException expected) {
        assertTrue(expected.getMessage().contains("DOCTYPE is disallowed"));
    }
}
Also used : XpathQuery(com.adaptris.core.services.metadata.xpath.XpathQuery) MultiItemConfiguredXpathQuery(com.adaptris.core.services.metadata.xpath.MultiItemConfiguredXpathQuery) MetadataXpathQuery(com.adaptris.core.services.metadata.xpath.MetadataXpathQuery) MultiItemMetadataXpathQuery(com.adaptris.core.services.metadata.xpath.MultiItemMetadataXpathQuery) ConfiguredXpathQuery(com.adaptris.core.services.metadata.xpath.ConfiguredXpathQuery) KeyValuePair(com.adaptris.util.KeyValuePair) ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MultiItemConfiguredXpathQuery(com.adaptris.core.services.metadata.xpath.MultiItemConfiguredXpathQuery) ConfiguredXpathQuery(com.adaptris.core.services.metadata.xpath.ConfiguredXpathQuery) DocumentBuilderFactoryBuilder(com.adaptris.core.util.DocumentBuilderFactoryBuilder) Test(org.junit.Test)

Example 2 with DocumentBuilderFactoryBuilder

use of com.adaptris.core.util.DocumentBuilderFactoryBuilder in project interlok by adaptris.

the class XpathQueryHelperTest method resolveSingleNode_Missing_AllowEmptyTrue.

@Test
public void resolveSingleNode_Missing_AllowEmptyTrue() throws Exception {
    DocumentBuilderFactoryBuilder builder = DocumentBuilderFactoryBuilder.newInstance();
    Document doc = XmlHelper.createDocument(XpathQueryCase.XML, builder);
    XPath xpathToUse = XPath.newXPathInstance(builder, null);
    assertNull(XpathQueryHelper.resolveSingleNode(doc, xpathToUse, "//@MissingAttribute", true));
}
Also used : XPath(com.adaptris.util.text.xml.XPath) DocumentBuilderFactoryBuilder(com.adaptris.core.util.DocumentBuilderFactoryBuilder) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 3 with DocumentBuilderFactoryBuilder

use of com.adaptris.core.util.DocumentBuilderFactoryBuilder in project interlok by adaptris.

the class XpathQueryHelperTest method testResolveSingleTextItem_Missing_AllowEmptyFalse.

@Test(expected = CoreException.class)
public void testResolveSingleTextItem_Missing_AllowEmptyFalse() throws Exception {
    DocumentBuilderFactoryBuilder builder = DocumentBuilderFactoryBuilder.newInstance();
    Document doc = XmlHelper.createDocument(XpathQueryCase.XML, builder);
    XPath xpathToUse = XPath.newXPathInstance(builder, null);
    XpathQueryHelper.resolveSingleTextItem(doc, xpathToUse, "//@MissingAttribute", false);
}
Also used : XPath(com.adaptris.util.text.xml.XPath) DocumentBuilderFactoryBuilder(com.adaptris.core.util.DocumentBuilderFactoryBuilder) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 4 with DocumentBuilderFactoryBuilder

use of com.adaptris.core.util.DocumentBuilderFactoryBuilder in project interlok by adaptris.

the class XpathQueryHelperTest method testResolveMultipleTextItems_Missing_AllowEmptyFalse.

@Test(expected = CoreException.class)
public void testResolveMultipleTextItems_Missing_AllowEmptyFalse() throws Exception {
    DocumentBuilderFactoryBuilder builder = DocumentBuilderFactoryBuilder.newInstance();
    Document doc = XmlHelper.createDocument(XpathQueryCase.XML, builder);
    XPath xpathToUse = XPath.newXPathInstance(builder, null);
    XpathQueryHelper.resolveMultipleTextItems(doc, xpathToUse, "//@MissingAttribute", false, "|");
}
Also used : XPath(com.adaptris.util.text.xml.XPath) DocumentBuilderFactoryBuilder(com.adaptris.core.util.DocumentBuilderFactoryBuilder) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 5 with DocumentBuilderFactoryBuilder

use of com.adaptris.core.util.DocumentBuilderFactoryBuilder in project interlok by adaptris.

the class XpathQueryHelperTest method testResolveMultipleNode_Missing_AllowEmptyFalse.

@Test(expected = CoreException.class)
public void testResolveMultipleNode_Missing_AllowEmptyFalse() throws Exception {
    DocumentBuilderFactoryBuilder builder = DocumentBuilderFactoryBuilder.newInstance();
    Document doc = XmlHelper.createDocument(XpathQueryCase.XML, builder);
    XPath xpathToUse = XPath.newXPathInstance(builder, null);
    XpathQueryHelper.resolveNodeList(doc, xpathToUse, "//@MissingAttribute", false);
}
Also used : XPath(com.adaptris.util.text.xml.XPath) DocumentBuilderFactoryBuilder(com.adaptris.core.util.DocumentBuilderFactoryBuilder) Document(org.w3c.dom.Document) Test(org.junit.Test)

Aggregations

DocumentBuilderFactoryBuilder (com.adaptris.core.util.DocumentBuilderFactoryBuilder)32 XPath (com.adaptris.util.text.xml.XPath)21 Document (org.w3c.dom.Document)21 Test (org.junit.Test)18 NamespaceContext (javax.xml.namespace.NamespaceContext)12 CoreException (com.adaptris.core.CoreException)10 SimpleNamespaceContext (com.adaptris.util.text.xml.SimpleNamespaceContext)10 ServiceException (com.adaptris.core.ServiceException)8 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)6 KeyValuePair (com.adaptris.util.KeyValuePair)4 NodeList (org.w3c.dom.NodeList)4 XpathQuery (com.adaptris.core.services.metadata.xpath.XpathQuery)3 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)3 Node (org.w3c.dom.Node)3 XpathMetadataServiceTest (com.adaptris.core.services.metadata.XpathMetadataServiceTest)2 ConfiguredXpathQuery (com.adaptris.core.services.metadata.xpath.ConfiguredXpathQuery)2 MetadataXpathQuery (com.adaptris.core.services.metadata.xpath.MetadataXpathQuery)2 MultiItemConfiguredXpathQuery (com.adaptris.core.services.metadata.xpath.MultiItemConfiguredXpathQuery)2 MultiItemMetadataXpathQuery (com.adaptris.core.services.metadata.xpath.MultiItemMetadataXpathQuery)2 XmlHelper.createDocument (com.adaptris.core.util.XmlHelper.createDocument)2