use of com.adaptris.core.services.exception.ThrowExceptionService in project interlok by adaptris.
the class ServiceListTest method testFail_CheckObjectMetadata.
@Test
public void testFail_CheckObjectMetadata() throws Exception {
ServiceList services = createServiceList(false);
ThrowExceptionService errorService = new ThrowExceptionService(new ConfiguredException("Fail"));
errorService.setUniqueId(getName());
services.addService(errorService);
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
String expectedName = String.format("%s(%s)", ThrowExceptionService.class.getSimpleName(), getName());
try {
execute(services, msg);
fail("Expected Service Exception");
} catch (ServiceException e) {
assertEquals("Fail", e.getMessage());
Exception captured = (Exception) msg.getObjectHeaders().get(CoreConstants.OBJ_METADATA_EXCEPTION);
String problemComponent = (String) msg.getObjectHeaders().get(CoreConstants.OBJ_METADATA_EXCEPTION_CAUSE);
assertNotNull(captured);
assertEquals(captured, e);
assertNotNull(problemComponent);
assertEquals(expectedName, problemComponent);
}
}
use of com.adaptris.core.services.exception.ThrowExceptionService in project interlok by adaptris.
the class MultiProducerWorkflowTest method testHandleServiceException.
@Test
public void testHandleServiceException() throws Exception {
System.out.println("*** HandleServiceException START");
MockMessageProducer mock1 = new MockMessageProducer();
MockMessageProducer mock2 = new MockMessageProducer();
MockMessageProducer meh = new MockMessageProducer();
MockChannel channel = createChannel(Arrays.asList(new AdaptrisMessageProducer[] { mock1, mock2 }), Arrays.asList(new Service[] { new ThrowExceptionService(new ConfiguredException("Fail")) }));
channel.setMessageErrorHandler(new StandardProcessingExceptionHandler(new ServiceList(new ArrayList(Arrays.asList(new Service[] { new StandaloneProducer(meh) })))));
try {
MultiProducerWorkflow workflow = (MultiProducerWorkflow) channel.getWorkflowList().get(0);
workflow.setUseProcessedMessage(false);
channel.prepare();
channel.requestStart();
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(ORIGINAL_PAYLOAD);
workflow.onAdaptrisMessage(msg);
assertEquals(0, mock1.getMessages().size());
assertEquals(0, mock2.getMessages().size());
assertEquals(1, meh.getMessages().size());
assertEquals(ORIGINAL_PAYLOAD, meh.getMessages().get(0).getContent());
} finally {
channel.requestClose();
}
System.out.println("*** HandleServiceException END");
}
use of com.adaptris.core.services.exception.ThrowExceptionService in project interlok by adaptris.
the class PoolingWorkflowTest method testHandleServiceException.
@Test
public void testHandleServiceException() throws Exception {
MockChannel channel = createChannel();
PoolingWorkflow wf = (PoolingWorkflow) channel.getWorkflowList().get(0);
MockMessageProducer meh = new MockMessageProducer();
channel.setMessageErrorHandler(new StandardProcessingExceptionHandler(new ServiceList(new ArrayList<Service>(Arrays.asList(new Service[] { new StandaloneProducer(meh) })))));
wf.getServiceCollection().add(new ThrowExceptionService(new ConfiguredException("Fail")));
try {
start(channel);
submitMessages(wf, 1);
waitForMessages(meh, 1);
assertEquals(1, meh.messageCount());
for (Iterator i = meh.getMessages().iterator(); i.hasNext(); ) {
AdaptrisMessage m = (AdaptrisMessage) i.next();
assertNotNull(m.getObjectHeaders().get(CoreConstants.OBJ_METADATA_EXCEPTION));
assertNotNull(m.getObjectHeaders().get(CoreConstants.OBJ_METADATA_EXCEPTION_CAUSE));
assertEquals(ThrowExceptionService.class.getSimpleName(), m.getObjectHeaders().get(CoreConstants.OBJ_METADATA_EXCEPTION_CAUSE));
}
} finally {
stop(channel);
}
}
use of com.adaptris.core.services.exception.ThrowExceptionService in project interlok by adaptris.
the class JettyRoutingServiceTest method retrieveObjectForSampleConfig.
@Override
protected Object retrieveObjectForSampleConfig() {
BranchingServiceCollection sl = new BranchingServiceCollection();
JettyRoutingService service = new JettyRoutingService("NotHandled", createRoutes());
service.setUniqueId("handleRouting");
sl.addService(service);
sl.setFirstServiceId(service.getUniqueId());
sl.addService(new LogMessageService("handleGet"));
sl.addService(new LogMessageService("handleDelete"));
sl.addService(new LogMessageService("handleInsert"));
sl.addService(new ThrowExceptionService("handleUpdate", new ConfiguredException("cannot handle updates")));
return sl;
}
use of com.adaptris.core.services.exception.ThrowExceptionService in project interlok by adaptris.
the class MetadataBranchingServiceTest method create.
protected BranchingServiceCollection create(MetadataValueMatcherCreator m) {
BranchingServiceCollection sl = new BranchingServiceCollection();
MetadataValueBranchingService service = new MetadataValueBranchingService();
service.setValueMatcher(m.create());
service.setDefaultServiceId("DefaultServiceId");
service.addMetadataKey("FirstMetadataKeyWhoseValueWeWantToCheck");
// service.addMetadataKey("Second_Metadata_Key_Whose_Value_Is_Appended_To_FirstMetadataKeyWhoseValueWeWantToCheck");
service.setMetadataToServiceIdMappings(m.createMappings());
service.setUniqueId("CheckMetadataValue");
sl.addService(service);
sl.setFirstServiceId(service.getUniqueId());
sl.addService(new LogMessageService("FirstServiceId"));
sl.addService(new ThrowExceptionService("SecondServiceId", new ConfiguredException("Fail")));
sl.addService(new LogMessageService("DefaultServiceId"));
return sl;
}
Aggregations