From 41cfd14858db52e8c3b8abd21a7f1944d14e4b0e Mon Sep 17 00:00:00 2001 From: antelder Date: Tue, 14 Jun 2011 08:57:19 +0000 Subject: Update to support using a node.xml config file in the domain directory git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1135417 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/tuscany/sca/TuscanyRuntime.java | 13 ++++++++++- .../tuscany/sca/impl/DirectoryDomainTestCase.java | 23 ++++++++++++++++++ .../resources/test-domains/NodeXMLDomain/node.xml | 27 ++++++++++++++++++++++ 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 sca-java-2.x/trunk/modules/domain-node/src/test/resources/test-domains/NodeXMLDomain/node.xml (limited to 'sca-java-2.x/trunk') diff --git a/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/TuscanyRuntime.java b/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/TuscanyRuntime.java index 69d2d24840..5d84933374 100644 --- a/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/TuscanyRuntime.java +++ b/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/TuscanyRuntime.java @@ -163,7 +163,9 @@ public class TuscanyRuntime { /* * Create a node from a file system directory. - * The directory can contain: + * If the directory is actually a file use createNodeFromXML + * if the directory contains a file named node.xml then use createNodeFromXML + * Otherwise, the directory can contain: * domain.properties * contributions - jar, zip, or exploded directories * sca-contribution.xml metaData files to override whats in a contribution @@ -173,6 +175,15 @@ public class TuscanyRuntime { */ public Node createNode(File directory) throws ContributionReadException, ValidationException, ActivationException, XMLStreamException, IOException { + if (!directory.isDirectory()) { + return createNodeFromXML(directory.toURI().toURL().toString()); + } + + File nodeXML = new File(directory, "node.xml"); + if (nodeXML.exists()) { + return createNodeFromXML(nodeXML.toURI().toURL().toString()); + } + Properties domainProps = new Properties(); File propsFile = new File(directory, "domain.properties"); if (propsFile.exists()) { diff --git a/sca-java-2.x/trunk/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl/DirectoryDomainTestCase.java b/sca-java-2.x/trunk/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl/DirectoryDomainTestCase.java index fb863402c6..5bf1f53690 100644 --- a/sca-java-2.x/trunk/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl/DirectoryDomainTestCase.java +++ b/sca-java-2.x/trunk/modules/domain-node/src/test/java/org/apache/tuscany/sca/impl/DirectoryDomainTestCase.java @@ -69,4 +69,27 @@ public class DirectoryDomainTestCase { Assert.assertEquals("sample", ic.getJavaExports().get(0)); } + @Test + public void testNodeXMLFile() throws ContributionReadException, ActivationException, ValidationException, XMLStreamException, IOException { + Node node = TuscanyRuntime.newInstance().createNode(new File("src/test/resources/helloworldNode.xml")); + Assert.assertEquals("helloworld", node.getDomainName()); + List cs = node.getInstalledContributionURIs(); + Assert.assertEquals(1, cs.size()); + Assert.assertEquals("sample-helloworld", cs.get(0)); + Map> startedComposites = node.getStartedCompositeURIs(); + Assert.assertEquals(1, startedComposites.size()); + Assert.assertEquals("helloworld.composite", startedComposites.get("sample-helloworld").get(0)); + } + + @Test + public void testNodeXMLDomain() throws ContributionReadException, ActivationException, ValidationException, XMLStreamException, IOException { + Node node = TuscanyRuntime.newInstance().createNode(new File("src/test/resources/test-domains/NodeXMLDomain")); + Assert.assertEquals("helloworld", node.getDomainName()); + List cs = node.getInstalledContributionURIs(); + Assert.assertEquals(1, cs.size()); + Assert.assertEquals("sample-helloworld", cs.get(0)); + Map> startedComposites = node.getStartedCompositeURIs(); + Assert.assertEquals(1, startedComposites.size()); + Assert.assertEquals("helloworld.composite", startedComposites.get("sample-helloworld").get(0)); + } } diff --git a/sca-java-2.x/trunk/modules/domain-node/src/test/resources/test-domains/NodeXMLDomain/node.xml b/sca-java-2.x/trunk/modules/domain-node/src/test/resources/test-domains/NodeXMLDomain/node.xml new file mode 100644 index 0000000000..1fe1ccff14 --- /dev/null +++ b/sca-java-2.x/trunk/modules/domain-node/src/test/resources/test-domains/NodeXMLDomain/node.xml @@ -0,0 +1,27 @@ + + + + + + + \ No newline at end of file -- cgit v1.2.3