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