Example usage for org.springframework.integration.handler.advice AbstractRequestHandlerAdvice invoke

List of usage examples for org.springframework.integration.handler.advice AbstractRequestHandlerAdvice invoke

Introduction

In this page you can find the example usage for org.springframework.integration.handler.advice AbstractRequestHandlerAdvice invoke.

Prototype

@Override
    public final Object invoke(final MethodInvocation invocation) throws Throwable 

Source Link

Usage

From source file:org.springframework.integration.handler.advice.AdvisedMessageHandlerTests.java

/**
 * Verify that Errors such as OOM are properly propagated.
 *//*  www  .  java  2  s.  c  om*/
@Test
public void throwableProperlyPropagated() throws Exception {
    AbstractRequestHandlerAdvice advice = new AbstractRequestHandlerAdvice() {

        @Override
        protected Object doInvoke(ExecutionCallback callback, Object target, Message<?> message)
                throws Exception {
            Object result;
            try {
                result = callback.execute();
            } catch (Exception e) {
                // should not be unwrapped because the cause is a Throwable
                throw this.unwrapExceptionIfNecessary(e);
            }
            return result;
        }
    };
    final Throwable theThrowable = new Throwable("foo");
    MethodInvocation methodInvocation = mock(MethodInvocation.class);

    Method method = AbstractReplyProducingMessageHandler.class.getDeclaredMethod("handleRequestMessage",
            Message.class);
    when(methodInvocation.getMethod()).thenReturn(method);
    when(methodInvocation.getArguments()).thenReturn(new Object[] { new GenericMessage<String>("foo") });
    try {
        doAnswer(new Answer<Object>() {
            public Object answer(InvocationOnMock invocation) throws Throwable {
                throw theThrowable;
            }
        }).when(methodInvocation).proceed();
        advice.invoke(methodInvocation);
        fail("Expected throwable");
    } catch (Throwable t) {
        assertSame(theThrowable, t);
    }
}