You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jl...@apache.org on 2020/07/28 09:55:16 UTC
[ofbiz-framework] branch trunk updated: Improved: Convert
ProductTagTest.xml to Groovy (OFBIZ-11857)
This is an automated email from the ASF dual-hosted git repository.
jleroux 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 782cd7d Improved: Convert ProductTagTest.xml to Groovy (OFBIZ-11857)
782cd7d is described below
commit 782cd7da639ab18d76d51ef5d683c5d9d990acaf
Author: Jacques Le Roux <ja...@les7arts.com>
AuthorDate: Tue Jul 28 11:54:48 2020 +0200
Improved: Convert ProductTagTest.xml to Groovy (OFBIZ-11857)
This can be tested using
./gradlew "ofbiz --test component=product --test suitename=producttagtests"
Thanks: Akash Jain for report, Anushi Gupta for the patch
---
.../minilang/product/test/ProductTagTest.xml | 165 ---------------------
.../org/apache/ofbiz/product/ProductTagTest.groovy | 120 +++++++++++++++
applications/product/testdef/ProductTagTest.xml | 2 +-
3 files changed, 121 insertions(+), 166 deletions(-)
diff --git a/applications/product/minilang/product/test/ProductTagTest.xml b/applications/product/minilang/product/test/ProductTagTest.xml
deleted file mode 100644
index 2ca243e..0000000
--- a/applications/product/minilang/product/test/ProductTagTest.xml
+++ /dev/null
@@ -1,165 +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="testProductTag" short-description="Test Product Tag" login-required="false">
- <!-- Test Product Tag
- Step 1) Create a product tag.
- Step 2) Check a product tag is created.
- Step 3) Approve a product tag.
- Step 4) Check a product tag is approved.
- Step 5) Create multiple product tag.
- Step 6) Approve all product tags.
- Step 7) Check all product tags is approved.
- Step 8) Check all product tags is created.
- -->
- <!-- Step 1 -->
- <entity-one entity-name="UserLogin" value-field="systemUserLogin">
- <field-map field-name="userLoginId" value="system"/>
- </entity-one>
- <set field="request" from-field="parameters.request"/>
- <script>groovy:
- request.setParameter("productId", "GZ-1000");
- request.setParameter("productTags", "test");
- </script>
- <call-class-method method-name="addProductTags" class-name="org.apache.ofbiz.product.product.ProductEvents" ret-field="result">
- <field field="request" type="javax.servlet.http.HttpServletRequest"/>
- <field field="response" type="javax.servlet.http.HttpServletResponse"/>
- </call-class-method>
- <!-- Step 2 -->
- <entity-one entity-name="ProductKeyword" value-field="productKeyword">
- <field-map field-name="productId" value="GZ-1000"/>
- <field-map field-name="keyword" value="test"/>
- <field-map field-name="keywordTypeId" value="KWT_TAG"/>
- </entity-one>
- <assert>
- <and>
- <not><if-empty field="productKeyword"/></not>
- <if-compare field="productKeyword.statusId" operator="equals" value="KW_PENDING"/>
- </and>
- </assert>
- <!-- Step 3 -->
- <set field="updateProductKeywordMap.userLogin" from-field="systemUserLogin"/>
- <set field="updateProductKeywordMap.productId" value="GZ-1000"/>
- <set field="updateProductKeywordMap.keyword" value="test"/>
- <set field="updateProductKeywordMap.keywordTypeId" value="KWT_TAG"/>
- <set field="updateProductKeywordMap.statusId" value="KW_APPROVED"/>
- <call-service service-name="updateProductKeyword" in-map-name="updateProductKeywordMap"/>
- <!-- Step 4 -->
- <entity-one entity-name="ProductKeyword" value-field="checkProductKeywordApprove">
- <field-map field-name="productId" value="GZ-1000"/>
- <field-map field-name="keyword" value="test"/>
- <field-map field-name="keywordTypeId" value="KWT_TAG"/>
- </entity-one>
- <assert>
- <if-compare field="checkProductKeywordApprove.statusId" operator="equals" value="KW_APPROVED"/>
- </assert>
- <!-- Step 5 -->
- <script>groovy:
- request.setParameter("productId", "GZ-1000");
- request.setParameter("productTags", "'rock and roll' t-shirt red");
- </script>
- <call-class-method method-name="addProductTags" class-name="org.apache.ofbiz.product.product.ProductEvents" ret-field="result">
- <field field="request" type="javax.servlet.http.HttpServletRequest"/>
- <field field="response" type="javax.servlet.http.HttpServletResponse"/>
- </call-class-method>
- <!-- Step 6 -->
- <entity-one entity-name="ProductKeyword" value-field="checkProductKeyword1">
- <field-map field-name="productId" value="GZ-1000"/>
- <field-map field-name="keyword" value="rock and roll"/>
- <field-map field-name="keywordTypeId" value="KWT_TAG"/>
- </entity-one>
- <assert>
- <and>
- <not><if-empty field="checkProductKeyword1"/></not>
- <if-compare field="checkProductKeyword1.statusId" operator="equals" value="KW_PENDING"/>
- </and>
- </assert>
-
- <entity-one entity-name="ProductKeyword" value-field="checkProductKeyword2">
- <field-map field-name="productId" value="GZ-1000"/>
- <field-map field-name="keyword" value="t-shirt"/>
- <field-map field-name="keywordTypeId" value="KWT_TAG"/>
- </entity-one>
- <assert>
- <and>
- <not><if-empty field="checkProductKeyword2"/></not>
- <if-compare field="checkProductKeyword2.statusId" operator="equals" value="KW_PENDING"/>
- </and>
- </assert>
-
- <entity-one entity-name="ProductKeyword" value-field="checkProductKeyword3">
- <field-map field-name="productId" value="GZ-1000"/>
- <field-map field-name="keyword" value="red"/>
- <field-map field-name="keywordTypeId" value="KWT_TAG"/>
- </entity-one>
- <assert>
- <and>
- <not><if-empty field="checkProductKeyword3"/></not>
- <if-compare field="checkProductKeyword3.statusId" operator="equals" value="KW_PENDING"/>
- </and>
- </assert>
- <!-- Step 7 -->
- <entity-and entity-name="ProductKeyword" list="checkAllProductKeywordApproveList">
- <field-map field-name="productId" value="GZ-1000"/>
- <field-map field-name="keywordTypeId" value="KWT_TAG"/>
- <field-map field-name="statusId" value="KW_PENDING"/>
- </entity-and>
- <iterate list="checkAllProductKeywordApproveList" entry="checkAllProductKeywordApprove">
- <set field="updateProductKeywordMap.userLogin" from-field="systemUserLogin"/>
- <set field="updateProductKeywordMap.productId" from-field="checkAllProductKeywordApprove.productId"/>
- <set field="updateProductKeywordMap.keyword" from-field="checkAllProductKeywordApprove.keyword"/>
- <set field="updateProductKeywordMap.keywordTypeId" from-field="checkAllProductKeywordApprove.keywordTypeId"/>
- <set field="updateProductKeywordMap.statusId" value="KW_APPROVED"/>
- <call-service service-name="updateProductKeyword" in-map-name="updateProductKeywordMap"/>
- </iterate>
- <!-- Step 8 -->
- <entity-one entity-name="ProductKeyword" value-field="checkProductKeywordApprove1">
- <field-map field-name="productId" value="GZ-1000"/>
- <field-map field-name="keyword" value="rock and roll"/>
- <field-map field-name="keywordTypeId" value="KWT_TAG"/>
- </entity-one>
- <assert>
- <if-compare field="checkProductKeywordApprove1.statusId" operator="equals" value="KW_APPROVED"/>
- </assert>
-
- <entity-one entity-name="ProductKeyword" value-field="checkProductKeywordApprove2">
- <field-map field-name="productId" value="GZ-1000"/>
- <field-map field-name="keyword" value="t-shirt"/>
- <field-map field-name="keywordTypeId" value="KWT_TAG"/>
- </entity-one>
- <assert>
- <if-compare field="checkProductKeywordApprove2.statusId" operator="equals" value="KW_APPROVED"/>
- </assert>
-
- <entity-one entity-name="ProductKeyword" value-field="checkProductKeywordApprove3">
- <field-map field-name="productId" value="GZ-1000"/>
- <field-map field-name="keyword" value="red"/>
- <field-map field-name="keywordTypeId" value="KWT_TAG"/>
- </entity-one>
- <assert>
- <if-compare field="checkProductKeywordApprove3.statusId" operator="equals" value="KW_APPROVED"/>
- </assert>
-
- <check-errors/>
- </simple-method>
-</simple-methods>
diff --git a/applications/product/src/main/groovy/org/apache/ofbiz/product/ProductTagTest.groovy b/applications/product/src/main/groovy/org/apache/ofbiz/product/ProductTagTest.groovy
new file mode 100644
index 0000000..67f97f0
--- /dev/null
+++ b/applications/product/src/main/groovy/org/apache/ofbiz/product/ProductTagTest.groovy
@@ -0,0 +1,120 @@
+/*******************************************************************************
+ * 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
+import org.springframework.mock.web.MockHttpServletRequest
+import org.springframework.mock.web.MockHttpServletResponse
+import org.apache.ofbiz.product.product.ProductEvents
+
+class ProductTagTest extends OFBizTestCase {
+ public ProductTagTest(String name) {
+ super(name)
+ }
+
+ void testProductTag() {
+ /*Test Product Tag
+ Step 1) Create a product tag.
+ Step 2) Check a product tag is created.
+ Step 3) Approve a product tag.
+ Step 4) Check a product tag is approved.
+ Step 5) Create multiple product tag.
+ Step 6) Approve all product tags.
+ Step 7) Check all product tags is approved.
+ Step 8) Check all product tags is created.*/
+
+
+ MockHttpServletRequest request = new MockHttpServletRequest()
+ MockHttpServletResponse response = new MockHttpServletResponse()
+ GenericValue systemUserLogin = from('UserLogin').where('userLoginId', 'system').queryOne()
+ request.setAttribute('delegator', delegator)
+ request.setAttribute('dispatcher', dispatcher)
+ // Step 1
+ request.setParameter('productId', 'GZ-1000');
+ request.setParameter('productTags', 'test');
+ ProductEvents.addProductTags(request, response)
+
+ // Step 2
+ GenericValue productKeyword = from('ProductKeyword').where('productId', 'GZ-1000', 'keyword', 'test', 'keywordTypeId', 'KWT_TAG').queryOne()
+ assert productKeyword != null
+ assert productKeyword.statusId == 'KW_PENDING'
+ // Step 3
+ Map updateProductKeywordMap = [
+ userLogin : systemUserLogin,
+ productId : 'GZ-1000',
+ keyword : 'test',
+ keywordTypeId : 'KWT_TAG',
+ statusId : 'KW_APPROVED',
+ ]
+ Map resultMap = dispatcher.runSync('updateProductKeyword', updateProductKeywordMap)
+ assert ServiceUtil.isSuccess(resultMap)
+
+ // Step 4
+ GenericValue checkProductKeywordApprove = from('ProductKeyword').where('productId', 'GZ-1000', 'keyword', 'test', 'keywordTypeId', 'KWT_TAG').queryOne()
+ assert checkProductKeywordApprove != null
+ assert checkProductKeywordApprove.statusId == 'KW_APPROVED'
+
+ // Step 5
+ request.setParameter('productId', 'GZ-1000');
+ request.setParameter('productTags', '\'rock and roll\' t-shirt red');
+ ProductEvents.addProductTags(request, response)
+
+ // Step 6
+ GenericValue checkProductKeyword1 = from('ProductKeyword').where('productId', 'GZ-1000', 'keyword', 'rock and roll', 'keywordTypeId', 'KWT_TAG').queryOne()
+ assert checkProductKeyword1 != null
+ assert checkProductKeyword1.statusId == 'KW_PENDING'
+
+ GenericValue checkProductKeyword2 = from('ProductKeyword').where('productId', 'GZ-1000', 'keyword', 't-shirt', 'keywordTypeId', 'KWT_TAG').queryOne()
+ assert checkProductKeyword2 != null
+ assert checkProductKeyword2.statusId == 'KW_PENDING'
+
+ GenericValue checkProductKeyword3 = from('ProductKeyword').where('productId', 'GZ-1000', 'keyword', 'red', 'keywordTypeId', 'KWT_TAG').queryOne()
+ assert checkProductKeyword3 != null
+ assert checkProductKeyword3.statusId == 'KW_PENDING'
+
+ // Step 7
+ List<GenericValue> checkAllProductKeywordApproveList = from('ProductKeyword').where('productId', 'GZ-1000', 'statusId', 'KW_PENDING', 'keywordTypeId', 'KWT_TAG').queryList()
+ for (GenericValue checkAllProductKeywordApprove : checkAllProductKeywordApproveList) {
+ updateProductKeywordMap = [
+ userLogin : systemUserLogin,
+ productId : checkAllProductKeywordApprove.productId,
+ keyword : checkAllProductKeywordApprove.keyword,
+ keywordTypeId : checkAllProductKeywordApprove.keywordTypeId,
+ statusId : 'KW_APPROVED',
+ ]
+ resultMap = dispatcher.runSync('updateProductKeyword', updateProductKeywordMap)
+ assert ServiceUtil.isSuccess(resultMap)
+ }
+
+ // Step 8
+ GenericValue checkProductKeywordApprove1 = from('ProductKeyword').where('productId', 'GZ-1000', 'keyword', 'rock and roll', 'keywordTypeId', 'KWT_TAG').queryOne()
+ assert checkProductKeywordApprove1 != null
+ assert checkProductKeywordApprove1.statusId == 'KW_APPROVED'
+
+ GenericValue checkProductKeywordApprove2 = from('ProductKeyword').where('productId', 'GZ-1000', 'keyword', 't-shirt', 'keywordTypeId', 'KWT_TAG').queryOne()
+ assert checkProductKeywordApprove2 != null
+ assert checkProductKeywordApprove2.statusId == 'KW_APPROVED'
+
+ GenericValue checkProductKeywordApprove3 = from('ProductKeyword').where('productId', 'GZ-1000', 'keyword', 'red', 'keywordTypeId', 'KWT_TAG').queryOne()
+ assert checkProductKeywordApprove3 != null
+ assert checkProductKeywordApprove3.statusId == 'KW_APPROVED'
+ }
+}
\ No newline at end of file
diff --git a/applications/product/testdef/ProductTagTest.xml b/applications/product/testdef/ProductTagTest.xml
index 098ca41..b5c2fe6 100644
--- a/applications/product/testdef/ProductTagTest.xml
+++ b/applications/product/testdef/ProductTagTest.xml
@@ -23,7 +23,7 @@ under the License.
xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/test-suite.xsd">
<test-case case-name="producttag-test">
- <simple-method-test location="component://product/minilang/product/test/ProductTagTest.xml" name="testProductTag"/>
+ <junit-test-suite class-name="org.apache.ofbiz.product.ProductTagTest"/>
</test-case>
</test-suite>