[ofbiz-framework] branch trunk updated: Improved: Converted RateTests from XML to Groovy (OFBIZ-11561)(OFBIZ-11562)(OFBIZ-11563)(OFBIZ-11564)(OFBIZ-11565)(OFBIZ-11566)(OFBIZ-11567)(OFBIZ-11569)

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: Converted RateTests from XML to Groovy (OFBIZ-11561)(OFBIZ-11562)(OFBIZ-11563)(OFBIZ-11564)(OFBIZ-11565)(OFBIZ-11566)(OFBIZ-11567)(OFBIZ-11569)

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 04bc8be  Improved: Converted RateTests from XML to Groovy (OFBIZ-11561)(OFBIZ-11562)(OFBIZ-11563)(OFBIZ-11564)(OFBIZ-11565)(OFBIZ-11566)(OFBIZ-11567)(OFBIZ-11569)
04bc8be is described below

commit 04bc8be7cb8f70d7df89dbd30acf5ea39fd5c841
Author: Pawan Verma <[hidden email]>
AuthorDate: Mon Jun 1 16:47:10 2020 +0530

    Improved: Converted RateTests from XML to Groovy
    (OFBIZ-11561)(OFBIZ-11562)(OFBIZ-11563)(OFBIZ-11564)(OFBIZ-11565)(OFBIZ-11566)(OFBIZ-11567)(OFBIZ-11569)
   
    Thanks: Rohit for the report and Anushi for the patch.
---
 .../accounting/minilang/test/RateTests.xml         | 192 ---------------------
 .../org/apache/ofbiz/accounting/RateTests.groovy   | 126 +++++++++++++-
 2 files changed, 124 insertions(+), 194 deletions(-)

diff --git a/applications/accounting/minilang/test/RateTests.xml b/applications/accounting/minilang/test/RateTests.xml
deleted file mode 100644
index 7aa8b2b..0000000
--- a/applications/accounting/minilang/test/RateTests.xml
+++ /dev/null
@@ -1,192 +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="testUpdateRateAmount" short-description="test to update RateAmount" login-required="false">
-        <set field="serviceCtx.rateTypeId" value="OVERTIME"/>
-        <set field="serviceCtx.periodTypeId" value="RATE_HOUR"/>
-        <set field="serviceCtx.rateCurrencyUomId" value="USD"/>
-        <set field="serviceCtx.rateAmount" type="BigDecimal" value="25"/>
-        <set field="serviceCtx.emplPositionTypeId" value="TEST_EMPLOYEE"/>
-        <set field="serviceCtx.fromDate" type="Timestamp" value="2013-07-04 00:00:00"/>
-        <entity-one entity-name="UserLogin" value-field="userLogin">
-            <field-map field-name="userLoginId" value="system"/>
-        </entity-one>
-        <set field="serviceCtx.userLogin" from-field="userLogin"/>
-        <call-service service-name="updateRateAmount" in-map-name="serviceCtx"/>
-        <entity-one entity-name="RateAmount" value-field="rateAmount">
-            <field-map field-name="rateTypeId" value="OVERTIME"/>
-            <field-map field-name="workEffortId" value="_NA_"/>
-            <field-map field-name="rateCurrencyUomId" value="USD"/>
-            <field-map field-name="emplPositionTypeId" value="TEST_EMPLOYEE"/>
-            <field-map field-name="partyId" value="_NA_"/>
-            <field-map field-name="periodTypeId" value="RATE_HOUR"/>
-            <field-map field-name="fromDate" value="2013-07-04 00:00:00"/>
-        </entity-one>
-        <assert>
-            <not><if-empty field="rateAmount"/></not>
-            <if-compare field="rateAmount.rateAmount" operator="equals" value="25"/>
-        </assert>
-        <check-errors/>
-    </simple-method>
-    <simple-method method-name="testExpireRateAmount" short-description="test to expire RateAmount" login-required="false">
-        <set field="serviceCtx.rateTypeId" value="AVERAGE_PAY_RATE"/>
-        <set field="serviceCtx.emplPositionTypeId" value="TEST_EMPLOYEE"/>
-        <set field="serviceCtx.periodTypeId" value="RATE_MONTH"/>
-        <set field="serviceCtx.fromDate" type="Timestamp" value="2013-07-04 00:00:00"/>
-        <entity-one entity-name="UserLogin" value-field="userLogin">
-            <field-map field-name="userLoginId" value="system"/>
-        </entity-one>
-        <set field="serviceCtx.userLogin" from-field="userLogin"/>
-        <call-service service-name="expireRateAmount" in-map-name="serviceCtx"/>
-        <entity-one entity-name="RateAmount" value-field="rateAmount">
-            <field-map field-name="rateTypeId" value="AVERAGE_PAY_RATE"/>
-            <field-map field-name="workEffortId" value="_NA_"/>
-            <field-map field-name="rateCurrencyUomId" value="USD"/>
-            <field-map field-name="emplPositionTypeId" value="TEST_EMPLOYEE"/>
-            <field-map field-name="partyId" value="_NA_"/>
-            <field-map field-name="periodTypeId" value="RATE_MONTH"/>
-            <field-map field-name="fromDate" value="2013-07-04 00:00:00"/>
-        </entity-one>
-        <assert>
-            <not><if-empty field="rateAmount"/></not>
-            <not><if-empty field="rateAmount.thruDate"/></not>
-        </assert>
-        <check-errors/>
-    </simple-method>
-    <simple-method method-name="testGetRateAmount" short-description="test to get Rates Amounts" login-required="false">
-        <set field="serviceCtx.workEffortId" value="Test_effort"/>
-        <set field="serviceCtx.rateTypeId" value="AVERAGE_PAY_RATE"/>
-        <entity-one entity-name="UserLogin" value-field="userLogin">
-            <field-map field-name="userLoginId" value="system"/>
-        </entity-one>
-        <set field="serviceCtx.userLogin" from-field="userLogin"/>
-        <call-service service-name="getRateAmount" in-map-name="serviceCtx">
-            <result-to-field result-name="rateAmount"/>
-        </call-service>
-        <assert>
-            <if-compare field="rateAmount" operator="equals" value="75"/>
-        </assert>
-        <check-errors/>
-    </simple-method>
-    <simple-method method-name="testGetRatesAmountsFromWorkEffortId" short-description="test to get Rates Amounts From WorkEffortId" login-required="false">
-        <set field="serviceCtx.periodTypeId" value="RATE_HOUR"/>
-        <set field="serviceCtx.rateCurrencyUomId" value="USD"/>
-        <set field="serviceCtx.rateTypeId" value="AVERAGE_PAY_RATE"/>
-        <set field="serviceCtx.workEffortId" value="Test_effort"/>
-        <entity-one entity-name="UserLogin" value-field="userLogin">
-            <field-map field-name="userLoginId" value="system"/>
-        </entity-one>
-        <set field="serviceCtx.userLogin" from-field="userLogin"/>
-        <call-service service-name="getRatesAmountsFromWorkEffortId" in-map-name="serviceCtx">
-            <result-to-field result-name="ratesList"/>
-        </call-service>
-        <assert>
-            <not><if-empty field="ratesList"/></not>
-        </assert>
-        <check-errors/>
-    </simple-method>
-    <simple-method method-name="testGetRatesAmountsFromPartyId" short-description="test to get Rates Amounts From partyId" login-required="false">
-        <set field="serviceCtx.periodTypeId" value="RATE_HOUR"/>
-        <set field="serviceCtx.rateCurrencyUomId" value="USD"/>
-        <set field="serviceCtx.rateTypeId" value="AVERAGE_PAY_RATE"/>
-        <set field="serviceCtx.partyId" value="TEST_PARTY"/>
-        <entity-one entity-name="UserLogin" value-field="userLogin">
-            <field-map field-name="userLoginId" value="system"/>
-        </entity-one>
-        <set field="serviceCtx.userLogin" from-field="userLogin"/>
-        <call-service service-name="getRatesAmountsFromPartyId" in-map-name="serviceCtx">
-            <result-to-field result-name="ratesList"/>
-        </call-service>
-        <assert>
-            <not><if-empty field="ratesList"/></not>
-        </assert>
-        <check-errors/>
-    </simple-method>
-    <simple-method method-name="testGetRatesAmountsFromEmplPositionTypeId" short-description="test to get Rates Amounts From EmplPositionTypeId" login-required="false">
-        <set field="serviceCtx.periodTypeId" value="RATE_HOUR"/>
-        <set field="serviceCtx.rateCurrencyUomId" value="USD"/>
-        <set field="serviceCtx.rateTypeId" value="AVERAGE_PAY_RATE"/>
-        <set field="serviceCtx.emplPositionTypeId" value="TEST_EMPLOYEE"/>
-        <entity-one entity-name="UserLogin" value-field="userLogin">
-            <field-map field-name="userLoginId" value="system"/>
-        </entity-one>
-        <set field="serviceCtx.userLogin" from-field="userLogin"/>
-        <call-service service-name="getRatesAmountsFromEmplPositionTypeId" in-map-name="serviceCtx">
-            <result-to-field result-name="ratesList"/>
-        </call-service>
-        <assert>
-            <not><if-empty field="ratesList"/></not>
-        </assert>
-        <check-errors/>
-    </simple-method>
-    <simple-method method-name="testUpdatePartyRate" short-description="test to update PartyRate" login-required="false">
-        <set field="serviceCtx.partyId" value="TEST_PARTY"/>
-        <set field="serviceCtx.periodTypeId" value="RATE_MONTH"/>
-        <set field="serviceCtx.rateTypeId" value="DISCOUNTED"/>
-        <set field="serviceCtx.rateAmount" type="BigDecimal" value="75"/>
-        <set field="serviceCtx.fromDate" type="Timestamp" value="2013-07-04 00:00:00"/>
-        <entity-one entity-name="UserLogin" value-field="userLogin">
-            <field-map field-name="userLoginId" value="system"/>
-        </entity-one>
-        <set field="serviceCtx.userLogin" from-field="userLogin"/>
-        <call-service service-name="updatePartyRate" in-map-name="serviceCtx"/>
-        <entity-one entity-name="RateAmount" value-field="rateAmount">
-            <field-map field-name="rateTypeId" value="DISCOUNTED"/>
-            <field-map field-name="workEffortId" value="_NA_"/>
-            <field-map field-name="rateCurrencyUomId" value="USD"/>
-            <field-map field-name="emplPositionTypeId" value="_NA_"/>
-            <field-map field-name="partyId" value="TEST_PARTY"/>
-            <field-map field-name="periodTypeId" value="RATE_MONTH"/>
-            <field-map field-name="fromDate" value="2013-07-04 00:00:00"/>
-        </entity-one>
-        <entity-one entity-name="PartyRate" value-field="partyRate">
-            <field-map field-name="rateTypeId" value="DISCOUNTED"/>
-            <field-map field-name="partyId" value="TEST_PARTY"/>
-            <field-map field-name="fromDate" value="2013-07-04 00:00:00"/>
-        </entity-one>
-        <assert>
-            <not><if-empty field="rateAmount"/></not>
-            <not><if-empty field="partyRate"/></not>
-            <if-compare field="rateAmount.rateAmount" operator="equals" value="75"/>
-        </assert>
-        <check-errors/>
-    </simple-method>
-    <simple-method method-name="testFilterRateAmountList" short-description="test the service filterRateAmountList" login-required="false">
-        <entity-and entity-name="RateAmount" list="amountList">
-            <field-map field-name="rateTypeId" value="AVERAGE_PAY_RATE"/>
-            <field-map field-name="rateCurrencyUomId" value="USD"/>
-        </entity-and>
-        <set field="serviceCtx.ratesList" from-field="amountList" type="List"/>
-        <set field="serviceCtx.rateTypeId" value="AVERAGE_PAY_RATE"/>
-        <entity-one entity-name="UserLogin" value-field="userLogin">
-            <field-map field-name="userLoginId" value="system"/>
-        </entity-one>
-        <set field="serviceCtx.userLogin" from-field="userLogin"/>
-        <call-service service-name="filterRateAmountList" in-map-name="serviceCtx">
-            <result-to-field result-name="filteredRatesList"/>
-        </call-service>
-        <assert>
-            <not><if-empty field="filteredRatesList"/></not>
-        </assert>
-        <check-errors/>
-    </simple-method>
-</simple-methods>
diff --git a/applications/accounting/src/main/groovy/org/apache/ofbiz/accounting/RateTests.groovy b/applications/accounting/src/main/groovy/org/apache/ofbiz/accounting/RateTests.groovy
index ce1d3fd..534bb74 100644
--- a/applications/accounting/src/main/groovy/org/apache/ofbiz/accounting/RateTests.groovy
+++ b/applications/accounting/src/main/groovy/org/apache/ofbiz/accounting/RateTests.groovy
@@ -4,7 +4,7 @@
  * 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
+ * "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
@@ -44,7 +44,129 @@ class RateTests extends OFBizTestCase {
         assert ServiceUtil.isSuccess(serviceResult)
 
         GenericValue partyRate = from("PartyRate").where("rateTypeId", "AVERAGE_PAY_RATE", "partyId", "TEST_PARTY", "fromDate", fromDate).queryOne()
-        assert partyRate;
+        assert partyRate
         assert partyRate.thruDate
     }
+
+    void testUpdateRateAmount() {
+        Timestamp fromDate = UtilDateTime.toTimestamp("04/07/2013 00:00:00")
+        Map serviceCtx = [
+                periodTypeId   : "RATE_HOUR",
+                rateTypeId          : 'OVERTIME',
+                rateCurrencyUomId   : "USD",
+                rateAmount          :  BigDecimal.valueOf(25),
+                emplPositionTypeId  : "TEST_EMPLOYEE",
+                fromDate            :  fromDate,
+                userLogin              : userLogin
+        ]
+        Map serviceResult = dispatcher.runSync('updateRateAmount', serviceCtx)
+        assert ServiceUtil.isSuccess(serviceResult)
+
+        GenericValue rateAmount = from("RateAmount").where("rateTypeId", "OVERTIME", "workEffortId", "_NA_", "rateCurrencyUomId", "USD", "emplPositionTypeId", "TEST_EMPLOYEE", "partyId", "_NA_", "periodTypeId", "RATE_HOUR", "fromDate", fromDate).queryOne()
+        assert rateAmount
+        assert rateAmount.rateAmount == 25
+    }
+
+    void testGetRateAmount() {
+        Map serviceCtx = [
+                rateTypeId            : 'AVERAGE_PAY_RATE',
+                workEffortId          : 'Test_effort',
+                userLogin              : userLogin
+        ]
+        Map serviceResult = dispatcher.runSync('getRateAmount', serviceCtx)
+        assert ServiceUtil.isSuccess(serviceResult)
+        assert serviceResult.rateAmount == 75
+    }
+
+    void testGetRatesAmountsFromWorkEffortId() {
+        Map serviceCtx = [
+                periodTypeId           : 'RATE_HOUR',
+                rateCurrencyUomId     : 'USD',
+                rateTypeId            : 'AVERAGE_PAY_RATE',
+                workEffortId          : 'Test_effort',
+                userLogin              : userLogin
+        ]
+        Map serviceResult = dispatcher.runSync('getRatesAmountsFromWorkEffortId', serviceCtx)
+        assert ServiceUtil.isSuccess(serviceResult)
+        assert serviceResult.ratesList
+    }
+
+    void testGetRatesAmountsFromPartyId() {
+        Map serviceCtx = [
+                periodTypeId    : 'RATE_HOUR',
+                rateCurrencyUomId   : 'USD',
+                rateTypeId          : 'AVERAGE_PAY_RATE',
+                partyId          : 'TEST_PARTY',
+                userLogin              : userLogin
+        ]
+        Map serviceResult = dispatcher.runSync('getRatesAmountsFromPartyId', serviceCtx)
+        assert ServiceUtil.isSuccess(serviceResult)
+        assert serviceResult.ratesList != null
+    }
+
+    void testGetRatesAmountsFromEmplPositionTypeId() {
+        Map serviceCtx = [
+                periodTypeId    : 'RATE_HOUR',
+                rateCurrencyUomId   : 'USD',
+                rateTypeId          : 'AVERAGE_PAY_RATE',
+                emplPositionTypeId          : 'TEST_EMPLOYEE',
+                userLogin              : userLogin
+        ]
+        Map serviceResult = dispatcher.runSync('getRatesAmountsFromEmplPositionTypeId', serviceCtx)
+        assert ServiceUtil.isSuccess(serviceResult)
+        assert serviceResult.ratesList
+    }
+
+    void testUpdatePartyRate() {
+        Timestamp fromDate = UtilDateTime.toTimestamp("04/07/2013 00:00:00")
+        Map serviceCtx = [
+                partyId     : "TEST_PARTY",
+                periodTypeId   : "RATE_MONTH",
+                rateTypeId          : 'DISCOUNTED',
+                rateAmount          :  BigDecimal.valueOf(75),
+                fromDate            :  fromDate,
+                userLogin              : userLogin
+
+        ]
+        Map serviceResult = dispatcher.runSync('updatePartyRate', serviceCtx)
+        assert ServiceUtil.isSuccess(serviceResult)
+
+        GenericValue rateAmount = from("RateAmount").where("rateTypeId", "DISCOUNTED", "workEffortId", "_NA_", "rateCurrencyUomId", "USD", "emplPositionTypeId", "_NA_", "partyId", "TEST_PARTY", "periodTypeId", "RATE_MONTH", "fromDate", fromDate).queryOne()
+        GenericValue partyRate = from("PartyRate").where("rateTypeId", "DISCOUNTED", "partyId", "TEST_PARTY", "fromDate", fromDate).queryOne()
+
+        assert rateAmount
+        assert partyRate
+        assert rateAmount.rateAmount == 75
+    }
+
+    void testFilterRateAmountList() {
+        List<GenericValue> amountList = from("RateAmount").where("rateTypeId", "AVERAGE_PAY_RATE", "rateCurrencyUomId", "USD").queryList()
+        Map serviceCtx = [
+                ratesList   : amountList,
+                rateTypeId          : 'AVERAGE_PAY_RATE',
+                userLogin              : userLogin
+        ]
+        Map serviceResult = dispatcher.runSync('filterRateAmountList', serviceCtx)
+        assert ServiceUtil.isSuccess(serviceResult)
+        assert serviceResult.filteredRatesList
+    }
+
+    void testExpireRateAmount() {
+        Timestamp fromDate = UtilDateTime.toTimestamp("07/04/2013 00:00:00")
+        Map serviceCtx = [
+                emplPositionTypeId   : 'TEST_EMPLOYEE',
+                rateTypeId          : 'AVERAGE_PAY_RATE',
+                periodTypeId   : 'RATE_MONTH',
+                fromDate            :  fromDate,
+                userLogin              : userLogin
+
+        ]
+        Map serviceResult = dispatcher.runSync('expireRateAmount', serviceCtx)
+        assert ServiceUtil.isSuccess(serviceResult)
+
+        GenericValue rateAmount = from("RateAmount").where("rateTypeId", "AVERAGE_PAY_RATE", "workEffortId", "_NA_", "rateCurrencyUomId", "USD", "emplPositionTypeId", "TEST_EMPLOYEE", "partyId", "_NA_", "periodTypeId", "RATE_MONTH", "fromDate", fromDate).queryOne()
+        assert rateAmount
+        assert rateAmount.thruDate
+    }
+
 }
\ No newline at end of file