From bd0fdbf902f8ca8e7e352582efe938e1d6743dd1 Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Mon, 16 Nov 2009 06:57:41 +0000 Subject: Cleaning up SVN structure, moving sca trunk to sca-cpp/trunk. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@880633 13f79535-47bb-0310-9956-ffa450edef68 --- sca-cpp/trunk/test/store-function/Makefile.am | 32 ++++++++++ sca-cpp/trunk/test/store-function/cart.hpp | 69 ++++++++++++++++++++++ sca-cpp/trunk/test/store-function/catalog.hpp | 54 +++++++++++++++++ .../trunk/test/store-function/catalogs.composite | 43 ++++++++++++++ .../test/store-function/currency-composite.hpp | 37 ++++++++++++ .../trunk/test/store-function/currency.composite | 32 ++++++++++ sca-cpp/trunk/test/store-function/currency.hpp | 58 ++++++++++++++++++ sca-cpp/trunk/test/store-function/item.hpp | 54 +++++++++++++++++ sca-cpp/trunk/test/store-function/service.hpp | 35 +++++++++++ .../trunk/test/store-function/store-composite.hpp | 47 +++++++++++++++ .../test/store-function/store-function-test.cpp | 50 ++++++++++++++++ .../trunk/test/store-function/store-solution.hpp | 41 +++++++++++++ sca-cpp/trunk/test/store-function/store-ui.hpp | 64 ++++++++++++++++++++ sca-cpp/trunk/test/store-function/store.composite | 64 ++++++++++++++++++++ 14 files changed, 680 insertions(+) create mode 100644 sca-cpp/trunk/test/store-function/Makefile.am create mode 100644 sca-cpp/trunk/test/store-function/cart.hpp create mode 100644 sca-cpp/trunk/test/store-function/catalog.hpp create mode 100644 sca-cpp/trunk/test/store-function/catalogs.composite create mode 100644 sca-cpp/trunk/test/store-function/currency-composite.hpp create mode 100644 sca-cpp/trunk/test/store-function/currency.composite create mode 100644 sca-cpp/trunk/test/store-function/currency.hpp create mode 100644 sca-cpp/trunk/test/store-function/item.hpp create mode 100644 sca-cpp/trunk/test/store-function/service.hpp create mode 100644 sca-cpp/trunk/test/store-function/store-composite.hpp create mode 100644 sca-cpp/trunk/test/store-function/store-function-test.cpp create mode 100644 sca-cpp/trunk/test/store-function/store-solution.hpp create mode 100644 sca-cpp/trunk/test/store-function/store-ui.hpp create mode 100644 sca-cpp/trunk/test/store-function/store.composite (limited to 'sca-cpp/trunk/test/store-function') diff --git a/sca-cpp/trunk/test/store-function/Makefile.am b/sca-cpp/trunk/test/store-function/Makefile.am new file mode 100644 index 0000000000..8d73bf3bff --- /dev/null +++ b/sca-cpp/trunk/test/store-function/Makefile.am @@ -0,0 +1,32 @@ +# 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_function_PROGRAMS = store-function-test +store_functiondir=$(prefix)/test/store-function/deploy + +nobase_include_HEADERS = *.hpp + +INCLUDES = -I. -I$(top_builddir)/kernel -I${LIBXML2_INCLUDE} -I${APR_INCLUDE} + +store_function_test_SOURCES = store-function-test.cpp +store_function_test_LDADD = -lpthread -L${LIBXML2_LIB} -lxml2 -L${APR_LIB} -lapr-1 -laprutil-1 + +EXTRA_DIST = *.composite +store_function_DATA = *.composite + +TESTS = store-function-test + diff --git a/sca-cpp/trunk/test/store-function/cart.hpp b/sca-cpp/trunk/test/store-function/cart.hpp new file mode 100644 index 0000000000..9ed6474985 --- /dev/null +++ b/sca-cpp/trunk/test/store-function/cart.hpp @@ -0,0 +1,69 @@ +/* + * 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$ */ + +#ifndef tuscany_cart_hpp +#define tuscany_cart_hpp + +#include +#include "service.hpp" +#include "item.hpp" + +namespace store +{ + +const double accumTotal(const double total, const ItemType& item) { + return total + itemPrice(item); +} + +tuscany::list cart; + +const tuscany::list shoppingCart_getAll() { + return cart; +} + +const bool shoppingCart_post(const ItemType& item) { + cart = cons(item, cart); + return true; +} + +const bool shoppingCart_deleteAll() { + cart = tuscany::list(); + return true; +} + +const double shoppingCart_getTotal() { + return tuscany::reduce(accumTotal, 0.0, cart); +} + +const tuscany::value shoppingCart_service(const tuscany::list& args) { + if (car(args) == "getAll") + return shoppingCart_getAll(); + if (car(args) == "post") + return shoppingCart_post(cadr(args)); + if (car(args) == "deleteAll") + return shoppingCart_deleteAll(); + if (car(args) == "getTotal") + return shoppingCart_getTotal(); + return tuscany::value(); +} + +} +#endif /* tuscany_cart_hpp */ diff --git a/sca-cpp/trunk/test/store-function/catalog.hpp b/sca-cpp/trunk/test/store-function/catalog.hpp new file mode 100644 index 0000000000..c49ebc8fa3 --- /dev/null +++ b/sca-cpp/trunk/test/store-function/catalog.hpp @@ -0,0 +1,54 @@ +/* + * 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$ */ + +#ifndef tuscany_catalog_hpp +#define tuscany_catalog_hpp + +#include +#include "service.hpp" +#include "currency.hpp" +#include "item.hpp" + +namespace store +{ + +std::string catalog_currencyCode = "USD"; + +double catalog_convert(const service& currencyConverter, const double price) { + return currencyConverter(tuscany::mklist("convert", "USD", catalog_currencyCode, price)); +} + +const tuscany::list catalog_get(const service& currencyConverter) { + const std::string currencySymbol = currencyConverter_service(tuscany::mklist("getSymbol", catalog_currencyCode)); + return tuscany::mklist( + item("Apple", catalog_currencyCode, currencySymbol, catalog_convert(currencyConverter, 2.99)), + item("Orange", catalog_currencyCode, currencySymbol, catalog_convert(currencyConverter, 3.55)), + item("Pear", catalog_currencyCode, currencySymbol, catalog_convert(currencyConverter, 1.55))); +} + +const tuscany::value catalog_service(const service& currencyConverter, const tuscany::list& args) { + if (car(args) == "get") + return catalog_get(currencyConverter); + return tuscany::value(); +} + +} +#endif /* tuscany_catalog_hpp */ diff --git a/sca-cpp/trunk/test/store-function/catalogs.composite b/sca-cpp/trunk/test/store-function/catalogs.composite new file mode 100644 index 0000000000..1638ed0a05 --- /dev/null +++ b/sca-cpp/trunk/test/store-function/catalogs.composite @@ -0,0 +1,43 @@ + + + + + + + + + + USD + + + + + + + + + + + + + diff --git a/sca-cpp/trunk/test/store-function/currency-composite.hpp b/sca-cpp/trunk/test/store-function/currency-composite.hpp new file mode 100644 index 0000000000..ae28471538 --- /dev/null +++ b/sca-cpp/trunk/test/store-function/currency-composite.hpp @@ -0,0 +1,37 @@ +/* + * 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$ */ + +#ifndef tuscany_currencycomposite_hpp +#define tuscany_currencycomposite_hpp + +#include +#include "service.hpp" +#include "currency.hpp" + +namespace store +{ + +const tuscany::value currency_service(const tuscany::list& args) { + return currencyConverter_service(args); +} + +} +#endif /* tuscany_currencycomposite_hpp */ diff --git a/sca-cpp/trunk/test/store-function/currency.composite b/sca-cpp/trunk/test/store-function/currency.composite new file mode 100644 index 0000000000..aefd474f1f --- /dev/null +++ b/sca-cpp/trunk/test/store-function/currency.composite @@ -0,0 +1,32 @@ + + + + + + + + + + + + diff --git a/sca-cpp/trunk/test/store-function/currency.hpp b/sca-cpp/trunk/test/store-function/currency.hpp new file mode 100644 index 0000000000..453a5e1e81 --- /dev/null +++ b/sca-cpp/trunk/test/store-function/currency.hpp @@ -0,0 +1,58 @@ +/* + * 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$ */ + +#ifndef tuscany_currency_hpp +#define tuscany_currency_hpp + +#include +#include +#include "service.hpp" +#include "item.hpp" + +namespace store +{ + +const double currencyConverter_convert(const std::string& fromCurrencyCode, const std::string& toCurrencyCode, const double amount) { + if(toCurrencyCode == "USD") + return amount; + if(toCurrencyCode == "EUR") + return round(amount * 0.7256 * 100) / 100; + return amount; +} + +const std::string currencyConverter_getSymbol(const std::string& currencyCode) { + if(currencyCode == "USD") + return "$"; + if(currencyCode == "EUR") + return "E"; + return "?"; +} + +const tuscany::value currencyConverter_service(const tuscany::list& args) { + if (car(args) == "convert") + return currencyConverter_convert(cadr(args), car(cdr(cdr(args))), car(cdr(cdr(cdr(args))))); + if (car(args) == "getSymbol") + return currencyConverter_getSymbol(cadr(args)); + return tuscany::value(); +} + +} +#endif /* tuscany_currency_hpp */ diff --git a/sca-cpp/trunk/test/store-function/item.hpp b/sca-cpp/trunk/test/store-function/item.hpp new file mode 100644 index 0000000000..fbe29915dc --- /dev/null +++ b/sca-cpp/trunk/test/store-function/item.hpp @@ -0,0 +1,54 @@ +/* + * 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$ */ + +#ifndef tuscany_item_hpp +#define tuscany_item_hpp + +#include +#include "service.hpp" + +namespace store +{ + +typedef tuscany::value ItemType; + +const ItemType item(const std::string& name, const std::string& currencyCode, const std::string& currencySymbol, const double price) { + return tuscany::mklist(name, currencyCode, currencySymbol, price); +} + +const std::string itemName(const ItemType& item) { + return car((tuscany::list)item); +} + +const std::string itemCurrencyCode(const ItemType& item) { + return car(cdr((tuscany::list)item)); +} + +const std::string itemCurrencySymbol(const ItemType& item) { + return car(cdr(cdr((tuscany::list)item))); +} + +const double itemPrice(const ItemType& item) { + return car(cdr(cdr(cdr((tuscany::list)item)))); +} + +} +#endif /* tuscany_item_hpp */ diff --git a/sca-cpp/trunk/test/store-function/service.hpp b/sca-cpp/trunk/test/store-function/service.hpp new file mode 100644 index 0000000000..b764e87d1a --- /dev/null +++ b/sca-cpp/trunk/test/store-function/service.hpp @@ -0,0 +1,35 @@ +/* + * 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$ */ + +#ifndef tuscany_service_hpp +#define tuscany_service_hpp + +#include "function.hpp" +#include "list.hpp" +#include "value.hpp" + +namespace store +{ + +typedef tuscany::lambda)> service; + +} +#endif /* tuscany_service_hpp */ diff --git a/sca-cpp/trunk/test/store-function/store-composite.hpp b/sca-cpp/trunk/test/store-function/store-composite.hpp new file mode 100644 index 0000000000..351c905eae --- /dev/null +++ b/sca-cpp/trunk/test/store-function/store-composite.hpp @@ -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. + */ + +/* $Rev$ $Date$ */ + +#ifndef tuscany_storecomposite_hpp +#define tuscany_storecomposite_hpp + +#include +#include "service.hpp" +#include "currency.hpp" +#include "currency-composite.hpp" +#include "item.hpp" +#include "catalog.hpp" +#include "cart.hpp" +#include "store-ui.hpp" + +namespace store +{ + +const tuscany::value store_service(const service& currency, const tuscany::list& args) { + const tuscany::lambda)> catalogService(catalog_service); + const service catalog(curry(catalogService, currency)); + const service cart(shoppingCart_service); + const tuscany::lambda)> storeUIService(storeUI_service); + const service configuredStoreUIService(curry(storeUIService, catalog, cart)); + return configuredStoreUIService(args); +} + +} +#endif /* tuscany_storecomposite_hpp */ diff --git a/sca-cpp/trunk/test/store-function/store-function-test.cpp b/sca-cpp/trunk/test/store-function/store-function-test.cpp new file mode 100644 index 0000000000..8a6a86eb8a --- /dev/null +++ b/sca-cpp/trunk/test/store-function/store-function-test.cpp @@ -0,0 +1,50 @@ +/* + * 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 +#include "store-solution.hpp" + +namespace store +{ + +bool testComponentAssembly() { + const service store(storeSolution_service); + assert(length((tuscany::list)store(tuscany::mklist("getCatalog"))) == 3); + return true; +} + +} + +int main() { + + std::cout << "Testing..." << std::endl; + + store::testComponentAssembly(); + std::cout << "OK" << std::endl; + + return 0; +} diff --git a/sca-cpp/trunk/test/store-function/store-solution.hpp b/sca-cpp/trunk/test/store-function/store-solution.hpp new file mode 100644 index 0000000000..e0addcba12 --- /dev/null +++ b/sca-cpp/trunk/test/store-function/store-solution.hpp @@ -0,0 +1,41 @@ +/* + * 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$ */ + +#ifndef tuscany_storesolution_hpp +#define tuscany_storesolution_hpp + +#include +#include "service.hpp" +#include "store-composite.hpp" +#include "currency-composite.hpp" + +namespace store +{ + +const tuscany::value storeSolution_service(const tuscany::list& args) { + const service currency(currency_service); + const tuscany::lambda)> storeService(store_service); + const service configuredStoreService(curry(storeService, currency)); + return configuredStoreService(args); +} + +} +#endif /* tuscany_storesolution_hpp */ diff --git a/sca-cpp/trunk/test/store-function/store-ui.hpp b/sca-cpp/trunk/test/store-function/store-ui.hpp new file mode 100644 index 0000000000..12b28d6a92 --- /dev/null +++ b/sca-cpp/trunk/test/store-function/store-ui.hpp @@ -0,0 +1,64 @@ +/* + * 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$ */ + +#ifndef tuscany_storeui_hpp +#define tuscany_storeui_hpp + +#include +#include "service.hpp" +#include "currency.hpp" +#include "item.hpp" +#include "catalog.hpp" +#include "cart.hpp" + +namespace store +{ + +const tuscany::list storeUI_getCatalog(const service& catalog) { + return catalog(tuscany::mklist("get")); +} + +const tuscany::list storeUI_getCart(const service& cart) { + return cart(tuscany::mklist("getAll")); +} + +const double storeUI_getTotal(const service& cart) { + return cart(tuscany::mklist("getTotal")); +} + +const bool storeUI_post(const service& cart, const ItemType& item) { + return cart(tuscany::mklist("post", item)); +} + +const tuscany::value storeUI_service(const service& catalog, const service& cart, const tuscany::list& args) { + if (car(args) == "getCatalog") + return storeUI_getCatalog(catalog); + if (car(args) == "getCart") + return storeUI_getCart(cart); + if (car(args) == "getTotal") + return storeUI_getTotal(cart); + if (car(args) == "post") + return storeUI_post(cart, cadr(args)); + return tuscany::value(); +} + +} +#endif /* STOREUI_HPP_ */ diff --git a/sca-cpp/trunk/test/store-function/store.composite b/sca-cpp/trunk/test/store-function/store.composite new file mode 100644 index 0000000000..124adff853 --- /dev/null +++ b/sca-cpp/trunk/test/store-function/store.composite @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + + + + + + + + + USD + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3