[ofbiz-framework] branch trunk updated: Improved: Groovy DSL test case for service addProductCategoryToCategory and getProductCategoryAndLimitedMembers (#111)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[ofbiz-framework] branch trunk updated: Improved: Groovy DSL test case for service addProductCategoryToCategory and getProductCategoryAndLimitedMembers (#111)

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

pawan 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 ff53e54  Improved: Groovy DSL test case for service addProductCategoryToCategory and getProductCategoryAndLimitedMembers (#111)
ff53e54 is described below

commit ff53e54a4ed487eed48067ab35b6faa5799b7db2
Author: Pawan Verma <[hidden email]>
AuthorDate: Wed May 6 11:33:44 2020 +0530

    Improved: Groovy DSL test case for service addProductCategoryToCategory and getProductCategoryAndLimitedMembers (#111)
   
    * Improved: Groovy DSL test case for service addProductCategoryToCategory and getProductCategoryAndLimitedMembers
    (OFBIZ-9088)
   
    Thanks: Pradhan Yash Sharma for report and initial patch and Suraj and Jacques for the review.
---
 .../minilang/product/test/CategoryTests.xml        | 48 ----------------
 .../org/apache/ofbiz/product/CategoryTests.groovy  | 67 ++++++++++++++++++++++
 applications/product/testdef/CatalogTests.xml      |  6 +-
 .../CategoryTestData.xml}                          | 19 ++----
 4 files changed, 77 insertions(+), 63 deletions(-)

diff --git a/applications/product/minilang/product/test/CategoryTests.xml b/applications/product/minilang/product/test/CategoryTests.xml
deleted file mode 100644
index 1358bc3..0000000
--- a/applications/product/minilang/product/test/CategoryTests.xml
+++ /dev/null
@@ -1,48 +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="testGetProductCategoryAndLimitedMembers" short-description="Test case for service getProductCategoryAndLimitedMembers" login-required="false">
-        <set field="serviceCtx.productCategoryId" value="101"/>
-        <set field="serviceCtx.prodCatalogId" value="DemoCatalog"/>
-        <set field="serviceCtx.defaultViewSize" value="10" type="Integer"/>
-        <set field="serviceCtx.limitView" value="true" type="Boolean"/>
-        <call-service service-name="getProductCategoryAndLimitedMembers" in-map-name="serviceCtx">
-            <result-to-field result-name="productCategoryMembers"/>
-            <result-to-field result-name="productCategory"/>
-        </call-service>
-        <assert>
-            <not><if-empty field="productCategory"/></not>
-            <not><if-empty field="productCategoryMembers"/></not>
-            <if-compare field="productCategory.productCategoryId" operator="equals" value="101"/>
-        </assert>
-        <check-errors/>
-        <entity-and entity-name="ProductCategoryMember" list="productCategoryMemberList">
-            <field-map field-name="productCategoryId" value="101"/>
-        </entity-and>
-        <set field="isValid" value="${groovy: productCategoryMemberList.containsAll(productCategoryMembers)}" type="Boolean"/>
-        <assert>
-            <if-compare field="isValid" operator="equals" value="true" type="Boolean"/>
-        </assert>
-        <check-errors/>
-    </simple-method>
-</simple-methods>
diff --git a/applications/product/src/main/groovy/org/apache/ofbiz/product/CategoryTests.groovy b/applications/product/src/main/groovy/org/apache/ofbiz/product/CategoryTests.groovy
new file mode 100644
index 0000000..a22bf53
--- /dev/null
+++ b/applications/product/src/main/groovy/org/apache/ofbiz/product/CategoryTests.groovy
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * 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.product
+
+import org.apache.ofbiz.base.util.UtilDateTime
+import org.apache.ofbiz.entity.GenericValue
+import org.apache.ofbiz.service.ServiceUtil
+import org.apache.ofbiz.service.testtools.OFBizTestCase
+
+class CategoryTests extends OFBizTestCase {
+    public CategoryTests(String name) {
+        super(name)
+    }
+
+    void testAddProductCategoryToCategory() {
+        Map serviceCtx = [
+                productCategoryId: 'TPC',
+                parentProductCategoryId: 'TPCP',
+                fromDate: UtilDateTime.nowTimestamp(),
+                userLogin: userLogin
+        ]
+        serviceCtx.userLogin = userLogin
+        Map serviceResult = dispatcher.runSync('addProductCategoryToCategory', serviceCtx)
+        assert ServiceUtil.isSuccess(serviceResult)
+
+        GenericValue prodCategory = from('ProductCategoryRollup').where('productCategoryId', 'TPC', 'parentProductCategoryId', 'TPCP').queryFirst()
+        assert prodCategory != null
+    }
+
+    void testGetProductCategoryAndLimitedMembers() {
+        Map serviceCtx = [
+                productCategoryId: '101',
+                prodCatalogId: 'DemoCatalog',
+                defaultViewSize: 10,
+                limitView: true,
+                userLogin: userLogin
+        ]
+        serviceCtx.userLogin = userLogin
+        Map serviceResult = dispatcher.runSync('getProductCategoryAndLimitedMembers', serviceCtx)
+        assert ServiceUtil.isSuccess(serviceResult)
+
+        assert serviceResult.productCategoryMembers != null
+        assert serviceResult.productCategory != null
+        assert serviceResult.productCategory.productCategoryId == '101'
+
+        List<GenericValue> productCategoryMemberList = from('ProductCategoryMember').where('productCategoryId', '101').queryList()
+        assert productCategoryMemberList.containsAll(serviceResult.productCategoryMembers)
+    }
+
+}
+
diff --git a/applications/product/testdef/CatalogTests.xml b/applications/product/testdef/CatalogTests.xml
index 7ddc143..3c28126 100644
--- a/applications/product/testdef/CatalogTests.xml
+++ b/applications/product/testdef/CatalogTests.xml
@@ -30,7 +30,11 @@ under the License.
         <simple-method-test location="component://product/minilang/product/test/ProductPriceTests.xml"/>
     </test-case>
 
+    <test-case case-name="loadCategoryTestData">
+        <entity-xml action="load" entity-xml-url="component://product/testdef/data/CategoryTestData.xml"/>
+    </test-case>
+
     <test-case case-name="category-tests">
-        <simple-method-test location="component://product/minilang/product/test/CategoryTests.xml"/>
+        <junit-test-suite class-name="org.apache.ofbiz.product.CategoryTests"/>
     </test-case>
 </test-suite>
diff --git a/applications/product/testdef/CatalogTests.xml b/applications/product/testdef/data/CategoryTestData.xml
similarity index 53%
copy from applications/product/testdef/CatalogTests.xml
copy to applications/product/testdef/data/CategoryTestData.xml
index 7ddc143..5aa16af 100644
--- a/applications/product/testdef/CatalogTests.xml
+++ b/applications/product/testdef/data/CategoryTestData.xml
@@ -18,19 +18,10 @@ specific language governing permissions and limitations
 under the License.
 -->
 
-<test-suite suite-name="catalogtests"
-        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-        xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/test-suite.xsd">
+<entity-engine-xml>
 
-    <test-case case-name="loadProductPriceTestData">
-        <entity-xml action="load" entity-xml-url="component://product/testdef/data/ProductPriceTestData.xml"/>
-    </test-case>
+    <ProductCategoryType description="Test Category" hasTable="N" productCategoryTypeId="TEST_CATEGORY"/>
+    <ProductCategory categoryName="Test Product Category Parent" longDescription="Long Test Product Category Parent Description" productCategoryId="TPCP" productCategoryTypeId="TEST_CATEGORY"/>
+    <ProductCategory categoryName="Test Product Category" longDescription="Long Test Product Category Description" primaryParentCategoryId="TPCP" productCategoryId="TPC" productCategoryTypeId="TEST_CATEGORY"/>
 
-    <test-case case-name="productPrice-tests">
-        <simple-method-test location="component://product/minilang/product/test/ProductPriceTests.xml"/>
-    </test-case>
-
-    <test-case case-name="category-tests">
-        <simple-method-test location="component://product/minilang/product/test/CategoryTests.xml"/>
-    </test-case>
-</test-suite>
+</entity-engine-xml>