summaryrefslogtreecommitdiffstats
path: root/java/sca/samples
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-01-14 00:31:58 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-01-14 00:31:58 +0000
commite0f38b2db6826c17d8e722939037261270f5bcd8 (patch)
tree6e1a4c31e60bd8a0b514ba8c45d8765823316036 /java/sca/samples
parent45d5073d1ab854cdc6174e48c7ce818964a63c08 (diff)
Bring up the RMI samples with 2.x
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@734282 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/samples')
-rw-r--r--java/sca/samples/calculator-rmi-reference/pom.xml16
-rw-r--r--java/sca/samples/calculator-rmi-reference/src/main/java/calculator/CalculatorClient.java17
-rw-r--r--java/sca/samples/calculator-rmi-reference/src/main/resources/CalculatorRMIReference.composite8
-rw-r--r--java/sca/samples/calculator-rmi-reference/src/test/java/calculator/CalculatorRMIReferenceTestCase.java44
-rw-r--r--java/sca/samples/calculator-rmi-service/pom.xml15
-rw-r--r--java/sca/samples/calculator-rmi-service/src/main/java/calculator/CalculatorServer.java12
-rw-r--r--java/sca/samples/calculator-rmi-service/src/main/resources/CalculatorRMIServer.composite2
-rw-r--r--java/sca/samples/calculator-rmi-service/src/test/java/calculator/CalculatorRMIServerTestCase.java44
8 files changed, 94 insertions, 64 deletions
diff --git a/java/sca/samples/calculator-rmi-reference/pom.xml b/java/sca/samples/calculator-rmi-reference/pom.xml
index 110a192f72..eb7a8b8584 100644
--- a/java/sca/samples/calculator-rmi-reference/pom.xml
+++ b/java/sca/samples/calculator-rmi-reference/pom.xml
@@ -28,19 +28,19 @@
<artifactId>sample-calculator-rmi-reference</artifactId>
<name>Apache Tuscany SCA Calculator RMI Reference Sample</name>
- <repositories>
- <repository>
- <id>apache.incubator</id>
- <url>http://people.apache.org/repo/m2-incubating-repository</url>
- </repository>
- </repositories>
-
<dependencies>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
- <artifactId>tuscany-host-embedded</artifactId>
+ <artifactId>tuscany-node-api</artifactId>
+ <version>2.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-node-impl</artifactId>
<version>2.0-SNAPSHOT</version>
+ <scope>test</scope>
</dependency>
+
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-implementation-java-runtime</artifactId>
diff --git a/java/sca/samples/calculator-rmi-reference/src/main/java/calculator/CalculatorClient.java b/java/sca/samples/calculator-rmi-reference/src/main/java/calculator/CalculatorClient.java
index cd1076c3f1..3ee36be233 100644
--- a/java/sca/samples/calculator-rmi-reference/src/main/java/calculator/CalculatorClient.java
+++ b/java/sca/samples/calculator-rmi-reference/src/main/java/calculator/CalculatorClient.java
@@ -19,7 +19,10 @@
package calculator;
-import org.apache.tuscany.sca.host.embedded.SCADomain;
+import org.apache.tuscany.sca.node.Contribution;
+import org.apache.tuscany.sca.node.ContributionLocationHelper;
+import org.apache.tuscany.sca.node.Node;
+import org.apache.tuscany.sca.node.NodeFactory;
/**
* This client program shows how to create an SCA runtime, start it,
@@ -27,17 +30,19 @@ import org.apache.tuscany.sca.host.embedded.SCADomain;
*/
public class CalculatorClient {
public static void main(String[] args) throws Exception {
- SCADomain scaDomain = SCADomain.newInstance("CalculatorRMIReference.composite");
- CalculatorService calculatorService =
- scaDomain.getService(CalculatorService.class, "CalculatorServiceComponent");
+ String uri = ContributionLocationHelper.getContributionLocation("CalculatorRMIReference.composite");
+ Contribution contribution = new Contribution("c1", uri);
+ Node node = NodeFactory.newInstance().createNode("CalculatorRMIReference.composite", contribution);
+ node.start();
+ CalculatorService calculatorService = node.getService(CalculatorService.class, "CalculatorServiceComponent");
// Calculate
System.out.println("3 + 2=" + calculatorService.add(3, 2));
System.out.println("3 - 2=" + calculatorService.subtract(3, 2));
System.out.println("3 * 2=" + calculatorService.multiply(3, 2));
System.out.println("3 / 2=" + calculatorService.divide(3, 2));
-
- scaDomain.close();
+
+ node.stop();
}
diff --git a/java/sca/samples/calculator-rmi-reference/src/main/resources/CalculatorRMIReference.composite b/java/sca/samples/calculator-rmi-reference/src/main/resources/CalculatorRMIReference.composite
index a5a6e1cd29..17341b2a59 100644
--- a/java/sca/samples/calculator-rmi-reference/src/main/resources/CalculatorRMIReference.composite
+++ b/java/sca/samples/calculator-rmi-reference/src/main/resources/CalculatorRMIReference.composite
@@ -26,16 +26,16 @@
<component name="CalculatorServiceComponent">
<implementation.java class="calculator.CalculatorServiceImpl"/>
<reference name="addService">
- <tuscany:binding.rmi host="localhost" port="8099" serviceName="CalculatorRMIService"/>
+ <tuscany:binding.rmi uri="rmi://localhost:8099/CalculatorRMIService"/>
</reference>
<reference name="subtractService">
- <tuscany:binding.rmi host="localhost" port="8099" serviceName="CalculatorRMIService"/>
+ <tuscany:binding.rmi uri="rmi://localhost:8099/CalculatorRMIService"/>
</reference>
<reference name="multiplyService">
- <tuscany:binding.rmi host="localhost" port="8099" serviceName="CalculatorRMIService"/>
+ <tuscany:binding.rmi uri="rmi://localhost:8099/CalculatorRMIService"/>
</reference>
<reference name="divideService">
- <tuscany:binding.rmi host="localhost" port="8099" serviceName="CalculatorRMIService"/>
+ <tuscany:binding.rmi uri="rmi://localhost:8099/CalculatorRMIService"/>
</reference>
</component>
diff --git a/java/sca/samples/calculator-rmi-reference/src/test/java/calculator/CalculatorRMIReferenceTestCase.java b/java/sca/samples/calculator-rmi-reference/src/test/java/calculator/CalculatorRMIReferenceTestCase.java
index 15e00f5946..f14191c411 100644
--- a/java/sca/samples/calculator-rmi-reference/src/test/java/calculator/CalculatorRMIReferenceTestCase.java
+++ b/java/sca/samples/calculator-rmi-reference/src/test/java/calculator/CalculatorRMIReferenceTestCase.java
@@ -18,43 +18,53 @@
*/
package calculator;
+import static org.junit.Assert.assertEquals;
+
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
-import junit.framework.TestCase;
-
-import org.apache.tuscany.sca.host.embedded.SCADomain;
+import org.apache.tuscany.sca.node.Contribution;
+import org.apache.tuscany.sca.node.ContributionLocationHelper;
+import org.apache.tuscany.sca.node.Node;
+import org.apache.tuscany.sca.node.NodeFactory;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
/**
* This shows how to test the Calculator service component.
*/
-public class CalculatorRMIReferenceTestCase extends TestCase {
+public class CalculatorRMIReferenceTestCase {
- private SCADomain scaDomain;
- private CalculatorService calculatorService;
+ private static Node node;
+ private static CalculatorService calculatorService;
- @Override
- protected void setUp() throws Exception {
+ @BeforeClass
+ public static void setUp() throws Exception {
CalculatorRMIServiceImpl rmiCalculatorImpl = new CalculatorRMIServiceImpl();
Registry rmiRegistry = LocateRegistry.createRegistry(8099);
rmiRegistry.bind("CalculatorRMIService", rmiCalculatorImpl);
- scaDomain = SCADomain.newInstance("CalculatorRMIReference.composite");
- calculatorService = scaDomain.getService(CalculatorService.class, "CalculatorServiceComponent");
+ String uri = ContributionLocationHelper.getContributionLocation("CalculatorRMIReference.composite");
+ Contribution contribution = new Contribution("c1", uri);
+ node = NodeFactory.newInstance().createNode("CalculatorRMIReference.composite", contribution);
+ node.start();
+ calculatorService = node.getService(CalculatorService.class, "CalculatorServiceComponent");
}
- @Override
- protected void tearDown() throws Exception {
- scaDomain.close();
+ @AfterClass
+ public static void tearDown() throws Exception {
+ node.stop();
LocateRegistry.getRegistry(8099).unbind("CalculatorRMIService");
}
+ @Test
public void testCalculator() throws Exception {
// Calculate
- assertEquals(calculatorService.add(3, 2), 5.0);
- assertEquals(calculatorService.subtract(3, 2), 1.0);
- assertEquals(calculatorService.multiply(3, 2), 6.0);
- assertEquals(calculatorService.divide(3, 2), 1.5);
+ assertEquals(calculatorService.add(3, 2), 5.0, 0.0);
+ assertEquals(calculatorService.subtract(3, 2), 1.0, 0.0);
+ assertEquals(calculatorService.multiply(3, 2), 6.0, 0.0);
+ assertEquals(calculatorService.divide(3, 2), 1.5, 0.0);
}
}
diff --git a/java/sca/samples/calculator-rmi-service/pom.xml b/java/sca/samples/calculator-rmi-service/pom.xml
index 0ce5d94a76..f121dea2fe 100644
--- a/java/sca/samples/calculator-rmi-service/pom.xml
+++ b/java/sca/samples/calculator-rmi-service/pom.xml
@@ -28,18 +28,17 @@
<artifactId>sample-calculator-rmi-service</artifactId>
<name>Apache Tuscany SCA Calculator RMI Service Sample</name>
- <repositories>
- <repository>
- <id>apache.incubator</id>
- <url>http://people.apache.org/repo/m2-incubating-repository</url>
- </repository>
- </repositories>
-
<dependencies>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
- <artifactId>tuscany-host-embedded</artifactId>
+ <artifactId>tuscany-node-api</artifactId>
+ <version>2.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-node-impl</artifactId>
<version>2.0-SNAPSHOT</version>
+ <scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
diff --git a/java/sca/samples/calculator-rmi-service/src/main/java/calculator/CalculatorServer.java b/java/sca/samples/calculator-rmi-service/src/main/java/calculator/CalculatorServer.java
index b698163c1b..ffa40d0234 100644
--- a/java/sca/samples/calculator-rmi-service/src/main/java/calculator/CalculatorServer.java
+++ b/java/sca/samples/calculator-rmi-service/src/main/java/calculator/CalculatorServer.java
@@ -19,7 +19,10 @@
package calculator;
-import org.apache.tuscany.sca.host.embedded.SCADomain;
+import org.apache.tuscany.sca.node.Contribution;
+import org.apache.tuscany.sca.node.ContributionLocationHelper;
+import org.apache.tuscany.sca.node.Node;
+import org.apache.tuscany.sca.node.NodeFactory;
/**
* A claculator service server. Starts up the SCA runtime which
@@ -28,10 +31,13 @@ import org.apache.tuscany.sca.host.embedded.SCADomain;
public class CalculatorServer {
public static void main(String[] args) throws Exception {
System.out.println("Starting of the SCA Calculator Application exposed as RMI Services...");
- SCADomain scaDomain = SCADomain.newInstance("CalculatorRMIServer.composite");
+ String uri = ContributionLocationHelper.getContributionLocation("CalculatorRMIServer.composite");
+ Contribution contribution = new Contribution("c1", uri);
+ Node node = NodeFactory.newInstance().createNode("CalculatorRMIServer.composite", contribution);
+ node.start();
System.out.println("... Press Enter to Exit...");
System.in.read();
- scaDomain.close();
+ node.stop();
System.out.println("Exited...");
System.exit(0);
}
diff --git a/java/sca/samples/calculator-rmi-service/src/main/resources/CalculatorRMIServer.composite b/java/sca/samples/calculator-rmi-service/src/main/resources/CalculatorRMIServer.composite
index 34d90ab451..c1a15e9107 100644
--- a/java/sca/samples/calculator-rmi-service/src/main/resources/CalculatorRMIServer.composite
+++ b/java/sca/samples/calculator-rmi-service/src/main/resources/CalculatorRMIServer.composite
@@ -27,7 +27,7 @@
<implementation.java class="calculator.CalculatorServiceImpl"/>
<service name="CalculatorService">
<interface.java interface="calculator.CalculatorService"/>
- <tuscany:binding.rmi host="localhost" port="8099" serviceName="CalculatorRMIService"/>
+ <tuscany:binding.rmi uri="rmi://localhost:8099/CalculatorRMIService"/>
</service>
<reference name="addService" target="AddServiceComponent"></reference>
<reference name="subtractService" target="SubtractServiceComponent"></reference>
diff --git a/java/sca/samples/calculator-rmi-service/src/test/java/calculator/CalculatorRMIServerTestCase.java b/java/sca/samples/calculator-rmi-service/src/test/java/calculator/CalculatorRMIServerTestCase.java
index 8943dd24f6..aafde63738 100644
--- a/java/sca/samples/calculator-rmi-service/src/test/java/calculator/CalculatorRMIServerTestCase.java
+++ b/java/sca/samples/calculator-rmi-service/src/test/java/calculator/CalculatorRMIServerTestCase.java
@@ -18,36 +18,46 @@
*/
package calculator;
-import java.rmi.Naming;
+import static org.junit.Assert.assertEquals;
-import junit.framework.TestCase;
+import java.rmi.Naming;
-import org.apache.tuscany.sca.host.embedded.SCADomain;
+import org.apache.tuscany.sca.node.Contribution;
+import org.apache.tuscany.sca.node.ContributionLocationHelper;
+import org.apache.tuscany.sca.node.Node;
+import org.apache.tuscany.sca.node.NodeFactory;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
/**
* This shows how to test the Calculator service component.
*/
-public class CalculatorRMIServerTestCase extends TestCase {
+public class CalculatorRMIServerTestCase {
- private SCADomain scaDomain;
- private CalculatorService calculatorService;
+ private static Node node;
+ private static CalculatorService calculatorService;
- @Override
- protected void setUp() throws Exception {
- scaDomain = SCADomain.newInstance("CalculatorRMIServer.composite");
+ @BeforeClass
+ public static void setUp() throws Exception {
+ String uri = ContributionLocationHelper.getContributionLocation("CalculatorRMIServer.composite");
+ Contribution contribution = new Contribution("c1", uri);
+ node = NodeFactory.newInstance().createNode("CalculatorRMIServer.composite", contribution);
+ node.start();
}
-
- @Override
- protected void tearDown() throws Exception {
- scaDomain.close();
+
+ @AfterClass
+ public static void tearDown() throws Exception {
+ node.stop();
}
+ @Test
public void testCalculator() throws Exception {
// Calculate
calculatorService = (CalculatorService)Naming.lookup("//localhost:8099/CalculatorRMIService");
- assertEquals(calculatorService.add(3, 2), 5.0);
- assertEquals(calculatorService.subtract(3, 2), 1.0);
- assertEquals(calculatorService.multiply(3, 2), 6.0);
- assertEquals(calculatorService.divide(3, 2), 1.5);
+ assertEquals(calculatorService.add(3, 2), 5.0, 0.0);
+ assertEquals(calculatorService.subtract(3, 2), 1.0, 0.0);
+ assertEquals(calculatorService.multiply(3, 2), 6.0, 0.0);
+ assertEquals(calculatorService.divide(3, 2), 1.5, 0.0);
}
}