1 package org.wamblee.system;
3 import junit.framework.TestCase;
5 public class SystemAssemblerTest extends TestCase {
7 private ServiceRegistry _registry;
10 protected void setUp() throws Exception {
12 _registry = new DefaultServiceRegistry();
15 public void testEnvironmentApplication() {
16 SubSystem environment = new Environment();
17 SubSystem application = new Application();
18 SystemAssembler assembler = new SystemAssembler(new SubSystem[] {
19 environment, application }, new ServiceDescriptor[0]);
20 assembler.start(_registry, new Service[0]);
21 Service[] envServices = environment.getRunningServices();
22 assertEquals(2, envServices.length);
23 Service[] appServices = environment.getRunningServices();
24 assertEquals(2, appServices.length);
25 assertEquals(2, _registry.listAllServices().length);
28 public void testApplicationEnvironment() {
30 SubSystem environment = new Environment();
31 SubSystem application = new Application();
32 SystemAssembler assembler = new SystemAssembler(new SubSystem[] {
33 application, environment }, new ServiceDescriptor[0]);
34 assembler.start(_registry, new Service[0]);
35 } catch (SystemAssemblyException e) {
36 // e.printStackTrace();
42 public void testComposite() {
43 SubSystem environment = new Environment();
44 SubSystem application = new Application();
45 CompositeSystem system = new CompositeSystem("all", new SubSystem[] {
46 environment, application }, new ServiceDescriptor[0],
47 new ServiceDescriptor[0]);
48 system.start("root", _registry, new Service[0]);
49 ServiceDescriptor[] required = system.getRequiredServices();
50 assertEquals(0, required.length);
51 ServiceDescriptor[] provided = system.getProvidedServices();
52 assertEquals(0, provided.length);
55 public void testCompositeWithWrongProvidedInfo() {
57 SubSystem environment = new Environment();
58 SubSystem application = new Application();
59 CompositeSystem system = new CompositeSystem("all",
60 new SubSystem[] { environment, application },
61 new ServiceDescriptor[] { new DefaultServiceDescriptor(
62 String.class) }, new ServiceDescriptor[0]);
63 } catch (SystemAssemblyException e) {
69 public void testCompositeWithSuperfluousRequiredInfo() {
70 SubSystem environment = new Environment();
71 SubSystem application = new Application();
72 CompositeSystem system = new CompositeSystem("all", new SubSystem[] {
73 environment, application }, new ServiceDescriptor[0],
74 new ServiceDescriptor[] { new DefaultServiceDescriptor(
76 system.start("root", _registry, new Service[0]);
77 ServiceDescriptor[] required = system.getRequiredServices();
78 assertEquals(1, required.length);
79 ServiceDescriptor[] provided = system.getProvidedServices();
80 assertEquals(0, provided.length);
83 public void testCompositeWithExternalDependencesNotProvided() {
85 SubSystem environment = new Environment();
86 SubSystem application = new Application();
87 CompositeSystem system = new CompositeSystem("all",
88 new SubSystem[] { application }, new ServiceDescriptor[0],
89 application.getRequiredServices());
90 system.start("root", _registry, new Service[0]);
91 } catch (SystemAssemblyException e) {
98 public void testCompositeWithExternalDependencesProvided() {
100 SubSystem environment = new Environment();
101 SubSystem application = new Application();
102 CompositeSystem system = new CompositeSystem("all",
103 new SubSystem[] { application }, new ServiceDescriptor[0],
104 application.getRequiredServices());
105 Service[] envServices = environment.start("env", _registry,new Service[0]);
106 system.start("root", _registry, envServices);
107 ServiceDescriptor[] required = system.getRequiredServices();
108 assertEquals(2, required.length);
109 ServiceDescriptor[] provided = system.getProvidedServices();
110 assertEquals(0, provided.length);