From 2ad26cd7431d5d1d0b333ec18212eb5db29fd537 Mon Sep 17 00:00:00 2001 From: ramkumar Date: Fri, 31 Oct 2008 12:52:47 +0000 Subject: Checkin for TUSCANY-2654, TUSCANY-2655 and TUSCANY-2656 git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@709400 13f79535-47bb-0310-9956-ffa450edef68 --- .../spring/annotations/CalculatorServiceImpl.java | 131 +++++++++++++++++++++ .../context-access/CalculatorService-context.xml | 3 + .../CalculatorService-context.xml | 41 +++++++ .../spring/annotations/Calculator.composite | 60 ++++++++++ .../test/java/context/access/CalculatorClient.java | 4 +- .../java/context/access/ContextAccessTestCase.java | 32 +++++ .../context/imports/ContextImportsTestCase.java | 32 +++++ .../context/multiple/MultipleContextTestCase.java | 32 +++++ .../implementation/policies/CalculatorClient.java | 2 - .../policies/ImplementationPoliciesTestCase.java | 32 +++++ .../java/spring/annotations/CalculatorClient.java | 65 ++++++++++ .../annotations/SpringAnnotationsTestCase.java | 32 +++++ 12 files changed, 462 insertions(+), 4 deletions(-) create mode 100644 java/sca/itest/spring/src/main/java/spring/annotations/CalculatorServiceImpl.java create mode 100644 java/sca/itest/spring/src/main/resources/META-INF/sca/spring-annotation/CalculatorService-context.xml create mode 100644 java/sca/itest/spring/src/main/resources/spring/annotations/Calculator.composite create mode 100644 java/sca/itest/spring/src/test/java/context/access/ContextAccessTestCase.java create mode 100644 java/sca/itest/spring/src/test/java/context/imports/ContextImportsTestCase.java create mode 100644 java/sca/itest/spring/src/test/java/context/multiple/MultipleContextTestCase.java create mode 100644 java/sca/itest/spring/src/test/java/implementation/policies/ImplementationPoliciesTestCase.java create mode 100644 java/sca/itest/spring/src/test/java/spring/annotations/CalculatorClient.java create mode 100644 java/sca/itest/spring/src/test/java/spring/annotations/SpringAnnotationsTestCase.java (limited to 'java/sca/itest/spring/src') diff --git a/java/sca/itest/spring/src/main/java/spring/annotations/CalculatorServiceImpl.java b/java/sca/itest/spring/src/main/java/spring/annotations/CalculatorServiceImpl.java new file mode 100644 index 0000000000..0206849a53 --- /dev/null +++ b/java/sca/itest/spring/src/main/java/spring/annotations/CalculatorServiceImpl.java @@ -0,0 +1,131 @@ +/* + * 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 spring.annotations; + +import org.osoa.sca.annotations.Destroy; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Service; +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Property; +import org.osoa.sca.annotations.ComponentName; + +import calculator.AddService; +import calculator.CalculatorService; +import calculator.DivideService; +import calculator.MultiplyService; +import calculator.SubtractService; + +/** + * An implementation of the Calculator service. + */ +@Service(CalculatorService.class) +public class CalculatorServiceImpl implements AddService, SubtractService, MultiplyService, DivideService { + + public AddService addService; // setter injection + + @Reference + public SubtractService subtractService; // field injection + + @Reference(name="multiplyService", required=false) + public MultiplyService multiply; // field injection (different reference and field name) + + public DivideService divide; // setter injection (different reference and field name) + + public String message; // setter injection + + @Property(name="message", required=false) + public String message2; // field injection + + public String componentName; + + @Init + public void initMethod () { + System.out.println("Init method is sucessfully called....."); + // Property value should be null here. + System.out.println("Property Value message is...." + message); + } + + @Destroy + public void destroyMethod () { + System.out.println("Component Name is...." + componentName); + System.out.println("Property Value message is...." + message); + System.out.println("Property Value message2 is...." + message2); + System.out.println("Destroy method is sucessfully called....."); + } + + @Reference + public void setAddService(AddService addService) { + this.addService = addService; + } + + public AddService getAddService() { + return addService; + } + + /*public void setSubtractService(SubtractService subtractService) { + this.subtractService = subtractService; + } + + public SubtractService getSubtractService() { + return subtractService; + }*/ + + @Reference(name="divideService", required=false) + public void setDivideService(DivideService divide) { + this.divide = divide; + } + + public DivideService getDivideService() { + return divide; + } + + /*public void setMultiplyService(MultiplyService multiplyService) { + this.multiplyService = multiplyService; + } + + public MultiplyService getMultiplyService() { + return multiplyService; + }*/ + + @ComponentName + public void setComponentName(String componentName) { + this.componentName = componentName; + } + + @Property + public void setMessage(String message) { + this.message = message; + } + + public double add(double n1, double n2) { + return addService.add(n1, n2); + } + + public double subtract(double n1, double n2) { + return subtractService.subtract(n1, n2); + } + + public double multiply(double n1, double n2) { + return multiply.multiply(n1, n2); + } + + public double divide(double n1, double n2) { + return divide.divide(n1, n2); + } +} diff --git a/java/sca/itest/spring/src/main/resources/META-INF/sca/context-access/CalculatorService-context.xml b/java/sca/itest/spring/src/main/resources/META-INF/sca/context-access/CalculatorService-context.xml index cac612fa83..87458b99a3 100644 --- a/java/sca/itest/spring/src/main/resources/META-INF/sca/context-access/CalculatorService-context.xml +++ b/java/sca/itest/spring/src/main/resources/META-INF/sca/context-access/CalculatorService-context.xml @@ -23,6 +23,9 @@ xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/sca http://www.osoa.org/xmlns/sca/1.0/spring-sca.xsd"> + + diff --git a/java/sca/itest/spring/src/main/resources/META-INF/sca/spring-annotation/CalculatorService-context.xml b/java/sca/itest/spring/src/main/resources/META-INF/sca/spring-annotation/CalculatorService-context.xml new file mode 100644 index 0000000000..4110a9a7b7 --- /dev/null +++ b/java/sca/itest/spring/src/main/resources/META-INF/sca/spring-annotation/CalculatorService-context.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + diff --git a/java/sca/itest/spring/src/main/resources/spring/annotations/Calculator.composite b/java/sca/itest/spring/src/main/resources/spring/annotations/Calculator.composite new file mode 100644 index 0000000000..a8a1f5b703 --- /dev/null +++ b/java/sca/itest/spring/src/main/resources/spring/annotations/Calculator.composite @@ -0,0 +1,60 @@ + + + + + + + HelloWorld + + + + + + + + + + + + + + + + + + + + + + + diff --git a/java/sca/itest/spring/src/test/java/context/access/CalculatorClient.java b/java/sca/itest/spring/src/test/java/context/access/CalculatorClient.java index e0cc246fab..9b7202d951 100644 --- a/java/sca/itest/spring/src/test/java/context/access/CalculatorClient.java +++ b/java/sca/itest/spring/src/test/java/context/access/CalculatorClient.java @@ -46,13 +46,13 @@ public class CalculatorClient { if (ctx.containsBean("CalculatorServiceBean")) System.out.println("CalculatorServiceBean is now available for use..."); - /*CalculatorService calculatorService = + CalculatorService calculatorService = ((SCAClient)node).getService(CalculatorService.class, "CalculatorServiceComponent"); 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));*/ + System.out.println("3 / 2=" + calculatorService.divide(3, 2)); node.stop(); } diff --git a/java/sca/itest/spring/src/test/java/context/access/ContextAccessTestCase.java b/java/sca/itest/spring/src/test/java/context/access/ContextAccessTestCase.java new file mode 100644 index 0000000000..5feb293bc8 --- /dev/null +++ b/java/sca/itest/spring/src/test/java/context/access/ContextAccessTestCase.java @@ -0,0 +1,32 @@ +/* + * 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 context.access; + +import junit.framework.TestCase; + +/** + * Tests out the big bank service + * + */ +public class ContextAccessTestCase extends TestCase { + + public void testServer() throws Exception { + CalculatorClient.main(new String[] {""}); + } +} diff --git a/java/sca/itest/spring/src/test/java/context/imports/ContextImportsTestCase.java b/java/sca/itest/spring/src/test/java/context/imports/ContextImportsTestCase.java new file mode 100644 index 0000000000..3940bf65fa --- /dev/null +++ b/java/sca/itest/spring/src/test/java/context/imports/ContextImportsTestCase.java @@ -0,0 +1,32 @@ +/* + * 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 context.imports; + +import junit.framework.TestCase; + +/** + * Tests out the big bank service + * + */ +public class ContextImportsTestCase extends TestCase { + + public void testServer() throws Exception { + CalculatorClient.main(new String[] {""}); + } +} diff --git a/java/sca/itest/spring/src/test/java/context/multiple/MultipleContextTestCase.java b/java/sca/itest/spring/src/test/java/context/multiple/MultipleContextTestCase.java new file mode 100644 index 0000000000..75b296bf32 --- /dev/null +++ b/java/sca/itest/spring/src/test/java/context/multiple/MultipleContextTestCase.java @@ -0,0 +1,32 @@ +/* + * 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 context.multiple; + +import junit.framework.TestCase; + +/** + * Tests out the big bank service + * + */ +public class MultipleContextTestCase extends TestCase { + + public void testServer() throws Exception { + StockQuoteServer.main(new String[] {"1000"}); + } +} diff --git a/java/sca/itest/spring/src/test/java/implementation/policies/CalculatorClient.java b/java/sca/itest/spring/src/test/java/implementation/policies/CalculatorClient.java index 9755a13f0b..27e634d301 100644 --- a/java/sca/itest/spring/src/test/java/implementation/policies/CalculatorClient.java +++ b/java/sca/itest/spring/src/test/java/implementation/policies/CalculatorClient.java @@ -47,8 +47,6 @@ public class CalculatorClient { SCANodeFactory factory = SCANodeFactory.newInstance(); SCANode node = factory.createSCANodeFromClassLoader("implementation/policies/Calculator.composite", CalculatorServiceImpl.class.getClassLoader()); - //SCANode node = factory.createSCANode(new File("itest/spring/src/main/resources/implementation/policies/Calculator.composite").toURL().toString(), - //new SCAContribution("TestContribution", new File("itest/spring/src/main/resources/implementation/policies").toURL().toString())); node.start(); CalculatorService calculatorService = diff --git a/java/sca/itest/spring/src/test/java/implementation/policies/ImplementationPoliciesTestCase.java b/java/sca/itest/spring/src/test/java/implementation/policies/ImplementationPoliciesTestCase.java new file mode 100644 index 0000000000..1e759f98a0 --- /dev/null +++ b/java/sca/itest/spring/src/test/java/implementation/policies/ImplementationPoliciesTestCase.java @@ -0,0 +1,32 @@ +/* + * 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 implementation.policies; + +import junit.framework.TestCase; + +/** + * Tests out the big bank service + * + */ +public class ImplementationPoliciesTestCase extends TestCase { + + public void testServer() throws Exception { + CalculatorClient.main(new String[] {""}); + } +} diff --git a/java/sca/itest/spring/src/test/java/spring/annotations/CalculatorClient.java b/java/sca/itest/spring/src/test/java/spring/annotations/CalculatorClient.java new file mode 100644 index 0000000000..c21561a962 --- /dev/null +++ b/java/sca/itest/spring/src/test/java/spring/annotations/CalculatorClient.java @@ -0,0 +1,65 @@ +/* + * 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 spring.annotations; + +import java.io.File; + +import org.apache.tuscany.sca.node.SCAClient; +import org.apache.tuscany.sca.node.SCAContribution; +import org.apache.tuscany.sca.node.SCANode; +import org.apache.tuscany.sca.node.SCANodeFactory; + +import calculator.CalculatorService; +import calculator.CalculatorServiceImpl; + + +/** + * This client program shows how to create an SCA runtime, start it, + * and locate and invoke a SCA component + */ +public class CalculatorClient { + public static void main(String[] args) throws Exception { + + SCANodeFactory factory = SCANodeFactory.newInstance(); + SCANode node = factory.createSCANode(new File("src/main/resources/spring/annotations/Calculator.composite").toURL().toString(), + new SCAContribution("TestContribution", new File("src/main/resources/spring/annotations/").toURL().toString())); + node.start(); + + CalculatorService calculatorService = + ((SCAClient)node).getService(CalculatorService.class, "CalculatorServiceComponent"); + + 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)); + + /*calculatorService = + ((SCAClient)node).getService(CalculatorService.class, "AnotherCalculatorServiceComponent"); + + 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));*/ + + node.stop(); + System.out.println("Bye"); + } + +} diff --git a/java/sca/itest/spring/src/test/java/spring/annotations/SpringAnnotationsTestCase.java b/java/sca/itest/spring/src/test/java/spring/annotations/SpringAnnotationsTestCase.java new file mode 100644 index 0000000000..3a9ec4bbb2 --- /dev/null +++ b/java/sca/itest/spring/src/test/java/spring/annotations/SpringAnnotationsTestCase.java @@ -0,0 +1,32 @@ +/* + * 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 spring.annotations; + +import junit.framework.TestCase; + +/** + * Tests out the big bank service + * + */ +public class SpringAnnotationsTestCase extends TestCase { + + public void testServer() throws Exception { + CalculatorClient.main(new String[] {""}); + } +} -- cgit v1.2.3