diff options
author | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2010-01-11 08:29:17 +0000 |
---|---|---|
committer | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2010-01-11 08:29:17 +0000 |
commit | 8015f0d53da53876b65fdcdc712f1dc92835a9b1 (patch) | |
tree | 4cffc808317d16435c19289bd2a14d88a357f088 /sca-cpp/trunk/test/store-python | |
parent | 11c57b87a39a30904cdf24ef81c770e8f17096a1 (diff) |
Minor fixes to server and python evaluator to get python store working. Some changes to python and scheme store test cases to simplify them a bit and make them consistent. Enabled a few more server test combinations.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@897785 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r-- | sca-cpp/trunk/test/store-python/Makefile.am | 2 | ||||
-rw-r--r-- | sca-cpp/trunk/test/store-python/currency-converter.py | 10 | ||||
-rw-r--r-- | sca-cpp/trunk/test/store-python/fruits-catalog.py | 10 | ||||
-rw-r--r-- | sca-cpp/trunk/test/store-python/htdocs/store.html | 4 | ||||
-rwxr-xr-x | sca-cpp/trunk/test/store-python/server-test (renamed from sca-cpp/trunk/test/store-python/store-composite-test) | 0 | ||||
-rw-r--r-- | sca-cpp/trunk/test/store-python/shopping-cart.py | 88 | ||||
-rw-r--r-- | sca-cpp/trunk/test/store-python/store.py | 7 |
7 files changed, 51 insertions, 70 deletions
diff --git a/sca-cpp/trunk/test/store-python/Makefile.am b/sca-cpp/trunk/test/store-python/Makefile.am index daefd9a405..345e58d544 100644 --- a/sca-cpp/trunk/test/store-python/Makefile.am +++ b/sca-cpp/trunk/test/store-python/Makefile.am @@ -15,5 +15,5 @@ # specific language governing permissions and limitations # under the License. -TESTS = store-composite-test +TESTS = server-test diff --git a/sca-cpp/trunk/test/store-python/currency-converter.py b/sca-cpp/trunk/test/store-python/currency-converter.py index 1ee39b63f3..61d3ae42ac 100644 --- a/sca-cpp/trunk/test/store-python/currency-converter.py +++ b/sca-cpp/trunk/test/store-python/currency-converter.py @@ -1,14 +1,12 @@ # Currency converter implementation def convert(fr, to, amount): - if (to == "EUR") + if to == "EUR": return amount * 0.70 - else - return amount + return amount def symbol(currency): - if (currency == "EUR") + if currency == "EUR": return "E" - else - return "$" + return "$" diff --git a/sca-cpp/trunk/test/store-python/fruits-catalog.py b/sca-cpp/trunk/test/store-python/fruits-catalog.py index 5fcb9216c2..ea71e93b22 100644 --- a/sca-cpp/trunk/test/store-python/fruits-catalog.py +++ b/sca-cpp/trunk/test/store-python/fruits-catalog.py @@ -3,17 +3,15 @@ def get(converter): def convert(price): return converter("convert", "USD", "USD", price) - code = "USD") + code = "USD" symbol = converter("symbol", code) return ( (("'javaClass", "services.Item"), ("'name", "Apple"), ("'currencyCode", code), ("'currencySymbol", symbol), ("'price", convert(2.99))), (("'javaClass", "services.Item"), ("'name", "Orange"), ("'currencyCode", code), ("'currencySymbol", symbol), ("'price", convert(3.55))), - (("'javaClass", "services.Item"), ("'name", "Pear"), ("'currencyCode", code), ("'currencySymbol", symbol), ("'price" convert(1.55))) + (("'javaClass", "services.Item"), ("'name", "Pear"), ("'currencyCode", code), ("'currencySymbol", symbol), ("'price", convert(1.55))) ) # TODO remove these JSON-RPC specific functions -def system.listMethods(converter): - return ("Service.get") - -Service.get = get +def listMethods(converter): + return ("Service.get",) diff --git a/sca-cpp/trunk/test/store-python/htdocs/store.html b/sca-cpp/trunk/test/store-python/htdocs/store.html index f8c6027abe..21eabca7a7 100644 --- a/sca-cpp/trunk/test/store-python/htdocs/store.html +++ b/sca-cpp/trunk/test/store-python/htdocs/store.html @@ -51,7 +51,7 @@ catalogItems = items;
// TEMP
- shoppingTotal.getTotal(shoppingTotal_getTotalResponse);
+ shoppingTotal.gettotal(shoppingTotal_getTotalResponse);
}
function shoppingCart_getResponse(feed) {
@@ -68,7 +68,7 @@ if (entries.length != 0) {
try {
- shoppingTotal.getTotal(shoppingTotal_getTotalResponse);
+ shoppingTotal.gettotal(shoppingTotal_getTotalResponse);
}
catch(e){
alert(e);
diff --git a/sca-cpp/trunk/test/store-python/store-composite-test b/sca-cpp/trunk/test/store-python/server-test index b41c4e5393..b41c4e5393 100755 --- a/sca-cpp/trunk/test/store-python/store-composite-test +++ b/sca-cpp/trunk/test/store-python/server-test diff --git a/sca-cpp/trunk/test/store-python/shopping-cart.py b/sca-cpp/trunk/test/store-python/shopping-cart.py index cc89bb6c99..317038d93f 100644 --- a/sca-cpp/trunk/test/store-python/shopping-cart.py +++ b/sca-cpp/trunk/test/store-python/shopping-cart.py @@ -1,77 +1,65 @@ # Shopping cart implementation +import uuid +import sys cartId = "1234" -#TODO finish conversion from scheme to python - # Get the shopping cart from the cache # Return an empty cart if not found -(define (getcart id cache) - (define cart (cache "get" id)) - (if (nul cart) - (list) - cart) -) +def getcart(id, cache): + cart = cache("get", id) + if cart is None: + return () + return cart # Post a new item to the cart, create a new cart if necessary -(define (post 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 -) +def post(item, cache): + id = str(uuid.uuid1()) + cart = ((item[0], id, item[2]),) + getcart(cartId, cache) + cache("put", cartId, cart) + return id # Return the content of the cart -(define (getall cache) - (cons "Your Cart" (cons cartId (getcart cartId cache))) -) +def getall(cache): + return ("Your Cart", cartId) + getcart(cartId, cache) # Find an item in the cart -(define (find id cart) - (if (nul cart) - (cons "Item" (list "0" (list))) - (if (= id (cadr (car cart))) - (car cart) - (find id (cdr cart)))) -) +def find(id, cart): + if cart == (): + return ("Item", "0", ()) + elif id == cart[0][1]: + return cart[0] + else: + return find(id, cart[1:]) # Get an item from the cart -(define (get id cache) - (find id (getcart cartId cache)) -) +def get(id, cache): + return find(id, getcart(cartId, cache)) # Delete the whole cart -(define (deleteall cache) - (cache "delete" cartId) -) +def deleteall(cache): + return cache("delete", cartId) # Delete an item from the cart -(define (delete id cache) - true -) +def delete(id, cache): + return true # Return the price of an item -(define (price item) - (cadr (assoc 'price (caddr item))) -) +def price(item): + return float(filter(lambda x: x[0] == "'price", item[2])[0][1]) # Sum the prices of a list of items -(define (sum items) - (if (nul items) - 0 - (+ (price (car items)) (sum (cdr items)))) -) +def sum(items): + if items == (): + return 0 + return price(items[0]) + sum(items[1:]) # Return the total price of the items in the cart -(define (gettotal cache) - (define cart (getcart cartId cache)) - (sum cart) -) +def gettotal(cache): + cart = getcart(cartId, cache) + return sum(cart) # TODO remove these JSON-RPC specific functions -def system.listMethods(cache): - return ("Service.getTotal") - -Service.getTotal = gettotal +def listMethods(cache): + return ("Service.gettotal",) diff --git a/sca-cpp/trunk/test/store-python/store.py b/sca-cpp/trunk/test/store-python/store.py index 942544a3b2..54fd315fea 100644 --- a/sca-cpp/trunk/test/store-python/store.py +++ b/sca-cpp/trunk/test/store-python/store.py @@ -22,9 +22,6 @@ def delete(id, catalog, shoppingCart, shoppingTotal): return shoppingCart("delete", id) # TODO remove these JSON-RPC specific functions -def system.listMethods(catalog, shoppingCart, shoppingTotal): - return ("Service.get", "Service.getTotal") - -Service.getCatalog = getcatalog -Service.getTotal = gettotal +def listMethods(catalog, shoppingCart, shoppingTotal): + return ("Service.get", "Service.gettotal") |