From 55962d29047c49a40aad45fdaeb79483e25a828d Mon Sep 17 00:00:00 2001 From: erik Date: Fri, 4 Apr 2008 18:52:29 +0000 Subject: [PATCH] Added missing test case. --- .../org/wamblee/system/AbstractComponent.java | 4 +- ...CompositeComponent.java => Container.java} | 16 ++-- .../java/org/wamblee/system/Application.java | 6 +- .../java/org/wamblee/system/Environment.java | 2 +- .../wamblee/system/SystemAssemblerTest.java | 78 ++++++++++++------- .../system/spring/SpringComponent.java | 6 +- 6 files changed, 67 insertions(+), 45 deletions(-) rename system/general/src/main/java/org/wamblee/system/{CompositeComponent.java => Container.java} (83%) diff --git a/system/general/src/main/java/org/wamblee/system/AbstractComponent.java b/system/general/src/main/java/org/wamblee/system/AbstractComponent.java index 47c82862..9354a5c3 100644 --- a/system/general/src/main/java/org/wamblee/system/AbstractComponent.java +++ b/system/general/src/main/java/org/wamblee/system/AbstractComponent.java @@ -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; diff --git a/system/general/src/main/java/org/wamblee/system/CompositeComponent.java b/system/general/src/main/java/org/wamblee/system/Container.java 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 7bc120aa..a80aa1a2 100644 --- a/system/general/src/main/java/org/wamblee/system/CompositeComponent.java +++ b/system/general/src/main/java/org/wamblee/system/Container.java @@ -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); } } diff --git a/system/general/src/test/java/org/wamblee/system/Application.java b/system/general/src/test/java/org/wamblee/system/Application.java index 47c92af8..0ebf0018 100644 --- a/system/general/src/test/java/org/wamblee/system/Application.java +++ b/system/general/src/test/java/org/wamblee/system/Application.java @@ -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 diff --git a/system/general/src/test/java/org/wamblee/system/Environment.java b/system/general/src/test/java/org/wamblee/system/Environment.java index 76d3a3c1..ebc43265 100644 --- a/system/general/src/test/java/org/wamblee/system/Environment.java +++ b/system/general/src/test/java/org/wamblee/system/Environment.java @@ -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 diff --git a/system/general/src/test/java/org/wamblee/system/SystemAssemblerTest.java b/system/general/src/test/java/org/wamblee/system/SystemAssemblerTest.java index ab8bae69..df08998e 100644 --- a/system/general/src/test/java/org/wamblee/system/SystemAssemblerTest.java +++ b/system/general/src/test/java/org/wamblee/system/SystemAssemblerTest.java @@ -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(); } - } diff --git a/system/spring/src/main/java/org/wamblee/system/spring/SpringComponent.java b/system/spring/src/main/java/org/wamblee/system/spring/SpringComponent.java index 633050cb..6f153e57 100644 --- a/system/spring/src/main/java/org/wamblee/system/spring/SpringComponent.java +++ b/system/spring/src/main/java/org/wamblee/system/spring/SpringComponent.java @@ -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 aProvided, Map 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; -- 2.31.1