[ofbiz-plugins] branch trunk updated: Improved: Convert FixedAssetMaintTests.xml to groovy (OFBIZ-11444) (#29)

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

[ofbiz-plugins] branch trunk updated: Improved: Convert FixedAssetMaintTests.xml to groovy (OFBIZ-11444) (#29)

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-plugins.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 3fe1219  Improved: Convert FixedAssetMaintTests.xml to groovy (OFBIZ-11444) (#29)
3fe1219 is described below

commit 3fe12199d37bc79211b0d7d715127a51a9e386d5
Author: Priya Sharma <[hidden email]>
AuthorDate: Tue Jun 16 10:49:02 2020 +0530

    Improved: Convert FixedAssetMaintTests.xml to groovy (OFBIZ-11444) (#29)
   
    * [Improved] Convert FixedAssetMaintTests.xml to groovy
    Done the following
    - Removed the xml tests file
    - Updated the test suite mappings to point to the groovy test file
    - Added Groovy implementation for all the test cases in FixedAssetMaintTests.xml
   
    (OFBIZ-11444)
   
    * [Improved]: Removed the userlogin fetching logic as the userlogin is already available in the groovy context. (OFBIZ-11444)
   
    Co-authored-by: Priya Sharma <[hidden email]>
---
 assetmaint/minilang/test/FixedAssetMaintTests.xml  | 146 --------------------
 .../assetmaint/test/FixedAssetMaintTests.groovy    | 148 +++++++++++++++++++++
 assetmaint/testdef/assetmainttests.xml             |   3 +-
 3 files changed, 149 insertions(+), 148 deletions(-)

diff --git a/assetmaint/minilang/test/FixedAssetMaintTests.xml b/assetmaint/minilang/test/FixedAssetMaintTests.xml
deleted file mode 100644
index 729cb15..0000000
--- a/assetmaint/minilang/test/FixedAssetMaintTests.xml
+++ /dev/null
@@ -1,146 +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="testCreateFixedAssetMaintUpdateWorkEffortWithProductMaint" short-description="Test case for service createFixedAssetMaintUpdateWorkEffort with a product Maintenance" login-required="false">
-        <set field="fixedAssetId" value="DEMO_VEHICLE_01"/>
-        <set field="serviceCtx.fixedAssetId" from-field="fixedAssetId"/>
-        <set field="serviceCtx.statusId" value="FAM_CREATED"/>
-        <set field="serviceCtx.productMaintSeqId" value="seq03"/><!-- Product Maintenance -->
-        <set field="serviceCtx.intervalMeterTypeId" value="ODOMETER"/>
-        <set field="serviceCtx.estimatedStartDate" value="2009-12-18 00:00:00.000" type="Timestamp"/>
-        <set field="serviceCtx.estimatedCompletionDate" value="2009-12-18 01:00:00.000" type="Timestamp"/>
-        <set field="serviceCtx.actualStartDate" value="2009-12-20 00:00:00.000" 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="createFixedAssetMaintUpdateWorkEffort" in-map-name="serviceCtx">
-            <result-to-field result-name="maintHistSeqId"/>
-        </call-service>
-
-        <entity-one entity-name="FixedAssetMaint" value-field="fixedAssetMaint"/>
-        <get-related-one relation-name="ScheduleWorkEffort" value-field="fixedAssetMaint" to-value-field="workEffort"/>
-        <assert>
-            <not><if-empty field="fixedAssetMaint"/></not>
-            <not><if-empty field="fixedAssetMaint.scheduleWorkEffortId"/></not>
-            <not><if-empty field="workEffort"/></not>
-            <if-compare-field field="workEffort.estimatedStartDate" operator="equals" to-field="serviceCtx.estimatedStartDate"/>
-            <if-compare-field field="workEffort.estimatedCompletionDate" operator="equals" to-field="serviceCtx.estimatedCompletionDate"/>
-            <if-compare-field field="workEffort.actualStartDate" operator="equals" to-field="serviceCtx.actualStartDate"/>
-        </assert>
-        <check-errors/>
-    </simple-method>
-
-    <simple-method method-name="testCreateFixedAssetMaintUpdateWorkEffortWithoutProductMaint" short-description="Test case for service createFixedAssetMaintUpdateWorkEffort without a product maintenance" login-required="false">
-        <set field="fixedAssetId" value="DEMO_VEHICLE_01"/>
-        <set field="serviceCtx.fixedAssetId" from-field="fixedAssetId"/>
-        <set field="serviceCtx.statusId" value="FAM_CREATED"/>
-        <set field="serviceCtx.productMaintTypeId" value="OIL_CHANGE"/>
-        <set field="serviceCtx.intervalMeterTypeId" value="ODOMETER"/>
-        <set field="serviceCtx.estimatedStartDate" value="2009-12-18 00:00:00.000" type="Timestamp"/>
-        <set field="serviceCtx.estimatedCompletionDate" value="2009-12-18 01:00:00.000" type="Timestamp"/>
-        <set field="serviceCtx.actualStartDate" value="2009-12-20 00:00:00.000" 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="createFixedAssetMaintUpdateWorkEffort" in-map-name="serviceCtx">
-            <result-to-field result-name="maintHistSeqId"/>
-        </call-service>
-
-        <entity-one entity-name="FixedAssetMaint" value-field="fixedAssetMaint">
-            <field-map field-name="fixedAssetId"/>
-            <field-map field-name="maintHistSeqId"/>
-        </entity-one>
-        <get-related-one relation-name="ScheduleWorkEffort" value-field="fixedAssetMaint" to-value-field="workEffort"/>
-        <assert>
-            <not><if-empty field="fixedAssetMaint"/></not>
-            <not><if-empty field="fixedAssetMaint.scheduleWorkEffortId"/></not>
-            <not><if-empty field="workEffort"/></not>
-            <if-compare-field field="workEffort.estimatedStartDate" operator="equals" to-field="serviceCtx.estimatedStartDate"/>
-            <if-compare-field field="workEffort.estimatedCompletionDate" operator="equals" to-field="serviceCtx.estimatedCompletionDate"/>
-            <if-compare-field field="workEffort.actualStartDate" operator="equals" to-field="serviceCtx.actualStartDate"/>
-        </assert>
-        <check-errors/>
-    </simple-method>
-
-    <simple-method method-name="testUpdateFixedAssetMaintAndWorkEffort" short-description="Test case for service updateFixedAssetMaintAndWorkEffort" login-required="false">
-        <set field="fixedAssetId" value="DEMO_VEHICLE_01"/>
-        <set field="maintHistSeqId" value="00001"/><!-- Sequence created by testCreateFixedAssetMaintUpdateWorkEffortWithProductMaint -->
-        <set field="serviceCtx.fixedAssetId" from-field="fixedAssetId"/>
-        <set field="serviceCtx.maintHistSeqId" from-field="maintHistSeqId"/>
-        <set field="serviceCtx.estimatedCompletionDate" value="2009-12-22 01:00:00.000" type="Timestamp"/><!-- Changed estimatedCompletionDate to test update service -->
-        <entity-one entity-name="FixedAssetMaint" value-field="fixedAssetMaint"/>
-        <set field="serviceCtx.workEffortId" from-field="fixedAssetMaint.scheduleWorkEffortId"/>
-        <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="updateFixedAssetMaintAndWorkEffort" in-map-name="serviceCtx"/>
-        <clear-field field="fixedAssetMaint"/>
-        <entity-one entity-name="FixedAssetMaint" value-field="fixedAssetMaint"/>
-        <get-related-one relation-name="ScheduleWorkEffort" value-field="fixedAssetMaint" to-value-field="workEffort"/>
-        <assert>
-            <not><if-empty field="fixedAssetMaint"/></not>
-            <not><if-empty field="fixedAssetMaint.scheduleWorkEffortId"/></not>
-            <not><if-empty field="workEffort"/></not>
-            <if-compare-field field="workEffort.estimatedCompletionDate" operator="equals" to-field="serviceCtx.estimatedCompletionDate"/>
-        </assert>
-        <check-errors/>
-    </simple-method>
-
-    <simple-method method-name="testUpdateFixedAssetMaintAndWorkEffortComplete" short-description="Test case for service updateFixedAssetMaintAndWorkEffort" login-required="false">
-        <entity-one entity-name="FixedAssetMaint" value-field="fixedAssetMaint">
-            <field-map field-name="fixedAssetId" value="DEMO_VEHICLE_01"/>
-            <field-map field-name="maintHistSeqId" value="00001"/>
-        </entity-one>
-        <set field="serviceInMap.fixedAssetId" from-field="fixedAssetMaint.fixedAssetId"/>
-        <set field="serviceInMap.maintHistSeqId" from-field="fixedAssetMaint.maintHistSeqId"/>
-        <set field="serviceInMap.scheduleWorkEffortId" from-field="fixedAssetMaint.scheduleWorkEffortId"/>
-        <set field="serviceInMap.statusId" value="FAM_COMPLETED"/>
-        <now-timestamp field="nowTimestamp"/>
-        <set field="serviceInMap.actualCompletionDate" from-field="nowTimestamp"/>
-        <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="updateFixedAssetMaintAndWorkEffort" in-map-name="serviceInMap"/>
-
-        <entity-one entity-name="FixedAssetMaint" value-field="newFixedAssetMaint">
-            <field-map field-name="fixedAssetId" value="DEMO_VEHICLE_01"/>
-            <field-map field-name="maintHistSeqId" value="00001"/>
-        </entity-one>
-        <assert>
-            <if-compare field="newFixedAssetMaint.statusId" operator="equals" value="FAM_COMPLETED"/>
-        </assert>
-        <check-errors/>
-        <entity-one entity-name="WorkEffort" value-field="workEffort">
-            <field-map field-name="workEffortId" from-field="fixedAssetMaint.scheduleWorkEffortId"/>
-        </entity-one>
-        <assert>
-            <if-compare field="workEffort.currentStatusId" operator="equals" value="CAL_COMPLETED"/>
-            <if-compare-field field="workEffort.actualCompletionDate" operator="equals" to-field="nowTimestamp" type="Timestamp"/>
-        </assert>
-        <check-errors/>
-    </simple-method>
-</simple-methods>
diff --git a/assetmaint/src/main/groovy/org/apache/ofbiz/assetmaint/test/FixedAssetMaintTests.groovy b/assetmaint/src/main/groovy/org/apache/ofbiz/assetmaint/test/FixedAssetMaintTests.groovy
new file mode 100644
index 0000000..c9af5b7
--- /dev/null
+++ b/assetmaint/src/main/groovy/org/apache/ofbiz/assetmaint/test/FixedAssetMaintTests.groovy
@@ -0,0 +1,148 @@
+/*
+ * 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.assetmaint.test
+
+import java.sql.Timestamp
+import java.text.SimpleDateFormat
+import org.apache.ofbiz.base.util.UtilDateTime
+import org.apache.ofbiz.entity.GenericValue
+import org.apache.ofbiz.service.testtools.OFBizTestCase
+
+class FixedAssetMaintTests extends OFBizTestCase {
+    public FixedAssetMaintTests(String name) {
+        super(name)
+    }
+
+    void testCreateFixedAssetMaintUpdateWorkEffortWithProductMaint() {
+        // Test case for service createFixedAssetMaintUpdateWorkEffort with a product Maintenance
+        String fixedAssetId = "DEMO_VEHICLE_01"
+        Map serviceCtx = [:]
+        serviceCtx.fixedAssetId = fixedAssetId
+        serviceCtx.statusId = "FAM_CREATED"
+        serviceCtx.productMaintSeqId = "seq03"  // product maintenance
+        serviceCtx.intervalMeterTypeId = "ODOMETER"
+
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
+        String estimatedStartDate = "2009-12-18 00:00:00.000"
+        serviceCtx.estimatedStartDate = new Timestamp(sdf.parse(estimatedStartDate).getTime());
+
+        String estimatedCompletionDate = "2009-12-18 01:00:00.000"
+        serviceCtx.estimatedCompletionDate = new Timestamp(sdf.parse(estimatedCompletionDate).getTime())
+
+        String actualStartDate = "2009-12-20 00:00:00.000"
+        serviceCtx.actualStartDate = new Timestamp(sdf.parse(actualStartDate).getTime())
+
+        serviceCtx.userLogin = userLogin
+        Map serviceResult = dispatcher.runSync('createFixedAssetMaintUpdateWorkEffort', serviceCtx)
+        String maintHistSeqId = serviceResult.maintHistSeqId
+
+        GenericValue fixedAssetMaint = from("FixedAssetMaint").where("fixedAssetId", fixedAssetId).queryFirst()
+        GenericValue workEffort = from("WorkEffort").where("workEffortId", fixedAssetMaint.scheduleWorkEffortId).queryOne()
+        assert fixedAssetMaint
+        assert fixedAssetMaint.scheduleWorkEffortId
+        assert workEffort
+        assert workEffort.estimatedStartDate == serviceCtx.estimatedStartDate
+        assert workEffort.estimatedCompletionDate == serviceCtx.estimatedCompletionDate
+        assert workEffort.actualStartDate == serviceCtx.actualStartDate
+    }
+
+    void testCreateFixedAssetMaintUpdateWorkEffortWithoutProductMaint() {
+        // Test case for service createFixedAssetMaintUpdateWorkEffort without a product maintenance
+        String fixedAssetId = "DEMO_VEHICLE_01"
+        Map serviceCtx = [:]
+        serviceCtx.fixedAssetId = fixedAssetId
+        serviceCtx.statusId = "FAM_CREATED"
+        serviceCtx.productMaintTypeId = "OIL_CHANGE"
+        serviceCtx.intervalMeterTypeId = "ODOMETER"
+
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
+        String estimatedStartDate = "2009-12-18 00:00:00.000"
+        serviceCtx.estimatedStartDate = new Timestamp(sdf.parse(estimatedStartDate).getTime());
+
+        String estimatedCompletionDate = "2009-12-18 01:00:00.000"
+        serviceCtx.estimatedCompletionDate = new Timestamp(sdf.parse(estimatedCompletionDate).getTime())
+
+        String actualStartDate = "2009-12-20 00:00:00.000"
+        serviceCtx.actualStartDate = new Timestamp(sdf.parse(actualStartDate).getTime())
+
+        serviceCtx.userLogin = userLogin
+        Map serviceResult = dispatcher.runSync('createFixedAssetMaintUpdateWorkEffort', serviceCtx)
+        String maintHistSeqId = serviceResult.maintHistSeqId
+
+        GenericValue fixedAssetMaint = from("FixedAssetMaint").where("fixedAssetId", fixedAssetId, "maintHistSeqId", maintHistSeqId).queryOne()
+        GenericValue workEffort = from("WorkEffort").where("workEffortId", fixedAssetMaint.scheduleWorkEffortId).queryOne()
+
+        assert fixedAssetMaint
+        assert fixedAssetMaint.scheduleWorkEffortId
+        assert workEffort
+        assert workEffort.estimatedStartDate == serviceCtx.estimatedStartDate
+        assert workEffort.estimatedCompletionDate == serviceCtx.estimatedCompletionDate
+        assert workEffort.actualStartDate == serviceCtx.actualStartDate
+    }
+
+    void testUpdateFixedAssetMaintAndWorkEffort() {
+        // Test case for service updateFixedAssetMaintAndWorkEffort
+        String fixedAssetId = "DEMO_VEHICLE_01"
+        String maintHistSeqId = "00001"    // Sequence created by testCreateFixedAssetMaintUpdateWorkEffortWithProductMaint
+        Map serviceCtx = [:]
+        serviceCtx.fixedAssetId = fixedAssetId
+        serviceCtx.maintHistSeqId = maintHistSeqId
+        serviceCtx.statusId = "FAM_CREATED"
+        serviceCtx.productMaintTypeId = "OIL_CHANGE"
+        serviceCtx.intervalMeterTypeId = "ODOMETER"
+
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
+        String estimatedCompletionDate = "2009-12-22 01:00:00.000"  // Changed estimatedCompletionDate to test update service
+        serviceCtx.estimatedCompletionDate = new Timestamp(sdf.parse(estimatedCompletionDate).getTime())
+
+        GenericValue fixedAssetMaint = from("FixedAssetMaint").where("fixedAssetId", fixedAssetId).queryFirst()
+        serviceCtx.workEffortId = fixedAssetMaint.scheduleWorkEffortId
+
+        serviceCtx.userLogin = userLogin
+        Map serviceResult = dispatcher.runSync('updateFixedAssetMaintAndWorkEffort', serviceCtx)
+
+        fixedAssetMaint.clear()
+        fixedAssetMaint = from("FixedAssetMaint").where("fixedAssetId", fixedAssetId).queryFirst()
+        GenericValue workEffort = from("WorkEffort").where("workEffortId", fixedAssetMaint.scheduleWorkEffortId).queryOne()
+
+        assert fixedAssetMaint
+        assert fixedAssetMaint.scheduleWorkEffortId
+        assert workEffort
+        assert workEffort.estimatedCompletionDate == serviceCtx.estimatedCompletionDate
+    }
+
+    void testUpdateFixedAssetMaintAndWorkEffortComplete() {
+        // Test case for service updateFixedAssetMaintAndWorkEffort
+        GenericValue fixedAssetMaint = from("FixedAssetMaint").where("fixedAssetId", "DEMO_VEHICLE_01", "maintHistSeqId", "00001").queryOne()
+        Map serviceCtx = [:]
+        serviceCtx.fixedAssetId = fixedAssetMaint.fixedAssetId
+        serviceCtx.maintHistSeqId = fixedAssetMaint.maintHistSeqId
+        serviceCtx.scheduleWorkEffortId = fixedAssetMaint.scheduleWorkEffortId
+        serviceCtx.statusId = "FAM_COMPLETED"
+        serviceCtx.actualCompletionDate = UtilDateTime.nowTimestamp()
+        serviceCtx.userLogin = userLogin
+
+        Map serviceResult = dispatcher.runSync('updateFixedAssetMaintAndWorkEffort', serviceCtx)
+        GenericValue newFixedAssetMaint = from("FixedAssetMaint").where("fixedAssetId", "DEMO_VEHICLE_01", "maintHistSeqId", "00001").queryOne()
+        assert newFixedAssetMaint.statusId == "FAM_COMPLETED"
+        GenericValue workEffort = from("WorkEffort").where("workEffortId", fixedAssetMaint.scheduleWorkEffortId).queryOne()
+        assert workEffort.currentStatusId == "CAL_COMPLETED"
+        assert workEffort.actualCompletionDate == serviceCtx.actualCompletionDate
+    }
+}
\ No newline at end of file
diff --git a/assetmaint/testdef/assetmainttests.xml b/assetmaint/testdef/assetmainttests.xml
index b95091c..237f113 100644
--- a/assetmaint/testdef/assetmainttests.xml
+++ b/assetmaint/testdef/assetmainttests.xml
@@ -23,7 +23,6 @@
         xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/test-suite.xsd">
 
     <test-case case-name="assetmaint-tests">
-        <simple-method-test location="component://assetmaint/minilang/test/FixedAssetMaintTests.xml"/>
+        <junit-test-suite class-name="org.apache.ofbiz.assetmaint.test.FixedAssetMaintTests"/>
     </test-case>
-
 </test-suite>