summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2010-04-21 08:04:27 +0000
committerantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2010-04-21 08:04:27 +0000
commit9161b6f0e413b85132bb83a03b2de4874a3a2877 (patch)
tree835d7b423569d693c709fc12a290c9e4f52da26b
parentc51886cd56d681230b8b1914b2b369d47619c65d (diff)
Add testcase for properties and add properties to the attributes
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@936188 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-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
+