From 3fb2e332a5ea00056419dcf422e07ae0d00dbce0 Mon Sep 17 00:00:00 2001 From: lresende Date: Wed, 30 Mar 2011 06:09:42 +0000 Subject: Starting to port store sample to next release git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1086849 13f79535-47bb-0310-9956-ffa450edef68 --- sca-java-2.x/trunk/samples/applications/pom.xml | 36 +++ .../trunk/samples/applications/store/README | 28 ++ .../trunk/samples/applications/store/build.xml | 82 ++++++ .../trunk/samples/applications/store/pom.xml | 114 ++++++++ .../store/src/main/java/launch/Launch.java | 39 +++ .../store/src/main/java/services/Cart.java | 28 ++ .../store/src/main/java/services/Catalog.java | 27 ++ .../src/main/java/services/CurrencyConverter.java | 29 ++ .../main/java/services/CurrencyConverterImpl.java | 38 +++ .../src/main/java/services/FruitsCatalogImpl.java | 52 ++++ .../store/src/main/java/services/Item.java | 54 ++++ .../src/main/java/services/ShoppingCartImpl.java | 112 ++++++++ .../store/src/main/java/services/Total.java | 29 ++ .../store/src/main/resources/store.composite | 58 ++++ .../store/src/main/resources/uiservices/store.html | 162 +++++++++++ .../store/src/test/java/client/Shopper.java | 29 ++ .../store/src/test/java/client/ShopperImpl.java | 64 +++++ .../store/src/test/java/store/StoreTestCase.java | 121 ++++++++ .../src/test/resources/store-client.composite | 38 +++ .../trunk/samples/applications/store/store.png | Bin 0 -> 15670 bytes .../trunk/samples/applications/store/store.svg | 304 +++++++++++++++++++++ .../getting-started/helloworld-scaclient/pom.xml | 2 +- .../getting-started/helloworld-webapp/pom.xml | 2 +- .../samples/getting-started/helloworld/pom.xml | 2 +- sca-java-2.x/trunk/samples/getting-started/pom.xml | 2 +- sca-java-2.x/trunk/samples/pom.xml | 2 +- 26 files changed, 1449 insertions(+), 5 deletions(-) create mode 100644 sca-java-2.x/trunk/samples/applications/pom.xml create mode 100644 sca-java-2.x/trunk/samples/applications/store/README create mode 100644 sca-java-2.x/trunk/samples/applications/store/build.xml create mode 100644 sca-java-2.x/trunk/samples/applications/store/pom.xml create mode 100644 sca-java-2.x/trunk/samples/applications/store/src/main/java/launch/Launch.java create mode 100644 sca-java-2.x/trunk/samples/applications/store/src/main/java/services/Cart.java create mode 100644 sca-java-2.x/trunk/samples/applications/store/src/main/java/services/Catalog.java create mode 100644 sca-java-2.x/trunk/samples/applications/store/src/main/java/services/CurrencyConverter.java create mode 100644 sca-java-2.x/trunk/samples/applications/store/src/main/java/services/CurrencyConverterImpl.java create mode 100644 sca-java-2.x/trunk/samples/applications/store/src/main/java/services/FruitsCatalogImpl.java create mode 100644 sca-java-2.x/trunk/samples/applications/store/src/main/java/services/Item.java create mode 100644 sca-java-2.x/trunk/samples/applications/store/src/main/java/services/ShoppingCartImpl.java create mode 100644 sca-java-2.x/trunk/samples/applications/store/src/main/java/services/Total.java create mode 100644 sca-java-2.x/trunk/samples/applications/store/src/main/resources/store.composite create mode 100644 sca-java-2.x/trunk/samples/applications/store/src/main/resources/uiservices/store.html create mode 100644 sca-java-2.x/trunk/samples/applications/store/src/test/java/client/Shopper.java create mode 100644 sca-java-2.x/trunk/samples/applications/store/src/test/java/client/ShopperImpl.java create mode 100644 sca-java-2.x/trunk/samples/applications/store/src/test/java/store/StoreTestCase.java create mode 100644 sca-java-2.x/trunk/samples/applications/store/src/test/resources/store-client.composite create mode 100644 sca-java-2.x/trunk/samples/applications/store/store.png create mode 100644 sca-java-2.x/trunk/samples/applications/store/store.svg (limited to 'sca-java-2.x/trunk') diff --git a/sca-java-2.x/trunk/samples/applications/pom.xml b/sca-java-2.x/trunk/samples/applications/pom.xml new file mode 100644 index 0000000000..039b6dca16 --- /dev/null +++ b/sca-java-2.x/trunk/samples/applications/pom.xml @@ -0,0 +1,36 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-samples + 2.0-SNAPSHOT + + + tuscany-samples-applications + 2.0-SNAPSHOT + pom + Apache Tuscany Sample Applications + + + store + + diff --git a/sca-java-2.x/trunk/samples/applications/store/README b/sca-java-2.x/trunk/samples/applications/store/README new file mode 100644 index 0000000000..d31e4c59b7 --- /dev/null +++ b/sca-java-2.x/trunk/samples/applications/store/README @@ -0,0 +1,28 @@ +Store Sample +====================================== + +This is a sample store scenario that is used as a getting started guide +for Tuscany SCA. For detailed information, please see: + +http://tuscany.apache.org/getting-started-with-tuscany.html + +or + +http://tuscany.apache.org/getting-started-with-tuscany-using-tuscany-eclipse-plugin.html + + +Building And Running The Sample Using Ant +----------------------------------------- +With the binary distribution the sample can be built using Ant as follows: + +cd store +ant compile + +and then, to run: + +ant run + +Once the store application is running use your browser to visit the following +URL: + +http://localhost:8080/store diff --git a/sca-java-2.x/trunk/samples/applications/store/build.xml b/sca-java-2.x/trunk/samples/applications/store/build.xml new file mode 100644 index 0000000000..e28e7c87be --- /dev/null +++ b/sca-java-2.x/trunk/samples/applications/store/build.xml @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-2.x/trunk/samples/applications/store/pom.xml b/sca-java-2.x/trunk/samples/applications/store/pom.xml new file mode 100644 index 0000000000..c088d528da --- /dev/null +++ b/sca-java-2.x/trunk/samples/applications/store/pom.xml @@ -0,0 +1,114 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-samples + 2.0-SNAPSHOT + + sample-store + Apache Tuscany SCA Sample Getting Started Online Store + + + + org.apache.tuscany.sca + tuscany-base-runtime-pom + 2.0-SNAPSHOT + pom + + + org.apache.tuscany.sca + tuscany-data-api + 2.0-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-binding-atom-runtime + 2.0-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-binding-http-runtime + 2.0-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-binding-jsonrpc-runtime + 2.0-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-implementation-widget-runtime + 2.0-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-implementation-widget-runtime-dojo + 2.0-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-web-javascript-dojo + 2.0-SNAPSHOT + + + org.mortbay.jetty + jetty + 6.1.19 + test + + + net.sourceforge.htmlunit + htmlunit + 2.6 + test + + + junit + junit + 4.8.1 + test + + + + + ${project.artifactId} + + + org.codehaus.mojo + exec-maven-plugin + 1.1.1 + + + + java + + + + + test + store.StoreTestCase + + + + + + diff --git a/sca-java-2.x/trunk/samples/applications/store/src/main/java/launch/Launch.java b/sca-java-2.x/trunk/samples/applications/store/src/main/java/launch/Launch.java new file mode 100644 index 0000000000..8e4b5839e4 --- /dev/null +++ b/sca-java-2.x/trunk/samples/applications/store/src/main/java/launch/Launch.java @@ -0,0 +1,39 @@ +/* + * 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 launch; + +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; + +public class Launch { + public static void main(String[] args) throws Exception { + System.out.println("Starting ..."); + String contribution = ContributionLocationHelper.getContributionLocation(Launch.class); + Node node = NodeFactory.newInstance().createNode("store.composite", new Contribution("test", contribution)); + node.start(); + System.out.println("store.composite ready for big business !!!"); + System.in.read(); + System.out.println("Stopping ..."); + node.stop(); + System.out.println(); + } +} diff --git a/sca-java-2.x/trunk/samples/applications/store/src/main/java/services/Cart.java b/sca-java-2.x/trunk/samples/applications/store/src/main/java/services/Cart.java new file mode 100644 index 0000000000..3fb5439bc3 --- /dev/null +++ b/sca-java-2.x/trunk/samples/applications/store/src/main/java/services/Cart.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 services; + +import org.apache.tuscany.sca.data.collection.Collection; +import org.oasisopen.sca.annotation.Remotable; + +@Remotable +public interface Cart extends Collection { + +} diff --git a/sca-java-2.x/trunk/samples/applications/store/src/main/java/services/Catalog.java b/sca-java-2.x/trunk/samples/applications/store/src/main/java/services/Catalog.java new file mode 100644 index 0000000000..b5e504fe11 --- /dev/null +++ b/sca-java-2.x/trunk/samples/applications/store/src/main/java/services/Catalog.java @@ -0,0 +1,27 @@ +/* + * 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 services; + +import org.oasisopen.sca.annotation.Remotable; + +@Remotable +public interface Catalog { + Item[] get(); +} diff --git a/sca-java-2.x/trunk/samples/applications/store/src/main/java/services/CurrencyConverter.java b/sca-java-2.x/trunk/samples/applications/store/src/main/java/services/CurrencyConverter.java new file mode 100644 index 0000000000..a064f3dd69 --- /dev/null +++ b/sca-java-2.x/trunk/samples/applications/store/src/main/java/services/CurrencyConverter.java @@ -0,0 +1,29 @@ +/* + * 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 services; + +import org.oasisopen.sca.annotation.Remotable; + +@Remotable +public interface CurrencyConverter { + public double getConversion(String fromCurrenycCode, String toCurrencyCode, double amount); + + public String getCurrencySymbol(String currencyCode); +} diff --git a/sca-java-2.x/trunk/samples/applications/store/src/main/java/services/CurrencyConverterImpl.java b/sca-java-2.x/trunk/samples/applications/store/src/main/java/services/CurrencyConverterImpl.java new file mode 100644 index 0000000000..c354aed447 --- /dev/null +++ b/sca-java-2.x/trunk/samples/applications/store/src/main/java/services/CurrencyConverterImpl.java @@ -0,0 +1,38 @@ +/* + * 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 services; + +public class CurrencyConverterImpl implements CurrencyConverter { + public double getConversion(String fromCurrencyCode, String toCurrencyCode, double amount) { + if (toCurrencyCode.equals("USD")) + return amount; + else if (toCurrencyCode.equals("EUR")) + return ((double)Math.round(amount * 0.7256 * 100)) /100; + return 0; + } + + public String getCurrencySymbol(String currencyCode) { + if (currencyCode.equals("USD")) + return "$"; + else if (currencyCode.equals("EUR")) + return "E"; //"€"; + return "?"; + } +} diff --git a/sca-java-2.x/trunk/samples/applications/store/src/main/java/services/FruitsCatalogImpl.java b/sca-java-2.x/trunk/samples/applications/store/src/main/java/services/FruitsCatalogImpl.java new file mode 100644 index 0000000000..d132a24b00 --- /dev/null +++ b/sca-java-2.x/trunk/samples/applications/store/src/main/java/services/FruitsCatalogImpl.java @@ -0,0 +1,52 @@ +/* + * 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 services; + +import java.util.ArrayList; +import java.util.List; + +import org.oasisopen.sca.annotation.Init; +import org.oasisopen.sca.annotation.Property; +import org.oasisopen.sca.annotation.Reference; + +public class FruitsCatalogImpl implements Catalog { + + @Property + public String currencyCode = "USD"; + + @Reference + public CurrencyConverter currencyConverter; + + private List catalog = new ArrayList(); + + @Init + public void init() { + String currencySymbol = currencyConverter.getCurrencySymbol(currencyCode); + catalog.add(new Item("Apple", currencySymbol + currencyConverter.getConversion("USD", currencyCode, 2.99))); + catalog.add(new Item("Orange", currencySymbol + currencyConverter.getConversion("USD", currencyCode, 3.55))); + catalog.add(new Item("Pear", currencySymbol + currencyConverter.getConversion("USD", currencyCode, 1.55))); + } + + public Item[] get() { + Item[] catalogArray = new Item[catalog.size()]; + catalog.toArray(catalogArray); + return catalogArray; + } +} diff --git a/sca-java-2.x/trunk/samples/applications/store/src/main/java/services/Item.java b/sca-java-2.x/trunk/samples/applications/store/src/main/java/services/Item.java new file mode 100644 index 0000000000..0a9dcb2ffc --- /dev/null +++ b/sca-java-2.x/trunk/samples/applications/store/src/main/java/services/Item.java @@ -0,0 +1,54 @@ +/* + * 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 services; + +public class Item { + private String name; + private String price; + + public Item() { + } + + public Item(String name, String price) { + this.name = name; + this.price = price; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getPrice() { + return price; + } + + public void setPrice(String price) { + this.price = price; + } + + public String toString() { + return "Item name: " + name + ", price: " + price; + } + +} diff --git a/sca-java-2.x/trunk/samples/applications/store/src/main/java/services/ShoppingCartImpl.java b/sca-java-2.x/trunk/samples/applications/store/src/main/java/services/ShoppingCartImpl.java new file mode 100644 index 0000000000..698614212d --- /dev/null +++ b/sca-java-2.x/trunk/samples/applications/store/src/main/java/services/ShoppingCartImpl.java @@ -0,0 +1,112 @@ +/* + * 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 services; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.apache.tuscany.sca.data.collection.Entry; +import org.apache.tuscany.sca.data.collection.NotFoundException; +import org.oasisopen.sca.annotation.Init; +import org.oasisopen.sca.annotation.Scope; + +@Scope("COMPOSITE") +public class ShoppingCartImpl implements Cart, Total { + + private Map cart; + + @Init + public void init() { + cart = new HashMap(); + } + + public Entry[] getAll() { + Entry[] entries = new Entry[cart.size()]; + int i = 0; + for (Map.Entry e: cart.entrySet()) { + entries[i++] = new Entry(e.getKey(), e.getValue()); + } + return entries; + } + + public Item get(String key) throws NotFoundException { + Item item = cart.get(key); + if (item == null) { + throw new NotFoundException(key); + } else { + return item; + } + } + + public String post(String key, Item item) { + if (key == null) { + key ="cart-" + UUID.randomUUID().toString(); + } + cart.put(key, item); + return key; + } + + public void put(String key, Item item) throws NotFoundException { + if (!cart.containsKey(key)) { + throw new NotFoundException(key); + } + cart.put(key, item); + } + + public void delete(String key) throws NotFoundException { + if (key == null || key.equals("")) { + cart.clear(); + } else { + Item item = cart.remove(key); + if (item == null) + throw new NotFoundException(key); + } + } + + public Entry[] query(String queryString) { + List> entries = new ArrayList>(); + if (queryString.startsWith("name=")) { + String name = queryString.substring(5); + for (Map.Entry e: cart.entrySet()) { + Item item = e.getValue(); + if (item.getName().equals(name)) { + entries.add(new Entry(e.getKey(), e.getValue())); + } + } + } + return entries.toArray(new Entry[entries.size()]); + } + + public String getTotal() { + double total = 0; + String currencySymbol = ""; + if (!cart.isEmpty()) { + Item item = cart.values().iterator().next(); + currencySymbol = item.getPrice().substring(0, 1); + } + for (Item item : cart.values()) { + total += Double.valueOf(item.getPrice().substring(1)); + } + return currencySymbol + String.valueOf(total); + } +} diff --git a/sca-java-2.x/trunk/samples/applications/store/src/main/java/services/Total.java b/sca-java-2.x/trunk/samples/applications/store/src/main/java/services/Total.java new file mode 100644 index 0000000000..b77cc1c7ac --- /dev/null +++ b/sca-java-2.x/trunk/samples/applications/store/src/main/java/services/Total.java @@ -0,0 +1,29 @@ +/* + * 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 services; + +import org.oasisopen.sca.annotation.Remotable; + +@Remotable +public interface Total { + + String getTotal(); + +} diff --git a/sca-java-2.x/trunk/samples/applications/store/src/main/resources/store.composite b/sca-java-2.x/trunk/samples/applications/store/src/main/resources/store.composite new file mode 100644 index 0000000000..9c3b79c508 --- /dev/null +++ b/sca-java-2.x/trunk/samples/applications/store/src/main/resources/store.composite @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + USD + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-2.x/trunk/samples/applications/store/src/main/resources/uiservices/store.html b/sca-java-2.x/trunk/samples/applications/store/src/main/resources/uiservices/store.html new file mode 100644 index 0000000000..be3efea327 --- /dev/null +++ b/sca-java-2.x/trunk/samples/applications/store/src/main/resources/uiservices/store.html @@ -0,0 +1,162 @@ + + + +Store + + + + + + + + + +

Store

+
+

Catalog

+
+
+
+ +
+ +
+ +

Your Shopping Cart

+
+
+
+
+
+ + + (feed) +
+
+ + diff --git a/sca-java-2.x/trunk/samples/applications/store/src/test/java/client/Shopper.java b/sca-java-2.x/trunk/samples/applications/store/src/test/java/client/Shopper.java new file mode 100644 index 0000000000..4e2fa63493 --- /dev/null +++ b/sca-java-2.x/trunk/samples/applications/store/src/test/java/client/Shopper.java @@ -0,0 +1,29 @@ +/* + * 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 client; + +import org.oasisopen.sca.annotation.Remotable; + +@Remotable +public interface Shopper { + + String shop(String itemName, int quantity); + +} diff --git a/sca-java-2.x/trunk/samples/applications/store/src/test/java/client/ShopperImpl.java b/sca-java-2.x/trunk/samples/applications/store/src/test/java/client/ShopperImpl.java new file mode 100644 index 0000000000..05b1800d4f --- /dev/null +++ b/sca-java-2.x/trunk/samples/applications/store/src/test/java/client/ShopperImpl.java @@ -0,0 +1,64 @@ +/* + * 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 client; + +import org.apache.tuscany.sca.data.collection.NotFoundException; +import org.oasisopen.sca.annotation.Reference; + +import services.Cart; +import services.Catalog; +import services.Item; +import services.Total; + +public class ShopperImpl implements Shopper { + + @Reference + public Catalog catalog; + + @Reference + public Cart shoppingCart; + + @Reference + public Total shoppingTotal; + + public String shop(String itemName, int quantity) { + + Item[] items = catalog.get(); + for (Item item: items) { + if (item.getName().startsWith(itemName)) { + + try { + shoppingCart.delete(""); + } catch (NotFoundException e) { + // ignore + } + + for (int i = 0; i < quantity; i++) { + shoppingCart.post("item" + i, item); + } + + return shoppingTotal.getTotal(); + } + } + + return ""; + } + +} diff --git a/sca-java-2.x/trunk/samples/applications/store/src/test/java/store/StoreTestCase.java b/sca-java-2.x/trunk/samples/applications/store/src/test/java/store/StoreTestCase.java new file mode 100644 index 0000000000..7fa866d1c6 --- /dev/null +++ b/sca-java-2.x/trunk/samples/applications/store/src/test/java/store/StoreTestCase.java @@ -0,0 +1,121 @@ +/* + * 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 store; + +import java.io.IOException; +import java.net.MalformedURLException; + +import junit.framework.Assert; + +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; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; + +import client.Shopper; + +import com.gargoylesoftware.htmlunit.BrowserVersion; +import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException; +import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController; +import com.gargoylesoftware.htmlunit.WebClient; +import com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput; +import com.gargoylesoftware.htmlunit.html.HtmlForm; +import com.gargoylesoftware.htmlunit.html.HtmlPage; + + +/** + * Test the store-merger. + * + * @version $Rev$ $Date$ + */ +public class StoreTestCase { + private static Node nodeStore; + + public static void main(String[] args) throws Exception { + setUp(); + testWaitForInput(); + tearDown(); + } + + @BeforeClass + public static void setUp() throws Exception { + String storeLocation = ContributionLocationHelper.getContributionLocation("store.composite"); + String storeClientLocation = ContributionLocationHelper.getContributionLocation("store-client.composite"); + + nodeStore = NodeFactory.newInstance().createNode(new Contribution("store", storeLocation), new Contribution("storeClient", storeClientLocation)); + nodeStore.start(); + } + + @AfterClass + public static void tearDown() throws Exception { + nodeStore.stop(); + } + + public static void testWaitForInput() { + try { + System.out.println("press enter to continue)"); + System.in.read(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Test + public void testShop() { + Shopper shopper = nodeStore.getService(Shopper.class, "StoreClient"); + + String total = shopper.shop("Orange", 5); + System.out.println("Total: " + total); + + Assert.assertEquals("$17.75", total); + + } + + @Test + public void testStoreWidget() throws FailingHttpStatusCodeException, MalformedURLException, IOException { + WebClient webClient = new WebClient(BrowserVersion.FIREFOX_3); + webClient.setRedirectEnabled(true); + webClient.setThrowExceptionOnScriptError(false); + //webClient.waitForBackgroundJavaScript(100000); + //webClient.waitForBackgroundJavaScriptStartingBefore(100000); + webClient.setAjaxController(new NicelyResynchronizingAjaxController()); + + HtmlPage page = (HtmlPage) webClient.getPage("http://localhost:8080/store/store.html"); + + HtmlForm form = (HtmlForm) page.getFormByName("catalogForm"); + + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + } + + HtmlCheckBoxInput catalogItems = (HtmlCheckBoxInput) form.getInputByName("items"); + + System.out.println(">>>" + catalogItems.getAttribute("value")); + Assert.assertEquals("Apple - $2.99", catalogItems.getAttribute("value")); + + webClient.closeAllWindows(); + } + +} diff --git a/sca-java-2.x/trunk/samples/applications/store/src/test/resources/store-client.composite b/sca-java-2.x/trunk/samples/applications/store/src/test/resources/store-client.composite new file mode 100644 index 0000000000..c9abe8e996 --- /dev/null +++ b/sca-java-2.x/trunk/samples/applications/store/src/test/resources/store-client.composite @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + diff --git a/sca-java-2.x/trunk/samples/applications/store/store.png b/sca-java-2.x/trunk/samples/applications/store/store.png new file mode 100644 index 0000000000..da413edeee Binary files /dev/null and b/sca-java-2.x/trunk/samples/applications/store/store.png differ diff --git a/sca-java-2.x/trunk/samples/applications/store/store.svg b/sca-java-2.x/trunk/samples/applications/store/store.svg new file mode 100644 index 0000000000..74f8ecd36d --- /dev/null +++ b/sca-java-2.x/trunk/samples/applications/store/store.svg @@ -0,0 +1,304 @@ + + + + + + + + + + image/svg+xml + + + + + + + + store + ufs + + ShoppingCart + + CurrencyConverter + + + + + + + + + + CurrenyCode HTTP JSONRPC Atom + + Catalog + + + + diff --git a/sca-java-2.x/trunk/samples/getting-started/helloworld-scaclient/pom.xml b/sca-java-2.x/trunk/samples/getting-started/helloworld-scaclient/pom.xml index f10cb6d343..dc91877d6c 100644 --- a/sca-java-2.x/trunk/samples/getting-started/helloworld-scaclient/pom.xml +++ b/sca-java-2.x/trunk/samples/getting-started/helloworld-scaclient/pom.xml @@ -22,7 +22,7 @@ 4.0.0 - org.apache.tuscany.sca.samples + org.apache.tuscany.sca tuscany-samples 2.0-SNAPSHOT diff --git a/sca-java-2.x/trunk/samples/getting-started/helloworld-webapp/pom.xml b/sca-java-2.x/trunk/samples/getting-started/helloworld-webapp/pom.xml index af6f446ce5..ac6e759140 100644 --- a/sca-java-2.x/trunk/samples/getting-started/helloworld-webapp/pom.xml +++ b/sca-java-2.x/trunk/samples/getting-started/helloworld-webapp/pom.xml @@ -22,7 +22,7 @@ 4.0.0 - org.apache.tuscany.sca.samples + org.apache.tuscany.sca tuscany-samples 2.0-SNAPSHOT diff --git a/sca-java-2.x/trunk/samples/getting-started/helloworld/pom.xml b/sca-java-2.x/trunk/samples/getting-started/helloworld/pom.xml index 6f4f92c230..f837dbf65d 100644 --- a/sca-java-2.x/trunk/samples/getting-started/helloworld/pom.xml +++ b/sca-java-2.x/trunk/samples/getting-started/helloworld/pom.xml @@ -22,7 +22,7 @@ 4.0.0 - org.apache.tuscany.sca.samples + org.apache.tuscany.sca tuscany-samples 2.0-SNAPSHOT diff --git a/sca-java-2.x/trunk/samples/getting-started/pom.xml b/sca-java-2.x/trunk/samples/getting-started/pom.xml index 378b6a2c31..c906c413c0 100644 --- a/sca-java-2.x/trunk/samples/getting-started/pom.xml +++ b/sca-java-2.x/trunk/samples/getting-started/pom.xml @@ -20,7 +20,7 @@ 4.0.0 - org.apache.tuscany.sca.samples + org.apache.tuscany.sca tuscany-samples 2.0-SNAPSHOT diff --git a/sca-java-2.x/trunk/samples/pom.xml b/sca-java-2.x/trunk/samples/pom.xml index ebb4efb8c0..b62dfda5a0 100644 --- a/sca-java-2.x/trunk/samples/pom.xml +++ b/sca-java-2.x/trunk/samples/pom.xml @@ -26,12 +26,12 @@ tuscany-samples - org.apache.tuscany.sca.samples 2.0-SNAPSHOT pom Apache Tuscany SCA Samples + applications getting-started -- cgit v1.2.3