diff options
Diffstat (limited to '')
2 files changed, 41 insertions, 0 deletions
diff --git a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java index febf4033e8..f162b73f0b 100644 --- a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java +++ b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java @@ -19,6 +19,7 @@ package org.apache.tuscany.sca.node.impl; +import java.util.ArrayList; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; @@ -27,10 +28,13 @@ import org.apache.tuscany.sca.assembly.Component; import org.apache.tuscany.sca.assembly.ComponentService; import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.assembly.CompositeService; +import org.apache.tuscany.sca.assembly.Endpoint2; +import org.apache.tuscany.sca.assembly.Service; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.UtilityExtensionPoint; import org.apache.tuscany.sca.core.assembly.ActivationException; import org.apache.tuscany.sca.core.assembly.CompositeActivator; +import org.apache.tuscany.sca.core.assembly.impl.RuntimeComponentServiceImpl; import org.apache.tuscany.sca.core.invocation.ProxyFactory; import org.apache.tuscany.sca.node.Client; import org.apache.tuscany.sca.node.Node; @@ -200,5 +204,29 @@ public class NodeImpl implements Node, Client { public ExtensionPointRegistry getExtensionPoints() { return manager.getExtensionPoints(); } + + /** + * Get the service endpoints in this Node + * TODO: needs review, works for the very simple testcase but i expect there are + * other endpoints to be included + */ + public List<Endpoint2> getServiceEndpoints() { + List<Endpoint2> endpoints = new ArrayList<Endpoint2>(); + if (compositeActivator != null) { + Composite domainComposite = compositeActivator.getDomainComposite(); + if (domainComposite != null) { + for (Composite composite : domainComposite.getIncludes()) { + for (Component component : composite.getComponents()) { + for (Service service : component.getServices()) { + if (service instanceof RuntimeComponentServiceImpl) { + endpoints.addAll(((RuntimeComponentServiceImpl)service).getEndpoints()); + } + } + } + } + } + } + return endpoints; + } } diff --git a/java/sca/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java b/java/sca/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java index da869e78e6..e24bd73d5e 100644 --- a/java/sca/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java +++ b/java/sca/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java @@ -23,7 +23,9 @@ import hello.HelloWorld; import java.io.File; import java.io.StringReader; +import java.util.List; +import org.apache.tuscany.sca.assembly.Endpoint2; import org.apache.tuscany.sca.node.Contribution; import org.apache.tuscany.sca.node.Node; import org.apache.tuscany.sca.node.NodeFactory; @@ -75,6 +77,17 @@ public class NodeImplTestCase { testNode(new NodeFactoryImpl().createNode()); } + @Test + public void testGetServiceEndpoints() { + NodeFactory factory = new NodeFactoryImpl(); + Contribution contribution = new Contribution("c1", new File("target/test-classes").toURI().toString()); + NodeImpl node = (NodeImpl)factory.createNode(new StringReader(composite), contribution); + node.start(); + List<Endpoint2> endpoints = node.getServiceEndpoints(); + Assert.assertEquals(1, endpoints.size()); + Assert.assertEquals("/HelloWorld2", endpoints.get(0).getBinding().getURI()); + } + private void testNode(Node node) { node.start(); HelloWorld hw = node.getService(HelloWorld.class, "HelloWorld"); |