+package org.wamblee.system;
+
+import junit.framework.TestCase;
+
+public class SystemAssemblerTest extends TestCase {
+
+ public void testEnvironmentApplication() {
+ SubSystem environment = new Environment();
+ SubSystem application = new Application();
+ SystemAssembler assembler = new SystemAssembler(new SubSystem[] {
+ environment, application }, new ServiceDescriptor[0]);
+ assembler.start(new Service[0]);
+ Service[] envServices = environment.getRunningServices();
+ assertEquals(2, envServices.length);
+ Service[] appServices = environment.getRunningServices();
+ assertEquals(2, appServices.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(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.initialize("root", 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.initialize("root", 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.initialize("root", 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.initialize("env", new Service[0]);
+ system.initialize("root", envServices);
+ ServiceDescriptor[] required = system.getRequiredServices();
+ assertEquals(2, required.length);
+ ServiceDescriptor[] provided = system.getProvidedServices();
+ assertEquals(0, provided.length);
+
+ }
+
+}