Added missing test case.
authorerik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Fri, 4 Apr 2008 18:52:29 +0000 (18:52 +0000)
committererik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Fri, 4 Apr 2008 18:52:29 +0000 (18:52 +0000)
system/general/src/main/java/org/wamblee/system/AbstractComponent.java
system/general/src/main/java/org/wamblee/system/Container.java [moved from system/general/src/main/java/org/wamblee/system/CompositeComponent.java with 83% similarity]
system/general/src/test/java/org/wamblee/system/Application.java
system/general/src/test/java/org/wamblee/system/Environment.java
system/general/src/test/java/org/wamblee/system/SystemAssemblerTest.java
system/spring/src/main/java/org/wamblee/system/spring/SpringComponent.java

index 47c82862683bc08881b1f42caacdd483f6d11df2..9354a5c3f8dde26b52ec885c1fb67de039383cc5 100644 (file)
@@ -37,8 +37,8 @@ public abstract class AbstractComponent implements Component {
         * @param aRequired
         *            Required services.
         */
-       protected AbstractComponent(String aName, ServiceRegistry aRegistry, InterfaceDescriptor[] aProvided,
-                       InterfaceDescriptor[] aRequired) {
+       protected AbstractComponent(String aName, ServiceRegistry aRegistry, ProvidedInterfaceDescriptor[] aProvided,
+                       RequiredInterfaceDescriptor[] aRequired) {
                _status = Status.NOT_STARTED;
                _name = aName;
                _registry = aRegistry; 
similarity index 83%
rename from system/general/src/main/java/org/wamblee/system/CompositeComponent.java
rename to system/general/src/main/java/org/wamblee/system/Container.java
index 7bc120aaf3b8991f08b7b5ddac851bca8cc9d3f7..a80aa1a21f0c7136b2acd66d8c2b8f9eff6091bf 100644 (file)
@@ -14,9 +14,9 @@ import sun.util.LocaleServiceProviderPool.LocalizedObjectGetter;
  *
  * @author Erik Brakkee
  */
-public class CompositeComponent extends AbstractComponent {
+public class Container extends AbstractComponent {
 
-       private static final Log LOG = LogFactory.getLog(CompositeComponent.class);
+       private static final Log LOG = LogFactory.getLog(Container.class);
 
        private Component[] _systems;
 
@@ -28,8 +28,8 @@ public class CompositeComponent extends AbstractComponent {
         * @param aProvided Provided services of the system. 
         * @param aRequired Required services by the system. 
         */
-       public CompositeComponent(String aName, ServiceRegistry aRegistry, Component[] aSystems,
-                       InterfaceDescriptor[] aProvided, InterfaceDescriptor[] aRequired) {
+       public Container(String aName, ServiceRegistry aRegistry, Component[] aSystems,
+                       ProvidedInterfaceDescriptor[] aProvided, RequiredInterfaceDescriptor[] aRequired) {
                super(aName, aRegistry, aProvided, aRequired);
                _systems = aSystems;
                validate();
@@ -75,8 +75,12 @@ public class CompositeComponent extends AbstractComponent {
                for (InterfaceDescriptor service: getRequiredServices()) { 
                        reallyRequired.remove(service); 
                }
-               for (InterfaceDescriptor service: reallyRequired) { 
-                       throw new SystemAssemblyException(getName() + ": " + "Service '" + service + "' is not provided internally and is not indicated as required for this sub system");
+               String missingRequired = "";
+               for (InterfaceDescriptor service: reallyRequired) {
+                       missingRequired += service + "\n";
+               }
+               if ( missingRequired.length() > 0 ) { 
+                       throw new SystemAssemblyException(getName() + ": missing required services\n" + missingRequired);
                }
        }
 
index 47c92af88405a1edae2990ff5c4c350e4c826078..0ebf001841e0a588ef42397ab87a78eb0dc01b72 100644 (file)
@@ -3,14 +3,14 @@ package org.wamblee.system;
 import javax.sql.DataSource;
 
 public class Application extends AbstractComponent {
-       private static final InterfaceDescriptor[] REQUIRED = 
-               new InterfaceDescriptor[] { 
+       private static final RequiredInterfaceDescriptor[] REQUIRED = 
+               new RequiredInterfaceDescriptor[] { 
                        new DefaultRequiredInterfaceDescriptor("datasource", DataSource.class), 
                        new DefaultRequiredInterfaceDescriptor("integer", Integer.class)
        };
        
        public Application(ServiceRegistry aRegistry) {
-               super("application", aRegistry, new InterfaceDescriptor[0], REQUIRED); 
+               super("application", aRegistry, new ProvidedInterfaceDescriptor[0], REQUIRED); 
        }
 
        @Override
index 76d3a3c1bfbb9bf0d736eeab4a1b7b103084b07d..ebc432657c88c227197f1ec0fd46d92964adc64e 100644 (file)
@@ -12,7 +12,7 @@ public class Environment extends AbstractComponent {
        };
        
        public Environment(ServiceRegistry aRegistry) { 
-               super("environment", aRegistry, PROVIDED, new InterfaceDescriptor[0]);
+               super("environment", aRegistry, PROVIDED, new RequiredInterfaceDescriptor[0]);
        }
        
        @Override
index ab8bae6902debd4b49c16554c57345166f9f19fd..df08998e4b7351b2b1cd82963da44efa32b9b4e5 100644 (file)
@@ -42,21 +42,22 @@ public class SystemAssemblerTest extends TestCase {
                                SystemAssembler.filterRequiredServices(prov1, Arrays
                                                .asList(new RequiredInterfaceDescriptor[] { req1 })));
                AssertionUtils.assertEquals(new RequiredInterfaceDescriptor[] { req1 },
-                               SystemAssembler
-                                               .filterRequiredServices(prov1, Arrays
-                                                               .asList(new RequiredInterfaceDescriptor[] { req1,
-                                                                               req2 })));
+                               SystemAssembler.filterRequiredServices(prov1,
+                                               Arrays.asList(new RequiredInterfaceDescriptor[] { req1,
+                                                               req2 })));
                AssertionUtils.assertEquals(new RequiredInterfaceDescriptor[] { req1,
                                req2 }, SystemAssembler.filterRequiredServices(prov3, Arrays
                                .asList(new RequiredInterfaceDescriptor[] { req1, req2 })));
 
-               AssertionUtils.assertEquals(new ProvidedInterfaceDescriptor[] { prov1 },
+               AssertionUtils.assertEquals(
+                               new ProvidedInterfaceDescriptor[] { prov1 },
                                SystemAssembler.filterProvidedServices(req1, Arrays
                                                .asList(new ProvidedInterfaceDescriptor[] { prov1 })));
-               AssertionUtils.assertEquals(new ProvidedInterfaceDescriptor[] { prov1 },
-                               SystemAssembler.filterProvidedServices(req1,
-                                               Arrays.asList(new ProvidedInterfaceDescriptor[] { prov1,
-                                                               prov2 })));
+               AssertionUtils.assertEquals(
+                               new ProvidedInterfaceDescriptor[] { prov1 }, SystemAssembler
+                                               .filterProvidedServices(req1, Arrays
+                                                               .asList(new ProvidedInterfaceDescriptor[] {
+                                                                               prov1, prov2 })));
                AssertionUtils.assertEquals(new ProvidedInterfaceDescriptor[] { prov1,
                                prov3 }, SystemAssembler.filterProvidedServices(req1, Arrays
                                .asList(new ProvidedInterfaceDescriptor[] { prov1, prov3 })));
@@ -101,9 +102,9 @@ public class SystemAssemblerTest extends TestCase {
                Component application = new Application(_registry);
                assertEquals(Status.NOT_STARTED, environment.getStatus());
                assertEquals(Status.NOT_STARTED, application.getStatus());
-               CompositeComponent system = new CompositeComponent("all", _registry,
-                               new Component[] { environment, application },
-                               new InterfaceDescriptor[0], new InterfaceDescriptor[0]);
+               Container system = new Container("all", _registry, new Component[] {
+                               environment, application }, new ProvidedInterfaceDescriptor[0],
+                               new RequiredInterfaceDescriptor[0]);
                assertEquals(Status.NOT_STARTED, system.getStatus());
                system.start("root", new Service[0]);
                InterfaceDescriptor[] required = system.getRequiredServices();
@@ -113,7 +114,7 @@ public class SystemAssemblerTest extends TestCase {
                assertEquals(Status.RUNNING, environment.getStatus());
                assertEquals(Status.RUNNING, application.getStatus());
                assertEquals(Status.RUNNING, system.getStatus());
-               
+
                system.stop();
                assertEquals(Status.STOPPED, environment.getStatus());
                assertEquals(Status.STOPPED, application.getStatus());
@@ -124,11 +125,11 @@ public class SystemAssemblerTest extends TestCase {
                try {
                        Component environment = new Environment(_registry);
                        Component application = new Application(_registry);
-                       CompositeComponent system = new CompositeComponent(
+                       Container system = new Container(
                                        "all",
                                        _registry,
                                        new Component[] { environment, application },
-                                       new InterfaceDescriptor[] { new DefaultProvidedInterfaceDescriptor(
+                                       new ProvidedInterfaceDescriptor[] { new DefaultProvidedInterfaceDescriptor(
                                                        "string", String.class) },
                                        new DefaultRequiredInterfaceDescriptor[0]);
                } catch (SystemAssemblyException e) {
@@ -140,15 +141,17 @@ public class SystemAssemblerTest extends TestCase {
        public void testCompositeWithSuperfluousRequiredInfo() {
                Component environment = new Environment(_registry);
                Component application = new Application(_registry);
-               CompositeComponent system = new CompositeComponent("all", _registry,
+               Container system = new Container(
+                               "all",
+                               _registry,
                                new Component[] { environment, application },
-                               new InterfaceDescriptor[0],
-                               new InterfaceDescriptor[] { new DefaultRequiredInterfaceDescriptor(
+                               new ProvidedInterfaceDescriptor[0],
+                               new RequiredInterfaceDescriptor[] { new DefaultRequiredInterfaceDescriptor(
                                                "string", String.class) });
                system.start("root", new Service[0]);
-               InterfaceDescriptor[] required = system.getRequiredServices();
+               RequiredInterfaceDescriptor[] required = system.getRequiredServices();
                assertEquals(1, required.length);
-               InterfaceDescriptor[] provided = system.getProvidedServices();
+               ProvidedInterfaceDescriptor[] provided = system.getProvidedServices();
                assertEquals(0, provided.length);
        }
 
@@ -156,9 +159,10 @@ public class SystemAssemblerTest extends TestCase {
                try {
                        Component environment = new Environment(_registry);
                        Component application = new Application(_registry);
-                       CompositeComponent system = new CompositeComponent("all", _registry,
-                                       new Component[] { application }, new InterfaceDescriptor[0],
-                                       application.getRequiredServices());
+                       Container system = new Container("all", _registry,
+                                       new Component[] { application },
+                                       new ProvidedInterfaceDescriptor[0], application
+                                                       .getRequiredServices());
                        system.start("root", new Service[0]);
                } catch (SystemAssemblyException e) {
                        return;
@@ -171,14 +175,15 @@ public class SystemAssemblerTest extends TestCase {
 
                Component environment = new Environment(_registry);
                Component application = new Application(_registry);
-               CompositeComponent system = new CompositeComponent("all", _registry,
-                               new Component[] { application }, new InterfaceDescriptor[0],
-                               application.getRequiredServices());
+               Container system = new Container("all", _registry,
+                               new Component[] { application },
+                               new ProvidedInterfaceDescriptor[0], application
+                                               .getRequiredServices());
                Service[] envServices = environment.start("env", new Service[0]);
                system.start("root", envServices);
-               InterfaceDescriptor[] required = system.getRequiredServices();
+               RequiredInterfaceDescriptor[] required = system.getRequiredServices();
                assertEquals(2, required.length);
-               InterfaceDescriptor[] provided = system.getProvidedServices();
+               ProvidedInterfaceDescriptor[] provided = system.getProvidedServices();
                assertEquals(0, provided.length);
 
        }
@@ -192,12 +197,25 @@ public class SystemAssemblerTest extends TestCase {
                                        environment1, environment2, application },
                                        new ProvidedInterfaceDescriptor[0]);
                        assembler.start(_registry, new Service[0]);
-                       
+
+               } catch (SystemAssemblyException e) {
+                       return;
+               }
+               fail();
+       }
+
+       public void testIncompleteRequirements() {
+               try {
+                       Component application = new Application(_registry);
+                       Container system = new Container("all", _registry,
+                                       new Component[] { application },
+                                       new ProvidedInterfaceDescriptor[0],
+                                       new RequiredInterfaceDescriptor[0]);
+                       system.start("root", new Service[0]);
                } catch (SystemAssemblyException e) {
                        return;
                }
                fail();
        }
 
-       
 }
index 633050cbfecacee89b2cd5a723762ec8d520b970..6f153e5749ee7154c25e685e90f5bb68f0b6f099 100644 (file)
@@ -13,7 +13,7 @@ import org.springframework.context.support.AbstractApplicationContext;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 import org.springframework.context.support.GenericApplicationContext;
 import org.wamblee.system.AbstractComponent;
-import org.wamblee.system.CompositeComponent;
+import org.wamblee.system.Container;
 import org.wamblee.system.ProvidedInterfaceDescriptor;
 import org.wamblee.system.RequiredInterfaceDescriptor;
 import org.wamblee.system.Service;
@@ -69,8 +69,8 @@ public class SpringComponent extends AbstractComponent {
        public SpringComponent(String aName, ServiceRegistry aRegistry, String[] aConfigFiles,
                        Map<String, ProvidedInterfaceDescriptor> aProvided,
                        Map<RequiredInterfaceDescriptor, String> aRequired) {
-               super(aName, aRegistry, aProvided.values().toArray(new InterfaceDescriptor[0]),
-                               aRequired.keySet().toArray(new InterfaceDescriptor[0]));
+               super(aName, aRegistry, aProvided.values().toArray(new ProvidedInterfaceDescriptor[0]),
+                               aRequired.keySet().toArray(new RequiredInterfaceDescriptor[0]));
                _properties = new Properties(); 
                _configFiles = aConfigFiles;
                _provided = aProvided;