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(_registry);
17 SubSystem application = new Application(_registry);
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 assertEquals(0, _registry.listAllServices().length);
31 assertEquals(0, _registry.listAllServices().length);
34 public void testApplicationEnvironment() {
36 SubSystem environment = new Environment(_registry);
37 SubSystem application = new Application(_registry);
38 SystemAssembler assembler = new SystemAssembler(new SubSystem[] {
39 application, environment }, new ServiceDescriptor[0]);
40 assembler.start(_registry, new Service[0]);
41 } catch (SystemAssemblyException e) {
42 // e.printStackTrace();
48 public void testComposite() {
49 SubSystem environment = new Environment(_registry);
50 SubSystem application = new Application(_registry);
51 CompositeSystem system = new CompositeSystem("all", _registry, new SubSystem[] {
52 environment, application }, new ServiceDescriptor[0],
53 new ServiceDescriptor[0]);
54 system.start("root", new Service[0]);
55 ServiceDescriptor[] required = system.getRequiredServices();
56 assertEquals(0, required.length);
57 ServiceDescriptor[] provided = system.getProvidedServices();
58 assertEquals(0, provided.length);
61 public void testCompositeWithWrongProvidedInfo() {
63 SubSystem environment = new Environment(_registry);
64 SubSystem application = new Application(_registry);
65 CompositeSystem system = new CompositeSystem("all", _registry,
66 new SubSystem[] { environment, application },
67 new ServiceDescriptor[] { new DefaultServiceDescriptor(
68 String.class) }, new ServiceDescriptor[0]);
69 } catch (SystemAssemblyException e) {
75 public void testCompositeWithSuperfluousRequiredInfo() {
76 SubSystem environment = new Environment(_registry);
77 SubSystem application = new Application(_registry);
78 CompositeSystem system = new CompositeSystem("all", _registry,new SubSystem[] {
79 environment, application }, new ServiceDescriptor[0],
80 new ServiceDescriptor[] { new DefaultServiceDescriptor(
82 system.start("root", new Service[0]);
83 ServiceDescriptor[] required = system.getRequiredServices();
84 assertEquals(1, required.length);
85 ServiceDescriptor[] provided = system.getProvidedServices();
86 assertEquals(0, provided.length);
89 public void testCompositeWithExternalDependencesNotProvided() {
91 SubSystem environment = new Environment(_registry);
92 SubSystem application = new Application(_registry);
93 CompositeSystem system = new CompositeSystem("all", _registry,
94 new SubSystem[] { application }, new ServiceDescriptor[0],
95 application.getRequiredServices());
96 system.start("root", new Service[0]);
97 } catch (SystemAssemblyException e) {
104 public void testCompositeWithExternalDependencesProvided() {
106 SubSystem environment = new Environment(_registry);
107 SubSystem application = new Application(_registry);
108 CompositeSystem system = new CompositeSystem("all", _registry,
109 new SubSystem[] { application }, new ServiceDescriptor[0],
110 application.getRequiredServices());
111 Service[] envServices = environment.start("env", new Service[0]);
112 system.start("root", envServices);
113 ServiceDescriptor[] required = system.getRequiredServices();
114 assertEquals(2, required.length);
115 ServiceDescriptor[] provided = system.getProvidedServices();
116 assertEquals(0, provided.length);