use of com.adaptris.core.stubs.MockChannel in project interlok by adaptris.
the class ConnectionErrorHandlerTest method testChannelInitialised_ConnectionErrorHandler.
@Test
public void testChannelInitialised_ConnectionErrorHandler() throws Exception {
MockChannel started = new MockChannel();
MockChannel initOnly = new MockChannel();
TriggeredFailingConnection con = new TriggeredFailingConnection();
started.setConsumeConnection(con);
initOnly.setConsumeConnection(con);
start(started);
initOnly.requestInit();
con.triggerError();
assertEquals(2, started.getInitCount());
assertEquals(2, started.getStartCount());
assertEquals(1, started.getStopCount());
assertEquals(1, started.getCloseCount());
assertEquals(1, initOnly.getInitCount());
assertEquals(0, initOnly.getStartCount());
assertEquals(0, initOnly.getStopCount());
assertEquals(1, initOnly.getCloseCount());
assertEquals(ClosedState.getInstance(), initOnly.retrieveComponentState());
stop(started);
}
use of com.adaptris.core.stubs.MockChannel in project interlok by adaptris.
the class ConnectionErrorHandlerTest method testChannelNullConnectionErrorHandler.
@Test
public void testChannelNullConnectionErrorHandler() throws Exception {
MockChannel c = new MockChannel();
TriggeredFailingConnection con = new TriggeredFailingConnection(new NullConnectionErrorHandler());
c.setConsumeConnection(con);
start(c);
con.triggerError();
assertEquals(1, c.getInitCount());
assertEquals(1, c.getStartCount());
assertEquals(0, c.getStopCount());
assertEquals(0, c.getCloseCount());
stop(c);
}
use of com.adaptris.core.stubs.MockChannel in project interlok by adaptris.
the class LargeMessageWorkflowTest method testRuntimeException.
@Override
@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 {
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.stubs.MockChannel in project interlok by adaptris.
the class FailoverJmsProducerCase method testBug1012.
@Test
public void testBug1012() throws Exception {
FailoverJmsConnection connection = new FailoverJmsConnection();
List<JmsConnection> ptp = new ArrayList<JmsConnection>();
ptp.add(activeMqBroker.getJmsConnection());
ptp.add(activeMqBroker.getJmsConnection(new BasicActiveMqImplementation(), true));
connection.setConnections(ptp);
LifecycleHelper.init(connection);
assertEquals(1, connection.currentJmsConnection().retrieveExceptionListeners().size());
AdaptrisComponent owner = (AdaptrisComponent) connection.currentJmsConnection().retrieveExceptionListeners().toArray()[0];
assertTrue("Owner should be failover connection", connection == owner);
LifecycleHelper.close(connection);
Channel channel = new MockChannel();
connection = new FailoverJmsConnection();
connection.setRegisterOwner(true);
channel.setConsumeConnection(connection);
ptp = new ArrayList<JmsConnection>();
ptp.add(activeMqBroker.getJmsConnection());
ptp.add(activeMqBroker.getJmsConnection(new BasicActiveMqImplementation(), true));
connection.setConnections(ptp);
LifecycleHelper.init(connection);
// setting the consume connection no longer sets up the exception handler, so expect 0 here.
assertEquals(0, connection.currentJmsConnection().retrieveExceptionListeners().size());
LifecycleHelper.close(connection);
}
use of com.adaptris.core.stubs.MockChannel 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);
}
}
Aggregations