[ofbiz-framework] branch trunk updated: Improved: Converted assertInvoiceTotal, testInvoiceAppl and testToPayment tests from XML to Groovy. (OFBIZ-11530)(OFBIZ-11557)(OFBIZ-11559)

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 assertInvoiceTotal, testInvoiceAppl and testToPayment tests from XML to Groovy. (OFBIZ-11530)(OFBIZ-11557)(OFBIZ-11559)

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 6d7c953  Improved: Converted assertInvoiceTotal, testInvoiceAppl and testToPayment tests from XML to Groovy. (OFBIZ-11530)(OFBIZ-11557)(OFBIZ-11559)
6d7c953 is described below

commit 6d7c953e5f371f2a9f9312e07aedd74bbcf65d66
Author: Pawan Verma <[hidden email]>
AuthorDate: Sun Jun 14 14:17:44 2020 +0530

    Improved: Converted assertInvoiceTotal, testInvoiceAppl and testToPayment tests from XML to Groovy.
    (OFBIZ-11530)(OFBIZ-11557)(OFBIZ-11559)
   
    Thanks, Rohit for the contribution and Jacques for the review.
---
 .../accounting/minilang/test/AutoInvoiceTests.xml  | 87 -------------------
 .../minilang/test/PaymentApplicationTests.xml      | 97 ----------------------
 .../ofbiz/accounting/AutoInvoiceTests.groovy       | 92 ++++++++++++++++++++
 .../accounting/PaymentApplicationTests.groovy      | 93 +++++++++++++++++++++
 applications/accounting/testdef/invoicetests.xml   |  5 +-
 .../accounting/testdef/paymentappltests.xml        |  7 +-
 6 files changed, 192 insertions(+), 189 deletions(-)

diff --git a/applications/accounting/minilang/test/AutoInvoiceTests.xml b/applications/accounting/minilang/test/AutoInvoiceTests.xml
index 7b6b21d..833d11c 100644
--- a/applications/accounting/minilang/test/AutoInvoiceTests.xml
+++ b/applications/accounting/minilang/test/AutoInvoiceTests.xml
@@ -21,93 +21,6 @@ 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="testInvoiceWorkerGetInvoiceTotal" login-required="false"
-        short-description="Tests InvoiceWorker.getInvoiceTotal(GenericValue) for all demo invoices">
-        <set field="invoiceId" value="demo10000"/>
-        <set field="amount" value="323.54" type="BigDecimal"/>
-        <call-simple-method method-name="assertInvoiceTotal"/>
-
-        <set field="invoiceId" value="demo10001"/>
-        <set field="amount" value="36.43" type="BigDecimal"/>
-        <call-simple-method method-name="assertInvoiceTotal"/>
-
-        <set field="invoiceId" value="demo10002"/>
-        <set field="amount" value="56.99" type="BigDecimal"/>
-        <call-simple-method method-name="assertInvoiceTotal"/>
-
-        <set field="invoiceId" value="demo11000"/>
-        <set field="amount" value="20" type="BigDecimal"/>
-        <call-simple-method method-name="assertInvoiceTotal"/>
-
-        <set field="invoiceId" value="demo11001"/>
-        <set field="amount" value="543.23" type="BigDecimal"/>
-        <call-simple-method method-name="assertInvoiceTotal"/>
-
-        <set field="invoiceId" value="demo1200"/>
-        <set field="amount" value="511.23" type="BigDecimal"/>
-        <call-simple-method method-name="assertInvoiceTotal"/>
-
-        <set field="invoiceId" value="8000"/>
-        <set field="amount" value="60" type="BigDecimal"/>
-        <call-simple-method method-name="assertInvoiceTotal"/>
-
-        <set field="invoiceId" value="8001"/>
-        <set field="amount" value="10" type="BigDecimal"/>
-        <call-simple-method method-name="assertInvoiceTotal"/>
-
-        <set field="invoiceId" value="8002"/>
-        <set field="amount" value="36.43" type="BigDecimal"/>
-        <call-simple-method method-name="assertInvoiceTotal"/>
-
-        <set field="invoiceId" value="8003"/>
-        <set field="amount" value="46.43" type="BigDecimal"/>
-        <call-simple-method method-name="assertInvoiceTotal"/>
-
-        <set field="invoiceId" value="8004"/>
-        <set field="amount" value="33.99" type="BigDecimal"/>
-        <call-simple-method method-name="assertInvoiceTotal"/>
-
-        <set field="invoiceId" value="8100"/>
-        <set field="amount" value="1320" type="BigDecimal"/>
-        <call-simple-method method-name="assertInvoiceTotal"/>
-
-        <set field="invoiceId" value="8005"/>
-        <set field="amount" value="33.99" type="BigDecimal"/>
-        <call-simple-method method-name="assertInvoiceTotal"/>
-
-        <set field="invoiceId" value="8006"/>
-        <set field="amount" value="46.43" type="BigDecimal"/>
-        <call-simple-method method-name="assertInvoiceTotal"/>
-
-        <set field="invoiceId" value="8007"/>
-        <set field="amount" value="36.43" type="BigDecimal"/>
-        <call-simple-method method-name="assertInvoiceTotal"/>
-
-        <set field="invoiceId" value="8008"/>
-        <set field="amount" value="48" type="BigDecimal"/>
-        <call-simple-method method-name="assertInvoiceTotal"/>
-
-        <set field="invoiceId" value="8009"/>
-        <set field="amount" value="127.09" type="BigDecimal"/>
-        <call-simple-method method-name="assertInvoiceTotal"/>
-
-        <set field="invoiceId" value="8010"/>
-        <set field="amount" value="179.97" type="BigDecimal"/>
-        <call-simple-method method-name="assertInvoiceTotal"/>
-
-        <check-errors/>
-    </simple-method>
-    <simple-method method-name="assertInvoiceTotal" login-required="false"
-    short-description="Inline method to assist testInvoiceWorkerGetInvoiceTotal">
-        <entity-one entity-name="Invoice" value-field="invoice">
-            <field-map field-name="invoiceId"/>
-        </entity-one>
-        <call-class-method method-name="getInvoiceTotal" class-name="org.apache.ofbiz.accounting.invoice.InvoiceWorker" ret-field="invoiceTotal">
-            <field field="invoice" type="GenericValue"/>
-        </call-class-method>
-        <assert><if-compare-field field="invoiceTotal" operator="equals" to-field="amount" type="BigDecimal"/></assert>
-    </simple-method>
-
     <!-- Test case for Commission Run -->
     <simple-method method-name="testCommissionRun" short-description="Test case for Commission Run" login-required="false">
 
diff --git a/applications/accounting/minilang/test/PaymentApplicationTests.xml b/applications/accounting/minilang/test/PaymentApplicationTests.xml
index 833c33b..f44a555 100644
--- a/applications/accounting/minilang/test/PaymentApplicationTests.xml
+++ b/applications/accounting/minilang/test/PaymentApplicationTests.xml
@@ -21,55 +21,6 @@ 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">
 
-
-    <!-- most simple test both invoice and payment same amount same currency -->
-    <simple-method method-name="testInvoiceAppl" short-description="test the application of a payment against an invoice" login-required="false">
-
-        <!-- from the test data -->
-        <set field="serviceInMap.invoiceId" value="appltest10000"/>
-        <set field="serviceInMap.paymentId" value="appltest10000"/>
-
-        <entity-one entity-name="UserLogin" value-field="userLogin">
-            <field-map field-name="userLoginId" value="system"/>
-        </entity-one>
-        
-        <set field="serviceInMap.userLogin" from-field="userLogin"/>
-        <call-service service-name="createPaymentApplication" in-map-name="serviceInMap" include-user-login="false">
-            <result-to-field result-name="amountApplied"/>
-            <result-to-field result-name="paymentApplicationId"/>
-        </call-service>
-        <entity-one entity-name="PaymentApplication" value-field="paymentApplication">
-            <field-map field-name="paymentApplicationId" from-field="paymentApplicationId"/>
-        </entity-one>
-        <entity-one entity-name="Payment" value-field="payment">
-            <field-map field-name="paymentId" from-field="serviceInMap.paymentId"/>
-        </entity-one>
-        <assert>
-            <not><if-empty field="paymentApplication"/></not>
-            <if-compare-field field="paymentApplication.invoiceId" operator="equals" to-field="serviceInMap.invoiceId"/>
-            <if-compare-field field="paymentApplication.paymentId" operator="equals" to-field="serviceInMap.paymentId"/>
-            <if-compare-field field="paymentApplication.amountApplied" operator="equals" to-field="payment.amount"/>
-        </assert>
-        <check-errors/>
-        <!-- both payment and invoice should be completely applied -->
-        <call-class-method method-name="getPaymentNotApplied" class-name="org.apache.ofbiz.accounting.payment.PaymentWorker" ret-field="notAppliedPayment">
-            <field field="delegator" type="org.apache.ofbiz.entity.Delegator"/>
-            <field field="serviceInMap.paymentId"/>
-        </call-class-method>
-        <call-class-method method-name="getInvoiceNotApplied" class-name="org.apache.ofbiz.accounting.invoice.InvoiceWorker" ret-field="notAppliedInvoice">
-            <field field="delegator" type="org.apache.ofbiz.entity.Delegator"/>
-            <field field="serviceInMap.invoiceId"/>
-        </call-class-method>
-        <set field="zero" value="0" type="BigDecimal"/>
-        <assert>
-            <if-compare-field operator="equals" field="notAppliedPayment" to-field="zero"/>                        
-            <if-compare-field operator="equals" field="notAppliedInvoice" to-field="zero"/>                        
-        </assert>
-        <check-errors/>
-        <remove-value value-field="paymentApplication"/>
-    </simple-method>
-
-
     <simple-method method-name="testBillingAppl" short-description="test the application of a payment against an billing account" login-required="false">
         <!-- from the test data -->
         <set field="serviceInMap.paymentId" value="appltest10000"/>
@@ -121,54 +72,6 @@ under the License.
         <remove-value value-field="paymentApplication"/>
     </simple-method>
 
-    <simple-method method-name="testToPayment" short-description="test the application of a payment against anotherpayment" login-required="false">
-        <!-- from the test data -->
-        <set field="serviceInMap.paymentId" value="appltest10000"/>
-        <set field="serviceInMap.toPaymentId" value="appltest10001"/>
-
-        <entity-one entity-name="UserLogin" value-field="userLogin">
-            <field-map field-name="userLoginId" value="system"/>
-        </entity-one>
-        
-        <set field="serviceInMap.userLogin" from-field="userLogin"/>
-        <call-service service-name="createPaymentApplication" in-map-name="serviceInMap" include-user-login="false">
-            <result-to-field result-name="amountApplied"/>
-            <result-to-field result-name="paymentApplicationId"/>
-        </call-service>
-        <entity-one entity-name="PaymentApplication" value-field="paymentApplication">
-            <field-map field-name="paymentApplicationId" from-field="paymentApplicationId"/>
-        </entity-one>
-        <call-class-method method-name="getPaymentNotApplied" class-name="org.apache.ofbiz.accounting.payment.PaymentWorker" ret-field="notAppliedPayment">
-            <field field="delegator" type="org.apache.ofbiz.entity.Delegator"/>
-            <field field="serviceInMap.paymentId"/>
-        </call-class-method>
-        <entity-one entity-name="Payment" value-field="payment">
-            <field-map field-name="paymentId" from-field="serviceInMap.paymentId"/>
-        </entity-one>
-        <assert>
-            <not><if-empty field="paymentApplication"/></not>
-            <if-compare-field field="paymentApplication.toPaymentId" operator="equals" to-field="serviceInMap.toPaymentId"/>
-            <if-compare-field field="paymentApplication.paymentId" operator="equals" to-field="serviceInMap.paymentId"/>
-            <if-compare-field field="paymentApplication.amountApplied" operator="equals" to-field="payment.amount"/>
-        </assert>
-        <check-errors/>
-        <!-- both payment and invoice should be completely applied -->
-        <call-class-method method-name="getPaymentNotApplied" class-name="org.apache.ofbiz.accounting.payment.PaymentWorker" ret-field="notAppliedPayment">
-            <field field="delegator" type="org.apache.ofbiz.entity.Delegator"/>
-            <field field="serviceInMap.paymentId"/>
-        </call-class-method>
-        <call-class-method method-name="getPaymentNotApplied" class-name="org.apache.ofbiz.accounting.payment.PaymentWorker" ret-field="notAppliedToPayment">
-            <field field="delegator" type="org.apache.ofbiz.entity.Delegator"/>
-            <field field="serviceInMap.toPaymentId"/>
-        </call-class-method>
-        <set field="zero" value="0" type="BigDecimal"/>
-        <assert>
-            <if-compare-field operator="equals" field="notAppliedPayment" to-field="zero"/>                        
-            <if-compare-field operator="equals" field="notAppliedToPayment" to-field="zero"/>                        
-        </assert>
-        <check-errors/>
-        <remove-value value-field="paymentApplication"/>
-    </simple-method>
     <simple-method method-name="testTaxGeoId" short-description="test the application of a payment against a tax geo id" login-required="false">
         <!-- from the test data -->
         <set field="serviceInMap.paymentId" value="appltest10000"/>
diff --git a/applications/accounting/src/main/groovy/org/apache/ofbiz/accounting/AutoInvoiceTests.groovy b/applications/accounting/src/main/groovy/org/apache/ofbiz/accounting/AutoInvoiceTests.groovy
new file mode 100644
index 0000000..bf62549
--- /dev/null
+++ b/applications/accounting/src/main/groovy/org/apache/ofbiz/accounting/AutoInvoiceTests.groovy
@@ -0,0 +1,92 @@
+package org.apache.ofbiz.accounting;
+
+import org.apache.ofbiz.entity.GenericValue
+import org.apache.ofbiz.entity.util.EntityQuery
+import org.apache.ofbiz.service.testtools.OFBizTestCase
+import org.apache.ofbiz.accounting.invoice.InvoiceWorker
+
+class AutoInvoiceTests extends OFBizTestCase {
+    public AutoInvoiceTests(String name) {
+        super(name)
+    }
+    void testInvoiceWorkerGetInvoiceTotal(){
+
+        String invoiceId="demo10000"
+        BigDecimal amount = new BigDecimal('323.54')
+        assertInvoiceTotal(invoiceId, amount)
+
+        invoiceId="demo10001"
+        amount = new BigDecimal('36.43')
+        assertInvoiceTotal(invoiceId, amount)
+
+        invoiceId="demo10002"
+        amount = new BigDecimal('56.99')
+        assertInvoiceTotal(invoiceId, amount)
+
+        invoiceId="demo11000"
+        amount = new BigDecimal('20.00')
+        assertInvoiceTotal(invoiceId, amount)
+
+        invoiceId="demo11001"
+        amount = new BigDecimal('543.23')
+        assertInvoiceTotal(invoiceId, amount)
+
+        invoiceId="demo1200"
+        amount = new BigDecimal('511.23')
+        assertInvoiceTotal(invoiceId, amount)
+
+        invoiceId="8000"
+        amount = new BigDecimal('60.00')
+        assertInvoiceTotal(invoiceId, amount)
+
+        invoiceId="8001"
+        amount = new BigDecimal('10.00')
+        assertInvoiceTotal(invoiceId, amount)
+
+        invoiceId="8002"
+        amount = new BigDecimal('36.43')
+        assertInvoiceTotal(invoiceId, amount)
+
+        invoiceId="8003"
+        amount = new BigDecimal('46.43')
+        assertInvoiceTotal(invoiceId, amount)
+
+        invoiceId="8004"
+        amount = new BigDecimal('33.99')
+        assertInvoiceTotal(invoiceId, amount)
+
+        invoiceId="8100"
+        amount = new BigDecimal('1320.00')
+        assertInvoiceTotal(invoiceId, amount)
+
+        invoiceId="8005"
+        amount = new BigDecimal('33.99')
+        assertInvoiceTotal(invoiceId, amount)
+
+        invoiceId="8006"
+        amount = new BigDecimal('46.43')
+        assertInvoiceTotal(invoiceId, amount)
+
+        invoiceId="8007"
+        amount = new BigDecimal('36.43')
+        assertInvoiceTotal(invoiceId, amount)
+
+        invoiceId="8008"
+        amount = new BigDecimal('48.00')
+        assertInvoiceTotal(invoiceId, amount)
+
+        invoiceId="8009"
+        amount = new BigDecimal('127.09')
+        assertInvoiceTotal(invoiceId, amount)
+
+        invoiceId="8010"
+        amount = new BigDecimal('179.97')
+        assertInvoiceTotal(invoiceId, amount)
+    }
+
+    void assertInvoiceTotal(String invoiceId, BigDecimal amount){
+        GenericValue invoice =  EntityQuery.use(delegator).from('Invoice').where('invoiceId', invoiceId).queryOne()
+        BigDecimal invoiceTotal = InvoiceWorker.getInvoiceTotal(invoice)
+        assert  invoiceTotal == amount
+    }
+}
\ No newline at end of file
diff --git a/applications/accounting/src/main/groovy/org/apache/ofbiz/accounting/PaymentApplicationTests.groovy b/applications/accounting/src/main/groovy/org/apache/ofbiz/accounting/PaymentApplicationTests.groovy
new file mode 100644
index 0000000..874f3f6
--- /dev/null
+++ b/applications/accounting/src/main/groovy/org/apache/ofbiz/accounting/PaymentApplicationTests.groovy
@@ -0,0 +1,93 @@
+/*
+ * 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.accounting
+
+import org.apache.ofbiz.entity.GenericValue
+import org.apache.ofbiz.entity.util.EntityQuery
+import org.apache.ofbiz.service.ServiceUtil
+import org.apache.ofbiz.service.testtools.OFBizTestCase
+import org.apache.ofbiz.accounting.invoice.InvoiceWorker
+import org.apache.ofbiz.accounting.payment.PaymentWorker
+
+class PaymentApplicationTests extends OFBizTestCase {
+    
+    public PaymentApplicationTests(String name) {
+        super(name)
+    }
+
+    void testInvoiceAppl() {
+        Map serviceInMap = [:]
+        //from the test data
+        serviceInMap.invoiceId = "appltest10000"
+        serviceInMap.paymentId = "appltest10000"
+        serviceInMap.userLogin = userLogin
+        Map serviceResult = dispatcher.runSync('createPaymentApplication', serviceInMap)
+        assert ServiceUtil.isSuccess(serviceResult)
+
+        GenericValue paymentApplication = from('PaymentApplication')
+                .where('paymentApplicationId', serviceResult.paymentApplicationId).queryOne()
+        assert paymentApplication
+
+        GenericValue payment = from('Payment').where('paymentId', serviceInMap.paymentId).queryOne()
+        assert payment
+
+        assert paymentApplication != null
+        assert paymentApplication.invoiceId == serviceInMap.invoiceId
+        assert paymentApplication.paymentId == serviceInMap.paymentId
+        assert paymentApplication.amountApplied == payment.amount
+        // both payment and invoice should be completely applied
+        BigDecimal notAppliedPayment = PaymentWorker.getPaymentNotApplied(delegator, serviceInMap.paymentId)
+        BigDecimal notAppliedInvoice = InvoiceWorker.getInvoiceNotApplied(delegator, serviceInMap.invoiceId)
+
+        assert notAppliedPayment == BigDecimal.ZERO
+        assert notAppliedInvoice == BigDecimal.ZERO
+        delegator.removeAll('PaymentApplication')
+    }
+
+    void testToPayment() {
+        Map serviceInMap = [:]
+        serviceInMap.paymentId = "appltest10000"
+        serviceInMap.toPaymentId = "appltest10001"
+        serviceInMap.userLogin = userLogin
+        Map serviceResult = dispatcher.runSync('createPaymentApplication', serviceInMap)
+        assert ServiceUtil.isSuccess(serviceResult)
+
+        GenericValue paymentApplication = from('PaymentApplication')
+                                            .where('paymentApplicationId', serviceResult.paymentApplicationId).queryOne()
+        assert paymentApplication
+
+        BigDecimal notAppliedPayment = PaymentWorker.getPaymentNotApplied(delegator, serviceInMap.paymentId)
+
+        GenericValue payment = from('Payment').where('paymentId', serviceInMap.paymentId).queryOne()
+        assert payment
+
+        assert paymentApplication != null
+        assert paymentApplication.toPaymentId == serviceInMap.toPaymentId
+        assert paymentApplication.paymentId == serviceInMap.paymentId
+        assert paymentApplication.amountApplied == payment.amount
+
+        notAppliedPayment = PaymentWorker.getPaymentNotApplied(delegator, serviceInMap.paymentId)
+        BigDecimal notAppliedToPayment = PaymentWorker.getPaymentNotApplied(delegator, serviceInMap.toPaymentId)
+
+        assert notAppliedPayment == BigDecimal.ZERO
+        assert notAppliedToPayment == BigDecimal.ZERO
+        delegator.removeAll('PaymentApplication')
+    }
+}
diff --git a/applications/accounting/testdef/invoicetests.xml b/applications/accounting/testdef/invoicetests.xml
index 39c3723..09d2e5f 100644
--- a/applications/accounting/testdef/invoicetests.xml
+++ b/applications/accounting/testdef/invoicetests.xml
@@ -22,9 +22,10 @@
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/test-suite.xsd">
 
-    <test-case case-name="auto-invoice-tests">
+    <test-group case-name="auto-invoice-tests">
         <simple-method-test location="component://accounting/minilang/test/AutoInvoiceTests.xml"/>
-    </test-case>
+        <junit-test-suite class-name="org.apache.ofbiz.accounting.AutoInvoiceTests"/>
+    </test-group>
     <test-case case-name="invoice-per-shipment-tests">
         <simple-method-test location="component://accounting/minilang/test/InvoicePerShipmentTests.xml"/>
     </test-case>
diff --git a/applications/accounting/testdef/paymentappltests.xml b/applications/accounting/testdef/paymentappltests.xml
index 434c245..f8ab446 100644
--- a/applications/accounting/testdef/paymentappltests.xml
+++ b/applications/accounting/testdef/paymentappltests.xml
@@ -25,8 +25,9 @@
     <test-case case-name="application-tests-data-load">
         <entity-xml action="load" entity-xml-url="component://accounting/testdef/data/PaymentApplicationTestsData.xml"/>
     </test-case>
-    <test-case case-name="application-tests">
+    <test-group case-name="application-tests">
         <simple-method-test location="component://accounting/minilang/test/PaymentApplicationTests.xml"/>
-    </test-case>
-    
+        <junit-test-suite class-name="org.apache.ofbiz.accounting.PaymentApplicationTests"/>
+    </test-group>
+
 </test-suite>