use of com.adaptris.core.services.metadata.AddMetadataService in project interlok by adaptris.
the class StandardWorkflowTest method testRuntimeException.
@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 {
StandardWorkflow workflow = (StandardWorkflow) 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 (Iterator i = meh.getMessages().iterator(); i.hasNext(); ) {
AdaptrisMessage m = (AdaptrisMessage) i.next();
assertEquals(PAYLOAD_1, m.getContent());
assertFalse("Does not contains correct metadata key", m.containsKey(METADATA_KEY));
}
} finally {
stop(channel);
}
}
use of com.adaptris.core.services.metadata.AddMetadataService in project interlok by adaptris.
the class StandardProcessingExceptionHandlerTest method testServiceListWithAddMetadata.
@Test
public void testServiceListWithAddMetadata() throws Exception {
StandardProcessingExceptionHandler meh = new StandardProcessingExceptionHandler();
MockMessageProducer producer = new MockMessageProducer();
try {
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage("XXXX");
meh.setProcessingExceptionService(new ServiceList(Arrays.asList(new Service[] { new StandaloneProducer(producer), new AddMetadataService(Arrays.asList(new MetadataElement[] { new MetadataElement("myKey", "myValue") })), new StandaloneProducer(producer) })));
start(meh);
meh.handleProcessingException(msg);
log.debug("Number of messages " + producer.getMessages().size());
assertTrue("Make sure all produced", producer.getMessages().size() == 2);
assertTrue(producer.getMessages().get(1).containsKey("myKey"));
assertEquals("myValue", producer.getMessages().get(1).getMetadataValue("myKey"));
} finally {
stop(meh);
}
}
use of com.adaptris.core.services.metadata.AddMetadataService in project interlok by adaptris.
the class BranchingServiceCollectionTest method setUp.
@Before
public void setUp() throws Exception {
branchService = new TestBranchingService();
branchService.setUniqueId(FIRST_SERVICE_ID);
lowService = new AddMetadataService();
lowService.setUniqueId(BRANCH_LOW);
lowService.addMetadataElement("service-id", BRANCH_LOW);
highService = new AddMetadataService();
highService.setUniqueId(BRANCH_HIGH);
highService.addMetadataElement("service-id", BRANCH_HIGH);
openMocks = MockitoAnnotations.openMocks(this);
}
use of com.adaptris.core.services.metadata.AddMetadataService in project interlok by adaptris.
the class CloneMessageServiceListTest method createServiceList.
private CloneMessageServiceList createServiceList() {
CloneMessageServiceList services = createServiceCollection();
services.addService(new AddMetadataService(Arrays.asList(new MetadataElement(KEY1, VAL1))));
return services;
}
use of com.adaptris.core.services.metadata.AddMetadataService 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);
}
}
Aggregations