[ofbiz-framework] branch trunk updated: Improved: Unit test case for some content services (OFBIZ-8420)

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: Unit test case for some content services (OFBIZ-8420)

akashjain
This is an automated email from the ASF dual-hosted git repository.

akashjain 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 dd04252  Improved: Unit test case for some content services (OFBIZ-8420)
dd04252 is described below

commit dd04252593cee5f02a8fedd7d4d2a20a1d8059e2
Author: Akash Jain <[hidden email]>
AuthorDate: Mon Aug 3 16:31:10 2020 +0530

    Improved: Unit test case for some content services (OFBIZ-8420)
   
    Covered following tickets/services,
    OFBIZ-8420 --> createDataCategory
    OFBIZ-8421 --> updateDataCategory
    OFBIZ-8422 --> removeDataCategory
    OFBIZ-8424 --> createDataResourceRole
    OFBIZ-8425 --> updateDataResourceRole
    OFBIZ-8426 --> removeDataResourceRole
   
    Thanks, Tanmay Muley for reporting the issue.
---
 .../org/apache/ofbiz/content/ContentTests.groovy   | 141 +++++++++++++++++++++
 1 file changed, 141 insertions(+)

diff --git a/applications/content/src/main/groovy/org/apache/ofbiz/content/ContentTests.groovy b/applications/content/src/main/groovy/org/apache/ofbiz/content/ContentTests.groovy
index bf932d7..3ef4b5d 100644
--- a/applications/content/src/main/groovy/org/apache/ofbiz/content/ContentTests.groovy
+++ b/applications/content/src/main/groovy/org/apache/ofbiz/content/ContentTests.groovy
@@ -18,6 +18,9 @@
  *******************************************************************************/
 package org.apache.ofbiz.content
 
+import org.apache.ofbiz.base.util.UtilDateTime
+import org.apache.ofbiz.base.util.UtilMisc
+import org.apache.ofbiz.entity.GenericValue
 import org.apache.ofbiz.service.ServiceUtil
 import org.apache.ofbiz.service.testtools.OFBizTestCase
 
@@ -35,4 +38,142 @@ class ContentTests extends OFBizTestCase {
         assert serviceResult.resultData.dataResource.dataResourceId == 'TEST_RESOURCE'
         assert serviceResult.resultData.dataResource.dataResourceTypeId == 'TEST_RESOURCE_TYPE'
     }
+
+    void testCreateDataCategory() {
+        Map serviceCtx = [:]
+        serviceCtx.dataCategoryId = 'TEST_DATA_CATEGORY_1'
+        serviceCtx.categoryName = 'Test Data Category 1'
+        serviceCtx.userLogin = userLogin
+        Map serviceResult = dispatcher.runSync('createDataCategory', serviceCtx)
+        assert ServiceUtil.isSuccess(serviceResult)
+
+        GenericValue dataCategory = from('DataCategory')
+                .where('dataCategoryId', 'TEST_DATA_CATEGORY_1')
+                .queryOne()
+        assert dataCategory
+        assert 'Test Data Category 1'.equals(dataCategory.categoryName)
+    }
+
+    void testUpdateDataCategory() {
+        Map serviceCtx = [:]
+        serviceCtx.dataCategoryId = 'TEST_DATA_CATEGORY_2'
+        serviceCtx.categoryName = 'Test Data Category 2'
+        serviceCtx.userLogin = userLogin
+        Map serviceResult = dispatcher.runSync('createDataCategory', serviceCtx)
+        assert ServiceUtil.isSuccess(serviceResult)
+
+        serviceCtx.clear()
+        serviceCtx.dataCategoryId = 'TEST_DATA_CATEGORY_2'
+        serviceCtx.categoryName = 'Test Data Category 20'
+        serviceCtx.userLogin = userLogin
+        serviceResult = dispatcher.runSync('updateDataCategory', serviceCtx)
+        assert ServiceUtil.isSuccess(serviceResult)
+
+        GenericValue dataCategory = from('DataCategory')
+                .where('categoryName', 'Test Data Category 2')
+                .queryFirst()
+        assert !dataCategory
+
+        dataCategory = from('DataCategory')
+                .where('categoryName', 'Test Data Category 20')
+                .queryFirst()
+        assert dataCategory
+    }
+
+    void testDeleteDataCategory() {
+        Map serviceCtx = [:]
+        serviceCtx.dataCategoryId = 'TEST_DATA_CATEGORY_3'
+        serviceCtx.categoryName = 'Test Data Category 3'
+        serviceCtx.userLogin = userLogin
+        Map serviceResult = dispatcher.runSync('createDataCategory', serviceCtx)
+        assert ServiceUtil.isSuccess(serviceResult)
+
+        serviceCtx.clear()
+        serviceCtx.dataCategoryId = 'TEST_DATA_CATEGORY_3'
+        serviceCtx.userLogin = userLogin
+        serviceResult = dispatcher.runSync('removeDataCategory', serviceCtx)
+        assert ServiceUtil.isSuccess(serviceResult)
+
+        GenericValue dataCategory = from('DataCategory')
+                .where('dataCategoryId', 'TEST_DATA_CATEGORY_3')
+                .queryOne()
+        assert !dataCategory
+    }
+
+    void testCreateDataResourceRole() {
+        Map serviceCtx = [:]
+        serviceCtx.dataResourceId = 'TEST_DATA_RESOURCE_1'
+        serviceCtx.userLogin = userLogin
+        Map serviceResult = dispatcher.runSync('createDataResource', serviceCtx)
+        assert ServiceUtil.isSuccess(serviceResult)
+
+        serviceCtx.partyId = 'admin'
+        serviceCtx.roleTypeId = 'OWNER'
+        serviceCtx.fromDate = UtilDateTime.toTimestamp("11/03/2016 00:00:00")
+        serviceResult = dispatcher.runSync('createDataResourceRole', serviceCtx)
+        assert ServiceUtil.isSuccess(serviceResult)
+
+        GenericValue dataResourceRole = from('DataResourceRole')
+                .where('dataResourceId', 'TEST_DATA_RESOURCE_1', 'partyId', 'admin', 'roleTypeId', 'OWNER',
+                'fromDate', UtilDateTime.toTimestamp("11/03/2016 00:00:00"))
+                .queryOne()
+        assert dataResourceRole
+    }
+
+    void testUpdateDataResourceRole() {
+        Map serviceCtx = [:]
+        serviceCtx.dataResourceId = 'TEST_DATA_RESOURCE_2'
+        serviceCtx.userLogin = userLogin
+        Map serviceResult = dispatcher.runSync('createDataResource', serviceCtx)
+        assert ServiceUtil.isSuccess(serviceResult)
+
+        serviceCtx.partyId = 'admin'
+        serviceCtx.roleTypeId = 'OWNER'
+        serviceCtx.fromDate = UtilDateTime.toTimestamp("11/03/2016 00:00:00")
+        serviceResult = dispatcher.runSync('createDataResourceRole', serviceCtx)
+        assert ServiceUtil.isSuccess(serviceResult)
+
+        GenericValue dataResourceRole = from('DataResourceRole')
+                .where('dataResourceId', 'TEST_DATA_RESOURCE_2', 'partyId', 'admin')
+                .queryOne()
+        assert dataResourceRole
+        assert !dataResourceRole.thruDate
+
+        serviceCtx.thruDate = UtilDateTime.nowTimestamp()
+        serviceResult = dispatcher.runSync('updateDataResourceRole', serviceCtx)
+        assert ServiceUtil.isSuccess(serviceResult)
+
+        dataResourceRole = from('DataResourceRole')
+                .where('dataResourceId', 'TEST_DATA_RESOURCE_2', 'partyId', 'admin')
+                .queryOne()
+        assert dataResourceRole
+        assert dataResourceRole.thruDate
+    }
+
+    void testRemoveDataResourceRole() {
+        Map serviceCtx = [:]
+        serviceCtx.dataResourceId = 'TEST_DATA_RESOURCE_3'
+        serviceCtx.userLogin = userLogin
+        Map serviceResult = dispatcher.runSync('createDataResource', serviceCtx)
+        assert ServiceUtil.isSuccess(serviceResult)
+
+        serviceCtx.partyId = 'admin'
+        serviceCtx.roleTypeId = 'OWNER'
+        serviceCtx.fromDate = UtilDateTime.nowTimestamp()
+        serviceResult = dispatcher.runSync('createDataResourceRole', serviceCtx)
+        assert ServiceUtil.isSuccess(serviceResult)
+
+        GenericValue dataResourceRole = from('DataResourceRole')
+                .where('dataResourceId', 'TEST_DATA_RESOURCE_3', 'partyId', 'admin')
+                .queryFirst()
+        assert dataResourceRole
+
+        serviceResult = dispatcher.runSync('removeDataResourceRole', serviceCtx)
+        assert ServiceUtil.isSuccess(serviceResult)
+
+        dataResourceRole = from('DataResourceRole')
+                .where('dataResourceId', 'TEST_DATA_RESOURCE_3', "partyId", "admin")
+                .queryFirst()
+        assert !dataResourceRole
+    }
 }