Search in sources :

Example 96 with MockChannel

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);
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) Test(org.junit.Test)

Example 97 with MockChannel

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);
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) Test(org.junit.Test)

Example 98 with MockChannel

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);
    }
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ServiceList(com.adaptris.core.ServiceList) PayloadFromTemplateService(com.adaptris.core.services.metadata.PayloadFromTemplateService) Service(com.adaptris.core.Service) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) MetadataElement(com.adaptris.core.MetadataElement) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) StandardProcessingExceptionHandler(com.adaptris.core.StandardProcessingExceptionHandler) PayloadFromTemplateService(com.adaptris.core.services.metadata.PayloadFromTemplateService) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test) StandardWorkflowTest(com.adaptris.core.StandardWorkflowTest)

Example 99 with MockChannel

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);
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) BasicActiveMqImplementation(com.adaptris.core.jms.activemq.BasicActiveMqImplementation) MockChannel(com.adaptris.core.stubs.MockChannel) Channel(com.adaptris.core.Channel) ArrayList(java.util.ArrayList) AdaptrisComponent(com.adaptris.core.AdaptrisComponent) Test(org.junit.Test)

Example 100 with MockChannel

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);
    }
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) FailFirstMockMessageProducer(com.adaptris.core.stubs.FailFirstMockMessageProducer) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException) Iterator(java.util.Iterator) PayloadFromTemplateService(com.adaptris.core.services.metadata.PayloadFromTemplateService) EventHandlerAwareService(com.adaptris.core.stubs.EventHandlerAwareService) MockSkipProducerService(com.adaptris.core.stubs.MockSkipProducerService) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) Test(org.junit.Test)

Aggregations

MockChannel (com.adaptris.core.stubs.MockChannel)145 Test (org.junit.Test)125 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)92 ThrowExceptionService (com.adaptris.core.services.exception.ThrowExceptionService)62 MockSkipProducerService (com.adaptris.core.stubs.MockSkipProducerService)59 PayloadFromTemplateService (com.adaptris.core.services.metadata.PayloadFromTemplateService)56 AddMetadataService (com.adaptris.core.services.metadata.AddMetadataService)44 FailFirstMockMessageProducer (com.adaptris.core.stubs.FailFirstMockMessageProducer)40 StaticMockMessageProducer (com.adaptris.core.stubs.StaticMockMessageProducer)32 TimeInterval (com.adaptris.util.TimeInterval)28 EventHandlerAwareService (com.adaptris.core.stubs.EventHandlerAwareService)22 Iterator (java.util.Iterator)17 StandardWorkflow (com.adaptris.core.StandardWorkflow)13 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)13 ConfiguredException (com.adaptris.core.services.exception.ConfiguredException)11 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)10 Channel (com.adaptris.core.Channel)10 JmsConnectionErrorHandler (com.adaptris.core.jms.JmsConnectionErrorHandler)9 MockMessageConsumer (com.adaptris.core.stubs.MockMessageConsumer)9 JmsConnection (com.adaptris.core.jms.JmsConnection)8