Class MockIntegrationContext
java.lang.Object
org.springframework.integration.test.context.MockIntegrationContext
- All Implemented Interfaces:
- Aware,- BeanFactoryAware,- BeanPostProcessor,- SmartInitializingSingleton
public class MockIntegrationContext
extends Object
implements BeanPostProcessor, SmartInitializingSingleton, BeanFactoryAware
A 
BeanFactoryAware component with an API to customize real beans
 in the application context from test code.
 
 The bean for this class is registered automatically via the SpringIntegrationTest
 annotation and can be autowired into test class.
- Since:
- 5.0
- Author:
- Artem Bilan, Yicheng Feng, Alexander Hain
- See Also:
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final StringThe bean name for the mock integration context.
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidpostProcessBeforeInitialization(Object bean, String beanName) voidresetBeans(String... beanNames) Reinstate the mocked beans after execution test to their real state.voidsetBeanFactory(BeanFactory beanFactory) voidsubstituteMessageHandlerFor(String consumerEndpointId, MessageHandler mockMessageHandler) voidsubstituteMessageHandlerFor(String consumerEndpointId, MessageHandler mockMessageHandler, boolean autoStartup) voidsubstituteMessageSourceFor(String pollingAdapterId, MessageSource<?> mockMessageSource) Replace the realMessageSourcein theSourcePollingChannelAdapterbean with providedMessageSourceinstance.voidsubstituteMessageSourceFor(String pollingAdapterId, MessageSource<?> mockMessageSource, boolean autoStartup) Replace the realMessageSourcein theSourcePollingChannelAdapterbean with providedMessageSourceinstance.voidsubstituteTriggerFor(String pollingEndpointId, Trigger trigger) Replace the realTriggerin theAbstractPollingEndpointbean with provided instance.voidsubstituteTriggerFor(String pollingEndpointId, Trigger trigger, boolean autoStartup) Replace the realTriggerin theAbstractPollingEndpointbean with provided instance.Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.beans.factory.config.BeanPostProcessorpostProcessAfterInitialization
- 
Field Details- 
MOCK_INTEGRATION_CONTEXT_BEAN_NAMEThe bean name for the mock integration context.- See Also:
 
 
- 
- 
Constructor Details- 
MockIntegrationContextpublic MockIntegrationContext()
 
- 
- 
Method Details- 
setBeanFactory- Specified by:
- setBeanFactoryin interface- BeanFactoryAware
- Throws:
- BeansException
 
- 
postProcessBeforeInitialization- Specified by:
- postProcessBeforeInitializationin interface- BeanPostProcessor
- Throws:
- BeansException
 
- 
afterSingletonsInstantiatedpublic void afterSingletonsInstantiated()- Specified by:
- afterSingletonsInstantiatedin interface- SmartInitializingSingleton
 
- 
resetBeansReinstate the mocked beans after execution test to their real state. Typically, this method is used from JUnit clean up methods.- Parameters:
- beanNames- the bean names to reset. If- null, all the mocked beans are reset
 
- 
substituteMessageSourceForReplace the realMessageSourcein theSourcePollingChannelAdapterbean with providedMessageSourceinstance. Can be a mock object.- Parameters:
- pollingAdapterId- the endpoint bean name
- mockMessageSource- the- MessageSourceto replace in the endpoint bean
- See Also:
 
- 
substituteMessageSourceForpublic void substituteMessageSourceFor(String pollingAdapterId, MessageSource<?> mockMessageSource, boolean autoStartup) Replace the realMessageSourcein theSourcePollingChannelAdapterbean with providedMessageSourceinstance. Can be a mock object. The endpoint is not started whenautoStartup == false.- Parameters:
- pollingAdapterId- the endpoint bean name
- mockMessageSource- the- MessageSourceto replace in the endpoint bean
- autoStartup- start or not the endpoint after replacing its- MessageSource
- See Also:
 
- 
substituteMessageHandlerForpublic void substituteMessageHandlerFor(String consumerEndpointId, MessageHandler mockMessageHandler) 
- 
substituteMessageHandlerForpublic void substituteMessageHandlerFor(String consumerEndpointId, MessageHandler mockMessageHandler, boolean autoStartup) 
- 
substituteTriggerForReplace the realTriggerin theAbstractPollingEndpointbean with provided instance.- Parameters:
- pollingEndpointId- the- AbstractPollingEndpointbean id to replace
- trigger- the- Triggerto set into- AbstractPollingEndpoint
- Since:
- 6.3
 
- 
substituteTriggerForReplace the realTriggerin theAbstractPollingEndpointbean with provided instance. The endpoint is not started whenautoStartup == false.- Parameters:
- pollingEndpointId- the- AbstractPollingEndpointbean id to replace
- trigger- the- Triggerto set into- AbstractPollingEndpoint
- autoStartup- start or not the endpoint after replacing its- MessageSource
- Since:
- 6.3
 
 
-