From 9f620f398d323e1e385d28d6a9630d2c406a3a19 Mon Sep 17 00:00:00 2001 From: erik Date: Fri, 6 Jun 2008 18:46:47 +0000 Subject: [PATCH] --- .../wamblee/system/container/Container.java | 24 ++- .../system/core/AbstractComponent.java | 43 ++++-- .../org/wamblee/system/core/Component.java | 6 +- .../org/wamblee/system/core/DefaultScope.java | 14 +- .../java/org/wamblee/system/core/Scope.java | 4 +- .../graph/component/ComponentGraph.java | 2 +- .../wamblee/system/container/Application.java | 139 +++++++++--------- .../system/container/ContainerTest.java | 64 ++++---- .../system/core/AbstractComponentTest.java | 8 +- .../org/wamblee/system/core/Environment.java | 2 +- .../wamblee/system/core/IntegerComponent.java | 2 +- .../wamblee/system/core/StringComponent.java | 2 +- ...xternalProvidedProvidedEdgeFilterTest.java | 2 +- ...uiredExternallyRequiredEdgeFilterTest.java | 2 +- ...ConnectRequiredProvidedEdgeFilterTest.java | 2 + .../system/spring/RequiredServiceBean.java | 4 +- .../system/spring/SpringComponent.java | 2 +- .../system/spring/SpringComponentTest.java | 25 ++-- 18 files changed, 199 insertions(+), 148 deletions(-) diff --git a/system/general/src/main/java/org/wamblee/system/container/Container.java b/system/general/src/main/java/org/wamblee/system/container/Container.java index fe744f74..60456c5e 100644 --- a/system/general/src/main/java/org/wamblee/system/container/Container.java +++ b/system/general/src/main/java/org/wamblee/system/container/Container.java @@ -16,6 +16,7 @@ package org.wamblee.system.container; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -63,7 +64,7 @@ public class Container extends AbstractComponent { * Required services by the container. */ public Container(String aName, Component[] aComponents, - ProvidedInterface[] aProvided, RequiredInterface[] aRequired) { + List aProvided, List aRequired) { super(aName, aProvided, aRequired); _components = new ArrayList(); @@ -74,6 +75,23 @@ public class Container extends AbstractComponent { addComponent(component); } } + + /** + * Constructs the container + * + * @param aName + * Name of the container + * @param aComponents + * Components. + * @param aProvided + * Provided services of the container + * @param aRequired + * Required services by the container. + */ + public Container(String aName, Component[] aComponents, + ProvidedInterface[] aProvided, RequiredInterface[] aRequired) { + this(aName, aComponents, Arrays.asList(aProvided), Arrays.asList(aRequired)); + } public Container(String aName) { this(aName, new Component[0], new ProvidedInterface[0], @@ -194,7 +212,7 @@ public class Container extends AbstractComponent { * @return Scope. */ public Scope start() { - Scope scope = new DefaultScope(getProvidedInterfaces().toArray()); + Scope scope = new DefaultScope(getProvidedInterfaces()); return super.start(scope); } @@ -202,7 +220,7 @@ public class Container extends AbstractComponent { protected Scope doStart(Scope aExternalScope) { checkSealed(); validate(); - Scope scope = new DefaultScope(getProvidedInterfaces().toArray(), aExternalScope); + Scope scope = new DefaultScope(getProvidedInterfaces().toArray(new ProvidedInterface[0]), aExternalScope); ComponentGraph graph = doStartOptionalDryRun(scope, false); exposeProvidedInterfaces(graph, aExternalScope, scope); seal(); diff --git a/system/general/src/main/java/org/wamblee/system/core/AbstractComponent.java b/system/general/src/main/java/org/wamblee/system/core/AbstractComponent.java index 31e50ed5..d2cf69fe 100644 --- a/system/general/src/main/java/org/wamblee/system/core/AbstractComponent.java +++ b/system/general/src/main/java/org/wamblee/system/core/AbstractComponent.java @@ -18,9 +18,7 @@ package org.wamblee.system.core; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; -import java.util.HashSet; import java.util.List; -import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -49,27 +47,40 @@ public abstract class AbstractComponent implements Component { * @param aRequired * Required services. */ - protected AbstractComponent(String aName, ProvidedInterface[] aProvided, - RequiredInterface[] aRequired) { + protected AbstractComponent(String aName, List aProvided, + List aRequired) { _remaining = new ThreadLocal>(); _context = null; _name = aName; - _provided = new ArrayList(); - _provided.addAll(Arrays.asList(aProvided)); - _required = new ArrayList(); - _required.addAll(Arrays.asList(aRequired)); + _provided = new ArrayList(aProvided); + _required = new ArrayList(aRequired); } + /** + * Constructs the subsystem. + * + * @param aName + * Name of the system. + * @param aProvided + * Provided services. + * @param aRequired + * Required services. + */ + protected AbstractComponent(String aName, ProvidedInterface[] aProvided, + RequiredInterface[] aRequired) { + this(aName, Arrays.asList(aProvided), Arrays.asList(aRequired)); + } + protected AbstractComponent(String aName) { this(aName, new ProvidedInterface[0], new RequiredInterface[0]); } - public AbstractComponent addProvidedInterface(ProvidedInterface aProvided) { + public AbstractComponent addProvidedInterface(ProvidedInterface aProvided) { _provided.add(aProvided); return this; } - public AbstractComponent addRequiredInterface(RequiredInterface aRequired) { + public AbstractComponent addRequiredInterface(RequiredInterface aRequired) { _required.add(aRequired); return this; } @@ -102,20 +113,20 @@ public abstract class AbstractComponent implements Component { } @Override - public final ProvidedInterfaces getProvidedInterfaces() { - return new ProvidedInterfaces(Collections.unmodifiableList(_provided)); + public final List getProvidedInterfaces() { + return Collections.unmodifiableList(_provided); } @Override - public final RequiredInterfaces getRequiredInterfaces() { - return new RequiredInterfaces(Collections.unmodifiableList(_required)); + public final List getRequiredInterfaces() { + return Collections.unmodifiableList(_required); } @Override public final Type start(Scope aScope) { LOG.info("Initialization starting '" + getQualifiedName() + "'"); List oldRemaining = _remaining.get(); - _remaining.set(new ArrayList(Arrays.asList(getProvidedInterfaces().toArray()))); + _remaining.set(new ArrayList(getProvidedInterfaces())); try { Type runtime = doStart(aScope); checkNotStartedInterfaces(); @@ -139,7 +150,7 @@ public abstract class AbstractComponent implements Component { /** * Must be implemented for initializing the subsystem. The implementation - * must call {@link #addService(Service)} for each service that is started. + * must call {@link #addInterface(ProvidedInterface, Object, Scope)} for each service that is started. * * @return Returns the runtime of the component. */ diff --git a/system/general/src/main/java/org/wamblee/system/core/Component.java b/system/general/src/main/java/org/wamblee/system/core/Component.java index 49ed1c7d..9506bb1f 100644 --- a/system/general/src/main/java/org/wamblee/system/core/Component.java +++ b/system/general/src/main/java/org/wamblee/system/core/Component.java @@ -15,6 +15,8 @@ */ package org.wamblee.system.core; +import java.util.List; + /** * A component represents a part of a system that requires a * number of interfaces and provides a number of interfaces. @@ -60,13 +62,13 @@ public interface Component { * Gets a description of the provided interfaces. * @return Provided interfaces. */ - ProvidedInterfaces getProvidedInterfaces(); + List getProvidedInterfaces(); /** * Gets a description of the required interfaces. * @return Required interfaces. */ - RequiredInterfaces getRequiredInterfaces(); + List getRequiredInterfaces(); /** diff --git a/system/general/src/main/java/org/wamblee/system/core/DefaultScope.java b/system/general/src/main/java/org/wamblee/system/core/DefaultScope.java index 7290a790..ad4b0986 100644 --- a/system/general/src/main/java/org/wamblee/system/core/DefaultScope.java +++ b/system/general/src/main/java/org/wamblee/system/core/DefaultScope.java @@ -17,6 +17,7 @@ package org.wamblee.system.core; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -29,7 +30,11 @@ public class DefaultScope implements Scope { private Map _properties; private Map _runtimes; private Map _provided; - private ProvidedInterface[] _externallyProvided; + private List _externallyProvided; + + public DefaultScope(ListaExternallyProvided) { + this(aExternallyProvided.toArray(new ProvidedInterface[0])); + } public DefaultScope(ProvidedInterface[] aExternallyProvided) { this(aExternallyProvided, new ArrayList()); @@ -45,12 +50,13 @@ public class DefaultScope implements Scope { _properties = new HashMap(); _runtimes = new HashMap(); _provided = new HashMap(); - _externallyProvided = aExternallyProvided; + _externallyProvided = new ArrayList(); + _externallyProvided.addAll(Arrays.asList(aExternallyProvided)); } @Override - public ProvidedInterface[] getProvidedInterfaces() { - return _externallyProvided; + public List getProvidedInterfaces() { + return Collections.unmodifiableList(_externallyProvided); } @Override diff --git a/system/general/src/main/java/org/wamblee/system/core/Scope.java b/system/general/src/main/java/org/wamblee/system/core/Scope.java index 4f26f53d..1b9f6615 100644 --- a/system/general/src/main/java/org/wamblee/system/core/Scope.java +++ b/system/general/src/main/java/org/wamblee/system/core/Scope.java @@ -15,6 +15,8 @@ */ package org.wamblee.system.core; +import java.util.List; + /** * A scope represents a set of running services and the runtime information for the * started components and is (usually) the result of @@ -28,7 +30,7 @@ public interface Scope { * Gets the provided interfaces by this scope. * @return Provided interfaces. */ - ProvidedInterface[] getProvidedInterfaces(); + List getProvidedInterfaces(); /** * Adds a key value pair to the scope. diff --git a/system/general/src/main/java/org/wamblee/system/graph/component/ComponentGraph.java b/system/general/src/main/java/org/wamblee/system/graph/component/ComponentGraph.java index aedaa0c3..008f0026 100644 --- a/system/general/src/main/java/org/wamblee/system/graph/component/ComponentGraph.java +++ b/system/general/src/main/java/org/wamblee/system/graph/component/ComponentGraph.java @@ -111,7 +111,7 @@ public class ComponentGraph extends Graph { * provided interfaces. * @param aComponent Component to add. */ - public void addComponent(Component aComponent) { + public void addComponent(Component aComponent) { // Add required interfaces. Node compNode = new ComponentNode(aComponent); List requiredNodes = new ArrayList(); diff --git a/system/general/src/test/java/org/wamblee/system/container/Application.java b/system/general/src/test/java/org/wamblee/system/container/Application.java index 56c267fe..58dcba60 100644 --- a/system/general/src/test/java/org/wamblee/system/container/Application.java +++ b/system/general/src/test/java/org/wamblee/system/container/Application.java @@ -12,9 +12,13 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ + */ package org.wamblee.system.container; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + import org.wamblee.system.core.AbstractComponent; import org.wamblee.system.core.DefaultRequiredInterface; import org.wamblee.system.core.ProvidedInterface; @@ -22,76 +26,79 @@ import org.wamblee.system.core.RequiredInterface; import org.wamblee.system.core.Scope; import org.wamblee.test.EventTracker; -public class Application extends AbstractComponent { - public static RequiredInterface[] required(boolean aOptional, String aPrefix) { - return - new RequiredInterface[] { - new DefaultRequiredInterface(aPrefix + "string", String.class, aOptional), - new DefaultRequiredInterface(aPrefix + "integer", Integer.class, aOptional) - }; - } - - public static RequiredInterface[] required(boolean aOptional) { +public class Application extends AbstractComponent { + public static RequiredInterface[] required(boolean aOptional, + String aPrefix) { + return new RequiredInterface[] { + new DefaultRequiredInterface(aPrefix + "string", String.class, + aOptional), + new DefaultRequiredInterface(aPrefix + "integer", + Integer.class, aOptional) }; + } + + public static RequiredInterface[] required(boolean aOptional) { return required(aOptional, ""); } - - private EventTracker _tracker; - private String _string; - private Integer _integer; - private double _random; - - public Application() { - this("application"); - } - - public Application(String aName) { - this(aName, ""); + private EventTracker _tracker; + private String _string; + private Integer _integer; + private double _random; + + public Application() { + this("application"); + } + + public Application(String aName) { + this(aName, ""); } - - public Application(String aName, String aPrefix) { - super(aName, new ProvidedInterface[0], required(false, aPrefix)); + + public Application(String aName, String aPrefix) { + super(aName, new ProvidedInterface[0], required(false, + aPrefix)); _random = Math.random(); } - - public Application(boolean aIsOptinal) { - super("application", new ProvidedInterface[0], required(true, "")); - } - - public Application(EventTracker aTracker) { - this(); - _tracker = aTracker; - } - @Override - public Object doStart(Scope aScope) { - track("start." + getName()); - _string = aScope.getInterfaceImplementation(getRequiredInterfaces().get(0).getProvider(), String.class); - _integer = aScope.getInterfaceImplementation(getRequiredInterfaces().get(1).getProvider(), Integer.class); - return _random; - } - - public String getString() { - return _string; - } - - public Integer getInteger() { - return _integer; - } - - @Override - public void doStop(Object aRuntime) { - track("stop." + getName()); - if ( _random != (Double)aRuntime) { - throw new IllegalArgumentException("Wrong runtime: expected " + _random + " but got " + - aRuntime); - } - } - - private void track(String aString) { - if ( _tracker == null ) { - return; - } - _tracker.eventOccurred(aString); - } + public Application(boolean aIsOptinal) { + super("application", new ProvidedInterface[0], required(true, "")); + } + + public Application(EventTracker aTracker) { + this(); + _tracker = aTracker; + } + + @Override + public Object doStart(Scope aScope) { + track("start." + getName()); + _string = aScope.getInterfaceImplementation(getRequiredInterfaces() + .get(0).getProvider(), String.class); + _integer = aScope.getInterfaceImplementation(getRequiredInterfaces() + .get(1).getProvider(), Integer.class); + return _random; + } + + public String getString() { + return _string; + } + + public Integer getInteger() { + return _integer; + } + + @Override + public void doStop(Object aRuntime) { + track("stop." + getName()); + if (_random != (Double) aRuntime) { + throw new IllegalArgumentException("Wrong runtime: expected " + + _random + " but got " + aRuntime); + } + } + + private void track(String aString) { + if (_tracker == null) { + return; + } + _tracker.eventOccurred(aString); + } } diff --git a/system/general/src/test/java/org/wamblee/system/container/ContainerTest.java b/system/general/src/test/java/org/wamblee/system/container/ContainerTest.java index 5da0f025..8cd119f3 100644 --- a/system/general/src/test/java/org/wamblee/system/container/ContainerTest.java +++ b/system/general/src/test/java/org/wamblee/system/container/ContainerTest.java @@ -79,7 +79,7 @@ public class ContainerTest extends TestCase { AssertionUtils.assertEquals(new String[] { "start.environment", "start.application" }, _tracker.getEvents( Thread.currentThread()).toArray(new String[0])); - assertEquals(0, scope.getProvidedInterfaces().length); + assertEquals(0, scope.getProvidedInterfaces().size()); assertEquals(environment.getString(), application.getString()); assertEquals(environment.getInteger(), application.getInteger()); @@ -96,7 +96,7 @@ public class ContainerTest extends TestCase { AssertionUtils.assertEquals(new String[] { "start.environment", "start.application" }, _tracker.getEvents( Thread.currentThread()).toArray(new String[0])); - assertEquals(0, scope.getProvidedInterfaces().length); + assertEquals(0, scope.getProvidedInterfaces().size()); assertEquals(environment.getString(), application.getString()); assertEquals(environment.getInteger(), application.getInteger()); @@ -105,8 +105,8 @@ public class ContainerTest extends TestCase { public void testApplicationEnvironment() { try { - Component environment = new Environment(); - Component application = new Application(); + Component environment = new Environment(); + Component application = new Application(); Container container = new Container("root", new Component[] { application, environment }, new ProvidedInterface[0], new RequiredInterface[0]); @@ -119,17 +119,17 @@ public class ContainerTest extends TestCase { } public void testComposite() { - Component environment = new Environment(_tracker); - Component application = new Application(_tracker); + Component environment = new Environment(_tracker); + Component application = new Application(_tracker); assertEquals(0, _tracker.getEventCount()); Container system = new Container("all", new Component[] { environment, application }, new ProvidedInterface[0], new RequiredInterface[0]); Scope runtime = system.start(); - RequiredInterfaces required = system.getRequiredInterfaces(); + List required = system.getRequiredInterfaces(); assertEquals(0, required.size()); - ProvidedInterfaces provided = system.getProvidedInterfaces(); + List provided = system.getProvidedInterfaces(); assertEquals(0, provided.size()); AssertionUtils.assertEquals(new String[] { "start.environment", @@ -146,8 +146,8 @@ public class ContainerTest extends TestCase { public void testCompositeWithWrongProvidedInfo() { try { - Component environment = new Environment(); - Component application = new Application(); + Component environment = new Environment(); + Component application = new Application(); Container system = new Container("all", new Component[] { environment, application }, new ProvidedInterface[] { new DefaultProvidedInterface( @@ -162,8 +162,8 @@ public class ContainerTest extends TestCase { public void testCompositeRequiredInterfaceNotProvided() { try { - Component environment = new Environment(); - Component application = new Application(); + Component environment = new Environment(); + Component application = new Application(); Container system = new Container("all", new Component[] { environment, application }, new ProvidedInterface[0], new RequiredInterface[] { new DefaultRequiredInterface( @@ -176,8 +176,8 @@ public class ContainerTest extends TestCase { } public void testCompositeWithSuperfluousRequiredInfo() { - Component environment = new Environment(); - Component application = new Application(); + Component environment = new Environment(); + Component application = new Application(); Container system = new Container("all", new Component[] { environment, application }, new ProvidedInterface[0], new RequiredInterface[] { new DefaultRequiredInterface("float", @@ -185,19 +185,19 @@ public class ContainerTest extends TestCase { system.getRequiredInterfaces().get(0) .setProvider(new DefaultProvidedInterface("hallo", Float.class)); system.start(); - RequiredInterfaces required = system.getRequiredInterfaces(); + List required = system.getRequiredInterfaces(); assertEquals(1, required.size()); - ProvidedInterfaces provided = system.getProvidedInterfaces(); + List provided = system.getProvidedInterfaces(); assertEquals(0, provided.size()); } public void testCompositeWithExternalDependencesNotProvided() { try { - Component environment = new Environment(); - Component application = new Application(); + Component application = new Application(); + Container system = new Container("all", new Component[] { application }, new ProvidedInterface[0], - application.getRequiredInterfaces().toArray()); + application.getRequiredInterfaces().toArray(new RequiredInterface[0])); system.start(); } catch (SystemAssemblyException e) { return; @@ -207,8 +207,8 @@ public class ContainerTest extends TestCase { public void testDuplicateComponent() { try { - Component comp1 = new Application(); - Component comp2 = new Application(); + Component comp1 = new Application(); + Component comp2 = new Application(); Container system = new Container("top"); system.addComponent(comp1).addComponent(comp2); } catch (SystemAssemblyException e) { @@ -220,7 +220,7 @@ public class ContainerTest extends TestCase { public void testInconsistentHierarchy() { try { - Component comp = new Application(); + Component comp = new Application(); Container system = new Container("top").addComponent(comp); Container system2 = new Container("top2").addComponent(comp); } catch (SystemAssemblyException e) { @@ -231,11 +231,11 @@ public class ContainerTest extends TestCase { public void testCompositeWithExternalDependencesProvided() { - Component environment = new Environment(); - Component application = new Application(); + Component environment = new Environment(); + Component application = new Application(); Container system = new Container("all", new Component[] { application }, new ProvidedInterface[0], - application.getRequiredInterfaces().toArray()); + application.getRequiredInterfaces().toArray(new RequiredInterface[0])); environment.start(new DefaultScope(new ProvidedInterface[0])); system.getRequiredInterfaces().get(0).setProvider(environment .getProvidedInterfaces().get(0)); @@ -243,18 +243,18 @@ public class ContainerTest extends TestCase { .getProvidedInterfaces().get(1)); system.start(); - RequiredInterfaces required = system.getRequiredInterfaces(); + List required = system.getRequiredInterfaces(); assertEquals(2, required.size()); - ProvidedInterfaces provided = system.getProvidedInterfaces(); + List provided = system.getProvidedInterfaces(); assertEquals(0, provided.size()); } public void testAmbiguousInterfaces() { try { - Component environment1 = new Environment(); - Component environment2 = new Environment(); - Component application = new Application(); + Component environment1 = new Environment(); + Component environment2 = new Environment(); + Component application = new Application(); Container container = new Container("root", new Component[] { environment1, environment2, application }, new ProvidedInterface[0], new RequiredInterface[0]); @@ -268,7 +268,7 @@ public class ContainerTest extends TestCase { public void testIncompleteRequirements() { try { - Component application = new Application(); + Component application = new Application(); Container system = new Container("all", new Component[] { application }, new ProvidedInterface[0], new RequiredInterface[0]); @@ -356,7 +356,7 @@ public class ContainerTest extends TestCase { .getProvidedInterfaces().get(0)); container.getRequiredInterfaces().get(1).setProvider(env .getProvidedInterfaces().get(1)); - Scope external = new DefaultScope(env.getProvidedInterfaces().toArray()); + Scope external = new DefaultScope(env.getProvidedInterfaces()); env.start(external); container.start(external); diff --git a/system/general/src/test/java/org/wamblee/system/core/AbstractComponentTest.java b/system/general/src/test/java/org/wamblee/system/core/AbstractComponentTest.java index 3b1b7d37..2fd48f6e 100644 --- a/system/general/src/test/java/org/wamblee/system/core/AbstractComponentTest.java +++ b/system/general/src/test/java/org/wamblee/system/core/AbstractComponentTest.java @@ -21,7 +21,7 @@ public class AbstractComponentTest extends TestCase { public void testNotAllInterfacesStarted() { try { - Component component = new AbstractComponent("xx", + Component component = new AbstractComponent("xx", new ProvidedInterface[] { new DefaultProvidedInterface( "xxx", String.class) }, new RequiredInterface[0]) { @Override @@ -35,7 +35,7 @@ public class AbstractComponentTest extends TestCase { // Empty. } }; - component.start(new DefaultScope(component.getProvidedInterfaces().toArray())); + component.start(new DefaultScope(component.getProvidedInterfaces())); } catch (SystemAssemblyException e) { //e.printStackTrace(); return; @@ -45,7 +45,7 @@ public class AbstractComponentTest extends TestCase { public void testUnexpectedServicesStarted() { try { - Component component = new AbstractComponent("xx", + Component component = new AbstractComponent("xx", new ProvidedInterface[0], new RequiredInterface[0]) { @Override protected Object doStart(Scope aScope) { @@ -58,7 +58,7 @@ public class AbstractComponentTest extends TestCase { // Empty. } }; - component.start(new DefaultScope(component.getProvidedInterfaces().toArray())); + component.start(new DefaultScope(component.getProvidedInterfaces())); } catch (SystemAssemblyException e) { //e.printStackTrace(); return; diff --git a/system/general/src/test/java/org/wamblee/system/core/Environment.java b/system/general/src/test/java/org/wamblee/system/core/Environment.java index c1e72ac4..d2c05271 100644 --- a/system/general/src/test/java/org/wamblee/system/core/Environment.java +++ b/system/general/src/test/java/org/wamblee/system/core/Environment.java @@ -23,7 +23,7 @@ import org.wamblee.system.core.ProvidedInterface; import org.wamblee.system.core.RequiredInterface; import org.wamblee.test.EventTracker; -public class Environment extends AbstractComponent { +public class Environment extends AbstractComponent { private static final ProvidedInterface[] provided(String aPrefix) { return new ProvidedInterface[] { diff --git a/system/general/src/test/java/org/wamblee/system/core/IntegerComponent.java b/system/general/src/test/java/org/wamblee/system/core/IntegerComponent.java index 547f831d..acf683fe 100644 --- a/system/general/src/test/java/org/wamblee/system/core/IntegerComponent.java +++ b/system/general/src/test/java/org/wamblee/system/core/IntegerComponent.java @@ -23,7 +23,7 @@ import org.wamblee.system.core.ProvidedInterface; import org.wamblee.system.core.RequiredInterface; import org.wamblee.test.EventTracker; -public class IntegerComponent extends AbstractComponent { +public class IntegerComponent extends AbstractComponent { private static final ProvidedInterface[] provided(String aPrefix) { return new ProvidedInterface[] { diff --git a/system/general/src/test/java/org/wamblee/system/core/StringComponent.java b/system/general/src/test/java/org/wamblee/system/core/StringComponent.java index c47112aa..7701c20b 100644 --- a/system/general/src/test/java/org/wamblee/system/core/StringComponent.java +++ b/system/general/src/test/java/org/wamblee/system/core/StringComponent.java @@ -23,7 +23,7 @@ import org.wamblee.system.core.ProvidedInterface; import org.wamblee.system.core.RequiredInterface; import org.wamblee.test.EventTracker; -public class StringComponent extends AbstractComponent { +public class StringComponent extends AbstractComponent { private static final ProvidedInterface[] provided(String aPrefix) { return new ProvidedInterface[] { diff --git a/system/general/src/test/java/org/wamblee/system/graph/component/ConnectExternalProvidedProvidedEdgeFilterTest.java b/system/general/src/test/java/org/wamblee/system/graph/component/ConnectExternalProvidedProvidedEdgeFilterTest.java index 2adea27b..32879657 100644 --- a/system/general/src/test/java/org/wamblee/system/graph/component/ConnectExternalProvidedProvidedEdgeFilterTest.java +++ b/system/general/src/test/java/org/wamblee/system/graph/component/ConnectExternalProvidedProvidedEdgeFilterTest.java @@ -32,7 +32,7 @@ import org.wamblee.system.graph.Node; public class ConnectExternalProvidedProvidedEdgeFilterTest extends TestCase { private Container _container; - private Component _internal; + private Component _internal; private String _externalInterfaceName; private String _internalComponentName; private String _internalInterfaceName; diff --git a/system/general/src/test/java/org/wamblee/system/graph/component/ConnectRequiredExternallyRequiredEdgeFilterTest.java b/system/general/src/test/java/org/wamblee/system/graph/component/ConnectRequiredExternallyRequiredEdgeFilterTest.java index 55d6d890..4f30b538 100644 --- a/system/general/src/test/java/org/wamblee/system/graph/component/ConnectRequiredExternallyRequiredEdgeFilterTest.java +++ b/system/general/src/test/java/org/wamblee/system/graph/component/ConnectRequiredExternallyRequiredEdgeFilterTest.java @@ -30,7 +30,7 @@ import junit.framework.TestCase; public class ConnectRequiredExternallyRequiredEdgeFilterTest extends TestCase { - private Component _comp; + private Component _comp; private Container _container; private Edge _edge; diff --git a/system/general/src/test/java/org/wamblee/system/graph/component/ConnectRequiredProvidedEdgeFilterTest.java b/system/general/src/test/java/org/wamblee/system/graph/component/ConnectRequiredProvidedEdgeFilterTest.java index ac43c9d0..0cb9013b 100644 --- a/system/general/src/test/java/org/wamblee/system/graph/component/ConnectRequiredProvidedEdgeFilterTest.java +++ b/system/general/src/test/java/org/wamblee/system/graph/component/ConnectRequiredProvidedEdgeFilterTest.java @@ -41,6 +41,8 @@ public class ConnectRequiredProvidedEdgeFilterTest extends TestCase { private void compare(Boolean[] aExpected, EdgeFilter aRestriction) { List result = new ArrayList(); + + // order will be: // env1, app1 // env1, app2 diff --git a/system/spring/src/main/java/org/wamblee/system/spring/RequiredServiceBean.java b/system/spring/src/main/java/org/wamblee/system/spring/RequiredServiceBean.java index abd5115e..2a349208 100644 --- a/system/spring/src/main/java/org/wamblee/system/spring/RequiredServiceBean.java +++ b/system/spring/src/main/java/org/wamblee/system/spring/RequiredServiceBean.java @@ -15,6 +15,8 @@ */ package org.wamblee.system.spring; +import java.util.List; + import org.springframework.beans.factory.FactoryBean; import org.wamblee.system.core.ProvidedInterface; import org.wamblee.system.core.RequiredInterface; @@ -36,7 +38,7 @@ class RequiredServiceBean implements FactoryBean { * @param aId Id of the bean in the service registry. */ public RequiredServiceBean(String aId) { - RequiredInterfaces required = SpringComponent.THIS.get().getRequiredInterfaces(); + List required = SpringComponent.THIS.get().getRequiredInterfaces(); for ( RequiredInterface intf: required) { if ( intf.getName().equals(aId)) { _required = intf; 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 c1e3a7b3..88746a5e 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 @@ -113,7 +113,7 @@ public class SpringComponent extends AbstractComponent { SpringComponent old = THIS.get(); Scope oldScope = SCOPE.get(); THIS.set(this); - Scope scope = new DefaultScope(getProvidedInterfaces().toArray(), aExternalScope); + Scope scope = new DefaultScope(getProvidedInterfaces().toArray(new ProvidedInterface[0]), aExternalScope); SCOPE.set(scope); try { GenericApplicationContext parentContext = new GenericApplicationContext(); diff --git a/system/spring/src/test/java/org/wamblee/system/spring/SpringComponentTest.java b/system/spring/src/test/java/org/wamblee/system/spring/SpringComponentTest.java index 67ed048d..1cc95c11 100644 --- a/system/spring/src/test/java/org/wamblee/system/spring/SpringComponentTest.java +++ b/system/spring/src/test/java/org/wamblee/system/spring/SpringComponentTest.java @@ -17,6 +17,7 @@ package org.wamblee.system.spring; import java.io.IOException; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Properties; @@ -59,7 +60,7 @@ public class SpringComponentTest extends TestCase { new HashMap()); Scope runtime = system.start(_externalScope); - assertEquals(0, _externalScope.getProvidedInterfaces().length); + assertEquals(0, _externalScope.getProvidedInterfaces().size()); system.stop(runtime); } @@ -73,10 +74,10 @@ public class SpringComponentTest extends TestCase { new String[] { HELLO_SERVICE_SPRING_XML }, provided, new HashMap()); Scope runtime = system.start(_externalScope); - ProvidedInterface[] services = runtime.getProvidedInterfaces(); + List services = runtime.getProvidedInterfaces(); - assertEquals(1, services.length); - Object service = runtime.getInterfaceImplementation(services[0], + assertEquals(1, services.size()); + Object service = runtime.getInterfaceImplementation(services.get(0), Object.class); assertTrue(service instanceof HelloService); @@ -106,9 +107,9 @@ public class SpringComponentTest extends TestCase { // unprocessed property // and another time with the processed property. assertEquals(1, EVENT_TRACKER.getEventCount()); - ProvidedInterface[] services = scope.getProvidedInterfaces(); + List services = scope.getProvidedInterfaces(); assertEquals("Property Value", scope.getInterfaceImplementation( - services[0], HelloService.class).say()); + services.get(0), HelloService.class).say()); } public void testWithPropertiesAsBean() throws IOException { @@ -124,9 +125,9 @@ public class SpringComponentTest extends TestCase { Scope scope = system.start(_externalScope); - ProvidedInterface[] services = scope.getProvidedInterfaces(); + List services = scope.getProvidedInterfaces(); - Properties props2 = scope.getInterfaceImplementation(services[0], + Properties props2 = scope.getInterfaceImplementation(services.get(0), HelloService2.class).getProperties(); assertEquals(props, props2); } @@ -183,7 +184,7 @@ public class SpringComponentTest extends TestCase { scope.publishInterface(helloService, helloObject); system.getRequiredInterfaces().get(0).setProvider(helloService); Scope runtime = system.start(scope); - ProvidedInterface started = runtime.getProvidedInterfaces()[0]; + ProvidedInterface started = runtime.getProvidedInterfaces().get(0); Object impl = runtime.getInterfaceImplementation(started, BlaService.class); @@ -208,10 +209,10 @@ public class SpringComponentTest extends TestCase { new HashMap()); Scope runtime = system.start(_externalScope); - ProvidedInterface[] services = runtime.getProvidedInterfaces(); + List services = runtime.getProvidedInterfaces(); - assertEquals(2, services.length); - Object service = runtime.getInterfaceImplementation(services[0], + assertEquals(2, services.size()); + Object service = runtime.getInterfaceImplementation(services.get(0), Object.class); assertTrue(service instanceof HelloService); -- 2.31.1