From ff124040623879bc48a0ba5cf06a841642adef53 Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Mon, 30 Nov 2009 08:36:32 +0000 Subject: Fixes to the http client, httpd modules and memcached component to get the store and shopping cart test case working end to end. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@885349 13f79535-47bb-0310-9956-ffa450edef68 --- .../trunk/test/store-script/currency-converter.scm | 1 + sca-cpp/trunk/test/store-script/fruits-catalog.scm | 4 +- sca-cpp/trunk/test/store-script/htdocs/store.html | 14 ++-- sca-cpp/trunk/test/store-script/shopping-cart.scm | 52 ++++++++++--- .../trunk/test/store-script/store-composite-test | 87 ++++++++++++++++++++++ sca-cpp/trunk/test/store-script/store-http-test | 76 ------------------- sca-cpp/trunk/test/store-script/store.composite | 10 +++ sca-cpp/trunk/test/store-script/store.scm | 6 +- 8 files changed, 153 insertions(+), 97 deletions(-) create mode 100755 sca-cpp/trunk/test/store-script/store-composite-test delete mode 100755 sca-cpp/trunk/test/store-script/store-http-test (limited to 'sca-cpp/trunk/test') diff --git a/sca-cpp/trunk/test/store-script/currency-converter.scm b/sca-cpp/trunk/test/store-script/currency-converter.scm index 7f58335951..498ac5da5b 100644 --- a/sca-cpp/trunk/test/store-script/currency-converter.scm +++ b/sca-cpp/trunk/test/store-script/currency-converter.scm @@ -7,3 +7,4 @@ (define (symbol currency) (if (equal? currency "EUR") "E" "$") ) + diff --git a/sca-cpp/trunk/test/store-script/fruits-catalog.scm b/sca-cpp/trunk/test/store-script/fruits-catalog.scm index 390068d71a..18128f0137 100644 --- a/sca-cpp/trunk/test/store-script/fruits-catalog.scm +++ b/sca-cpp/trunk/test/store-script/fruits-catalog.scm @@ -1,12 +1,9 @@ ; 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))) @@ -17,3 +14,4 @@ ; TODO remove these JSON-RPC specific functions (define (system.listMethods converter) (list "Service.get")) (define Service.get get) + diff --git a/sca-cpp/trunk/test/store-script/htdocs/store.html b/sca-cpp/trunk/test/store-script/htdocs/store.html index 4d300f1adb..0378b454cc 100644 --- a/sca-cpp/trunk/test/store-script/htdocs/store.html +++ b/sca-cpp/trunk/test/store-script/htdocs/store.html @@ -94,11 +94,15 @@ var j = 0; for (var i=0; i' + - '' + catalogItems[i].name + '' + '' + catalogItems[i].price + '' + - '' + ''; + var entry = 'Item' + + '' + + '' + catalogItems[i].javaClass + '' + + '' + catalogItems[i].name + '' + + '' + catalogItems[i].currencyCode + '' + + '' + catalogItems[i].currencySymbol + '' + + '' + catalogItems[i].price + '' + + '' + + ''; shoppingCart.post(entry, shoppingCart_postResponse); items[i].checked = false; } diff --git a/sca-cpp/trunk/test/store-script/shopping-cart.scm b/sca-cpp/trunk/test/store-script/shopping-cart.scm index ebb3504e25..01ca62df40 100644 --- a/sca-cpp/trunk/test/store-script/shopping-cart.scm +++ b/sca-cpp/trunk/test/store-script/shopping-cart.scm @@ -1,26 +1,58 @@ ; Shopping cart implementation -(define (post item) - (uuid) +(define cartId "1234") + +; 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) +) + +; Post a new item to the cart, create a new cart if necessary +(define (post item cache) + (define id (uuid)) + (define cart (cons item (getcart cartId cache))) + (cache "put" cartId cart) + id ) -(define (getall) - (cons "Sample Feed" (cons (uuid) '())) +; Return the content of the cart +(define (getall cache) + (define cart (getcart cartId cache)) + (cons "Your Cart" (cons cartId cart)) ) -(define (get id) +; Get an item from the cart +(define (get id cache) (define entry (list (list 'name "Apple") (list 'currencyCode "USD") (list 'currencySymbol "$") (list 'price 2.99))) (cons "Item" (list id entry)) ) -(define (delete id) - true +; Delete the cart +(define (delete id cache) + (cache "delete" cartId) +) + +; Return the price of an item +(define (price item) + (car (cdr (car (cdr (cdr (cdr (cdr (car (cdr (cdr item)))))))))) +) + +; Sum the prices of a list of items +(define (sum items) + (if (nul items) 0 (+ (price (car items)) (sum (cdr items)))) ) -(define (gettotal) - 11.0 +; Return the total price of the items in the cart +(define (gettotal cache) + (define cart (getcart cartId cache)) + (sum cart) ) ; TODO remove these JSON-RPC specific functions -(define (system.listMethods) (list "Service.getTotal")) +(define (system.listMethods cache) (list "Service.getTotal")) (define Service.getTotal gettotal) + diff --git a/sca-cpp/trunk/test/store-script/store-composite-test b/sca-cpp/trunk/test/store-script/store-composite-test new file mode 100755 index 0000000000..43923fca36 --- /dev/null +++ b/sca-cpp/trunk/test/store-script/store-composite-test @@ -0,0 +1,87 @@ +#!/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 < +SetHandler mod_tuscany_eval +SCAContribution `pwd`/ +SCAComposite store.composite +SCAComponent Catalog + + + +SetHandler mod_tuscany_eval +SCAContribution `pwd`/ +SCAComposite store.composite +SCAComponent ShoppingCart + + + +SetHandler mod_tuscany_eval +SCAContribution `pwd`/ +SCAComposite store.composite +SCAComponent ShoppingCart + + + +SetHandler mod_tuscany_eval +SCAContribution `pwd`/ +SCAComposite store.composite +SCAComponent CurrencyConverter + + + +SetHandler mod_tuscany_eval +SCAContribution `pwd`/ +SCAComposite store.composite +SCAComponent Cache + + + +SetHandler mod_tuscany_wiring +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 1 + +# 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 1 +if [ "$rc" = "0" ]; then + echo "OK" +fi +return $rc diff --git a/sca-cpp/trunk/test/store-script/store-http-test b/sca-cpp/trunk/test/store-script/store-http-test deleted file mode 100755 index d04eab8a6c..0000000000 --- a/sca-cpp/trunk/test/store-script/store-http-test +++ /dev/null @@ -1,76 +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 < -SetHandler mod_tuscany_eval -SCAContribution `pwd`/ -SCAComposite store.composite -SCAComponent Catalog - - - -SetHandler mod_tuscany_eval -SCAContribution `pwd`/ -SCAComposite store.composite -SCAComponent ShoppingCart - - - -SetHandler mod_tuscany_eval -SCAContribution `pwd`/ -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:8090/store.html 2>/dev/null >tmp/store.html -diff tmp/store.html htdocs/store.html -rc=$? - -# Cleanup -apachectl -k stop -d `pwd`/tmp -sleep 2 -if [ "$rc" = "0" ]; then - echo "OK" -fi -return $rc diff --git a/sca-cpp/trunk/test/store-script/store.composite b/sca-cpp/trunk/test/store-script/store.composite index cd34f81840..2cfadf3f71 100644 --- a/sca-cpp/trunk/test/store-script/store.composite +++ b/sca-cpp/trunk/test/store-script/store.composite @@ -57,6 +57,9 @@ + + + @@ -66,4 +69,11 @@ + + + + + + + diff --git a/sca-cpp/trunk/test/store-script/store.scm b/sca-cpp/trunk/test/store-script/store.scm index 2434b18b51..01f72d0bea 100644 --- a/sca-cpp/trunk/test/store-script/store.scm +++ b/sca-cpp/trunk/test/store-script/store.scm @@ -24,8 +24,8 @@ (shoppingCart "delete" id) ) -(define (system.listMethods) (list "Service.get" "Service.getTotal")) - +; 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) + -- cgit v1.2.3