/**
* Tests autowiring to a system service which is wired to an atomic component.
*/
public void testSystemServiceAutowire() throws Exception {
CompositeComponent parent = new CompositeComponentImpl("parent", null, null, null);
parent.start();
List<Class<?>> interfaces = new ArrayList<Class<?>>();
interfaces.add(Source.class);
interfaces.add(Source2.class);
Source serviceSource = new SourceImpl();
SystemService component = EasyMock.createMock(SystemService.class);
EasyMock.expect(component.getName()).andReturn("service").atLeastOnce();
component.getInterface();
EasyMock.expectLastCall().andReturn(Source.class).atLeastOnce();
EasyMock.expect(component.isSystem()).andReturn(true).atLeastOnce();
EasyMock.expect(component.getServiceInstance()).andReturn(serviceSource);
EasyMock.replay(component);
parent.register(component);
SystemAtomicComponent component2 = EasyMock.createMock(SystemAtomicComponent.class);
EasyMock.expect(component2.getName()).andReturn("source").atLeastOnce();
EasyMock.expect(component2.getServiceInterfaces()).andReturn(interfaces).atLeastOnce();
EasyMock.expect(component2.isSystem()).andReturn(true).atLeastOnce();
EasyMock.replay(component2);
parent.register(component2);
Source source = parent.resolveSystemExternalInstance(Source.class);
assertSame(serviceSource, source);
Source2 source2 = parent.resolveSystemExternalInstance(Source2.class);
assertNull(source2);
EasyMock.verify(component);
EasyMock.verify(component2);
}