Search in sources :

Example 6 with ConfiguredXpathQuery

use of com.adaptris.core.services.metadata.xpath.ConfiguredXpathQuery in project interlok by adaptris.

the class XpathMetadataServiceTest method testDoService_UsingXpathQuery_WithNamespaceContext.

@Test
public void testDoService_UsingXpathQuery_WithNamespaceContext() throws CoreException {
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_WITH_NAMESPACE);
    XpathMetadataService service = new XpathMetadataService();
    service.setXpathQueries(new ArrayList<XpathQuery>(Arrays.asList(new ConfiguredXpathQuery("failureCount", "count(/svrl:schematron-output/svrl:failed-assert)"))));
    service.setNamespaceContext(createContextEntries());
    execute(service, msg);
    assertTrue(msg.containsKey("failureCount"));
    assertEquals("2", msg.getMetadataValue("failureCount"));
}
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) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MultiItemConfiguredXpathQuery(com.adaptris.core.services.metadata.xpath.MultiItemConfiguredXpathQuery) ConfiguredXpathQuery(com.adaptris.core.services.metadata.xpath.ConfiguredXpathQuery) Test(org.junit.Test)

Example 7 with ConfiguredXpathQuery

use of com.adaptris.core.services.metadata.xpath.ConfiguredXpathQuery in project interlok by adaptris.

the class XpathMetadataServiceTest method testPayloadSingleAttributeValueXPathIntoMetadata.

@Test
public void testPayloadSingleAttributeValueXPathIntoMetadata() throws Exception {
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML);
    XpathMetadataService service = new XpathMetadataService();
    service.addXpathQuery(new ConfiguredXpathQuery("attribute", "//extra/@att"));
    service.addXpathQuery(new ConfiguredXpathQuery("attr", "//extraa/@att"));
    execute(service, msg);
    assertEquals("att", msg.getMetadataValue("attribute"));
    assertEquals("two", msg.getMetadataValue("attr"));
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MultiItemConfiguredXpathQuery(com.adaptris.core.services.metadata.xpath.MultiItemConfiguredXpathQuery) ConfiguredXpathQuery(com.adaptris.core.services.metadata.xpath.ConfiguredXpathQuery) Test(org.junit.Test)

Example 8 with ConfiguredXpathQuery

use of com.adaptris.core.services.metadata.xpath.ConfiguredXpathQuery in project interlok by adaptris.

the class XpathMetadataServiceTest method testDoService_NotXML.

@Test
public void testDoService_NotXML() throws Exception {
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage("ABCDEFG");
    XpathMetadataService service = new XpathMetadataService().withMetadataLogger(new TruncateMetadata(20));
    service.setXpathQueries(new ArrayList<XpathQuery>(Arrays.asList(new ConfiguredXpathQuery("source", "//source-id"), new ConfiguredXpathQuery("destination", "//destination-id"))));
    try {
        execute(service, msg);
        fail();
    } catch (ServiceException expected) {
    }
}
Also used : TruncateMetadata(com.adaptris.core.util.TruncateMetadata) 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) 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) Test(org.junit.Test)

Example 9 with ConfiguredXpathQuery

use of com.adaptris.core.services.metadata.xpath.ConfiguredXpathQuery in project interlok by adaptris.

the class XpathMetadataServiceTest method testDoService_UsingXpathQuery_WithNamespaceContext_NotNamespaceAware.

@Test
public void testDoService_UsingXpathQuery_WithNamespaceContext_NotNamespaceAware() throws CoreException {
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_WITH_NAMESPACE);
    XpathMetadataService service = new XpathMetadataService();
    service.setXpathQueries(new ArrayList<XpathQuery>(Arrays.asList(new ConfiguredXpathQuery("failureCount", "count(/schematron-output/failed-assert)"))));
    execute(service, msg);
    // count(/schematron-output/failed-assert) will return 0; becaue Saxon failed
    // like the mostly amusing thing that it is.
    assertEquals("0", msg.getMetadataValue("failureCount"));
    service.setXmlDocumentFactoryConfig(new DocumentBuilderFactoryBuilder().withNamespaceAware(false));
    execute(service, msg);
    assertTrue(msg.containsKey("failureCount"));
    assertEquals("2", msg.getMetadataValue("failureCount"));
}
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) 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 10 with ConfiguredXpathQuery

use of com.adaptris.core.services.metadata.xpath.ConfiguredXpathQuery in project interlok by adaptris.

the class XpathMetadataServiceTest method testSetXpathQueryList.

@Test
public void testSetXpathQueryList() {
    XpathMetadataService service = new XpathMetadataService();
    assertEquals(0, service.getXpathQueries().size());
    XpathQuery query = new ConfiguredXpathQuery("metadataKey", "//root");
    List<XpathQuery> list = new ArrayList<>();
    list.add(query);
    service.setXpathQueries(list);
    assertEquals(list, service.getXpathQueries());
    try {
        service.setXpathQueries(null);
        fail();
    } catch (IllegalArgumentException e) {
    }
    assertEquals(list, service.getXpathQueries());
}
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) MultiItemConfiguredXpathQuery(com.adaptris.core.services.metadata.xpath.MultiItemConfiguredXpathQuery) ConfiguredXpathQuery(com.adaptris.core.services.metadata.xpath.ConfiguredXpathQuery) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

ConfiguredXpathQuery (com.adaptris.core.services.metadata.xpath.ConfiguredXpathQuery)14 Test (org.junit.Test)12 MultiItemConfiguredXpathQuery (com.adaptris.core.services.metadata.xpath.MultiItemConfiguredXpathQuery)10 XpathQuery (com.adaptris.core.services.metadata.xpath.XpathQuery)10 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)8 MetadataXpathQuery (com.adaptris.core.services.metadata.xpath.MetadataXpathQuery)8 MultiItemMetadataXpathQuery (com.adaptris.core.services.metadata.xpath.MultiItemMetadataXpathQuery)8 ServiceException (com.adaptris.core.ServiceException)4 XpathObjectQuery (com.adaptris.core.services.metadata.xpath.XpathObjectQuery)2 DocumentBuilderFactoryBuilder (com.adaptris.core.util.DocumentBuilderFactoryBuilder)2 ArrayList (java.util.ArrayList)2 LogMessageService (com.adaptris.core.services.LogMessageService)1 AddMetadataService (com.adaptris.core.services.metadata.AddMetadataService)1 XpathMetadataService (com.adaptris.core.services.metadata.XpathMetadataService)1 TruncateMetadata (com.adaptris.core.util.TruncateMetadata)1 KeyValuePair (com.adaptris.util.KeyValuePair)1