From a8a286315d8994283b280d88b84aa790a4fedf74 Mon Sep 17 00:00:00 2001 From: rfeng Date: Wed, 11 Mar 2009 00:51:55 +0000 Subject: Create test bundles git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@752324 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/test/java/calculator/AddService.java | 31 ------ .../src/test/java/calculator/AddServiceImpl.java | 35 ------- .../test/java/calculator/CalculatorActivator.java | 11 ++- .../java/calculator/CalculatorServiceImpl.java | 10 +- .../src/test/java/calculator/DivideService.java | 31 ------ .../test/java/calculator/DivideServiceImpl.java | 35 ------- .../src/test/java/calculator/MultiplyService.java | 31 ------ .../test/java/calculator/MultiplyServiceImpl.java | 35 ------- .../test/java/calculator/OperationsActivator.java | 59 ------------ .../src/test/java/calculator/SubtractService.java | 31 ------ .../test/java/calculator/SubtractServiceImpl.java | 35 ------- .../java/calculator/operations/AddService.java | 31 ++++++ .../java/calculator/operations/AddServiceImpl.java | 35 +++++++ .../java/calculator/operations/DivideService.java | 31 ++++++ .../calculator/operations/DivideServiceImpl.java | 35 +++++++ .../calculator/operations/MultiplyService.java | 31 ++++++ .../calculator/operations/MultiplyServiceImpl.java | 35 +++++++ .../calculator/operations/OperationsActivator.java | 67 +++++++++++++ .../calculator/operations/SubtractService.java | 31 ++++++ .../calculator/operations/SubtractServiceImpl.java | 35 +++++++ .../calculator/test/CalculatorOSGiTestCase.java | 104 +++++++++++++++++++++ .../implementation/osgi/runtime/OSGiTestCase.java | 4 +- .../implementation/osgi/test/OSGiTestBundles.java | 29 +++++- .../osgi/xml/OSGiReadImplTestCase.java | 4 +- 24 files changed, 475 insertions(+), 341 deletions(-) delete mode 100644 java/sca/modules/implementation-osgi/src/test/java/calculator/AddService.java delete mode 100644 java/sca/modules/implementation-osgi/src/test/java/calculator/AddServiceImpl.java delete mode 100644 java/sca/modules/implementation-osgi/src/test/java/calculator/DivideService.java delete mode 100644 java/sca/modules/implementation-osgi/src/test/java/calculator/DivideServiceImpl.java delete mode 100644 java/sca/modules/implementation-osgi/src/test/java/calculator/MultiplyService.java delete mode 100644 java/sca/modules/implementation-osgi/src/test/java/calculator/MultiplyServiceImpl.java delete mode 100644 java/sca/modules/implementation-osgi/src/test/java/calculator/OperationsActivator.java delete mode 100644 java/sca/modules/implementation-osgi/src/test/java/calculator/SubtractService.java delete mode 100644 java/sca/modules/implementation-osgi/src/test/java/calculator/SubtractServiceImpl.java create mode 100644 java/sca/modules/implementation-osgi/src/test/java/calculator/operations/AddService.java create mode 100644 java/sca/modules/implementation-osgi/src/test/java/calculator/operations/AddServiceImpl.java create mode 100644 java/sca/modules/implementation-osgi/src/test/java/calculator/operations/DivideService.java create mode 100644 java/sca/modules/implementation-osgi/src/test/java/calculator/operations/DivideServiceImpl.java create mode 100644 java/sca/modules/implementation-osgi/src/test/java/calculator/operations/MultiplyService.java create mode 100644 java/sca/modules/implementation-osgi/src/test/java/calculator/operations/MultiplyServiceImpl.java create mode 100644 java/sca/modules/implementation-osgi/src/test/java/calculator/operations/OperationsActivator.java create mode 100644 java/sca/modules/implementation-osgi/src/test/java/calculator/operations/SubtractService.java create mode 100644 java/sca/modules/implementation-osgi/src/test/java/calculator/operations/SubtractServiceImpl.java create mode 100644 java/sca/modules/implementation-osgi/src/test/java/calculator/test/CalculatorOSGiTestCase.java (limited to 'java/sca/modules') diff --git a/java/sca/modules/implementation-osgi/src/test/java/calculator/AddService.java b/java/sca/modules/implementation-osgi/src/test/java/calculator/AddService.java deleted file mode 100644 index 19e43317eb..0000000000 --- a/java/sca/modules/implementation-osgi/src/test/java/calculator/AddService.java +++ /dev/null @@ -1,31 +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.Remotable; - -/** - * The interface for the add service - */ -@Remotable -public interface AddService { - - double add(double n1, double n2); - -} diff --git a/java/sca/modules/implementation-osgi/src/test/java/calculator/AddServiceImpl.java b/java/sca/modules/implementation-osgi/src/test/java/calculator/AddServiceImpl.java deleted file mode 100644 index 0865ddb5fe..0000000000 --- a/java/sca/modules/implementation-osgi/src/test/java/calculator/AddServiceImpl.java +++ /dev/null @@ -1,35 +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 java.util.logging.Level; -import java.util.logging.Logger; - -/** - * An implementation of the Add service - */ -public class AddServiceImpl implements AddService { - - public double add(double n1, double n2) { - Logger logger = Logger.getLogger("calculator"); - logger.log(Level.INFO, "Adding " + n1 + " and " + n2); - return n1 + n2; - } - -} diff --git a/java/sca/modules/implementation-osgi/src/test/java/calculator/CalculatorActivator.java b/java/sca/modules/implementation-osgi/src/test/java/calculator/CalculatorActivator.java index a7b6b748b1..b06474cb46 100644 --- a/java/sca/modules/implementation-osgi/src/test/java/calculator/CalculatorActivator.java +++ b/java/sca/modules/implementation-osgi/src/test/java/calculator/CalculatorActivator.java @@ -21,6 +21,7 @@ package calculator; import java.util.Dictionary; import java.util.Hashtable; +import java.util.logging.Logger; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; @@ -30,18 +31,20 @@ import org.osgi.framework.ServiceRegistration; * */ public class CalculatorActivator implements BundleActivator { + private Logger logger = Logger.getLogger(CalculatorActivator.class.getName()); + private ServiceRegistration registration; public void start(BundleContext context) throws Exception { Dictionary props = new Hashtable(); props.put("sca.service", "CalculatorComponent#service-name(Calculator)"); - registration = context.registerService(CalculatorService.class.getName(), - new CalculatorServiceImpl(), - props); + logger.info("Registering " + CalculatorService.class.getName()); + registration = context.registerService(CalculatorService.class.getName(), new CalculatorServiceImpl(), props); } public void stop(BundleContext context) throws Exception { - context.ungetService(registration.getReference()); + logger.info("UnRegistering " + registration); + registration.unregister(); } } diff --git a/java/sca/modules/implementation-osgi/src/test/java/calculator/CalculatorServiceImpl.java b/java/sca/modules/implementation-osgi/src/test/java/calculator/CalculatorServiceImpl.java index bcfd8871b6..c2c65463ea 100644 --- a/java/sca/modules/implementation-osgi/src/test/java/calculator/CalculatorServiceImpl.java +++ b/java/sca/modules/implementation-osgi/src/test/java/calculator/CalculatorServiceImpl.java @@ -18,7 +18,11 @@ */ package calculator; -import org.oasisopen.sca.annotation.Reference; +import calculator.operations.AddService; +import calculator.operations.DivideService; +import calculator.operations.MultiplyService; +import calculator.operations.SubtractService; + /** * An implementation of the Calculator service. @@ -30,22 +34,18 @@ public class CalculatorServiceImpl implements CalculatorService { private MultiplyService multiplyService; private DivideService divideService; - @Reference public void setAddService(AddService addService) { this.addService = addService; } - @Reference public void setSubtractService(SubtractService subtractService) { this.subtractService = subtractService; } - @Reference public void setDivideService(DivideService divideService) { this.divideService = divideService; } - @Reference public void setMultiplyService(MultiplyService multiplyService) { this.multiplyService = multiplyService; } diff --git a/java/sca/modules/implementation-osgi/src/test/java/calculator/DivideService.java b/java/sca/modules/implementation-osgi/src/test/java/calculator/DivideService.java deleted file mode 100644 index ac05068e56..0000000000 --- a/java/sca/modules/implementation-osgi/src/test/java/calculator/DivideService.java +++ /dev/null @@ -1,31 +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.Remotable; - -/** - * The interface for the divide service - */ -@Remotable -public interface DivideService { - - double divide(double n1, double n2); - -} diff --git a/java/sca/modules/implementation-osgi/src/test/java/calculator/DivideServiceImpl.java b/java/sca/modules/implementation-osgi/src/test/java/calculator/DivideServiceImpl.java deleted file mode 100644 index cb1fe7ed48..0000000000 --- a/java/sca/modules/implementation-osgi/src/test/java/calculator/DivideServiceImpl.java +++ /dev/null @@ -1,35 +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 java.util.logging.Level; -import java.util.logging.Logger; - -/** - * An implementation of the Divide service. - */ -public class DivideServiceImpl implements DivideService { - - public double divide(double n1, double n2) { - Logger logger = Logger.getLogger("calculator"); - logger.log(Level.INFO, "Dividing " + n1 + " with " + n2); - return n1 / n2; - } - -} diff --git a/java/sca/modules/implementation-osgi/src/test/java/calculator/MultiplyService.java b/java/sca/modules/implementation-osgi/src/test/java/calculator/MultiplyService.java deleted file mode 100644 index c89e10e9e2..0000000000 --- a/java/sca/modules/implementation-osgi/src/test/java/calculator/MultiplyService.java +++ /dev/null @@ -1,31 +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.Remotable; - -/** - * The interface for the multiply service - */ -@Remotable -public interface MultiplyService { - - double multiply(double n1, double n2); - -} diff --git a/java/sca/modules/implementation-osgi/src/test/java/calculator/MultiplyServiceImpl.java b/java/sca/modules/implementation-osgi/src/test/java/calculator/MultiplyServiceImpl.java deleted file mode 100644 index 0b86bda2b7..0000000000 --- a/java/sca/modules/implementation-osgi/src/test/java/calculator/MultiplyServiceImpl.java +++ /dev/null @@ -1,35 +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 java.util.logging.Level; -import java.util.logging.Logger; - -/** - * An implementation of the Multiply service. - */ -public class MultiplyServiceImpl implements MultiplyService { - - public double multiply(double n1, double n2) { - Logger logger = Logger.getLogger("calculator"); - logger.log(Level.INFO, "Multiplying " + n1 + " with " + n2); - return n1 * n2; - } - -} diff --git a/java/sca/modules/implementation-osgi/src/test/java/calculator/OperationsActivator.java b/java/sca/modules/implementation-osgi/src/test/java/calculator/OperationsActivator.java deleted file mode 100644 index 4968191a0e..0000000000 --- a/java/sca/modules/implementation-osgi/src/test/java/calculator/OperationsActivator.java +++ /dev/null @@ -1,59 +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 java.util.ArrayList; -import java.util.Dictionary; -import java.util.Hashtable; -import java.util.List; -import java.util.logging.Logger; - -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceRegistration; - -/** - * - */ -public class OperationsActivator implements BundleActivator { - private Logger logger = Logger.getLogger(OperationsActivator.class.getName()); - - private List registrations = new ArrayList(); - - public void start(BundleContext context) throws Exception { - Dictionary props = new Hashtable(); - props.put("sca.service", "AddComponent#service-name(Add)"); - registrations.add(context.registerService(AddService.class.getName(), new AddServiceImpl(), props)); - props.put("sca.service", "SubtractComponent#service-name(Subtract)"); - registrations.add(context.registerService(SubtractService.class.getName(), new SubtractServiceImpl(), props)); - props.put("sca.service", "MultiplyComponent#service-name(Multiply)"); - registrations.add(context.registerService(MultiplyService.class.getName(), new MultiplyServiceImpl(), props)); - props.put("sca.service", "DivideComponent#service-name(Divide)"); - registrations.add(context.registerService(DivideService.class.getName(), new DivideServiceImpl(), props)); - } - - public void stop(BundleContext context) throws Exception { - for (ServiceRegistration registration : registrations) { - logger.info("Unregistering " + registration); - context.ungetService(registration.getReference()); - } - } - -} diff --git a/java/sca/modules/implementation-osgi/src/test/java/calculator/SubtractService.java b/java/sca/modules/implementation-osgi/src/test/java/calculator/SubtractService.java deleted file mode 100644 index 3326a08a3b..0000000000 --- a/java/sca/modules/implementation-osgi/src/test/java/calculator/SubtractService.java +++ /dev/null @@ -1,31 +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.Remotable; - -/** - * The interface for the subtract service - */ -@Remotable -public interface SubtractService { - - double subtract(double n1, double n2); - -} diff --git a/java/sca/modules/implementation-osgi/src/test/java/calculator/SubtractServiceImpl.java b/java/sca/modules/implementation-osgi/src/test/java/calculator/SubtractServiceImpl.java deleted file mode 100644 index 610803dab7..0000000000 --- a/java/sca/modules/implementation-osgi/src/test/java/calculator/SubtractServiceImpl.java +++ /dev/null @@ -1,35 +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 java.util.logging.Level; -import java.util.logging.Logger; - -/** - * An implementation of the subtract service. - */ -public class SubtractServiceImpl implements SubtractService { - - public double subtract(double n1, double n2) { - Logger logger = Logger.getLogger("calculator"); - logger.log(Level.INFO, "Subtracting " + n1 + " from " + n2); - return n1 - n2; - } - -} diff --git a/java/sca/modules/implementation-osgi/src/test/java/calculator/operations/AddService.java b/java/sca/modules/implementation-osgi/src/test/java/calculator/operations/AddService.java new file mode 100644 index 0000000000..2fe405a322 --- /dev/null +++ b/java/sca/modules/implementation-osgi/src/test/java/calculator/operations/AddService.java @@ -0,0 +1,31 @@ +/* + * 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.operations; + +import org.oasisopen.sca.annotation.Remotable; + +/** + * The interface for the add service + */ +@Remotable +public interface AddService { + + double add(double n1, double n2); + +} diff --git a/java/sca/modules/implementation-osgi/src/test/java/calculator/operations/AddServiceImpl.java b/java/sca/modules/implementation-osgi/src/test/java/calculator/operations/AddServiceImpl.java new file mode 100644 index 0000000000..685d641b1c --- /dev/null +++ b/java/sca/modules/implementation-osgi/src/test/java/calculator/operations/AddServiceImpl.java @@ -0,0 +1,35 @@ +/* + * 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.operations; + +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * An implementation of the Add service + */ +public class AddServiceImpl implements AddService { + + public double add(double n1, double n2) { + Logger logger = Logger.getLogger("calculator"); + logger.log(Level.INFO, "Adding " + n1 + " and " + n2); + return n1 + n2; + } + +} diff --git a/java/sca/modules/implementation-osgi/src/test/java/calculator/operations/DivideService.java b/java/sca/modules/implementation-osgi/src/test/java/calculator/operations/DivideService.java new file mode 100644 index 0000000000..dfc5df6784 --- /dev/null +++ b/java/sca/modules/implementation-osgi/src/test/java/calculator/operations/DivideService.java @@ -0,0 +1,31 @@ +/* + * 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.operations; + +import org.oasisopen.sca.annotation.Remotable; + +/** + * The interface for the divide service + */ +@Remotable +public interface DivideService { + + double divide(double n1, double n2); + +} diff --git a/java/sca/modules/implementation-osgi/src/test/java/calculator/operations/DivideServiceImpl.java b/java/sca/modules/implementation-osgi/src/test/java/calculator/operations/DivideServiceImpl.java new file mode 100644 index 0000000000..945b0315b0 --- /dev/null +++ b/java/sca/modules/implementation-osgi/src/test/java/calculator/operations/DivideServiceImpl.java @@ -0,0 +1,35 @@ +/* + * 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.operations; + +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * An implementation of the Divide service. + */ +public class DivideServiceImpl implements DivideService { + + public double divide(double n1, double n2) { + Logger logger = Logger.getLogger("calculator"); + logger.log(Level.INFO, "Dividing " + n1 + " with " + n2); + return n1 / n2; + } + +} diff --git a/java/sca/modules/implementation-osgi/src/test/java/calculator/operations/MultiplyService.java b/java/sca/modules/implementation-osgi/src/test/java/calculator/operations/MultiplyService.java new file mode 100644 index 0000000000..b70c233f1a --- /dev/null +++ b/java/sca/modules/implementation-osgi/src/test/java/calculator/operations/MultiplyService.java @@ -0,0 +1,31 @@ +/* + * 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.operations; + +import org.oasisopen.sca.annotation.Remotable; + +/** + * The interface for the multiply service + */ +@Remotable +public interface MultiplyService { + + double multiply(double n1, double n2); + +} diff --git a/java/sca/modules/implementation-osgi/src/test/java/calculator/operations/MultiplyServiceImpl.java b/java/sca/modules/implementation-osgi/src/test/java/calculator/operations/MultiplyServiceImpl.java new file mode 100644 index 0000000000..175322c14d --- /dev/null +++ b/java/sca/modules/implementation-osgi/src/test/java/calculator/operations/MultiplyServiceImpl.java @@ -0,0 +1,35 @@ +/* + * 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.operations; + +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * An implementation of the Multiply service. + */ +public class MultiplyServiceImpl implements MultiplyService { + + public double multiply(double n1, double n2) { + Logger logger = Logger.getLogger("calculator"); + logger.log(Level.INFO, "Multiplying " + n1 + " with " + n2); + return n1 * n2; + } + +} diff --git a/java/sca/modules/implementation-osgi/src/test/java/calculator/operations/OperationsActivator.java b/java/sca/modules/implementation-osgi/src/test/java/calculator/operations/OperationsActivator.java new file mode 100644 index 0000000000..03260b312b --- /dev/null +++ b/java/sca/modules/implementation-osgi/src/test/java/calculator/operations/OperationsActivator.java @@ -0,0 +1,67 @@ +/* + * 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.operations; + +import java.util.ArrayList; +import java.util.Dictionary; +import java.util.Hashtable; +import java.util.List; +import java.util.logging.Logger; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceRegistration; + +/** + * + */ +public class OperationsActivator implements BundleActivator { + private Logger logger = Logger.getLogger(OperationsActivator.class.getName()); + + private List registrations = new ArrayList(); + + public void start(BundleContext context) throws Exception { + Dictionary props = new Hashtable(); + + logger.info("Registering " + AddService.class.getName()); + props.put("sca.service", "AddComponent#service-name(Add)"); + registrations.add(context.registerService(AddService.class.getName(), new AddServiceImpl(), props)); + + logger.info("Registering " + SubtractService.class.getName()); + props.put("sca.service", "SubtractComponent#service-name(Subtract)"); + registrations.add(context.registerService(SubtractService.class.getName(), new SubtractServiceImpl(), props)); + + logger.info("Registering " + MultiplyService.class.getName()); + props.put("sca.service", "MultiplyComponent#service-name(Multiply)"); + registrations.add(context.registerService(MultiplyService.class.getName(), new MultiplyServiceImpl(), props)); + + logger.info("Registering " + DivideService.class.getName()); + props.put("sca.service", "DivideComponent#service-name(Divide)"); + registrations.add(context.registerService(DivideService.class.getName(), new DivideServiceImpl(), props)); + } + + public void stop(BundleContext context) throws Exception { + for (ServiceRegistration registration : registrations) { + logger.info("Unregistering " + registration); + registration.unregister(); + } + } + +} diff --git a/java/sca/modules/implementation-osgi/src/test/java/calculator/operations/SubtractService.java b/java/sca/modules/implementation-osgi/src/test/java/calculator/operations/SubtractService.java new file mode 100644 index 0000000000..1d83a23229 --- /dev/null +++ b/java/sca/modules/implementation-osgi/src/test/java/calculator/operations/SubtractService.java @@ -0,0 +1,31 @@ +/* + * 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.operations; + +import org.oasisopen.sca.annotation.Remotable; + +/** + * The interface for the subtract service + */ +@Remotable +public interface SubtractService { + + double subtract(double n1, double n2); + +} diff --git a/java/sca/modules/implementation-osgi/src/test/java/calculator/operations/SubtractServiceImpl.java b/java/sca/modules/implementation-osgi/src/test/java/calculator/operations/SubtractServiceImpl.java new file mode 100644 index 0000000000..cf1744bc61 --- /dev/null +++ b/java/sca/modules/implementation-osgi/src/test/java/calculator/operations/SubtractServiceImpl.java @@ -0,0 +1,35 @@ +/* + * 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.operations; + +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * An implementation of the subtract service. + */ +public class SubtractServiceImpl implements SubtractService { + + public double subtract(double n1, double n2) { + Logger logger = Logger.getLogger("calculator"); + logger.log(Level.INFO, "Subtracting " + n1 + " from " + n2); + return n1 - n2; + } + +} diff --git a/java/sca/modules/implementation-osgi/src/test/java/calculator/test/CalculatorOSGiTestCase.java b/java/sca/modules/implementation-osgi/src/test/java/calculator/test/CalculatorOSGiTestCase.java new file mode 100644 index 0000000000..1d37e69a03 --- /dev/null +++ b/java/sca/modules/implementation-osgi/src/test/java/calculator/test/CalculatorOSGiTestCase.java @@ -0,0 +1,104 @@ +/* + * 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.test; + +import java.net.URL; +import java.util.HashSet; +import java.util.Set; + +import org.apache.tuscany.sca.implementation.osgi.test.OSGiTestBundles; +import org.apache.tuscany.sca.node.equinox.launcher.EquinoxHost; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; + +import calculator.CalculatorActivator; +import calculator.CalculatorService; +import calculator.CalculatorServiceImpl; +import calculator.operations.AddService; +import calculator.operations.AddServiceImpl; +import calculator.operations.DivideService; +import calculator.operations.DivideServiceImpl; +import calculator.operations.MultiplyService; +import calculator.operations.MultiplyServiceImpl; +import calculator.operations.OperationsActivator; +import calculator.operations.SubtractService; +import calculator.operations.SubtractServiceImpl; + +/** + * + */ +public class CalculatorOSGiTestCase { + private static EquinoxHost host; + + /** + * @throws java.lang.Exception + */ + @BeforeClass + public static void setUpBeforeClass() throws Exception { + Set bundles = new HashSet(); + bundles.add(OSGiTestBundles.createBundle("target/test-classes/calculator-bundle.jar", + "calculator", + "calculator.operations", + CalculatorService.class, + CalculatorServiceImpl.class, CalculatorActivator.class)); + + bundles.add(OSGiTestBundles.createBundle("target/test-classes/operations-bundle.jar", + "operations", + null, + OperationsActivator.class, + AddService.class, + AddServiceImpl.class, + SubtractService.class, + SubtractServiceImpl.class, + MultiplyService.class, + MultiplyServiceImpl.class, + DivideService.class, DivideServiceImpl.class)); + try { + host = new EquinoxHost(bundles); + BundleContext context = host.start(); + for (Bundle b : context.getBundles()) { + System.out.println(b); + b.start(); + } + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testOSGi() { + + } + + /** + * @throws java.lang.Exception + */ + @AfterClass + public static void tearDownAfterClass() throws Exception { + if (host != null) { + host.stop(); + } + } + +} diff --git a/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTestCase.java b/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTestCase.java index 76f41a6021..92d99a04ba 100644 --- a/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTestCase.java +++ b/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTestCase.java @@ -52,8 +52,8 @@ public class OSGiTestCase { compositeName = "osgitest.composite"; OSGiTestBundles.createBundle("target/test-classes/OSGiTestService.jar", OSGiTestInterface.class.getName(), - OSGiTestImpl.class, - OSGiTestInterface.class); + null, + OSGiTestImpl.class, OSGiTestInterface.class); node = host.createNode("osgitest.composite", new Contribution("c1", new File("target/test-classes").toURI() diff --git a/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestBundles.java b/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestBundles.java index 882f29126e..15cbd77c4e 100644 --- a/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestBundles.java +++ b/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestBundles.java @@ -20,11 +20,14 @@ package org.apache.tuscany.sca.implementation.osgi.test; import java.io.ByteArrayOutputStream; +import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.net.URL; +import java.util.HashSet; +import java.util.Set; import java.util.jar.JarOutputStream; import java.util.jar.Manifest; import java.util.zip.ZipEntry; @@ -45,16 +48,21 @@ public class OSGiTestBundles { return index == -1 ? "" : name.substring(0, index); } - public static void createBundle(String jarName, String bundleName, Class... classes) throws Exception { + public static URL createBundle(String jarName, String bundleName, String imports, Class... classes) + throws Exception { Class activator = null; + Set packages = new HashSet(); StringBuffer exports = new StringBuffer(); for (Class cls : classes) { - if (cls.isAssignableFrom(BundleActivator.class)) { + if (BundleActivator.class.isAssignableFrom(cls)) { activator = cls; } if (cls.isInterface()) { - exports.append(getPackageName(cls)).append(","); + String pkg = getPackageName(cls); + if (packages.add(pkg)) { + exports.append(pkg).append(","); + } } } if (exports.length() > 0) { @@ -62,12 +70,20 @@ public class OSGiTestBundles { } Manifest manifest = new Manifest(); + // This attribute Manifest-Version is required so that the MF will be added to the jar + manifest.getMainAttributes().putValue("Manifest-Version", "1.0"); manifest.getMainAttributes().putValue(Constants.BUNDLE_MANIFESTVERSION, "2"); manifest.getMainAttributes().putValue(Constants.BUNDLE_SYMBOLICNAME, bundleName); manifest.getMainAttributes().putValue(Constants.BUNDLE_VERSION, "1.0.0"); manifest.getMainAttributes().putValue(Constants.BUNDLE_NAME, bundleName); manifest.getMainAttributes().putValue(Constants.EXPORT_PACKAGE, exports.toString()); - manifest.getMainAttributes().putValue(Constants.IMPORT_PACKAGE, "org.osgi.framework," + exports.toString()); + String importPackages = null; + if (imports != null) { + importPackages = "org.osgi.framework," + imports; + } else { + importPackages = "org.osgi.framework"; + } + manifest.getMainAttributes().putValue(Constants.IMPORT_PACKAGE, importPackages); if (activator != null) { manifest.getMainAttributes().putValue(Constants.BUNDLE_ACTIVATOR, activator.getName()); @@ -83,10 +99,12 @@ public class OSGiTestBundles { jarOut.close(); out.close(); - FileOutputStream fileOut = new FileOutputStream(jarName); + File jar = new File(jarName); + FileOutputStream fileOut = new FileOutputStream(jar); fileOut.write(out.toByteArray()); fileOut.close(); + return jar.toURI().toURL(); } private static void addClass(JarOutputStream jarOut, Class javaClass) throws IOException, FileNotFoundException { @@ -102,5 +120,6 @@ public class OSGiTestBundles { byte[] fileContents = new byte[file.available()]; file.read(fileContents); jarOut.write(fileContents); + jarOut.closeEntry(); } } diff --git a/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiReadImplTestCase.java b/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiReadImplTestCase.java index c4c7f502ed..ca458a2d4e 100644 --- a/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiReadImplTestCase.java +++ b/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiReadImplTestCase.java @@ -72,8 +72,8 @@ public class OSGiReadImplTestCase { OSGiTestBundles.createBundle("target/test-classes/OSGiTestService.jar", OSGiTestInterface.class.getName(), - OSGiTestImpl.class, - OSGiTestInterface.class); + null, + OSGiTestImpl.class, OSGiTestInterface.class); } -- cgit v1.2.3