use of com.adaptris.core.services.metadata.PayloadFromTemplateService in project interlok by adaptris.
the class ThreadContextWorkflowTest method testOnMessageWithoutEvents.
@Test
public void testOnMessageWithoutEvents() 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) }));
try {
channel.setEventHandler(evtHandler);
ThreadContextWorkflow workflow = (ThreadContextWorkflow) channel.getWorkflowList().get(0);
workflow.setSendEvents(false);
channel.prepare();
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(PAYLOAD_1);
start(channel);
workflow.onAdaptrisMessage(msg);
assertEquals("Make sure all produced", 1, producer.getMessages().size());
for (Iterator i = producer.getMessages().iterator(); i.hasNext(); ) {
AdaptrisMessage m = (AdaptrisMessage) i.next();
assertEquals(PAYLOAD_2, m.getContent());
assertTrue("Contains correct metadata key", m.headersContainsKey(METADATA_KEY));
assertEquals(METADATA_VALUE, m.getMetadataValue(METADATA_KEY));
}
waitForMessages(eventProd, 0);
assertEquals(0, eventProd.messageCount());
} finally {
stop(channel);
stop(evtHandler);
}
}
use of com.adaptris.core.services.metadata.PayloadFromTemplateService in project interlok by adaptris.
the class ThreadContextWorkflowTest method testHandleChannelUnavailable.
@Test
public void testHandleChannelUnavailable() throws Exception {
MockMessageProducer producer = new MockMessageProducer();
final 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 {
ThreadContextWorkflow workflow = (ThreadContextWorkflow) channel.getWorkflowList().get(0);
workflow.setChannelUnavailableWaitInterval(new TimeInterval(1200L, TimeUnit.MILLISECONDS));
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(PAYLOAD_1);
channel.prepare();
start(channel);
channel.toggleAvailability(false);
Timer t = new Timer(true);
t.schedule(new TimerTask() {
@Override
public void run() {
channel.toggleAvailability(true);
}
}, 500);
workflow.onAdaptrisMessage(msg);
assertEquals("Make sure all produced", 1, producer.getMessages().size());
for (Iterator i = producer.getMessages().iterator(); i.hasNext(); ) {
AdaptrisMessage m = (AdaptrisMessage) i.next();
assertEquals(PAYLOAD_2, m.getContent());
assertTrue("Contains correct metadata key", m.headersContainsKey(METADATA_KEY));
assertEquals(METADATA_VALUE, m.getMetadataValue(METADATA_KEY));
}
} finally {
stop(channel);
}
}
use of com.adaptris.core.services.metadata.PayloadFromTemplateService in project interlok by adaptris.
the class ThreadContextWorkflowTest 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 {
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);
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.PayloadFromTemplateService in project interlok by adaptris.
the class MultiProducerWorkflowTest method testWorkflowWithInterceptor.
@Test
public void testWorkflowWithInterceptor() throws Exception {
MockMessageProducer mock1 = new MockMessageProducer();
MockMessageProducer mock2 = new MockMessageProducer();
MockWorkflowInterceptor interceptor = new MockWorkflowInterceptor();
MockChannel channel = createChannel(Arrays.asList(new AdaptrisMessageProducer[] { mock1, mock2 }), Arrays.asList(new Service[] { new PayloadFromTemplateService().withTemplate(MODIFIED_PAYLOAD) }));
try {
MultiProducerWorkflow workflow = (MultiProducerWorkflow) channel.getWorkflowList().get(0);
workflow.setUseProcessedMessage(false);
workflow.addInterceptor(interceptor);
channel.prepare();
channel.requestStart();
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(ORIGINAL_PAYLOAD);
workflow.onAdaptrisMessage(msg);
assertEquals(1, mock1.getMessages().size());
assertEquals(ORIGINAL_PAYLOAD, mock1.getMessages().get(0).getContent());
assertEquals(1, mock2.getMessages().size());
assertEquals(ORIGINAL_PAYLOAD, mock2.getMessages().get(0).getContent());
assertEquals(1, interceptor.messageCount());
} finally {
channel.requestClose();
}
}
use of com.adaptris.core.services.metadata.PayloadFromTemplateService in project interlok by adaptris.
the class MultiProducerWorkflowTest method testUseProcessedMessage.
@Test
public void testUseProcessedMessage() throws Exception {
MockMessageProducer mock1 = new MockMessageProducer();
MockMessageProducer mock2 = new MockMessageProducer();
MockChannel channel = createChannel(Arrays.asList(new AdaptrisMessageProducer[] { mock1, mock2 }), Arrays.asList(new Service[] { new PayloadFromTemplateService().withTemplate(MODIFIED_PAYLOAD) }));
try {
MultiProducerWorkflow workflow = (MultiProducerWorkflow) channel.getWorkflowList().get(0);
workflow.setUseProcessedMessage(true);
channel.prepare();
channel.requestStart();
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(ORIGINAL_PAYLOAD);
workflow.onAdaptrisMessage(msg);
assertEquals(1, mock1.getMessages().size());
assertEquals(MODIFIED_PAYLOAD, mock1.getMessages().get(0).getContent());
assertEquals(1, mock2.getMessages().size());
assertEquals(MODIFIED_PAYLOAD, mock2.getMessages().get(0).getContent());
} finally {
channel.requestClose();
}
}
Aggregations