From 4d79142934a425e2787eb3aca01a369ec329550e Mon Sep 17 00:00:00 2001 From: slaws Date: Wed, 12 May 2010 13:48:35 +0000 Subject: Using binding-ws-calulator as an example of turning samples into contributions. First step is to remove the client code from the contribution and adjust the composite and test case accordingly. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@943495 13f79535-47bb-0310-9956-ffa450edef68 --- .../main/java/calculator/CalculatorClientImpl.java | 66 ---------------------- .../src/main/java/sample/SampleClient.java | 26 --------- .../src/main/java/sample/SampleClientImpl.java | 45 --------------- .../src/main/resources/Calculator.composite | 5 -- .../test/java/calculator/CalculatorTestCase.java | 26 +++++++-- 5 files changed, 21 insertions(+), 147 deletions(-) delete mode 100644 sca-java-2.x/trunk/samples/binding-ws-calculator/src/main/java/calculator/CalculatorClientImpl.java delete mode 100644 sca-java-2.x/trunk/samples/binding-ws-calculator/src/main/java/sample/SampleClient.java delete mode 100644 sca-java-2.x/trunk/samples/binding-ws-calculator/src/main/java/sample/SampleClientImpl.java (limited to 'sca-java-2.x/trunk/samples/binding-ws-calculator/src') diff --git a/sca-java-2.x/trunk/samples/binding-ws-calculator/src/main/java/calculator/CalculatorClientImpl.java b/sca-java-2.x/trunk/samples/binding-ws-calculator/src/main/java/calculator/CalculatorClientImpl.java deleted file mode 100644 index 7e5ff160f0..0000000000 --- a/sca-java-2.x/trunk/samples/binding-ws-calculator/src/main/java/calculator/CalculatorClientImpl.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package calculator; - -import org.oasisopen.sca.annotation.Reference; -import org.oasisopen.sca.annotation.Scope; - -import sample.SampleClient; - -/** - * This client program shows how to create an SCA runtime, start it, - * and locate and invoke a SCA component - */ -@Scope("COMPOSITE") -public class CalculatorClientImpl implements SampleClient { - - private CalculatorService calculatorService; - - @Reference - public void setCalculatorService(CalculatorService calculatorService) { - this.calculatorService = calculatorService; - } - - /** - * This code used to be in an @Init method which removed the need for a JSE client - * to prod the compoite. However OASIS is debating whether to allow references to be used - * inside @Init methods and it can cause deadlocks in our runtime. So rather than make - * changes in the runtime we are falling backon the JSE drive mechanism until we know - * which way the specs are going - */ - public void runSample() { - System.out.println("SCA API ClassLoader: " + print(Reference.class.getClassLoader())); - 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)); - } - - private static String print(ClassLoader cl) { - StringBuffer buf = new StringBuffer(); - for (; cl != null;) { - buf.append(cl.toString()); - buf.append(' '); - cl = cl.getParent(); - } - return buf.toString(); - } - -} diff --git a/sca-java-2.x/trunk/samples/binding-ws-calculator/src/main/java/sample/SampleClient.java b/sca-java-2.x/trunk/samples/binding-ws-calculator/src/main/java/sample/SampleClient.java deleted file mode 100644 index 6620f6a5e7..0000000000 --- a/sca-java-2.x/trunk/samples/binding-ws-calculator/src/main/java/sample/SampleClient.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package sample; - -/** - * The sample service interface. - */ -public interface SampleClient { - void runSample(); -} diff --git a/sca-java-2.x/trunk/samples/binding-ws-calculator/src/main/java/sample/SampleClientImpl.java b/sca-java-2.x/trunk/samples/binding-ws-calculator/src/main/java/sample/SampleClientImpl.java deleted file mode 100644 index 000c108934..0000000000 --- a/sca-java-2.x/trunk/samples/binding-ws-calculator/src/main/java/sample/SampleClientImpl.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package sample; - -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, - * and locate and invoke a SCA component - */ -public class SampleClientImpl { - public static void main(String[] args) throws Exception { - String location = ContributionLocationHelper.getContributionLocation(SampleClient.class); - Node node = NodeFactory.newInstance().createNode(new Contribution("c1", location)); - - node.start(); - - SampleClient sampleClient = node.getService(SampleClient.class, "SampleClient"); - sampleClient.runSample(); - - node.stop(); - - } - -} diff --git a/sca-java-2.x/trunk/samples/binding-ws-calculator/src/main/resources/Calculator.composite b/sca-java-2.x/trunk/samples/binding-ws-calculator/src/main/resources/Calculator.composite index 22117278d3..ac4d7321e7 100644 --- a/sca-java-2.x/trunk/samples/binding-ws-calculator/src/main/resources/Calculator.composite +++ b/sca-java-2.x/trunk/samples/binding-ws-calculator/src/main/resources/Calculator.composite @@ -22,11 +22,6 @@ xmlns:sample="http://sample" name="Calculator"> - - - - - diff --git a/sca-java-2.x/trunk/samples/binding-ws-calculator/src/test/java/calculator/CalculatorTestCase.java b/sca-java-2.x/trunk/samples/binding-ws-calculator/src/test/java/calculator/CalculatorTestCase.java index 8f6b5e4845..9d3024f451 100644 --- a/sca-java-2.x/trunk/samples/binding-ws-calculator/src/test/java/calculator/CalculatorTestCase.java +++ b/sca-java-2.x/trunk/samples/binding-ws-calculator/src/test/java/calculator/CalculatorTestCase.java @@ -18,17 +18,33 @@ */ package calculator; -import org.junit.Test; +import static org.junit.Assert.assertEquals; -import sample.SampleClientImpl; +import org.junit.Test; /** - * Test the Calculator composition. + * A unit test of the basic Java implementation classes in this contribution + * without using SCA */ public class CalculatorTestCase { @Test - public void testSample() throws Exception { - SampleClientImpl.main(null); + public void testCalculator() throws Exception { + AddService add = new AddServiceImpl(); + SubtractService subtract = new SubtractServiceImpl(); + MultiplyService multiply = new MultiplyServiceImpl(); + DivideService divide = new DivideServiceImpl(); + + CalculatorServiceImpl calculator = new CalculatorServiceImpl(); + + calculator.setAddService(add); + calculator.setSubtractService(subtract); + calculator.setMultiplyService(multiply); + calculator.setDivideService(divide); + + assertEquals(calculator.add(3, 2), 5.0, 0); + assertEquals(calculator.subtract(3, 2), 1.0, 0); + assertEquals(calculator.multiply(3, 2), 6.0, 0); + assertEquals(calculator.divide(3, 2), 1.5, 0); } } -- cgit v1.2.3