use of com.adaptris.core.services.metadata.AddMetadataService in project interlok by adaptris.
the class ServiceListTest method createServiceList.
private ServiceList createServiceList(boolean assignId) {
ServiceList services = createServiceCollection();
services.addService(new AddMetadataService(Arrays.asList(new MetadataElement(KEY1, VAL1))));
services.addService(new AddMetadataService(Arrays.asList(new MetadataElement(KEY2, VAL2))));
if (assignId) {
for (Service s : services) {
s.setUniqueId(new PlainIdGenerator().create(s));
}
}
return services;
}
use of com.adaptris.core.services.metadata.AddMetadataService in project interlok by adaptris.
the class ServiceListTest method testFailWithContinueOnFail.
@Test
public void testFailWithContinueOnFail() throws Exception {
ServiceList services = createServiceList(true);
ThrowExceptionService service3 = new ThrowExceptionService(new ConfiguredException("Fail"));
service3.setContinueOnFail(true);
services.addService(service3);
services.addService(new AddMetadataService(Arrays.asList(new MetadataElement(KEY4, VAL4))));
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
execute(services, msg);
assertTrue(msg.getMetadataValue(KEY4).equals(VAL4));
}
use of com.adaptris.core.services.metadata.AddMetadataService in project interlok by adaptris.
the class ServiceListTest method testAddService.
@Override
public void testAddService() {
ServiceList services = createServiceList(false);
AddMetadataService newService = new AddMetadataService(Arrays.asList(new MetadataElement(KEY3, VAL3)));
services.addService(newService);
Collection tmp = services.getServices();
assertTrue(tmp.contains(newService));
}
use of com.adaptris.core.services.metadata.AddMetadataService in project interlok by adaptris.
the class ThreadContextWorkflowTest method testBrokenPool.
@Test
public void testBrokenPool() throws Exception {
MockMessageProducer producer = new MockMessageProducer();
MockMessageProducer eventProd = new MockMessageProducer();
DefaultEventHandler evtHandler = new DefaultEventHandler(eventProd);
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) }));
MockMessageProducer meh = new MockMessageProducer();
try {
ThreadContextWorkflow workflow = (ThreadContextWorkflow) 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);
// close the pool which should cause an IllegalStateException
workflow.getObjectPool().close();
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.headersContainsKey(METADATA_KEY));
}
} finally {
stop(channel);
}
}
use of com.adaptris.core.services.metadata.AddMetadataService in project interlok by adaptris.
the class ThreadContextWorkflowTest method testOnMessageWithInterceptors.
@Test
public void testOnMessageWithInterceptors() throws Exception {
MockWorkflowInterceptor interceptor = new MockWorkflowInterceptor();
MockMessageProducer producer = 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) }));
int count = 10;
try {
ThreadContextWorkflow workflow = (ThreadContextWorkflow) channel.getWorkflowList().get(0);
workflow.setAdditionalDebug(Boolean.TRUE);
workflow.addInterceptor(interceptor);
channel.prepare();
start(channel);
for (int i = 0; i < count; i++) {
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(PAYLOAD_1);
workflow.onAdaptrisMessage(msg);
}
assertEquals("Make sure all produced", count, producer.messageCount());
assertEquals("Make sure all intercepted", count, interceptor.messageCount());
for (AdaptrisMessage m : producer.getMessages()) {
assertEquals(PAYLOAD_2, m.getContent());
assertTrue("Contains correct metadata key", m.headersContainsKey(METADATA_KEY));
assertEquals(METADATA_VALUE, m.getMetadataValue(METADATA_KEY));
}
} finally {
stop(channel);
}
}
Aggregations