use of com.adaptris.core.services.exception.ThrowExceptionService in project interlok by adaptris.
the class StandardWorkflowTest method testServiceException.
@Test
public void testServiceException() throws Exception {
MockMessageProducer producer = new MockMessageProducer();
MockMessageProducer meh = new MockMessageProducer();
MockChannel channel = createChannel(producer, Arrays.asList(new Service[] { new ThrowExceptionService(new ConfiguredException("Fail")) }));
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));
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 StandardWorkflowTest method testProduceException.
@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 ThrowExceptionService(new ConfiguredException("Fail")) }));
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.exception.ThrowExceptionService in project interlok by adaptris.
the class ThreadContextWorkflowTest method testProduceException.
@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 ThrowExceptionService(new ConfiguredException("Fail")) }));
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.exception.ThrowExceptionService in project interlok by adaptris.
the class StandardProcessingExceptionHandlerTest method testServiceListWithErrorWithServiceId.
@Test
public void testServiceListWithErrorWithServiceId() throws Exception {
StandardProcessingExceptionHandler meh = new StandardProcessingExceptionHandler();
MockMessageProducer producer = new MockMessageProducer();
try {
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage("XXXX");
ServiceList services = new ServiceList(Arrays.asList(new Service[] { new ThrowExceptionService(new ConfiguredException("Always Fail")), new StandaloneProducer(producer) }));
services.setUniqueId("FailingServiceList");
meh.setProcessingExceptionService(services);
start(meh);
meh.handleProcessingException(msg);
assertTrue("Make sure none produced", producer.getMessages().size() == 0);
} finally {
stop(meh);
}
}
use of com.adaptris.core.services.exception.ThrowExceptionService in project interlok by adaptris.
the class StandardProcessingExceptionHandlerTest method testMultipleErrorHandlers_AlwaysHandle_True.
@Test
public void testMultipleErrorHandlers_AlwaysHandle_True() throws Exception {
MockMessageProducer aep = new MockMessageProducer();
MockMessageProducer wep = new MockMessageProducer();
MockMessageProducer cep = new MockMessageProducer();
StandardProcessingExceptionHandler aeh = new StandardProcessingExceptionHandler(new StandaloneProducer(aep));
aeh.setAlwaysHandleException(true);
StandardProcessingExceptionHandler ceh = new StandardProcessingExceptionHandler(new StandaloneProducer(cep));
ceh.setAlwaysHandleException(true);
StandardProcessingExceptionHandler weh = new StandardProcessingExceptionHandler(new StandaloneProducer(wep));
Adapter adapter = AdapterTest.createAdapter(getName());
adapter.setMessageErrorHandler(aeh);
MockMessageConsumer consumer = new MockMessageConsumer();
adapter.getChannelList().clear();
adapter.getChannelList().add(createChannel(consumer, ceh, weh, new ThrowExceptionService(new ConfiguredException(getName()))));
try {
start(adapter);
consumer.submitMessage(AdaptrisMessageFactory.getDefaultInstance().newMessage());
assertEquals(1, aep.messageCount());
assertEquals(1, cep.messageCount());
assertEquals(1, wep.messageCount());
} finally {
stop(adapter);
}
}
Aggregations