You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by pa...@apache.org on 2020/04/25 06:55:29 UTC

[ofbiz-framework] branch trunk updated: Improved: Convert AutoAcctgFinAccountTests from XML to Groovy. (#68)

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 a74480e  Improved: Convert AutoAcctgFinAccountTests from XML to Groovy. (#68)
a74480e is described below

commit a74480ec5a53f2b7033281f1a6129805a99a0631
Author: Pawan Verma <ve...@users.noreply.github.com>
AuthorDate: Sat Apr 25 12:25:22 2020 +0530

    Improved: Convert AutoAcctgFinAccountTests from XML to Groovy. (#68)
    
    (OFBIZ-11507)(OFBIZ-11508)(OFBIZ-11509)(OFBIZ-11510)(OFBIZ-11511)(OFBIZ-11512)(OFBIZ-11513)(OFBIZ-11514)(OFBIZ-11515)(OFBIZ-11516)
    
    Thanks: Rohit Hukkeri for the report
---
 .../minilang/test/AutoAcctgFinAccountTests.xml     | 223 ---------------------
 .../accounting/AutoAcctgFinAccountTests.groovy     | 199 ++++++++++++++++++
 .../accounting/testdef/accountingtests.xml         |   2 +-
 3 files changed, 200 insertions(+), 224 deletions(-)

diff --git a/applications/accounting/minilang/test/AutoAcctgFinAccountTests.xml b/applications/accounting/minilang/test/AutoAcctgFinAccountTests.xml
deleted file mode 100644
index b344f79..0000000
--- a/applications/accounting/minilang/test/AutoAcctgFinAccountTests.xml
+++ /dev/null
@@ -1,223 +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="testCreateFinAccount" short-description="Test case for service createFinAccount" login-required="false">
-        <set field="serviceCtx.finAccountId" value="1000"/>
-        <set field="serviceCtx.finAccountTypeId" value="BANK_ACCOUNT"/>
-        <set field="serviceCtx.finAccountName" value="Bank Account" />
-        <set field="serviceCtx.finAccountCode" value="1000"/>
-        <set field="serviceCtx.currencyUomId" value="USD"/>
-        <set field="serviceCtx.organizationPartyId" value="DEMO_COMPANY"/>
-        <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="createFinAccount" in-map-name="serviceCtx"/>
-        <entity-one entity-name="FinAccount" value-field="finAccount">
-            <field-map field-name="finAccountId" value="1000"/>
-        </entity-one>
-        <assert>
-            <not><if-empty field="finAccount"/></not>
-            <if-compare operator="equals" value="BANK_ACCOUNT" field="finAccount.finAccountTypeId"></if-compare>
-            <if-compare operator="equals" value="1000" field="finAccount.finAccountCode"></if-compare>
-        </assert>
-        <check-errors/>
-    </simple-method>
-    <simple-method method-name="testUpdateFinAccount" short-description="Test case for service updateFinAccount" login-required="false">
-        <set field="serviceCtx.finAccountId" value="1001"/>
-        <set field="serviceCtx.organizationPartyId" value="DEMO_COMPANY2"/>
-        <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="updateFinAccount" in-map-name="serviceCtx"/>
-        <entity-one entity-name="FinAccount" value-field="finAccount">
-            <field-map field-name="finAccountId" value="1001"/>
-        </entity-one>
-        <assert>
-            <not><if-empty field="finAccount"/></not>
-            <if-compare operator="equals" value="DEMO_COMPANY2" field="finAccount.organizationPartyId"></if-compare>
-        </assert>
-        <check-errors/>
-    </simple-method>
-    <simple-method method-name="testDeleteFinAccount" short-description="Test case for service deleteFinAccount" login-required="false">
-        <set field="serviceCtx.finAccountId" value="1002"/>
-        <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="deleteFinAccount" in-map-name="serviceCtx"/>
-        <entity-one entity-name="FinAccount" value-field="finAccount">
-            <field-map field-name="finAccountId" value="1002"/>
-        </entity-one>
-        <assert>
-            <if-empty field="finAccount"/>
-        </assert>
-        <check-errors/>
-    </simple-method>
-    <simple-method method-name="testCreateFinAccountRole" short-description="Test case for service createFinAccountRole" login-required="false">
-        <now-timestamp field="nowTimestamp"/>
-        <set field="serviceCtx.finAccountId" value="1003"/>
-        <set field="serviceCtx.partyId" value="DEMO_COMPANY"/>
-        <set field="serviceCtx.roleTypeId" value="INTERNAL_ORGANIZATIO"/>
-        <set field="serviceCtx.fromDate" from-field="nowTimestamp"/>
-        <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="createFinAccountRole" in-map-name="serviceCtx"/>
-        <entity-and list="finAccountRoles" entity-name="FinAccountRole">
-            <field-map field-name="finAccountId" value="1003"/>
-            <field-map field-name="partyId" value="DEMO_COMPANY"/>
-            <field-map field-name="roleTypeId" value="INTERNAL_ORGANIZATIO"/>
-        </entity-and>
-        <first-from-list entry="finAccountRole" list="finAccountRoles"/>
-        <assert>
-            <not><if-empty field="finAccountRole"/></not>
-        </assert>
-        <check-errors/>
-    </simple-method>
-    <simple-method method-name="testUpdateFinAccountRole" short-description="Test case for service updateFinAccountRole" login-required="false">
-        <now-timestamp field="nowTimestamp"/>
-        <set field="serviceCtx.finAccountId" value="1004"/>
-        <set field="serviceCtx.partyId" value="DEMO_COMPANY"/>
-        <set field="serviceCtx.roleTypeId" value="SUPPLIER"/>
-        <set field="serviceCtx.fromDate" value="2016-11-03 00:00:00" type="Timestamp"/>
-        <set field="serviceCtx.thruDate" from-field="nowTimestamp"/>
-        <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="updateFinAccountRole" in-map-name="serviceCtx"/>
-        <entity-and list="finAccountRoles" entity-name="FinAccountRole">
-            <field-map field-name="finAccountId" value="1004"/>
-            <field-map field-name="partyId" value="DEMO_COMPANY"/>
-            <field-map field-name="roleTypeId" value="SUPPLIER"/>
-        </entity-and>
-        <first-from-list entry="finAccountRole" list="finAccountRoles"/>
-        <assert>
-            <not><if-empty field="finAccountRole"/></not>
-            <not><if-empty field="finAccountRole.thruDate"/></not>
-        </assert>
-        <check-errors/>
-    </simple-method>
-    <simple-method method-name="testDeleteFinAccountRole" short-description="Test case for service deleteFinAccountRole" login-required="false">
-        <set field="serviceCtx.finAccountId" value="1004"/>
-        <set field="serviceCtx.partyId" value="DEMO_COMPANY"/>
-        <set field="serviceCtx.roleTypeId" value="SUPPLIER"/>
-        <set field="serviceCtx.fromDate" value="2016-11-03 00:00:00" type="Timestamp"/>
-        <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="deleteFinAccountRole" in-map-name="serviceCtx"/>
-        <entity-and list="finAccountRoles" entity-name="FinAccountRole">
-            <field-map field-name="finAccountId" value="1004"/>
-            <field-map field-name="partyId" value="DEMO_COMPANY"/>
-            <field-map field-name="roleTypeId" value="SUPPLIER"/>
-        </entity-and>
-        <first-from-list entry="finAccountRole" list="finAccountRoles"/>
-        <assert>
-            <if-empty field="finAccountRole"/>
-        </assert>
-        <check-errors/>
-    </simple-method>
-    <simple-method method-name="testCreateFinAccountTrans" short-description="Test case for service createFinAccountTrans" login-required="false">
-        <set field="serviceCtx.finAccountId" value="1003"/>
-        <set field="serviceCtx.finAccountTransTypeId" value="ADJUSTMENT"/>
-        <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="createFinAccountTrans" in-map-name="serviceCtx"/>
-        <entity-and list="finAccountTransList" entity-name="FinAccountTrans">
-            <field-map field-name="finAccountId" value="1003"/>
-        </entity-and>
-        <first-from-list entry="finAccountTrans" list="finAccountTransList"/>
-        <assert>
-            <not><if-empty field="finAccountTrans"/></not>
-            <if-compare operator="equals" value="ADJUSTMENT" field="finAccountTrans.finAccountTransTypeId"></if-compare>
-        </assert>
-        <check-errors/>
-    </simple-method>
-    <simple-method method-name="testCreateFinAccountStatus" short-description="Test case for service createFinAccountStatus" login-required="false">
-        <now-timestamp field="nowTimestamp"/>
-        <set field="serviceCtx.finAccountId" value="1003"/>
-        <set field="serviceCtx.statusId" value="FNACT_ACTIVE"/>
-        <set field="serviceCtx.statusDate" from-field="nowTimestamp"/>
-        <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="createFinAccountStatus" in-map-name="serviceCtx"/>
-        <entity-and list="finAccountStatuses" entity-name="FinAccountStatus">
-            <field-map field-name="finAccountId" value="1003"/>
-        </entity-and>
-        <first-from-list entry="finAccountStatus" list="finAccountStatuses"/>
-        <assert>
-            <not><if-empty field="finAccountStatus"/></not>
-            <if-compare operator="equals" value="FNACT_ACTIVE" field="finAccountStatus.statusId"></if-compare>
-        </assert>
-        <check-errors/>
-    </simple-method>
-    <simple-method method-name="testCreateFinAccountAuth" short-description="Test case for service createFinAccountAuth" login-required="false">
-        <now-timestamp field="nowTimestamp"/>
-        <set field="serviceCtx.finAccountId" value="1004"/>
-        <set field="serviceCtx.amount" value="100.00" type="BigDecimal"/>
-        <set field="serviceCtx.currencyUomId" value="USD" />
-        <set field="serviceCtx.authorizationDate" from-field="nowTimestamp"/>
-        <set field="serviceCtx.fromDate" from-field="nowTimestamp"/>
-        <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="createFinAccountAuth" in-map-name="serviceCtx">
-            <results-to-map map-name="finAccountAuthResult"/>
-        </call-service>
-        <assert>
-            <not><if-empty field="finAccountAuthResult"/></not>
-            <not><if-empty field="finAccountAuthResult.finAccountAuthId"/></not>
-        </assert>
-        <check-errors/>
-    </simple-method>
-    <simple-method method-name="setFinAccountTransStatus" short-description="Test case for service setFinAccountTransStatus" login-required="false">
-        <now-timestamp field="nowTimestamp"/>
-        <set field="serviceCtx.finAccountTransId" value="1010"/>
-        <set field="serviceCtx.statusId" value="FINACT_TRNS_APPROVED"/>
-        <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="setFinAccountTransStatus" in-map-name="serviceCtx">
-            <results-to-map map-name="serviceResult"/>
-        </call-service>
-        <entity-one entity-name="FinAccountTrans" value-field="finAccountTrans">
-            <field-map field-name="finAccountTransId" value="1010"/>
-        </entity-one>
-        <assert>
-            <not><if-empty field="finAccountTrans"/></not>
-            <if-compare operator="equals" value="FINACT_TRNS_APPROVED" field="finAccountTrans.statusId"></if-compare>
-            <if-compare operator="equals" value="FINACT_TRNS_CREATED" field="serviceResult.oldStatusId"></if-compare>
-        </assert>
-        <check-errors/>
-    </simple-method>
-</simple-methods>
\ No newline at end of file
diff --git a/applications/accounting/src/main/groovy/org/apache/ofbiz/accounting/AutoAcctgFinAccountTests.groovy b/applications/accounting/src/main/groovy/org/apache/ofbiz/accounting/AutoAcctgFinAccountTests.groovy
new file mode 100644
index 0000000..3f94468
--- /dev/null
+++ b/applications/accounting/src/main/groovy/org/apache/ofbiz/accounting/AutoAcctgFinAccountTests.groovy
@@ -0,0 +1,199 @@
+/*
+ * 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.base.util.UtilDateTime
+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 java.sql.Timestamp
+
+class AutoAcctgFinAccountTests extends OFBizTestCase {
+    public AutoAcctgFinAccountTests(String name) {
+        super(name)
+    }
+
+    void testCreateFinAccount() {
+        Map serviceCtx = [
+                finAccountId: '1000',
+                finAccountTypeId: 'BANK_ACCOUNT',
+                finAccountName: 'Bank Account',
+                finAccountCode: '1000',
+                currencyUomId: 'USD',
+                organizationPartyId: 'DEMO_COMPANY',
+                userLogin: userLogin
+        ]
+        Map serviceResult = dispatcher.runSync('createFinAccount', serviceCtx)
+        assert ServiceUtil.isSuccess(serviceResult)
+
+        GenericValue finAccount = EntityQuery.use(delegator).from('FinAccount')
+                                    .where('finAccountId', '1000', 'finAccountTypeId', 'BANK_ACCOUNT')
+                                    .queryOne()
+        assert finAccount
+        assert finAccount.finAccountCode == '1000'
+    }
+
+    void testUpdateFinAccount() {
+        Map serviceCtx = [
+                finAccountId: '1001',
+                organizationPartyId: 'DEMO_COMPANY2',
+                userLogin: userLogin
+        ]
+        Map serviceResult = dispatcher.runSync('updateFinAccount', serviceCtx)
+        assert ServiceUtil.isSuccess(serviceResult)
+
+        GenericValue finAccount = EntityQuery.use(delegator).from('FinAccount')
+                .where('finAccountId', '1001')
+                .queryOne()
+        assert finAccount
+        assert finAccount.organizationPartyId == 'DEMO_COMPANY2'
+    }
+
+    void testDeleteFinAccount() {
+        Map serviceCtx = [
+                finAccountId: '1002',
+                userLogin: userLogin
+        ]
+        Map serviceResult = dispatcher.runSync('deleteFinAccount', serviceCtx)
+        assert ServiceUtil.isSuccess(serviceResult)
+
+        GenericValue finAccount = EntityQuery.use(delegator).from('FinAccount')
+                .where('finAccountId', '1002')
+                .queryOne()
+        assert finAccount == null
+    }
+
+    void testCreateFinAccountRole() {
+        Map serviceCtx = [
+                finAccountId: '1003',
+                partyId: 'DEMO_COMPANY',
+                roleTypeId: 'INTERNAL_ORGANIZATIO',
+                fromDate: UtilDateTime.nowTimestamp(),
+                currencyUomId: 'USD',
+                userLogin: userLogin
+        ]
+        Map serviceResult = dispatcher.runSync('createFinAccountRole', serviceCtx)
+        assert ServiceUtil.isSuccess(serviceResult)
+
+        GenericValue finAccountRole = EntityQuery.use(delegator).from('FinAccountRole')
+                .where('finAccountId', '1003', 'partyId', 'DEMO_COMPANY', 'roleTypeId', 'INTERNAL_ORGANIZATIO')
+                .queryFirst()
+        assert finAccountRole
+    }
+
+    void testUpdateFinAccountRole() {
+        Map serviceCtx = [
+                finAccountId: '1004',
+                partyId: 'DEMO_COMPANY',
+                roleTypeId: 'SUPPLIER',
+                fromDate: UtilDateTime.toTimestamp("11/03/2016 00:00:00"),
+                thruDate: UtilDateTime.nowTimestamp(),
+                userLogin: userLogin
+        ]
+        Map serviceResult = dispatcher.runSync('updateFinAccountRole', serviceCtx)
+        assert ServiceUtil.isSuccess(serviceResult)
+
+        GenericValue finAccountRole = EntityQuery.use(delegator).from('FinAccountRole')
+                .where('finAccountId', '1004', 'partyId', 'DEMO_COMPANY', 'roleTypeId', 'SUPPLIER')
+                .queryFirst()
+        assert finAccountRole
+        assert finAccountRole.thruDate != null
+    }
+
+    void testDeleteFinAccountRole() {
+        Map serviceCtx = [
+                finAccountId: '1004',
+                partyId: 'DEMO_COMPANY',
+                roleTypeId: 'SUPPLIER',
+                fromDate: UtilDateTime.toTimestamp("11/03/2016 00:00:00"),
+                userLogin: userLogin
+        ]
+        Map serviceResult = dispatcher.runSync('deleteFinAccountRole', serviceCtx)
+        assert ServiceUtil.isSuccess(serviceResult)
+
+        GenericValue finAccountRole = EntityQuery.use(delegator).from('FinAccountRole')
+                .where('finAccountId', '1004', 'partyId', 'DEMO_COMPANY', 'roleTypeId', 'SUPPLIER')
+                .queryFirst()
+        assert finAccountRole == null
+    }
+
+    void testCreateFinAccountTrans() {
+        Map serviceCtx = [
+                finAccountId: '1003',
+                finAccountTransTypeId: 'ADJUSTMENT',
+                userLogin: userLogin
+        ]
+        Map serviceResult = dispatcher.runSync('createFinAccountTrans', serviceCtx)
+        assert ServiceUtil.isSuccess(serviceResult)
+
+        GenericValue finAccountTran = EntityQuery.use(delegator).from('FinAccountTrans')
+                .where('finAccountId', '1003', 'finAccountTransTypeId', 'ADJUSTMENT')
+                .queryFirst()
+        assert finAccountTran
+    }
+
+    void testCreateFinAccountStatus() {
+        Map serviceCtx = [
+                finAccountId: '1003',
+                statusId: 'FNACT_ACTIVE',
+                statusDate: UtilDateTime.nowTimestamp(),
+                userLogin: userLogin
+        ]
+        Map serviceResult = dispatcher.runSync('createFinAccountStatus', serviceCtx)
+        assert ServiceUtil.isSuccess(serviceResult)
+
+        GenericValue finAccountStatus = EntityQuery.use(delegator).from('FinAccountStatus')
+                .where('finAccountId', '1003', 'statusId', 'FNACT_ACTIVE')
+                .queryFirst()
+        assert finAccountStatus
+    }
+
+    void testCreateFinAccountAuth() {
+        Map serviceCtx = [
+                finAccountId: '1004',
+                amount: new BigDecimal('100'),
+                currencyUomId: 'USD',
+                authorizationDate: UtilDateTime.nowTimestamp(),
+                fromDate: UtilDateTime.nowTimestamp(),
+                userLogin: userLogin
+        ]
+        Map serviceResult = dispatcher.runSync('createFinAccountAuth', serviceCtx)
+        assert ServiceUtil.isSuccess(serviceResult)
+        assert serviceResult.finAccountAuthId != null
+    }
+
+    void setFinAccountTransStatus() {
+        Map serviceCtx = [
+                finAccountTransId: '1010',
+                statusId: 'FINACT_TRNS_APPROVED',
+                userLogin: userLogin
+        ]
+        Map serviceResult = dispatcher.runSync('setFinAccountTransStatus', serviceCtx)
+        assert ServiceUtil.isSuccess(serviceResult)
+
+        GenericValue finAccountTrans = EntityQuery.use(delegator).from('FinAccountTrans')
+                .where('finAccountTransId', '1010')
+                .queryOne()
+        assert finAccountTrans
+        assert finAccountTrans.statusId == 'FINACT_TRNS_APPROVED'
+        assert finAccountTrans.oldStatusId == 'FINACT_TRNS_CREATED'
+    }
+}
diff --git a/applications/accounting/testdef/accountingtests.xml b/applications/accounting/testdef/accountingtests.xml
index 8eb9424..78bf7f1 100644
--- a/applications/accounting/testdef/accountingtests.xml
+++ b/applications/accounting/testdef/accountingtests.xml
@@ -49,7 +49,7 @@
         <junit-test-suite class-name="org.apache.ofbiz.accounting.AutoAcctgCostTests"/>
     </test-case>
     <test-case case-name="auto-accounting-finaccount-tests">
-        <simple-method-test location="component://accounting/minilang/test/AutoAcctgFinAccountTests.xml"/>
+        <junit-test-suite class-name="org.apache.ofbiz.accounting.AutoAcctgFinAccountTests"/>
     </test-case>
     <test-case case-name="auto-accounting-fixedasset-tests">
         <simple-method-test location="component://accounting/minilang/test/AutoAcctgFixedAssetTests.xml"/>