Search in sources :

Example 6 with NullMessageConsumer

use of com.adaptris.core.NullMessageConsumer in project interlok by adaptris.

the class OnMessageHandlerTest method testOnMessageHandlerProducerFailsRollback.

@Test
public void testOnMessageHandlerProducerFailsRollback() throws Exception {
    when(mockSession.getTransacted()).thenReturn(true);
    JmsTransactedWorkflow jmsTransactedWorkflow = new JmsTransactedWorkflow();
    jmsTransactedWorkflow.setConsumer(new NullMessageConsumer());
    jmsTransactedWorkflow.setProducer(new MockProducer());
    jmsTransactedWorkflow.setStrict(true);
    jmsTransactedWorkflow.registerChannel(mockChannel);
    config.setCorrelationIdSource(mockCorrelationSourceId);
    config.setMessageTranslator(mockTranslator);
    config.registerAdaptrisMessageListener(jmsTransactedWorkflow);
    handler = new OnMessageHandler(config);
    handler.onMessage(jmsMessage);
    verify(mockSession).rollback();
}
Also used : MockProducer(com.adaptris.interlok.junit.scaffolding.jms.MockProducer) NullMessageConsumer(com.adaptris.core.NullMessageConsumer) Test(org.junit.Test)

Example 7 with NullMessageConsumer

use of com.adaptris.core.NullMessageConsumer in project interlok by adaptris.

the class OnMessageHandlerTest method testOnMessageHandlerSuccessTransactedRollback.

@Test
public void testOnMessageHandlerSuccessTransactedRollback() throws Exception {
    when(mockSession.getTransacted()).thenReturn(true);
    doThrow(new ProduceException("Expected")).when(mockProducer).produce(any());
    when(mockProducer.createName()).thenReturn("name");
    when(mockProducer.createQualifier()).thenReturn("Qualifier");
    when(mockProducer.isTrackingEndpoint()).thenReturn(false);
    JmsTransactedWorkflow jmsTransactedWorkflow = new JmsTransactedWorkflow();
    jmsTransactedWorkflow.setConsumer(new NullMessageConsumer());
    jmsTransactedWorkflow.setProducer(mockProducer);
    jmsTransactedWorkflow.registerChannel(mockChannel);
    config.setCorrelationIdSource(mockCorrelationSourceId);
    config.setMessageTranslator(mockTranslator);
    config.registerAdaptrisMessageListener(jmsTransactedWorkflow);
    handler = new OnMessageHandler(config);
    handler.onMessage(jmsMessage);
    verify(mockSession).rollback();
}
Also used : ProduceException(com.adaptris.core.ProduceException) NullMessageConsumer(com.adaptris.core.NullMessageConsumer) Test(org.junit.Test)

Example 8 with NullMessageConsumer

use of com.adaptris.core.NullMessageConsumer in project interlok by adaptris.

the class OnMessageHandlerTest method testOnMessageHandlerCommitFailsThenRollback.

@Test
public void testOnMessageHandlerCommitFailsThenRollback() throws Exception {
    when(mockSession.getTransacted()).thenReturn(true);
    doThrow(new JMSException("Expected")).when(mockSession).commit();
    JmsTransactedWorkflow jmsTransactedWorkflow = new JmsTransactedWorkflow();
    jmsTransactedWorkflow.setConsumer(new NullMessageConsumer());
    jmsTransactedWorkflow.setProducer(new NullMessageProducer());
    jmsTransactedWorkflow.registerChannel(mockChannel);
    config.setCorrelationIdSource(mockCorrelationSourceId);
    config.setMessageTranslator(mockTranslator);
    config.registerAdaptrisMessageListener(jmsTransactedWorkflow);
    handler = new OnMessageHandler(config);
    handler.onMessage(jmsMessage);
    verify(mockSession).commit();
    verify(mockSession).rollback();
}
Also used : JMSException(javax.jms.JMSException) NullMessageProducer(com.adaptris.core.NullMessageProducer) NullMessageConsumer(com.adaptris.core.NullMessageConsumer) Test(org.junit.Test)

Example 9 with NullMessageConsumer

use of com.adaptris.core.NullMessageConsumer in project interlok by adaptris.

the class JmsTransactedWorkflow method initialiseWorkflow.

@Override
protected void initialiseWorkflow() throws CoreException {
    AdaptrisMessageConsumer amc = getConsumer();
    if (amc instanceof JmsPollingConsumerImpl) {
        ((JmsPollingConsumerImpl) amc).setRollbackTimeout(waitPeriodAfterRollbackMs());
        ((JmsPollingConsumerImpl) amc).setTransacted(Boolean.TRUE);
    } else if (amc instanceof JmsConsumerImpl) {
        ((JmsConsumerImpl) amc).setRollbackTimeout(waitPeriodAfterRollbackMs());
        ((JmsConsumerImpl) amc).setTransacted(Boolean.TRUE);
    } else if (!(amc instanceof NullMessageConsumer)) {
        throw new CoreException(this.getClass().getSimpleName() + " must be used with a JMSConsumer");
    }
    ProduceExceptionHandler produceExceptionHandler = getProduceExceptionHandler();
    if (produceExceptionHandler != null && !(produceExceptionHandler instanceof NullProduceExceptionHandler)) {
        throw new CoreException(this.getClass().getSimpleName() + " may not have a ProduceExceptionHandler set");
    }
    super.initialiseWorkflow();
}
Also used : CoreException(com.adaptris.core.CoreException) AdaptrisMessageConsumer(com.adaptris.core.AdaptrisMessageConsumer) NullProduceExceptionHandler(com.adaptris.core.NullProduceExceptionHandler) NullProduceExceptionHandler(com.adaptris.core.NullProduceExceptionHandler) ProduceExceptionHandler(com.adaptris.core.ProduceExceptionHandler) NullMessageConsumer(com.adaptris.core.NullMessageConsumer)

Aggregations

NullMessageConsumer (com.adaptris.core.NullMessageConsumer)9 Test (org.junit.Test)6 NullMessageProducer (com.adaptris.core.NullMessageProducer)5 JMSException (javax.jms.JMSException)3 AdaptrisMessageConsumer (com.adaptris.core.AdaptrisMessageConsumer)2 Adapter (com.adaptris.core.Adapter)1 Channel (com.adaptris.core.Channel)1 CoreException (com.adaptris.core.CoreException)1 NullProduceExceptionHandler (com.adaptris.core.NullProduceExceptionHandler)1 ProduceException (com.adaptris.core.ProduceException)1 ProduceExceptionHandler (com.adaptris.core.ProduceExceptionHandler)1 StandardWorkflow (com.adaptris.core.StandardWorkflow)1 AddTimestampMetadataService (com.adaptris.core.services.metadata.AddTimestampMetadataService)1 MockProducer (com.adaptris.interlok.junit.scaffolding.jms.MockProducer)1