Example usage for org.springframework.amqp.rabbit.listener ConditionalRejectingErrorHandler handleError

List of usage examples for org.springframework.amqp.rabbit.listener ConditionalRejectingErrorHandler handleError

Introduction

In this page you can find the example usage for org.springframework.amqp.rabbit.listener ConditionalRejectingErrorHandler handleError.

Prototype

@Override
    public void handleError(Throwable t) 

Source Link

Usage

From source file:org.springframework.amqp.rabbit.listener.ErrorHandlerTests.java

@Test
public void testFatalsAreRejected() throws Exception {
    ConditionalRejectingErrorHandler handler = new ConditionalRejectingErrorHandler();
    Log logger = spy(TestUtils.getPropertyValue(handler, "logger", Log.class));
    willDoNothing().given(logger).warn(anyString(), any(Throwable.class));
    new DirectFieldAccessor(handler).setPropertyValue("logger", logger);
    handler.handleError(new ListenerExecutionFailedException("intended", new RuntimeException()));

    try {// ww w. j a v  a  2s .  co m
        handler.handleError(
                new ListenerExecutionFailedException("intended", new MessageConversionException("")));
        fail("Expected exception");
    } catch (AmqpRejectAndDontRequeueException e) {
    }

    try {
        handler.handleError(new ListenerExecutionFailedException("intended",
                new org.springframework.messaging.converter.MessageConversionException("")));
        fail("Expected exception");
    } catch (AmqpRejectAndDontRequeueException e) {
    }

    Message<?> message = mock(Message.class);
    MethodParameter mp = new MethodParameter(Foo.class.getMethod("foo", String.class), 0);
    try {
        handler.handleError(new ListenerExecutionFailedException("intended",
                new MethodArgumentNotValidException(message, mp)));
        fail("Expected exception");
    } catch (AmqpRejectAndDontRequeueException e) {
    }

    try {
        handler.handleError(new ListenerExecutionFailedException("intended",
                new MethodArgumentTypeMismatchException(message, mp, "")));
        fail("Expected exception");
    } catch (AmqpRejectAndDontRequeueException e) {
    }
}