From c9bfccc35345ce58fb5774d4b0b6a9868b262c0a Mon Sep 17 00:00:00 2001 From: giorgio Date: Wed, 5 Sep 2012 08:31:30 +0000 Subject: git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1381061 13f79535-47bb-0310-9956-ffa450edef68 --- .../samples/store-constdb/Makefile.am | 25 ++++ .../samples/store-constdb/currency-converter.scm | 27 ++++ .../samples/store-constdb/fruits-catalog.scm | 30 ++++ .../samples/store-constdb/htdocs/index.html | 156 +++++++++++++++++++++ .../samples/store-constdb/server-test | 58 ++++++++ .../samples/store-constdb/shopping-cart.scm | 82 +++++++++++ .../samples/store-constdb/ssl-start | 36 +++++ .../lightweight-sca/samples/store-constdb/start | 33 +++++ .../lightweight-sca/samples/store-constdb/stop | 20 +++ .../samples/store-constdb/store.composite | 69 +++++++++ .../samples/store-constdb/store.scm | 47 +++++++ 11 files changed, 583 insertions(+) create mode 100644 sca-cpp/branches/lightweight-sca/samples/store-constdb/Makefile.am create mode 100644 sca-cpp/branches/lightweight-sca/samples/store-constdb/currency-converter.scm create mode 100644 sca-cpp/branches/lightweight-sca/samples/store-constdb/fruits-catalog.scm create mode 100644 sca-cpp/branches/lightweight-sca/samples/store-constdb/htdocs/index.html create mode 100755 sca-cpp/branches/lightweight-sca/samples/store-constdb/server-test create mode 100644 sca-cpp/branches/lightweight-sca/samples/store-constdb/shopping-cart.scm create mode 100755 sca-cpp/branches/lightweight-sca/samples/store-constdb/ssl-start create mode 100755 sca-cpp/branches/lightweight-sca/samples/store-constdb/start create mode 100755 sca-cpp/branches/lightweight-sca/samples/store-constdb/stop create mode 100644 sca-cpp/branches/lightweight-sca/samples/store-constdb/store.composite create mode 100644 sca-cpp/branches/lightweight-sca/samples/store-constdb/store.scm (limited to 'sca-cpp/branches/lightweight-sca/samples/store-constdb') diff --git a/sca-cpp/branches/lightweight-sca/samples/store-constdb/Makefile.am b/sca-cpp/branches/lightweight-sca/samples/store-constdb/Makefile.am new file mode 100644 index 0000000000..d2783f3f3b --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-constdb/Makefile.am @@ -0,0 +1,25 @@ +# 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. + +dist_sample_SCRIPTS = start stop ssl-start +sampledir = $(prefix)/samples/store-constdb + +nobase_dist_sample_DATA = currency-converter.scm fruits-catalog.scm shopping-cart.scm store.scm store.composite htdocs/*.html + +dist_noinst_SCRIPTS = server-test +TESTS = server-test + diff --git a/sca-cpp/branches/lightweight-sca/samples/store-constdb/currency-converter.scm b/sca-cpp/branches/lightweight-sca/samples/store-constdb/currency-converter.scm new file mode 100644 index 0000000000..fc506c3d73 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-constdb/currency-converter.scm @@ -0,0 +1,27 @@ +; 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. + +; 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/sca-cpp/branches/lightweight-sca/samples/store-constdb/fruits-catalog.scm b/sca-cpp/branches/lightweight-sca/samples/store-constdb/fruits-catalog.scm new file mode 100644 index 0000000000..d55394b96a --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-constdb/fruits-catalog.scm @@ -0,0 +1,30 @@ +; 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. + +; Catalog implementation + +(define (items converter currencyCode) + (define code (currencyCode)) + (define (convert price) (converter "convert" "USD" code price)) + (define symbol (converter "symbol" code)) + (list + (list (list 'name "Apple") (list 'currencyCode code) (list 'currencySymbol symbol) (list 'price (convert 2.99))) + (list (list 'name "Orange") (list 'currencyCode code) (list 'currencySymbol symbol) (list 'price (convert 3.55))) + (list (list 'name "Pear") (list 'currencyCode code) (list 'currencySymbol symbol) (list 'price (convert 1.55))) + ) +) + diff --git a/sca-cpp/branches/lightweight-sca/samples/store-constdb/htdocs/index.html b/sca-cpp/branches/lightweight-sca/samples/store-constdb/htdocs/index.html new file mode 100644 index 0000000000..0698a32cc5 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-constdb/htdocs/index.html @@ -0,0 +1,156 @@ + + + + + + + +Store + + + + + + + +

Store

+
+
+

Catalog

+
+
+
+ +
+
+ +

Your Shopping Cart

+
+
+
+
+
+ + +(feed) +
+
+ + + diff --git a/sca-cpp/branches/lightweight-sca/samples/store-constdb/server-test b/sca-cpp/branches/lightweight-sca/samples/store-constdb/server-test new file mode 100755 index 0000000000..fb629a6814 --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-constdb/server-test @@ -0,0 +1,58 @@ +#!/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..." +here=`echo "import os; print os.path.realpath('$0')" | python`; here=`dirname $here` +curl_prefix=`cat $here/../../modules/http/curl.prefix` + +# Setup +./start +sleep 2 + +# Test HTTP GET +$curl_prefix/bin/curl http://localhost:8090/ 2>/dev/null >tmp/index.html +diff tmp/index.html htdocs/index.html +rc=$? + +# Test Catalog +if [ "$rc" = "0" ]; then + $curl_prefix/bin/curl http://localhost:8090/references/Store/catalog -X POST -H "Content-type: application/json-rpc" --data @../store-cpp/htdocs/test/items-request.txt >tmp/items-result.txt 2>/dev/null + diff tmp/items-result.txt ../store-cpp/htdocs/test/items-result.txt + rc=$? +fi + +# Test Shopping Cart +if [ "$rc" = "0" ]; then + $curl_prefix/bin/curl http://localhost:8090/references/Store/shoppingCart -X POST -H "Content-type: application/atom+xml" --data @../store-cpp/htdocs/test/shopping-cart-entry.xml 2>/dev/null + rc=$? +fi +if [ "$rc" = "0" ]; then + $curl_prefix/bin/curl http://localhost:8090/references/Store/shoppingCart >tmp/shopping-cart-feed.xml 2>/dev/null + grep "3.55" tmp/shopping-cart-feed.xml >/dev/null + rc=$? +fi + +# Cleanup +./stop +sleep 2 + +if [ "$rc" = "0" ]; then + echo "OK" +fi +exit $rc diff --git a/sca-cpp/branches/lightweight-sca/samples/store-constdb/shopping-cart.scm b/sca-cpp/branches/lightweight-sca/samples/store-constdb/shopping-cart.scm new file mode 100644 index 0000000000..e653f1e33c --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-constdb/shopping-cart.scm @@ -0,0 +1,82 @@ +; 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. + +; Shopping cart implementation + +(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" (list id))) + (if (nul cart) + (list) + cart) +) + +; Post a new item to the cart, create a new cart if necessary +(define (post collection item cache) + (define id (uuid)) + (define newItem (list 'entry (cadr (car item)) (list 'id id) (cadddr (car item)))) + (define cart (cons newItem (getcart cartId cache))) + (cache "put" (list cartId) cart) + (list id) +) + +; Find an item in the cart +(define (find id cart) + (if (nul cart) + (list (list 'entry (list 'title "Item") (list 'id "0"))) + (if (= id (cadr (caddr (car cart)))) + (list (car cart)) + (find id (cdr cart)))) +) + +; Get items from the cart +(define (get id cache) + (if (nul id) + (list (append (list 'feed (list 'title "Your Cart") (list 'id cartId)) (getcart cartId cache))) + (find (car id) (getcart cartId cache)) + ) +) + +; Delete items from the cart +(define (delete id cache) + (if (nul id) + (cache "delete" (list cartId)) + true + ) +) + +; Return the price of an item +(define (price item) + (cadr (assoc 'price (cadr (cadddr item)))) +) + +; Sum the prices of a list of items +(define (sum items) + (if (nul items) + 0 + (+ (price (car items)) (sum (cdr items)))) +) + +; Return the total price of the items in the cart +(define (total cache) + (define cart (getcart cartId cache)) + (sum cart) +) + diff --git a/sca-cpp/branches/lightweight-sca/samples/store-constdb/ssl-start b/sca-cpp/branches/lightweight-sca/samples/store-constdb/ssl-start new file mode 100755 index 0000000000..047ec974cb --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-constdb/ssl-start @@ -0,0 +1,36 @@ +#!/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. + +../../modules/http/ssl-ca-conf tmp localhost +../../modules/http/ssl-cert-conf tmp localhost +../../modules/http/httpd-conf tmp localhost 8090 htdocs +../../modules/http/httpd-ssl-conf tmp 8453 +../../modules/http/basic-auth-conf tmp +../../modules/http/passwd-auth-conf tmp foo foo +../../modules/server/server-conf tmp +../../modules/server/scheme-conf tmp +cat >>tmp/conf/httpd.conf <>tmp/conf/httpd.conf < + + + + + + + + + + + + + + + + USD + + + + + + + + + + + + + + + + + + + + + + + + + + + tmp/store.cdb + + + + + + diff --git a/sca-cpp/branches/lightweight-sca/samples/store-constdb/store.scm b/sca-cpp/branches/lightweight-sca/samples/store-constdb/store.scm new file mode 100644 index 0000000000..f54257343e --- /dev/null +++ b/sca-cpp/branches/lightweight-sca/samples/store-constdb/store.scm @@ -0,0 +1,47 @@ +; 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. + +; Store implementation + +(define (post item catalog shoppingCart shoppingTotal) + (shoppingCart "post" item) +) + +(define (getall catalog shoppingCart shoppingTotal) + (shoppingCart "getall") +) + +(define (get id catalog shoppingCart shoppingTotal) + (shoppingCart "get" id) +) + +(define (items catalog shoppingCart shoppingTotal) + (catalog "items") +) + +(define (total catalog shoppingCart shoppingTotal) + (shoppingCart "total") +) + +(define (deleteall catalog shoppingCart shoppingTotal) + (shoppingCart "deleteall") +) + +(define (delete id catalog shoppingCart shoppingTotal) + (shoppingCart "delete" id) +) + -- cgit v1.2.3