diff options
author | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-16 06:01:41 +0000 |
---|---|---|
committer | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-16 06:01:41 +0000 |
commit | 51a97b5d9350b37f95d6f0c00d013b886e64fcd3 (patch) | |
tree | 480092faac7c7deb40265fb070d1b4b059638814 /cpp/sca/test/store-script | |
parent | ada8802640aa232d34b1fe2793b9f52cd62b41f1 (diff) |
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
Diffstat (limited to '')
-rw-r--r-- | cpp/sca/modules/http/httpd-test.composite (renamed from cpp/sca/test/store-script/catalogs.composite) | 41 | ||||
-rw-r--r-- | cpp/sca/test/store-script/currency-converter.scm | 9 | ||||
-rw-r--r-- | cpp/sca/test/store-script/currency.composite | 16 | ||||
-rw-r--r-- | cpp/sca/test/store-script/fruits-catalog.scm | 19 | ||||
-rw-r--r-- | cpp/sca/test/store-script/shopping-cart.scm | 26 | ||||
-rwxr-xr-x | cpp/sca/test/store-script/store-http-test | 39 | ||||
-rw-r--r-- | cpp/sca/test/store-script/store-script-test.cpp | 28 | ||||
-rw-r--r-- | cpp/sca/test/store-script/store-script.scm | 149 | ||||
-rw-r--r-- | cpp/sca/test/store-script/store.composite | 71 | ||||
-rw-r--r-- | cpp/sca/test/store-script/store.scm | 147 |
10 files changed, 320 insertions, 225 deletions
diff --git a/cpp/sca/test/store-script/catalogs.composite b/cpp/sca/modules/http/httpd-test.composite index 1638ed0a05..875d26ae1b 100644 --- a/cpp/sca/test/store-script/catalogs.composite +++ b/cpp/sca/modules/http/httpd-test.composite @@ -19,25 +19,24 @@ --> <composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200903" xmlns:t="http://tuscany.apache.org/xmlns/sca/1.1" - targetNamespace="http://services" - name="catalogs"> - - <component name="FruitsCatalogWebService"> - <implementation.java class="services.FruitsCatalogImpl"/> - <service name="Catalog"> - <binding.ws/> - </service> - <property name="currencyCode">USD</property> - <reference name="currencyConverter" target="CurrencyConverterWebService"> - <binding.ws/> - </reference> - </component> - - <component name="VegetablesCatalogWebService"> - <implementation.java class="services.VegetablesCatalogImpl"/> - <service name="Catalog"> - <binding.ws/> - </service> - </component> - + targetNamespace="http://test" + name="httpd-test"> + + <component name="httpd-test"> + <t:implementation.scheme uri="httpd-test.scm"/> + <service name="test"> + <t:binding.http uri="test"/> + </service> + </component> + + <component name="httpd-client"> + <t:implementation.scheme uri="httpd-client.scm"/> + <service name="client"> + <t:binding.http uri="client"/> + </service> + <reference name="ref" target="test"> + <t:binding.http/> + </reference> + </component> + </composite> 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 @@ --> <composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200903" xmlns:t="http://tuscany.apache.org/xmlns/sca/1.1" - targetNamespace="http://services" + targetNamespace="http://services" name="currency"> - - <component name="CurrencyConverterWebService"> - <implementation.java class="services.CurrencyConverterImpl"/> - <service name="CurrencyConverter"> - <binding.ws/> - </service> - </component> + + <component name="CurrencyConverterWebService"> + <t:implementation.scheme script="currency-converter.scm"/> + <service name="CurrencyConverter"> + <binding.http uri="currency-converter"/> + </service> + </component> </composite> 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 <<EOF + <Location /Catalog> -SetHandler mod_tuscany +SetHandler mod_tuscany_eval SCAContribution `pwd`/ -SCAComponent store -SCAImplementation store.scm +SCAComposite store.composite +SCAComponent Catalog </Location> <Location /Total> -SetHandler mod_tuscany +SetHandler mod_tuscany_eval SCAContribution `pwd`/ -SCAComponent store -SCAImplementation store.scm +SCAComposite store.composite +SCAComponent ShoppingCart </Location> <Location /ShoppingCart> -SetHandler mod_tuscany +SetHandler mod_tuscany_eval SCAContribution `pwd`/ -SCAComponent store -SCAImplementation store.scm +SCAComposite store.composite +SCAComponent ShoppingCart +</Location> + +<Location /CurrencyConverter> +SetHandler mod_tuscany_eval +SCAContribution `pwd`/ +SCAComposite store.composite +SCAComponent CurrencyConverter +</Location> + +<Location /references> +SetHandler mod_tuscany_wiring +SCAContribution `pwd`/ +SCAComposite store.composite </Location> 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<value>("storeui_service", std::string("getcatalog"))); - const value val = evalLoop(is, req, globalEnv, pool); + const value exp(mklist<value>("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<value>("storeui_service", std::string("gettotal"))); - const value res = evalLoop(is, req, globalEnv, pool); + const value exp(mklist<value>("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"> - + <component name="Store"> - <t:implementation.widget location="uiservices/store.html"/> + <!-- <t:implementation.widget location="store.html"/> --> + <t:implementation.scheme uri="store.scm"/> + <service name="Widget"> - <t:binding.http uri="/ui"/> + <t:binding.http uri="store"/> </service> - <reference name="catalog" target="StoreCatalog"> - <t:binding.jsonrpc/> - </reference> - <reference name="shoppingCart" target="StoreShoppingCart/Cart"> - <t:binding.atom/> - </reference> - <reference name="shoppingTotal" target="StoreShoppingCart/Total"> - <t:binding.jsonrpc/> - </reference> + <reference name="catalog" target="Catalog"> + <t:binding.jsonrpc uri="Catalog"/> + </reference> + <reference name="shoppingCart" target="ShoppingCart/Cart"> + <t:binding.atom/> + </reference> + <reference name="shoppingTotal" target="ShoppingCart/Total"> + <t:binding.jsonrpc/> + </reference> </component> - <component name="StoreCatalog"> - <implementation.java class="services.FruitsCatalogImpl"/> - <property name="currencyCode">USD</property> - <service name="Catalog"> - <t:binding.jsonrpc/> - </service> - <reference name="currencyConverter" target="StoreCurrencyConverter"/> - </component> - - <component name="StoreShoppingCart"> - <implementation.java class="services.ShoppingCartImpl"/> - <service name="Cart"> - <t:binding.atom uri="/ShoppingCart/Cart"/> - </service> - <service name="Total"> - <t:binding.jsonrpc/> - </service> - </component> + <component name="Catalog"> + <t:implementation.scheme uri="fruits-catalog.scm"/> + <property name="currencyCode">USD</property> + <service name="Catalog"> + <t:binding.jsonrpc uri="Catalog"/> + </service> + <reference name="currencyConverter" target="CurrencyConverter"/> + </component> + + <component name="ShoppingCart"> + <t:implementation.scheme uri="shopping-cart.scm"/> + <service name="ShoppingCart"> + <t:binding.atom uri="ShoppingCart"/> + </service> + <service name="Total"> + <t:binding.jsonrpc uri="Total"/> + </service> + </component> - <component name="StoreCurrencyConverter"> - <implementation.java class="services.CurrencyConverterImpl"/> - </component> + <component name="CurrencyConverter"> + <t:implementation.scheme uri="currency-converter.scm"/> + <service name="CurrencyConverter"> + <t:binding.jsonrpc uri="CurrencyConverter"/> + </service> + </component> </composite> 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) |