94bf63c0cb88e8547e31eaf1215d7c822693a9ae
[utils] / system / general / src / test / java / org / wamblee / system / SystemAssemblerTest.java
1 package org.wamblee.system;
2
3 import junit.framework.TestCase;
4
5 public class SystemAssemblerTest extends TestCase {
6
7         public void testEnvironmentApplication() {
8                 SubSystem environment = new Environment();
9                 SubSystem application = new Application();
10                 SystemAssembler assembler = new SystemAssembler(new SubSystem[] {
11                                 environment, application }, new ServiceDescriptor[0]);
12                 assembler.start(new Service[0]);
13                 Service[] envServices = environment.getRunningServices();
14                 assertEquals(2, envServices.length);
15                 Service[] appServices = environment.getRunningServices();
16                 assertEquals(2, appServices.length);
17         }
18
19         public void testApplicationEnvironment() {
20                 try {
21                         SubSystem environment = new Environment();
22                         SubSystem application = new Application();
23                         SystemAssembler assembler = new SystemAssembler(new SubSystem[] {
24                                         application, environment }, new ServiceDescriptor[0]);
25                         assembler.start(new Service[0]);
26                 } catch (SystemAssemblyException e) {
27                         // e.printStackTrace();
28                         return;
29                 }
30                 fail();
31         }
32
33         public void testComposite() {
34                 SubSystem environment = new Environment();
35                 SubSystem application = new Application();
36                 CompositeSystem system = new CompositeSystem("all", new SubSystem[] {
37                                 environment, application }, new ServiceDescriptor[0],
38                                 new ServiceDescriptor[0]);
39                 system.initialize("root", new Service[0]);
40                 ServiceDescriptor[] required = system.getRequiredServices();
41                 assertEquals(0, required.length);
42                 ServiceDescriptor[] provided = system.getProvidedServices();
43                 assertEquals(0, provided.length);
44         }
45
46         public void testCompositeWithWrongProvidedInfo() {
47                 try {
48                         SubSystem environment = new Environment();
49                         SubSystem application = new Application();
50                         CompositeSystem system = new CompositeSystem("all",
51                                         new SubSystem[] { environment, application },
52                                         new ServiceDescriptor[] { new DefaultServiceDescriptor(
53                                                         String.class) }, new ServiceDescriptor[0]);
54                 } catch (SystemAssemblyException e) {
55                         return;
56                 }
57                 fail();
58         }
59
60         public void testCompositeWithSuperfluousRequiredInfo() {
61                 SubSystem environment = new Environment();
62                 SubSystem application = new Application();
63                 CompositeSystem system = new CompositeSystem("all", new SubSystem[] {
64                                 environment, application }, new ServiceDescriptor[0],
65                                 new ServiceDescriptor[] { new DefaultServiceDescriptor(
66                                                 String.class) });
67                 system.initialize("root", new Service[0]);
68                 ServiceDescriptor[] required = system.getRequiredServices();
69                 assertEquals(1, required.length);
70                 ServiceDescriptor[] provided = system.getProvidedServices();
71                 assertEquals(0, provided.length);
72         }
73
74         public void testCompositeWithExternalDependencesNotProvided() {
75                 try {
76                         SubSystem environment = new Environment();
77                         SubSystem application = new Application();
78                         CompositeSystem system = new CompositeSystem("all",
79                                         new SubSystem[] { application }, new ServiceDescriptor[0],
80                                         application.getRequiredServices());
81                         system.initialize("root", new Service[0]);
82                 } catch (SystemAssemblyException e) {
83                         return;
84                 }
85                 fail();
86
87         }
88
89         public void testCompositeWithExternalDependencesProvided() {
90
91                 SubSystem environment = new Environment();
92                 SubSystem application = new Application();
93                 CompositeSystem system = new CompositeSystem("all",
94                                 new SubSystem[] { application }, new ServiceDescriptor[0],
95                                 application.getRequiredServices());
96                 Service[] envServices = environment.initialize("env", new Service[0]);
97                 system.initialize("root", envServices);
98                 ServiceDescriptor[] required = system.getRequiredServices();
99                 assertEquals(2, required.length);
100                 ServiceDescriptor[] provided = system.getProvidedServices();
101                 assertEquals(0, provided.length);
102
103         }
104
105 }