Class MockMessageHandler

java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
org.springframework.integration.handler.MessageHandlerSupport
org.springframework.integration.handler.AbstractMessageHandler
org.springframework.integration.handler.AbstractMessageProducingHandler
org.springframework.integration.test.mock.MockMessageHandler
All Implemented Interfaces:
org.reactivestreams.Subscriber<org.springframework.messaging.Message<?>>, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationContextAware, org.springframework.core.Ordered, org.springframework.integration.context.ExpressionCapable, org.springframework.integration.context.Orderable, org.springframework.integration.core.MessageProducer, org.springframework.integration.handler.HeaderPropagationAware, org.springframework.integration.IntegrationPattern, org.springframework.integration.support.context.NamedComponent, org.springframework.integration.support.management.IntegrationManagement, org.springframework.integration.support.management.TrackableComponent, org.springframework.messaging.MessageHandler, reactor.core.CoreSubscriber<org.springframework.messaging.Message<?>>

public class MockMessageHandler extends org.springframework.integration.handler.AbstractMessageProducingHandler
The AbstractMessageProducingHandler extension for the mocking purpose in tests.

The provided Consumers and Functions are applied to the incoming messages one at a time until the last, which is applied for all subsequent messages. The similar behavior exists in the Mockito.doReturn(Object toBeReturned, Object... toBeReturnedNext).

Typically is used as a chain of stub actions:

 
      MockIntegration.mockMessageHandler()
               .handleNext(...)
               .handleNext(...)
               .handleNextAndReply(...)
               .handleNextAndReply(...)
               .handleNext(...)
               .handleNextAndReply(...);
 
 
Since:
5.0
  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.springframework.integration.support.management.IntegrationManagement

    org.springframework.integration.support.management.IntegrationManagement.ManagementOverrides
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected boolean
     
    protected Function<org.springframework.messaging.Message<?>,?>
     
    protected final List<Function<org.springframework.messaging.Message<?>,?>>
     

    Fields inherited from class org.springframework.integration.handler.AbstractMessageProducingHandler

    messagingTemplate

    Fields inherited from class org.springframework.integration.context.IntegrationObjectSupport

    EXPRESSION_PARSER, logger

    Fields inherited from interface org.springframework.integration.support.management.IntegrationManagement

    METER_PREFIX, RECEIVE_COUNTER_NAME, SEND_TIMER_NAME

    Fields inherited from interface org.springframework.core.Ordered

    HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    MockMessageHandler(org.mockito.ArgumentCaptor<org.springframework.messaging.Message<?>> messageArgumentCaptor)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    handleMessageInternal(org.springframework.messaging.Message<?> message)
     
    handleNext(Consumer<org.springframework.messaging.Message<?>> nextMessageConsumer)
    Add the Consumer to the stack to handle the next incoming message.
    handleNextAndReply(Function<org.springframework.messaging.Message<?>,?> nextMessageFunction)
    Add the Function to the stack to handle the next incoming message and produce reply for it.

    Methods inherited from class org.springframework.integration.handler.AbstractMessageProducingHandler

    addNotPropagatedHeaders, createOutputMessage, getNotPropagatedHeaders, getOutputChannel, isAsync, messageBuilderForReply, onInit, produceOutput, resolveErrorChannel, sendErrorMessage, sendOutput, sendOutputs, setAsync, setNotPropagatedHeaders, setOutputChannel, setOutputChannelName, setSendTimeout, shouldCopyRequestHeaders, shouldSplitOutput, updateNotPropagatedHeaders

    Methods inherited from class org.springframework.integration.handler.AbstractMessageHandler

    handleMessage, onComplete, onError, onNext, onSubscribe, setObservationConvention

    Methods inherited from class org.springframework.integration.handler.MessageHandlerSupport

    buildSendTimer, destroy, getComponentType, getIntegrationPatternType, getManagedName, getManagedType, getMetricsCaptor, getObservationRegistry, getOrder, getOverrides, isLoggingEnabled, registerMetricsCaptor, registerObservationRegistry, sendTimer, setLoggingEnabled, setManagedName, setManagedType, setOrder, setShouldTrack, shouldTrack

    Methods inherited from class org.springframework.integration.context.IntegrationObjectSupport

    afterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentName, getConversionService, getExpression, getIntegrationProperties, getIntegrationProperty, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentName, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toString

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface reactor.core.CoreSubscriber

    currentContext

    Methods inherited from interface org.springframework.integration.support.management.IntegrationManagement

    getThisAs

    Methods inherited from interface org.springframework.integration.support.context.NamedComponent

    getBeanName, getComponentName
  • Field Details

    • messageFunctions

      protected final List<Function<org.springframework.messaging.Message<?>,?>> messageFunctions
    • lastFunction

      protected Function<org.springframework.messaging.Message<?>,?> lastFunction
    • hasReplies

      protected boolean hasReplies
  • Constructor Details

    • MockMessageHandler

      protected MockMessageHandler(org.mockito.ArgumentCaptor<org.springframework.messaging.Message<?>> messageArgumentCaptor)
  • Method Details

    • handleNext

      public MockMessageHandler handleNext(Consumer<org.springframework.messaging.Message<?>> nextMessageConsumer)
      Add the Consumer to the stack to handle the next incoming message.
      Parameters:
      nextMessageConsumer - the Consumer to handle the next incoming message.
      Returns:
      this
    • handleNextAndReply

      public MockMessageHandler handleNextAndReply(Function<org.springframework.messaging.Message<?>,?> nextMessageFunction)
      Add the Function to the stack to handle the next incoming message and produce reply for it.
      Parameters:
      nextMessageFunction - the Function to handle the next incoming message.
      Returns:
      this
    • handleMessageInternal

      protected void handleMessageInternal(org.springframework.messaging.Message<?> message)
      Specified by:
      handleMessageInternal in class org.springframework.integration.handler.AbstractMessageHandler