summaryrefslogtreecommitdiffstats
path: root/sca-cpp/trunk/test/store-python
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--sca-cpp/trunk/test/store-python/Makefile.am19
-rw-r--r--sca-cpp/trunk/test/store-python/currency-converter.py14
-rw-r--r--sca-cpp/trunk/test/store-python/currency.composite32
-rw-r--r--sca-cpp/trunk/test/store-python/fruits-catalog.py19
-rw-r--r--sca-cpp/trunk/test/store-python/htdocs/.htaccess (renamed from sca-cpp/trunk/test/store-script/htdocs/.htaccess)0
-rw-r--r--sca-cpp/trunk/test/store-python/htdocs/store.html (renamed from sca-cpp/trunk/test/store-script/htdocs/store.html)0
-rw-r--r--sca-cpp/trunk/test/store-python/htdocs/store.js (renamed from sca-cpp/trunk/test/store-script/htdocs/store.js)0
-rw-r--r--sca-cpp/trunk/test/store-python/shopping-cart.py77
-rwxr-xr-xsca-cpp/trunk/test/store-python/store-composite-test (renamed from sca-cpp/trunk/test/store-script/store-composite-test)0
-rw-r--r--sca-cpp/trunk/test/store-python/store.composite70
-rw-r--r--sca-cpp/trunk/test/store-python/store.py30
11 files changed, 261 insertions, 0 deletions
diff --git a/sca-cpp/trunk/test/store-python/Makefile.am b/sca-cpp/trunk/test/store-python/Makefile.am
new file mode 100644
index 0000000000..daefd9a405
--- /dev/null
+++ b/sca-cpp/trunk/test/store-python/Makefile.am
@@ -0,0 +1,19 @@
+# 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.
+
+TESTS = store-composite-test
+
diff --git a/sca-cpp/trunk/test/store-python/currency-converter.py b/sca-cpp/trunk/test/store-python/currency-converter.py
new file mode 100644
index 0000000000..1ee39b63f3
--- /dev/null
+++ b/sca-cpp/trunk/test/store-python/currency-converter.py
@@ -0,0 +1,14 @@
+# Currency converter implementation
+
+def convert(fr, to, amount):
+ if (to == "EUR")
+ return amount * 0.70
+ else
+ return amount
+
+def symbol(currency):
+ if (currency == "EUR")
+ return "E"
+ else
+ return "$"
+
diff --git a/sca-cpp/trunk/test/store-python/currency.composite b/sca-cpp/trunk/test/store-python/currency.composite
new file mode 100644
index 0000000000..17066e9626
--- /dev/null
+++ b/sca-cpp/trunk/test/store-python/currency.composite
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.
+-->
+<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="currency">
+
+ <component name="CurrencyConverterWebService">
+ <t:implementation.python script="currency-converter.py"/>
+ <service name="CurrencyConverter">
+ <binding.http uri="currency-converter"/>
+ </service>
+ </component>
+
+</composite>
diff --git a/sca-cpp/trunk/test/store-python/fruits-catalog.py b/sca-cpp/trunk/test/store-python/fruits-catalog.py
new file mode 100644
index 0000000000..5fcb9216c2
--- /dev/null
+++ b/sca-cpp/trunk/test/store-python/fruits-catalog.py
@@ -0,0 +1,19 @@
+# Catalog implementation
+
+def get(converter):
+ def convert(price):
+ return converter("convert", "USD", "USD", price)
+ code = "USD")
+ symbol = converter("symbol", code)
+ return (
+ (("'javaClass", "services.Item"), ("'name", "Apple"), ("'currencyCode", code), ("'currencySymbol", symbol), ("'price", convert(2.99))),
+ (("'javaClass", "services.Item"), ("'name", "Orange"), ("'currencyCode", code), ("'currencySymbol", symbol), ("'price", convert(3.55))),
+ (("'javaClass", "services.Item"), ("'name", "Pear"), ("'currencyCode", code), ("'currencySymbol", symbol), ("'price" convert(1.55)))
+ )
+
+# TODO remove these JSON-RPC specific functions
+def system.listMethods(converter):
+ return ("Service.get")
+
+Service.get = get
+
diff --git a/sca-cpp/trunk/test/store-script/htdocs/.htaccess b/sca-cpp/trunk/test/store-python/htdocs/.htaccess
index e2e343b6b2..e2e343b6b2 100644
--- a/sca-cpp/trunk/test/store-script/htdocs/.htaccess
+++ b/sca-cpp/trunk/test/store-python/htdocs/.htaccess
diff --git a/sca-cpp/trunk/test/store-script/htdocs/store.html b/sca-cpp/trunk/test/store-python/htdocs/store.html
index f8c6027abe..f8c6027abe 100644
--- a/sca-cpp/trunk/test/store-script/htdocs/store.html
+++ b/sca-cpp/trunk/test/store-python/htdocs/store.html
diff --git a/sca-cpp/trunk/test/store-script/htdocs/store.js b/sca-cpp/trunk/test/store-python/htdocs/store.js
index 9cd8eb526d..9cd8eb526d 100644
--- a/sca-cpp/trunk/test/store-script/htdocs/store.js
+++ b/sca-cpp/trunk/test/store-python/htdocs/store.js
diff --git a/sca-cpp/trunk/test/store-python/shopping-cart.py b/sca-cpp/trunk/test/store-python/shopping-cart.py
new file mode 100644
index 0000000000..cc89bb6c99
--- /dev/null
+++ b/sca-cpp/trunk/test/store-python/shopping-cart.py
@@ -0,0 +1,77 @@
+# Shopping cart implementation
+
+cartId = "1234"
+
+#TODO finish conversion from scheme to python
+
+# 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 newItem (list (car item) id (caddr item)))
+ (define cart (cons newItem (getcart cartId cache)))
+ (cache "put" cartId cart)
+ id
+)
+
+# Return the content of the cart
+(define (getall cache)
+ (cons "Your Cart" (cons cartId (getcart cartId cache)))
+)
+
+# 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 an item from the cart
+(define (get id cache)
+ (find id (getcart cartId cache))
+)
+
+# Delete the whole cart
+(define (deleteall cache)
+ (cache "delete" cartId)
+)
+
+# Delete an item from the cart
+(define (delete id cache)
+ 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 (gettotal cache)
+ (define cart (getcart cartId cache))
+ (sum cart)
+)
+
+# TODO remove these JSON-RPC specific functions
+def system.listMethods(cache):
+ return ("Service.getTotal")
+
+Service.getTotal = gettotal
+
diff --git a/sca-cpp/trunk/test/store-script/store-composite-test b/sca-cpp/trunk/test/store-python/store-composite-test
index b41c4e5393..b41c4e5393 100755
--- a/sca-cpp/trunk/test/store-script/store-composite-test
+++ b/sca-cpp/trunk/test/store-python/store-composite-test
diff --git a/sca-cpp/trunk/test/store-python/store.composite b/sca-cpp/trunk/test/store-python/store.composite
new file mode 100644
index 0000000000..8ea2dec373
--- /dev/null
+++ b/sca-cpp/trunk/test/store-python/store.composite
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.
+-->
+<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200903"
+ xmlns:t="http://tuscany.apache.org/xmlns/sca/1.1"
+ targetNamespace="http://store"
+ name="store">
+
+ <component name="Store">
+ <!-- <t:implementation.widget location="store.html"/> -->
+ <t:implementation.python uri="store.py"/>
+ <service name="Widget">
+ <t:binding.http uri="store"/>
+ </service>
+ <reference name="catalog" target="Catalog"/>
+ <reference name="shoppingCart" target="ShoppingCart/Cart"/>
+ <reference name="shoppingTotal" target="ShoppingCart/Total"/>
+ </component>
+
+ <component name="Catalog">
+ <t:implementation.python uri="fruits-catalog.py"/>
+ <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.python uri="shopping-cart.py"/>
+ <service name="ShoppingCart">
+ <t:binding.atom uri="shoppingCart"/>
+ </service>
+ <service name="Total">
+ <t:binding.jsonrpc uri="total"/>
+ </service>
+ <reference name="cache" target="Cache"/>
+ </component>
+
+ <component name="CurrencyConverter">
+ <t:implementation.python uri="currency-converter.py"/>
+ <service name="CurrencyConverter">
+ <t:binding.jsonrpc uri="currencyConverter"/>
+ </service>
+ </component>
+
+ <component name="Cache">
+ <t:implementation.cpp uri="../../components/cache/.libs/libmcache"/>
+ <service name="Cache">
+ <t:binding.atom uri="cache"/>
+ </service>
+ </component>
+
+</composite>
diff --git a/sca-cpp/trunk/test/store-python/store.py b/sca-cpp/trunk/test/store-python/store.py
new file mode 100644
index 0000000000..942544a3b2
--- /dev/null
+++ b/sca-cpp/trunk/test/store-python/store.py
@@ -0,0 +1,30 @@
+# Store implementation
+
+def post(item, catalog, shoppingCart, shoppingTotal):
+ return shoppingCart("post", item)
+
+def getall(catalog, shoppingCart, shoppingTotal):
+ return shoppingCart("getall")
+
+def get(id, catalog, shoppingCart, shoppingTotal):
+ return shoppingCart("get", id)
+
+def getcatalog(catalog, shoppingCart, shoppingTotal):
+ return catalog("get")
+
+def gettotal(catalog, shoppingCart, shoppingTotal):
+ return shoppingCart("gettotal")
+
+def deleteall(catalog, shoppingCart, shoppingTotal):
+ return shoppingCart("deleteall")
+
+def delete(id, catalog, shoppingCart, shoppingTotal):
+ return shoppingCart("delete", id)
+
+# TODO remove these JSON-RPC specific functions
+def system.listMethods(catalog, shoppingCart, shoppingTotal):
+ return ("Service.get", "Service.getTotal")
+
+Service.getCatalog = getcatalog
+Service.getTotal = gettotal
+