From a6e35170a7b48c37bd0fd108929f9e2c41389d66 Mon Sep 17 00:00:00 2001 From: kaibalya-fynarfin Date: Wed, 4 Sep 2024 12:54:01 +0530 Subject: [PATCH] FINERACT-2120: Add new global configuration - enable payment hub integration (#4043) --- .../db/changelog/tenant/changelog-tenant.xml | 1 + .../0147_enable_payment_hub_integration.xml | 42 +++++++++++++++++++ .../GlobalConfigurationTest.java | 42 +++++++++++++++++++ .../common/GlobalConfigurationHelper.java | 26 +++++++++++- 4 files changed, 109 insertions(+), 2 deletions(-) create mode 100644 fineract-provider/src/main/resources/db/changelog/tenant/parts/0147_enable_payment_hub_integration.xml diff --git a/fineract-provider/src/main/resources/db/changelog/tenant/changelog-tenant.xml b/fineract-provider/src/main/resources/db/changelog/tenant/changelog-tenant.xml index cf753dc26..6d9c8aaf1 100644 --- a/fineract-provider/src/main/resources/db/changelog/tenant/changelog-tenant.xml +++ b/fineract-provider/src/main/resources/db/changelog/tenant/changelog-tenant.xml @@ -165,4 +165,5 @@ + diff --git a/fineract-provider/src/main/resources/db/changelog/tenant/parts/0147_enable_payment_hub_integration.xml b/fineract-provider/src/main/resources/db/changelog/tenant/parts/0147_enable_payment_hub_integration.xml new file mode 100644 index 000000000..cac890a89 --- /dev/null +++ b/fineract-provider/src/main/resources/db/changelog/tenant/parts/0147_enable_payment_hub_integration.xml @@ -0,0 +1,42 @@ + + + + + + SELECT SETVAL('c_configuration_id_seq', COALESCE(MAX(id), 0)+1, false ) FROM c_configuration; + + + + + + + + + + + + + + + diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/GlobalConfigurationTest.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/GlobalConfigurationTest.java index 51d6a15de..d536a396a 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/GlobalConfigurationTest.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/GlobalConfigurationTest.java @@ -111,6 +111,48 @@ public class GlobalConfigurationTest { } } + @Test + public void testGlobalConfigurationsEnableDisable() { + this.globalConfigurationHelper = new GlobalConfigurationHelper(this.requestSpec, this.responseSpec); + + // Retrieving All Global Configuration details + final ArrayList globalConfig = GlobalConfigurationHelper.getAllGlobalConfigurations(this.requestSpec, this.responseSpec); + Assertions.assertNotNull(globalConfig); + String configName = "enable_payment_hub_integration"; + for (Integer configIndex = 0; configIndex < globalConfig.size() - 1; configIndex++) { + if (globalConfig.get(configIndex).get("name").equals(configName)) { + Integer configId = (Integer) globalConfig.get(configIndex).get("id"); + Assertions.assertNotNull(configId); + + HashMap configDataBefore = GlobalConfigurationHelper.getGlobalConfigurationById(this.requestSpec, this.responseSpec, + configId.toString()); + Assertions.assertNotNull(configDataBefore); + + Integer value = (Integer) configDataBefore.get("value") + 1; + + // Updating Enabled Flag for use-payment-hub Global + // Configuration + Boolean enabled = (Boolean) globalConfig.get(configIndex).get("enabled"); + + if (enabled == true) { + enabled = false; + } else { + enabled = true; + } + + configId = GlobalConfigurationHelper.updateEnabledFlagForGlobalConfiguration(this.requestSpec, this.responseSpec, + configId.toString(), enabled); + + HashMap configDataAfter = GlobalConfigurationHelper.getGlobalConfigurationById(this.requestSpec, this.responseSpec, + configId.toString()); + + // Verifying Enabled Flag for use-payment-hub after Updation + Assertions.assertEquals(enabled, configDataAfter.get("enabled"), "Verifying Enabled Flag Global Config after Updation"); + break; + } + } + } + @Test public void testGlobalConfigurationIsCacheEnabled() { this.globalConfigurationHelper = new GlobalConfigurationHelper(this.requestSpec, this.responseSpec); diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/GlobalConfigurationHelper.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/GlobalConfigurationHelper.java index 1e49b10ae..98049242c 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/GlobalConfigurationHelper.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/GlobalConfigurationHelper.java @@ -119,8 +119,8 @@ public class GlobalConfigurationHelper { ArrayList expectedGlobalConfigurations = getAllDefaultGlobalConfigurations(); ArrayList actualGlobalConfigurations = getAllGlobalConfigurations(requestSpec, responseSpec); - Assertions.assertEquals(54, expectedGlobalConfigurations.size()); - Assertions.assertEquals(54, actualGlobalConfigurations.size()); + Assertions.assertEquals(55, expectedGlobalConfigurations.size()); + Assertions.assertEquals(55, actualGlobalConfigurations.size()); for (int i = 0; i < expectedGlobalConfigurations.size(); i++) { @@ -590,6 +590,15 @@ public class GlobalConfigurationHelper { nextPaymentDateConfigForLoan.put("string_value", "earliest-unpaid-date"); defaults.add(nextPaymentDateConfigForLoan); + HashMap enablePaymentHubIntegrationConfig = new HashMap<>(); + enablePaymentHubIntegrationConfig.put("id", 60); + enablePaymentHubIntegrationConfig.put("name", "enable-payment-hub-integration"); + enablePaymentHubIntegrationConfig.put("value", 0); + enablePaymentHubIntegrationConfig.put("enabled", false); + enablePaymentHubIntegrationConfig.put("trapDoor", false); + enablePaymentHubIntegrationConfig.put("string_value", "enable payment hub integration"); + defaults.add(enablePaymentHubIntegrationConfig); + return defaults; } @@ -735,4 +744,17 @@ public class GlobalConfigurationHelper { } + public static Integer updateEnablePaymentHubIntegrationConfiguration(final RequestSpecification requestSpec, + final ResponseSpecification responseSpec, final String stringValue) { + long configId = 60; + final HashMap map = new HashMap<>(); + map.put("stringValue", stringValue); + log.info("map : {}", map); + final String configValue = GSON.toJson(map); + final String GLOBAL_CONFIG_UPDATE_URL = "/fineract-provider/api/v1/configurations/" + configId + "?" + Utils.TENANT_IDENTIFIER; + log.info("---------------------------------UPDATE VALUE FOR GLOBAL CONFIG---------------------------------------------"); + return Utils.performServerPut(requestSpec, responseSpec, GLOBAL_CONFIG_UPDATE_URL, configValue, "resourceId"); + + } + }