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
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
The bean name for the mock integration context. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
postProcessBeforeInitialization
(Object bean, String beanName) void
resetBeans
(String... beanNames) Reinstate the mocked beans after execution test to their real state.void
setBeanFactory
(BeanFactory beanFactory) void
substituteMessageHandlerFor
(String consumerEndpointId, MessageHandler mockMessageHandler) void
substituteMessageHandlerFor
(String consumerEndpointId, MessageHandler mockMessageHandler, boolean autoStartup) void
substituteMessageSourceFor
(String pollingAdapterId, MessageSource<?> mockMessageSource) Replace the realMessageSource
in theSourcePollingChannelAdapter
bean with providedMessageSource
instance.void
substituteMessageSourceFor
(String pollingAdapterId, MessageSource<?> mockMessageSource, boolean autoStartup) Replace the realMessageSource
in theSourcePollingChannelAdapter
bean with providedMessageSource
instance.void
substituteTriggerFor
(String pollingEndpointId, Trigger trigger) Replace the realTrigger
in theAbstractPollingEndpoint
bean with provided instance.void
substituteTriggerFor
(String pollingEndpointId, Trigger trigger, boolean autoStartup) Replace the realTrigger
in theAbstractPollingEndpoint
bean with provided instance.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods 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:
setBeanFactory
in interfaceBeanFactoryAware
- Throws:
BeansException
-
postProcessBeforeInitialization
- Specified by:
postProcessBeforeInitialization
in interfaceBeanPostProcessor
- Throws:
BeansException
-
afterSingletonsInstantiated
public void afterSingletonsInstantiated()- Specified by:
afterSingletonsInstantiated
in 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 realMessageSource
in theSourcePollingChannelAdapter
bean with providedMessageSource
instance. Can be a mock object.- Parameters:
pollingAdapterId
- the endpoint bean namemockMessageSource
- theMessageSource
to replace in the endpoint bean- See Also:
-
substituteMessageSourceFor
public void substituteMessageSourceFor(String pollingAdapterId, MessageSource<?> mockMessageSource, boolean autoStartup) Replace the realMessageSource
in theSourcePollingChannelAdapter
bean with providedMessageSource
instance. Can be a mock object. The endpoint is not started whenautoStartup == false
.- Parameters:
pollingAdapterId
- the endpoint bean namemockMessageSource
- theMessageSource
to 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 realTrigger
in theAbstractPollingEndpoint
bean with provided instance.- Parameters:
pollingEndpointId
- theAbstractPollingEndpoint
bean id to replacetrigger
- theTrigger
to set intoAbstractPollingEndpoint
- Since:
- 6.3
-
substituteTriggerFor
Replace the realTrigger
in theAbstractPollingEndpoint
bean with provided instance. The endpoint is not started whenautoStartup == false
.- Parameters:
pollingEndpointId
- theAbstractPollingEndpoint
bean id to replacetrigger
- theTrigger
to set intoAbstractPollingEndpoint
autoStartup
- start or not the endpoint after replacing itsMessageSource
- Since:
- 6.3
-