Class RabbitListenerTestHarness

  • All Implemented Interfaces:
    org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanClassLoaderAware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.config.BeanPostProcessor, org.springframework.beans.factory.SmartInitializingSingleton, org.springframework.context.EnvironmentAware, org.springframework.core.Ordered

    public class RabbitListenerTestHarness
    extends org.springframework.amqp.rabbit.annotation.RabbitListenerAnnotationBeanPostProcessor
    BeanPostProcessor extending RabbitListenerAnnotationBeanPostProcessor. Wraps the listener bean in a CGLIB proxy with an advice to capture the arguments and result (if any) in a blocking queue. Test cases can access the results by autowiring the test harness into test cases.
    Since:
    1.6
    • Field Summary

      • Fields inherited from class org.springframework.amqp.rabbit.annotation.RabbitListenerAnnotationBeanPostProcessor

        DEFAULT_RABBIT_LISTENER_CONTAINER_FACTORY_BEAN_NAME, RABBIT_EMPTY_STRING_ARGUMENTS_PROPERTY
      • Fields inherited from interface org.springframework.core.Ordered

        HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
    • Constructor Summary

      Constructors 
      Constructor Description
      RabbitListenerTestHarness​(org.springframework.core.type.AnnotationMetadata importMetadata)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <T> T getDelegate​(java.lang.String id)
      Get the actual listener object (not the spy).
      <T> LambdaAnswer<T> getLambdaAnswerFor​(java.lang.String id, boolean callRealMethod, LambdaAnswer.ValueToReturn<T> callback)
      Return a LambdaAnswer that is properly configured to invoke the listener.
      LatchCountDownAndCallRealMethodAnswer getLatchAnswerFor​(java.lang.String id, int count)
      Return a LatchCountDownAndCallRealMethodAnswer that is properly configured to invoke the listener.
      RabbitListenerTestHarness.InvocationData getNextInvocationDataFor​(java.lang.String id, long wait, java.util.concurrent.TimeUnit unit)  
      <T> T getSpy​(java.lang.String id)  
      protected java.util.Collection<org.springframework.amqp.core.Declarable> processListener​(org.springframework.amqp.rabbit.listener.MethodRabbitListenerEndpoint endpoint, org.springframework.amqp.rabbit.annotation.RabbitListener rabbitListener, java.lang.Object bean, java.lang.Object target, java.lang.String beanName)  
      • Methods inherited from class org.springframework.amqp.rabbit.annotation.RabbitListenerAnnotationBeanPostProcessor

        afterSingletonsInstantiated, assertBeanFactory, getOrder, noBeanFoundMessage, postProcessAfterInitialization, postProcessBeforeInitialization, processAmqpListener, resolveExpressionAsString, setBeanClassLoader, setBeanFactory, setCharset, setContainerFactoryBeanName, setEndpointRegistry, setEnvironment, setMessageHandlerMethodFactory
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • RabbitListenerTestHarness

        public RabbitListenerTestHarness​(org.springframework.core.type.AnnotationMetadata importMetadata)
    • Method Detail

      • processListener

        protected java.util.Collection<org.springframework.amqp.core.Declarable> processListener​(org.springframework.amqp.rabbit.listener.MethodRabbitListenerEndpoint endpoint,
                                                                                                 org.springframework.amqp.rabbit.annotation.RabbitListener rabbitListener,
                                                                                                 java.lang.Object bean,
                                                                                                 java.lang.Object target,
                                                                                                 java.lang.String beanName)
        Overrides:
        processListener in class org.springframework.amqp.rabbit.annotation.RabbitListenerAnnotationBeanPostProcessor
      • getLambdaAnswerFor

        public <T> LambdaAnswer<T> getLambdaAnswerFor​(java.lang.String id,
                                                      boolean callRealMethod,
                                                      LambdaAnswer.ValueToReturn<T> callback)
        Return a LambdaAnswer that is properly configured to invoke the listener.
        Type Parameters:
        T - the return type.
        Parameters:
        id - the listener id.
        callRealMethod - true to call the real method.
        callback - the callback.
        Returns:
        the answer.
        Since:
        2.1.16
      • getNextInvocationDataFor

        public RabbitListenerTestHarness.InvocationData getNextInvocationDataFor​(java.lang.String id,
                                                                                 long wait,
                                                                                 java.util.concurrent.TimeUnit unit)
                                                                          throws java.lang.InterruptedException
        Throws:
        java.lang.InterruptedException
      • getSpy

        public <T> T getSpy​(java.lang.String id)
      • getDelegate

        public <T> T getDelegate​(java.lang.String id)
        Get the actual listener object (not the spy).
        Type Parameters:
        T - the type.
        Parameters:
        id - the id.
        Returns:
        the listener.
        Since:
        2.1.16