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/07/25 11:56:28 UTC
[ofbiz-framework] branch trunk updated: Improved: Convert
CostTests.xml to Groovy(OFBIZ-11859)
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 5799c7e Improved: Convert CostTests.xml to Groovy(OFBIZ-11859)
5799c7e is described below
commit 5799c7e5e46f9915fcb0a8160b8f5e3f9644603f
Author: Pawan Verma <pa...@hotwaxsystems.com>
AuthorDate: Sat Jul 25 17:25:42 2020 +0530
Improved: Convert CostTests.xml to Groovy(OFBIZ-11859)
Thanks, Akash for report and Anushi for the Patch.
---
.../product/minilang/product/test/CostTests.xml | 90 ----------------------
.../org/apache/ofbiz/product/CostTests.groovy | 73 ++++++++++++++++++
applications/product/testdef/CostTests.xml | 2 +-
3 files changed, 74 insertions(+), 91 deletions(-)
diff --git a/applications/product/minilang/product/test/CostTests.xml b/applications/product/minilang/product/test/CostTests.xml
deleted file mode 100644
index f7ddc68..0000000
--- a/applications/product/minilang/product/test/CostTests.xml
+++ /dev/null
@@ -1,90 +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="testCalculateProductStandardCosts" short-description="Test case for service calculateProductCosts" login-required="false">
- <set field="productId" value="PROD_MANUF"/>
- <entity-one entity-name="UserLogin" value-field="userLogin">
- <field-map field-name="userLoginId" value="admin"/>
- </entity-one>
-
- <set field="serviceCtx.userLogin" from-field="userLogin"/>
- <set field="serviceCtx.productId" from-field="productId"/>
- <set field="serviceCtx.currencyUomId" value="USD"/>
- <set field="serviceCtx.costComponentTypePrefix" value="EST_STD"/>
- <call-service service-name="calculateProductCosts" in-map-name="serviceCtx"/>
-
- <entity-and entity-name="CostComponent" list="costComponents">
- <field-map field-name="productId" from-field="productId"/>
- </entity-and>
- <filter-list-by-date list="costComponents"/>
- <set field="costTotalAmount" value="0.0" type="BigDecimal"/>
- <iterate list="costComponents" entry="costComponent">
- <assert>
- <if-compare field="costComponent.costUomId" operator="equals" value="USD"/>
- <or>
- <and>
- <if-compare field="costComponent.costComponentTypeId" operator="equals" value="EST_STD_ROUTE_COST"/>
- <if-compare field="costComponent.cost" operator="equals" value="10.00" type="BigDecimal"/>
- </and>
- <and>
- <if-compare field="costComponent.costComponentTypeId" operator="equals" value="EST_STD_MAT_COST"/>
- <if-compare field="costComponent.cost" operator="equals" value="39.00" type="BigDecimal"/>
- </and>
- <and>
- <if-compare field="costComponent.costComponentTypeId" operator="equals" value="EST_STD_OTHER_COST"/>
- <if-compare field="costComponent.cost" operator="equals" value="31.00" type="BigDecimal"/>
- </and>
- <and>
- <!--<if-compare field="costComponent.costComponentCalcId" operator="equals" value="GEN_COST_CALC"/>-->
- <if-compare field="costComponent.costComponentTypeId" operator="equals" value="EST_STD_GEN_COST"/>
- <if-compare field="costComponent.cost" operator="equals" value="4.00" type="BigDecimal"/>
- </and>
- </or>
- </assert>
- <set field="costTotalAmount" value="${costTotalAmount + costComponent.cost}" type="BigDecimal"/>
- </iterate>
- <assert>
- <if-compare field="costTotalAmount" operator="equals" value="84.00" type="BigDecimal"/>
- </assert>
- <check-errors/>
- </simple-method>
- <simple-method method-name="testGetProductCost" short-description="Test case for service getProductCost" login-required="false">
- <set field="productId" value="PROD_MANUF"/>
- <entity-one entity-name="UserLogin" value-field="userLogin">
- <field-map field-name="userLoginId" value="admin"/>
- </entity-one>
-
- <set field="serviceCtx.userLogin" from-field="userLogin"/>
- <set field="serviceCtx.productId" from-field="productId"/>
- <set field="serviceCtx.currencyUomId" value="USD"/>
- <set field="serviceCtx.costComponentTypePrefix" value="EST_STD"/>
- <call-service service-name="getProductCost" in-map-name="serviceCtx">
- <result-to-field result-name="productCost"/>
- </call-service>
-
- <assert>
- <if-compare field="productCost" operator="equals" value="84.00" type="BigDecimal"/>
- </assert>
- <check-errors/>
- </simple-method>
-</simple-methods>
diff --git a/applications/product/src/main/groovy/org/apache/ofbiz/product/CostTests.groovy b/applications/product/src/main/groovy/org/apache/ofbiz/product/CostTests.groovy
new file mode 100644
index 0000000..5c17a09
--- /dev/null
+++ b/applications/product/src/main/groovy/org/apache/ofbiz/product/CostTests.groovy
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * 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 CostTests extends OFBizTestCase {
+ public CostTests(String name) {
+ super(name)
+ }
+
+ void testCalculateProductStandardCosts() {
+ String productId = 'PROD_MANUF'
+ Map serviceCtx = [
+ productId: productId,
+ currencyUomId: 'USD',
+ costComponentTypePrefix: 'EST_STD',
+ userLogin: userLogin
+ ]
+ Map resultMap = dispatcher.runSync('calculateProductCosts', serviceCtx)
+ assert ServiceUtil.isSuccess(resultMap)
+
+ List<GenericValue> costComponents = from('CostComponent').where('productId', productId).filterByDate().queryList()
+ BigDecimal costTotalAmount = BigDecimal.ZERO;
+
+ for (GenericValue costComponent : costComponents) {
+ assert costComponent.costUomId == 'USD'
+ if (costComponent.costComponentTypeId == 'EST_STD_ROUTE_COST') {
+ assert costComponent.cost == 10
+ } else if (costComponent.costComponentTypeId == 'EST_STD_MAT_COST') {
+ assert costComponent.cost == 39
+ } else if (costComponent.costComponentTypeId == 'EST_STD_OTHER_COST') {
+ assert costComponent.cost == 31
+ } else if (costComponent.costComponentTypeId == 'EST_STD_GEN_COST') {
+ assert costComponent.cost == 4
+ }
+ costTotalAmount += costComponent.cost
+ }
+ assert costTotalAmount == 84
+ }
+
+ void testGetProductCost() {
+ String productId = 'PROD_MANUF'
+ Map serviceCtx = [
+ productId: productId,
+ currencyUomId: 'USD',
+ costComponentTypePrefix: 'EST_STD',
+ userLogin: userLogin
+ ]
+ Map resultMap = dispatcher.runSync('getProductCost', serviceCtx)
+ assert ServiceUtil.isSuccess(resultMap)
+ assert resultMap.productCost == 84
+ }
+
+}
\ No newline at end of file
diff --git a/applications/product/testdef/CostTests.xml b/applications/product/testdef/CostTests.xml
index 4761f3a..de3a738 100644
--- a/applications/product/testdef/CostTests.xml
+++ b/applications/product/testdef/CostTests.xml
@@ -23,6 +23,6 @@ under the License.
xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/test-suite.xsd">
<test-case case-name="cost-tests">
- <simple-method-test location="component://product/minilang/product/test/CostTests.xml"/>
+ <junit-test-suite class-name="org.apache.ofbiz.product.CostTests"/>
</test-case>
</test-suite>