From dc15dc32bb3348c760ba3643c083af7e0c8e43fe Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Sat, 25 Dec 2010 01:49:19 +0000 Subject: Create a sandbox branch to experiment with latest APR. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1052740 13f79535-47bb-0310-9956-ffa450edef68 --- .../cpp/apr-2/samples/store-scheme/Makefile.am | 30 +++++ .../samples/store-scheme/currency-converter.scm | 27 ++++ .../apr-2/samples/store-scheme/fruits-catalog.scm | 30 +++++ .../apr-2/samples/store-scheme/htdocs/index.html | 150 +++++++++++++++++++++ .../cpp/apr-2/samples/store-scheme/script-test.cpp | 96 +++++++++++++ .../cpp/apr-2/samples/store-scheme/script-test.scm | 140 +++++++++++++++++++ .../cpp/apr-2/samples/store-scheme/server-test | 58 ++++++++ .../apr-2/samples/store-scheme/shopping-cart.scm | 82 +++++++++++ .../cpp/apr-2/samples/store-scheme/ssl-start | 36 +++++ .../sebastien/cpp/apr-2/samples/store-scheme/start | 31 +++++ .../sebastien/cpp/apr-2/samples/store-scheme/stop | 21 +++ .../cpp/apr-2/samples/store-scheme/store.composite | 70 ++++++++++ .../cpp/apr-2/samples/store-scheme/store.scm | 47 +++++++ 13 files changed, 818 insertions(+) create mode 100644 sandbox/sebastien/cpp/apr-2/samples/store-scheme/Makefile.am create mode 100644 sandbox/sebastien/cpp/apr-2/samples/store-scheme/currency-converter.scm create mode 100644 sandbox/sebastien/cpp/apr-2/samples/store-scheme/fruits-catalog.scm create mode 100644 sandbox/sebastien/cpp/apr-2/samples/store-scheme/htdocs/index.html create mode 100644 sandbox/sebastien/cpp/apr-2/samples/store-scheme/script-test.cpp create mode 100644 sandbox/sebastien/cpp/apr-2/samples/store-scheme/script-test.scm create mode 100755 sandbox/sebastien/cpp/apr-2/samples/store-scheme/server-test create mode 100644 sandbox/sebastien/cpp/apr-2/samples/store-scheme/shopping-cart.scm create mode 100755 sandbox/sebastien/cpp/apr-2/samples/store-scheme/ssl-start create mode 100755 sandbox/sebastien/cpp/apr-2/samples/store-scheme/start create mode 100755 sandbox/sebastien/cpp/apr-2/samples/store-scheme/stop create mode 100644 sandbox/sebastien/cpp/apr-2/samples/store-scheme/store.composite create mode 100644 sandbox/sebastien/cpp/apr-2/samples/store-scheme/store.scm (limited to 'sandbox/sebastien/cpp/apr-2/samples/store-scheme') diff --git a/sandbox/sebastien/cpp/apr-2/samples/store-scheme/Makefile.am b/sandbox/sebastien/cpp/apr-2/samples/store-scheme/Makefile.am new file mode 100644 index 0000000000..2330d45422 --- /dev/null +++ b/sandbox/sebastien/cpp/apr-2/samples/store-scheme/Makefile.am @@ -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. + +dist_sample_SCRIPTS = start stop ssl-start +sampledir = $(prefix)/samples/store-scheme + +nobase_dist_sample_DATA = currency-converter.scm fruits-catalog.scm shopping-cart.scm store.scm store.composite htdocs/*.html + +EXTRA_DIST = script-test.scm + +dist_noinst_SCRIPTS = server-test +noinst_PROGRAMS = script-test +script_test_SOURCES = script-test.cpp +script_test_LDFLAGS = -lxml2 -lmozjs + +TESTS = script-test server-test diff --git a/sandbox/sebastien/cpp/apr-2/samples/store-scheme/currency-converter.scm b/sandbox/sebastien/cpp/apr-2/samples/store-scheme/currency-converter.scm new file mode 100644 index 0000000000..fc506c3d73 --- /dev/null +++ b/sandbox/sebastien/cpp/apr-2/samples/store-scheme/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/sandbox/sebastien/cpp/apr-2/samples/store-scheme/fruits-catalog.scm b/sandbox/sebastien/cpp/apr-2/samples/store-scheme/fruits-catalog.scm new file mode 100644 index 0000000000..d55394b96a --- /dev/null +++ b/sandbox/sebastien/cpp/apr-2/samples/store-scheme/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/sandbox/sebastien/cpp/apr-2/samples/store-scheme/htdocs/index.html b/sandbox/sebastien/cpp/apr-2/samples/store-scheme/htdocs/index.html new file mode 100644 index 0000000000..3945e45bb7 --- /dev/null +++ b/sandbox/sebastien/cpp/apr-2/samples/store-scheme/htdocs/index.html @@ -0,0 +1,150 @@ + + + +Store + + + + + + + + +

Store

+
+

Catalog

+
+
+
+ +
+
+ +

Your Shopping Cart

+
+
+
+
+
+ + +(feed) +
+
+ + + diff --git a/sandbox/sebastien/cpp/apr-2/samples/store-scheme/script-test.cpp b/sandbox/sebastien/cpp/apr-2/samples/store-scheme/script-test.cpp new file mode 100644 index 0000000000..0d5a9ccf9d --- /dev/null +++ b/sandbox/sebastien/cpp/apr-2/samples/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), "\" ((name \"Orange\") (currencyCode \"USD\") (currencySymbol \"$\") (price 3.55))) (\"Item\" \"")); + assert(contains(str(os), "\" ((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("items"))); + const value val = scheme::evalScript(exp, is, globalEnv); + + ostringstream vs; + vs << val; + assert(contains(str(vs), "(((name \"Apple\") (currencyCode \"USD\") (currencySymbol \"$\") (price 2.99)) ((name \"Orange\") (currencyCode \"USD\") (currencySymbol \"$\") (price 3.55)) ((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("total"))); + 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/sandbox/sebastien/cpp/apr-2/samples/store-scheme/script-test.scm b/sandbox/sebastien/cpp/apr-2/samples/store-scheme/script-test.scm new file mode 100644 index 0000000000..50b587b8f1 --- /dev/null +++ b/sandbox/sebastien/cpp/apr-2/samples/store-scheme/script-test.scm @@ -0,0 +1,140 @@ +; 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 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 'name "Apple") (list 'currencyCode code) (list 'currencySymbol symbol) (list 'price 2.99)) + (list (list 'name "Orange") (list 'currencyCode code) (list 'currencySymbol symbol) (list 'price 3.55)) + (list (list 'name "Pear") (list 'currencyCode code) (list 'currencySymbol symbol) (list 'price 1.55)) + ) +) + +(define (catalog_impl converter op args) + (cond + ((equal? op "items") (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_total) + 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 "total") (apply cart_total 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_items catalog) + (catalog "items") +) + +(define (storeui_total cart) + (cart "total") +) + +(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 "items") (apply storeui_items (cons catalog args))) + ((equal? op "total") (apply storeui_total (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 "items")) +(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 "total")) + diff --git a/sandbox/sebastien/cpp/apr-2/samples/store-scheme/server-test b/sandbox/sebastien/cpp/apr-2/samples/store-scheme/server-test new file mode 100755 index 0000000000..1612bc59e2 --- /dev/null +++ b/sandbox/sebastien/cpp/apr-2/samples/store-scheme/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=`readlink -f $0`; 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 +return $rc diff --git a/sandbox/sebastien/cpp/apr-2/samples/store-scheme/shopping-cart.scm b/sandbox/sebastien/cpp/apr-2/samples/store-scheme/shopping-cart.scm new file mode 100644 index 0000000000..61b169426f --- /dev/null +++ b/sandbox/sebastien/cpp/apr-2/samples/store-scheme/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 (car item) id (caddr 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) + (cons "Item" (list "0" (list))) + (if (= id (cadr (car cart))) + (car cart) + (find id (cdr cart)))) +) + +; Get items from the cart +(define (get id cache) + (if (nul id) + (cons "Your Cart" (cons 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 (caddr 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/sandbox/sebastien/cpp/apr-2/samples/store-scheme/ssl-start b/sandbox/sebastien/cpp/apr-2/samples/store-scheme/ssl-start new file mode 100755 index 0000000000..70e62f1f04 --- /dev/null +++ b/sandbox/sebastien/cpp/apr-2/samples/store-scheme/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 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + localhost:11211 + + + diff --git a/sandbox/sebastien/cpp/apr-2/samples/store-scheme/store.scm b/sandbox/sebastien/cpp/apr-2/samples/store-scheme/store.scm new file mode 100644 index 0000000000..f54257343e --- /dev/null +++ b/sandbox/sebastien/cpp/apr-2/samples/store-scheme/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