From 3c7c4a749baafcf375f4785a7668d3a25c9063e3 Mon Sep 17 00:00:00 2001 From: lresende Date: Fri, 13 Nov 2009 01:42:27 +0000 Subject: Moving 1.x trunk git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835700 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/supplychain/client/SupplyChainClient.java | 115 +++++++++++++++++++++ .../main/java/supplychain/customer/Customer.java | 37 +++++++ .../customer/JavaCustomerComponentImpl.java | 61 +++++++++++ .../retailer/JavaRetailerComponentImpl.java | 59 +++++++++++ .../main/java/supplychain/retailer/Retailer.java | 28 +++++ .../shipper/JavaShipperComponentImpl.java | 50 +++++++++ .../src/main/java/supplychain/shipper/Shipper.java | 28 +++++ .../warehouse/JavaWarehouseComponentImpl.java | 49 +++++++++ .../main/java/supplychain/warehouse/Warehouse.java | 28 +++++ 9 files changed, 455 insertions(+) create mode 100644 sca-java-1.x/trunk/itest/osgi-tuscany/test-bundles/src/main/java/supplychain/client/SupplyChainClient.java create mode 100644 sca-java-1.x/trunk/itest/osgi-tuscany/test-bundles/src/main/java/supplychain/customer/Customer.java create mode 100644 sca-java-1.x/trunk/itest/osgi-tuscany/test-bundles/src/main/java/supplychain/customer/JavaCustomerComponentImpl.java create mode 100644 sca-java-1.x/trunk/itest/osgi-tuscany/test-bundles/src/main/java/supplychain/retailer/JavaRetailerComponentImpl.java create mode 100644 sca-java-1.x/trunk/itest/osgi-tuscany/test-bundles/src/main/java/supplychain/retailer/Retailer.java create mode 100644 sca-java-1.x/trunk/itest/osgi-tuscany/test-bundles/src/main/java/supplychain/shipper/JavaShipperComponentImpl.java create mode 100644 sca-java-1.x/trunk/itest/osgi-tuscany/test-bundles/src/main/java/supplychain/shipper/Shipper.java create mode 100644 sca-java-1.x/trunk/itest/osgi-tuscany/test-bundles/src/main/java/supplychain/warehouse/JavaWarehouseComponentImpl.java create mode 100644 sca-java-1.x/trunk/itest/osgi-tuscany/test-bundles/src/main/java/supplychain/warehouse/Warehouse.java (limited to 'sca-java-1.x/trunk/itest/osgi-tuscany/test-bundles/src/main/java/supplychain') diff --git a/sca-java-1.x/trunk/itest/osgi-tuscany/test-bundles/src/main/java/supplychain/client/SupplyChainClient.java b/sca-java-1.x/trunk/itest/osgi-tuscany/test-bundles/src/main/java/supplychain/client/SupplyChainClient.java new file mode 100644 index 0000000000..0ac96b35a3 --- /dev/null +++ b/sca-java-1.x/trunk/itest/osgi-tuscany/test-bundles/src/main/java/supplychain/client/SupplyChainClient.java @@ -0,0 +1,115 @@ +/* + * 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 supplychain.client; + + +import java.io.File; +import java.net.URL; +import java.util.Hashtable; + + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.service.ContributionService; +import org.apache.tuscany.sca.host.embedded.impl.EmbeddedSCADomain; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; + + + +import supplychain.customer.Customer; + +/** + * SupplyChain test client + */ +public class SupplyChainClient implements BundleActivator { + + private EmbeddedSCADomain scaDomain; + private Customer customer; + + + + public void start(BundleContext context) throws Exception { + + context.registerService(SupplyChainClient.class.getName(), this, new Hashtable()); + + } + + public void stop(BundleContext context) throws Exception { + + } + + protected void setUp(String contributionJarName) throws Exception { + + scaDomain = new EmbeddedSCADomain(EmbeddedSCADomain.class.getClassLoader(), "http://localhost"); + scaDomain.start(); + ContributionService contributionService = scaDomain.getContributionService(); + String folderName = "../test-bundles/target/"; + String supplychainJarName = contributionJarName; + URL supplyChainURL = new File(folderName + supplychainJarName).toURI().toURL(); + + Contribution contribution = contributionService.contribute("SupplyChain", supplyChainURL, false); + for (Composite deployable : contribution.getDeployables() ) { + scaDomain.getDomainComposite().getIncludes().add(deployable); + scaDomain.buildComposite(deployable); + } + + for (Composite deployable : contribution.getDeployables() ) { + scaDomain.getCompositeActivator().activate(deployable); + scaDomain.getCompositeActivator().start(deployable); + } + customer = scaDomain.getService(Customer.class, "CustomerComponent"); + } + + protected void tearDown() throws Exception { + if (scaDomain != null) { + scaDomain.close(); + scaDomain = null; + } + } + + + public void runTest(String contributionJarName) throws Exception { + + try { + setUp(contributionJarName); + customer.purchaseGoods(); + int retries = 10; + int outstandingCount = 1; + while (retries-- > 0) { + + outstandingCount = customer.outstandingOrderCount(); + if (outstandingCount == 0) + break; + else + Thread.sleep(100); + } + if (outstandingCount != 0) + throw new RuntimeException("Orders not processed on time"); + + } finally { + + tearDown(); + } + + + } + + +} diff --git a/sca-java-1.x/trunk/itest/osgi-tuscany/test-bundles/src/main/java/supplychain/customer/Customer.java b/sca-java-1.x/trunk/itest/osgi-tuscany/test-bundles/src/main/java/supplychain/customer/Customer.java new file mode 100644 index 0000000000..a3aa2531fc --- /dev/null +++ b/sca-java-1.x/trunk/itest/osgi-tuscany/test-bundles/src/main/java/supplychain/customer/Customer.java @@ -0,0 +1,37 @@ +/* + * 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 supplychain.customer; + +import org.osoa.sca.annotations.OneWay; +import org.osoa.sca.annotations.Remotable; + +/** + * This is the business interface of the Customer service component. + */ +@Remotable +public interface Customer { + + public void purchaseGoods(); + + @OneWay + public void notifyShipment(String order); + + public int outstandingOrderCount(); + +} diff --git a/sca-java-1.x/trunk/itest/osgi-tuscany/test-bundles/src/main/java/supplychain/customer/JavaCustomerComponentImpl.java b/sca-java-1.x/trunk/itest/osgi-tuscany/test-bundles/src/main/java/supplychain/customer/JavaCustomerComponentImpl.java new file mode 100644 index 0000000000..5f1342c40b --- /dev/null +++ b/sca-java-1.x/trunk/itest/osgi-tuscany/test-bundles/src/main/java/supplychain/customer/JavaCustomerComponentImpl.java @@ -0,0 +1,61 @@ +/* + * 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 supplychain.customer; + +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Scope; +import org.osoa.sca.annotations.Service; + +import supplychain.retailer.Retailer; + +/** + * This class implements the Customer service component (POJO implementation). + */ +@Service(Customer.class) +@Scope("COMPOSITE") +public class JavaCustomerComponentImpl implements Customer { + + private static int outstandingOrderCount; + + private Retailer retailer; + + public JavaCustomerComponentImpl() { + } + + @Reference + public void setRetailer(Retailer retailer) { + this.retailer = retailer; + } + + public void purchaseGoods() { + outstandingOrderCount++; + retailer.submitOrder("Order"); + } + + public void notifyShipment(String order) { + outstandingOrderCount--; + System.out.print("Work thread " + Thread.currentThread() + " - "); + System.out.println(order); + } + + public int outstandingOrderCount() { + return outstandingOrderCount; + } + +} diff --git a/sca-java-1.x/trunk/itest/osgi-tuscany/test-bundles/src/main/java/supplychain/retailer/JavaRetailerComponentImpl.java b/sca-java-1.x/trunk/itest/osgi-tuscany/test-bundles/src/main/java/supplychain/retailer/JavaRetailerComponentImpl.java new file mode 100644 index 0000000000..f5708dec40 --- /dev/null +++ b/sca-java-1.x/trunk/itest/osgi-tuscany/test-bundles/src/main/java/supplychain/retailer/JavaRetailerComponentImpl.java @@ -0,0 +1,59 @@ +/* + * 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 supplychain.retailer; + + +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Scope; +import org.osoa.sca.annotations.Service; + +import supplychain.warehouse.Warehouse; + +/** + * This class implements the Retailer service component (POJO implementation). + */ +@Service(Retailer.class) +@Scope("STATELESS") +public class JavaRetailerComponentImpl implements Retailer { + + private Warehouse warehouse; + + public JavaRetailerComponentImpl() { + } + + @Reference + public void setWarehouse(Warehouse warehouse) { + this.warehouse = warehouse; + } + + + public Warehouse getWarehouse() { + return warehouse; + } + + public void submitOrder(String order) { + + warehouse.fulfillOrder(order + ", submitted"); + + } + + + + +} diff --git a/sca-java-1.x/trunk/itest/osgi-tuscany/test-bundles/src/main/java/supplychain/retailer/Retailer.java b/sca-java-1.x/trunk/itest/osgi-tuscany/test-bundles/src/main/java/supplychain/retailer/Retailer.java new file mode 100644 index 0000000000..17b342f8dd --- /dev/null +++ b/sca-java-1.x/trunk/itest/osgi-tuscany/test-bundles/src/main/java/supplychain/retailer/Retailer.java @@ -0,0 +1,28 @@ +/* + * 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 supplychain.retailer; + +/** + * This is the business interface of the Retailer service component. + */ +public interface Retailer { + + public void submitOrder(String order); + +} diff --git a/sca-java-1.x/trunk/itest/osgi-tuscany/test-bundles/src/main/java/supplychain/shipper/JavaShipperComponentImpl.java b/sca-java-1.x/trunk/itest/osgi-tuscany/test-bundles/src/main/java/supplychain/shipper/JavaShipperComponentImpl.java new file mode 100644 index 0000000000..afaf7aea02 --- /dev/null +++ b/sca-java-1.x/trunk/itest/osgi-tuscany/test-bundles/src/main/java/supplychain/shipper/JavaShipperComponentImpl.java @@ -0,0 +1,50 @@ +/* + * 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 supplychain.shipper; + + +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Scope; +import org.osoa.sca.annotations.Service; + +import supplychain.customer.Customer; + +/** + * This class implements the Shipper service component (POJO implementation). + */ +@Service(Shipper.class) +@Scope("COMPOSITE") +public class JavaShipperComponentImpl implements Shipper { + + private Customer customer; + + public JavaShipperComponentImpl() { + } + + @Reference + public void setCustomer(Customer customer) { + this.customer = customer; + } + + public void processShipment(String order) { + customer.notifyShipment(order + ", shipped"); + } + + +} diff --git a/sca-java-1.x/trunk/itest/osgi-tuscany/test-bundles/src/main/java/supplychain/shipper/Shipper.java b/sca-java-1.x/trunk/itest/osgi-tuscany/test-bundles/src/main/java/supplychain/shipper/Shipper.java new file mode 100644 index 0000000000..cd204ebc2e --- /dev/null +++ b/sca-java-1.x/trunk/itest/osgi-tuscany/test-bundles/src/main/java/supplychain/shipper/Shipper.java @@ -0,0 +1,28 @@ +/* + * 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 supplychain.shipper; + +/** + * This is the business interface of the Shipper service component. + */ +public interface Shipper { + + public void processShipment(String order); + +} diff --git a/sca-java-1.x/trunk/itest/osgi-tuscany/test-bundles/src/main/java/supplychain/warehouse/JavaWarehouseComponentImpl.java b/sca-java-1.x/trunk/itest/osgi-tuscany/test-bundles/src/main/java/supplychain/warehouse/JavaWarehouseComponentImpl.java new file mode 100644 index 0000000000..ca720085c5 --- /dev/null +++ b/sca-java-1.x/trunk/itest/osgi-tuscany/test-bundles/src/main/java/supplychain/warehouse/JavaWarehouseComponentImpl.java @@ -0,0 +1,49 @@ +/* + * 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 supplychain.warehouse; + +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Scope; +import org.osoa.sca.annotations.Service; + +import supplychain.shipper.Shipper; + +/** + * This class implements the Warehouse service component (POJO implementation). + */ +@Service(Warehouse.class) +@Scope("STATELESS") +public class JavaWarehouseComponentImpl implements Warehouse { + + private Shipper shipper; + + public JavaWarehouseComponentImpl() { + } + + @Reference + public void setShipper(Shipper shipper) { + this.shipper = shipper; + } + + public void fulfillOrder(String order) { + shipper.processShipment(order + ", fulfilled"); + } + + +} diff --git a/sca-java-1.x/trunk/itest/osgi-tuscany/test-bundles/src/main/java/supplychain/warehouse/Warehouse.java b/sca-java-1.x/trunk/itest/osgi-tuscany/test-bundles/src/main/java/supplychain/warehouse/Warehouse.java new file mode 100644 index 0000000000..b4807b80d1 --- /dev/null +++ b/sca-java-1.x/trunk/itest/osgi-tuscany/test-bundles/src/main/java/supplychain/warehouse/Warehouse.java @@ -0,0 +1,28 @@ +/* + * 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 supplychain.warehouse; + +/** + * This is the business interface of the Warehouse service component. + */ +public interface Warehouse { + + public void fulfillOrder(String order); + +} -- cgit v1.2.3