From c186ff24ecfc13e14e4b29130c7ca387f7050dd5 Mon Sep 17 00:00:00 2001 From: kelvingoodson Date: Tue, 14 Sep 2010 12:43:01 +0000 Subject: TUSCANY-3677 move store sample into applications folder git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@996875 13f79535-47bb-0310-9956-ffa450edef68 --- .../trunk/samples/applications/store/README | 28 ++ .../trunk/samples/applications/store/build.xml | 79 ++++++ .../trunk/samples/applications/store/pom.xml | 70 +++++ .../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 | 50 ++++ .../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 | 117 ++++++++ .../src/test/resources/store-client.composite | 38 +++ .../trunk/samples/applications/store/store.png | Bin 0 -> 15670 bytes .../trunk/samples/applications/store/store.svg | 304 +++++++++++++++++++++ sca-java-2.x/trunk/samples/store/README | 28 -- sca-java-2.x/trunk/samples/store/build.xml | 79 ------ sca-java-2.x/trunk/samples/store/pom.xml | 70 ----- .../samples/store/src/main/java/launch/Launch.java | 39 --- .../samples/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 ---- .../samples/store/src/main/java/services/Item.java | 50 ---- .../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 | 117 -------- .../src/test/resources/store-client.composite | 38 --- sca-java-2.x/trunk/samples/store/store.png | Bin 15670 -> 0 bytes sca-java-2.x/trunk/samples/store/store.svg | 304 --------------------- 40 files changed, 1353 insertions(+), 1353 deletions(-) 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 delete mode 100644 sca-java-2.x/trunk/samples/store/README delete mode 100644 sca-java-2.x/trunk/samples/store/build.xml delete mode 100644 sca-java-2.x/trunk/samples/store/pom.xml delete mode 100644 sca-java-2.x/trunk/samples/store/src/main/java/launch/Launch.java delete mode 100644 sca-java-2.x/trunk/samples/store/src/main/java/services/Cart.java delete mode 100644 sca-java-2.x/trunk/samples/store/src/main/java/services/Catalog.java delete mode 100644 sca-java-2.x/trunk/samples/store/src/main/java/services/CurrencyConverter.java delete mode 100644 sca-java-2.x/trunk/samples/store/src/main/java/services/CurrencyConverterImpl.java delete mode 100644 sca-java-2.x/trunk/samples/store/src/main/java/services/FruitsCatalogImpl.java delete mode 100644 sca-java-2.x/trunk/samples/store/src/main/java/services/Item.java delete mode 100644 sca-java-2.x/trunk/samples/store/src/main/java/services/ShoppingCartImpl.java delete mode 100644 sca-java-2.x/trunk/samples/store/src/main/java/services/Total.java delete mode 100644 sca-java-2.x/trunk/samples/store/src/main/resources/store.composite delete mode 100644 sca-java-2.x/trunk/samples/store/src/main/resources/uiservices/store.html delete mode 100644 sca-java-2.x/trunk/samples/store/src/test/java/client/Shopper.java delete mode 100644 sca-java-2.x/trunk/samples/store/src/test/java/client/ShopperImpl.java delete mode 100644 sca-java-2.x/trunk/samples/store/src/test/java/store/StoreTestCase.java delete mode 100644 sca-java-2.x/trunk/samples/store/src/test/resources/store-client.composite delete mode 100644 sca-java-2.x/trunk/samples/store/store.png delete mode 100644 sca-java-2.x/trunk/samples/store/store.svg (limited to 'sca-java-2.x/trunk/samples') 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..bd36a0d398 --- /dev/null +++ b/sca-java-2.x/trunk/samples/applications/store/build.xml @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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..6386a58525 --- /dev/null +++ b/sca-java-2.x/trunk/samples/applications/store/pom.xml @@ -0,0 +1,70 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-samples + 2.0-SNAPSHOT + ../pom.xml + + sample-store + Apache Tuscany SCA Sample Getting Started Online Store + + + + org.apache.tuscany.sca + tuscany-node-impl + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-data-api + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-feature-web20 + pom + 2.0-SNAPSHOT + + + + net.sourceforge.htmlunit + htmlunit + 2.6 + test + + + + junit + junit + 4.8.1 + test + + + + + ${artifactId} + + + 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..fe32cfc828 --- /dev/null +++ b/sca-java-2.x/trunk/samples/applications/store/src/main/java/services/Item.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 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; + } + +} 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..000f1f891f --- /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..883aaa76f6 --- /dev/null +++ b/sca-java-2.x/trunk/samples/applications/store/src/test/java/store/StoreTestCase.java @@ -0,0 +1,117 @@ +/* + * 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; + + @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(); + } + + @Test + @Ignore + public 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/store/README b/sca-java-2.x/trunk/samples/store/README deleted file mode 100644 index d31e4c59b7..0000000000 --- a/sca-java-2.x/trunk/samples/store/README +++ /dev/null @@ -1,28 +0,0 @@ -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/store/build.xml b/sca-java-2.x/trunk/samples/store/build.xml deleted file mode 100644 index bd36a0d398..0000000000 --- a/sca-java-2.x/trunk/samples/store/build.xml +++ /dev/null @@ -1,79 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/sca-java-2.x/trunk/samples/store/pom.xml b/sca-java-2.x/trunk/samples/store/pom.xml deleted file mode 100644 index 6386a58525..0000000000 --- a/sca-java-2.x/trunk/samples/store/pom.xml +++ /dev/null @@ -1,70 +0,0 @@ - - - - 4.0.0 - - org.apache.tuscany.sca - tuscany-samples - 2.0-SNAPSHOT - ../pom.xml - - sample-store - Apache Tuscany SCA Sample Getting Started Online Store - - - - org.apache.tuscany.sca - tuscany-node-impl - 2.0-SNAPSHOT - - - - org.apache.tuscany.sca - tuscany-data-api - 2.0-SNAPSHOT - - - - org.apache.tuscany.sca - tuscany-feature-web20 - pom - 2.0-SNAPSHOT - - - - net.sourceforge.htmlunit - htmlunit - 2.6 - test - - - - junit - junit - 4.8.1 - test - - - - - ${artifactId} - - - diff --git a/sca-java-2.x/trunk/samples/store/src/main/java/launch/Launch.java b/sca-java-2.x/trunk/samples/store/src/main/java/launch/Launch.java deleted file mode 100644 index 8e4b5839e4..0000000000 --- a/sca-java-2.x/trunk/samples/store/src/main/java/launch/Launch.java +++ /dev/null @@ -1,39 +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 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/store/src/main/java/services/Cart.java b/sca-java-2.x/trunk/samples/store/src/main/java/services/Cart.java deleted file mode 100644 index 3fb5439bc3..0000000000 --- a/sca-java-2.x/trunk/samples/store/src/main/java/services/Cart.java +++ /dev/null @@ -1,28 +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 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/store/src/main/java/services/Catalog.java b/sca-java-2.x/trunk/samples/store/src/main/java/services/Catalog.java deleted file mode 100644 index b5e504fe11..0000000000 --- a/sca-java-2.x/trunk/samples/store/src/main/java/services/Catalog.java +++ /dev/null @@ -1,27 +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 services; - -import org.oasisopen.sca.annotation.Remotable; - -@Remotable -public interface Catalog { - Item[] get(); -} diff --git a/sca-java-2.x/trunk/samples/store/src/main/java/services/CurrencyConverter.java b/sca-java-2.x/trunk/samples/store/src/main/java/services/CurrencyConverter.java deleted file mode 100644 index a064f3dd69..0000000000 --- a/sca-java-2.x/trunk/samples/store/src/main/java/services/CurrencyConverter.java +++ /dev/null @@ -1,29 +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 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/store/src/main/java/services/CurrencyConverterImpl.java b/sca-java-2.x/trunk/samples/store/src/main/java/services/CurrencyConverterImpl.java deleted file mode 100644 index c354aed447..0000000000 --- a/sca-java-2.x/trunk/samples/store/src/main/java/services/CurrencyConverterImpl.java +++ /dev/null @@ -1,38 +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 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/store/src/main/java/services/FruitsCatalogImpl.java b/sca-java-2.x/trunk/samples/store/src/main/java/services/FruitsCatalogImpl.java deleted file mode 100644 index d132a24b00..0000000000 --- a/sca-java-2.x/trunk/samples/store/src/main/java/services/FruitsCatalogImpl.java +++ /dev/null @@ -1,52 +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 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/store/src/main/java/services/Item.java b/sca-java-2.x/trunk/samples/store/src/main/java/services/Item.java deleted file mode 100644 index fe32cfc828..0000000000 --- a/sca-java-2.x/trunk/samples/store/src/main/java/services/Item.java +++ /dev/null @@ -1,50 +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 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; - } - -} diff --git a/sca-java-2.x/trunk/samples/store/src/main/java/services/ShoppingCartImpl.java b/sca-java-2.x/trunk/samples/store/src/main/java/services/ShoppingCartImpl.java deleted file mode 100644 index 698614212d..0000000000 --- a/sca-java-2.x/trunk/samples/store/src/main/java/services/ShoppingCartImpl.java +++ /dev/null @@ -1,112 +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 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/store/src/main/java/services/Total.java b/sca-java-2.x/trunk/samples/store/src/main/java/services/Total.java deleted file mode 100644 index b77cc1c7ac..0000000000 --- a/sca-java-2.x/trunk/samples/store/src/main/java/services/Total.java +++ /dev/null @@ -1,29 +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 services; - -import org.oasisopen.sca.annotation.Remotable; - -@Remotable -public interface Total { - - String getTotal(); - -} diff --git a/sca-java-2.x/trunk/samples/store/src/main/resources/store.composite b/sca-java-2.x/trunk/samples/store/src/main/resources/store.composite deleted file mode 100644 index 9c3b79c508..0000000000 --- a/sca-java-2.x/trunk/samples/store/src/main/resources/store.composite +++ /dev/null @@ -1,58 +0,0 @@ - - - - - - - - - - - - - - - - - USD - - - - - - - - - - - - - - - - - - - - - diff --git a/sca-java-2.x/trunk/samples/store/src/main/resources/uiservices/store.html b/sca-java-2.x/trunk/samples/store/src/main/resources/uiservices/store.html deleted file mode 100644 index 000f1f891f..0000000000 --- a/sca-java-2.x/trunk/samples/store/src/main/resources/uiservices/store.html +++ /dev/null @@ -1,162 +0,0 @@ - - - -Store - - - - - - - - - -

Store

-
-

Catalog

-
-
-
- -
- -
- -

Your Shopping Cart

-
-
-
-
-
- - - (feed) -
-
- - diff --git a/sca-java-2.x/trunk/samples/store/src/test/java/client/Shopper.java b/sca-java-2.x/trunk/samples/store/src/test/java/client/Shopper.java deleted file mode 100644 index 4e2fa63493..0000000000 --- a/sca-java-2.x/trunk/samples/store/src/test/java/client/Shopper.java +++ /dev/null @@ -1,29 +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 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/store/src/test/java/client/ShopperImpl.java b/sca-java-2.x/trunk/samples/store/src/test/java/client/ShopperImpl.java deleted file mode 100644 index 05b1800d4f..0000000000 --- a/sca-java-2.x/trunk/samples/store/src/test/java/client/ShopperImpl.java +++ /dev/null @@ -1,64 +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 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/store/src/test/java/store/StoreTestCase.java b/sca-java-2.x/trunk/samples/store/src/test/java/store/StoreTestCase.java deleted file mode 100644 index 883aaa76f6..0000000000 --- a/sca-java-2.x/trunk/samples/store/src/test/java/store/StoreTestCase.java +++ /dev/null @@ -1,117 +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 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; - - @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(); - } - - @Test - @Ignore - public 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/store/src/test/resources/store-client.composite b/sca-java-2.x/trunk/samples/store/src/test/resources/store-client.composite deleted file mode 100644 index c9abe8e996..0000000000 --- a/sca-java-2.x/trunk/samples/store/src/test/resources/store-client.composite +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - - - - - - - - - diff --git a/sca-java-2.x/trunk/samples/store/store.png b/sca-java-2.x/trunk/samples/store/store.png deleted file mode 100644 index da413edeee..0000000000 Binary files a/sca-java-2.x/trunk/samples/store/store.png and /dev/null differ diff --git a/sca-java-2.x/trunk/samples/store/store.svg b/sca-java-2.x/trunk/samples/store/store.svg deleted file mode 100644 index 74f8ecd36d..0000000000 --- a/sca-java-2.x/trunk/samples/store/store.svg +++ /dev/null @@ -1,304 +0,0 @@ - - - - - - - - - - image/svg+xml - - - - - - - - store - ufs - - ShoppingCart - - CurrencyConverter - - - - - - - - - - CurrenyCode HTTP JSONRPC Atom - - Catalog - - - - -- cgit v1.2.3