diff options
Diffstat (limited to 'cpp/sca/test')
34 files changed, 1738 insertions, 0 deletions
diff --git a/cpp/sca/test/Makefile.am b/cpp/sca/test/Makefile.am new file mode 100644 index 0000000000..4a20e27139 --- /dev/null +++ b/cpp/sca/test/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. + +SUBDIRS = store-object store-function store-script + diff --git a/cpp/sca/test/store-function/Makefile.am b/cpp/sca/test/store-function/Makefile.am new file mode 100644 index 0000000000..b63381c0cf --- /dev/null +++ b/cpp/sca/test/store-function/Makefile.am @@ -0,0 +1,28 @@ +# 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 + +INCLUDES = -I. -I$(top_builddir)/kernel -I${LIBXML2_INCLUDE} + +store_function_test_SOURCES = store-function-test.cpp +store_function_test_LDADD = -L${LIBXML2_LIB} -lxml2 -lpthread + +EXTRA_DIST = *.composite +store_function_DATA = *.composite + diff --git a/cpp/sca/test/store-function/cart.hpp b/cpp/sca/test/store-function/cart.hpp new file mode 100644 index 0000000000..c21e509487 --- /dev/null +++ b/cpp/sca/test/store-function/cart.hpp @@ -0,0 +1,70 @@ +/* + * 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 <string> +#include "service.hpp" +#include "item.hpp" + +namespace store +{ + +const double accumTotal(const double total, const ItemType& item) { + return total + itemPrice(item); +} + +tuscany::list<ItemType> cart; + +const tuscany::list<ItemType> shoppingCart_getAll() { + return cart; +} + +const bool shoppingCart_post(const ItemType& item) { + cart = cons(item, cart); + return true; +} + +const bool shoppingCart_deleteAll() { + cart = tuscany::list<ItemType>(); + return true; +} + +const double shoppingCart_getTotal() { + tuscany::lambda<double(double, ItemType)> a(accumTotal); + return reduce(a, 0.0, cart); +} + +const tuscany::value shoppingCart_service(const tuscany::list<tuscany::value>& args) { + if (car(args) == tuscany::value("getAll")) + return tuscany::value(shoppingCart_getAll()); + if (car(args) == tuscany::value("post")) + return tuscany::value(shoppingCart_post(cadr(args))); + if (car(args) == tuscany::value("deleteAll")) + return tuscany::value(shoppingCart_deleteAll()); + if (car(args) == tuscany::value("getTotal")) + return tuscany::value(shoppingCart_getTotal()); + return tuscany::value(); +} + +} +#endif /* tuscany_cart_hpp */ diff --git a/cpp/sca/test/store-function/catalog.hpp b/cpp/sca/test/store-function/catalog.hpp new file mode 100644 index 0000000000..82a69e2bbd --- /dev/null +++ b/cpp/sca/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 <string> +#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(makeList(tuscany::value("convert"), tuscany::value("USD"), tuscany::value(catalog_currencyCode), tuscany::value(price))); +} + +const tuscany::list<ItemType> catalog_get(const service& currencyConverter) { + const std::string currencySymbol = currencyConverter_service(makeList(tuscany::value("getSymbol"), tuscany::value(catalog_currencyCode))); + return makeList( + makeItem("Apple", catalog_currencyCode, currencySymbol, catalog_convert(currencyConverter, 2.99)), + makeItem("Orange", catalog_currencyCode, currencySymbol, catalog_convert(currencyConverter, 3.55)), + makeItem("Pear", catalog_currencyCode, currencySymbol, catalog_convert(currencyConverter, 1.55))); +} + +const tuscany::value catalog_service(const service& currencyConverter, const tuscany::list<tuscany::value>& args) { + if (car(args) == tuscany::value("get")) + return tuscany::value(catalog_get(currencyConverter)); + return tuscany::value(); +} + +} +#endif /* tuscany_catalog_hpp */ diff --git a/cpp/sca/test/store-function/catalogs.composite b/cpp/sca/test/store-function/catalogs.composite new file mode 100644 index 0000000000..1638ed0a05 --- /dev/null +++ b/cpp/sca/test/store-function/catalogs.composite @@ -0,0 +1,43 @@ +<?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="catalogs"> + + <component name="FruitsCatalogWebService"> + <implementation.java class="services.FruitsCatalogImpl"/> + <service name="Catalog"> + <binding.ws/> + </service> + <property name="currencyCode">USD</property> + <reference name="currencyConverter" target="CurrencyConverterWebService"> + <binding.ws/> + </reference> + </component> + + <component name="VegetablesCatalogWebService"> + <implementation.java class="services.VegetablesCatalogImpl"/> + <service name="Catalog"> + <binding.ws/> + </service> + </component> + +</composite> diff --git a/cpp/sca/test/store-function/currency-composite.hpp b/cpp/sca/test/store-function/currency-composite.hpp new file mode 100644 index 0000000000..ae28471538 --- /dev/null +++ b/cpp/sca/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 <string> +#include "service.hpp" +#include "currency.hpp" + +namespace store +{ + +const tuscany::value currency_service(const tuscany::list<tuscany::value>& args) { + return currencyConverter_service(args); +} + +} +#endif /* tuscany_currencycomposite_hpp */ diff --git a/cpp/sca/test/store-function/currency.composite b/cpp/sca/test/store-function/currency.composite new file mode 100644 index 0000000000..aefd474f1f --- /dev/null +++ b/cpp/sca/test/store-function/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"> + <implementation.java class="services.CurrencyConverterImpl"/> + <service name="CurrencyConverter"> + <binding.ws/> + </service> + </component> + +</composite> diff --git a/cpp/sca/test/store-function/currency.hpp b/cpp/sca/test/store-function/currency.hpp new file mode 100644 index 0000000000..ce7e4f464b --- /dev/null +++ b/cpp/sca/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 <math.h> +#include <string> +#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<tuscany::value>& args) { + if (car(args) == tuscany::value("convert")) + return tuscany::value(currencyConverter_convert(cadr(args), car(cdr(cdr(args))), car(cdr(cdr(cdr(args)))))); + if (car(args) == tuscany::value("getSymbol")) + return tuscany::value(currencyConverter_getSymbol(cadr(args))); + return tuscany::value(); +} + +} +#endif /* tuscany_currency_hpp */ diff --git a/cpp/sca/test/store-function/item.hpp b/cpp/sca/test/store-function/item.hpp new file mode 100644 index 0000000000..8a121124a3 --- /dev/null +++ b/cpp/sca/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 <string> +#include "service.hpp" + +namespace store +{ + +typedef tuscany::value ItemType; + +const ItemType makeItem(const std::string& name, const std::string& currencyCode, const std::string& currencySymbol, const double price) { + return tuscany::value(makeList(tuscany::value(name), tuscany::value(currencyCode), tuscany::value(currencySymbol), tuscany::value(price))); +} + +const std::string itemName(const ItemType& item) { + return car((tuscany::list<tuscany::value>)item); +} + +const std::string itemCurrencyCode(const ItemType& item) { + return car(cdr((tuscany::list<tuscany::value>)item)); +} + +const std::string itemCurrencySymbol(const ItemType& item) { + return car(cdr(cdr((tuscany::list<tuscany::value>)item))); +} + +const double itemPrice(const ItemType& item) { + return car(cdr(cdr(cdr((tuscany::list<tuscany::value>)item)))); +} + +} +#endif /* tuscany_item_hpp */ diff --git a/cpp/sca/test/store-function/service.hpp b/cpp/sca/test/store-function/service.hpp new file mode 100644 index 0000000000..b764e87d1a --- /dev/null +++ b/cpp/sca/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<tuscany::value(tuscany::list<tuscany::value>)> service; + +} +#endif /* tuscany_service_hpp */ diff --git a/cpp/sca/test/store-function/store-composite.hpp b/cpp/sca/test/store-function/store-composite.hpp new file mode 100644 index 0000000000..351c905eae --- /dev/null +++ b/cpp/sca/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 <string> +#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<tuscany::value>& args) { + const tuscany::lambda<tuscany::value(service, tuscany::list<tuscany::value>)> catalogService(catalog_service); + const service catalog(curry(catalogService, currency)); + const service cart(shoppingCart_service); + const tuscany::lambda<tuscany::value(service, service, tuscany::list<tuscany::value>)> storeUIService(storeUI_service); + const service configuredStoreUIService(curry(storeUIService, catalog, cart)); + return configuredStoreUIService(args); +} + +} +#endif /* tuscany_storecomposite_hpp */ diff --git a/cpp/sca/test/store-function/store-function-test.cpp b/cpp/sca/test/store-function/store-function-test.cpp new file mode 100644 index 0000000000..e71ecfd633 --- /dev/null +++ b/cpp/sca/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 <assert.h> +#include <iostream> +#include <string> +#include "store-solution.hpp" + +namespace store +{ + +bool testComponentAssembly() { + const service store(storeSolution_service); + assert(length((tuscany::list<tuscany::value>)store(makeList(tuscany::value("getCatalog")))) == 3); + return true; +} + +} + +int main() { + + std::cout << "Testing..." << std::endl; + + store::testComponentAssembly(); + std::cout << "OK" << std::endl; + + return 0; +} diff --git a/cpp/sca/test/store-function/store-solution.hpp b/cpp/sca/test/store-function/store-solution.hpp new file mode 100644 index 0000000000..e0addcba12 --- /dev/null +++ b/cpp/sca/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 <string> +#include "service.hpp" +#include "store-composite.hpp" +#include "currency-composite.hpp" + +namespace store +{ + +const tuscany::value storeSolution_service(const tuscany::list<tuscany::value>& args) { + const service currency(currency_service); + const tuscany::lambda<tuscany::value(service, tuscany::list<tuscany::value>)> storeService(store_service); + const service configuredStoreService(curry(storeService, currency)); + return configuredStoreService(args); +} + +} +#endif /* tuscany_storesolution_hpp */ diff --git a/cpp/sca/test/store-function/store-ui.hpp b/cpp/sca/test/store-function/store-ui.hpp new file mode 100644 index 0000000000..9b100a6793 --- /dev/null +++ b/cpp/sca/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 <string> +#include "service.hpp" +#include "currency.hpp" +#include "item.hpp" +#include "catalog.hpp" +#include "cart.hpp" + +namespace store +{ + +const tuscany::list<ItemType> storeUI_getCatalog(const service& catalog) { + return catalog(makeList(tuscany::value("get"))); +} + +const tuscany::list<ItemType> storeUI_getCart(const service& cart) { + return cart(makeList(tuscany::value("getAll"))); +} + +const double storeUI_getTotal(const service& cart) { + return cart(makeList(tuscany::value("getTotal"))); +} + +const bool storeUI_post(const service& cart, const ItemType& item) { + return cart(makeList(tuscany::value("post"), tuscany::value(item))); +} + +const tuscany::value storeUI_service(const service& catalog, const service& cart, const tuscany::list<tuscany::value>& args) { + if (car(args) == tuscany::value("getCatalog")) + return tuscany::value(storeUI_getCatalog(catalog)); + if (car(args) == tuscany::value("getCart")) + return tuscany::value(storeUI_getCart(cart)); + if (car(args) == tuscany::value("getTotal")) + return tuscany::value(storeUI_getTotal(cart)); + if (car(args) == tuscany::value("post")) + return tuscany::value(storeUI_post(cart, cadr(args))); + return tuscany::value(); +} + +} +#endif /* STOREUI_HPP_ */ diff --git a/cpp/sca/test/store-function/store.composite b/cpp/sca/test/store-function/store.composite new file mode 100644 index 0000000000..124adff853 --- /dev/null +++ b/cpp/sca/test/store-function/store.composite @@ -0,0 +1,64 @@ +<?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="uiservices/store.html"/> + <service name="Widget"> + <t:binding.http uri="/ui"/> + </service> + <reference name="catalog" target="StoreCatalog"> + <t:binding.jsonrpc/> + </reference> + <reference name="shoppingCart" target="StoreShoppingCart/Cart"> + <t:binding.atom/> + </reference> + <reference name="shoppingTotal" target="StoreShoppingCart/Total"> + <t:binding.jsonrpc/> + </reference> + </component> + + <component name="StoreCatalog"> + <implementation.java class="services.FruitsCatalogImpl"/> + <property name="currencyCode">USD</property> + <service name="Catalog"> + <t:binding.jsonrpc/> + </service> + <reference name="currencyConverter" target="StoreCurrencyConverter"/> + </component> + + <component name="StoreShoppingCart"> + <implementation.java class="services.ShoppingCartImpl"/> + <service name="Cart"> + <t:binding.atom uri="/ShoppingCart/Cart"/> + </service> + <service name="Total"> + <t:binding.jsonrpc/> + </service> + </component> + + <component name="StoreCurrencyConverter"> + <implementation.java class="services.CurrencyConverterImpl"/> + </component> + +</composite> diff --git a/cpp/sca/test/store-object/Makefile.am b/cpp/sca/test/store-object/Makefile.am new file mode 100644 index 0000000000..c79bf6ebde --- /dev/null +++ b/cpp/sca/test/store-object/Makefile.am @@ -0,0 +1,28 @@ +# 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_object_PROGRAMS = store-object-test +store_objectdir=$(prefix)/test/store-object/deploy + +INCLUDES = -I. -I$(top_builddir)/kernel -I${LIBXML2_INCLUDE} + +store_object_test_SOURCES = store-object-test.cpp +store_object_test_LDADD = -L${LIBXML2_LIB} -lxml2 -lpthread + +EXTRA_DIST = *.composite +store_object_DATA = *.composite + diff --git a/cpp/sca/test/store-object/cart.hpp b/cpp/sca/test/store-object/cart.hpp new file mode 100644 index 0000000000..fc6155aa25 --- /dev/null +++ b/cpp/sca/test/store-object/cart.hpp @@ -0,0 +1,75 @@ +/* + * 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 store_cart_hpp +#define store_cart_hpp + +#include <string> +#include "function.hpp" +#include "list.hpp" +#include "currency.hpp" +#include "item.hpp" +#include "catalog.hpp" + +namespace store +{ + +const double accum(const double total, const Item& item) { + return total + item.price; +} + +class ShoppingCart { +public: + virtual const tuscany::list<Item> getAll() const = 0; + + virtual const bool post(const Item& item) = 0; + + virtual const bool deleteAll() = 0; + + virtual const double getTotal() const = 0; +}; + +class ShoppingCartImpl : public ShoppingCart { +public: + tuscany::list<Item> cart; + + virtual const tuscany::list<Item> getAll() const { + return cart; + } + + virtual const bool post(const Item& item) { + cart = cons(item, cart); + return true; + } + + virtual const bool deleteAll() { + cart = tuscany::list<Item>(); + return true; + } + + virtual const double getTotal() const { + tuscany::lambda<double(double, Item)> a(accum); + return reduce(a, 0.0, cart); + } +}; + +} +#endif /* store_cart_hpp */ diff --git a/cpp/sca/test/store-object/catalog.hpp b/cpp/sca/test/store-object/catalog.hpp new file mode 100644 index 0000000000..6909911c07 --- /dev/null +++ b/cpp/sca/test/store-object/catalog.hpp @@ -0,0 +1,65 @@ +/* + * 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 store_catalog_hpp +#define store_catalog_hpp + +#include <string> +#include "list.hpp" +#include "currency.hpp" +#include "item.hpp" + +namespace store +{ + +class Catalog { +public: + + virtual const double convert(const double price) const = 0; + + virtual const tuscany::list<Item> get() const = 0; +}; + +class CatalogImpl : public Catalog { +public: + + const std::string currencyCode; + const CurrencyConverter& currencyConverter; + + CatalogImpl(const CurrencyConverter& currencyConverter) : + currencyCode("USD"), currencyConverter(currencyConverter) { + } + + virtual const double convert(const double price) const { + return currencyConverter.convert("USD", currencyCode, price); + } + + virtual const tuscany::list<Item> get() const { + const std::string currencySymbol = currencyConverter.getSymbol(currencyCode); + return tuscany::makeList( + Item("Apple", currencyCode, currencySymbol, convert(2.99)), + Item("Orange", currencyCode, currencySymbol, convert(3.55)), + Item("Pear", currencyCode, currencySymbol, convert(1.55))); + } +}; + +} +#endif /* store_catalog_hpp */ diff --git a/cpp/sca/test/store-object/catalogs.composite b/cpp/sca/test/store-object/catalogs.composite new file mode 100644 index 0000000000..1638ed0a05 --- /dev/null +++ b/cpp/sca/test/store-object/catalogs.composite @@ -0,0 +1,43 @@ +<?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="catalogs"> + + <component name="FruitsCatalogWebService"> + <implementation.java class="services.FruitsCatalogImpl"/> + <service name="Catalog"> + <binding.ws/> + </service> + <property name="currencyCode">USD</property> + <reference name="currencyConverter" target="CurrencyConverterWebService"> + <binding.ws/> + </reference> + </component> + + <component name="VegetablesCatalogWebService"> + <implementation.java class="services.VegetablesCatalogImpl"/> + <service name="Catalog"> + <binding.ws/> + </service> + </component> + +</composite> diff --git a/cpp/sca/test/store-object/currency-composite.hpp b/cpp/sca/test/store-object/currency-composite.hpp new file mode 100644 index 0000000000..94b52b461e --- /dev/null +++ b/cpp/sca/test/store-object/currency-composite.hpp @@ -0,0 +1,51 @@ +/* + * 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 store_currencycomposite_hpp +#define store_currencycomposite_hpp + +#include <string> +#include "currency.hpp" + +namespace store +{ + +class Currency : public CurrencyConverter { +}; + +class CurrencyImpl : public Currency { +public: + const CurrencyConverterImpl currencyConverter; + + CurrencyImpl() : currencyConverter(CurrencyConverterImpl()) { + } + + virtual const double convert(const std::string& fromCurrencyCode, const std::string& toCurrencyCode, const double amount) const { + return currencyConverter.convert(fromCurrencyCode, toCurrencyCode, amount); + } + + virtual const std::string getSymbol(const std::string& currencyCode) const { + return currencyConverter.getSymbol(currencyCode); + } +}; + +} +#endif /* store_currencycomposite_hpp */ diff --git a/cpp/sca/test/store-object/currency.composite b/cpp/sca/test/store-object/currency.composite new file mode 100644 index 0000000000..aefd474f1f --- /dev/null +++ b/cpp/sca/test/store-object/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"> + <implementation.java class="services.CurrencyConverterImpl"/> + <service name="CurrencyConverter"> + <binding.ws/> + </service> + </component> + +</composite> diff --git a/cpp/sca/test/store-object/currency.hpp b/cpp/sca/test/store-object/currency.hpp new file mode 100644 index 0000000000..a8228ea51c --- /dev/null +++ b/cpp/sca/test/store-object/currency.hpp @@ -0,0 +1,59 @@ +/* + * 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 store_currency_hpp +#define store_currency_hpp + +#include <math.h> +#include <string> + +namespace store +{ + +class CurrencyConverter { +public: + + virtual const double convert(const std::string& fromCurrencyCode, const std::string& toCurrencyCode, const double amount) const = 0; + virtual const std::string getSymbol(const std::string& currencyCode) const = 0; +}; + +class CurrencyConverterImpl : public CurrencyConverter { +public: + + virtual const double convert(const std::string& fromCurrencyCode, const std::string& toCurrencyCode, const double amount) const { + if(toCurrencyCode == "USD") + return amount; + if(toCurrencyCode == "EUR") + return round(amount * 0.7256 * 100) / 100; + return amount; + } + + virtual const std::string getSymbol(const std::string& currencyCode) const { + if(currencyCode == "USD") + return "$"; + if(currencyCode == "EUR") + return "E"; + return "?"; + } +}; + +} +#endif /* store_currency_hpp */ diff --git a/cpp/sca/test/store-object/item.hpp b/cpp/sca/test/store-object/item.hpp new file mode 100644 index 0000000000..ab8e52769b --- /dev/null +++ b/cpp/sca/test/store-object/item.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 store_item_hpp +#define store_item_hpp + +#include <string> + +namespace store +{ + +class Item { +public: + std::string name; + double price; + std::string currencyCode; + std::string currencySymbol; + + Item() { + } + + Item(const std::string& name, const std::string& currencyCode, const std::string& currencySymbol, const double price) : + name(name), price(price), currencyCode(currencyCode), currencySymbol(currencySymbol) { + } + +}; + +} +#endif /* store_item_hpp */ diff --git a/cpp/sca/test/store-object/store-composite.hpp b/cpp/sca/test/store-object/store-composite.hpp new file mode 100644 index 0000000000..8cee5a943f --- /dev/null +++ b/cpp/sca/test/store-object/store-composite.hpp @@ -0,0 +1,68 @@ +/* + * 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 store_storecomposite_hpp +#define store_storecomposite_hpp + +#include "list.hpp" +#include "currency.hpp" +#include "currency-composite.hpp" +#include "item.hpp" +#include "catalog.hpp" +#include "cart.hpp" +#include "store-ui.hpp" + +namespace store +{ + +class Store : public StoreUI { +}; + +class StoreImpl : public Store { +public: + const CatalogImpl catalog; + ShoppingCartImpl cart; + StoreUIImpl storeUI; + + StoreImpl(const Currency& currency) : + catalog(CatalogImpl(currency)), cart(ShoppingCartImpl()), storeUI(StoreUIImpl(catalog, cart)) { + } + + virtual const tuscany::list<Item> getCatalog() const { + return storeUI.getCatalog(); + } + + virtual const tuscany::list<Item> getCart() const { + return storeUI.getCart(); + } + + virtual const double getTotal() const { + return storeUI.getTotal(); + } + + virtual const bool post(const Item& item) { + return storeUI.post(item); + } + +}; + +} +#endif /* store_storecomposite_hpp */ diff --git a/cpp/sca/test/store-object/store-object-test.cpp b/cpp/sca/test/store-object/store-object-test.cpp new file mode 100644 index 0000000000..bfbf5459ac --- /dev/null +++ b/cpp/sca/test/store-object/store-object-test.cpp @@ -0,0 +1,52 @@ +/* + * 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 <assert.h> +#include <iostream> +#include "store-solution.hpp" + +namespace store +{ + +bool testComponentAssembly() { + StoreSolutionImpl store = StoreSolutionImpl(); + assert(length(store.getCatalog()) == 3); + assert(store.post(car(store.getCatalog())) == true); + assert(store.post(cadr(store.getCatalog())) == true); + assert(length(store.getCart()) == 2); + assert(store.getTotal() == 6.54); + return true; +} + +} + +int main() { + std::cout << "Testing..." << std::endl; + + store::testComponentAssembly(); + std::cout << "OK" << std::endl; + + return 0; +} diff --git a/cpp/sca/test/store-object/store-solution.hpp b/cpp/sca/test/store-object/store-solution.hpp new file mode 100644 index 0000000000..ecabb18f1c --- /dev/null +++ b/cpp/sca/test/store-object/store-solution.hpp @@ -0,0 +1,62 @@ +/* + * 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 store_storesolution_hpp +#define store_storesolution_hpp + +#include "list.hpp" +#include "store-composite.hpp" +#include "currency-composite.hpp" + +namespace store +{ + +class StoreSolution : public Store { +}; + +class StoreSolutionImpl : public StoreSolution { +public: + const CurrencyImpl currency; + StoreImpl store; + + StoreSolutionImpl() : + currency(CurrencyImpl()), store(StoreImpl(currency)) { + } + + virtual const tuscany::list<Item> getCatalog() const { + return store.getCatalog(); + } + + virtual const tuscany::list<Item> getCart() const { + return store.getCart(); + } + + virtual const double getTotal() const { + return store.getTotal(); + } + + virtual const bool post(const Item& item) { + return store.post(item); + } +}; + +} +#endif /* store_storesolution_hpp */ diff --git a/cpp/sca/test/store-object/store-ui.hpp b/cpp/sca/test/store-object/store-ui.hpp new file mode 100644 index 0000000000..c9d0f4330b --- /dev/null +++ b/cpp/sca/test/store-object/store-ui.hpp @@ -0,0 +1,72 @@ +/* + * 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 store_storeui_hpp +#define store_storeui_hpp + +#include "list.hpp" +#include "currency.hpp" +#include "item.hpp" +#include "catalog.hpp" +#include "cart.hpp" + +namespace store +{ + +class StoreUI { +public: + + virtual const tuscany::list<Item> getCatalog() const =0; + + virtual const tuscany::list<Item> getCart() const = 0; + + virtual const double getTotal() const =0; + + virtual const bool post(const Item& item) = 0; +}; + +class StoreUIImpl : public StoreUI { +public: + const Catalog& catalog; + ShoppingCart& cart; + + StoreUIImpl(const Catalog& catalog, ShoppingCart& cart) : catalog(catalog), cart(cart) { + } + + virtual const tuscany::list<Item> getCatalog() const { + return catalog.get(); + } + + virtual const tuscany::list<Item> getCart() const { + return cart.getAll(); + } + + virtual const double getTotal() const { + return cart.getTotal(); + } + + virtual const bool post(const Item& item) { + return cart.post(item); + } +}; + +} +#endif /* store_storeui_hpp */ diff --git a/cpp/sca/test/store-object/store.composite b/cpp/sca/test/store-object/store.composite new file mode 100644 index 0000000000..124adff853 --- /dev/null +++ b/cpp/sca/test/store-object/store.composite @@ -0,0 +1,64 @@ +<?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="uiservices/store.html"/> + <service name="Widget"> + <t:binding.http uri="/ui"/> + </service> + <reference name="catalog" target="StoreCatalog"> + <t:binding.jsonrpc/> + </reference> + <reference name="shoppingCart" target="StoreShoppingCart/Cart"> + <t:binding.atom/> + </reference> + <reference name="shoppingTotal" target="StoreShoppingCart/Total"> + <t:binding.jsonrpc/> + </reference> + </component> + + <component name="StoreCatalog"> + <implementation.java class="services.FruitsCatalogImpl"/> + <property name="currencyCode">USD</property> + <service name="Catalog"> + <t:binding.jsonrpc/> + </service> + <reference name="currencyConverter" target="StoreCurrencyConverter"/> + </component> + + <component name="StoreShoppingCart"> + <implementation.java class="services.ShoppingCartImpl"/> + <service name="Cart"> + <t:binding.atom uri="/ShoppingCart/Cart"/> + </service> + <service name="Total"> + <t:binding.jsonrpc/> + </service> + </component> + + <component name="StoreCurrencyConverter"> + <implementation.java class="services.CurrencyConverterImpl"/> + </component> + +</composite> diff --git a/cpp/sca/test/store-script/Makefile.am b/cpp/sca/test/store-script/Makefile.am new file mode 100644 index 0000000000..aded08f6b3 --- /dev/null +++ b/cpp/sca/test/store-script/Makefile.am @@ -0,0 +1,28 @@ +# 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_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} + +store_script_test_SOURCES = store-script-test.cpp +store_script_test_LDADD = -L${LIBXML2_LIB} -lxml2 -lpthread + +EXTRA_DIST = *.composite +store_script_DATA = *.composite + diff --git a/cpp/sca/test/store-script/catalogs.composite b/cpp/sca/test/store-script/catalogs.composite new file mode 100644 index 0000000000..1638ed0a05 --- /dev/null +++ b/cpp/sca/test/store-script/catalogs.composite @@ -0,0 +1,43 @@ +<?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="catalogs"> + + <component name="FruitsCatalogWebService"> + <implementation.java class="services.FruitsCatalogImpl"/> + <service name="Catalog"> + <binding.ws/> + </service> + <property name="currencyCode">USD</property> + <reference name="currencyConverter" target="CurrencyConverterWebService"> + <binding.ws/> + </reference> + </component> + + <component name="VegetablesCatalogWebService"> + <implementation.java class="services.VegetablesCatalogImpl"/> + <service name="Catalog"> + <binding.ws/> + </service> + </component> + +</composite> diff --git a/cpp/sca/test/store-script/currency.composite b/cpp/sca/test/store-script/currency.composite new file mode 100644 index 0000000000..aefd474f1f --- /dev/null +++ b/cpp/sca/test/store-script/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"> + <implementation.java class="services.CurrencyConverterImpl"/> + <service name="CurrencyConverter"> + <binding.ws/> + </service> + </component> + +</composite> diff --git a/cpp/sca/test/store-script/store-script-test.cpp b/cpp/sca/test/store-script/store-script-test.cpp new file mode 100644 index 0000000000..dff802b714 --- /dev/null +++ b/cpp/sca/test/store-script/store-script-test.cpp @@ -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$ */ + +/** + * Store Test case. + */ + +#include <assert.h> +#include <iostream> +#include <fstream> +#include <string> +#include "driver.hpp" + +namespace store +{ + +bool contains(const std::string& str, const std::string& pattern) { + return str.find(pattern) != str.npos; +} + +bool testScript() { + std::ifstream is("store-script.scm", std::ios_base::in); + std::ostringstream os; + tuscany::evalDriverRun(is, os); + assert(contains(os.str(), "List::(List::(String::'apple', (String::'USD', (String::'$', (Number::2.99, ())))), ())")); + return true; +} + +} + +int main() { + + std::cout << "Testing..." << std::endl; + + store::testScript(); + + std::cout << "OK" << std::endl; + + return 0; +} diff --git a/cpp/sca/test/store-script/store-script.scm b/cpp/sca/test/store-script/store-script.scm new file mode 100644 index 0000000000..8af88b45f0 --- /dev/null +++ b/cpp/sca/test/store-script/store-script.scm @@ -0,0 +1,99 @@ + +(display "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)) + ) +) + +(display "Currency composite") + +(define (currency_service op . args) (currency_impl op args)) + +(display "Catalog implementation") + +(define (catalog_get converter) + (define (convert price) (converter "convert" "USD" "USD" price)) + + (define code "USD") + (define symbol (converter "symbol" code)) + + (list (list "apple" code symbol (convert 2.99)) + (list "orange" code symbol (convert 3.55)) + (list "pear" code symbol (convert 1.55)) + ) +) + +(define (catalog_impl converter op args) + (cond + ((equal? op "get") (apply catalog_get (cons converter args))) + ) +) + +(display "Catalog composite") + +(define (catalog_service op . args) (catalog_impl currency_service op args)) + +(display "Cart implementation") + +(define (cart_post content item) + (cons item content) +) + +(define (cart_getall content) + content +) + +(define (cart_impl op args) + (cond + ((equal? op "post") (apply cart_post args)) + ((equal? op "getall") (apply cart_getall args)) + ) +) + +(display "Store UI implementation") + +(define (storeui_post cart content item) + (cart "post" content item) +) + +(define (storeui_getcart cart content) + (cart "getall" content) +) + +(define (storeui_getcatalog catalog) + (catalog "get") +) + +(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 "getcatalog") (apply storeui_getcatalog (cons catalog args))) + ) +) + +(display "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)) + +(display "Store UI test case") + +(define catalog (storeui_service "getcatalog")) +(define empty (list)) +(define apple (car catalog)) +(define full (storeui_service "post" empty apple)) +(display (storeui_service "getall" full)) + diff --git a/cpp/sca/test/store-script/store.composite b/cpp/sca/test/store-script/store.composite new file mode 100644 index 0000000000..124adff853 --- /dev/null +++ b/cpp/sca/test/store-script/store.composite @@ -0,0 +1,64 @@ +<?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="uiservices/store.html"/> + <service name="Widget"> + <t:binding.http uri="/ui"/> + </service> + <reference name="catalog" target="StoreCatalog"> + <t:binding.jsonrpc/> + </reference> + <reference name="shoppingCart" target="StoreShoppingCart/Cart"> + <t:binding.atom/> + </reference> + <reference name="shoppingTotal" target="StoreShoppingCart/Total"> + <t:binding.jsonrpc/> + </reference> + </component> + + <component name="StoreCatalog"> + <implementation.java class="services.FruitsCatalogImpl"/> + <property name="currencyCode">USD</property> + <service name="Catalog"> + <t:binding.jsonrpc/> + </service> + <reference name="currencyConverter" target="StoreCurrencyConverter"/> + </component> + + <component name="StoreShoppingCart"> + <implementation.java class="services.ShoppingCartImpl"/> + <service name="Cart"> + <t:binding.atom uri="/ShoppingCart/Cart"/> + </service> + <service name="Total"> + <t:binding.jsonrpc/> + </service> + </component> + + <component name="StoreCurrencyConverter"> + <implementation.java class="services.CurrencyConverterImpl"/> + </component> + +</composite> |