1 package org.wamblee.system;
3 import junit.framework.TestCase;
5 public class SystemAssemblerTest extends TestCase {
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);
19 public void testApplicationEnvironment() {
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();
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);
46 public void testCompositeWithWrongProvidedInfo() {
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) {
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(
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);
74 public void testCompositeWithExternalDependencesNotProvided() {
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) {
89 public void testCompositeWithExternalDependencesProvided() {
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);