use of com.adaptris.core.Service in project interlok by adaptris.
the class LargeMessageWorkflowTest method testProduceException.
@Override
@Test
public void testProduceException() throws Exception {
MockMessageProducer producer = new MockMessageProducer() {
@Override
protected void doProduce(AdaptrisMessage msg, String endpoint) throws ProduceException {
throw new ProduceException();
}
};
;
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.Service in project interlok by adaptris.
the class StatelessServiceWrapperTest method testWrappedServiceCreateName.
@Test
public void testWrappedServiceCreateName() throws Exception {
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage("");
MockMessageProducer prod = new MockMessageProducer();
Service s = create(prod);
assertNotSame(StatelessServiceWrapper.class.getName(), s.createName());
assertEquals(MockMessageProducer.class.getName(), s.createName());
StatelessServiceWrapper sw = new StatelessServiceWrapper();
assertEquals(StatelessServiceWrapper.class.getName(), sw.createName());
}
use of com.adaptris.core.Service in project interlok by adaptris.
the class DoWhileTest method testStopProcessingServiceCancelsLoop.
@Test
public void testStopProcessingServiceCancelsLoop() throws Exception {
when(mockCondition.evaluate(message)).thenReturn(true);
Service stopProcessingService = new StopProcessingService();
ServiceList services = new ServiceList();
services.add(stopProcessingService);
services.add(mockService);
thenService = new ThenService();
thenService.setService(services);
doWhile = new DoWhile().withThen(thenService).withCondition(mockCondition);
LifecycleHelper.init(doWhile);
LifecycleHelper.start(doWhile);
doWhile.doService(message);
// The default would loop 10 times, but the stop-processing-service should
// limit us to only a single loop and the condition will never be tested.
verify(mockCondition, times(0)).evaluate(message);
}
use of com.adaptris.core.Service in project interlok by adaptris.
the class DynamicServiceExecutorTest method testDoService_DefaultServiceExtractor_WithMarshaller.
@Test
public void testDoService_DefaultServiceExtractor_WithMarshaller() throws Exception {
AddMetadataService metadataService = new AddMetadataService();
metadataService.addMetadataElement(new MetadataElement(getName(), getName()));
DynamicServiceExecutor dynamicService = createService();
dynamicService.setMarshaller(new XStreamMarshaller());
AdaptrisMessage msg = createMessage(new ServiceList(new Service[] { metadataService }));
execute(dynamicService, msg);
assertEquals(getName(), msg.getMetadataValue(getName()));
}
use of com.adaptris.core.Service in project interlok by adaptris.
the class DynamicServiceExecutorTest method testDoService_MimeServiceExtractor_ByContentId_NotFound.
@Test
public void testDoService_MimeServiceExtractor_ByContentId_NotFound() throws Exception {
AddMetadataService metadataService = new AddMetadataService();
metadataService.addMetadataElement(new MetadataElement(getName(), getName()));
DynamicServiceExecutor dynamicService = createService();
dynamicService.setServiceExtractor(new MimeServiceExtractor(new SelectByContentId("Blah")));
AdaptrisMessage msg = createMimeMessage(new ServiceList(new Service[] { metadataService }), ENCODING_BASE64);
try {
execute(dynamicService, msg);
fail();
} catch (ServiceException expected) {
}
}
Aggregations