diff options
author | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2010-02-22 06:08:34 +0000 |
---|---|---|
committer | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2010-02-22 06:08:34 +0000 |
commit | 8c771c8ecd9bdc6b3ef0d5417db9bb9917b65fa9 (patch) | |
tree | a3671bc719d351a822b3728323e6456f163af2c3 /sca-cpp/trunk/test | |
parent | d11cbfda813c7c6b32c06ddb33242fe3c82514eb (diff) |
Moved component start calls from HTTPD postConfig to childInit, to give components an opportunity to start and setup connections and resources in each HTTPD child process. Adjusted utility components and test cases to this change. Minor code cleanup of Java components and integration tests.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@912491 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-cpp/trunk/test')
5 files changed, 92 insertions, 116 deletions
diff --git a/sca-cpp/trunk/test/store-cpp/shopping-cart.cpp b/sca-cpp/trunk/test/store-cpp/shopping-cart.cpp index 5dcbc88ee9..eaad0d3c77 100644 --- a/sca-cpp/trunk/test/store-cpp/shopping-cart.cpp +++ b/sca-cpp/trunk/test/store-cpp/shopping-cart.cpp @@ -41,7 +41,7 @@ const string cartId("1234"); * cart if not found. */ const list<value> getcart(const value& id, const lambda<value(const list<value>&)> cache) { - const value cart = cache(mklist<value>("get", id)); + const value cart = cache(mklist<value>("get", mklist<value>(id))); if (isNil(cart)) return value(list<value>()); return (list<value>)cart; @@ -61,19 +61,12 @@ const value uuid() { /** * Post a new item to the cart. Create a new cart if necessary. */ -const failable<value> post(const value& item, const lambda<value(const list<value>&)> cache) { +const failable<value> post(unused const list<value>& collection, const value& item, const lambda<value(const list<value>&)> cache) { const value id(uuid()); const list<value> newItem(mklist<value>(car<value>(item), id, caddr<value>(item))); const list<value> cart(cons<value>(newItem, getcart(cartId, cache))); - cache(mklist<value>("put", cartId, cart)); - return id; -} - -/** - * Return the contents of the cart. - */ -const failable<value> getall(const lambda<value(const list<value>&)> cache) { - return value(append(mklist<value>(string("Your Cart"), cartId), getcart(cartId, cache))); + cache(mklist<value>("put", mklist<value>(cartId), cart)); + return value(mklist<value>(id)); } /** @@ -87,21 +80,21 @@ const value find(const value& id, const list<value>& cart) { return find(id, cdr(cart)); } -const failable<value> get(const value& id, const lambda<value(const list<value>&)> cache) { - return find(id, getcart(cartId, cache)); -} - /** - * Delete the whole cart. + * Return items from the cart. */ -const failable<value> delall(const lambda<value(const list<value>&)> cache) { - return cache(mklist<value>("delete", cartId)); +const failable<value> get(const list<value>& id, const lambda<value(const list<value>&)> cache) { + if (isNil(id)) + return value(append(mklist<value>(string("Your Cart"), cartId), getcart(cartId, cache))); + return find(car(id), getcart(cartId, cache)); } /** - * Delete an item from the cart. + * Delete items from the cart. */ -const failable<value> del(unused const value& id, unused const lambda<value(const list<value>&)> cache) { +const failable<value> del(const list<value>& id, unused const lambda<value(const list<value>&)> cache) { + if (isNil(id)) + return cache(mklist<value>("delete", mklist<value>(cartId))); return value(true); } @@ -144,13 +137,9 @@ extern "C" { const tuscany::value apply(const tuscany::list<tuscany::value>& params) { const tuscany::value func(car(params)); if (func == "post") - return tuscany::store::post(cadr(params), caddr(params)); - if (func == "getall") - return tuscany::store::getall(cadr(params)); + return tuscany::store::post(cadr(params), caddr(params), cadddr(params)); if (func == "get") return tuscany::store::get(cadr(params), caddr(params)); - if (func == "deleteall") - return tuscany::store::delall(cadr(params)); if (func == "delete") return tuscany::store::del(cadr(params), caddr(params)); if (func == "gettotal") diff --git a/sca-cpp/trunk/test/store-java/store/FruitsCatalogImpl.java b/sca-cpp/trunk/test/store-java/store/FruitsCatalogImpl.java index bb75926b1f..2904bbd8a1 100644 --- a/sca-cpp/trunk/test/store-java/store/FruitsCatalogImpl.java +++ b/sca-cpp/trunk/test/store-java/store/FruitsCatalogImpl.java @@ -19,34 +19,33 @@ package store; +import static org.apache.tuscany.IterableUtil.*; + import org.apache.tuscany.Service; -import static org.apache.tuscany.IterableUtil.list; /** * Catalog component implementation. */ public class FruitsCatalogImpl { - + /** * Returns the catalog. */ public Iterable<?> get(final CurrencyConverter converter, final Service currencyCode) { final String code = currencyCode.eval(); - + class Converter { - Double convert(Double price) { + Double convert(final Double price) { return converter.convert(code, "USD", price); } - }; + } - Converter c = new Converter(); - String symbol = converter.symbol(code); - - return list( - list(list("'javaClass", "services.Item"), list("'name", "Apple"), list("'currencyCode", code), list("'currencySymbol", symbol), list("'price", c.convert(2.99))), + final Converter c = new Converter(); + final String symbol = converter.symbol(code); + + return list(list(list("'javaClass", "services.Item"), list("'name", "Apple"), list("'currencyCode", code), list("'currencySymbol", symbol), list("'price", c.convert(2.99))), list(list("'javaClass", "services.Item"), list("'name", "Orange"), list("'currencyCode", code), list("'currencySymbol", symbol), list("'price", c.convert(3.55))), - list(list("'javaClass", "services.Item"), list("'name", "Pear"), list("'currencyCode", code), list("'currencySymbol", symbol), list("'price", c.convert(1.55))) - ); + list(list("'javaClass", "services.Item"), list("'name", "Pear"), list("'currencyCode", code), list("'currencySymbol", symbol), list("'price", c.convert(1.55)))); } /** @@ -55,5 +54,5 @@ public class FruitsCatalogImpl { public Iterable<?> listMethods(final CurrencyConverter converter, final Service currencyCode) { return list("Service.get"); } - + } diff --git a/sca-cpp/trunk/test/store-java/store/ShoppingCartImpl.java b/sca-cpp/trunk/test/store-java/store/ShoppingCartImpl.java index 7937b097ce..6620cbbbb0 100644 --- a/sca-cpp/trunk/test/store-java/store/ShoppingCartImpl.java +++ b/sca-cpp/trunk/test/store-java/store/ShoppingCartImpl.java @@ -19,25 +19,26 @@ package store; -import org.apache.tuscany.Service; -import java.lang.System; -import java.util.UUID; import static org.apache.tuscany.IterableUtil.*; +import java.util.UUID; + +import org.apache.tuscany.Service; + /** * Shopping cart component implementation. */ public class ShoppingCartImpl { - + static String cartId = "1234"; - + /** - * Get the shopping cart from the cache. Return an empty - * cart if not found. + * Get the shopping cart from the cache. Return an empty cart if not found. */ - public Iterable<?> getcart(String id, Service cache) { - Iterable<?> cart = cache.get(id); - if (cart == null) + public Iterable<?> getcart(final String id, final Service cache) { + final Iterable<String> iid = list(id); + final Iterable<?> cart = cache.get(iid); + if(cart == null) return list(); return cart; } @@ -52,72 +53,68 @@ public class ShoppingCartImpl { /** * Post a new item to the cart. Create a new cart if necessary. */ - public String post(Iterable<?> item, Service cache) { - String id = uuid(); - Iterable<?> newItem = list(car(item), id, caddr(item)); - Iterable<?> cart = cons(newItem, getcart(cartId, cache)); - cache.put(cartId, cart); - return id; - } - - /** - * Return the contents of the cart. - */ - public Iterable<?> getall(Service cache) { - return cons("Your Cart", cons(cartId, getcart(cartId, cache))); + public Iterable<String> post(final Iterable<String> collection, final Iterable<?> item, final Service cache) { + final String id = this.uuid(); + final Iterable<?> newItem = list(car(item), id, caddr(item)); + final Iterable<?> cart = cons(newItem, this.getcart(cartId, cache)); + final Iterable<String> iid = list(cartId); + cache.put(iid, cart); + return list(id); } /** * Find an item in the cart. */ - public Iterable<?> find(String id, Iterable<?> cart) { - if (isNil(cart)) + public Iterable<?> find(final String id, final Iterable<?> cart) { + if(isNil(cart)) return cons("Item", list("0", list())); - if (id.equals(cadr(car(cart)))) + if(id.equals(cadr(car(cart)))) return car(cart); - return find(id, cdr(cart)); - } - - public Iterable<?> get(String id, Service cache) { - return find(id, getcart(cartId, cache)); + return this.find(id, cdr(cart)); } /** - * Delete the whole cart. + * Return items from the cart. */ - public Boolean deleteall(Service cache) { - return cache.delete(cartId); + public Iterable<?> get(final Iterable<String> id, final Service cache) { + if(isNil(id)) + return cons("Your Cart", cons(cartId, this.getcart(cartId, cache))); + return this.find((String)car(id), this.getcart(cartId, cache)); } /** - * Delete an item from the cart. + * Delete items from the cart. */ - public Boolean delete(String id, Service cache) { + public Boolean delete(final Iterable<String> id, final Service cache) { + if(isNil(id)) { + final Iterable<String> iid = list(cartId); + return cache.delete(iid); + } return true; } /** * Return the price of an item. */ - Double price(Iterable<?> item) { + Double price(final Iterable<?> item) { return Double.valueOf((String)cadr(assoc("'price", caddr(item)))); } /** * Sum the prices of a list of items. */ - Double sum(Iterable<?> items) { - if (isNil(items)) + Double sum(final Iterable<?> items) { + if(isNil(items)) return 0.0; - return price((Iterable<?>)car(items)) + sum(cdr(items)); + return this.price((Iterable<?>)car(items)) + this.sum(cdr(items)); } /** * Return the total price of the items in the cart. */ - public Double gettotal(Service cache) { - Iterable<?> cart = getcart(cartId, cache); - return sum(cart); + public Double gettotal(final Service cache) { + final Iterable<?> cart = this.getcart(cartId, cache); + return this.sum(cart); } /** @@ -126,5 +123,5 @@ public class ShoppingCartImpl { public Iterable<?> listMethods(final Service cache) { return list("Service.gettotal"); } - + } diff --git a/sca-cpp/trunk/test/store-python/shopping-cart.py b/sca-cpp/trunk/test/store-python/shopping-cart.py index 083cd94fe0..988fe7bea6 100644 --- a/sca-cpp/trunk/test/store-python/shopping-cart.py +++ b/sca-cpp/trunk/test/store-python/shopping-cart.py @@ -24,21 +24,18 @@ cartId = "1234" # Get the shopping cart from the cache # Return an empty cart if not found def getcart(id, cache): - cart = cache("get", id) + cart = cache("get", (id,)) if cart is None: return () return cart # Post a new item to the cart, create a new cart if necessary -def post(item, cache): +def post(collection, item, cache): id = str(uuid.uuid1()) cart = ((item[0], id, item[2]),) + getcart(cartId, cache) - cache("put", cartId, cart) - return id + cache("put", (cartId,), cart) + return (id,) -# Return the content of the cart -def getall(cache): - return ("Your Cart", cartId) + getcart(cartId, cache) # Find an item in the cart def find(id, cart): @@ -49,16 +46,16 @@ def find(id, cart): else: return find(id, cart[1:]) -# Get an item from the cart +# Get items from the cart def get(id, cache): - return find(id, getcart(cartId, cache)) + if id == (): + return ("Your Cart", cartId) + getcart(cartId, cache) + return find(id[0], getcart(cartId, cache)) -# Delete the whole cart -def deleteall(cache): - return cache("delete", cartId) - -# Delete an item from the cart +# Delete items from the cart def delete(id, cache): + if id == (): + return cache("delete", (cartId,)) return true # Return the price of an item @@ -79,4 +76,3 @@ def gettotal(cache): # TODO remove these JSON-RPC specific functions def listMethods(cache): return ("Service.gettotal",) - diff --git a/sca-cpp/trunk/test/store-scheme/shopping-cart.scm b/sca-cpp/trunk/test/store-scheme/shopping-cart.scm index f6a4cd3cfa..484044d420 100644 --- a/sca-cpp/trunk/test/store-scheme/shopping-cart.scm +++ b/sca-cpp/trunk/test/store-scheme/shopping-cart.scm @@ -22,24 +22,19 @@ ; Get the shopping cart from the cache ; Return an empty cart if not found (define (getcart id cache) - (define cart (cache "get" id)) + (define cart (cache "get" (list id))) (if (nul cart) (list) cart) ) ; Post a new item to the cart, create a new cart if necessary -(define (post item cache) +(define (post collection item cache) (define id (uuid)) (define newItem (list (car item) id (caddr item))) (define cart (cons newItem (getcart cartId cache))) - (cache "put" cartId cart) - id -) - -; Return the content of the cart -(define (getall cache) - (cons "Your Cart" (cons cartId (getcart cartId cache))) + (cache "put" (list cartId) cart) + (list id) ) ; Find an item in the cart @@ -51,19 +46,20 @@ (find id (cdr cart)))) ) -; Get an item from the cart +; Get items from the cart (define (get id cache) - (find id (getcart cartId cache)) + (if (nul id) + (cons "Your Cart" (cons cartId (getcart cartId cache))) + (find (car id) (getcart cartId cache)) + ) ) -; Delete the whole cart -(define (deleteall cache) - (cache "delete" cartId) -) - -; Delete an item from the cart +; Delete items from the cart (define (delete id cache) - true + (if (nul id) + (cache "delete" (list cartId)) + true + ) ) ; Return the price of an item @@ -86,4 +82,3 @@ ; TODO remove these JSON-RPC specific functions (define (listMethods cache) (list "Service.gettotal")) - |