You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jl...@apache.org on 2021/07/10 12:00:07 UTC

[ofbiz-framework] branch trunk updated: Improved: Convert ShoppingListTests.xml to Groovy (OFBIZ-11861)

This is an automated email from the ASF dual-hosted git repository.

jleroux pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 497c950  Improved: Convert ShoppingListTests.xml to Groovy (OFBIZ-11861)
497c950 is described below

commit 497c950fd159e071100c43e9c6cd3642ce62c896
Author: Jacques Le Roux <ja...@les7arts.com>
AuthorDate: Sat Jul 10 13:59:49 2021 +0200

    Improved: Convert ShoppingListTests.xml to Groovy (OFBIZ-11861)
    
    This can be tested using this command:
    ./gradlew "ofbiz --test component=order --test suitename=shoppinglisttests"
    
    Thanks: Praveen Sharma
---
 .../order/minilang/test/ShoppingListTests.xml      | 165 ---------------------
 .../apache/ofbiz/order/ShoppingListTests.groovy    | 149 +++++++++++++++++++
 applications/order/testdef/ShoppingListTests.xml   |   2 +-
 3 files changed, 150 insertions(+), 166 deletions(-)

diff --git a/applications/order/minilang/test/ShoppingListTests.xml b/applications/order/minilang/test/ShoppingListTests.xml
deleted file mode 100644
index a4f851a..0000000
--- a/applications/order/minilang/test/ShoppingListTests.xml
+++ /dev/null
@@ -1,165 +0,0 @@
-<?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.
--->
-
-<simple-methods xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-        xmlns="http://ofbiz.apache.org/Simple-Method" xsi:schemaLocation="http://ofbiz.apache.org/Simple-Method http://ofbiz.apache.org/dtds/simple-methods.xsd">
-
-    <simple-method method-name="testCreateShoppingList" short-description="Test create shopping list" login-required="false">
-        <set field="serviceCtx.partyId" value="DemoCustomer"/>
-        <set field="serviceCtx.shoppingListTypeId" value="SLT_WISH_LIST"/>
-        <set field="serviceCtx.productStoreId" value="9000"/>
-        <set field="serviceCtx.listName" value="Demo Wish List 1"/>
-        <set field="serviceCtx.isActive" value="Y"/>
-        <set field="serviceCtx.currencyUom" value="USD"/>
-
-        <entity-one entity-name="UserLogin" value-field="userLogin">
-            <field-map field-name="userLoginId" value="DemoCustomer"/>
-        </entity-one>
-        <set field="serviceCtx.userLogin" from-field="userLogin"/>
-        <call-service service-name="createShoppingList" in-map-name="serviceCtx" require-new-transaction="true">
-            <result-to-field result-name="shoppingListId"/>
-        </call-service>
-        <entity-one entity-name="ShoppingList" value-field="shoppingList"/>
-        <assert>
-            <not><if-empty field="shoppingList"/></not>
-            <if-compare field="shoppingList.partyId" operator="equals" value="DemoCustomer"/>
-            <if-compare field="shoppingList.listName" operator="equals" value="Demo Wish List 1"/>
-        </assert>
-        <check-errors/>
-    </simple-method>
-
-    <simple-method method-name="testCreateShoppingListItem" short-description="Test create shopping list item" login-required="false">
-        <set field="shoppingListId" value="DemoWishList"/>
-        <set field="serviceCtx.shoppingListId" from-field="shoppingListId"/>
-        <set field="serviceCtx.productId" value="GZ-8544"/>
-        <set field="serviceCtx.quantity" value="3" type="BigDecimal"/>
-        <set field="serviceCtx.productStoreId" value="9000"/>
-        <entity-one entity-name="UserLogin" value-field="userLogin">
-            <field-map field-name="userLoginId" value="DemoCustomer"/>
-        </entity-one>
-        <set field="serviceCtx.userLogin" from-field="userLogin"/>
-        <call-service service-name="createShoppingListItem" in-map-name="serviceCtx">
-            <result-to-field result-name="shoppingListItemSeqId"/>
-        </call-service>
-        <entity-one entity-name="ShoppingListItem" value-field="shoppingListItem"/>
-        <assert>
-            <not><if-empty field="shoppingListItem"/></not>
-            <if-compare field="shoppingListItem.productId" operator="equals" value="GZ-8544"/>
-            <if-compare field="shoppingListItem.quantity" operator="equals" value="3" type="BigDecimal"/>
-        </assert>
-        <check-errors/>
-    </simple-method>
-
-    <simple-method method-name="testCreateShoppingListItemWithSameProduct" short-description="Test create shopping list item by adding a product that already exist in shopping list." login-required="false">
-        <set field="shoppingListId" value="DemoWishList"/>
-        <set field="serviceCtx.shoppingListId" from-field="shoppingListId"/>
-        <set field="serviceCtx.productId" value="GZ-2644"/>
-        <set field="serviceCtx.quantity" value="2" type="BigDecimal"/>
-        <set field="serviceCtx.productStoreId" value="9000"/>
-        <entity-one entity-name="UserLogin" value-field="userLogin">
-            <field-map field-name="userLoginId" value="DemoCustomer"/>
-        </entity-one>
-        <set field="serviceCtx.userLogin" from-field="userLogin"/>
-        <call-service service-name="createShoppingListItem" in-map-name="serviceCtx">
-            <result-to-field result-name="shoppingListItemSeqId"/>
-        </call-service>
-        <entity-one entity-name="ShoppingListItem" value-field="shoppingListItem"/>
-        <assert>
-            <not><if-empty field="shoppingListItem"/></not>
-            <if-compare field="shoppingListItem.quantity" operator="equals" value="7" type="BigDecimal"/>
-        </assert>
-        <check-errors/>
-    </simple-method>
-
-    <simple-method method-name="testUpdateShoppingList" short-description="Test update shopping list by updating the listName" login-required="false">
-        <set field="serviceCtx.shoppingListId" value="DemoWishList"/>
-        <set field="serviceCtx.listName" value="New Demo Wish List"/>
-        <entity-one entity-name="UserLogin" value-field="userLogin">
-            <field-map field-name="userLoginId" value="DemoCustomer"/>
-        </entity-one>
-        <set field="serviceCtx.userLogin" from-field="userLogin"/>
-        <call-service service-name="updateShoppingList" in-map-name="serviceCtx"/>
-        <entity-one entity-name="ShoppingList" value-field="shoppingList">
-            <field-map field-name="shoppingListId" from-field="serviceCtx.shoppingListId"/>
-        </entity-one>
-        <assert>
-            <not><if-empty field="shoppingList"/></not>
-            <if-compare field="shoppingList.listName" operator="equals" value="New Demo Wish List"/>
-        </assert>
-        <check-errors/>
-    </simple-method>
-
-    <simple-method method-name="testUpdateShoppingListItem" short-description="Test update shopping list item by updating quantity of item" login-required="false">
-        <set field="serviceCtx.shoppingListId" value="DemoWishList"/>
-        <set field="serviceCtx.shoppingListItemSeqId" value="00002"/>
-        <set field="serviceCtx.quantity" value="4" type="BigDecimal"/>
-        <entity-one entity-name="UserLogin" value-field="userLogin">
-            <field-map field-name="userLoginId" value="DemoCustomer"/>
-        </entity-one>
-        <set field="serviceCtx.userLogin" from-field="userLogin"/>
-        <call-service service-name="updateShoppingListItem" in-map-name="serviceCtx"/>
-        <entity-one entity-name="ShoppingListItem" value-field="shoppingListItem">
-            <field-map field-name="shoppingListId" from-field="serviceCtx.shoppingListId"/>
-            <field-map field-name="shoppingListItemSeqId" value="00002"/>
-        </entity-one>
-        <assert>
-            <not><if-empty field="shoppingListItem"/></not>
-            <if-compare field="shoppingListItem.quantity" operator="equals" value="4" type="BigDecimal"/>
-        </assert>
-        <check-errors/>
-    </simple-method>
-
-    <simple-method method-name="testUpdateShoppingListItemWithZeroQty" short-description="Test update shopping list item for a product with zero quantity" login-required="false">
-        <set field="serviceCtx.shoppingListId" value="DemoWishList"/>
-        <set field="serviceCtx.shoppingListItemSeqId" value="00003"/>
-        <set field="serviceCtx.quantity" value="0" type="BigDecimal"/>
-        <entity-one entity-name="UserLogin" value-field="userLogin">
-            <field-map field-name="userLoginId" value="DemoCustomer"/>
-        </entity-one>
-        <set field="serviceCtx.userLogin" from-field="userLogin"/>
-        <call-service service-name="updateShoppingListItem" in-map-name="serviceCtx"/>
-        <entity-one entity-name="ShoppingListItem" value-field="shoppingListItem">
-            <field-map field-name="shoppingListId" from-field="serviceCtx.shoppingListId"/>
-            <field-map field-name="shoppingListItemSeqId" value="00003"/>
-        </entity-one>
-        <assert>
-            <not><if-empty field="shoppingListItem"/></not>
-        </assert>
-        <check-errors/>
-    </simple-method>
-
-    <simple-method method-name="testRemoveShoppingListItem" short-description="Test remove shopping list item" login-required="false">
-        <set field="serviceCtx.shoppingListId" value="DemoWishList"/>
-        <set field="serviceCtx.shoppingListItemSeqId" value="00002"/>
-        <entity-one entity-name="UserLogin" value-field="userLogin">
-            <field-map field-name="userLoginId" value="DemoCustomer"/>
-        </entity-one>
-        <set field="serviceCtx.userLogin" from-field="userLogin"/>
-        <call-service service-name="removeShoppingListItem" in-map-name="serviceCtx"/>
-        <entity-one entity-name="ShoppingListItem" value-field="shoppingListItem">
-            <field-map field-name="shoppingListId" from-field="serviceCtx.shoppingListId"/>
-            <field-map field-name="shoppingListItemSeqId" value="00002"/>
-        </entity-one>
-        <assert>
-            <if-empty field="shoppingListItem"/>
-        </assert>
-        <check-errors/>
-    </simple-method>
-</simple-methods>
diff --git a/applications/order/src/main/groovy/org/apache/ofbiz/order/ShoppingListTests.groovy b/applications/order/src/main/groovy/org/apache/ofbiz/order/ShoppingListTests.groovy
new file mode 100644
index 0000000..ff9094d
--- /dev/null
+++ b/applications/order/src/main/groovy/org/apache/ofbiz/order/ShoppingListTests.groovy
@@ -0,0 +1,149 @@
+/*
+ * 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.
+ */
+package org.apache.ofbiz.order
+
+import org.apache.ofbiz.entity.GenericValue
+import org.apache.ofbiz.service.ServiceUtil
+import org.apache.ofbiz.service.testtools.OFBizTestCase
+
+class ShoppingListTests extends OFBizTestCase {
+    public ShoppingListTests(String name) {
+        super(name)
+    }
+
+    // Test create shopping list.
+    void testCreateShoppingList() {
+        GenericValue userLogin = delegator.findOne("UserLogin", [userLoginId:'DemoCustomer'], false);
+        Map serviceCtx = [
+                partyId: 'DemoCustomer',
+                shoppingListTypeId: 'SLT_WISH_LIST',
+                productStoreId: '9000',
+                listName: 'Demo Wish List 1',
+                isActive: 'Y',
+                currencyUom: 'USD',
+                userLogin: userLogin
+        ]
+        Map resultMap = dispatcher.runSync('createShoppingList', serviceCtx, 600, true);
+        def shoppingListId = resultMap.shoppingListId;
+        GenericValue shoppingList = delegator.findOne("ShoppingList", [shoppingListId:shoppingListId], false);
+        assert ServiceUtil.isSuccess(resultMap);
+        assert shoppingList;
+        assert shoppingList.partyId == 'DemoCustomer';
+        assert shoppingList.listName == 'Demo Wish List 1';
+    }
+
+    // Test create shopping list item
+    void testCreateShoppingListItem() {
+        GenericValue userLogin = delegator.findOne("UserLogin", [userLoginId:'DemoCustomer'], false);
+        def shoppingListId = 'DemoWishList';
+        Map serviceCtx = [
+                shoppingListId: shoppingListId,
+                productId: 'GZ-8544',
+                quantity: new BigDecimal(3),
+                productStoreId: '9000',
+                userLogin: userLogin
+        ]
+        Map resultMap = dispatcher.runSync('createShoppingListItem', serviceCtx);
+        def shoppingListItemSeqId = resultMap.shoppingListItemSeqId;
+        GenericValue shoppingListItem = from('ShoppingListItem').where('shoppingListItemSeqId', shoppingListItemSeqId).queryOne()
+        assert ServiceUtil.isSuccess(resultMap);
+        assert shoppingListItem;
+        assert shoppingListItem.productId == 'GZ-8544';
+        assert shoppingListItem.quantity == 3;
+    }
+
+    // Test create shopping list item by adding a product that already exist in shopping list.
+    void testCreateShoppingListItemWithSameProduct() {
+        GenericValue userLogin = delegator.findOne("UserLogin", [userLoginId:'DemoCustomer'], false);
+        def shoppingListId = 'DemoWishList';
+        Map serviceCtx = [
+                shoppingListId: shoppingListId,
+                productId: 'GZ-2644',
+                quantity: new BigDecimal(2),
+                productStoreId: '9000',
+                userLogin: userLogin
+        ]
+        Map resultMap = dispatcher.runSync('createShoppingListItem', serviceCtx);
+        def shoppingListItemSeqId = resultMap.shoppingListItemSeqId;
+        GenericValue shoppingListItem = from('ShoppingListItem').where('shoppingListItemSeqId', shoppingListItemSeqId).queryOne()
+        assert ServiceUtil.isSuccess(resultMap);
+        assert shoppingListItem;
+        assert shoppingListItem.quantity == 7;
+    }
+
+    // Test update shopping list by updating the listName
+    void testUpdateShoppingList() {
+        GenericValue userLogin = delegator.findOne("UserLogin", [userLoginId:'DemoCustomer'], false);
+        Map serviceCtx = [
+                shoppingListId: 'DemoWishList',
+                listName: 'New Demo Wish List',
+                userLogin: userLogin
+        ]
+        Map resultMap = dispatcher.runSync('updateShoppingList', serviceCtx);
+        GenericValue shoppingList = delegator.findOne("ShoppingList", [shoppingListId:serviceCtx.shoppingListId], false);
+        assert ServiceUtil.isSuccess(resultMap);
+        assert shoppingList;
+        assert shoppingList.listName == 'New Demo Wish List';
+    }
+
+    // Test update shopping list item by updating quantity of item
+    void testUpdateShoppingListItem () {
+        GenericValue userLogin = delegator.findOne("UserLogin", [userLoginId:'DemoCustomer'], false);
+        Map serviceCtx = [
+                shoppingListId: 'DemoWishList',
+                shoppingListItemSeqId: '00002',
+                quantity: new BigDecimal(4),
+                userLogin: userLogin
+        ]
+        Map resultMap = dispatcher.runSync('updateShoppingListItem', serviceCtx);
+        GenericValue shoppingListItem = delegator.findOne("ShoppingListItem", [shoppingListId:serviceCtx.shoppingListId, 'shoppingListItemSeqId': '00002'], false);
+        assert ServiceUtil.isSuccess(resultMap)
+        assert shoppingListItem
+        assert shoppingListItem.quantity == 4
+    }
+
+    // Test update shopping list item for a product with zero quantity
+    void testUpdateShoppingListItemWithZeroQty() {
+        GenericValue userLogin = delegator.findOne("UserLogin", [userLoginId:'DemoCustomer'], false);
+        Map serviceCtx = [
+                shoppingListId: 'DemoWishList',
+                shoppingListItemSeqId: '00003',
+                quantity: new BigDecimal(0),
+                userLogin: userLogin
+        ]
+        Map resultMap = dispatcher.runSync('updateShoppingListItem', serviceCtx);
+        GenericValue shoppingListItem = delegator.findOne("ShoppingListItem", [shoppingListId:serviceCtx.shoppingListId, 'shoppingListItemSeqId': '00003'], false);
+        assert ServiceUtil.isSuccess(resultMap)
+        assert shoppingListItem
+    }
+
+    // Test remove shopping list item
+    void testRemoveShoppingListItem() {
+        GenericValue userLogin = delegator.findOne("UserLogin", [userLoginId:'DemoCustomer'], false);
+        Map serviceCtx = [
+                shoppingListId: 'DemoWishList',
+                shoppingListItemSeqId: '00002',
+                userLogin: userLogin
+        ]
+        Map resultMap = dispatcher.runSync('removeShoppingListItem', serviceCtx);
+        GenericValue shoppingListItem = delegator.findOne("ShoppingListItem", [shoppingListId:serviceCtx.shoppingListId, 'shoppingListItemSeqId': '00002'], false);
+        assert ServiceUtil.isSuccess(resultMap)
+        assert !shoppingListItem
+    }
+}
diff --git a/applications/order/testdef/ShoppingListTests.xml b/applications/order/testdef/ShoppingListTests.xml
index e1a723c..7484e6b 100644
--- a/applications/order/testdef/ShoppingListTests.xml
+++ b/applications/order/testdef/ShoppingListTests.xml
@@ -27,6 +27,6 @@ under the License.
     </test-case>
 
     <test-case case-name="shoppingList-test">
-        <simple-method-test location="component://order/minilang/test/ShoppingListTests.xml"/>
+        <junit-test-suite class-name="org.apache.ofbiz.order.ShoppingListTests"/>
     </test-case>
 </test-suite>