From 51a97b5d9350b37f95d6f0c00d013b886e64fcd3 Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Mon, 16 Nov 2009 06:01:41 +0000 Subject: Added test cases and scripts to test the HTTP binding support. Refactored httpd module and added a wiring httpd module. Implementation of the store demo prepared for ApacheCon. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@880601 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/sca/test/store-script/catalogs.composite | 43 ------- cpp/sca/test/store-script/currency-converter.scm | 9 ++ cpp/sca/test/store-script/currency.composite | 16 +-- cpp/sca/test/store-script/fruits-catalog.scm | 19 +++ cpp/sca/test/store-script/shopping-cart.scm | 26 ++++ cpp/sca/test/store-script/store-http-test | 39 ++++-- cpp/sca/test/store-script/store-script-test.cpp | 28 ++--- cpp/sca/test/store-script/store-script.scm | 149 +++++++++++++++++++++++ cpp/sca/test/store-script/store.composite | 71 ++++++----- cpp/sca/test/store-script/store.scm | 147 +++------------------- 10 files changed, 300 insertions(+), 247 deletions(-) delete mode 100644 cpp/sca/test/store-script/catalogs.composite create mode 100644 cpp/sca/test/store-script/currency-converter.scm create mode 100644 cpp/sca/test/store-script/fruits-catalog.scm create mode 100644 cpp/sca/test/store-script/shopping-cart.scm create mode 100644 cpp/sca/test/store-script/store-script.scm (limited to 'cpp/sca/test') diff --git a/cpp/sca/test/store-script/catalogs.composite b/cpp/sca/test/store-script/catalogs.composite deleted file mode 100644 index 1638ed0a05..0000000000 --- a/cpp/sca/test/store-script/catalogs.composite +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - - - - USD - - - - - - - - - - - - - diff --git a/cpp/sca/test/store-script/currency-converter.scm b/cpp/sca/test/store-script/currency-converter.scm new file mode 100644 index 0000000000..7f58335951 --- /dev/null +++ b/cpp/sca/test/store-script/currency-converter.scm @@ -0,0 +1,9 @@ +; Currency converter implementation + +(define (convert from to amount) + (if (equal? to "EUR") (* amount 0.70) amount) +) + +(define (symbol currency) + (if (equal? currency "EUR") "E" "$") +) diff --git a/cpp/sca/test/store-script/currency.composite b/cpp/sca/test/store-script/currency.composite index aefd474f1f..eaea331dbe 100644 --- a/cpp/sca/test/store-script/currency.composite +++ b/cpp/sca/test/store-script/currency.composite @@ -19,14 +19,14 @@ --> - - - - - - - + + + + + + + diff --git a/cpp/sca/test/store-script/fruits-catalog.scm b/cpp/sca/test/store-script/fruits-catalog.scm new file mode 100644 index 0000000000..390068d71a --- /dev/null +++ b/cpp/sca/test/store-script/fruits-catalog.scm @@ -0,0 +1,19 @@ +; Catalog implementation + +(define (get converter) + (display "catalog") + (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 (convert 2.99))) + (list (list 'javaClass "services.Item") (list 'name "Orange") (list 'currencyCode code) (list 'currencySymbol symbol) (list 'price (convert 3.55))) + (list (list 'javaClass "services.Item") (list 'name "Pear") (list 'currencyCode code) (list 'currencySymbol symbol) (list 'price (convert 1.55))) + ) +) + +; TODO remove these JSON-RPC specific functions +(define (system.listMethods converter) (list "Service.get")) +(define Service.get get) diff --git a/cpp/sca/test/store-script/shopping-cart.scm b/cpp/sca/test/store-script/shopping-cart.scm new file mode 100644 index 0000000000..ebb3504e25 --- /dev/null +++ b/cpp/sca/test/store-script/shopping-cart.scm @@ -0,0 +1,26 @@ +; Shopping cart implementation + +(define (post item) + (uuid) +) + +(define (getall) + (cons "Sample Feed" (cons (uuid) '())) +) + +(define (get id) + (define entry (list (list 'name "Apple") (list 'currencyCode "USD") (list 'currencySymbol "$") (list 'price 2.99))) + (cons "Item" (list id entry)) +) + +(define (delete id) + true +) + +(define (gettotal) + 11.0 +) + +; TODO remove these JSON-RPC specific functions +(define (system.listMethods) (list "Service.getTotal")) +(define Service.getTotal gettotal) diff --git a/cpp/sca/test/store-script/store-http-test b/cpp/sca/test/store-script/store-http-test index 4a5a3df685..551731e856 100755 --- a/cpp/sca/test/store-script/store-http-test +++ b/cpp/sca/test/store-script/store-http-test @@ -20,40 +20,55 @@ echo "Testing..." # Setup -../../modules/http/httpd-conf tmp 8092 htdocs +../../modules/http/httpd-conf tmp 8093 htdocs cat >>tmp/conf/httpd.conf < -SetHandler mod_tuscany +SetHandler mod_tuscany_eval SCAContribution `pwd`/ -SCAComponent store -SCAImplementation store.scm +SCAComposite store.composite +SCAComponent Catalog -SetHandler mod_tuscany +SetHandler mod_tuscany_eval SCAContribution `pwd`/ -SCAComponent store -SCAImplementation store.scm +SCAComposite store.composite +SCAComponent ShoppingCart -SetHandler mod_tuscany +SetHandler mod_tuscany_eval SCAContribution `pwd`/ -SCAComponent store -SCAImplementation store.scm +SCAComposite store.composite +SCAComponent ShoppingCart + + + +SetHandler mod_tuscany_eval +SCAContribution `pwd`/ +SCAComposite store.composite +SCAComponent CurrencyConverter + + + +SetHandler mod_tuscany_wiring +SCAContribution `pwd`/ +SCAComposite store.composite EOF + apachectl -k start -d `pwd`/tmp sleep 1 # Test HTTP GET -curl http://localhost:8092/store.html 2>/dev/null >tmp/store.html +curl http://localhost:8093/store.html 2>/dev/null >tmp/store.html diff tmp/store.html htdocs/store.html rc=$? # Cleanup apachectl -k stop -d `pwd`/tmp -sleep 1 +sleep 2 if [ "$rc" = "0" ]; then echo "OK" fi diff --git a/cpp/sca/test/store-script/store-script-test.cpp b/cpp/sca/test/store-script/store-script-test.cpp index 5a29d8caba..add5cb75e5 100644 --- a/cpp/sca/test/store-script/store-script-test.cpp +++ b/cpp/sca/test/store-script/store-script-test.cpp @@ -43,50 +43,42 @@ bool contains(const std::string& str, const std::string& pattern) { } bool testScript() { - std::ifstream is("store.scm", std::ios_base::in); + std::ifstream is("store-script.scm", std::ios_base::in); std::ostringstream os; eval::evalDriverRun(is, os); assert(contains(os.str(), "(\"Sample Feed\" \"")); assert(contains(os.str(), "\" (\"Item\" \"")); - assert(contains(os.str(), "\" ((javaClass \"services.Item\") (name \"Orange\") (currency \"USD\") (symbol \"$\") (price 3.55))) (\"Item\" \"")); - assert(contains(os.str(), "\" ((javaClass \"services.Item\") (name \"Apple\") (currency \"USD\") (symbol \"$\") (price 2.99))))")); + assert(contains(os.str(), "\" ((javaClass \"services.Item\") (name \"Orange\") (currencyCode \"USD\") (currencySymbol \"$\") (price 3.55))) (\"Item\" \"")); + assert(contains(os.str(), "\" ((javaClass \"services.Item\") (name \"Apple\") (currencyCode \"USD\") (currencySymbol \"$\") (price 2.99))))")); return true; } -const value evalLoop(std::istream& is, const value& req, eval::Env& globalEnv, const gc_pool& pool) { - value in = eval::readValue(is); - if(isNil(in)) - return eval::evalExpr(req, globalEnv, pool); - eval::evalExpr(in, globalEnv, pool); - return evalLoop(is, req, globalEnv, pool); -} - bool testEval() { { - std::ifstream is("store.scm", std::ios_base::in); + std::ifstream is("store-script.scm", std::ios_base::in); std::ostringstream os; eval::setupDisplay(os); gc_pool pool; eval::Env globalEnv = eval::setupEnvironment(pool); - const value req(mklist("storeui_service", std::string("getcatalog"))); - const value val = evalLoop(is, req, globalEnv, pool); + const value exp(mklist("storeui_service", std::string("getcatalog"))); + const value val = eval::evalScript(exp, is, globalEnv, pool); std::ostringstream vs; vs << val; - assert(contains(vs.str(), "(((javaClass \"services.Item\") (name \"Apple\") (currency \"USD\") (symbol \"$\") (price 2.99)) ((javaClass \"services.Item\") (name \"Orange\") (currency \"USD\") (symbol \"$\") (price 3.55)) ((javaClass \"services.Item\") (name \"Pear\") (currency \"USD\") (symbol \"$\") (price 1.55)))")); + assert(contains(vs.str(), "(((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)))")); } { - std::ifstream is("store.scm", std::ios_base::in); + std::ifstream is("store-script.scm", std::ios_base::in); std::ostringstream os; eval::setupDisplay(os); gc_pool pool; eval::Env globalEnv = eval::setupEnvironment(pool); - const value req(mklist("storeui_service", std::string("gettotal"))); - const value res = evalLoop(is, req, globalEnv, pool); + const value exp(mklist("storeui_service", std::string("gettotal"))); + const value res = eval::evalScript(exp, is, globalEnv, pool); std::ostringstream rs; rs << res; diff --git a/cpp/sca/test/store-script/store-script.scm b/cpp/sca/test/store-script/store-script.scm new file mode 100644 index 0000000000..30c10d8184 --- /dev/null +++ b/cpp/sca/test/store-script/store-script.scm @@ -0,0 +1,149 @@ +; 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/cpp/sca/test/store-script/store.composite b/cpp/sca/test/store-script/store.composite index 124adff853..cd34f81840 100644 --- a/cpp/sca/test/store-script/store.composite +++ b/cpp/sca/test/store-script/store.composite @@ -21,44 +21,49 @@ xmlns:t="http://tuscany.apache.org/xmlns/sca/1.1" targetNamespace="http://store" name="store"> - + - + + + - + - - - - - - - - - + + + + + + + + + - - - USD - - - - - - - - - - - - - - - + + + USD + + + + + + + + + + + + + + + - - - + + + + + + diff --git a/cpp/sca/test/store-script/store.scm b/cpp/sca/test/store-script/store.scm index 709fd943f1..2434b18b51 100644 --- a/cpp/sca/test/store-script/store.scm +++ b/cpp/sca/test/store-script/store.scm @@ -1,150 +1,31 @@ +; Store implementation -(; "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 'currency code) (list 'symbol symbol) (list 'price 2.99)) - (list (list 'javaClass "services.Item") (list 'name "Orange") (list 'currency code) (list 'symbol symbol) (list 'price 3.55)) - (list (list 'javaClass "services.Item") (list 'name "Pear") (list 'currency code) (list 'symbol 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 'currency "USD") (list 'symbol "$") (list 'price 2.99))) - (cons "Item" (list id entry)) +(define (post item catalog shoppingCart shoppingTotal) + (shoppingCart "post" item) ) -(define (cart_gettotal) - 10.0 +(define (getall catalog shoppingCart shoppingTotal) + (shoppingCart "getall") ) -(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)) - ) +(define (get id catalog shoppingCart shoppingTotal) + (shoppingCart "get" id) ) -(; "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) +(define (getcatalog catalog shoppingCart shoppingTotal) (catalog "get") ) -(define (storeui_gettotal cart) - (cart "gettotal") +(define (gettotal catalog shoppingCart shoppingTotal) + (shoppingCart "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))) - ) +(define (delete id catalog shoppingCart shoppingTotal) + (shoppingCart "delete" id) ) -(; "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 . args) - (display args) - true -) +(define Service.getCatalog getcatalog) +(define Service.getTotal gettotal) -- cgit v1.2.3