use of com.adaptris.util.text.xml.XPath in project interlok by adaptris.
the class XmlPayloadTranslatorTest method testXpathStatementParam.
@Test
public void testXpathStatementParam() throws Exception {
createDatabase();
List<AdapterTypeVersion> dbItems = generate(10);
AdapterTypeVersion entry = dbItems.get(0);
populateDatabase(dbItems, false);
JdbcDataQueryService s = createXmlService();
s.setResultSetTranslator(new XmlPayloadTranslator());
AdaptrisMessage msg = createMessage(entry);
execute(s, msg);
assertTrue(ADAPTER_ID_KEY + " exists", msg.containsKey(ADAPTER_ID_KEY));
assertNotSame(XML_PAYLOAD_PREFIX + entry.getUniqueId() + XML_PAYLOAD_SUFFIX, msg.getContent());
assertFalse(msg.containsKey(JdbcDataQueryService.class.getCanonicalName()));
System.out.println(msg.getContent());
XPath xp = new XPath();
Document xmlDoc = XmlHelper.createDocument(msg, DocumentBuilderFactoryBuilder.newInstance());
assertNull(xp.selectSingleNode(xmlDoc, "/Results/OriginalMessage"));
assertNotNull(xp.selectSingleNode(xmlDoc, "/Results/Row"));
assertEquals(entry.getVersion(), xp.selectSingleTextItem(xmlDoc, "/Results/Row/ADAPTER_VERSION"));
assertEquals(String.valueOf(entry.getCounter()), xp.selectSingleTextItem(xmlDoc, "/Results/Row/COUNTER"));
assertEquals(entry.getTranslatorType(), xp.selectSingleTextItem(xmlDoc, "/Results/Row/MESSAGE_TRANSLATOR_TYPE"));
// Convert date into a Timestamp for toString purposes, as it's different from Date.toString()
assertEquals(new Timestamp(entry.getDate().getTime()).toString(), xp.selectSingleTextItem(xmlDoc, "/Results/Row/INSERTED_ON"));
}
use of com.adaptris.util.text.xml.XPath in project interlok by adaptris.
the class XmlPayloadTranslatorTest method testService_XpathParam_WithTranslators.
@Test
public void testService_XpathParam_WithTranslators() throws Exception {
createDatabase();
List<AdapterTypeVersion> dbItems = generate(10);
AdapterTypeVersion entry = dbItems.get(0);
populateDatabase(dbItems, false);
JdbcDataQueryService s = createXmlService();
s.setResultSetTranslator(new XmlPayloadTranslator().withColumnTranslators(new StringColumnTranslator(), new StringColumnTranslator(), new TimestampColumnTranslator(), new IntegerColumnTranslator()).withColumnNameStyle(ColumnStyle.NoStyle));
AdaptrisMessage msg = createMessage(entry);
execute(s, msg);
XPath xp = new XPath();
Document xmlDoc = XmlHelper.createDocument(msg, DocumentBuilderFactoryBuilder.newInstance());
assertNull(xp.selectSingleNode(xmlDoc, "/Results/OriginalMessage"));
assertNotNull(xp.selectSingleNode(xmlDoc, "/Results/Row"));
assertEquals(entry.getVersion(), xp.selectSingleTextItem(xmlDoc, "/Results/Row/ADAPTER_VERSION"));
assertEquals(String.valueOf(entry.getCounter()), xp.selectSingleTextItem(xmlDoc, "/Results/Row/COUNTER"));
assertEquals(entry.getTranslatorType(), xp.selectSingleTextItem(xmlDoc, "/Results/Row/MESSAGE_TRANSLATOR_TYPE"));
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
assertEquals(df.format(entry.getDate()), xp.selectSingleTextItem(xmlDoc, "/Results/Row/INSERTED_ON"));
}
use of com.adaptris.util.text.xml.XPath in project interlok by adaptris.
the class MetadataXpathQueryTest method testResolveXpath_function.
@Test
public void testResolveXpath_function() throws Exception {
MetadataXpathQuery query = init(create());
Document doc = XmlHelper.createDocument(XML);
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML);
msg.addMetadata("xpathMetadataKey", "count(/message)");
MetadataElement result = query.resolveXpath(doc, new XPath(), query.createXpathQuery(msg));
assertEquals("1", result.getValue());
}
use of com.adaptris.util.text.xml.XPath in project interlok by adaptris.
the class MetadataXpathQueryTest method testResolveNodesAsString.
@Test
public void testResolveNodesAsString() throws Exception {
MetadataXpathQuery query = init(create());
query.setAsXmlString(true);
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML);
msg.addMetadata("xpathMetadataKey", "//source-id");
MetadataElement result = query.resolveXpath(XmlHelper.createDocument(msg.getContent()), new XPath(), query.createXpathQuery(msg));
assertEquals("<source-id>partnera</source-id>", result.getValue().strip());
}
use of com.adaptris.util.text.xml.XPath in project interlok by adaptris.
the class MetadataXpathQueryTest method testResolveXpath_NamespaceWithNamespaceContext.
// Invalid test
// Namedspaced document with non-namespace xpath never matches with SAXON
// public void testResolveXpath_NamespaceNoNamespaceContext() throws Exception {
// MetadataXpathQuery query = init(create());
// Document doc = XmlHelper.createDocument(XML_WITH_NAMESPACE);
// AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_WITH_NAMESPACE);
// msg.addMetadata("xpathMetadataKey", "count(/schematron-output/failed-assert)");
// MetadataElement result = query.resolveXpath(doc, null, query.createXpathQuery(msg));
// assertEquals("2", result.getValue());
// }
@Test
public void testResolveXpath_NamespaceWithNamespaceContext() throws Exception {
MetadataXpathQuery query = init(create());
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_WITH_NAMESPACE);
msg.addMetadata("xpathMetadataKey", "count(/svrl:schematron-output/svrl:failed-assert)");
StaticNamespaceContext ctx = new StaticNamespaceContext();
Document doc = XmlHelper.createDocument(XML_WITH_NAMESPACE, ctx);
MetadataElement result = query.resolveXpath(doc, new XPath(ctx), query.createXpathQuery(msg));
assertEquals("2", result.getValue());
}
Aggregations