summaryrefslogtreecommitdiffstats
path: root/cpp/sca/test/store-script
diff options
context:
space:
mode:
authorjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2009-10-26 05:13:21 +0000
committerjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2009-10-26 05:13:21 +0000
commit965e129717da78c4ac56531200631836b74758f4 (patch)
treeede32dd54b9ff3aedd4f56dc7b1057b3715f82d5 /cpp/sca/test/store-script
parentf61164c77c5c21a32b58ad61c868bd8ff6a4a79e (diff)
Added test cases to make check build target. Changed store-script to interop with java store sample. Added reference support to http module.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@829700 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r--cpp/sca/test/store-script/Makefile.am6
-rw-r--r--cpp/sca/test/store-script/htdocs/store.html6
-rw-r--r--cpp/sca/test/store-script/htdocs/store.js2
-rw-r--r--cpp/sca/test/store-script/store-script-test.cpp45
-rw-r--r--cpp/sca/test/store-script/store.scm35
5 files changed, 61 insertions, 33 deletions
diff --git a/cpp/sca/test/store-script/Makefile.am b/cpp/sca/test/store-script/Makefile.am
index aded08f6b3..2bd969b5ba 100644
--- a/cpp/sca/test/store-script/Makefile.am
+++ b/cpp/sca/test/store-script/Makefile.am
@@ -18,11 +18,13 @@
store_script_PROGRAMS = store-script-test
store_scriptdir=$(prefix)/test/store-script/deploy
-INCLUDES = -I. -I$(top_builddir)/kernel -I$(top_builddir)/modules/eval -I${LIBXML2_INCLUDE}
+INCLUDES = -I. -I$(top_builddir)/kernel -I$(top_builddir)/modules/eval -I${LIBXML2_INCLUDE} -I${LIBMOZJS_INCLUDE}
store_script_test_SOURCES = store-script-test.cpp
-store_script_test_LDADD = -L${LIBXML2_LIB} -lxml2 -lpthread
+store_script_test_LDADD = -L${LIBXML2_LIB} -lxml2 -lpthread -L${LIBMOZJS_LIB} -lmozjs
EXTRA_DIST = *.composite
store_script_DATA = *.composite
+TESTS = store-script-test
+
diff --git a/cpp/sca/test/store-script/htdocs/store.html b/cpp/sca/test/store-script/htdocs/store.html
index 4a2c65d07c..98d6ec8e8e 100644
--- a/cpp/sca/test/store-script/htdocs/store.html
+++ b/cpp/sca/test/store-script/htdocs/store.html
@@ -28,7 +28,7 @@
var catalog = new tuscany.sca.Reference("catalog");
//@Reference
- //var shoppingCart = new tuscany.sca.Reference("shoppingCart");
+ var shoppingCart = new tuscany.sca.Reference("shoppingCart");
//@Reference
var shoppingTotal = new tuscany.sca.Reference("shoppingTotal");
@@ -86,7 +86,7 @@
}
function shoppingCart_postResponse(entry) {
- //shoppingCart.get("", shoppingCart_getResponse);
+ shoppingCart.get("", shoppingCart_getResponse);
}
function addToCart() {
@@ -127,7 +127,7 @@
try {
catalog.get(catalog_getResponse);
- //shoppingCart.get("", shoppingCart_getResponse);
+ shoppingCart.get("", shoppingCart_getResponse);
}
catch(e){
alert(e);
diff --git a/cpp/sca/test/store-script/htdocs/store.js b/cpp/sca/test/store-script/htdocs/store.js
index 526d36790a..64749ce6c1 100644
--- a/cpp/sca/test/store-script/htdocs/store.js
+++ b/cpp/sca/test/store-script/htdocs/store.js
@@ -651,7 +651,7 @@ tuscany.sca.Property = function (name) {
tuscany.sca.referenceMap = new Object();
tuscany.sca.referenceMap.catalog = new JSONRpcClient("/Catalog").Service;
-//tuscany.sca.referenceMap.shoppingCart = new AtomClient("/ShoppingCart/Cart");
+tuscany.sca.referenceMap.shoppingCart = new AtomClient("/ShoppingCart/Cart");
tuscany.sca.referenceMap.shoppingTotal = new JSONRpcClient("/ShoppingCart/Total").Service;
tuscany.sca.Reference = function (name) {
return tuscany.sca.referenceMap[name];
diff --git a/cpp/sca/test/store-script/store-script-test.cpp b/cpp/sca/test/store-script/store-script-test.cpp
index 8eac2f7b8b..2d1891dd14 100644
--- a/cpp/sca/test/store-script/store-script-test.cpp
+++ b/cpp/sca/test/store-script/store-script-test.cpp
@@ -27,10 +27,16 @@
#include <iostream>
#include <fstream>
#include <string>
+#include "list.hpp"
#include "driver.hpp"
+#include "slist.hpp"
+#include "xml.hpp"
+#include "../json/json.hpp"
namespace store {
+using namespace tuscany;
+
bool contains(const std::string& str, const std::string& pattern) {
return str.find(pattern) != str.npos;
}
@@ -38,16 +44,16 @@ bool contains(const std::string& str, const std::string& pattern) {
bool testScript() {
std::ifstream is("store.scm", std::ios_base::in);
std::ostringstream os;
- tuscany::evalDriverRun(is, os);
- assert(contains(os.str(), "List::(List::(List::(Symbol::name, (String::\"apple\", ())), (List::(Symbol::currency, (String::\"USD\", ())), (List::(Symbol::symbol, (String::\"$\", ())), (List::(Symbol::price, (Number::2.99, ())), ())))), ())"));
+ eval::evalDriverRun(is, os);
+ assert(contains(os.str(), "(string::\"Sample Feed\", string::\"123\", (string::\"Item\", string::\"123456789\", ((symbol::javaClass, string::\"services.Item\"), (symbol::name, string::\"Orange\"), (symbol::currency, string::\"USD\"), (symbol::symbol, string::\"$\"), (symbol::price, number::3.55))), (string::\"Item\", string::\"123456789\", ((symbol::javaClass, string::\"services.Item\"), (symbol::name, string::\"Apple\"), (symbol::currency, string::\"USD\"), (symbol::symbol, string::\"$\"), (symbol::price, number::2.99))))"));
return true;
}
-const tuscany::value evalLoop(std::istream& is, const tuscany::value& req, tuscany::Env& globalEnv) {
- tuscany::value in = tuscany::read(is);
- if(tuscany::isNil(in))
- return tuscany::eval(req, globalEnv);
- tuscany::eval(in, globalEnv);
+const value evalLoop(std::istream& is, const value& req, eval::Env& globalEnv) {
+ value in = eval::read(is);
+ if(isNil(in))
+ return eval::evalApply(req, globalEnv);
+ eval::evalApply(in, globalEnv);
return evalLoop(is, req, globalEnv);
}
@@ -55,31 +61,30 @@ bool testEval() {
{
std::ifstream is("store.scm", std::ios_base::in);
std::ostringstream os;
+ eval::setupEvalOut(os);
+ eval::Env globalEnv = eval::setupEnvironment();
- tuscany::setupEvalOut(os);
- tuscany::Env globalEnv = tuscany::setupEnvironment();
-
- const tuscany::value req(tuscany::mklist<tuscany::value>("storeui_service", std::string("getcatalog")));
- const tuscany::value res = evalLoop(is, req, globalEnv);
+ const value req(mklist<value>("storeui_service", std::string("getcatalog")));
+ const value val = evalLoop(is, req, globalEnv);
- std::ostringstream rs;
- rs << res;
- assert(contains(rs.str(), "List::(List::(List::(Symbol::name, (String::\"apple\", ())), (List::(Symbol::currency, (String::\"USD\", ())), (List::(Symbol::symbol, (String::\"$\", ())), (List::(Symbol::price, (Number::2.99, ())), ())))), (List::(List::(Symbol::name, (String::\"orange\", ())), (List::(Symbol::currency, (String::\"USD\", ())), (List::(Symbol::symbol, (String::\"$\", ())), (List::(Symbol::price, (Number::3.55, ())), ())))), (List::(List::(Symbol::name, (String::\"pear\", ())), (List::(Symbol::currency, (String::\"USD\", ())), (List::(Symbol::symbol, (String::\"$\", ())), (List::(Symbol::price, (Number::1.55, ())), ())))), ())))"));
+ std::ostringstream vs;
+ vs << val;
+ assert(contains(vs.str(),"(((symbol::javaClass, string::\"services.Item\"), (symbol::name, string::\"Apple\"), (symbol::currency, string::\"USD\"), (symbol::symbol, string::\"$\"), (symbol::price, number::2.99)), ((symbol::javaClass, string::\"services.Item\"), (symbol::name, string::\"Orange\"), (symbol::currency, string::\"USD\"), (symbol::symbol, string::\"$\"), (symbol::price, number::3.55)), ((symbol::javaClass, string::\"services.Item\"), (symbol::name, string::\"Pear\"), (symbol::currency, string::\"USD\"), (symbol::symbol, string::\"$\"), (symbol::price, number::1.55)))"));
}
{
std::ifstream is("store.scm", std::ios_base::in);
std::ostringstream os;
- tuscany::setupEvalOut(os);
- tuscany::Env globalEnv = tuscany::setupEnvironment();
+ eval::setupEvalOut(os);
+ eval::Env globalEnv = eval::setupEnvironment();
- const tuscany::value req(tuscany::mklist<tuscany::value>("storeui_service", std::string("gettotal")));
- const tuscany::value res = evalLoop(is, req, globalEnv);
+ const value req(mklist<value>("storeui_service", std::string("gettotal")));
+ const value res = evalLoop(is, req, globalEnv);
std::ostringstream rs;
rs << res;
- assert(contains(rs.str(), "Number::10"));
+ assert(contains(rs.str(), "number::10"));
}
return true;
}
diff --git a/cpp/sca/test/store-script/store.scm b/cpp/sca/test/store-script/store.scm
index 323a2ca304..99ae33481c 100644
--- a/cpp/sca/test/store-script/store.scm
+++ b/cpp/sca/test/store-script/store.scm
@@ -28,9 +28,10 @@
(define code "USD")
(define symbol (converter "symbol" code))
- (list (list (list 'name "apple") (list 'currency code) (list 'symbol symbol) (list 'price (convert 2.99)))
- (list (list 'name "orange") (list 'currency code) (list 'symbol symbol) (list 'price (convert 3.55)))
- (list (list 'name "pear") (list 'currency code) (list 'symbol symbol) (list 'price (convert 1.55)))
+ (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))
)
)
@@ -47,11 +48,16 @@
(; "Cart implementation")
(define (cart_post content item)
- (cons item content)
+ (cons (cons "Item" (list "123456789" item)) content)
)
(define (cart_getall content)
- content
+ (cons "Sample Feed" (cons "123" 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 (cart_gettotal)
@@ -62,6 +68,7 @@
(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))
)
)
@@ -76,6 +83,10 @@
(cart "getall" content)
)
+(define (storeui_getentry cart id)
+ (cart "getentry" id)
+)
+
(define (storeui_getcatalog catalog)
(catalog "get")
)
@@ -88,6 +99,7 @@
(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)))
)
@@ -104,13 +116,22 @@
(define catalog (storeui_service "getcatalog"))
(define empty (list))
(define apple (car catalog))
-(define full (storeui_service "post" empty apple))
-(display (storeui_service "getall" full))
+(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))
+