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<Message<?>>
,Aware
,BeanFactoryAware
,BeanNameAware
,DisposableBean
,InitializingBean
,ApplicationContextAware
,Ordered
,ExpressionCapable
,Orderable
,MessageProducer
,HeaderPropagationAware
,IntegrationPattern
,NamedComponent
,IntegrationManagement
,TrackableComponent
,MessageHandler
,reactor.core.CoreSubscriber<Message<?>>
public class MockMessageHandler extends AbstractMessageProducingHandler
The
AbstractMessageProducingHandler
extension for the mocking purpose in tests.
The provided Consumer
s and Function
s 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
- Author:
- Artem Bilan
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.springframework.integration.support.management.IntegrationManagement
IntegrationManagement.ManagementOverrides
-
Field Summary
Fields Modifier and Type Field Description protected boolean
hasReplies
protected Function<Message<?>,?>
lastFunction
protected List<Function<Message<?>,?>>
messageFunctions
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<Message<?>> messageArgumentCaptor)
-
Method Summary
Modifier and Type Method Description protected void
handleMessageInternal(Message<?> message)
MockMessageHandler
handleNext(Consumer<Message<?>> nextMessageConsumer)
Add theConsumer
to the stack to handle the next incoming message.MockMessageHandler
handleNextAndReply(Function<Message<?>,?> nextMessageFunction)
Add theFunction
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
Methods inherited from class org.springframework.integration.handler.MessageHandlerSupport
buildSendTimer, destroy, getComponentType, getIntegrationPatternType, getManagedName, getManagedType, getMetricsCaptor, getOrder, getOverrides, isLoggingEnabled, registerMetricsCaptor, 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 org.springframework.integration.support.management.IntegrationManagement
getThisAs
Methods inherited from interface org.springframework.integration.support.context.NamedComponent
getBeanName, getComponentName
-
Field Details
-
messageFunctions
-
lastFunction
-
hasReplies
protected boolean hasReplies
-
-
Constructor Details
-
Method Details
-
handleNext
Add theConsumer
to the stack to handle the next incoming message.- Parameters:
nextMessageConsumer
- the Consumer to handle the next incoming message.- Returns:
- this
-
handleNextAndReply
Add theFunction
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
- Specified by:
handleMessageInternal
in classAbstractMessageHandler
-