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 Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe bean name for the mock integration context. -
Constructor Summary
Constructors -
Method Summary
Modifier 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.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.beans.factory.config.BeanPostProcessor
postProcessAfterInitialization
-
Field Details
-
MOCK_INTEGRATION_CONTEXT_BEAN_NAME
The bean name for the mock integration context.- See Also:
-
-
Constructor Details
-
MockIntegrationContext
public MockIntegrationContext()
-
-
Method Details
-
setBeanFactory
- Specified by:
setBeanFactoryin interfaceBeanFactoryAware- Throws:
BeansException
-
postProcessBeforeInitialization
- Specified by:
postProcessBeforeInitializationin interfaceBeanPostProcessor- Throws:
BeansException
-
afterSingletonsInstantiated
public void afterSingletonsInstantiated()- Specified by:
afterSingletonsInstantiatedin interfaceSmartInitializingSingleton
-
resetBeans
Reinstate 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. Ifnull, all the mocked beans are reset
-
substituteMessageSourceFor
Replace the realMessageSourcein theSourcePollingChannelAdapterbean with providedMessageSourceinstance. Can be a mock object.- Parameters:
pollingAdapterId- the endpoint bean namemockMessageSource- theMessageSourceto replace in the endpoint bean- See Also:
-
substituteMessageSourceFor
public 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 namemockMessageSource- theMessageSourceto replace in the endpoint beanautoStartup- start or not the endpoint after replacing itsMessageSource- See Also:
-
substituteMessageHandlerFor
public void substituteMessageHandlerFor(String consumerEndpointId, MessageHandler mockMessageHandler) -
substituteMessageHandlerFor
public void substituteMessageHandlerFor(String consumerEndpointId, MessageHandler mockMessageHandler, boolean autoStartup) -
substituteTriggerFor
Replace the realTriggerin theAbstractPollingEndpointbean with provided instance.- Parameters:
pollingEndpointId- theAbstractPollingEndpointbean id to replacetrigger- theTriggerto set intoAbstractPollingEndpoint- Since:
- 6.3
-
substituteTriggerFor
Replace the realTriggerin theAbstractPollingEndpointbean with provided instance. The endpoint is not started whenautoStartup == false.- Parameters:
pollingEndpointId- theAbstractPollingEndpointbean id to replacetrigger- theTriggerto set intoAbstractPollingEndpointautoStartup- start or not the endpoint after replacing itsMessageSource- Since:
- 6.3
-