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 String
MOCK_INTEGRATION_CONTEXT_BEAN_NAME
The bean name for the mock integration context. -
Constructor Summary
Constructors Constructor Description MockIntegrationContext()
-
Method Summary
Modifier and Type Method Description 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.
-
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:
setBeanFactory
in 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 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:
MockIntegration.mockMessageSource(T)
-
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:
MockIntegration.mockMessageSource(T)
-
substituteMessageHandlerFor
public void substituteMessageHandlerFor(String consumerEndpointId, MessageHandler mockMessageHandler) -
substituteMessageHandlerFor
public void substituteMessageHandlerFor(String consumerEndpointId, MessageHandler mockMessageHandler, boolean autoStartup)
-