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

aleks pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract.git


The following commit(s) were added to refs/heads/develop by this push:
     new 45264ea  FINERACT-984: Test improvements to not rely on database 
storage ordering and some database independent query implementations
45264ea is described below

commit 45264ea209318a13706f861d4ae5871f79adbd96
Author: Arnold Galovics <[email protected]>
AuthorDate: Sun Feb 20 12:55:01 2022 +0100

    FINERACT-984: Test improvements to not rely on database storage ordering 
and some database independent query implementations
---
 .../useradministration/domain/PermissionRepository.java        |  6 ++++++
 .../fineract/useradministration/domain/RoleRepository.java     |  2 +-
 .../service/AppUserReadPlatformServiceImpl.java                |  4 ++--
 .../service/AppUserWritePlatformServiceJpaRepositoryImpl.java  |  4 ++--
 .../service/PermissionReadPlatformServiceImpl.java             |  8 ++++----
 .../service/RoleReadPlatformServiceImpl.java                   |  2 +-
 .../fineract/integrationtests/CenterIntegrationTest.java       |  2 +-
 .../integrationtests/CreditBureauConfigurationTest.java        |  4 ++--
 .../apache/fineract/integrationtests/common/CenterHelper.java  |  9 +++++++++
 .../common/CreditBureauConfigurationHelper.java                | 10 +++++-----
 10 files changed, 33 insertions(+), 18 deletions(-)

diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/useradministration/domain/PermissionRepository.java
 
b/fineract-provider/src/main/java/org/apache/fineract/useradministration/domain/PermissionRepository.java
index f3fd71b..6a9f2f8 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/useradministration/domain/PermissionRepository.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/useradministration/domain/PermissionRepository.java
@@ -19,8 +19,14 @@
 package org.apache.fineract.useradministration.domain;
 
 import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Query;
 
 public interface PermissionRepository extends JpaRepository<Permission, Long> {
 
+    // It's important to use the same case for equality check because there 
are cases when the codes are not capitalized
+    // the same way. (UNDOTRANSACTION_CLIENT vs UNDOTRANSACTION_client)
+    // Also, trimming leading and trailing spaces is critical 
("CREATE_STANDINGINSTRUCTION" vs
+    // "CREATE_STANDINGINSTRUCTION ").
+    @Query("SELECT p FROM Permission p WHERE LOWER(TRIM(BOTH FROM p.code)) = 
LOWER(TRIM(BOTH FROM ?1))")
     Permission findOneByCode(String code);
 }
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/useradministration/domain/RoleRepository.java
 
b/fineract-provider/src/main/java/org/apache/fineract/useradministration/domain/RoleRepository.java
index 6368c41..832286e 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/useradministration/domain/RoleRepository.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/useradministration/domain/RoleRepository.java
@@ -28,7 +28,7 @@ public interface RoleRepository extends JpaRepository<Role, 
Long>, JpaSpecificat
     @Query("SELECT COUNT(a) FROM AppUser a JOIN a.roles r WHERE r.id = :roleId 
AND a.deleted = false")
     Integer getCountOfRolesAssociatedWithUsers(@Param("roleId") Long roleId);
 
-    @Query("SELECT role FROM Role role WHERE role.name = :name")
+    @Query("SELECT role FROM Role role WHERE LOWER(role.name) = LOWER(:name)")
     Role getRoleByName(@Param("name") String name);
 
 }
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/AppUserReadPlatformServiceImpl.java
 
b/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/AppUserReadPlatformServiceImpl.java
index ac37343..f0432ad 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/AppUserReadPlatformServiceImpl.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/AppUserReadPlatformServiceImpl.java
@@ -193,7 +193,7 @@ public class AppUserReadPlatformServiceImpl implements 
AppUserReadPlatformServic
         public String schema() {
             return " u.id as id, u.username as username, u.firstname as 
firstname, u.lastname as lastname, u.email as email, u.password_never_expires 
as passwordNeverExpires, "
                     + " u.office_id as officeId, o.name as officeName, 
u.staff_id as staffId, u.is_self_service_user as isSelfServiceUser from 
m_appuser u "
-                    + " join m_office o on o.id = u.office_id where 
o.hierarchy like ? and u.is_deleted=0 order by u.username";
+                    + " join m_office o on o.id = u.office_id where 
o.hierarchy like ? and u.is_deleted=false order by u.username";
         }
 
     }
@@ -211,7 +211,7 @@ public class AppUserReadPlatformServiceImpl implements 
AppUserReadPlatformServic
 
         public String schema() {
             return " u.id as id, u.username as username from m_appuser u "
-                    + " join m_office o on o.id = u.office_id where 
o.hierarchy like ? and u.is_deleted=0 order by u.username";
+                    + " join m_office o on o.id = u.office_id where 
o.hierarchy like ? and u.is_deleted=false order by u.username";
         }
     }
 
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/AppUserWritePlatformServiceJpaRepositoryImpl.java
 
b/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/AppUserWritePlatformServiceJpaRepositoryImpl.java
index 4826795..607ac06 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/AppUserWritePlatformServiceJpaRepositoryImpl.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/AppUserWritePlatformServiceJpaRepositoryImpl.java
@@ -317,7 +317,7 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl 
implements AppUserWrit
         // TODO: this needs to be fixed. The error condition should be 
independent from the underlying message and
         // naming
         // of the constraint
-        if (realCause.getMessage().contains("'username_org'")) {
+        if (realCause.getMessage().contains("username_org")) {
             final String username = 
command.stringValueOfParameterNamed("username");
             final StringBuilder defaultMessageBuilder = new 
StringBuilder("User with username ").append(username)
                     .append(" already exists.");
@@ -328,7 +328,7 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl 
implements AppUserWrit
         // TODO: this needs to be fixed. The error condition should be 
independent from the underlying message and
         // naming
         // of the constraint
-        if (realCause.getMessage().contains("'unique_self_client'")) {
+        if (realCause.getMessage().contains("unique_self_client")) {
             return new 
PlatformDataIntegrityException("error.msg.user.self.service.user.already.exist",
                     "Self Service User Id is already created. Go to 
Admin->Users to edit or delete the self-service user.");
         }
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/PermissionReadPlatformServiceImpl.java
 
b/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/PermissionReadPlatformServiceImpl.java
index c1b57e9..fdb03ab 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/PermissionReadPlatformServiceImpl.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/PermissionReadPlatformServiceImpl.java
@@ -96,7 +96,7 @@ public class PermissionReadPlatformServiceImpl implements 
PermissionReadPlatform
             /* get all non-CHECKER permissions */
             return "select p.grouping, p.code, p.entity_name as entityName, 
p.action_name as actionName, true as selected"
                     + " from m_permission p " + " where code not like 
'%\\_CHECKER'"
-                    + " order by p.grouping, ifnull(entity_name, ''), p.code";
+                    + " order by p.grouping, coalesce(entity_name, ''), 
p.code";
         }
 
         public String makerCheckerablePermissionSchema() {
@@ -107,13 +107,13 @@ public class PermissionReadPlatformServiceImpl implements 
PermissionReadPlatform
 
             return "select p.grouping, p.code, p.entity_name as entityName, 
p.action_name as actionName, p.can_maker_checker as selected"
                     + " from m_permission p " + " where `grouping` != 
'special' and code not like 'READ_%' and code not like '%\\_CHECKER'"
-                    + " order by p.grouping, ifnull(entity_name, ''), p.code";
+                    + " order by p.grouping, coalesce(entity_name, ''), 
p.code";
         }
 
         public String rolePermissionSchema() {
-            return "select p.grouping, p.code, p.entity_name as entityName, 
p.action_name as actionName, if(isnull(rp.role_id), false, true) as selected "
+            return "select p.grouping, p.code, p.entity_name as entityName, 
p.action_name as actionName, rp.role_id IS NOT NULL as selected "
                     + " from m_permission p " + " left join m_role_permission 
rp on rp.permission_id = p.id and rp.role_id = ? "
-                    + " order by p.grouping, ifnull(entity_name, ''), p.code";
+                    + " order by p.grouping, COALESCE(entity_name, ''), 
p.code";
         }
     }
 
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/RoleReadPlatformServiceImpl.java
 
b/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/RoleReadPlatformServiceImpl.java
index a00fb99..ea3b74f 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/RoleReadPlatformServiceImpl.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/useradministration/service/RoleReadPlatformServiceImpl.java
@@ -53,7 +53,7 @@ public class RoleReadPlatformServiceImpl implements 
RoleReadPlatformService {
 
     @Override
     public Collection<RoleData> retrieveAllActiveRoles() {
-        final String sql = "select " + this.roleRowMapper.schema() + " where 
r.is_disabled = 0 order by r.id";
+        final String sql = "select " + this.roleRowMapper.schema() + " where 
r.is_disabled = false order by r.id";
 
         return this.jdbcTemplate.query(sql, this.roleRowMapper);
     }
diff --git 
a/integration-tests/src/test/java/org/apache/fineract/integrationtests/CenterIntegrationTest.java
 
b/integration-tests/src/test/java/org/apache/fineract/integrationtests/CenterIntegrationTest.java
index 22a35a4..4259296 100644
--- 
a/integration-tests/src/test/java/org/apache/fineract/integrationtests/CenterIntegrationTest.java
+++ 
b/integration-tests/src/test/java/org/apache/fineract/integrationtests/CenterIntegrationTest.java
@@ -113,7 +113,7 @@ public class CenterIntegrationTest {
 
     @Test
     public void testVoidCenterRetrieval() {
-        ArrayList<CenterDomain> arr = CenterHelper.listCenters(requestSpec, 
responseSpec);
+        ArrayList<CenterDomain> arr = 
CenterHelper.listCentersOrdered(requestSpec, responseSpec);
         int id = arr.get(arr.size() - 1).getId() + 1;
         ResponseSpecification responseSpec = new 
ResponseSpecBuilder().expectStatusCode(404).build();
         CenterDomain center = CenterHelper.retrieveByID(id, requestSpec, 
responseSpec);
diff --git 
a/integration-tests/src/test/java/org/apache/fineract/integrationtests/CreditBureauConfigurationTest.java
 
b/integration-tests/src/test/java/org/apache/fineract/integrationtests/CreditBureauConfigurationTest.java
index 9d49224..70a01a3 100644
--- 
a/integration-tests/src/test/java/org/apache/fineract/integrationtests/CreditBureauConfigurationTest.java
+++ 
b/integration-tests/src/test/java/org/apache/fineract/integrationtests/CreditBureauConfigurationTest.java
@@ -56,8 +56,8 @@ public class CreditBureauConfigurationTest {
     public void creditBureauConfigurationTest() {
 
         // create creditBureauConfiguration
-        final Integer configurationId = 
CreditBureauConfigurationHelper.createCreditBureauConfiguration(this.requestSpec,
-                this.responseSpec);
+        final Integer configurationId = 
CreditBureauConfigurationHelper.createCreditBureauConfiguration(this.requestSpec,
 this.responseSpec,
+                Utils.randomNameGenerator("testConfigKey_", 5));
         Assertions.assertNotNull(configurationId);
 
         // update creditBureauConfiguration
diff --git 
a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/CenterHelper.java
 
b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/CenterHelper.java
index 09816cb..b136569 100644
--- 
a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/CenterHelper.java
+++ 
b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/CenterHelper.java
@@ -68,6 +68,15 @@ public final class CenterHelper {
         return new Gson().fromJson(jsonData, new 
TypeToken<ArrayList<CenterDomain>>() {}.getType());
     }
 
+    public static ArrayList<CenterDomain> listCentersOrdered(final 
RequestSpecification requestSpec,
+            final ResponseSpecification responseSpec) {
+        final String GET_CENTER = CENTERS_URL + 
"?limit=-1&orderBy=id&sortOrder=asc&" + Utils.TENANT_IDENTIFIER;
+        LOG.info("------------------------ RETRIEVING 
CENTERS-------------------------");
+        Object get = Utils.performServerGet(requestSpec, responseSpec, 
GET_CENTER, "");
+        final String jsonData = new Gson().toJson(get);
+        return new Gson().fromJson(jsonData, new 
TypeToken<ArrayList<CenterDomain>>() {}.getType());
+    }
+
     public static int createCenter(final String name, final int officeId, 
final RequestSpecification requestSpec,
             final ResponseSpecification responseSpec) {
         return createCenter(name, officeId, null, -1, null, null, requestSpec, 
responseSpec);
diff --git 
a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/CreditBureauConfigurationHelper.java
 
b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/CreditBureauConfigurationHelper.java
index 41dda39..62c68d9 100644
--- 
a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/CreditBureauConfigurationHelper.java
+++ 
b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/CreditBureauConfigurationHelper.java
@@ -40,18 +40,18 @@ public class CreditBureauConfigurationHelper {
         this.responseSpec = responseSpec;
     }
 
-    public static Integer createCreditBureauConfiguration(final 
RequestSpecification requestSpec,
-            final ResponseSpecification responseSpec) {
-        return createCreditBureauConfiguration(requestSpec, responseSpec, "1");
+    public static Integer createCreditBureauConfiguration(final 
RequestSpecification requestSpec, final ResponseSpecification responseSpec,
+            String configKey) {
+        return createCreditBureauConfiguration(requestSpec, responseSpec, "1", 
configKey);
     }
 
     public static Integer createCreditBureauConfiguration(final 
RequestSpecification requestSpec, final ResponseSpecification responseSpec,
-            final String creditBureauId) {
+            final String creditBureauId, String configKey) {
         LOG.info("---------------------------------CREATING A 
CREDIT_BUREAU_CONFIGURATION---------------------------------------------");
         final String CREDITBUREAU_CONFIGURATION_URL = " 
/fineract-provider/api/v1/CreditBureauConfiguration/configuration/" + 
creditBureauId
                 + "?" + Utils.TENANT_IDENTIFIER;
         return Utils.performServerPost(requestSpec, responseSpec, 
CREDITBUREAU_CONFIGURATION_URL,
-                creditBureauConfigurationAsJson("testConfigKey", 
"testConfigKeyValue", "description"), "resourceId");
+                creditBureauConfigurationAsJson(configKey, 
"testConfigKeyValue", "description"), "resourceId");
     }
 
     /*

Reply via email to