diff options
author | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2010-05-12 13:48:35 +0000 |
---|---|---|
committer | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2010-05-12 13:48:35 +0000 |
commit | 4d79142934a425e2787eb3aca01a369ec329550e (patch) | |
tree | b104db0b02afdc56ac94286287a746ae10214a69 /sca-java-2.x/trunk/samples/binding-ws-calculator | |
parent | f2f3636bdd5d7b669fb2d8ad3159ab840a7a6b45 (diff) |
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
Diffstat (limited to 'sca-java-2.x/trunk/samples/binding-ws-calculator')
5 files changed, 21 insertions, 147 deletions
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"> - <component name="SampleClient"> - <implementation.java class="calculator.CalculatorClientImpl"/> - <reference name="calculatorService" target="CalculatorServiceComponent" /> - </component> - <component name="CalculatorServiceComponent"> <implementation.java class="calculator.CalculatorServiceImpl"/> <reference name="addService" > 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); } } |