package org.wamblee.system; import junit.framework.TestCase; public class SystemAssemblerTest extends TestCase { private ServiceRegistry _registry; @Override protected void setUp() throws Exception { super.setUp(); _registry = new DefaultServiceRegistry(); } public void testEnvironmentApplication() { SubSystem environment = new Environment(); SubSystem application = new Application(); SystemAssembler assembler = new SystemAssembler(new SubSystem[] { environment, application }, new ServiceDescriptor[0]); assembler.start(_registry, new Service[0]); Service[] envServices = environment.getRunningServices(); assertEquals(2, envServices.length); Service[] appServices = environment.getRunningServices(); assertEquals(2, appServices.length); assertEquals(2, _registry.listAllServices().length); environment.stop("", _registry); assertEquals(0, _registry.listAllServices().length); application.stop("", _registry); assertEquals(0, _registry.listAllServices().length); } public void testApplicationEnvironment() { try { SubSystem environment = new Environment(); SubSystem application = new Application(); SystemAssembler assembler = new SystemAssembler(new SubSystem[] { application, environment }, new ServiceDescriptor[0]); assembler.start(_registry, new Service[0]); } catch (SystemAssemblyException e) { // e.printStackTrace(); return; } fail(); } public void testComposite() { SubSystem environment = new Environment(); SubSystem application = new Application(); CompositeSystem system = new CompositeSystem("all", new SubSystem[] { environment, application }, new ServiceDescriptor[0], new ServiceDescriptor[0]); system.start("root", _registry, new Service[0]); ServiceDescriptor[] required = system.getRequiredServices(); assertEquals(0, required.length); ServiceDescriptor[] provided = system.getProvidedServices(); assertEquals(0, provided.length); } public void testCompositeWithWrongProvidedInfo() { try { SubSystem environment = new Environment(); SubSystem application = new Application(); CompositeSystem system = new CompositeSystem("all", new SubSystem[] { environment, application }, new ServiceDescriptor[] { new DefaultServiceDescriptor( String.class) }, new ServiceDescriptor[0]); } catch (SystemAssemblyException e) { return; } fail(); } public void testCompositeWithSuperfluousRequiredInfo() { SubSystem environment = new Environment(); SubSystem application = new Application(); CompositeSystem system = new CompositeSystem("all", new SubSystem[] { environment, application }, new ServiceDescriptor[0], new ServiceDescriptor[] { new DefaultServiceDescriptor( String.class) }); system.start("root", _registry, new Service[0]); ServiceDescriptor[] required = system.getRequiredServices(); assertEquals(1, required.length); ServiceDescriptor[] provided = system.getProvidedServices(); assertEquals(0, provided.length); } public void testCompositeWithExternalDependencesNotProvided() { try { SubSystem environment = new Environment(); SubSystem application = new Application(); CompositeSystem system = new CompositeSystem("all", new SubSystem[] { application }, new ServiceDescriptor[0], application.getRequiredServices()); system.start("root", _registry, new Service[0]); } catch (SystemAssemblyException e) { return; } fail(); } public void testCompositeWithExternalDependencesProvided() { SubSystem environment = new Environment(); SubSystem application = new Application(); CompositeSystem system = new CompositeSystem("all", new SubSystem[] { application }, new ServiceDescriptor[0], application.getRequiredServices()); Service[] envServices = environment.start("env", _registry,new Service[0]); system.start("root", _registry, envServices); ServiceDescriptor[] required = system.getRequiredServices(); assertEquals(2, required.length); ServiceDescriptor[] provided = system.getProvidedServices(); assertEquals(0, provided.length); } }