use of com.adaptris.util.XmlUtils in project interlok by adaptris.
the class SplittingXmlPayloadTranslatorTest method testMultipleResultMessages.
@Test
public void testMultipleResultMessages() throws Exception {
createDatabase();
List<AdapterTypeVersion> dbItems = generate(11);
AdapterTypeVersion entry = dbItems.get(0);
populateDatabase(dbItems, false);
JdbcDataQueryService s = createMultiService();
SplittingXmlPayloadTranslator translator = createPayloadTranslator().withMaxRowsPerMessage(2);
s.setResultSetTranslator(translator);
AdaptrisMessage msg = createMessage(entry);
execute(s, msg);
assertTrue(msg.headersContainsKey(ADAPTER_ID_KEY));
assertFalse(msg.headersContainsKey(JdbcDataQueryService.class.getCanonicalName()));
List<AdaptrisMessage> outputMessages = producer.getMessages();
assertEquals(6, outputMessages.size());
int count = 0;
for (AdaptrisMessage outputMessage : outputMessages) {
XmlUtils xu = XmlHelper.createXmlUtils(outputMessage);
assertNull("Xpath /Results/OriginalMessage", xu.getSingleNode("/Results/OriginalMessage"));
assertEquals("/Results/Row", count < 5 ? 2 : 1, xu.getNodeList("/Results/Row").getLength());
assertFalse(outputMessage.headersContainsKey(ADAPTER_ID_KEY));
count++;
}
}
use of com.adaptris.util.XmlUtils in project interlok by adaptris.
the class XmlHelperTest method testCreateDocument.
@Test
public void testCreateDocument() throws Exception {
Document d = XmlHelper.createDocument(EXAMPLE_XML);
assertNotNull(d);
XmlUtils xu = new XmlUtils();
xu.setSource(d);
assertEquals("text body", xu.getSingleTextItem("/document/content"));
assertNotNull(createDocument(EXAMPLE_XML, DocumentBuilderFactoryBuilderTest.createNamespaceContext()));
assertNotNull(createDocument(EXAMPLE_XML, (NamespaceContext) null));
}
use of com.adaptris.util.XmlUtils in project interlok by adaptris.
the class ReplaceNodeTest method testReplaceNode.
@Test
public void testReplaceNode() throws Exception {
ReplaceNode rn = new ReplaceNode(XPATH_ROOT_NODE);
Document original = XmlHelper.createDocument(ORIGINAL);
Document newDoc = XmlHelper.createDocument(REPLACEMENT);
Document merged = rn.merge(original, newDoc);
XmlUtils xml = new XmlUtils();
xml.setSource(merged);
assertNotNull(xml.getSingleTextItem(XPATH_ROOT_NODE));
assertNotSame(DATA_A, xml.getSingleTextItem(XPATH_ROOT_NODE));
assertEquals(DATA_B, xml.getSingleTextItem(XPATH_ROOT_NODE));
}
use of com.adaptris.util.XmlUtils in project interlok by adaptris.
the class InsertNodeTest method testInsertNode.
@Test
public void testInsertNode() throws Exception {
InsertNode rn = new InsertNode(XPATH_ROOT);
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(XPATH_NEW_NODE));
}
use of com.adaptris.util.XmlUtils in project interlok by adaptris.
the class SharedComponentConfigurationChecker method performConfigCheck.
@Override
public ConfigurationCheckReport performConfigCheck(ConfigurationCheckReport report, BootstrapProperties bootProperties) {
try {
String xml = CachingConfigLoader.loadInterlokConfig(bootProperties);
try (InputStream in = IOUtils.toInputStream(xml, Charset.defaultCharset())) {
XmlUtils xmlUtils = new XmlUtils();
xmlUtils.setSource(in);
Set<String> availableComponents = evaluate(xmlUtils, xpathAvailableComponents);
Set<String> referencedComponents = evaluate(xmlUtils, xpathReferencedComponents);
// **********************************
// Check all shared components are used.
availableComponents.forEach(component -> {
if (!referencedComponents.contains(component)) {
report.getWarnings().add("Shared " + componentType + " unused: " + component);
}
});
// **********************************
// Check all referenced components exist.
referencedComponents.forEach(component -> {
if (!availableComponents.contains(component)) {
report.getFailureExceptions().add(new ConfigurationException("Shared " + componentType + " does not exist in shared components: " + component));
}
});
}
} catch (Exception ex) {
report.getFailureExceptions().add(ex);
}
return report;
}
Aggregations