Class MockIntegrationContext

java.lang.Object
org.springframework.integration.test.context.MockIntegrationContext
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.config.BeanPostProcessor, org.springframework.beans.factory.SmartInitializingSingleton

public class MockIntegrationContext extends Object implements org.springframework.beans.factory.config.BeanPostProcessor, org.springframework.beans.factory.SmartInitializingSingleton, org.springframework.beans.factory.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
See Also:
  • Field Details

    • MOCK_INTEGRATION_CONTEXT_BEAN_NAME

      public static final String MOCK_INTEGRATION_CONTEXT_BEAN_NAME
      The bean name for the mock integration context.
      See Also:
  • Constructor Details

    • MockIntegrationContext

      public MockIntegrationContext()
  • Method Details

    • setBeanFactory

      public void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory) throws org.springframework.beans.BeansException
      Specified by:
      setBeanFactory in interface org.springframework.beans.factory.BeanFactoryAware
      Throws:
      org.springframework.beans.BeansException
    • postProcessBeforeInitialization

      public Object postProcessBeforeInitialization(Object bean, String beanName) throws org.springframework.beans.BeansException
      Specified by:
      postProcessBeforeInitialization in interface org.springframework.beans.factory.config.BeanPostProcessor
      Throws:
      org.springframework.beans.BeansException
    • afterSingletonsInstantiated

      public void afterSingletonsInstantiated()
      Specified by:
      afterSingletonsInstantiated in interface org.springframework.beans.factory.SmartInitializingSingleton
    • resetBeans

      public void resetBeans(String... beanNames)
      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. If null, all the mocked beans are reset
    • substituteMessageSourceFor

      public void substituteMessageSourceFor(String pollingAdapterId, org.springframework.integration.core.MessageSource<?> mockMessageSource)
      Replace the real MessageSource in the SourcePollingChannelAdapter bean with provided MessageSource instance. Can be a mock object.
      Parameters:
      pollingAdapterId - the endpoint bean name
      mockMessageSource - the MessageSource to replace in the endpoint bean
      See Also:
    • substituteMessageSourceFor

      public void substituteMessageSourceFor(String pollingAdapterId, org.springframework.integration.core.MessageSource<?> mockMessageSource, boolean autoStartup)
      Replace the real MessageSource in the SourcePollingChannelAdapter bean with provided MessageSource instance. Can be a mock object. The endpoint is not started when autoStartup == false.
      Parameters:
      pollingAdapterId - the endpoint bean name
      mockMessageSource - the MessageSource to replace in the endpoint bean
      autoStartup - start or not the endpoint after replacing its MessageSource
      See Also:
    • substituteMessageHandlerFor

      public void substituteMessageHandlerFor(String consumerEndpointId, org.springframework.messaging.MessageHandler mockMessageHandler)
    • substituteMessageHandlerFor

      public void substituteMessageHandlerFor(String consumerEndpointId, org.springframework.messaging.MessageHandler mockMessageHandler, boolean autoStartup)