summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk
diff options
context:
space:
mode:
Diffstat (limited to 'sca-java-2.x/trunk')
-rw-r--r--sca-java-2.x/trunk/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java11
-rw-r--r--sca-java-2.x/trunk/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java61
-rw-r--r--sca-java-2.x/trunk/modules/node-impl/src/test/resources/test.properties2
3 files changed, 72 insertions, 2 deletions
diff --git a/sca-java-2.x/trunk/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java b/sca-java-2.x/trunk/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java
index 3b98588e65..d8da3b3cc7 100644
--- a/sca-java-2.x/trunk/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java
+++ b/sca-java-2.x/trunk/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java
@@ -99,8 +99,7 @@ public class NodeFactoryImpl extends NodeFactory {
protected ExtensionPointRegistry registry;
protected ProxyFactory proxyFactory;
protected MonitorFactory monitorFactory;
-
-
+
/**
* Automatically destroy the factory when last node is stopped. Subclasses
* can set this flag.
@@ -471,6 +470,14 @@ public class NodeFactoryImpl extends NodeFactory {
for (Map.Entry<String, Map<String, String>> e : attributes.entrySet()) {
discovery.setAttribute(e.getKey(), e.getValue());
}
+ for (Object o : properties.keySet()) {
+ String p = (String) o;
+ if (p.indexOf('.') > -1) {
+ String serviceType = p.substring(0, p.lastIndexOf('.'));
+ String attribute = p.substring(p.lastIndexOf('.')+1);
+ discovery.setAttribute(serviceType, attribute, properties.getProperty(p));
+ }
+ }
super.configure(attributes);
}
diff --git a/sca-java-2.x/trunk/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java b/sca-java-2.x/trunk/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java
index 126340891e..46fae2fabc 100644
--- a/sca-java-2.x/trunk/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java
+++ b/sca-java-2.x/trunk/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java
@@ -30,14 +30,18 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Properties;
import org.apache.tuscany.sca.assembly.Endpoint;
import org.apache.tuscany.sca.contribution.processor.ValidationSchemaExtensionPoint;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
import org.apache.tuscany.sca.extensibility.ServiceDeclarationParser;
+import org.apache.tuscany.sca.monitor.MonitorFactory;
import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.apache.tuscany.sca.runtime.DomainRegistryFactoryExtensionPoint;
+import org.apache.tuscany.sca.runtime.RuntimeProperties;
import org.junit.Assert;
import org.junit.Test;
@@ -146,6 +150,63 @@ public class NodeImplTestCase {
}
@Test
+ public void testNodeFactoryProperties() throws Exception {
+ NodeFactoryImpl factory = (NodeFactoryImpl)NodeFactory.newInstance();
+ factory.init();
+ UtilityExtensionPoint utilities = factory.getExtensionPointRegistry().getExtensionPoint(UtilityExtensionPoint.class);
+ Properties ps = utilities.getUtility(RuntimeProperties.class).getProperties();
+ Assert.assertEquals(1, ps.size());
+ Assert.assertEquals("vm", ps.getProperty("defaultScheme"));
+
+ Properties properties = new Properties();
+ properties.setProperty("foo.bla", "some value");
+ factory = (NodeFactoryImpl)NodeFactory.newInstance(properties);
+ factory.init();
+ utilities = factory.getExtensionPointRegistry().getExtensionPoint(UtilityExtensionPoint.class);
+ ps = utilities.getUtility(RuntimeProperties.class).getProperties();
+ Assert.assertEquals(1, ps.size());
+ Assert.assertEquals("some value", ps.getProperty("foo.bla"));
+
+ factory = (NodeFactoryImpl)NodeFactory.newInstance("properties:test.properties");
+ factory.init();
+ utilities = factory.getExtensionPointRegistry().getExtensionPoint(UtilityExtensionPoint.class);
+ ps = utilities.getUtility(RuntimeProperties.class).getProperties();
+ Assert.assertEquals(1, ps.size());
+ Assert.assertEquals("xyz", ps.getProperty("foo.bla"));
+
+ factory = (NodeFactoryImpl)NodeFactory.newInstance("uri:foo?k1=v1&k2=v2");
+ factory.init();
+ utilities = factory.getExtensionPointRegistry().getExtensionPoint(UtilityExtensionPoint.class);
+ ps = utilities.getUtility(RuntimeProperties.class).getProperties();
+ Assert.assertEquals(3, ps.size());
+ Assert.assertEquals("foo", ps.getProperty("defaultDomainName"));
+ Assert.assertEquals("v1", ps.getProperty("k1"));
+ Assert.assertEquals("v2", ps.getProperty("k2"));
+
+ factory = (NodeFactoryImpl)NodeFactory.newInstance("uri:");
+ factory.init();
+ utilities = factory.getExtensionPointRegistry().getExtensionPoint(UtilityExtensionPoint.class);
+ ps = utilities.getUtility(RuntimeProperties.class).getProperties();
+ Assert.assertEquals(1, ps.size());
+ Assert.assertEquals("", ps.getProperty("defaultDomainName"));
+
+ factory = (NodeFactoryImpl)NodeFactory.newInstance("uri:?");
+ factory.init();
+ utilities = factory.getExtensionPointRegistry().getExtensionPoint(UtilityExtensionPoint.class);
+ ps = utilities.getUtility(RuntimeProperties.class).getProperties();
+ Assert.assertEquals(1, ps.size());
+ Assert.assertEquals("", ps.getProperty("defaultDomainName"));
+
+ factory = (NodeFactoryImpl)NodeFactory.newInstance("uri:?foo");
+ factory.init();
+ utilities = factory.getExtensionPointRegistry().getExtensionPoint(UtilityExtensionPoint.class);
+ ps = utilities.getUtility(RuntimeProperties.class).getProperties();
+ Assert.assertEquals(2, ps.size());
+ Assert.assertEquals("", ps.getProperty("defaultDomainName"));
+ Assert.assertEquals("", ps.getProperty("foo"));
+ }
+
+ @Test
public void testLoadNodeFactoryProperties() throws Exception {
URL url = getClass().getResource("/org/apache/tuscany/sca/node/configuration/test-node-factory.config");
Collection<Map<String, String>> items = ServiceDeclarationParser.load(url, false);
diff --git a/sca-java-2.x/trunk/modules/node-impl/src/test/resources/test.properties b/sca-java-2.x/trunk/modules/node-impl/src/test/resources/test.properties
new file mode 100644
index 0000000000..ab07d2c8cf
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/node-impl/src/test/resources/test.properties
@@ -0,0 +1,2 @@
+foo.bla = xyz
+