public class MockMessageHandler extends AbstractMessageProducingHandler
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(...);
IntegrationManagement.ManagementOverrides| Modifier and Type | Field and Description |
|---|---|
protected boolean |
hasReplies |
protected java.util.function.Function<org.springframework.messaging.Message<?>,?> |
lastFunction |
protected java.util.List<java.util.function.Function<org.springframework.messaging.Message<?>,?>> |
messageFunctions |
messagingTemplateEXPRESSION_PARSER, loggerMETER_PREFIX, RECEIVE_COUNTER_NAME, SEND_TIMER_NAME| Modifier | Constructor and Description |
|---|---|
protected |
MockMessageHandler(org.mockito.ArgumentCaptor<org.springframework.messaging.Message<?>> messageArgumentCaptor) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
handleMessageInternal(org.springframework.messaging.Message<?> message) |
MockMessageHandler |
handleNext(java.util.function.Consumer<org.springframework.messaging.Message<?>> nextMessageConsumer)
Add the
Consumer to the stack to handle the next incoming message. |
MockMessageHandler |
handleNextAndReply(java.util.function.Function<org.springframework.messaging.Message<?>,?> nextMessageFunction)
Add the
Function to the stack to handle the next incoming message
and produce reply for it. |
addNotPropagatedHeaders, createOutputMessage, getNotPropagatedHeaders, getOutputChannel, isAsync, onInit, produceOutput, resolveErrorChannel, sendErrorMessage, sendOutput, sendOutputs, setAsync, setNotPropagatedHeaders, setOutputChannel, setOutputChannelName, setSendTimeout, shouldCopyRequestHeaders, shouldSplitOutput, updateNotPropagatedHeadersconfigureMetrics, destroy, getActiveCount, getActiveCountLong, getComponentType, getDuration, getErrorCount, getErrorCountLong, getHandleCount, getHandleCountLong, getManagedName, getManagedType, getMaxDuration, getMeanDuration, getMinDuration, getOrder, getOverrides, getStandardDeviationDuration, handleMessage, isCountsEnabled, isLoggingEnabled, isStatsEnabled, onComplete, onError, onNext, onSubscribe, registerMetricsCaptor, reset, setCountsEnabled, setLoggingEnabled, setManagedName, setManagedType, setOrder, setShouldTrack, setStatsEnabledafterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanFactory, getChannelResolver, getComponentName, getConversionService, getExpression, getIntegrationProperties, getIntegrationProperty, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentName, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitgetComponentNameprotected final java.util.List<java.util.function.Function<org.springframework.messaging.Message<?>,?>> messageFunctions
protected java.util.function.Function<org.springframework.messaging.Message<?>,?> lastFunction
protected boolean hasReplies
protected MockMessageHandler(org.mockito.ArgumentCaptor<org.springframework.messaging.Message<?>> messageArgumentCaptor)
public MockMessageHandler handleNext(java.util.function.Consumer<org.springframework.messaging.Message<?>> nextMessageConsumer)
Consumer to the stack to handle the next incoming message.nextMessageConsumer - the Consumer to handle the next incoming message.public MockMessageHandler handleNextAndReply(java.util.function.Function<org.springframework.messaging.Message<?>,?> nextMessageFunction)
Function to the stack to handle the next incoming message
and produce reply for it.nextMessageFunction - the Function to handle the next incoming message.protected void handleMessageInternal(org.springframework.messaging.Message<?> message)
throws java.lang.Exception
handleMessageInternal in class AbstractMessageHandlerjava.lang.Exception