/**
* Verifies system services in a CompositeComponentImpl are wired during the parent composite's prepare callback
*/
public void testSystemServiceWire() {
InboundWire inbound = EasyMock.createMock(InboundWire.class);
EasyMock.expect(inbound.getServiceContract()).andReturn(new JavaServiceContract(Foo.class));
inbound.getInvocationChains();
EasyMock.expectLastCall().andReturn(Collections.emptyMap());
List<Class<?>> services = new ArrayList<Class<?>>();
services.add(Foo.class);
QualifiedName qName = new QualifiedName("target/bar");
OutboundWire outbound = EasyMock.createMock(OutboundWire.class);
EasyMock.expect(outbound.getTargetName()).andReturn(qName).atLeastOnce();
outbound.getInvocationChains();
EasyMock.expectLastCall().andReturn(Collections.emptyMap());
outbound.setTargetWire(EasyMock.eq(inbound));
EasyMock.expect(outbound.getServiceContract()).andReturn(new JavaServiceContract(Foo.class)).atLeastOnce();
List<OutboundWire> wires = new ArrayList<OutboundWire>();
wires.add(outbound);
Map<String, List<OutboundWire>> wireMap = new HashMap<String, List<OutboundWire>>();
wireMap.put("ref", wires);
CompositeComponent parent = new CompositeComponentImpl("foo", "foo", null, new ConnectorImpl(), null);
SystemAtomicComponent source = EasyMock.createMock(SystemAtomicComponent.class);
EasyMock.expect(source.getScope()).andReturn(Scope.MODULE).atLeastOnce();
EasyMock.expect(source.getName()).andReturn("source").atLeastOnce();
EasyMock.expect(source.getServiceInterfaces()).andReturn(services);
EasyMock.expect(source.getOutboundWires()).andReturn(wireMap);
source.getInboundWires();
EasyMock.expectLastCall().andReturn(Collections.emptyMap());
EasyMock.expect(source.isSystem()).andReturn(true).atLeastOnce();
EasyMock.expect(source.getParent()).andReturn(parent).atLeastOnce();
source.prepare();
EasyMock.replay(source);
EasyMock.expect(outbound.getContainer()).andReturn(source);
EasyMock.replay(outbound);
parent.register(source);
SystemAtomicComponent target = EasyMock.createMock(SystemAtomicComponent.class);
EasyMock.expect(target.getName()).andReturn("target").atLeastOnce();
EasyMock.expect(target.getServiceInterfaces()).andReturn(services);
EasyMock.expect(target.getInboundWire("bar")).andReturn(inbound).atLeastOnce();
EasyMock.expect(target.getScope()).andReturn(Scope.MODULE).atLeastOnce();
EasyMock.expect(target.getParent()).andReturn(parent).atLeastOnce();
target.getInboundWires();
EasyMock.expectLastCall().andReturn(Collections.emptyMap());
target.prepare();
target.getOutboundWires();
EasyMock.expectLastCall().andReturn(Collections.emptyMap());
EasyMock.expect(target.isSystem()).andReturn(true).atLeastOnce();
EasyMock.replay(target);
EasyMock.expect(inbound.getContainer()).andReturn(target);
EasyMock.replay(inbound);
parent.register(target);
parent.prepare();
EasyMock.verify(source);