* @version $$Rev: 441935 $$ $$Date: 2006-09-10 02:57:47 -0700 (Sun, 10 Sep 2006) $$
*/
public class JavaReferenceWireTestCase extends TestCase {
public void testReferenceSet() throws Exception {
ScopeContainer scope = createMock();
scope.start();
final Target target = new TargetImpl();
PojoConfiguration configuration = new PojoConfiguration();
configuration.addReferenceSite("target", SourceImpl.class.getMethod("setTarget", Target.class));
configuration.addServiceInterface(Source.class);
Constructor<SourceImpl> ctr = SourceImpl.class.getConstructor();
configuration.setInstanceFactory(new PojoObjectFactory<SourceImpl>(ctr));
configuration.setScopeContainer(scope);
OutboundWire wire = EasyMock.createMock(OutboundWire.class);
wire.getInvocationChains();
EasyMock.expectLastCall().andReturn(new HashMap<Operation<?>, OutboundInvocationChain>());
EasyMock.expect(wire.getReferenceName()).andReturn("target").atLeastOnce();
EasyMock.replay(wire);
WireService service = EasyMock.createMock(WireService.class);
EasyMock.expect(service.createProxy(EasyMock.eq(wire))).andAnswer(new IAnswer<Object>() {
public Object answer() throws Throwable {
OutboundWire wire = (OutboundWire) EasyMock.getCurrentArguments()[0];
wire.getInvocationChains();
return target;
}
}).atLeastOnce();
EasyMock.replay(service);
configuration.setWireService(service);
JavaAtomicComponent sourceContext = new JavaAtomicComponent("source", configuration, null);
sourceContext.addOutboundWire(wire);
sourceContext.start();
Source source = (Source) sourceContext.getServiceInstance();
assertSame(target, source.getTarget());
scope.stop();
EasyMock.verify(wire);
EasyMock.verify(scope);
EasyMock.verify(service);
}