use of com.adaptris.core.MetadataElement in project interlok by adaptris.
the class OrderedItemMetadataFilter method filter.
@Override
public MetadataCollection filter(MetadataCollection originalCollection) {
MetadataCollection results = new MetadataCollection();
Map<String, String> original;
if (ignoreCase()) {
original = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
original.putAll(MetadataCollection.asMap(originalCollection));
} else {
original = MetadataCollection.asMap(originalCollection);
}
for (String key : getMetadataKeys()) {
String value = original.get(key);
if (value != null) {
results.add(new MetadataElement(key, value));
} else {
results.add(new MetadataElement(key, ""));
}
}
return results;
}
use of com.adaptris.core.MetadataElement in project interlok by adaptris.
the class LargeMessageWorkflowTest method testRuntimeException.
@Override
@Test
public void testRuntimeException() throws Exception {
MockMessageProducer producer = new MockMessageProducer() {
@Override
protected void doProduce(AdaptrisMessage msg, String endpoint) throws ProduceException {
throw new RuntimeException();
}
};
;
MockMessageProducer meh = new MockMessageProducer();
MockChannel channel = createChannel(producer, Arrays.asList(new Service[] { new AddMetadataService(Arrays.asList(new MetadataElement[] { new MetadataElement(METADATA_KEY, METADATA_VALUE) })), new PayloadFromTemplateService().withTemplate(PAYLOAD_2) }));
try {
LargeMessageWorkflow workflow = (LargeMessageWorkflow) channel.getWorkflowList().get(0);
channel.setMessageErrorHandler(new StandardProcessingExceptionHandler(new ServiceList(new ArrayList<Service>(Arrays.asList(new Service[] { new StandaloneProducer(meh) })))));
channel.prepare();
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(PAYLOAD_1);
start(channel);
workflow.onAdaptrisMessage(msg);
assertEquals("Make none produced", 0, producer.getMessages().size());
assertEquals(1, meh.getMessages().size());
for (AdaptrisMessage m : meh.getMessages()) {
assertEquals(PAYLOAD_2, m.getContent());
assertTrue("Contains correct metadata key", m.containsKey(METADATA_KEY));
assertEquals(METADATA_VALUE, m.getMetadataValue(METADATA_KEY));
}
} finally {
stop(channel);
}
}
use of com.adaptris.core.MetadataElement in project interlok by adaptris.
the class MimePartChooserTest method testSelect_MarkAsNotMime_OriginalWasNotMarked.
@Test
public void testSelect_MarkAsNotMime_OriginalWasNotMarked() throws Exception {
MimePartSelector mps = createBaseService();
mps.setSelector(new com.adaptris.util.text.mime.SelectByPosition(1));
mps.setMarkAsNonMime(true);
AdaptrisMessage msg = create();
msg.removeMetadata(new MetadataElement(CoreConstants.MSG_MIME_ENCODED, "true"));
assertFalse("Should be not marked as a MIME Message", msg.containsKey(CoreConstants.MSG_MIME_ENCODED));
execute(mps, msg);
assertEquals(ASSERT_PAYLOAD, PAYLOAD_2, msg.getContent());
assertTrue(ASSERT_MSG_SUBJECT_HEADER, msg.containsKey(KEY_METADATA_SUBJECT));
assertTrue(ASSERT_PART_CID_HEADER, msg.containsKey(METADATA_PART_HDR_CONTENT_ID));
assertFalse("Should no longer be marked as a MIME Message", msg.containsKey(CoreConstants.MSG_MIME_ENCODED));
}
use of com.adaptris.core.MetadataElement in project interlok by adaptris.
the class MetadataXpathQueryTest method testResolveXpath_EmptyResults_Allowed.
@Test
public void testResolveXpath_EmptyResults_Allowed() throws Exception {
MetadataXpathQuery query = init(create());
query.setAllowEmptyResults(Boolean.TRUE);
Document doc = XmlHelper.createDocument(XML);
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML);
msg.addMetadata("xpathMetadataKey", "//@MissingAttribute");
MetadataElement result = query.resolveXpath(doc, new XPath(), query.createXpathQuery(msg));
assertEquals("", result.getValue());
}
use of com.adaptris.core.MetadataElement in project interlok by adaptris.
the class MetadataXpathQueryTest method testResolveXpath_EmptyResults_NotAllowed.
@Test
public void testResolveXpath_EmptyResults_NotAllowed() throws Exception {
MetadataXpathQuery query = init(create());
Document doc = XmlHelper.createDocument(XML);
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML);
msg.addMetadata("xpathMetadataKey", "//@MissingAttribute");
try {
MetadataElement result = query.resolveXpath(doc, new XPath(), query.createXpathQuery(msg));
fail();
} catch (CoreException expected) {
}
}
Aggregations