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

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: Convert ProductPriceTests.xml to Groovy(OFBIZ-11856)

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 a779bdc  Improved: Convert ProductPriceTests.xml to Groovy(OFBIZ-11856)
a779bdc is described below

commit a779bdc5f0ff0819e7c0efdf45a19e2d58b705e1
Author: Pawan Verma <[hidden email]>
AuthorDate: Sat Jul 25 11:49:28 2020 +0530

    Improved: Convert ProductPriceTests.xml to Groovy(OFBIZ-11856)
   
    Thanks, Akash for report and Anushi for patch.
---
 .../minilang/product/test/ProductPriceTests.xml    | 66 ----------------------
 .../apache/ofbiz/product/ProductPriceTests.groovy  | 63 +++++++++++++++++++++
 applications/product/testdef/CatalogTests.xml      |  2 +-
 3 files changed, 64 insertions(+), 67 deletions(-)

diff --git a/applications/product/minilang/product/test/ProductPriceTests.xml b/applications/product/minilang/product/test/ProductPriceTests.xml
deleted file mode 100644
index 335207a..0000000
--- a/applications/product/minilang/product/test/ProductPriceTests.xml
+++ /dev/null
@@ -1,66 +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="testCalculateProductPrice" short-description="Test case for service calculateProductPrice" login-required="false">
-        <set field="productId" value="GZ-2002"/>
-        <entity-one entity-name="Product" value-field="product"/>
-        <set field="serviceCtx.product" from-field="product"/>
-        <call-service service-name="calculateProductPrice" in-map-name="serviceCtx">
-            <results-to-map map-name="resultMap"/>
-        </call-service>
-        <assert>
-            <if-compare field="resultMap.defaultPrice" operator="equals" value="47.99" type="BigDecimal"/>
-            <if-compare field="resultMap.listPrice" operator="equals" value="48" type="BigDecimal"/>
-        </assert>
-        <check-errors/>
-    </simple-method>
-
-    <simple-method method-name="testCalculateProductPriceOfVariantProduct" short-description="Test case for service calculateProductPrice, when product is a variant and does not have product price" login-required="false">
-        <!-- If product is a variant and no price is set, then default price of virtual product will be set -->
-        <set field="productId" value="GZ-1006-3"/>
-        <entity-one entity-name="Product" value-field="product"/>
-        <set field="serviceCtx.product" from-field="product"/>
-        <call-service service-name="calculateProductPrice" in-map-name="serviceCtx">
-            <results-to-map map-name="resultMap"/>
-        </call-service>
-        <assert>
-            <if-compare field="resultMap.defaultPrice" operator="equals" value="1.99" type="BigDecimal"/>
-            <if-compare field="resultMap.listPrice" operator="equals" value="5.99" type="BigDecimal"/>
-        </assert>
-        <check-errors/>
-    </simple-method>
-
-    <simple-method method-name="testCalculateProductPriceOfVirtualProduct" short-description="Test case for service calculateProductPrice, when product is virtual and does not have product price set" login-required="false">
-        <!--  If product is a virtual and no price is set then then the service return price of a variant product which have lowest DEFAULT_PRICE. It is also considered whether the product is discontinued for sale before using the lowest price against a variant for a virtual product  -->
-        <set field="productId" value="DemoProduct"/>
-        <entity-one entity-name="Product" value-field="product"/>
-        <set field="serviceCtx.product" from-field="product"/>
-        <call-service service-name="calculateProductPrice" in-map-name="serviceCtx">
-            <results-to-map map-name="resultMap"/>
-        </call-service>
-        <assert>
-            <if-compare field="resultMap.defaultPrice" operator="equals" value="10" type="BigDecimal"/>
-        </assert>
-        <check-errors/>
-    </simple-method>
-</simple-methods>
diff --git a/applications/product/src/main/groovy/org/apache/ofbiz/product/ProductPriceTests.groovy b/applications/product/src/main/groovy/org/apache/ofbiz/product/ProductPriceTests.groovy
new file mode 100644
index 0000000..8717113
--- /dev/null
+++ b/applications/product/src/main/groovy/org/apache/ofbiz/product/ProductPriceTests.groovy
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * 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.entity.GenericValue
+import org.apache.ofbiz.service.ServiceUtil
+import org.apache.ofbiz.service.testtools.OFBizTestCase
+
+class ProductPriceTests extends OFBizTestCase {
+    public ProductPriceTests(String name) {
+        super(name)
+    }
+
+    void testCalculateProductPrice() {
+        String productId = 'GZ-2002'
+        GenericValue product = from('Product').where('productId', productId).queryOne()
+        Map serviceCtx = [:]
+        serviceCtx.product = product
+        Map resultMap = dispatcher.runSync('calculateProductPrice', serviceCtx)
+        assert ServiceUtil.isSuccess(resultMap)
+        assert resultMap.defaultPrice == 47.99
+        assert resultMap.listPrice == 48
+    }
+
+    void testCalculateProductPriceOfVariantProduct() {
+        // If product is a variant and no price is set, then default price of virtual product will be set
+        String productId = 'GZ-1006-3'
+        GenericValue product = from('Product').where('productId', productId).queryOne()
+        Map serviceCtx = [:]
+        serviceCtx.product = product
+        Map resultMap = dispatcher.runSync('calculateProductPrice', serviceCtx)
+        assert ServiceUtil.isSuccess(resultMap)
+        assert resultMap.defaultPrice == 1.99
+        assert resultMap.listPrice == 5.99
+    }
+
+    void testCalculateProductPriceOfVirtualProduct() {
+        // If product is a virtual and no price is set then then the service return price of a variant product which have lowest DEFAULT_PRICE. It is also considered whether the product is discontinued for sale before using the lowest price against a variant for a virtual product
+        String productId = 'DemoProduct'
+        GenericValue product = from('Product').where('productId', productId).queryOne()
+        Map serviceCtx = [:]
+        serviceCtx.product = product
+        Map resultMap = dispatcher.runSync('calculateProductPrice', serviceCtx)
+        assert ServiceUtil.isSuccess(resultMap)
+        assert resultMap.defaultPrice == 10
+    }
+}
\ No newline at end of file
diff --git a/applications/product/testdef/CatalogTests.xml b/applications/product/testdef/CatalogTests.xml
index 3c28126..006ace1 100644
--- a/applications/product/testdef/CatalogTests.xml
+++ b/applications/product/testdef/CatalogTests.xml
@@ -27,7 +27,7 @@ under the License.
     </test-case>
 
     <test-case case-name="productPrice-tests">
-        <simple-method-test location="component://product/minilang/product/test/ProductPriceTests.xml"/>
+        <junit-test-suite class-name="org.apache.ofbiz.product.ProductPriceTests"/>
     </test-case>
 
     <test-case case-name="loadCategoryTestData">