From 93ee28a97432d9448fa793cf47ff71f33186ae3b Mon Sep 17 00:00:00 2001 From: slaws Date: Fri, 14 May 2010 14:52:13 +0000 Subject: Launch binding-sca and binding-ws based contributions. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@944300 13f79535-47bb-0310-9956-ffa450edef68 --- .../trunk/samples/launcher-embedded-jse/build.xml | 18 ++++++++- .../src/main/java/launcher/SampleJSELauncher.java | 45 +++++++++++++--------- .../src/test/java/launcher/LauncherTestCase.java | 13 ++++--- 3 files changed, 51 insertions(+), 25 deletions(-) (limited to 'sca-java-2.x/trunk/samples/launcher-embedded-jse') diff --git a/sca-java-2.x/trunk/samples/launcher-embedded-jse/build.xml b/sca-java-2.x/trunk/samples/launcher-embedded-jse/build.xml index 1b67df3b7e..74f613109f 100644 --- a/sca-java-2.x/trunk/samples/launcher-embedded-jse/build.xml +++ b/sca-java-2.x/trunk/samples/launcher-embedded-jse/build.xml @@ -54,7 +54,7 @@ Please use 'ant run-name-of-sample-contribution-to-run' - + @@ -64,8 +64,22 @@ - + + + + + + + + + + + + + diff --git a/sca-java-2.x/trunk/samples/launcher-embedded-jse/src/main/java/launcher/SampleJSELauncher.java b/sca-java-2.x/trunk/samples/launcher-embedded-jse/src/main/java/launcher/SampleJSELauncher.java index 7249e92f43..79bd8403e6 100644 --- a/sca-java-2.x/trunk/samples/launcher-embedded-jse/src/main/java/launcher/SampleJSELauncher.java +++ b/sca-java-2.x/trunk/samples/launcher-embedded-jse/src/main/java/launcher/SampleJSELauncher.java @@ -21,8 +21,6 @@ package launcher; import org.apache.tuscany.sca.node.Contribution; import org.apache.tuscany.sca.node.Node; -import org.apache.tuscany.sca.node.NodeFactory; -import org.oasisopen.sca.ServiceRuntimeException; import calculator.CalculatorService; @@ -31,7 +29,7 @@ import calculator.CalculatorService; * This client program shows how to create an embedded SCA runtime, start it, * and locate and invoke a SCA component */ -public class SampleJSELauncher { +public class SampleJSELauncher extends RuntimeIntegration { public static void main(String[] args) throws Exception { SampleJSELauncher launcher = new SampleJSELauncher(); @@ -40,34 +38,45 @@ public class SampleJSELauncher { if (args == null || args.length != 1){ System.out.println("Please provide the name of the sample contribution to run as a parameter"); - System.out.println("Running binding-ws-calculator by default"); - contribution = "contribution-binding-ws-calculator"; + System.out.println("Running binding-sca-calculator by default"); + contribution = "contribution-binding-sca-calculator"; } else { contribution = args[0]; } - if (contribution.equals("contribution-binding-ws-calculator")){ + if (contribution.equals("contribution-binding-sca-calculator")){ + launcher.launchBindingSCACalculator(); + } else if (contribution.equals("contribution-binding-ws-calculator")){ launcher.launchBindingWSCalculator(); } else { System.out.println("Sample contribution " + contribution + "not found"); } - - } - - public Node startNode(Contribution... contributions){ - Node node = NodeFactory.newInstance().createNode(contributions); - node.start(); - return node; - } - - public void stopNode(Node node){ - node.stop(); } + + /** + * The contribution-binding-sca-calculator contribution includes a client component + * that calls the CalculatorServiceComponent from an operation marked by @Init. + */ + public void launchBindingSCACalculator(){ + Node node = startNode(new Contribution("c1", "../contribution-binding-sca-calculator/target/classes")); + + //CalculatorService calculator = node.getService(CalculatorService.class, "CalculatorServiceComponent"); + // TODO - could use JUnit assertions but don't want to have to handle JUnit dependency from Ant script + //double result = calculator.add(3, 2); + //System.out.println("3 + 2 = " + result); + //if (result != 5.0){ + // throw new SampleLauncherException(); + //} + stopNode(node); + } + /* + * Using a Tuscany specific mechanism for getting at local service proxies + */ public void launchBindingWSCalculator(){ Node node = startNode(new Contribution("c1", "../contribution-binding-ws-calculator/target/classes")); - CalculatorService calculator = node.getService(CalculatorService.class, "CalculatorServiceComponent"); + CalculatorService calculator = node.getService(CalculatorService.class, "CalculatorServiceComponent"); // TODO - could use JUnit assertions but don't want to have to handle JUnit dependency from Ant script double result = calculator.add(3, 2); System.out.println("3 + 2 = " + result); diff --git a/sca-java-2.x/trunk/samples/launcher-embedded-jse/src/test/java/launcher/LauncherTestCase.java b/sca-java-2.x/trunk/samples/launcher-embedded-jse/src/test/java/launcher/LauncherTestCase.java index d0b9dab4d4..6154f9fce3 100644 --- a/sca-java-2.x/trunk/samples/launcher-embedded-jse/src/test/java/launcher/LauncherTestCase.java +++ b/sca-java-2.x/trunk/samples/launcher-embedded-jse/src/test/java/launcher/LauncherTestCase.java @@ -20,15 +20,18 @@ package launcher; import org.junit.Test; - - /** - * Test the Calculator composition. + * Test sample contributions. */ public class LauncherTestCase { @Test - public void testSample() throws Exception { - SampleJSELauncher.main(null); + public void testCOntributionBindingSCACalculator() throws Exception { + SampleJSELauncher.main(new String[] {"contribution-binding-sca-calculator"}); } + + @Test + public void testCOntributionBindingWSCalculator() throws Exception { + SampleJSELauncher.main(new String[] {"contribution-binding-ws-calculator"}); + } } -- cgit v1.2.3