*/
public void testInvocation() throws Exception {
MessageFactory msgFactory = new MessageFactoryImpl();
SourceInvocationConfiguration source = new SourceInvocationConfiguration(hello);
MockHandler sourceRequestHandler = new MockHandler();
MockHandler sourceResponseHandler = new MockHandler();
MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor();
source.addRequestHandler(sourceRequestHandler);
source.addResponseHandler(sourceResponseHandler);
source.addInterceptor(sourceInterceptor);
SourceWireFactory sourceFactory = new JDKWireFactoryFactory().createSourceWireFactory();
Map<Method, SourceInvocationConfiguration> sourceInvocationConfigs = new MethodHashMap<SourceInvocationConfiguration>();
sourceInvocationConfigs.put(hello, source);
WireSourceConfiguration sourceConfig = new WireSourceConfiguration("foo",new QualifiedName("target/SimpleTarget"),
sourceInvocationConfigs, Thread.currentThread().getContextClassLoader(), msgFactory);
sourceFactory.setConfiguration(sourceConfig);
sourceFactory.setBusinessInterface(SimpleTarget.class);
TargetInvocationConfiguration target = new TargetInvocationConfiguration(hello);
MockHandler targetRequestHandler = new MockHandler();
MockHandler targetResponseHandler = new MockHandler();
MockSyncInterceptor targetInterceptor = new MockSyncInterceptor();
target.addRequestHandler(targetRequestHandler);
target.addResponseHandler(targetResponseHandler);
target.addInterceptor(targetInterceptor);
target.addInterceptor(new InvokerInterceptor());
TargetWireFactory targetFactory = new JDKWireFactoryFactory().createTargetWireFactory();
Map<Method, TargetInvocationConfiguration> targetInvocationConfigs = new MethodHashMap<TargetInvocationConfiguration>();
targetInvocationConfigs.put(hello, target);
WireTargetConfiguration targetConfig = new WireTargetConfiguration(new QualifiedName("target/SimpleTarget"),
targetInvocationConfigs, Thread.currentThread().getContextClassLoader(), msgFactory);
targetFactory.setConfiguration(targetConfig);
targetFactory.setBusinessInterface(SimpleTarget.class);
// bootstrap a scope container with the target in it
Map<String,Object> instances = new HashMap<String,Object>();
SimpleTarget simpleTarget = new SimpleTargetImpl();
instances.put("target",simpleTarget);
MockScopeContext scopeCtx = new MockScopeContext(instances);
// connect the source to the target
DefaultWireBuilder builder = new DefaultWireBuilder();
builder.addWireBuilder(new JavaTargetWireBuilder());
builder.connect(sourceFactory, targetFactory, JavaContextFactory.class, true, scopeCtx);
source.build();
target.build();
Assert.assertNotNull(source.getTargetInvoker());
Message msg = msgFactory.createMessage();
msg.setBody("foo");
msg.setTargetInvoker(source.getTargetInvoker());
Message response = source.getHeadInterceptor().invoke(msg);
Assert.assertEquals("foo", response.getBody());
Assert.assertEquals(1, sourceRequestHandler.getCount());
Assert.assertEquals(1, sourceResponseHandler.getCount());
Assert.assertEquals(1, sourceInterceptor.getCount());
Assert.assertEquals(1, targetRequestHandler.getCount());
Assert.assertEquals(1, targetResponseHandler.getCount());
Assert.assertEquals(1, targetInterceptor.getCount());
}