From 8015f0d53da53876b65fdcdc712f1dc92835a9b1 Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Mon, 11 Jan 2010 08:29:17 +0000 Subject: 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 --- sca-cpp/trunk/test/store-python/Makefile.am | 2 +- .../trunk/test/store-python/currency-converter.py | 10 +- sca-cpp/trunk/test/store-python/fruits-catalog.py | 10 +- sca-cpp/trunk/test/store-python/htdocs/store.html | 4 +- sca-cpp/trunk/test/store-python/server-test | 51 +++++++ sca-cpp/trunk/test/store-python/shopping-cart.py | 88 ++++++------ .../trunk/test/store-python/store-composite-test | 51 ------- sca-cpp/trunk/test/store-python/store.py | 7 +- sca-cpp/trunk/test/store-scheme/Makefile.am | 10 +- sca-cpp/trunk/test/store-scheme/fruits-catalog.scm | 3 +- sca-cpp/trunk/test/store-scheme/htdocs/store.html | 4 +- sca-cpp/trunk/test/store-scheme/script-test.cpp | 96 +++++++++++++ sca-cpp/trunk/test/store-scheme/script-test.scm | 123 +++++++++++++++++ sca-cpp/trunk/test/store-scheme/server-test | 51 +++++++ sca-cpp/trunk/test/store-scheme/shopping-cart.scm | 3 +- .../trunk/test/store-scheme/store-composite-test | 51 ------- .../trunk/test/store-scheme/store-script-test.cpp | 96 ------------- .../trunk/test/store-scheme/store-script-test.scm | 149 --------------------- sca-cpp/trunk/test/store-scheme/store.scm | 4 +- 19 files changed, 382 insertions(+), 431 deletions(-) create mode 100755 sca-cpp/trunk/test/store-python/server-test delete mode 100755 sca-cpp/trunk/test/store-python/store-composite-test create mode 100644 sca-cpp/trunk/test/store-scheme/script-test.cpp create mode 100644 sca-cpp/trunk/test/store-scheme/script-test.scm create mode 100755 sca-cpp/trunk/test/store-scheme/server-test delete mode 100755 sca-cpp/trunk/test/store-scheme/store-composite-test delete mode 100644 sca-cpp/trunk/test/store-scheme/store-script-test.cpp delete mode 100644 sca-cpp/trunk/test/store-scheme/store-script-test.scm (limited to 'sca-cpp/trunk/test') 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/server-test b/sca-cpp/trunk/test/store-python/server-test new file mode 100755 index 0000000000..b41c4e5393 --- /dev/null +++ b/sca-cpp/trunk/test/store-python/server-test @@ -0,0 +1,51 @@ +#!/bin/sh + +# 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. + +echo "Testing..." + +# Setup +../../modules/http/httpd-conf tmp 8090 htdocs +../../modules/server/server-conf tmp +cat >>tmp/conf/httpd.conf < +SCAContribution `pwd`/ +SCAComposite store.composite + +EOF + +apachectl -k start -d `pwd`/tmp + +mc="memcached -l 127.0.0.1 -m 4 -p 11211" +$mc & +sleep 2 + +# Test HTTP GET +curl http://localhost:8090/store.html 2>/dev/null >tmp/store.html +diff tmp/store.html htdocs/store.html +rc=$? + +# Cleanup +apachectl -k stop -d `pwd`/tmp +kill `ps -f | grep -v grep | grep "$mc" | awk '{ print $2 }'` +sleep 2 +if [ "$rc" = "0" ]; then + echo "OK" +fi +return $rc 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-composite-test b/sca-cpp/trunk/test/store-python/store-composite-test deleted file mode 100755 index b41c4e5393..0000000000 --- a/sca-cpp/trunk/test/store-python/store-composite-test +++ /dev/null @@ -1,51 +0,0 @@ -#!/bin/sh - -# 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. - -echo "Testing..." - -# Setup -../../modules/http/httpd-conf tmp 8090 htdocs -../../modules/server/server-conf tmp -cat >>tmp/conf/httpd.conf < -SCAContribution `pwd`/ -SCAComposite store.composite - -EOF - -apachectl -k start -d `pwd`/tmp - -mc="memcached -l 127.0.0.1 -m 4 -p 11211" -$mc & -sleep 2 - -# Test HTTP GET -curl http://localhost:8090/store.html 2>/dev/null >tmp/store.html -diff tmp/store.html htdocs/store.html -rc=$? - -# Cleanup -apachectl -k stop -d `pwd`/tmp -kill `ps -f | grep -v grep | grep "$mc" | awk '{ print $2 }'` -sleep 2 -if [ "$rc" = "0" ]; then - echo "OK" -fi -return $rc 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") diff --git a/sca-cpp/trunk/test/store-scheme/Makefile.am b/sca-cpp/trunk/test/store-scheme/Makefile.am index fc6a1f88fb..19b2640f3b 100644 --- a/sca-cpp/trunk/test/store-scheme/Makefile.am +++ b/sca-cpp/trunk/test/store-scheme/Makefile.am @@ -15,12 +15,12 @@ # specific language governing permissions and limitations # under the License. -noinst_PROGRAMS = store-script-test +noinst_PROGRAMS = script-test INCLUDES = -I. -I$(top_builddir)/kernel -I${LIBXML2_INCLUDE} -I${APR_INCLUDE} -I${JS_INCLUDE} -store_script_test_SOURCES = store-script-test.cpp -store_script_test_LDADD = -L${LIBXML2_LIB} -lxml2 -L${APR_LIB} -lapr-1 -laprutil-1 -L${JS_LIB} -lmozjs - -TESTS = store-script-test store-composite-test +script_test_SOURCES = script-test.cpp +script_test_LDADD = -L${LIBXML2_LIB} -lxml2 -L${APR_LIB} -lapr-1 -laprutil-1 -L${JS_LIB} -lmozjs + +TESTS = script-test server-test diff --git a/sca-cpp/trunk/test/store-scheme/fruits-catalog.scm b/sca-cpp/trunk/test/store-scheme/fruits-catalog.scm index 18128f0137..173bcbe9c0 100644 --- a/sca-cpp/trunk/test/store-scheme/fruits-catalog.scm +++ b/sca-cpp/trunk/test/store-scheme/fruits-catalog.scm @@ -12,6 +12,5 @@ ) ; TODO remove these JSON-RPC specific functions -(define (system.listMethods converter) (list "Service.get")) -(define Service.get get) +(define (listMethods converter) (list "Service.get")) diff --git a/sca-cpp/trunk/test/store-scheme/htdocs/store.html b/sca-cpp/trunk/test/store-scheme/htdocs/store.html index f8c6027abe..21eabca7a7 100644 --- a/sca-cpp/trunk/test/store-scheme/htdocs/store.html +++ b/sca-cpp/trunk/test/store-scheme/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-scheme/script-test.cpp b/sca-cpp/trunk/test/store-scheme/script-test.cpp new file mode 100644 index 0000000000..c8eecb65c3 --- /dev/null +++ b/sca-cpp/trunk/test/store-scheme/script-test.cpp @@ -0,0 +1,96 @@ +/* + * 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. + */ + +/* $Rev$ $Date$ */ + +/** + * Store Test case. + */ + +#include +#include +#include "stream.hpp" +#include "string.hpp" +#include "list.hpp" +#include "xml.hpp" +#include "../../modules/scheme/driver.hpp" +#include "../../modules/json/json.hpp" + +namespace store { + +using namespace tuscany; + +bool testScript() { + gc_scoped_pool pool; + + ifstream is("script-test.scm"); + ostringstream os; + scheme::evalDriverRun(is, os); + assert(contains(str(os), "(\"Sample Feed\" \"")); + assert(contains(str(os), "\" (\"Item\" \"")); + assert(contains(str(os), "\" ((javaClass \"services.Item\") (name \"Orange\") (currencyCode \"USD\") (currencySymbol \"$\") (price 3.55))) (\"Item\" \"")); + assert(contains(str(os), "\" ((javaClass \"services.Item\") (name \"Apple\") (currencyCode \"USD\") (currencySymbol \"$\") (price 2.99))))")); + return true; +} + +bool testEval() { + { + gc_scoped_pool pool; + ifstream is("script-test.scm"); + ostringstream os; + scheme::setupDisplay(os); + scheme::Env globalEnv = scheme::setupEnvironment(); + const value exp(mklist("storeui_service", string("getcatalog"))); + const value val = scheme::evalScript(exp, is, globalEnv); + + ostringstream vs; + vs << val; + assert(contains(str(vs), "(((javaClass \"services.Item\") (name \"Apple\") (currencyCode \"USD\") (currencySymbol \"$\") (price 2.99)) ((javaClass \"services.Item\") (name \"Orange\") (currencyCode \"USD\") (currencySymbol \"$\") (price 3.55)) ((javaClass \"services.Item\") (name \"Pear\") (currencyCode \"USD\") (currencySymbol \"$\") (price 1.55)))")); + } + + { + gc_scoped_pool pool; + ifstream is("script-test.scm"); + ostringstream os; + scheme::setupDisplay(os); + + scheme::Env globalEnv = scheme::setupEnvironment(); + const value exp(mklist("storeui_service", string("gettotal"))); + const value res = scheme::evalScript(exp, is, globalEnv); + + ostringstream rs; + rs << res; + assert(contains(str(rs), "10")); + } + return true; +} + +} + +int main() { + + tuscany::cout << "Testing..." << tuscany::endl; + + store::testScript(); + store::testEval(); + + tuscany::cout << "OK" << tuscany::endl; + + return 0; +} diff --git a/sca-cpp/trunk/test/store-scheme/script-test.scm b/sca-cpp/trunk/test/store-scheme/script-test.scm new file mode 100644 index 0000000000..711656019a --- /dev/null +++ b/sca-cpp/trunk/test/store-scheme/script-test.scm @@ -0,0 +1,123 @@ +; Currency implementation + +(define (currency_convert from to amount) + (if (equal? to "EUR") (* amount 0.70) amount) +) + +(define (currency_symbol currency) + (if (equal? currency "EUR") "E" "$") +) + +(define (currency_impl op args) + (cond + ((equal? op "convert") (apply currency_convert args)) + ((equal? op "symbol") (apply currency_symbol args)) + ) +) + +; Currency composite + +(define (currency_service op . args) (currency_impl op args)) + +; Catalog implementation + +(define (catalog_get converter) + (define (convert price) (converter "convert" "USD" "USD" price)) + + (define code "USD") + (define symbol (converter "symbol" code)) + + (list + (list (list 'javaClass "services.Item") (list 'name "Apple") (list 'currencyCode code) (list 'currencySymbol symbol) (list 'price 2.99)) + (list (list 'javaClass "services.Item") (list 'name "Orange") (list 'currencyCode code) (list 'currencySymbol symbol) (list 'price 3.55)) + (list (list 'javaClass "services.Item") (list 'name "Pear") (list 'currencyCode code) (list 'currencySymbol symbol) (list 'price 1.55)) + ) +) + +(define (catalog_impl converter op args) + (cond + ((equal? op "get") (apply catalog_get (cons converter args))) + ) +) + +; Catalog composite + +(define (catalog_service op . args) (catalog_impl currency_service op args)) + +; Cart implementation + +(define (cart_post content item) + (cons (cons "Item" (list (uuid) item)) content) +) + +(define (cart_getall content) + (cons "Sample Feed" (cons (uuid) content)) +) + +(define (cart_getentry id) + (define entry (list (list 'name "Apple") (list 'currencyCode "USD") (list 'currencySymbol "$") (list 'price 2.99))) + (cons "Item" (list id entry)) +) + +(define (cart_gettotal) + 10.0 +) + +(define (cart_impl op args) + (cond + ((equal? op "post") (apply cart_post args)) + ((equal? op "getall") (apply cart_getall args)) + ((equal? op "getentry") (apply cart_getentry args)) + ((equal? op "gettotal") (apply cart_gettotal args)) + ) +) + +; Store UI implementation + +(define (storeui_post cart content item) + (cart "post" content item) +) + +(define (storeui_getcart cart content) + (cart "getall" content) +) + +(define (storeui_getentry cart id) + (cart "getentry" id) +) + +(define (storeui_getcatalog catalog) + (catalog "get") +) + +(define (storeui_gettotal cart) + (cart "gettotal") +) + +(define (storeui_impl cart catalog op args) + (cond + ((equal? op "post") (apply storeui_post (cons cart args))) + ((equal? op "getall") (apply storeui_getcart (cons cart args))) + ((equal? op "getentry") (apply storeui_getentry (cons cart args))) + ((equal? op "getcatalog") (apply storeui_getcatalog (cons catalog args))) + ((equal? op "gettotal") (apply storeui_gettotal (cons cart args))) + ) +) + +; Store UI composite + +(define (cart_service op . args) (cart_impl op args)) + +(define (storeui_service op . args) (storeui_impl cart_service catalog_service op args)) + +; Store UI test case + +(define catalog (storeui_service "getcatalog")) +(define empty (list)) +(define apple (car catalog)) +(define orange (car (cdr catalog))) +(define added1 (storeui_service "post" empty apple)) +(define added2 (storeui_service "post" added1 orange)) +(display (storeui_service "getall" added2)) +(display (storeui_service "gettotal")) + diff --git a/sca-cpp/trunk/test/store-scheme/server-test b/sca-cpp/trunk/test/store-scheme/server-test new file mode 100755 index 0000000000..b41c4e5393 --- /dev/null +++ b/sca-cpp/trunk/test/store-scheme/server-test @@ -0,0 +1,51 @@ +#!/bin/sh + +# 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. + +echo "Testing..." + +# Setup +../../modules/http/httpd-conf tmp 8090 htdocs +../../modules/server/server-conf tmp +cat >>tmp/conf/httpd.conf < +SCAContribution `pwd`/ +SCAComposite store.composite + +EOF + +apachectl -k start -d `pwd`/tmp + +mc="memcached -l 127.0.0.1 -m 4 -p 11211" +$mc & +sleep 2 + +# Test HTTP GET +curl http://localhost:8090/store.html 2>/dev/null >tmp/store.html +diff tmp/store.html htdocs/store.html +rc=$? + +# Cleanup +apachectl -k stop -d `pwd`/tmp +kill `ps -f | grep -v grep | grep "$mc" | awk '{ print $2 }'` +sleep 2 +if [ "$rc" = "0" ]; then + echo "OK" +fi +return $rc diff --git a/sca-cpp/trunk/test/store-scheme/shopping-cart.scm b/sca-cpp/trunk/test/store-scheme/shopping-cart.scm index 60981411c7..77a98c9fd7 100644 --- a/sca-cpp/trunk/test/store-scheme/shopping-cart.scm +++ b/sca-cpp/trunk/test/store-scheme/shopping-cart.scm @@ -68,6 +68,5 @@ ) ; TODO remove these JSON-RPC specific functions -(define (system.listMethods cache) (list "Service.getTotal")) -(define Service.getTotal gettotal) +(define (listMethods cache) (list "Service.gettotal")) diff --git a/sca-cpp/trunk/test/store-scheme/store-composite-test b/sca-cpp/trunk/test/store-scheme/store-composite-test deleted file mode 100755 index b41c4e5393..0000000000 --- a/sca-cpp/trunk/test/store-scheme/store-composite-test +++ /dev/null @@ -1,51 +0,0 @@ -#!/bin/sh - -# 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. - -echo "Testing..." - -# Setup -../../modules/http/httpd-conf tmp 8090 htdocs -../../modules/server/server-conf tmp -cat >>tmp/conf/httpd.conf < -SCAContribution `pwd`/ -SCAComposite store.composite - -EOF - -apachectl -k start -d `pwd`/tmp - -mc="memcached -l 127.0.0.1 -m 4 -p 11211" -$mc & -sleep 2 - -# Test HTTP GET -curl http://localhost:8090/store.html 2>/dev/null >tmp/store.html -diff tmp/store.html htdocs/store.html -rc=$? - -# Cleanup -apachectl -k stop -d `pwd`/tmp -kill `ps -f | grep -v grep | grep "$mc" | awk '{ print $2 }'` -sleep 2 -if [ "$rc" = "0" ]; then - echo "OK" -fi -return $rc diff --git a/sca-cpp/trunk/test/store-scheme/store-script-test.cpp b/sca-cpp/trunk/test/store-scheme/store-script-test.cpp deleted file mode 100644 index fe2a64e57f..0000000000 --- a/sca-cpp/trunk/test/store-scheme/store-script-test.cpp +++ /dev/null @@ -1,96 +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. - */ - -/* $Rev$ $Date$ */ - -/** - * Store Test case. - */ - -#include -#include -#include "stream.hpp" -#include "string.hpp" -#include "list.hpp" -#include "xml.hpp" -#include "../../modules/scheme/driver.hpp" -#include "../../modules/json/json.hpp" - -namespace store { - -using namespace tuscany; - -bool testScript() { - gc_scoped_pool pool; - - ifstream is("store-script-test.scm"); - ostringstream os; - scheme::evalDriverRun(is, os); - assert(contains(str(os), "(\"Sample Feed\" \"")); - assert(contains(str(os), "\" (\"Item\" \"")); - assert(contains(str(os), "\" ((javaClass \"services.Item\") (name \"Orange\") (currencyCode \"USD\") (currencySymbol \"$\") (price 3.55))) (\"Item\" \"")); - assert(contains(str(os), "\" ((javaClass \"services.Item\") (name \"Apple\") (currencyCode \"USD\") (currencySymbol \"$\") (price 2.99))))")); - return true; -} - -bool testEval() { - { - gc_scoped_pool pool; - ifstream is("store-script-test.scm"); - ostringstream os; - scheme::setupDisplay(os); - scheme::Env globalEnv = scheme::setupEnvironment(); - const value exp(mklist("storeui_service", string("getcatalog"))); - const value val = scheme::evalScript(exp, is, globalEnv); - - ostringstream vs; - vs << val; - assert(contains(str(vs), "(((javaClass \"services.Item\") (name \"Apple\") (currencyCode \"USD\") (currencySymbol \"$\") (price 2.99)) ((javaClass \"services.Item\") (name \"Orange\") (currencyCode \"USD\") (currencySymbol \"$\") (price 3.55)) ((javaClass \"services.Item\") (name \"Pear\") (currencyCode \"USD\") (currencySymbol \"$\") (price 1.55)))")); - } - - { - gc_scoped_pool pool; - ifstream is("store-script-test.scm"); - ostringstream os; - scheme::setupDisplay(os); - - scheme::Env globalEnv = scheme::setupEnvironment(); - const value exp(mklist("storeui_service", string("gettotal"))); - const value res = scheme::evalScript(exp, is, globalEnv); - - ostringstream rs; - rs << res; - assert(contains(str(rs), "10")); - } - return true; -} - -} - -int main() { - - tuscany::cout << "Testing..." << tuscany::endl; - - store::testScript(); - store::testEval(); - - tuscany::cout << "OK" << tuscany::endl; - - return 0; -} diff --git a/sca-cpp/trunk/test/store-scheme/store-script-test.scm b/sca-cpp/trunk/test/store-scheme/store-script-test.scm deleted file mode 100644 index 30c10d8184..0000000000 --- a/sca-cpp/trunk/test/store-scheme/store-script-test.scm +++ /dev/null @@ -1,149 +0,0 @@ -; Currency implementation - -(define (currency_convert from to amount) - (if (equal? to "EUR") (* amount 0.70) amount) -) - -(define (currency_symbol currency) - (if (equal? currency "EUR") "E" "$") -) - -(define (currency_impl op args) - (cond - ((equal? op "convert") (apply currency_convert args)) - ((equal? op "symbol") (apply currency_symbol args)) - ) -) - -; Currency composite - -(define (currency_service op . args) (currency_impl op args)) - -; Catalog implementation - -(define (catalog_get converter) - (define (convert price) (converter "convert" "USD" "USD" price)) - - (define code "USD") - (define symbol (converter "symbol" code)) - - (list - (list (list 'javaClass "services.Item") (list 'name "Apple") (list 'currencyCode code) (list 'currencySymbol symbol) (list 'price 2.99)) - (list (list 'javaClass "services.Item") (list 'name "Orange") (list 'currencyCode code) (list 'currencySymbol symbol) (list 'price 3.55)) - (list (list 'javaClass "services.Item") (list 'name "Pear") (list 'currencyCode code) (list 'currencySymbol symbol) (list 'price 1.55)) - ) -) - -(define (catalog_impl converter op args) - (cond - ((equal? op "get") (apply catalog_get (cons converter args))) - ) -) - -; Catalog composite - -(define (catalog_service op . args) (catalog_impl currency_service op args)) - -; Cart implementation - -(define (cart_post content item) - (cons (cons "Item" (list (uuid) item)) content) -) - -(define (cart_getall content) - (cons "Sample Feed" (cons (uuid) content)) -) - -(define (cart_getentry id) - (define entry (list (list 'name "Apple") (list 'currencyCode "USD") (list 'currencySymbol "$") (list 'price 2.99))) - (cons "Item" (list id entry)) -) - -(define (cart_gettotal) - 10.0 -) - -(define (cart_impl op args) - (cond - ((equal? op "post") (apply cart_post args)) - ((equal? op "getall") (apply cart_getall args)) - ((equal? op "getentry") (apply cart_getentry args)) - ((equal? op "gettotal") (apply cart_gettotal args)) - ) -) - -; Store UI implementation - -(define (storeui_post cart content item) - (cart "post" content item) -) - -(define (storeui_getcart cart content) - (cart "getall" content) -) - -(define (storeui_getentry cart id) - (cart "getentry" id) -) - -(define (storeui_getcatalog catalog) - (catalog "get") -) - -(define (storeui_gettotal cart) - (cart "gettotal") -) - -(define (storeui_impl cart catalog op args) - (cond - ((equal? op "post") (apply storeui_post (cons cart args))) - ((equal? op "getall") (apply storeui_getcart (cons cart args))) - ((equal? op "getentry") (apply storeui_getentry (cons cart args))) - ((equal? op "getcatalog") (apply storeui_getcatalog (cons catalog args))) - ((equal? op "gettotal") (apply storeui_gettotal (cons cart args))) - ) -) - -; Store UI composite - -(define (cart_service op . args) (cart_impl op args)) - -(define (storeui_service op . args) (storeui_impl cart_service catalog_service op args)) - -; Store UI test case - -(define catalog (storeui_service "getcatalog")) -(define empty (list)) -(define apple (car catalog)) -(define orange (car (cdr catalog))) -(define added1 (storeui_service "post" empty apple)) -(define added2 (storeui_service "post" added1 orange)) -(display (storeui_service "getall" added2)) -(display (storeui_service "gettotal")) - -; Store UI JSON-RPC interop test case - -(define (system.listMethods) (list "Service.get" "Service.getTotal")) - -(define (Service.get) (storeui_service "getcatalog")) - -(define (.get) (storeui_service "getcatalog")) - -(define (Service.getTotal) (storeui_service "gettotal")) - -; Store UI ATOMPub interop test case - -(define (getall) (storeui_service "getall" added2)) - -(define (get id) (storeui_service "getentry" id)) - -(define (post entry) - (display entry) - (uuid) -) - -(define (delete id) - (display id) - true -) - diff --git a/sca-cpp/trunk/test/store-scheme/store.scm b/sca-cpp/trunk/test/store-scheme/store.scm index e325a65d74..0091af542d 100644 --- a/sca-cpp/trunk/test/store-scheme/store.scm +++ b/sca-cpp/trunk/test/store-scheme/store.scm @@ -29,7 +29,5 @@ ) ; TODO remove these JSON-RPC specific functions -(define (system.listMethods catalog shoppingCart shoppingTotal) (list "Service.get" "Service.getTotal")) -(define Service.getCatalog getcatalog) -(define Service.getTotal gettotal) +(define (listMethods catalog shoppingCart shoppingTotal) (list "Service.getcatalog" "Service.gettotal")) -- cgit v1.2.3