/**
* Validates building a wire from an atomic context to a reference context
*/
public void testAtomicToReferenceWireBuild() throws Exception {
WorkContext work = new WorkContextImpl();
ScopeContainer scope = new ModuleScopeContainer(work);
scope.start();
Connector connector = new ConnectorImpl();
SystemComponentBuilder builder = new SystemComponentBuilder();
SystemBindingBuilder bindingBuilder = new SystemBindingBuilder();
CompositeComponent grandParent = new CompositeComponentImpl("grandparent", null, null, null);
CompositeComponent parent = new CompositeComponentImpl("parent", grandParent, null, null);
// create a context in the grandparent that the reference will be autowired to
ComponentDefinition<SystemImplementation> targetComponentDefinition = MockComponentFactory.createTarget();
AtomicComponent targetComponentComponent = builder.build(parent, targetComponentDefinition, deploymentContext);
grandParent.register(targetComponentComponent);
BoundReferenceDefinition<SystemBinding> targetReferenceDefinition = MockComponentFactory.createBoundReference();
ComponentDefinition<SystemImplementation> sourceComponentDefinition =
MockComponentFactory.createSourceWithTargetReference();
AtomicComponent sourceComponent = builder.build(parent, sourceComponentDefinition, deploymentContext);
Reference reference = bindingBuilder.build(parent, targetReferenceDefinition, deploymentContext);
parent.register(sourceComponent);
parent.register(reference);
connector.connect(reference.getInboundWire(), reference.getOutboundWire(), true);
connector.connect(sourceComponent);
grandParent.register(parent);
grandParent.start();
scope.onEvent(new CompositeStart(this, parent));
Source source = (Source) parent.getSystemChild("source").getServiceInstance();
assertNotNull(source);
Target target = (Target) parent.getSystemChild("target").getServiceInstance();
assertNotNull(target);
assertSame(target, source.getTarget());
scope.onEvent(new CompositeStop(this, parent));
grandParent.stop();
scope.stop();
}