public void testInvokeWithRequestHandlers() throws Exception {
SourceInvocationConfiguration source = new SourceInvocationConfiguration(hello);
source.addInterceptor(new AsyncInterceptor(workManager, factory));
MockHandler sourceRequestHandler = new MockHandler();
MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor();
source.addRequestHandler(sourceRequestHandler);
source.addInterceptor(sourceInterceptor);
TargetInvocationConfiguration target = new TargetInvocationConfiguration(hello);
MockHandler targetRequestHandler = new MockHandler();
MockSyncInterceptor targetInterceptor = new MockSyncInterceptor();
target.addRequestHandler(targetRequestHandler);
target.addInterceptor(targetInterceptor);
target.addInterceptor(new InvokerInterceptor());
// connect the source to the target
source.setTargetRequestChannel(new MessageChannelImpl(target.getRequestHandlers()));
source.setTargetResponseChannel(new MessageChannelImpl(target.getResponseHandlers()));
source.build();
target.build();
CountDownLatch startSignal = new CountDownLatch(1);
CountDownLatch doneSignal = new CountDownLatch(1);
MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl(startSignal, doneSignal));
source.setTargetInvoker(invoker);
Message msg = factory.createMessage();
msg.setBody("foo");
msg.setTargetInvoker(invoker);
Message response = source.getHeadInterceptor().invoke(msg);
startSignal.countDown();
doneSignal.await();
Assert.assertEquals(null, response.getBody());
Assert.assertEquals(1, sourceRequestHandler.getCount());
Assert.assertEquals(1, sourceInterceptor.getCount());
Assert.assertEquals(1, targetRequestHandler.getCount());
Assert.assertEquals(1, targetInterceptor.getCount());
}