use of com.adaptris.util.XmlUtils in project interlok by adaptris.
the class XmlPayloadTranslatorTest method testPreserveOriginal.
@Test
public void testPreserveOriginal() throws Exception {
createDatabase();
List<AdapterTypeVersion> dbItems = generate(10);
AdapterTypeVersion entry = dbItems.get(0);
populateDatabase(dbItems, false);
JdbcDataQueryService s = createMetadataService();
XmlPayloadTranslator t = new XmlPayloadTranslator();
t.setPreserveOriginalMessage(true);
s.setResultSetTranslator(t);
AdaptrisMessage msg = createMessage(entry);
execute(s, msg);
assertTrue(ADAPTER_ID_KEY + " exists", msg.containsKey(ADAPTER_ID_KEY));
XmlUtils xu = XmlHelper.createXmlUtils(msg);
assertNotNull("Xpath /Results/OriginalMessage", xu.getSingleNode("/Results/OriginalMessage"));
assertNotNull("/Results/Row", xu.getSingleNode("/Results/Row"));
}
use of com.adaptris.util.XmlUtils in project interlok by adaptris.
the class XmlPayloadTranslatorTest method testMetadataStatementParam.
@Test
public void testMetadataStatementParam() throws Exception {
createDatabase();
List<AdapterTypeVersion> dbItems = generate(10);
AdapterTypeVersion entry = dbItems.get(0);
populateDatabase(dbItems, false);
JdbcDataQueryService s = createMetadataService();
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()));
XmlUtils xu = XmlHelper.createXmlUtils(msg);
assertNull("Xpath /Results/OriginalMessage", xu.getSingleNode("/Results/OriginalMessage"));
assertNotNull("/Results/Row", xu.getSingleNode("/Results/Row"));
}
use of com.adaptris.util.XmlUtils in project interlok by adaptris.
the class XmlPayloadTranslatorTest method testContainsRowCount.
@Test
public void testContainsRowCount() throws Exception {
createDatabase();
List<AdapterTypeVersion> dbItems = generate(10);
AdapterTypeVersion entry = dbItems.get(0);
populateDatabase(dbItems, false);
JdbcDataQueryService s = createMetadataService();
XmlPayloadTranslator t = new XmlPayloadTranslator();
t.setResultCountMetadataItem(getName());
s.setResultSetTranslator(t);
AdaptrisMessage msg = createMessage(entry);
execute(s, msg);
assertTrue(ADAPTER_ID_KEY + " exists", msg.containsKey(ADAPTER_ID_KEY));
XmlUtils xu = XmlHelper.createXmlUtils(msg);
assertNull("Xpath /Results/OriginalMessage", xu.getSingleNode("/Results/OriginalMessage"));
assertNotNull("/Results/Row", xu.getSingleNode("/Results/Row"));
assertTrue(msg.containsKey(getName()));
assertEquals("1", msg.getMetadataValue(getName()));
}
use of com.adaptris.util.XmlUtils in project interlok by adaptris.
the class XmlNotificationSerializer method serialize.
@Override
public AdaptrisMessage serialize(Notification n, AdaptrisMessage msg) throws CoreException, IOException {
try {
XmlUtils xmlBuilder = new XmlUtils();
Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
Element root = doc.createElement(XML_ROOT_ELEMENT);
doc.appendChild(root);
xmlBuilder.setSource(doc);
for (NotificationElement e : NotificationElement.values()) {
xmlBuilder.setNodeValue(e.xpathToNode(), e.getValue(n));
}
try (OutputStream out = msg.getOutputStream()) {
String encoding = XmlHelper.getXmlEncoding(msg, getOutputMessageEncoding());
xmlBuilder.writeDocument(out, encoding);
msg.setContentEncoding(encoding);
}
if (n.getUserData() != null) {
msg.getObjectHeaders().put(OBJ_METADATA_USERDATA, n.getUserData());
}
} catch (Exception e) {
throw ExceptionHelper.wrapCoreException(e);
}
return msg;
}
use of com.adaptris.util.XmlUtils in project interlok by adaptris.
the class InsertNodeTest method testInsertNode_NodeDoesNotExist.
@Test
public void testInsertNode_NodeDoesNotExist() throws Exception {
InsertNode rn = new InsertNode("/Root/AnotherNode");
rn.setXmlDocumentFactoryConfig(DocumentBuilderFactoryBuilder.newInstance());
Document merged = rn.merge(XmlHelper.createDocument(ORIGINAL), XmlHelper.createDocument(REPLACEMENT));
XmlUtils xml = new XmlUtils();
xml.setSource(merged);
assertNotNull(xml.getSingleTextItem(XPATH_ORIGINAL_NODE));
assertEquals(DATA_A, xml.getSingleTextItem(XPATH_ORIGINAL_NODE));
assertEquals(DATA_B, xml.getSingleTextItem("/Root/AnotherNode/NewNode"));
}
Aggregations