Assert.assertEquals(1, targetResponseHandler.getCount());
Assert.assertEquals(1, targetInterceptor.getCount());
}
public void testWireWithTargetInterceptor() throws Exception {
MessageFactory msgFactory = new MessageFactoryImpl();
SourceInvocationConfiguration source = new SourceInvocationConfiguration(hello);
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);
MockSyncInterceptor targetInterceptor = new MockSyncInterceptor();
target.addInterceptor(targetInterceptor);
target.addInterceptor(new InvokerInterceptor());
TargetWireFactory targetFactory = wireFactoryFactory.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);
// connect the source to the target
DefaultWireBuilder builder = new DefaultWireBuilder();
// no need for scopes since we use a static invoker
builder.connect(sourceFactory, targetFactory, null, true, null);
target.build();
// set a static invoker
MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl());
source.setTargetInvoker(invoker);
Message msg = msgFactory.createMessage();
msg.setBody("foo");
msg.setTargetInvoker(invoker);
Message response = source.getHeadInterceptor().invoke(msg);
Assert.assertEquals("foo", response.getBody());
Assert.assertEquals(1, targetInterceptor.getCount());