From 132aa8a77685ec92bc90c03f987650d275a7b639 Mon Sep 17 00:00:00 2001 From: lresende Date: Mon, 30 Sep 2013 06:59:11 +0000 Subject: 2.0.1 RC1 release tag git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1527464 13f79535-47bb-0310-9956-ffa450edef68 --- .../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 | 55 +++++++ .../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 | 120 +++++++++++++++ .../src/test/resources/store-client.composite | 38 +++++ 15 files changed, 876 insertions(+) create mode 100644 sca-java-2.x/tags/2.0.1-RC1/samples/applications/store/src/main/java/launch/Launch.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/samples/applications/store/src/main/java/services/Cart.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/samples/applications/store/src/main/java/services/Catalog.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/samples/applications/store/src/main/java/services/CurrencyConverter.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/samples/applications/store/src/main/java/services/CurrencyConverterImpl.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/samples/applications/store/src/main/java/services/FruitsCatalogImpl.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/samples/applications/store/src/main/java/services/Item.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/samples/applications/store/src/main/java/services/ShoppingCartImpl.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/samples/applications/store/src/main/java/services/Total.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/samples/applications/store/src/main/resources/store.composite create mode 100644 sca-java-2.x/tags/2.0.1-RC1/samples/applications/store/src/main/resources/uiservices/store.html create mode 100644 sca-java-2.x/tags/2.0.1-RC1/samples/applications/store/src/test/java/client/Shopper.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/samples/applications/store/src/test/java/client/ShopperImpl.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/samples/applications/store/src/test/java/store/StoreTestCase.java create mode 100644 sca-java-2.x/tags/2.0.1-RC1/samples/applications/store/src/test/resources/store-client.composite (limited to 'sca-java-2.x/tags/2.0.1-RC1/samples/applications/store/src') diff --git a/sca-java-2.x/tags/2.0.1-RC1/samples/applications/store/src/main/java/launch/Launch.java b/sca-java-2.x/tags/2.0.1-RC1/samples/applications/store/src/main/java/launch/Launch.java new file mode 100644 index 0000000000..8e4b5839e4 --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/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/tags/2.0.1-RC1/samples/applications/store/src/main/java/services/Cart.java b/sca-java-2.x/tags/2.0.1-RC1/samples/applications/store/src/main/java/services/Cart.java new file mode 100644 index 0000000000..3fb5439bc3 --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/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/tags/2.0.1-RC1/samples/applications/store/src/main/java/services/Catalog.java b/sca-java-2.x/tags/2.0.1-RC1/samples/applications/store/src/main/java/services/Catalog.java new file mode 100644 index 0000000000..b5e504fe11 --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/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/tags/2.0.1-RC1/samples/applications/store/src/main/java/services/CurrencyConverter.java b/sca-java-2.x/tags/2.0.1-RC1/samples/applications/store/src/main/java/services/CurrencyConverter.java new file mode 100644 index 0000000000..a064f3dd69 --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/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/tags/2.0.1-RC1/samples/applications/store/src/main/java/services/CurrencyConverterImpl.java b/sca-java-2.x/tags/2.0.1-RC1/samples/applications/store/src/main/java/services/CurrencyConverterImpl.java new file mode 100644 index 0000000000..c354aed447 --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/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/tags/2.0.1-RC1/samples/applications/store/src/main/java/services/FruitsCatalogImpl.java b/sca-java-2.x/tags/2.0.1-RC1/samples/applications/store/src/main/java/services/FruitsCatalogImpl.java new file mode 100644 index 0000000000..d132a24b00 --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/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/tags/2.0.1-RC1/samples/applications/store/src/main/java/services/Item.java b/sca-java-2.x/tags/2.0.1-RC1/samples/applications/store/src/main/java/services/Item.java new file mode 100644 index 0000000000..0a9dcb2ffc --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/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/tags/2.0.1-RC1/samples/applications/store/src/main/java/services/ShoppingCartImpl.java b/sca-java-2.x/tags/2.0.1-RC1/samples/applications/store/src/main/java/services/ShoppingCartImpl.java new file mode 100644 index 0000000000..698614212d --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/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/tags/2.0.1-RC1/samples/applications/store/src/main/java/services/Total.java b/sca-java-2.x/tags/2.0.1-RC1/samples/applications/store/src/main/java/services/Total.java new file mode 100644 index 0000000000..b77cc1c7ac --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/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/tags/2.0.1-RC1/samples/applications/store/src/main/resources/store.composite b/sca-java-2.x/tags/2.0.1-RC1/samples/applications/store/src/main/resources/store.composite new file mode 100644 index 0000000000..bb60f96a7a --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/samples/applications/store/src/main/resources/store.composite @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + USD + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-2.x/tags/2.0.1-RC1/samples/applications/store/src/main/resources/uiservices/store.html b/sca-java-2.x/tags/2.0.1-RC1/samples/applications/store/src/main/resources/uiservices/store.html new file mode 100644 index 0000000000..be3efea327 --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/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/tags/2.0.1-RC1/samples/applications/store/src/test/java/client/Shopper.java b/sca-java-2.x/tags/2.0.1-RC1/samples/applications/store/src/test/java/client/Shopper.java new file mode 100644 index 0000000000..4e2fa63493 --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/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/tags/2.0.1-RC1/samples/applications/store/src/test/java/client/ShopperImpl.java b/sca-java-2.x/tags/2.0.1-RC1/samples/applications/store/src/test/java/client/ShopperImpl.java new file mode 100644 index 0000000000..05b1800d4f --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/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/tags/2.0.1-RC1/samples/applications/store/src/test/java/store/StoreTestCase.java b/sca-java-2.x/tags/2.0.1-RC1/samples/applications/store/src/test/java/store/StoreTestCase.java new file mode 100644 index 0000000000..2aa4f89e2f --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/samples/applications/store/src/test/java/store/StoreTestCase.java @@ -0,0 +1,120 @@ +/* + * 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.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/tags/2.0.1-RC1/samples/applications/store/src/test/resources/store-client.composite b/sca-java-2.x/tags/2.0.1-RC1/samples/applications/store/src/test/resources/store-client.composite new file mode 100644 index 0000000000..c9abe8e996 --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/samples/applications/store/src/test/resources/store-client.composite @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + -- cgit v1.2.3