Class MockIntegrationContext
java.lang.Object
org.springframework.integration.test.context.MockIntegrationContext
- All Implemented Interfaces:
Aware,BeanFactoryAware
public class MockIntegrationContext extends Object implements 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:
SpringIntegrationTest
-
Field Summary
Fields Modifier and Type Field Description static StringMOCK_INTEGRATION_CONTEXT_BEAN_NAMEThe bean name for the mock integration context. -
Constructor Summary
Constructors Constructor Description MockIntegrationContext() -
Method Summary
Modifier and Type Method Description 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.
-
Field Details
-
MOCK_INTEGRATION_CONTEXT_BEAN_NAME
The bean name for the mock integration context.- See Also:
- Constant Field Values
-
-
Constructor Details
-
MockIntegrationContext
public MockIntegrationContext()
-
-
Method Details
-
setBeanFactory
- Specified by:
setBeanFactoryin interfaceBeanFactoryAware- Throws:
BeansException
-
resetBeans
Reinstate the mocked beans after execution test to their real state. Typically is used from JUnit clean up method.- Parameters:
beanNames- the bean names to reset. Ifnull, all the mocked beans are reset
-
substituteMessageSourceFor
public void substituteMessageSourceFor(String pollingAdapterId, MessageSource<?> mockMessageSource)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:
MockIntegration.mockMessageSource(T)
-
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:
MockIntegration.mockMessageSource(T)
-
substituteMessageHandlerFor
public void substituteMessageHandlerFor(String consumerEndpointId, MessageHandler mockMessageHandler) -
substituteMessageHandlerFor
public void substituteMessageHandlerFor(String consumerEndpointId, MessageHandler mockMessageHandler, boolean autoStartup)
-