From 0e8570c1b86866b47595016e9cfc50028869152b Mon Sep 17 00:00:00 2001 From: elnafateh Date: Fri, 5 Jun 2026 15:52:26 +0100 Subject: [PATCH] FINERACT-2165: Migrate event, provisioning, and standing instruction helpers to fineract-client-feign --- .../client/feign/ObjectMapperFactory.java | 27 + ...rovisioningCriteriaApiResourceSwagger.java | 6 +- ...StandingInstructionApiResourceSwagger.java | 34 +- .../CustomSnapshotEventIntegrationTest.java | 18 +- .../ExternalBusinessEventTest.java | 88 +- ...rnalEventConfigurationIntegrationTest.java | 6 +- ...ementToSavingsWithAutoDownPaymentTest.java | 7 +- .../SchedulerJobsTestResults.java | 18 +- .../tests/FeignProvisioningEntryTest.java | 35 +- .../ExternalEventConfigurationHelper.java | 756 +----------------- .../common/ProvisioningIntegrationTest.java | 127 ++- .../common/StandingInstructionsHelper.java | 129 +-- .../externalevents/ExternalEventHelper.java | 76 +- .../ExternalEventsExtension.java | 3 +- .../externalevents/LoanBusinessEvent.java | 7 +- .../LoanTransactionBusinessEvent.java | 14 +- .../provisioning/ProvisioningHelper.java | 158 ++-- .../ProvisioningTransactionHelper.java | 131 +-- 18 files changed, 420 insertions(+), 1220 deletions(-) diff --git a/fineract-client-feign/src/main/java/org/apache/fineract/client/feign/ObjectMapperFactory.java b/fineract-client-feign/src/main/java/org/apache/fineract/client/feign/ObjectMapperFactory.java index 5c2d2c0f61a..63eea754c94 100644 --- a/fineract-client-feign/src/main/java/org/apache/fineract/client/feign/ObjectMapperFactory.java +++ b/fineract-client-feign/src/main/java/org/apache/fineract/client/feign/ObjectMapperFactory.java @@ -18,10 +18,15 @@ */ package org.apache.fineract.client.feign; +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.databind.deser.DeserializationProblemHandler; +import com.fasterxml.jackson.databind.deser.ValueInstantiator; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import org.apache.fineract.client.adapter.ExternalIdAdapter; import org.openapitools.jackson.nullable.JsonNullableModule; @@ -62,6 +67,28 @@ public static ObjectMapper createObjectMapper() { // Disable FAIL_ON_EMPTY_BEANS for empty responses mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); + // Only serialize the 'id' field of LoanProductData to avoid sending unsupported parameters + // LoanProductData constructor initializes many empty collections which would be rejected by the server + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE, getterVisibility = JsonAutoDetect.Visibility.NONE, isGetterVisibility = JsonAutoDetect.Visibility.NONE) + abstract class LoanProductDataMixin { + + @com.fasterxml.jackson.annotation.JsonProperty("id") + abstract Long getId(); + } + mapper.addMixIn(org.apache.fineract.client.models.LoanProductData.class, LoanProductDataMixin.class); + + // Handle cases where server returns a plain string for a field the model expects as POJO + // e.g. "fromAccountType": "SAVINGS" instead of {"id":2,"code":"accountType.savings","value":"Savings Account"} + mapper.addHandler(new DeserializationProblemHandler() { + + @Override + public Object handleMissingInstantiator(DeserializationContext ctxt, Class instClass, ValueInstantiator valueInst, + com.fasterxml.jackson.core.JsonParser p, String msg) throws java.io.IOException { + p.skipChildren(); + return null; + } + }); return mapper; } diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/provisioning/api/ProvisioningCriteriaApiResourceSwagger.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/provisioning/api/ProvisioningCriteriaApiResourceSwagger.java index afe7f739ddb..664846b134e 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/provisioning/api/ProvisioningCriteriaApiResourceSwagger.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/provisioning/api/ProvisioningCriteriaApiResourceSwagger.java @@ -42,7 +42,7 @@ private PostProvisioningCriteriaRequest() { @Schema(example = "High Risk Products Criteria") public String criteriaName; public Collection loanProducts; - public Collection provisioningcriteria; + public Collection definitions; } @Schema(description = "PostProvisioningCriteriaResponse") @@ -85,7 +85,7 @@ private GetProvisioningCriteriaCriteriaIdResponse() { @Schema(example = "mifos") public String createdBy; public Collection loanProducts; - public Collection provisioningcriteria; + public Collection definitions; } @Schema(description = "PutProvisioningCriteriaRequest") @@ -98,7 +98,7 @@ private PutProvisioningCriteriaRequest() { @Schema(example = "High Risk Products Criteria") public String criteriaName; public Collection loanProducts; - public Collection provisioningcriteria; + public Collection definitions; } @Schema(description = "PutProvisioningCriteriaResponse") diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/api/StandingInstructionApiResourceSwagger.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/api/StandingInstructionApiResourceSwagger.java index 60649d0cf9b..2a13f494e56 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/api/StandingInstructionApiResourceSwagger.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/account/api/StandingInstructionApiResourceSwagger.java @@ -63,7 +63,7 @@ private GetFromAccountTypeResponseStandingInstructionSwagger() {} @Schema(example = "accountType.savings") public String code; @Schema(example = "Savings Account") - public String description; + public String value; } static final class GetFromOfficeOptionsResponseStandingInstructionSwagger { @@ -101,7 +101,7 @@ private GetFromAccountTypeOptionsResponseStandingInstructionSwagger() {} @Schema(example = "accountType.savings") public String code; @Schema(example = "Savings Account") - public String description; + public String value; } static final class GetToOfficeOptionsResponseStandingInstructionSwagger { @@ -125,7 +125,7 @@ private GetToAccountTypeOptionsResponseStandingInstructionSwagger() {} @Schema(example = "accountType.loan") public String code; @Schema(example = "Loan Account") - public String description; + public String value; } static final class GetTransferTypeOptionsResponseStandingInstructionSwagger { @@ -137,7 +137,7 @@ private GetTransferTypeOptionsResponseStandingInstructionSwagger() {} @Schema(example = "accountTransferType.account.transfer") public String code; @Schema(example = "Account Transfer") - public String description; + public String value; } static final class GetStatusOptionsResponseStandingInstructionSwagger { @@ -149,7 +149,7 @@ private GetStatusOptionsResponseStandingInstructionSwagger() {} @Schema(example = "standingInstructionStatus.active") public String code; @Schema(example = "Active") - public String description; + public String value; } static final class GetInstructionTypeOptionsResponseStandingInstructionSwagger { @@ -161,7 +161,7 @@ private GetInstructionTypeOptionsResponseStandingInstructionSwagger() {} @Schema(example = "standingInstructionType.fixed") public String code; @Schema(example = "Fixed") - public String description; + public String value; } static final class GetPriorityOptionsResponseStandingInstructionSwagger { @@ -173,7 +173,7 @@ private GetPriorityOptionsResponseStandingInstructionSwagger() {} @Schema(example = "standingInstructionPriority.urgent") public String code; @Schema(example = "Urgent Priority") - public String description; + public String value; } static final class GetRecurrenceTypeOptionsResponseStandingInstructionSwagger { @@ -185,7 +185,7 @@ private GetRecurrenceTypeOptionsResponseStandingInstructionSwagger() {} @Schema(example = "accountTransferRecurrenceType.periodic") public String code; @Schema(example = "Periodic Recurrence") - public String description; + public String value; } static final class GetRecurrenceFrequencyOptionsResponseStandingInstructionSwagger { @@ -197,7 +197,7 @@ private GetRecurrenceFrequencyOptionsResponseStandingInstructionSwagger() {} @Schema(example = "frequencyperiodFrequencyType.days") public String code; @Schema(example = "Days") - public String description; + public String value; } public GetFromOfficeResponseStandingInstructionSwagger fromOffice; @@ -266,7 +266,7 @@ private GetFromAccountTypeStandingInstructionSwagger() {} @Schema(example = "accountType.savings") public String code; @Schema(example = "Savings Account") - public String description; + public String value; } static final class GetFromAccountStandingInstructionSwagger { @@ -316,7 +316,7 @@ private GetToAccountTypeStandingInstructionSwagger() {} @Schema(example = "accountType.savings") public String code; @Schema(example = "Savings Account") - public String description; + public String value; } static final class GetToAccountStandingInstructionSwagger { @@ -342,7 +342,7 @@ private GetTransferTypeStandingInstructionSwagger() {} @Schema(example = "accountTransferType.account.transfer") public String code; @Schema(example = "Account Transfer") - public String description; + public String value; } static final class GetPriorityStandingInstructionSwagger { @@ -354,7 +354,7 @@ private GetPriorityStandingInstructionSwagger() {} @Schema(example = "standingInstructionPriority.medium") public String code; @Schema(example = "Medium Priority") - public String description; + public String value; } static final class GetInstructionTypeStandingInstructionSwagger { @@ -366,7 +366,7 @@ private GetInstructionTypeStandingInstructionSwagger() {} @Schema(example = "standingInstructionType.fixed") public String code; @Schema(example = "Fixed") - public String description; + public String value; } static final class GetStatusStandingInstructionSwagger { @@ -378,7 +378,7 @@ private GetStatusStandingInstructionSwagger() {} @Schema(example = "standingInstructionStatus.deleted") public String code; @Schema(example = "Deleted") - public String description; + public String value; } static final class GetRecurrenceTypeStandingInstructionSwagger { @@ -390,7 +390,7 @@ private GetRecurrenceTypeStandingInstructionSwagger() {} @Schema(example = "accountTransferRecurrenceType.periodic") public String code; @Schema(example = "Periodic Recurrence") - public String description; + public String value; } static final class GetRecurrenceFrequencyStandingInstructionSwagger { @@ -402,7 +402,7 @@ private GetRecurrenceFrequencyStandingInstructionSwagger() {} @Schema(example = "frequencyperiodFrequencyType.months") public String code; @Schema(example = "Months") - public String description; + public String value; } @Schema(example = "1") diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/CustomSnapshotEventIntegrationTest.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/CustomSnapshotEventIntegrationTest.java index 41e3487ebf3..a9857f8632b 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/CustomSnapshotEventIntegrationTest.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/CustomSnapshotEventIntegrationTest.java @@ -18,13 +18,12 @@ */ package org.apache.fineract.integrationtests; -import com.google.gson.Gson; import java.math.BigDecimal; -import java.util.HashMap; import java.util.List; import java.util.Map; import lombok.extern.slf4j.Slf4j; import org.apache.fineract.client.models.BusinessDateUpdateRequest; +import org.apache.fineract.client.models.ExternalEventConfigurationUpdateRequest; import org.apache.fineract.client.models.PostLoanProductsRequest; import org.apache.fineract.client.models.PostLoanProductsResponse; import org.apache.fineract.infrastructure.event.external.data.ExternalEventResponse; @@ -307,18 +306,10 @@ private void enableCOBBusinessStep(String... steps) { } - public static String getExternalEventConfigurationsForUpdateJSON() { - Map> configurationsForUpdate = new HashMap<>(); - Map configurations = new HashMap<>(); - configurations.put("CentersCreateBusinessEvent", true); - configurations.put("ClientActivateBusinessEvent", true); - configurationsForUpdate.put("externalEventConfigurations", configurations); - return new Gson().toJson(configurationsForUpdate); - } - private void enableLoanAccountCustomSnapshotBusinessEvent() { final Map updatedConfigurations = ExternalEventConfigurationHelper.updateExternalEventConfigurations(requestSpec, - responseSpec, "{\"externalEventConfigurations\":{\"LoanAccountCustomSnapshotBusinessEvent\":true}}\n"); + responseSpec, new ExternalEventConfigurationUpdateRequest() + .externalEventConfigurations(Map.of("LoanAccountCustomSnapshotBusinessEvent", true))); Assertions.assertEquals(updatedConfigurations.size(), 1); Assertions.assertTrue(updatedConfigurations.containsKey("LoanAccountCustomSnapshotBusinessEvent")); Assertions.assertTrue(updatedConfigurations.get("LoanAccountCustomSnapshotBusinessEvent")); @@ -326,7 +317,8 @@ private void enableLoanAccountCustomSnapshotBusinessEvent() { private void disableLoanAccountCustomSnapshotBusinessEvent() { final Map updatedConfigurations = ExternalEventConfigurationHelper.updateExternalEventConfigurations(requestSpec, - responseSpec, "{\"externalEventConfigurations\":{\"LoanAccountCustomSnapshotBusinessEvent\":false}}\n"); + responseSpec, new ExternalEventConfigurationUpdateRequest() + .externalEventConfigurations(Map.of("LoanAccountCustomSnapshotBusinessEvent", false))); Assertions.assertEquals(updatedConfigurations.size(), 1); Assertions.assertTrue(updatedConfigurations.containsKey("LoanAccountCustomSnapshotBusinessEvent")); Assertions.assertFalse(updatedConfigurations.get("LoanAccountCustomSnapshotBusinessEvent")); diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/ExternalBusinessEventTest.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/ExternalBusinessEventTest.java index e15de61e1ad..411ef03980e 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/ExternalBusinessEventTest.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/ExternalBusinessEventTest.java @@ -193,9 +193,9 @@ public void verifyLoanChargeAdjustmentPostBusinessEvent01() { Assertions.assertEquals(1, ((List) loanChargePaidByList).size()); Map chargePaidBy = (Map) ((List) loanChargePaidByList).get(0); Assertions.assertInstanceOf(Map.class, chargePaidBy); - Assertions.assertEquals(111.0D, chargePaidBy.get("amount")); - Assertions.assertEquals(chargeId.doubleValue(), chargePaidBy.get("chargeId")); - Assertions.assertEquals(transactionId.doubleValue(), chargePaidBy.get("transactionId")); + Assertions.assertEquals(111.0D, toDouble(chargePaidBy.get("amount"))); + Assertions.assertEquals(chargeId.doubleValue(), toDouble(chargePaidBy.get("chargeId"))); + Assertions.assertEquals(transactionId.doubleValue(), toDouble(chargePaidBy.get("transactionId"))); }); } @@ -235,9 +235,9 @@ public void verifyLoanChargeAdjustmentPostBusinessEvent02() { Assertions.assertEquals(1, ((List) loanChargePaidByList).size()); Map chargePaidBy = (Map) ((List) loanChargePaidByList).get(0); Assertions.assertInstanceOf(Map.class, chargePaidBy); - Assertions.assertEquals(69.0D, chargePaidBy.get("amount")); - Assertions.assertEquals(chargeId.doubleValue(), chargePaidBy.get("chargeId")); - Assertions.assertEquals(transactionId.doubleValue(), chargePaidBy.get("transactionId")); + Assertions.assertEquals(69.0D, toDouble(chargePaidBy.get("amount"))); + Assertions.assertEquals(chargeId.doubleValue(), toDouble(chargePaidBy.get("chargeId"))); + Assertions.assertEquals(transactionId.doubleValue(), toDouble(chargePaidBy.get("transactionId"))); // check second part deleteAllExternalEvents(); @@ -255,9 +255,9 @@ public void verifyLoanChargeAdjustmentPostBusinessEvent02() { Assertions.assertEquals(1, ((List) loanChargePaidByList).size()); chargePaidBy = (Map) ((List) loanChargePaidByList).get(0); Assertions.assertInstanceOf(Map.class, chargePaidBy); - Assertions.assertEquals(42.0D, chargePaidBy.get("amount")); - Assertions.assertEquals(chargeId.doubleValue(), chargePaidBy.get("chargeId")); - Assertions.assertEquals(transactionId.doubleValue(), chargePaidBy.get("transactionId")); + Assertions.assertEquals(42.0D, toDouble(chargePaidBy.get("amount"))); + Assertions.assertEquals(chargeId.doubleValue(), toDouble(chargePaidBy.get("chargeId"))); + Assertions.assertEquals(transactionId.doubleValue(), toDouble(chargePaidBy.get("transactionId"))); Assertions.assertFalse((Boolean) event.getPayLoad().get("reversed")); // check that third part cannot post for that charge, because it already fully adjusted @@ -297,14 +297,14 @@ public void verifyLoanChargeAdjustmentPostBusinessEvent03() { ExternalEventResponse event = list.get(0); log.info(event.toString()); Object loanChargePaidByList = event.getPayLoad().get("loanChargePaidByList"); - Assertions.assertEquals(111.0D, event.getPayLoad().get("feeChargesPortion")); + Assertions.assertEquals(111.0D, toDouble(event.getPayLoad().get("feeChargesPortion"))); Assertions.assertInstanceOf(List.class, loanChargePaidByList); Assertions.assertEquals(1, ((List) loanChargePaidByList).size()); Map chargePaidBy = (Map) ((List) loanChargePaidByList).get(0); Assertions.assertInstanceOf(Map.class, chargePaidBy); - Assertions.assertEquals(111.0D, chargePaidBy.get("amount")); - Assertions.assertEquals(chargeId.doubleValue(), chargePaidBy.get("chargeId")); - Assertions.assertEquals(transactionId.doubleValue(), chargePaidBy.get("transactionId")); + Assertions.assertEquals(111.0D, toDouble(chargePaidBy.get("amount"))); + Assertions.assertEquals(chargeId.doubleValue(), toDouble(chargePaidBy.get("chargeId"))); + Assertions.assertEquals(transactionId.doubleValue(), toDouble(chargePaidBy.get("transactionId"))); // check first part deleteAllExternalEvents(); @@ -378,9 +378,9 @@ public void verifyLoanChargeAdjustmentPostBusinessEvent04() { Assertions.assertEquals(1, ((List) loanChargePaidByList).size()); Map chargePaidBy = (Map) ((List) loanChargePaidByList).get(0); Assertions.assertInstanceOf(Map.class, chargePaidBy); - Assertions.assertEquals(111.0D, chargePaidBy.get("amount")); - Assertions.assertEquals(chargeId.doubleValue(), chargePaidBy.get("chargeId")); - Assertions.assertEquals(transactionId.doubleValue(), chargePaidBy.get("transactionId")); + Assertions.assertEquals(111.0D, toDouble(chargePaidBy.get("amount"))); + Assertions.assertEquals(chargeId.doubleValue(), toDouble(chargePaidBy.get("chargeId"))); + Assertions.assertEquals(transactionId.doubleValue(), toDouble(chargePaidBy.get("transactionId"))); }); } @@ -421,9 +421,9 @@ public void verifyLoanChargeAdjustmentPostBusinessEvent05() { Assertions.assertEquals(1, ((List) loanChargePaidByList).size()); Map chargePaidBy = (Map) ((List) loanChargePaidByList).get(0); Assertions.assertInstanceOf(Map.class, chargePaidBy); - Assertions.assertEquals(69.0D, chargePaidBy.get("amount")); - Assertions.assertEquals(chargeId.doubleValue(), chargePaidBy.get("chargeId")); - Assertions.assertEquals(transactionId.doubleValue(), chargePaidBy.get("transactionId")); + Assertions.assertEquals(69.0D, toDouble(chargePaidBy.get("amount"))); + Assertions.assertEquals(chargeId.doubleValue(), toDouble(chargePaidBy.get("chargeId"))); + Assertions.assertEquals(transactionId.doubleValue(), toDouble(chargePaidBy.get("transactionId"))); // check second part deleteAllExternalEvents(); @@ -441,9 +441,9 @@ public void verifyLoanChargeAdjustmentPostBusinessEvent05() { Assertions.assertEquals(1, ((List) loanChargePaidByList).size()); chargePaidBy = (Map) ((List) loanChargePaidByList).get(0); Assertions.assertInstanceOf(Map.class, chargePaidBy); - Assertions.assertEquals(42.0D, chargePaidBy.get("amount")); - Assertions.assertEquals(chargeId.doubleValue(), chargePaidBy.get("chargeId")); - Assertions.assertEquals(transactionId.doubleValue(), chargePaidBy.get("transactionId")); + Assertions.assertEquals(42.0D, toDouble(chargePaidBy.get("amount"))); + Assertions.assertEquals(chargeId.doubleValue(), toDouble(chargePaidBy.get("chargeId"))); + Assertions.assertEquals(transactionId.doubleValue(), toDouble(chargePaidBy.get("transactionId"))); // check that third part cannot post for that charge, because it already fully adjusted Assertions.assertThrows(RuntimeException.class, () -> loanTransactionHelper.chargeAdjustment(loanId, chargeId, @@ -483,14 +483,14 @@ public void verifyLoanChargeAdjustmentPostBusinessEvent06() { ExternalEventResponse event = list.get(0); log.info(event.toString()); Object loanChargePaidByList = event.getPayLoad().get("loanChargePaidByList"); - Assertions.assertEquals(111.0D, event.getPayLoad().get("feeChargesPortion")); + Assertions.assertEquals(111.0D, toDouble(event.getPayLoad().get("feeChargesPortion"))); Assertions.assertInstanceOf(List.class, loanChargePaidByList); Assertions.assertEquals(1, ((List) loanChargePaidByList).size()); Map chargePaidBy = (Map) ((List) loanChargePaidByList).get(0); Assertions.assertInstanceOf(Map.class, chargePaidBy); - Assertions.assertEquals(111.0D, chargePaidBy.get("amount")); - Assertions.assertEquals(chargeId.doubleValue(), chargePaidBy.get("chargeId")); - Assertions.assertEquals(transactionId.doubleValue(), chargePaidBy.get("transactionId")); + Assertions.assertEquals(111.0D, toDouble(chargePaidBy.get("amount"))); + Assertions.assertEquals(chargeId.doubleValue(), toDouble(chargePaidBy.get("chargeId"))); + Assertions.assertEquals(transactionId.doubleValue(), toDouble(chargePaidBy.get("transactionId"))); // check first part deleteAllExternalEvents(); @@ -563,9 +563,9 @@ public void verifyLoanChargeAdjustmentPostBusinessEvent07() { Assertions.assertEquals(1, ((List) loanChargePaidByList).size()); Map chargePaidBy = (Map) ((List) loanChargePaidByList).get(0); Assertions.assertInstanceOf(Map.class, chargePaidBy); - Assertions.assertEquals(111.0D, chargePaidBy.get("amount")); - Assertions.assertEquals(chargeId.doubleValue(), chargePaidBy.get("chargeId")); - Assertions.assertEquals(transactionId.doubleValue(), chargePaidBy.get("transactionId")); + Assertions.assertEquals(111.0D, toDouble(chargePaidBy.get("amount"))); + Assertions.assertEquals(chargeId.doubleValue(), toDouble(chargePaidBy.get("chargeId"))); + Assertions.assertEquals(transactionId.doubleValue(), toDouble(chargePaidBy.get("transactionId"))); }); } @@ -605,9 +605,9 @@ public void verifyLoanChargeAdjustmentPostBusinessEvent08() { Assertions.assertEquals(1, ((List) loanChargePaidByList).size()); Map chargePaidBy = (Map) ((List) loanChargePaidByList).get(0); Assertions.assertInstanceOf(Map.class, chargePaidBy); - Assertions.assertEquals(69.0D, chargePaidBy.get("amount")); - Assertions.assertEquals(chargeId.doubleValue(), chargePaidBy.get("chargeId")); - Assertions.assertEquals(transactionId.doubleValue(), chargePaidBy.get("transactionId")); + Assertions.assertEquals(69.0D, toDouble(chargePaidBy.get("amount"))); + Assertions.assertEquals(chargeId.doubleValue(), toDouble(chargePaidBy.get("chargeId"))); + Assertions.assertEquals(transactionId.doubleValue(), toDouble(chargePaidBy.get("transactionId"))); // check second part deleteAllExternalEvents(); @@ -625,9 +625,9 @@ public void verifyLoanChargeAdjustmentPostBusinessEvent08() { Assertions.assertEquals(1, ((List) loanChargePaidByList).size()); chargePaidBy = (Map) ((List) loanChargePaidByList).get(0); Assertions.assertInstanceOf(Map.class, chargePaidBy); - Assertions.assertEquals(42.0D, chargePaidBy.get("amount")); - Assertions.assertEquals(chargeId.doubleValue(), chargePaidBy.get("chargeId")); - Assertions.assertEquals(transactionId.doubleValue(), chargePaidBy.get("transactionId")); + Assertions.assertEquals(42.0D, toDouble(chargePaidBy.get("amount"))); + Assertions.assertEquals(chargeId.doubleValue(), toDouble(chargePaidBy.get("chargeId"))); + Assertions.assertEquals(transactionId.doubleValue(), toDouble(chargePaidBy.get("transactionId"))); // check that third part cannot post for that charge, because it already fully adjusted Assertions.assertThrows(RuntimeException.class, () -> loanTransactionHelper.chargeAdjustment(loanId, chargeId, @@ -666,14 +666,14 @@ public void verifyLoanChargeAdjustmentPostBusinessEvent09() { ExternalEventResponse event = list.get(0); log.info(event.toString()); Object loanChargePaidByList = event.getPayLoad().get("loanChargePaidByList"); - Assertions.assertEquals(111.0D, event.getPayLoad().get("feeChargesPortion")); + Assertions.assertEquals(111.0D, toDouble(event.getPayLoad().get("feeChargesPortion"))); Assertions.assertInstanceOf(List.class, loanChargePaidByList); Assertions.assertEquals(1, ((List) loanChargePaidByList).size()); Map chargePaidBy = (Map) ((List) loanChargePaidByList).get(0); Assertions.assertInstanceOf(Map.class, chargePaidBy); - Assertions.assertEquals(111.0D, chargePaidBy.get("amount")); - Assertions.assertEquals(chargeId.doubleValue(), chargePaidBy.get("chargeId")); - Assertions.assertEquals(transactionId.doubleValue(), chargePaidBy.get("transactionId")); + Assertions.assertEquals(111.0D, toDouble(chargePaidBy.get("amount"))); + Assertions.assertEquals(chargeId.doubleValue(), toDouble(chargePaidBy.get("chargeId"))); + Assertions.assertEquals(transactionId.doubleValue(), toDouble(chargePaidBy.get("transactionId"))); // check first part deleteAllExternalEvents(); @@ -927,7 +927,7 @@ public void verifyLoanApplicationModifiedBusinessEvent01() { Assertions.assertEquals(1, modifiedEvents.size()); ExternalEventResponse event = modifiedEvents.get(0); - Assertions.assertEquals(550.0D, event.getPayLoad().get("principal")); // the new principal + Assertions.assertEquals(550.0D, toDouble(event.getPayLoad().get("principal"))); // the new principal }); } @@ -1128,4 +1128,12 @@ private void configureLoanAdjustTransactionBusinessEvent(boolean enabled) { private void configureLoanAccrualTransactionCreatedBusinessEvent(boolean enabled) { externalEventHelper.configureBusinessEvent("LoanAccrualTransactionCreatedBusinessEvent", enabled); } + + private static Double toDouble(Object value) { + if (value instanceof Number) { + return ((Number) value).doubleValue(); + } + return (Double) value; + } + } diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/ExternalEventConfigurationIntegrationTest.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/ExternalEventConfigurationIntegrationTest.java index fcddf43bad1..1be6cd68e21 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/ExternalEventConfigurationIntegrationTest.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/ExternalEventConfigurationIntegrationTest.java @@ -25,6 +25,7 @@ import io.restassured.specification.ResponseSpecification; import java.util.ArrayList; import java.util.Map; +import org.apache.fineract.client.models.ExternalEventConfigurationUpdateRequest; import org.apache.fineract.integrationtests.common.ExternalEventConfigurationHelper; import org.apache.fineract.integrationtests.common.Utils; import org.junit.jupiter.api.AfterEach; @@ -68,9 +69,10 @@ private void verifyAllEventConfigurations(ArrayList> actualE @Test public void updateExternalEventConfigurations() { - String updateRequestJson = ExternalEventConfigurationHelper.getExternalEventConfigurationsForUpdateJSON(); + ExternalEventConfigurationUpdateRequest updateRequest = ExternalEventConfigurationHelper + .getExternalEventConfigurationsForUpdateRequest(); final Map updatedConfigurations = ExternalEventConfigurationHelper.updateExternalEventConfigurations(requestSpec, - responseSpec, updateRequestJson); + responseSpec, updateRequest); Assertions.assertEquals(updatedConfigurations.size(), 2); Assertions.assertTrue(updatedConfigurations.containsKey("CentersCreateBusinessEvent")); Assertions.assertTrue(updatedConfigurations.containsKey("ClientActivateBusinessEvent")); diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanAccountDisbursementToSavingsWithAutoDownPaymentTest.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanAccountDisbursementToSavingsWithAutoDownPaymentTest.java index e69813aae12..b9ec270c186 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanAccountDisbursementToSavingsWithAutoDownPaymentTest.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanAccountDisbursementToSavingsWithAutoDownPaymentTest.java @@ -31,6 +31,7 @@ import java.util.Optional; import java.util.UUID; import org.apache.fineract.accounting.common.AccountingConstants; +import org.apache.fineract.client.models.ExternalEventConfigurationUpdateRequest; import org.apache.fineract.client.models.GetLoanProductsProductIdResponse; import org.apache.fineract.client.models.GetSavingsAccountTransactionsPageItem; import org.apache.fineract.client.models.PostLoanProductsRequest; @@ -248,7 +249,8 @@ private void verifyTransactionIsAccountTransfer(final LocalDate transactionDate, private void enableLoanBalanceChangedBusinessEvent() { final Map updatedConfigurations = ExternalEventConfigurationHelper.updateExternalEventConfigurations(requestSpec, - responseSpec, "{\"externalEventConfigurations\":{\"LoanBalanceChangedBusinessEvent\":true}}\n"); + responseSpec, + new ExternalEventConfigurationUpdateRequest().externalEventConfigurations(Map.of("LoanBalanceChangedBusinessEvent", true))); Assertions.assertEquals(updatedConfigurations.size(), 1); Assertions.assertTrue(updatedConfigurations.containsKey("LoanBalanceChangedBusinessEvent")); Assertions.assertTrue(updatedConfigurations.get("LoanBalanceChangedBusinessEvent")); @@ -256,7 +258,8 @@ private void enableLoanBalanceChangedBusinessEvent() { private void disableLoanBalanceChangedBusinessEvent() { final Map updatedConfigurations = ExternalEventConfigurationHelper.updateExternalEventConfigurations(requestSpec, - responseSpec, "{\"externalEventConfigurations\":{\"LoanBalanceChangedBusinessEvent\":false}}\n"); + responseSpec, new ExternalEventConfigurationUpdateRequest() + .externalEventConfigurations(Map.of("LoanBalanceChangedBusinessEvent", false))); Assertions.assertEquals(updatedConfigurations.size(), 1); Assertions.assertTrue(updatedConfigurations.containsKey("LoanBalanceChangedBusinessEvent")); Assertions.assertFalse(updatedConfigurations.get("LoanBalanceChangedBusinessEvent")); diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/SchedulerJobsTestResults.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/SchedulerJobsTestResults.java index 0a9441ab688..c0f4d2d4fdf 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/SchedulerJobsTestResults.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/SchedulerJobsTestResults.java @@ -48,10 +48,13 @@ import java.util.Locale; import java.util.Map; import java.util.Objects; +import java.util.Set; import java.util.TimeZone; import org.apache.fineract.client.models.BusinessDateUpdateRequest; import org.apache.fineract.client.models.GetJournalEntriesTransactionIdResponse; import org.apache.fineract.client.models.GetLoansLoanIdResponse; +import org.apache.fineract.client.models.GetStandingInstructionHistoryPageItemsResponse; +import org.apache.fineract.client.models.GetStandingInstructionsStandingInstructionIdResponse; import org.apache.fineract.client.models.JournalEntryTransactionItem; import org.apache.fineract.client.models.PostClientsResponse; import org.apache.fineract.client.models.PostLoansLoanIdTransactionsRequest; @@ -741,9 +744,10 @@ public void testExecuteStandingInstructionsJobOutcome() throws InterruptedExcept HashMap toSavingsSummaryAfter = this.savingsAccountHelper.getSavingsSummary(toSavingsId); Float toSavingsBalanceAfter = (Float) toSavingsSummaryAfter.get("accountBalance"); - final HashMap standingInstructionData = standingInstructionsHelper.getStandingInstructionById(standingInstructionId.toString()); - Float expectedFromSavingsBalance = fromSavingsBalanceBefore - (Float) standingInstructionData.get("amount"); - Float expectedToSavingsBalance = toSavingsBalanceBefore + (Float) standingInstructionData.get("amount"); + final GetStandingInstructionsStandingInstructionIdResponse standingInstructionData = standingInstructionsHelper + .getStandingInstructionById(standingInstructionId.longValue()); + Float expectedFromSavingsBalance = fromSavingsBalanceBefore - standingInstructionData.getAmount(); + Float expectedToSavingsBalance = toSavingsBalanceBefore + standingInstructionData.getAmount(); Assertions.assertEquals(expectedFromSavingsBalance, fromSavingsBalanceAfter, "Verifying From Savings Balance after Successful completion of Scheduler Job"); @@ -751,13 +755,13 @@ public void testExecuteStandingInstructionsJobOutcome() throws InterruptedExcept "Verifying To Savings Balance after Successful completion of Scheduler Job"); Integer fromAccountType = PortfolioAccountType.SAVINGS.getValue(); Integer transferType = AccountTransferType.ACCOUNT_TRANSFER.getValue(); - List standingInstructionHistoryData = standingInstructionsHelper.getStandingInstructionHistory(fromSavingsId, - fromAccountType, clientID, transferType); + Set standingInstructionHistoryData = standingInstructionsHelper + .getStandingInstructionHistory(fromSavingsId, fromAccountType, clientID, transferType); Assertions.assertEquals(1, standingInstructionHistoryData.size(), "Verifying the no of standing instruction transactions logged for the client"); - HashMap loggedTransaction = standingInstructionHistoryData.get(0); + GetStandingInstructionHistoryPageItemsResponse loggedTransaction = standingInstructionHistoryData.iterator().next(); - Assertions.assertEquals((Float) standingInstructionData.get("amount"), (Float) loggedTransaction.get("amount"), + Assertions.assertEquals(standingInstructionData.getAmount(), loggedTransaction.getAmount(), "Verifying transferred amount and logged transaction amounts"); } diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/client/feign/tests/FeignProvisioningEntryTest.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/client/feign/tests/FeignProvisioningEntryTest.java index a43d2c9bb59..e9c86c031c0 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/client/feign/tests/FeignProvisioningEntryTest.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/client/feign/tests/FeignProvisioningEntryTest.java @@ -20,16 +20,13 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; -import com.google.gson.Gson; -import io.restassured.builder.RequestSpecBuilder; -import io.restassured.builder.ResponseSpecBuilder; -import io.restassured.http.ContentType; -import io.restassured.specification.RequestSpecification; -import io.restassured.specification.ResponseSpecification; import java.util.ArrayList; -import java.util.Map; +import java.util.List; +import org.apache.fineract.client.models.PostProvisioningCriteriaRequest; +import org.apache.fineract.client.models.PostProvisioningCriteriaResponse; import org.apache.fineract.client.models.PostProvisioningEntriesResponse; import org.apache.fineract.client.models.ProvisionEntryRequest; +import org.apache.fineract.client.models.ProvisioningCategoryData; import org.apache.fineract.client.models.ProvisioningEntryData; import org.apache.fineract.integrationtests.client.feign.FeignLoanTestBase; import org.apache.fineract.integrationtests.common.Utils; @@ -43,12 +40,6 @@ public class FeignProvisioningEntryTest extends FeignLoanTestBase { @Test public void testRetrieveProvisioningEntryWithNoActiveLoansDoesNotReturn500() { - // Set up REST spec for legacy helpers - Utils.initializeRESTAssured(); - RequestSpecification requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build(); - requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); - requestSpec.header("Fineract-Platform-TenantId", "default"); - ResponseSpecification responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); // Create a loan product to satisfy criteria validation, // but do NOT disburse any loans — so m_loanproduct_provisioning_entry @@ -59,16 +50,22 @@ public void testRetrieveProvisioningEntryWithNoActiveLoansDoesNotReturn500() { ArrayList loanProducts = new ArrayList<>(); loanProducts.add(loanProductId.intValue()); - ProvisioningTransactionHelper transactionHelper = new ProvisioningTransactionHelper(requestSpec, responseSpec); + Utils.initializeRESTAssured(); + var requestSpec = new io.restassured.builder.RequestSpecBuilder().setContentType(io.restassured.http.ContentType.JSON).build(); + requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); + requestSpec.header("Fineract-Platform-TenantId", "default"); + var responseSpec = new io.restassured.builder.ResponseSpecBuilder().expectStatusCode(200).build(); + ProvisioningTransactionHelper transactionHelper = new ProvisioningTransactionHelper(); AccountHelper accountHelper = new AccountHelper(requestSpec, responseSpec); - ArrayList categories = transactionHelper.retrieveAllProvisioningCategories(); + List categories = transactionHelper.retrieveAllProvisioningCategories(); Account liability = accountHelper.createLiabilityAccount(); Account expense = accountHelper.createExpenseAccount(); - Map requestCriteria = ProvisioningHelper.createProvisioingCriteriaJson(loanProducts, categories, liability, expense); - String criteriaJson = new Gson().toJson(requestCriteria); - Integer criteriaId = transactionHelper.createProvisioningCriteria(criteriaJson); - assertNotNull(criteriaId); + PostProvisioningCriteriaRequest criteriaRequest = ProvisioningHelper.buildProvisioningCriteriaRequest(loanProducts, categories, + liability, expense); + PostProvisioningCriteriaResponse createdCriteria = transactionHelper.createProvisioningCriteria(criteriaRequest); + assertNotNull(createdCriteria.getResourceId()); + Long criteriaId = createdCriteria.getResourceId(); // Create the provisioning entry String today = Utils.dateFormatter.format(Utils.getLocalDateOfTenant()); diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/ExternalEventConfigurationHelper.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/ExternalEventConfigurationHelper.java index d6750fbfe26..3f2ffbdcdb0 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/ExternalEventConfigurationHelper.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/ExternalEventConfigurationHelper.java @@ -18,745 +18,71 @@ */ package org.apache.fineract.integrationtests.common; -import com.google.gson.Gson; +import static org.apache.fineract.client.feign.util.FeignCalls.ok; + import io.restassured.specification.RequestSpecification; import io.restassured.specification.ResponseSpecification; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; +import org.apache.fineract.client.models.ExternalEventConfigurationItemResponse; +import org.apache.fineract.client.models.ExternalEventConfigurationResponse; +import org.apache.fineract.client.models.ExternalEventConfigurationUpdateRequest; +import org.apache.fineract.client.models.ExternalEventConfigurationUpdateResponse; public class ExternalEventConfigurationHelper { - private static final String EXTERNAL_EVENT_CONFIGURATION = "externalEventConfiguration"; - private static final String EXTERNAL_EVENT_CONFIGURATION_RESPONSE = "externalEventConfigurations"; - protected ExternalEventConfigurationHelper() {} - private static final String EXTERNAL_EVENT_CONFIGURATION_URL = "/fineract-provider/api/v1/externalevents/configuration?" - + Utils.TENANT_IDENTIFIER; - - // TODO: Rewrite to use fineract-client instead! - // Example: - // org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long, - // org.apache.fineract.client.models.PostLoansLoanIdRequest) - @Deprecated(forRemoval = true) public static ArrayList> getAllExternalEventConfigurations(RequestSpecification requestSpec, ResponseSpecification responseSpec) { - Map>> response = Utils.performServerGet(requestSpec, responseSpec, - EXTERNAL_EVENT_CONFIGURATION_URL, ""); - return response.get(EXTERNAL_EVENT_CONFIGURATION); + ExternalEventConfigurationResponse response = ok( + () -> FineractFeignClientHelper.getFineractFeignClient().externalEventConfiguration().getExternalEventConfigurations()); + ArrayList> configurations = new ArrayList<>(); + if (response.getExternalEventConfiguration() != null) { + for (ExternalEventConfigurationItemResponse item : response.getExternalEventConfiguration()) { + configurations.add(toMap(item)); + } + } + return configurations; } - // TODO: Rewrite to use fineract-client instead! - // Example: - // org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long, - // org.apache.fineract.client.models.PostLoansLoanIdRequest) - @Deprecated(forRemoval = true) public static ArrayList> getDefaultExternalEventConfigurations() { - ArrayList> defaults = new ArrayList<>(); - - Map centersCreateBusinessEvent = new HashMap<>(); - centersCreateBusinessEvent.put("type", "CentersCreateBusinessEvent"); - centersCreateBusinessEvent.put("enabled", false); - defaults.add(centersCreateBusinessEvent); - - Map clientActivateBusinessEvent = new HashMap<>(); - clientActivateBusinessEvent.put("type", "ClientActivateBusinessEvent"); - clientActivateBusinessEvent.put("enabled", false); - defaults.add(clientActivateBusinessEvent); - - Map clientCreateBusinessEvent = new HashMap<>(); - clientCreateBusinessEvent.put("type", "ClientCreateBusinessEvent"); - clientCreateBusinessEvent.put("enabled", false); - defaults.add(clientCreateBusinessEvent); - - Map clientRejectBusinessEvent = new HashMap<>(); - clientRejectBusinessEvent.put("type", "ClientRejectBusinessEvent"); - clientRejectBusinessEvent.put("enabled", false); - defaults.add(clientRejectBusinessEvent); - - Map documentCreatedBusinessEvent = new HashMap<>(); - documentCreatedBusinessEvent.put("type", "DocumentCreatedBusinessEvent"); - documentCreatedBusinessEvent.put("enabled", false); - defaults.add(documentCreatedBusinessEvent); - - Map documentDeletedBusinessEvent = new HashMap<>(); - documentDeletedBusinessEvent.put("type", "DocumentDeletedBusinessEvent"); - documentDeletedBusinessEvent.put("enabled", false); - defaults.add(documentDeletedBusinessEvent); - - Map fixedDepositAccountCreateBusinessEvent = new HashMap<>(); - fixedDepositAccountCreateBusinessEvent.put("type", "FixedDepositAccountCreateBusinessEvent"); - fixedDepositAccountCreateBusinessEvent.put("enabled", false); - defaults.add(fixedDepositAccountCreateBusinessEvent); - - Map groupsCreateBusinessEvent = new HashMap<>(); - groupsCreateBusinessEvent.put("type", "GroupsCreateBusinessEvent"); - groupsCreateBusinessEvent.put("enabled", false); - defaults.add(groupsCreateBusinessEvent); - - Map loanAcceptTransferBusinessEvent = new HashMap<>(); - loanAcceptTransferBusinessEvent.put("type", "LoanAcceptTransferBusinessEvent"); - loanAcceptTransferBusinessEvent.put("enabled", false); - defaults.add(loanAcceptTransferBusinessEvent); - - Map loanAddChargeBusinessEvent = new HashMap<>(); - loanAddChargeBusinessEvent.put("type", "LoanAddChargeBusinessEvent"); - loanAddChargeBusinessEvent.put("enabled", false); - defaults.add(loanAddChargeBusinessEvent); - - Map loanAdjustTransactionBusinessEvent = new HashMap<>(); - loanAdjustTransactionBusinessEvent.put("type", "LoanAdjustTransactionBusinessEvent"); - loanAdjustTransactionBusinessEvent.put("enabled", false); - defaults.add(loanAdjustTransactionBusinessEvent); - - Map LoanApplicationModifiedBusinessEvent = new HashMap<>(); - LoanApplicationModifiedBusinessEvent.put("type", "LoanApplicationModifiedBusinessEvent"); - LoanApplicationModifiedBusinessEvent.put("enabled", false); - defaults.add(LoanApplicationModifiedBusinessEvent); - - Map loanApplyOverdueChargeBusinessEvent = new HashMap<>(); - loanApplyOverdueChargeBusinessEvent.put("type", "LoanApplyOverdueChargeBusinessEvent"); - loanApplyOverdueChargeBusinessEvent.put("enabled", false); - defaults.add(loanApplyOverdueChargeBusinessEvent); - - Map loanApprovedBusinessEvent = new HashMap<>(); - loanApprovedBusinessEvent.put("type", "LoanApprovedBusinessEvent"); - loanApprovedBusinessEvent.put("enabled", false); - defaults.add(loanApprovedBusinessEvent); - - Map loanBalanceChangedBusinessEvent = new HashMap<>(); - loanBalanceChangedBusinessEvent.put("type", "LoanBalanceChangedBusinessEvent"); - loanBalanceChangedBusinessEvent.put("enabled", false); - defaults.add(loanBalanceChangedBusinessEvent); - - Map loanChargebackTransactionBusinessEvent = new HashMap<>(); - loanChargebackTransactionBusinessEvent.put("type", "LoanChargebackTransactionBusinessEvent"); - loanChargebackTransactionBusinessEvent.put("enabled", false); - defaults.add(loanChargebackTransactionBusinessEvent); - - Map loanChargePaymentPostBusinessEvent = new HashMap<>(); - loanChargePaymentPostBusinessEvent.put("type", "LoanChargePaymentPostBusinessEvent"); - loanChargePaymentPostBusinessEvent.put("enabled", false); - defaults.add(loanChargePaymentPostBusinessEvent); - - Map loanChargePaymentPreBusinessEvent = new HashMap<>(); - loanChargePaymentPreBusinessEvent.put("type", "LoanChargePaymentPreBusinessEvent"); - loanChargePaymentPreBusinessEvent.put("enabled", false); - defaults.add(loanChargePaymentPreBusinessEvent); - - Map loanChargeRefundBusinessEvent = new HashMap<>(); - loanChargeRefundBusinessEvent.put("type", "LoanChargeRefundBusinessEvent"); - loanChargeRefundBusinessEvent.put("enabled", false); - defaults.add(loanChargeRefundBusinessEvent); - - Map loanCloseAsRescheduleBusinessEvent = new HashMap<>(); - loanCloseAsRescheduleBusinessEvent.put("type", "LoanCloseAsRescheduleBusinessEvent"); - loanCloseAsRescheduleBusinessEvent.put("enabled", false); - defaults.add(loanCloseAsRescheduleBusinessEvent); - - Map loanCloseBusinessEvent = new HashMap<>(); - loanCloseBusinessEvent.put("type", "LoanCloseBusinessEvent"); - loanCloseBusinessEvent.put("enabled", false); - defaults.add(loanCloseBusinessEvent); - - Map loanCreatedBusinessEvent = new HashMap<>(); - loanCreatedBusinessEvent.put("type", "LoanCreatedBusinessEvent"); - loanCreatedBusinessEvent.put("enabled", false); - defaults.add(loanCreatedBusinessEvent); - - Map loanCreditBalanceRefundPostBusinessEvent = new HashMap<>(); - loanCreditBalanceRefundPostBusinessEvent.put("type", "LoanCreditBalanceRefundPostBusinessEvent"); - loanCreditBalanceRefundPostBusinessEvent.put("enabled", false); - defaults.add(loanCreditBalanceRefundPostBusinessEvent); - - Map loanCreditBalanceRefundPreBusinessEvent = new HashMap<>(); - loanCreditBalanceRefundPreBusinessEvent.put("type", "LoanCreditBalanceRefundPreBusinessEvent"); - loanCreditBalanceRefundPreBusinessEvent.put("enabled", false); - defaults.add(loanCreditBalanceRefundPreBusinessEvent); - - Map loanDeleteChargeBusinessEvent = new HashMap<>(); - loanDeleteChargeBusinessEvent.put("type", "LoanDeleteChargeBusinessEvent"); - loanDeleteChargeBusinessEvent.put("enabled", false); - defaults.add(loanDeleteChargeBusinessEvent); - - Map loanDisbursalBusinessEvent = new HashMap<>(); - loanDisbursalBusinessEvent.put("type", "LoanDisbursalBusinessEvent"); - loanDisbursalBusinessEvent.put("enabled", false); - defaults.add(loanDisbursalBusinessEvent); - - Map loanDisbursalTransactionBusinessEvent = new HashMap<>(); - loanDisbursalTransactionBusinessEvent.put("type", "LoanDisbursalTransactionBusinessEvent"); - loanDisbursalTransactionBusinessEvent.put("enabled", false); - defaults.add(loanDisbursalTransactionBusinessEvent); - - Map wcLoanDisbursalTransactionBusinessEvent = new HashMap<>(); - wcLoanDisbursalTransactionBusinessEvent.put("type", "WorkingCapitalLoanDisbursalTransactionBusinessEvent"); - wcLoanDisbursalTransactionBusinessEvent.put("enabled", false); - defaults.add(wcLoanDisbursalTransactionBusinessEvent); - - Map wcLoanUndoDisbursalTransactionBusinessEvent = new HashMap<>(); - wcLoanUndoDisbursalTransactionBusinessEvent.put("type", "WorkingCapitalLoanUndoDisbursalTransactionBusinessEvent"); - wcLoanUndoDisbursalTransactionBusinessEvent.put("enabled", false); - defaults.add(wcLoanUndoDisbursalTransactionBusinessEvent); - - Map loanForeClosurePostBusinessEvent = new HashMap<>(); - loanForeClosurePostBusinessEvent.put("type", "LoanForeClosurePostBusinessEvent"); - loanForeClosurePostBusinessEvent.put("enabled", false); - defaults.add(loanForeClosurePostBusinessEvent); - - Map loanForeClosurePreBusinessEvent = new HashMap<>(); - loanForeClosurePreBusinessEvent.put("type", "LoanForeClosurePreBusinessEvent"); - loanForeClosurePreBusinessEvent.put("enabled", false); - defaults.add(loanForeClosurePreBusinessEvent); - - Map loanInitiateTransferBusinessEvent = new HashMap<>(); - loanInitiateTransferBusinessEvent.put("type", "LoanInitiateTransferBusinessEvent"); - loanInitiateTransferBusinessEvent.put("enabled", false); - defaults.add(loanInitiateTransferBusinessEvent); - - Map loanInterestRecalculationBusinessEvent = new HashMap<>(); - loanInterestRecalculationBusinessEvent.put("type", "LoanInterestRecalculationBusinessEvent"); - loanInterestRecalculationBusinessEvent.put("enabled", false); - defaults.add(loanInterestRecalculationBusinessEvent); - - Map loanProductCreateBusinessEvent = new HashMap<>(); - loanProductCreateBusinessEvent.put("type", "LoanProductCreateBusinessEvent"); - loanProductCreateBusinessEvent.put("enabled", false); - defaults.add(loanProductCreateBusinessEvent); - - Map loanReassignOfficerBusinessEvent = new HashMap<>(); - loanReassignOfficerBusinessEvent.put("type", "LoanReassignOfficerBusinessEvent"); - loanReassignOfficerBusinessEvent.put("enabled", false); - defaults.add(loanReassignOfficerBusinessEvent); - - Map loanRefundPostBusinessEvent = new HashMap<>(); - loanRefundPostBusinessEvent.put("type", "LoanRefundPostBusinessEvent"); - loanRefundPostBusinessEvent.put("enabled", false); - defaults.add(loanRefundPostBusinessEvent); - - Map loanRefundPreBusinessEvent = new HashMap<>(); - loanRefundPreBusinessEvent.put("type", "LoanRefundPreBusinessEvent"); - loanRefundPreBusinessEvent.put("enabled", false); - defaults.add(loanRefundPreBusinessEvent); - - Map loanRejectedBusinessEvent = new HashMap<>(); - loanRejectedBusinessEvent.put("type", "LoanRejectedBusinessEvent"); - loanRejectedBusinessEvent.put("enabled", false); - defaults.add(loanRejectedBusinessEvent); - - Map loanRejectTransferBusinessEvent = new HashMap<>(); - loanRejectTransferBusinessEvent.put("type", "LoanRejectTransferBusinessEvent"); - loanRejectTransferBusinessEvent.put("enabled", false); - defaults.add(loanRejectTransferBusinessEvent); - - Map loanRemoveOfficerBusinessEvent = new HashMap<>(); - loanRemoveOfficerBusinessEvent.put("type", "LoanRemoveOfficerBusinessEvent"); - loanRemoveOfficerBusinessEvent.put("enabled", false); - defaults.add(loanRemoveOfficerBusinessEvent); - - Map loanRepaymentDueBusinessEvent = new HashMap<>(); - loanRepaymentDueBusinessEvent.put("type", "LoanRepaymentDueBusinessEvent"); - loanRepaymentDueBusinessEvent.put("enabled", false); - defaults.add(loanRepaymentDueBusinessEvent); - - Map loanRepaymentOverdueBusinessEvent = new HashMap<>(); - loanRepaymentOverdueBusinessEvent.put("type", "LoanRepaymentOverdueBusinessEvent"); - loanRepaymentOverdueBusinessEvent.put("enabled", false); - defaults.add(loanRepaymentOverdueBusinessEvent); - - Map loanRescheduledDueCalendarChangeBusinessEvent = new HashMap<>(); - loanRescheduledDueCalendarChangeBusinessEvent.put("type", "LoanRescheduledDueCalendarChangeBusinessEvent"); - loanRescheduledDueCalendarChangeBusinessEvent.put("enabled", false); - defaults.add(loanRescheduledDueCalendarChangeBusinessEvent); - - Map loanRescheduledDueHolidayBusinessEvent = new HashMap<>(); - loanRescheduledDueHolidayBusinessEvent.put("type", "LoanRescheduledDueHolidayBusinessEvent"); - loanRescheduledDueHolidayBusinessEvent.put("enabled", false); - defaults.add(loanRescheduledDueHolidayBusinessEvent); - - Map loanScheduleVariationsAddedBusinessEvent = new HashMap<>(); - loanScheduleVariationsAddedBusinessEvent.put("type", "LoanScheduleVariationsAddedBusinessEvent"); - loanScheduleVariationsAddedBusinessEvent.put("enabled", false); - defaults.add(loanScheduleVariationsAddedBusinessEvent); - - Map loanScheduleVariationsDeletedBusinessEvent = new HashMap<>(); - loanScheduleVariationsDeletedBusinessEvent.put("type", "LoanScheduleVariationsDeletedBusinessEvent"); - loanScheduleVariationsDeletedBusinessEvent.put("enabled", false); - defaults.add(loanScheduleVariationsDeletedBusinessEvent); - - Map loanStatusChangedBusinessEvent = new HashMap<>(); - loanStatusChangedBusinessEvent.put("type", "LoanStatusChangedBusinessEvent"); - loanStatusChangedBusinessEvent.put("enabled", false); - defaults.add(loanStatusChangedBusinessEvent); - - Map loanTransactionGoodwillCreditPostBusinessEvent = new HashMap<>(); - loanTransactionGoodwillCreditPostBusinessEvent.put("type", "LoanTransactionGoodwillCreditPostBusinessEvent"); - loanTransactionGoodwillCreditPostBusinessEvent.put("enabled", false); - defaults.add(loanTransactionGoodwillCreditPostBusinessEvent); - - Map loanTransactionGoodwillCreditPreBusinessEvent = new HashMap<>(); - loanTransactionGoodwillCreditPreBusinessEvent.put("type", "LoanTransactionGoodwillCreditPreBusinessEvent"); - loanTransactionGoodwillCreditPreBusinessEvent.put("enabled", false); - defaults.add(loanTransactionGoodwillCreditPreBusinessEvent); - - Map loanTransactionMakeRepaymentPostBusinessEvent = new HashMap<>(); - loanTransactionMakeRepaymentPostBusinessEvent.put("type", "LoanTransactionMakeRepaymentPostBusinessEvent"); - loanTransactionMakeRepaymentPostBusinessEvent.put("enabled", false); - defaults.add(loanTransactionMakeRepaymentPostBusinessEvent); - - Map loanTransactionMakeRepaymentPreBusinessEvent = new HashMap<>(); - loanTransactionMakeRepaymentPreBusinessEvent.put("type", "LoanTransactionMakeRepaymentPreBusinessEvent"); - loanTransactionMakeRepaymentPreBusinessEvent.put("enabled", false); - defaults.add(loanTransactionMakeRepaymentPreBusinessEvent); - - Map wcLoanTransactionMakeRepaymentBusinessEvent = new HashMap<>(); - wcLoanTransactionMakeRepaymentBusinessEvent.put("type", "WorkingCapitalLoanRepaymentTransactionBusinessEvent"); - wcLoanTransactionMakeRepaymentBusinessEvent.put("enabled", false); - defaults.add(wcLoanTransactionMakeRepaymentBusinessEvent); - - Map wcLoanCreditBalanceRefundTransactionBusinessEvent = new HashMap<>(); - wcLoanCreditBalanceRefundTransactionBusinessEvent.put("type", "WorkingCapitalLoanCreditBalanceRefundTransactionBusinessEvent"); - wcLoanCreditBalanceRefundTransactionBusinessEvent.put("enabled", false); - defaults.add(wcLoanCreditBalanceRefundTransactionBusinessEvent); - - Map loanTransactionMerchantIssuedRefundPostBusinessEvent = new HashMap<>(); - loanTransactionMerchantIssuedRefundPostBusinessEvent.put("type", "LoanTransactionMerchantIssuedRefundPostBusinessEvent"); - loanTransactionMerchantIssuedRefundPostBusinessEvent.put("enabled", false); - defaults.add(loanTransactionMerchantIssuedRefundPostBusinessEvent); - - Map loanTransactionMerchantIssuedRefundPreBusinessEvent = new HashMap<>(); - loanTransactionMerchantIssuedRefundPreBusinessEvent.put("type", "LoanTransactionMerchantIssuedRefundPreBusinessEvent"); - loanTransactionMerchantIssuedRefundPreBusinessEvent.put("enabled", false); - defaults.add(loanTransactionMerchantIssuedRefundPreBusinessEvent); - - Map loanTransactionPayoutRefundPostBusinessEvent = new HashMap<>(); - loanTransactionPayoutRefundPostBusinessEvent.put("type", "LoanTransactionPayoutRefundPostBusinessEvent"); - loanTransactionPayoutRefundPostBusinessEvent.put("enabled", false); - defaults.add(loanTransactionPayoutRefundPostBusinessEvent); - - Map loanTransactionPayoutRefundPreBusinessEvent = new HashMap<>(); - loanTransactionPayoutRefundPreBusinessEvent.put("type", "LoanTransactionPayoutRefundPreBusinessEvent"); - loanTransactionPayoutRefundPreBusinessEvent.put("enabled", false); - defaults.add(loanTransactionPayoutRefundPreBusinessEvent); - - Map loanTransactionRecoveryPaymentPostBusinessEvent = new HashMap<>(); - loanTransactionRecoveryPaymentPostBusinessEvent.put("type", "LoanTransactionRecoveryPaymentPostBusinessEvent"); - loanTransactionRecoveryPaymentPostBusinessEvent.put("enabled", false); - defaults.add(loanTransactionRecoveryPaymentPostBusinessEvent); - - Map loanTransactionRecoveryPaymentPreBusinessEvent = new HashMap<>(); - loanTransactionRecoveryPaymentPreBusinessEvent.put("type", "LoanTransactionRecoveryPaymentPreBusinessEvent"); - loanTransactionRecoveryPaymentPreBusinessEvent.put("enabled", false); - defaults.add(loanTransactionRecoveryPaymentPreBusinessEvent); - - Map loanUndoApprovalBusinessEvent = new HashMap<>(); - loanUndoApprovalBusinessEvent.put("type", "LoanUndoApprovalBusinessEvent"); - loanUndoApprovalBusinessEvent.put("enabled", false); - defaults.add(loanUndoApprovalBusinessEvent); - - Map loanUndoDisbursalBusinessEvent = new HashMap<>(); - loanUndoDisbursalBusinessEvent.put("type", "LoanUndoDisbursalBusinessEvent"); - loanUndoDisbursalBusinessEvent.put("enabled", false); - defaults.add(loanUndoDisbursalBusinessEvent); - - Map loanUndoLastDisbursalBusinessEvent = new HashMap<>(); - loanUndoLastDisbursalBusinessEvent.put("type", "LoanUndoLastDisbursalBusinessEvent"); - loanUndoLastDisbursalBusinessEvent.put("enabled", false); - defaults.add(loanUndoLastDisbursalBusinessEvent); - - Map loanUndoWrittenOffBusinessEvent = new HashMap<>(); - loanUndoWrittenOffBusinessEvent.put("type", "LoanUndoWrittenOffBusinessEvent"); - loanUndoWrittenOffBusinessEvent.put("enabled", false); - defaults.add(loanUndoWrittenOffBusinessEvent); - - Map loanUpdateChargeBusinessEvent = new HashMap<>(); - loanUpdateChargeBusinessEvent.put("type", "LoanUpdateChargeBusinessEvent"); - loanUpdateChargeBusinessEvent.put("enabled", false); - defaults.add(loanUpdateChargeBusinessEvent); - - Map loanUpdateDisbursementDataBusinessEvent = new HashMap<>(); - loanUpdateDisbursementDataBusinessEvent.put("type", "LoanUpdateDisbursementDataBusinessEvent"); - loanUpdateDisbursementDataBusinessEvent.put("enabled", false); - defaults.add(loanUpdateDisbursementDataBusinessEvent); - - Map loanWaiveChargeBusinessEvent = new HashMap<>(); - loanWaiveChargeBusinessEvent.put("type", "LoanWaiveChargeBusinessEvent"); - loanWaiveChargeBusinessEvent.put("enabled", false); - defaults.add(loanWaiveChargeBusinessEvent); - - Map loanWaiveChargeUndoBusinessEvent = new HashMap<>(); - loanWaiveChargeUndoBusinessEvent.put("type", "LoanWaiveChargeUndoBusinessEvent"); - loanWaiveChargeUndoBusinessEvent.put("enabled", false); - defaults.add(loanWaiveChargeUndoBusinessEvent); - - Map loanWaiveInterestBusinessEvent = new HashMap<>(); - loanWaiveInterestBusinessEvent.put("type", "LoanWaiveInterestBusinessEvent"); - loanWaiveInterestBusinessEvent.put("enabled", false); - defaults.add(loanWaiveInterestBusinessEvent); - - Map LoanWithdrawnByApplicantBusinessEvent = new HashMap<>(); - LoanWithdrawnByApplicantBusinessEvent.put("type", "LoanWithdrawnByApplicantBusinessEvent"); - LoanWithdrawnByApplicantBusinessEvent.put("enabled", false); - defaults.add(LoanWithdrawnByApplicantBusinessEvent); - - Map loanWithdrawTransferBusinessEvent = new HashMap<>(); - loanWithdrawTransferBusinessEvent.put("type", "LoanWithdrawTransferBusinessEvent"); - loanWithdrawTransferBusinessEvent.put("enabled", false); - defaults.add(loanWithdrawTransferBusinessEvent); - - Map loanWrittenOffPostBusinessEvent = new HashMap<>(); - loanWrittenOffPostBusinessEvent.put("type", "LoanWrittenOffPostBusinessEvent"); - loanWrittenOffPostBusinessEvent.put("enabled", false); - defaults.add(loanWrittenOffPostBusinessEvent); - - Map loanWrittenOffPreBusinessEvent = new HashMap<>(); - loanWrittenOffPreBusinessEvent.put("type", "LoanWrittenOffPreBusinessEvent"); - loanWrittenOffPreBusinessEvent.put("enabled", false); - defaults.add(loanWrittenOffPreBusinessEvent); - - Map recurringDepositAccountCreateBusinessEvent = new HashMap<>(); - recurringDepositAccountCreateBusinessEvent.put("type", "RecurringDepositAccountCreateBusinessEvent"); - recurringDepositAccountCreateBusinessEvent.put("enabled", false); - defaults.add(recurringDepositAccountCreateBusinessEvent); - - Map savingsActivateBusinessEvent = new HashMap<>(); - savingsActivateBusinessEvent.put("type", "SavingsActivateBusinessEvent"); - savingsActivateBusinessEvent.put("enabled", false); - defaults.add(savingsActivateBusinessEvent); - - Map savingsApproveBusinessEvent = new HashMap<>(); - savingsApproveBusinessEvent.put("type", "SavingsApproveBusinessEvent"); - savingsApproveBusinessEvent.put("enabled", false); - defaults.add(savingsApproveBusinessEvent); - - Map savingsCloseBusinessEvent = new HashMap<>(); - savingsCloseBusinessEvent.put("type", "SavingsCloseBusinessEvent"); - savingsCloseBusinessEvent.put("enabled", false); - defaults.add(savingsCloseBusinessEvent); - - Map savingsCreateBusinessEvent = new HashMap<>(); - savingsCreateBusinessEvent.put("type", "SavingsCreateBusinessEvent"); - savingsCreateBusinessEvent.put("enabled", false); - defaults.add(savingsCreateBusinessEvent); - - Map savingsDepositBusinessEvent = new HashMap<>(); - savingsDepositBusinessEvent.put("type", "SavingsDepositBusinessEvent"); - savingsDepositBusinessEvent.put("enabled", false); - defaults.add(savingsDepositBusinessEvent); - - Map savingsPostInterestBusinessEvent = new HashMap<>(); - savingsPostInterestBusinessEvent.put("type", "SavingsPostInterestBusinessEvent"); - savingsPostInterestBusinessEvent.put("enabled", false); - defaults.add(savingsPostInterestBusinessEvent); - - Map savingsRejectBusinessEvent = new HashMap<>(); - savingsRejectBusinessEvent.put("type", "SavingsRejectBusinessEvent"); - savingsRejectBusinessEvent.put("enabled", false); - defaults.add(savingsRejectBusinessEvent); - - Map savingsWithdrawalBusinessEvent = new HashMap<>(); - savingsWithdrawalBusinessEvent.put("type", "SavingsWithdrawalBusinessEvent"); - savingsWithdrawalBusinessEvent.put("enabled", false); - defaults.add(savingsWithdrawalBusinessEvent); - - Map shareAccountApproveBusinessEvent = new HashMap<>(); - shareAccountApproveBusinessEvent.put("type", "ShareAccountApproveBusinessEvent"); - shareAccountApproveBusinessEvent.put("enabled", false); - defaults.add(shareAccountApproveBusinessEvent); - - Map shareAccountCreateBusinessEvent = new HashMap<>(); - shareAccountCreateBusinessEvent.put("type", "ShareAccountCreateBusinessEvent"); - shareAccountCreateBusinessEvent.put("enabled", false); - defaults.add(shareAccountCreateBusinessEvent); - - Map shareProductDividentsCreateBusinessEvent = new HashMap<>(); - shareProductDividentsCreateBusinessEvent.put("type", "ShareProductDividentsCreateBusinessEvent"); - shareProductDividentsCreateBusinessEvent.put("enabled", false); - defaults.add(shareProductDividentsCreateBusinessEvent); - - Map loanChargeAdjustmentPostBusinessEvent = new HashMap<>(); - loanChargeAdjustmentPostBusinessEvent.put("type", "LoanChargeAdjustmentPostBusinessEvent"); - loanChargeAdjustmentPostBusinessEvent.put("enabled", false); - defaults.add(loanChargeAdjustmentPostBusinessEvent); - - Map loanChargeAdjustmentPreBusinessEvent = new HashMap<>(); - loanChargeAdjustmentPreBusinessEvent.put("type", "LoanChargeAdjustmentPreBusinessEvent"); - loanChargeAdjustmentPreBusinessEvent.put("enabled", false); - defaults.add(loanChargeAdjustmentPreBusinessEvent); - - Map loanDelinquencyRangeChangeBusinessEvent = new HashMap<>(); - loanDelinquencyRangeChangeBusinessEvent.put("type", "LoanDelinquencyRangeChangeBusinessEvent"); - loanDelinquencyRangeChangeBusinessEvent.put("enabled", false); - defaults.add(loanDelinquencyRangeChangeBusinessEvent); - - Map loanAccountsStayedLockedBusinessEvent = new HashMap<>(); - loanAccountsStayedLockedBusinessEvent.put("type", "LoanAccountsStayedLockedBusinessEvent"); - loanAccountsStayedLockedBusinessEvent.put("enabled", false); - defaults.add(loanAccountsStayedLockedBusinessEvent); - - Map loanChargeOffPreBusinessEvent = new HashMap<>(); - loanChargeOffPreBusinessEvent.put("type", "LoanChargeOffPreBusinessEvent"); - loanChargeOffPreBusinessEvent.put("enabled", false); - defaults.add(loanChargeOffPreBusinessEvent); - - Map loanChargeOffPostBusinessEvent = new HashMap<>(); - loanChargeOffPostBusinessEvent.put("type", "LoanChargeOffPostBusinessEvent"); - loanChargeOffPostBusinessEvent.put("enabled", false); - defaults.add(loanChargeOffPostBusinessEvent); - - Map loanUndoChargeOffPostBusinessEvent = new HashMap<>(); - loanUndoChargeOffPostBusinessEvent.put("type", "LoanUndoChargeOffBusinessEvent"); - loanUndoChargeOffPostBusinessEvent.put("enabled", false); - defaults.add(loanUndoChargeOffPostBusinessEvent); - - Map loanAccrualTransactionCreatedBusinessEvent = new HashMap<>(); - loanAccrualTransactionCreatedBusinessEvent.put("type", "LoanAccrualTransactionCreatedBusinessEvent"); - loanAccrualTransactionCreatedBusinessEvent.put("enabled", false); - defaults.add(loanAccrualTransactionCreatedBusinessEvent); - - Map loanAccrualAdjustmentTransactionBusinessEvent = new HashMap<>(); - loanAccrualAdjustmentTransactionBusinessEvent.put("type", "LoanAccrualAdjustmentTransactionBusinessEvent"); - loanAccrualAdjustmentTransactionBusinessEvent.put("enabled", false); - defaults.add(loanAccrualAdjustmentTransactionBusinessEvent); - - Map loanRescheduledDueAdjustScheduleBusinessEvent = new HashMap<>(); - loanRescheduledDueAdjustScheduleBusinessEvent.put("type", "LoanRescheduledDueAdjustScheduleBusinessEvent"); - loanRescheduledDueAdjustScheduleBusinessEvent.put("enabled", false); - defaults.add(loanRescheduledDueAdjustScheduleBusinessEvent); - - Map loanOwnershipTransferBusinessEvent = new HashMap<>(); - loanOwnershipTransferBusinessEvent.put("type", "LoanOwnershipTransferBusinessEvent"); - loanOwnershipTransferBusinessEvent.put("enabled", false); - defaults.add(loanOwnershipTransferBusinessEvent); - - Map loanAccountSnapshotBusinessEvent = new HashMap<>(); - loanAccountSnapshotBusinessEvent.put("type", "LoanAccountSnapshotBusinessEvent"); - loanAccountSnapshotBusinessEvent.put("enabled", false); - defaults.add(loanAccountSnapshotBusinessEvent); - - Map loanTransactionDownPaymentPreBusinessEvent = new HashMap<>(); - loanTransactionDownPaymentPreBusinessEvent.put("type", "LoanTransactionDownPaymentPreBusinessEvent"); - loanTransactionDownPaymentPreBusinessEvent.put("enabled", false); - defaults.add(loanTransactionDownPaymentPreBusinessEvent); - - Map loanTransactionDownPaymentPostBusinessEvent = new HashMap<>(); - loanTransactionDownPaymentPostBusinessEvent.put("type", "LoanTransactionDownPaymentPostBusinessEvent"); - loanTransactionDownPaymentPostBusinessEvent.put("enabled", false); - defaults.add(loanTransactionDownPaymentPostBusinessEvent); - - Map loanAccountDelinquencyPauseChangedBusinessEvent = new HashMap<>(); - loanAccountDelinquencyPauseChangedBusinessEvent.put("type", "LoanAccountDelinquencyPauseChangedBusinessEvent"); - loanAccountDelinquencyPauseChangedBusinessEvent.put("enabled", false); - defaults.add(loanAccountDelinquencyPauseChangedBusinessEvent); - - Map loanAccountCustomSnapshotBusinessEvent = new HashMap<>(); - loanAccountCustomSnapshotBusinessEvent.put("type", "LoanAccountCustomSnapshotBusinessEvent"); - loanAccountCustomSnapshotBusinessEvent.put("enabled", false); - defaults.add(loanAccountCustomSnapshotBusinessEvent); - - Map loanReAgeTransactionBusinessEvent = new HashMap<>(); - loanReAgeTransactionBusinessEvent.put("type", "LoanReAgeTransactionBusinessEvent"); - loanReAgeTransactionBusinessEvent.put("enabled", false); - defaults.add(loanReAgeTransactionBusinessEvent); - - Map loanUndoReAgeTransactionBusinessEvent = new HashMap<>(); - loanUndoReAgeTransactionBusinessEvent.put("type", "LoanUndoReAgeTransactionBusinessEvent"); - loanUndoReAgeTransactionBusinessEvent.put("enabled", false); - defaults.add(loanUndoReAgeTransactionBusinessEvent); - - Map loanReAmortizeTransactionBusinessEvent = new HashMap<>(); - loanReAmortizeTransactionBusinessEvent.put("type", "LoanReAmortizeTransactionBusinessEvent"); - loanReAmortizeTransactionBusinessEvent.put("enabled", false); - defaults.add(loanReAmortizeTransactionBusinessEvent); - - Map loanUndoReAmortizeTransactionBusinessEvent = new HashMap<>(); - loanUndoReAmortizeTransactionBusinessEvent.put("type", "LoanUndoReAmortizeTransactionBusinessEvent"); - loanUndoReAmortizeTransactionBusinessEvent.put("enabled", false); - defaults.add(loanUndoReAmortizeTransactionBusinessEvent); - - Map loanReAgeBusinessEvent = new HashMap<>(); - loanReAgeBusinessEvent.put("type", "LoanReAgeBusinessEvent"); - loanReAgeBusinessEvent.put("enabled", false); - defaults.add(loanReAgeBusinessEvent); - - Map loanUndoReAgeBusinessEvent = new HashMap<>(); - loanUndoReAgeBusinessEvent.put("type", "LoanUndoReAgeBusinessEvent"); - loanUndoReAgeBusinessEvent.put("enabled", false); - defaults.add(loanUndoReAgeBusinessEvent); - - Map loanReAmortizeBusinessEvent = new HashMap<>(); - loanReAmortizeBusinessEvent.put("type", "LoanReAmortizeBusinessEvent"); - loanReAmortizeBusinessEvent.put("enabled", false); - defaults.add(loanReAmortizeBusinessEvent); - - Map loanUndoReAmortizeBusinessEvent = new HashMap<>(); - loanUndoReAmortizeBusinessEvent.put("type", "LoanUndoReAmortizeBusinessEvent"); - loanUndoReAmortizeBusinessEvent.put("enabled", false); - defaults.add(loanUndoReAmortizeBusinessEvent); - - Map loanTransactionInterestPaymentWaiverPostBusinessEvent = new HashMap<>(); - loanTransactionInterestPaymentWaiverPostBusinessEvent.put("type", "LoanTransactionInterestPaymentWaiverPostBusinessEvent"); - loanTransactionInterestPaymentWaiverPostBusinessEvent.put("enabled", false); - defaults.add(loanTransactionInterestPaymentWaiverPostBusinessEvent); - - Map loanTransactionInterestPaymentWaiverPreBusinessEvent = new HashMap<>(); - loanTransactionInterestPaymentWaiverPreBusinessEvent.put("type", "LoanTransactionInterestPaymentWaiverPreBusinessEvent"); - loanTransactionInterestPaymentWaiverPreBusinessEvent.put("enabled", false); - defaults.add(loanTransactionInterestPaymentWaiverPreBusinessEvent); - - Map loanTransactionAccrualActivityPostBusinessEvent = new HashMap<>(); - loanTransactionAccrualActivityPostBusinessEvent.put("type", "LoanTransactionAccrualActivityPostBusinessEvent"); - loanTransactionAccrualActivityPostBusinessEvent.put("enabled", false); - defaults.add(loanTransactionAccrualActivityPostBusinessEvent); - - Map loanTransactionAccrualActivityPreBusinessEvent = new HashMap<>(); - loanTransactionAccrualActivityPreBusinessEvent.put("type", "LoanTransactionAccrualActivityPreBusinessEvent"); - loanTransactionAccrualActivityPreBusinessEvent.put("enabled", false); - defaults.add(loanTransactionAccrualActivityPreBusinessEvent); - - Map loanTransactionInterestRefundPostBusinessEvent = new HashMap<>(); - loanTransactionInterestRefundPostBusinessEvent.put("type", "LoanTransactionInterestRefundPostBusinessEvent"); - loanTransactionInterestRefundPostBusinessEvent.put("enabled", false); - defaults.add(loanTransactionInterestRefundPostBusinessEvent); - - Map loanTransactionInterestRefundPreBusinessEvent = new HashMap<>(); - loanTransactionInterestRefundPreBusinessEvent.put("type", "LoanTransactionInterestRefundPreBusinessEvent"); - loanTransactionInterestRefundPreBusinessEvent.put("enabled", false); - defaults.add(loanTransactionInterestRefundPreBusinessEvent); - - Map loanCapitalizedIncomeAmortizationTransactionCreatedBusinessEvent = new HashMap<>(); - loanCapitalizedIncomeAmortizationTransactionCreatedBusinessEvent.put("type", - "LoanCapitalizedIncomeAmortizationTransactionCreatedBusinessEvent"); - loanCapitalizedIncomeAmortizationTransactionCreatedBusinessEvent.put("enabled", false); - defaults.add(loanCapitalizedIncomeAmortizationTransactionCreatedBusinessEvent); - - Map loanCapitalizedIncomeAdjustmentTransactionCreatedBusinessEvent = new HashMap<>(); - loanCapitalizedIncomeAdjustmentTransactionCreatedBusinessEvent.put("type", - "LoanCapitalizedIncomeAdjustmentTransactionCreatedBusinessEvent"); - loanCapitalizedIncomeAdjustmentTransactionCreatedBusinessEvent.put("enabled", false); - defaults.add(loanCapitalizedIncomeAdjustmentTransactionCreatedBusinessEvent); - - Map loanTransactionContractTerminationPostBusinessEvent = new HashMap<>(); - loanTransactionContractTerminationPostBusinessEvent.put("type", "LoanTransactionContractTerminationPostBusinessEvent"); - loanTransactionContractTerminationPostBusinessEvent.put("enabled", false); - defaults.add(loanTransactionContractTerminationPostBusinessEvent); - - Map loanCapitalizedIncomeAmortizationAdjustmentTransactionCreatedBusinessEvent = new HashMap<>(); - loanCapitalizedIncomeAmortizationAdjustmentTransactionCreatedBusinessEvent.put("type", - "LoanCapitalizedIncomeAmortizationAdjustmentTransactionCreatedBusinessEvent"); - loanCapitalizedIncomeAmortizationAdjustmentTransactionCreatedBusinessEvent.put("enabled", false); - defaults.add(loanCapitalizedIncomeAmortizationAdjustmentTransactionCreatedBusinessEvent); - - Map loanCapitalizedIncomeTransactionCreatedBusinessEvent = new HashMap<>(); - loanCapitalizedIncomeTransactionCreatedBusinessEvent.put("type", "LoanCapitalizedIncomeTransactionCreatedBusinessEvent"); - loanCapitalizedIncomeTransactionCreatedBusinessEvent.put("enabled", false); - defaults.add(loanCapitalizedIncomeTransactionCreatedBusinessEvent); - - Map loanTransactionUndoContractTerminationBusinessEvent = new HashMap<>(); - loanTransactionUndoContractTerminationBusinessEvent.put("type", "LoanUndoContractTerminationBusinessEvent"); - loanTransactionUndoContractTerminationBusinessEvent.put("enabled", false); - defaults.add(loanTransactionUndoContractTerminationBusinessEvent); - - Map loanTransactionBuyDownFeePostBusinessEvent = new HashMap<>(); - loanTransactionBuyDownFeePostBusinessEvent.put("type", "LoanBuyDownFeeTransactionCreatedBusinessEvent"); - loanTransactionBuyDownFeePostBusinessEvent.put("enabled", false); - defaults.add(loanTransactionBuyDownFeePostBusinessEvent); - - Map loanTransactionBuyDownFeeAdjustmentPostBusinessEvent = new HashMap<>(); - loanTransactionBuyDownFeeAdjustmentPostBusinessEvent.put("type", "LoanBuyDownFeeAdjustmentTransactionCreatedBusinessEvent"); - loanTransactionBuyDownFeeAdjustmentPostBusinessEvent.put("enabled", false); - defaults.add(loanTransactionBuyDownFeeAdjustmentPostBusinessEvent); - - Map loanBuyDownFeeAmortizationTransactionCreatedBusinessEvent = new HashMap<>(); - loanBuyDownFeeAmortizationTransactionCreatedBusinessEvent.put("type", "LoanBuyDownFeeAmortizationTransactionCreatedBusinessEvent"); - loanBuyDownFeeAmortizationTransactionCreatedBusinessEvent.put("enabled", false); - defaults.add(loanBuyDownFeeAmortizationTransactionCreatedBusinessEvent); - - Map loanBuyDownFeeAmortizationAdjustmentTransactionCreatedBusinessEvent = new HashMap<>(); - loanBuyDownFeeAmortizationAdjustmentTransactionCreatedBusinessEvent.put("type", - "LoanBuyDownFeeAmortizationAdjustmentTransactionCreatedBusinessEvent"); - loanBuyDownFeeAmortizationAdjustmentTransactionCreatedBusinessEvent.put("enabled", false); - defaults.add(loanBuyDownFeeAmortizationAdjustmentTransactionCreatedBusinessEvent); - - Map loanApprovedAmountChangedBusinessEvent = new HashMap<>(); - loanApprovedAmountChangedBusinessEvent.put("type", "LoanApprovedAmountChangedBusinessEvent"); - loanApprovedAmountChangedBusinessEvent.put("enabled", false); - defaults.add(loanApprovedAmountChangedBusinessEvent); - - Map savingsAccountsStayedLockedBusinessEvent = new HashMap<>(); - savingsAccountsStayedLockedBusinessEvent.put("type", "SavingsAccountsStayedLockedBusinessEvent"); - savingsAccountsStayedLockedBusinessEvent.put("enabled", false); - defaults.add(savingsAccountsStayedLockedBusinessEvent); - - Map savingsAccountForceWithdrawalBusinessEvent = new HashMap<>(); - savingsAccountForceWithdrawalBusinessEvent.put("type", "SavingsAccountForceWithdrawalBusinessEvent"); - savingsAccountForceWithdrawalBusinessEvent.put("enabled", false); - defaults.add(savingsAccountForceWithdrawalBusinessEvent); - - Map workingCapitalLoanDiscountDisbursalTransactionBusinessEvent = new HashMap<>(); - workingCapitalLoanDiscountDisbursalTransactionBusinessEvent.put("type", "WorkingCapitalLoanDiscountFeeTransactionBusinessEvent"); - workingCapitalLoanDiscountDisbursalTransactionBusinessEvent.put("enabled", false); - defaults.add(workingCapitalLoanDiscountDisbursalTransactionBusinessEvent); - - Map workingCapitalLoanDiscountFeeAdjustmentTransactionBusinessEvent = new HashMap<>(); - workingCapitalLoanDiscountFeeAdjustmentTransactionBusinessEvent.put("type", - "WorkingCapitalLoanDiscountFeeAdjustmentTransactionBusinessEvent"); - workingCapitalLoanDiscountFeeAdjustmentTransactionBusinessEvent.put("enabled", false); - defaults.add(workingCapitalLoanDiscountFeeAdjustmentTransactionBusinessEvent); - + ArrayList> defaults = getAllExternalEventConfigurations(null, null); + for (Map defaultConfiguration : defaults) { + defaultConfiguration.put("enabled", false); + } return defaults; } - // TODO: Rewrite to use fineract-client instead! - // Example: - // org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long, - // org.apache.fineract.client.models.PostLoansLoanIdRequest) - @Deprecated(forRemoval = true) - public static String getExternalEventConfigurationsForUpdateJSON() { - - Map> configurationsForUpdate = new HashMap<>(); - - Map configurations = new HashMap<>(); - - configurations.put("CentersCreateBusinessEvent", true); - configurations.put("ClientActivateBusinessEvent", true); - - configurationsForUpdate.put("externalEventConfigurations", configurations); - - return new Gson().toJson(configurationsForUpdate); - + public static ExternalEventConfigurationUpdateRequest getExternalEventConfigurationsForUpdateRequest() { + return new ExternalEventConfigurationUpdateRequest() + .externalEventConfigurations(Map.of("CentersCreateBusinessEvent", true, "ClientActivateBusinessEvent", true)); } - // TODO: Rewrite to use fineract-client instead! - // Example: - // org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long, - // org.apache.fineract.client.models.PostLoansLoanIdRequest) - @Deprecated(forRemoval = true) public static Map updateExternalEventConfigurations(RequestSpecification requestSpec, - ResponseSpecification responseSpec, String json) { - Map> response = Utils.performServerPut(requestSpec, responseSpec, EXTERNAL_EVENT_CONFIGURATION_URL, - json, "changes"); - return response.get(EXTERNAL_EVENT_CONFIGURATION_RESPONSE); + ResponseSpecification responseSpec, ExternalEventConfigurationUpdateRequest request) { + ExternalEventConfigurationUpdateResponse response = ok(() -> FineractFeignClientHelper.getFineractFeignClient() + .externalEventConfiguration().updateExternalEventConfigurations(request)); + Map updatedConfigurations = new HashMap<>(); + Object configurations = response.getChanges().get("externalEventConfigurations"); + if (configurations instanceof Map configurationMap) { + for (Map.Entry entry : configurationMap.entrySet()) { + updatedConfigurations.put(String.valueOf(entry.getKey()), (Boolean) entry.getValue()); + } + } + return updatedConfigurations; } - // TODO: Rewrite to use fineract-client instead! - // Example: - // org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long, - // org.apache.fineract.client.models.PostLoansLoanIdRequest) - @Deprecated(forRemoval = true) public static void resetDefaultConfigurations(RequestSpecification requestSpec, ResponseSpecification responseSpec) { - Map> configurationsForReset = new HashMap<>(); - - Map configurations = new HashMap<>(); - - configurations.put("CentersCreateBusinessEvent", false); - configurations.put("ClientActivateBusinessEvent", false); - - configurationsForReset.put("externalEventConfigurations", configurations); - - String jsonForResettingConfigurations = new Gson().toJson(configurationsForReset); - Utils.performServerPut(requestSpec, responseSpec, EXTERNAL_EVENT_CONFIGURATION_URL, jsonForResettingConfigurations, ""); + updateExternalEventConfigurations(requestSpec, responseSpec, new ExternalEventConfigurationUpdateRequest() + .externalEventConfigurations(Map.of("CentersCreateBusinessEvent", false, "ClientActivateBusinessEvent", false))); + } + private static Map toMap(ExternalEventConfigurationItemResponse item) { + Map map = new HashMap<>(); + map.put("type", item.getType()); + map.put("enabled", item.getEnabled()); + return map; } } diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/ProvisioningIntegrationTest.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/ProvisioningIntegrationTest.java index dba7db1326a..dc45b037e42 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/ProvisioningIntegrationTest.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/ProvisioningIntegrationTest.java @@ -18,7 +18,6 @@ */ package org.apache.fineract.integrationtests.common; -import com.google.gson.Gson; import io.restassured.builder.RequestSpecBuilder; import io.restassured.builder.ResponseSpecBuilder; import io.restassured.http.ContentType; @@ -30,9 +29,18 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; -import java.util.Map; +import org.apache.fineract.client.models.GetProvisioningCriteriaCriteriaIdResponse; +import org.apache.fineract.client.models.PageLoanProductProvisioningEntryData; import org.apache.fineract.client.models.PageProvisioningEntryData; +import org.apache.fineract.client.models.PostProvisioningCriteriaRequest; +import org.apache.fineract.client.models.PostProvisioningCriteriaResponse; +import org.apache.fineract.client.models.PostProvisioningEntriesResponse; +import org.apache.fineract.client.models.ProvisionEntryRequest; +import org.apache.fineract.client.models.ProvisioningCategoryData; +import org.apache.fineract.client.models.ProvisioningCriteriaDefinitionData; import org.apache.fineract.client.models.ProvisioningEntryData; +import org.apache.fineract.client.models.PutProvisioningCriteriaRequest; +import org.apache.fineract.client.models.PutProvisioningCriteriaResponse; import org.apache.fineract.integrationtests.common.accounting.Account; import org.apache.fineract.integrationtests.common.accounting.AccountHelper; import org.apache.fineract.integrationtests.common.loans.LoanApplicationTestBuilder; @@ -50,7 +58,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@SuppressWarnings({ "rawtypes", "unchecked" }) @ExtendWith(LoanTestLifecycleExtension.class) public class ProvisioningIntegrationTest { @@ -77,7 +84,7 @@ public void setup() throws ParseException { @Test public void testCreateProvisioningCriteria() { - ProvisioningTransactionHelper transactionHelper = new ProvisioningTransactionHelper(requestSpec, responseSpec); + ProvisioningTransactionHelper transactionHelper = new ProvisioningTransactionHelper(); ArrayList loanProducts = new ArrayList<>(LOANPRODUCTS_SIZE); final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec); ClientHelper.verifyClientCreatedOnServer(this.requestSpec, this.responseSpec, clientID); @@ -107,49 +114,47 @@ public void testCreateProvisioningCriteria() { Assertions.assertNotNull(loanID); } - ArrayList categories = transactionHelper.retrieveAllProvisioningCategories(); + List categories = transactionHelper.retrieveAllProvisioningCategories(); Assertions.assertTrue(categories.size() > 0); Account liability = accountHelper.createLiabilityAccount(); Account expense = accountHelper.createExpenseAccount(); - Map requestCriteria = ProvisioningHelper.createProvisioingCriteriaJson(loanProducts, categories, liability, expense); - String provisioningCriteriaCreateJson = new Gson().toJson(requestCriteria); - Integer criteriaId = transactionHelper.createProvisioningCriteria(provisioningCriteriaCreateJson); - Assertions.assertNotNull(criteriaId); + PostProvisioningCriteriaRequest criteriaRequest = ProvisioningHelper.buildProvisioningCriteriaRequest(loanProducts, categories, + liability, expense); + PostProvisioningCriteriaResponse createdCriteria = transactionHelper.createProvisioningCriteria(criteriaRequest); + Assertions.assertNotNull(createdCriteria.getResourceId()); + Long criteriaId = createdCriteria.getResourceId(); - Map newCriteria = transactionHelper.retrieveProvisioningCriteria(criteriaId); - validateProvisioningCriteria(requestCriteria, newCriteria); + GetProvisioningCriteriaCriteriaIdResponse newCriteria = transactionHelper.retrieveProvisioningCriteria(criteriaId); + validateProvisioningCriteria(criteriaRequest, newCriteria); - ArrayList definitions = (ArrayList) newCriteria.get("definitions"); - for (int i = 0; i < definitions.size(); i++) { - Map criteriadefinition = (Map) definitions.get(i); - criteriadefinition.put("provisioningPercentage", Float.valueOf((float) 20.0)); - } - newCriteria.put("locale", "en"); - String updateCriteriaString = new Gson().toJson(newCriteria); - Integer criteriaId1 = transactionHelper.updateProvisioningCriteria(criteriaId, updateCriteriaString); - Map updatedCriteria = transactionHelper.retrieveProvisioningCriteria(criteriaId1); - validateProvisioningCriteria(newCriteria, updatedCriteria); + PutProvisioningCriteriaRequest updateRequest = ProvisioningHelper.buildUpdateProvisioningCriteriaRequest(loanProducts, categories, + liability, expense); + PutProvisioningCriteriaResponse updatedCriteriaResponse = transactionHelper.updateProvisioningCriteria(criteriaId, updateRequest); + GetProvisioningCriteriaCriteriaIdResponse updatedCriteria = transactionHelper + .retrieveProvisioningCriteria(updatedCriteriaResponse.getResourceId()); + validateProvisioningCriteria(criteriaRequest, updatedCriteria); - transactionHelper.deleteProvisioningCriteria(criteriaId1); + transactionHelper.deleteProvisioningCriteria(criteriaId); categories = transactionHelper.retrieveAllProvisioningCategories(); liability = accountHelper.createLiabilityAccount(); expense = accountHelper.createExpenseAccount(); - requestCriteria = ProvisioningHelper.createProvisioingCriteriaJson(loanProducts, categories, liability, expense); - provisioningCriteriaCreateJson = new Gson().toJson(requestCriteria); - criteriaId = transactionHelper.createProvisioningCriteria(provisioningCriteriaCreateJson); - Assertions.assertNotNull(criteriaId); - - String provisioningEntryJson = ProvisioningHelper.createProvisioningEntryJson(); - Integer provisioningEntryId = transactionHelper.createProvisioningEntries(provisioningEntryJson); + criteriaRequest = ProvisioningHelper.buildProvisioningCriteriaRequest(loanProducts, categories, liability, expense); + createdCriteria = transactionHelper.createProvisioningCriteria(criteriaRequest); + Assertions.assertNotNull(createdCriteria.getResourceId()); + criteriaId = createdCriteria.getResourceId(); + + ProvisionEntryRequest provisioningEntryRequest = ProvisioningHelper.createProvisioningEntryRequest(); + PostProvisioningEntriesResponse createdEntry = transactionHelper.createProvisioningEntries(provisioningEntryRequest); + Long provisioningEntryId = createdEntry.getResourceId(); Assertions.assertNotNull(provisioningEntryId); - transactionHelper.updateProvisioningEntry("recreateprovisioningentry", provisioningEntryId, ""); - transactionHelper.updateProvisioningEntry("createjournalentry", provisioningEntryId, ""); - Map entry = transactionHelper.retrieveProvisioningEntry(provisioningEntryId); - Assertions.assertTrue((Boolean) entry.get("journalEntry")); - Map provisioningEntry = transactionHelper.retrieveProvisioningEntries(provisioningEntryId); - Assertions.assertTrue(((ArrayList) provisioningEntry.get("pageItems")).size() > 0); + transactionHelper.updateProvisioningEntry("recreateprovisioningentry", provisioningEntryId, null); + transactionHelper.updateProvisioningEntry("createjournalentry", provisioningEntryId, null); + ProvisioningEntryData entry = transactionHelper.retrieveProvisioningEntry(provisioningEntryId); + Assertions.assertTrue(entry.getJournalEntry()); + PageLoanProductProvisioningEntryData provisioningEntry = transactionHelper.retrieveProvisioningEntries(provisioningEntryId); + Assertions.assertTrue(provisioningEntry.getPageItems().size() > 0); } private HashMap collaterals(Integer collateralId, BigDecimal quantity) { @@ -163,52 +168,20 @@ private void addCollaterals(List collaterals, Integer collateralId, Big collaterals.add(collaterals(collateralId, quantity)); } - private void validateProvisioningCriteria(Map requestCriteria, Map newCriteria) { - - // criteria name validation - String requestCriteriaName = (String) requestCriteria.get("criteriaName"); - String criteriaName = (String) newCriteria.get("criteriaName"); - Assertions.assertEquals(criteriaName, requestCriteriaName); - - // loan products validation - ArrayList requestProducts = (ArrayList) requestCriteria.get("loanProducts"); - ArrayList products = (ArrayList) newCriteria.get("loanProducts"); - Assertions.assertEquals(products.size(), requestProducts.size()); - - ArrayList requestedDefinitions = (ArrayList) requestCriteria.get("definitions"); - ArrayList newdefintions = (ArrayList) newCriteria.get("definitions"); - Assertions.assertEquals(newdefintions.size(), requestedDefinitions.size()); - for (int i = 0; i < newdefintions.size(); i++) { - Map requestedMap = (Map) requestedDefinitions.get(i); - Object requestedCategoryId = requestedMap.get("categoryId"); - boolean found = false; - for (int j = 0; j < newdefintions.size(); j++) { - Map newMap = (Map) newdefintions.get(j); - Object newCategoryId = newMap.get("categoryId"); - if (requestedCategoryId.equals(newCategoryId)) { - found = true; - checkProperty("categoryId", requestedMap, newMap); - checkProperty("categoryName", requestedMap, newMap); - checkProperty("minAge", requestedMap, newMap); - checkProperty("maxAge", requestedMap, newMap); - checkProperty("provisioningPercentage", requestedMap, newMap); - checkProperty("liabilityAccount", requestedMap, newMap); - checkProperty("expenseAccount", requestedMap, newMap); - break; // internal loop - } - } + private void validateProvisioningCriteria(PostProvisioningCriteriaRequest request, GetProvisioningCriteriaCriteriaIdResponse response) { + Assertions.assertEquals(request.getCriteriaName(), response.getCriteriaName()); + Assertions.assertEquals(request.getLoanProducts().size(), response.getLoanProducts().size()); + List requestDefinitions = request.getDefinitions(); + List responseDefinitions = response.getDefinitions(); + Assertions.assertEquals(requestDefinitions.size(), responseDefinitions.size()); + for (ProvisioningCriteriaDefinitionData requestDef : requestDefinitions) { + boolean found = responseDefinitions.stream().anyMatch(d -> d.getCategoryId().equals(requestDef.getCategoryId())); if (!found) { - Assertions.fail("No Category found with Id:" + requestedCategoryId); + Assertions.fail("No Category found with Id:" + requestDef.getCategoryId()); } } } - private void checkProperty(String propertyName, Map requestMap, Map newMap) { - Object requested = requestMap.get(propertyName); - Object modified = newMap.get(propertyName); - Assertions.assertEquals(requested, modified); - } - private Integer createLoanProduct(final boolean multiDisburseLoan, final String accountingRule, final Account... accounts) { LOG.info("------------------------------CREATING NEW LOAN PRODUCT ---------------------------------------"); LoanProductTestBuilder builder = new LoanProductTestBuilder() // @@ -251,7 +224,7 @@ private Integer applyForLoanApplication(final Integer clientID, final Integer lo } private boolean isAlreadyProvisioningEntriesCreated() throws ParseException { - ProvisioningTransactionHelper transactionHelper = new ProvisioningTransactionHelper(requestSpec, responseSpec); + ProvisioningTransactionHelper transactionHelper = new ProvisioningTransactionHelper(); PageProvisioningEntryData entries = transactionHelper.retrieveAllProvisioningEntries(); boolean provisioningetryAlreadyCreated = false; diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/StandingInstructionsHelper.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/StandingInstructionsHelper.java index 848a8330146..4571641c3d7 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/StandingInstructionsHelper.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/StandingInstructionsHelper.java @@ -18,125 +18,64 @@ */ package org.apache.fineract.integrationtests.common; -import com.google.gson.Gson; +import static org.apache.fineract.client.feign.util.FeignCalls.ok; + import io.restassured.specification.RequestSpecification; import io.restassured.specification.ResponseSpecification; -import java.util.HashMap; -import java.util.List; -import lombok.extern.slf4j.Slf4j; +import java.util.Set; +import org.apache.fineract.client.feign.services.StandingInstructionsHistoryApi.RetrieveAllStandingInstructionHistoryQueryParams; +import org.apache.fineract.client.models.GetStandingInstructionHistoryPageItemsResponse; +import org.apache.fineract.client.models.GetStandingInstructionRunHistoryResponse; +import org.apache.fineract.client.models.GetStandingInstructionsStandingInstructionIdResponse; +import org.apache.fineract.client.models.PostStandingInstructionsResponse; +import org.apache.fineract.client.models.StandingInstructionCreationRequest; -@Slf4j -@SuppressWarnings({ "unused", "rawtypes", "unchecked" }) public class StandingInstructionsHelper { - private static final String STANDING_INSTRUCTIONS_URL = "/fineract-provider/api/v1/standinginstructions"; - private static final String STANDING_INSTRUCTIONS_RUN_HISTORY_URL = "/fineract-provider/api/v1/standinginstructionrunhistory"; private static final String LOCALE = "en_GB"; private static final String OFFICE_ID = "1"; private static final String INSTRUCTION_TYPE_FIXED = "1"; - private static final String INSTRUCTION_TYPE_DUES = "2"; private static final String PRIORITY_URGENT = "1"; - private static final String PRIORITY_HIGH = "2"; - private static final String PRIORITY_MEDIUM = "3"; - private static final String PRIORITY_LOW = "4"; - private static final String RECURRENCE_FREQUENCY_DAYS = "0"; private static final String RECURRENCE_FREQUENCY_WEEKS = "1"; - private static final String RECURRENCE_FREQUENCY_MONTHS = "2"; - private static final String RECURRENCE_FREQUENCY_YEARS = "3"; private static final String RECURRENCE_TYPE_PERIODIC = "1"; - private static final String RECURRENCE_TYPE_AS_PER_DUES = "2"; private static final String STATUS_ACTIVE = "1"; - private static final String STATUS_DISABLED = "2"; private static final String TRANSFER_TYPE_ACCOUNT_TRANSFER = "1"; - private static final String TRANSFER_TYPE_LOAN_REPAYMENT = "2"; - private static final String ACCOUNT_TRANSFER_DATE = "01 March 2013"; - private String transferDate = ""; private String officeId = OFFICE_ID; - private RequestSpecification requestSpec; - private ResponseSpecification responseSpec; - - // TODO: Rewrite to use fineract-client instead! - // Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long, - // org.apache.fineract.client.models.PostLoansLoanIdRequest) - @Deprecated(forRemoval = true) - public StandingInstructionsHelper(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { - this.requestSpec = requestSpec; - this.responseSpec = responseSpec; - } - - // TODO: Rewrite to use fineract-client instead! - // Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long, - // org.apache.fineract.client.models.PostLoansLoanIdRequest) - @Deprecated(forRemoval = true) - public String build(final String clientId, final String fromAccountId, final String toAccountId, final String fromAccountType, - final String toAccountType, final String validFrom, final String validTo, final String monthDay) { + public StandingInstructionsHelper(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {} - final HashMap map = new HashMap<>(); - map.put("name", Utils.uniqueRandomStringGenerator("STANDING_INSTRUCTION_", 5)); - map.put("dateFormat", "dd MMMM yyyy"); - map.put("monthDayFormat", "dd MMMM"); - map.put("locale", LOCALE); - map.put("fromClientId", clientId); - map.put("fromAccountId", fromAccountId); - map.put("fromAccountType", fromAccountType); - map.put("fromOfficeId", this.officeId); - map.put("toClientId", clientId); - map.put("toAccountId", toAccountId); - map.put("toAccountType", toAccountType); - map.put("toOfficeId", this.officeId); - map.put("amount", "500"); - map.put("transferType", TRANSFER_TYPE_ACCOUNT_TRANSFER); - map.put("priority", PRIORITY_URGENT); - map.put("status", STATUS_ACTIVE); - map.put("instructionType", INSTRUCTION_TYPE_FIXED); - map.put("validFrom", validFrom); - map.put("validTill", validTo); - map.put("recurrenceType", RECURRENCE_TYPE_PERIODIC); - map.put("recurrenceInterval", "1"); - map.put("recurrenceFrequency", RECURRENCE_FREQUENCY_WEEKS); - map.put("recurrenceOnMonthDay", monthDay); - String savingsApplicationJSON = new Gson().toJson(map); - log.info("{}", savingsApplicationJSON); - return savingsApplicationJSON; + public StandingInstructionCreationRequest build(final String clientId, final String fromAccountId, final String toAccountId, + final String fromAccountType, final String toAccountType, final String validFrom, final String validTo, final String monthDay) { + return new StandingInstructionCreationRequest().name(Utils.uniqueRandomStringGenerator("STANDING_INSTRUCTION_", 5)) + .dateFormat("dd MMMM yyyy").monthDayFormat("dd MMMM").locale(LOCALE).fromClientId(clientId).fromAccountId(fromAccountId) + .fromAccountType(fromAccountType).fromOfficeId(this.officeId).toClientId(clientId).toAccountId(toAccountId) + .toAccountType(toAccountType).toOfficeId(this.officeId).amount("500").transferType(TRANSFER_TYPE_ACCOUNT_TRANSFER) + .priority(PRIORITY_URGENT).status(STATUS_ACTIVE).instructionType(INSTRUCTION_TYPE_FIXED).validFrom(validFrom) + .validTill(validTo).recurrenceType(RECURRENCE_TYPE_PERIODIC).recurrenceInterval("1") + .recurrenceFrequency(RECURRENCE_FREQUENCY_WEEKS).recurrenceOnMonthDay(monthDay); } - // TODO: Rewrite to use fineract-client instead! - // Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long, - // org.apache.fineract.client.models.PostLoansLoanIdRequest) - @Deprecated(forRemoval = true) public Integer createStandingInstruction(final String clientId, final String fromAccountId, final String toAccountId, final String fromAccountType, final String toAccountType, final String validFrom, final String validTo, final String monthDay) { - log.info("-------------------------------- CREATE STANDING INSTRUCTIONS --------------------------------"); - final String standingInstructionAsJSON = new StandingInstructionsHelper(this.requestSpec, this.responseSpec).build(clientId, - fromAccountId, toAccountId, fromAccountType, toAccountType, validFrom, validTo, monthDay); - return Utils.performServerPost(this.requestSpec, this.responseSpec, STANDING_INSTRUCTIONS_URL + "?" + Utils.TENANT_IDENTIFIER, - standingInstructionAsJSON, "resourceId"); + PostStandingInstructionsResponse response = ok( + () -> FineractFeignClientHelper.getFineractFeignClient().standingInstructions().createStandingInstruction( + build(clientId, fromAccountId, toAccountId, fromAccountType, toAccountType, validFrom, validTo, monthDay))); + return response.getResourceId(); } - // TODO: Rewrite to use fineract-client instead! - // Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long, - // org.apache.fineract.client.models.PostLoansLoanIdRequest) - @Deprecated(forRemoval = true) - public HashMap getStandingInstructionById(final String standingInstructionId) { - - log.info("----------------------------- RETRIEVING STANDING INSTRUCTION BY ID---------------------------"); - final String GET_STANDING_INSTRUCTION_BY_ID_URL = STANDING_INSTRUCTIONS_URL + "/" + standingInstructionId + "?" - + Utils.TENANT_IDENTIFIER; - return Utils.performServerGet(this.requestSpec, this.responseSpec, GET_STANDING_INSTRUCTION_BY_ID_URL, ""); + public GetStandingInstructionsStandingInstructionIdResponse getStandingInstructionById(final Long standingInstructionId) { + return ok(() -> FineractFeignClientHelper.getFineractFeignClient().standingInstructions() + .retrieveOneStandingInstruction(standingInstructionId, null, null, null, null, null)); } - // TODO: Rewrite to use fineract-client instead! - // Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long, - // org.apache.fineract.client.models.PostLoansLoanIdRequest) - @Deprecated(forRemoval = true) - public List getStandingInstructionHistory(Integer fromSavingsId, Integer fromAccountType, Integer fromClientId, - Integer transferType) { - final String STANDING_INSTRUCTIONS_HISTORY_URL = STANDING_INSTRUCTIONS_RUN_HISTORY_URL + "?" + Utils.TENANT_IDENTIFIER - + "&fromSavingsId=" + fromSavingsId + "&fromAccountType=" + fromAccountType + "&clientId=" + fromClientId + "&transferType=" - + transferType; - log.info("STANDING_INSTRUCTIONS_HISTORY_URL= {}", STANDING_INSTRUCTIONS_HISTORY_URL); - return Utils.performServerGet(this.requestSpec, this.responseSpec, STANDING_INSTRUCTIONS_HISTORY_URL, "pageItems"); + public Set getStandingInstructionHistory(Integer fromSavingsId, Integer fromAccountType, + Integer fromClientId, Integer transferType) { + RetrieveAllStandingInstructionHistoryQueryParams queryParams = new RetrieveAllStandingInstructionHistoryQueryParams() + .fromAccountId(fromSavingsId.longValue()).fromAccountType(fromAccountType).clientId(fromClientId.longValue()) + .transferType(transferType); + GetStandingInstructionRunHistoryResponse response = ok(() -> FineractFeignClientHelper.getFineractFeignClient() + .standingInstructionsHistory().retrieveAllStandingInstructionHistory(queryParams)); + return response.getPageItems(); } } diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/externalevents/ExternalEventHelper.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/externalevents/ExternalEventHelper.java index fc862beeae5..796fb025245 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/externalevents/ExternalEventHelper.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/externalevents/ExternalEventHelper.java @@ -18,29 +18,23 @@ */ package org.apache.fineract.integrationtests.common.externalevents; -import com.google.common.reflect.TypeToken; -import com.google.gson.Gson; +import static org.apache.fineract.client.feign.util.FeignCalls.ok; + import io.restassured.specification.RequestSpecification; import io.restassured.specification.ResponseSpecification; import java.util.List; import java.util.Map; import lombok.Builder; -import lombok.extern.slf4j.Slf4j; import org.apache.fineract.client.models.ExternalEventConfigurationUpdateRequest; import org.apache.fineract.client.models.ExternalEventConfigurationUpdateResponse; -import org.apache.fineract.client.util.Calls; -import org.apache.fineract.client.util.JSON; import org.apache.fineract.infrastructure.event.external.data.ExternalEventResponse; +import org.apache.fineract.integrationtests.client.feign.helpers.InternalExternalEventsApi; import org.apache.fineract.integrationtests.common.ExternalEventConfigurationHelper; -import org.apache.fineract.integrationtests.common.FineractClientHelper; -import org.apache.fineract.integrationtests.common.Utils; +import org.apache.fineract.integrationtests.common.FineractFeignClientHelper; import org.junit.jupiter.api.Assertions; -@Slf4j public final class ExternalEventHelper { - private static final Gson GSON = new JSON().getGson(); - public ExternalEventHelper() {} @Builder @@ -51,79 +45,53 @@ public static class Filter { private final String category; private final Long aggregateRootId; - public String toQueryParams() { - StringBuilder stringBuilder = new StringBuilder(); + public Map toQueryParams() { + Map queryParams = new java.util.HashMap<>(); if (idempotencyKey != null) { - stringBuilder.append("idempotencyKey=").append(idempotencyKey).append("&"); + queryParams.put("idempotencyKey", idempotencyKey); } - if (type != null) { - stringBuilder.append("type=").append(type).append("&"); + queryParams.put("type", type); } - if (category != null) { - stringBuilder.append("category=").append(category).append("&"); + queryParams.put("category", category); } - if (aggregateRootId != null) { - stringBuilder.append("aggregateRootId=").append(aggregateRootId).append("&"); + queryParams.put("aggregateRootId", aggregateRootId); } - - return stringBuilder.toString(); - + return queryParams; } } - // TODO: Rewrite to use fineract-client instead! - // Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long, - // org.apache.fineract.client.models.PostLoansLoanIdRequest) - @Deprecated(forRemoval = true) public static List getAllExternalEvents(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { - final String url = "/fineract-provider/api/v1/internal/externalevents?" + Utils.TENANT_IDENTIFIER; - log.info("---------------------------------GETTING ALL EXTERNAL EVENTS---------------------------------------------"); - String response = Utils.performServerGet(requestSpec, responseSpec, url); - return GSON.fromJson(response, new TypeToken>() {}.getType()); + return ok(() -> internalExternalEventsApi().getAllExternalEvents(Map.of())); } - // TODO: Rewrite to use fineract-client instead! - // Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long, - // org.apache.fineract.client.models.PostLoansLoanIdRequest) - @Deprecated(forRemoval = true) public static List getAllExternalEvents(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, Filter filter) { - final String url = "/fineract-provider/api/v1/internal/externalevents?" + filter.toQueryParams() + Utils.TENANT_IDENTIFIER; - log.info("---------------------------------GETTING ALL EXTERNAL EVENTS---------------------------------------------"); - String response = Utils.performServerGet(requestSpec, responseSpec, url); - return GSON.fromJson(response, new TypeToken>() {}.getType()); + return ok(() -> internalExternalEventsApi().getAllExternalEvents(filter.toQueryParams())); } - // TODO: Rewrite to use fineract-client instead! - // Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long, - // org.apache.fineract.client.models.PostLoansLoanIdRequest) - @Deprecated(forRemoval = true) public static void deleteAllExternalEvents(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { - final String url = "/fineract-provider/api/v1/internal/externalevents?" + Utils.TENANT_IDENTIFIER; - log.info("-----------------------------DELETE ALL EXTERNAL EVENTS PARTITIONS----------------------------------------"); - Utils.performServerDelete(requestSpec, responseSpec, url, null); + ok(() -> { + internalExternalEventsApi().deleteAllExternalEvents(); + return null; + }); } - // TODO: Rewrite to use fineract-client instead! - // Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long, - // org.apache.fineract.client.models.PostLoansLoanIdRequest) - @Deprecated(forRemoval = true) public static void changeEventState(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, String eventName, boolean status) { final Map updatedConfigurations = ExternalEventConfigurationHelper.updateExternalEventConfigurations(requestSpec, - responseSpec, "{\"externalEventConfigurations\":{\"" + eventName + "\":" + status + "}}\n"); + responseSpec, new ExternalEventConfigurationUpdateRequest().externalEventConfigurations(Map.of(eventName, status))); Assertions.assertEquals(updatedConfigurations.size(), 1); Assertions.assertTrue(updatedConfigurations.containsKey(eventName)); Assertions.assertEquals(status, updatedConfigurations.get(eventName)); } public void configureBusinessEvent(String eventName, boolean enabled) { - ExternalEventConfigurationUpdateResponse result = Calls - .ok(FineractClientHelper.getFineractClient().externalEventConfigurationApi.updateExternalEventConfigurations( + ExternalEventConfigurationUpdateResponse result = ok( + () -> FineractFeignClientHelper.getFineractFeignClient().externalEventConfiguration().updateExternalEventConfigurations( new ExternalEventConfigurationUpdateRequest().externalEventConfigurations(Map.of(eventName, enabled)))); Map changes = result.getChanges(); Assertions.assertNotNull(changes); @@ -143,4 +111,8 @@ public void disableBusinessEvent(String eventName) { configureBusinessEvent(eventName, false); } + private static InternalExternalEventsApi internalExternalEventsApi() { + return FineractFeignClientHelper.getFineractFeignClient().create(InternalExternalEventsApi.class); + } + } diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/externalevents/ExternalEventsExtension.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/externalevents/ExternalEventsExtension.java index 80befb045a8..dab5bfe950b 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/externalevents/ExternalEventsExtension.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/externalevents/ExternalEventsExtension.java @@ -31,6 +31,7 @@ import java.util.Map; import java.util.stream.Collectors; import lombok.extern.slf4j.Slf4j; +import org.apache.fineract.client.models.ExternalEventConfigurationUpdateRequest; import org.apache.fineract.integrationtests.common.ExternalEventConfigurationHelper; import org.apache.fineract.integrationtests.common.Utils; import org.junit.jupiter.api.Assertions; @@ -80,7 +81,7 @@ public void beforeEach(ExtensionContext context) { private void restore(String key, Boolean value) { final Map updatedConfigurations = ExternalEventConfigurationHelper.updateExternalEventConfigurations(requestSpec, - responseSpec, "{\"externalEventConfigurations\":{\"" + key + "\":" + value + "}}\n"); + responseSpec, new ExternalEventConfigurationUpdateRequest().externalEventConfigurations(Map.of(key, value))); Assertions.assertEquals(updatedConfigurations.size(), 1); Assertions.assertTrue(updatedConfigurations.containsKey(key)); Assertions.assertEquals(value, updatedConfigurations.get(key)); diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/externalevents/LoanBusinessEvent.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/externalevents/LoanBusinessEvent.java index 49a52db9615..c924d663ab9 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/externalevents/LoanBusinessEvent.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/externalevents/LoanBusinessEvent.java @@ -62,10 +62,11 @@ public boolean verify(ExternalEventResponse externalEvent, DateTimeFormatter for var principalDisbursed = summary.get("principalDisbursed"); var principalOutstanding = summary.get("principalOutstanding"); - Double statusId = (Double) status.get("id"); + Double statusId = status.get("id") instanceof Number ? ((Number) status.get("id")).doubleValue() : null; + Double pd = principalDisbursed instanceof Number ? ((Number) principalDisbursed).doubleValue() : null; + Double po = principalOutstanding instanceof Number ? ((Number) principalOutstanding).doubleValue() : null; return super.verify(externalEvent, formatter) && Objects.equals(statusId, getStatusId().doubleValue()) - && Objects.equals(principalDisbursed, getPrincipalDisbursed()) - && Objects.equals(principalOutstanding, getPrincipalOutstanding()) && loanTermVariationsMatch( + && Objects.equals(pd, getPrincipalDisbursed()) && Objects.equals(po, getPrincipalOutstanding()) && loanTermVariationsMatch( (List>) externalEvent.getPayLoad().get("loanTermVariations"), loanTermVariationType); } diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/externalevents/LoanTransactionBusinessEvent.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/externalevents/LoanTransactionBusinessEvent.java index f878e011701..8f87e3f8a54 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/externalevents/LoanTransactionBusinessEvent.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/externalevents/LoanTransactionBusinessEvent.java @@ -55,9 +55,15 @@ public boolean verify(ExternalEventResponse externalEvent, DateTimeFormatter for Object feePortion = externalEvent.getPayLoad().get("feeChargesPortion"); Object penaltyPortion = externalEvent.getPayLoad().get("penaltyChargesPortion"); - return super.verify(externalEvent, formatter) && Objects.equals(amount, getAmount()) - && Objects.equals(outstandingLoanBalance, getOutstandingLoanBalance()) - && Objects.equals(principalPortion, getPrincipalPortion()) && Objects.equals(interestPortion, getInterestPortion()) - && Objects.equals(feePortion, getFeeChargesPortion()) && Objects.equals(penaltyPortion, getPenaltyChargesPortion()); + Double amt = amount instanceof Number ? ((Number) amount).doubleValue() : null; + Double olb = outstandingLoanBalance instanceof Number ? ((Number) outstandingLoanBalance).doubleValue() : null; + Double pp = principalPortion instanceof Number ? ((Number) principalPortion).doubleValue() : null; + Double ip = interestPortion instanceof Number ? ((Number) interestPortion).doubleValue() : null; + Double fp = feePortion instanceof Number ? ((Number) feePortion).doubleValue() : null; + Double pep = penaltyPortion instanceof Number ? ((Number) penaltyPortion).doubleValue() : null; + return super.verify(externalEvent, formatter) && Objects.equals(amt, getAmount()) + && Objects.equals(olb, getOutstandingLoanBalance()) && Objects.equals(pp, getPrincipalPortion()) + && Objects.equals(ip, getInterestPortion()) && Objects.equals(fp, getFeeChargesPortion()) + && Objects.equals(pep, getPenaltyChargesPortion()); } } diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/provisioning/ProvisioningHelper.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/provisioning/ProvisioningHelper.java index 8f9bfcf94cb..abd3b19abad 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/provisioning/ProvisioningHelper.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/provisioning/ProvisioningHelper.java @@ -18,16 +18,24 @@ */ package org.apache.fineract.integrationtests.common.provisioning; -import com.google.gson.Gson; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import static org.apache.fineract.client.feign.util.FeignCalls.ok; + +import java.math.BigDecimal; import java.security.SecureRandom; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; -import java.util.HashMap; +import java.util.List; import java.util.Locale; -import java.util.Map; +import org.apache.fineract.client.models.LoanProductData; +import org.apache.fineract.client.models.PostProvisioningCriteriaRequest; +import org.apache.fineract.client.models.PostProvisioningCriteriaResponse; +import org.apache.fineract.client.models.ProvisionEntryRequest; +import org.apache.fineract.client.models.ProvisioningCategoryData; +import org.apache.fineract.client.models.ProvisioningCriteriaDefinitionData; +import org.apache.fineract.client.models.PutProvisioningCriteriaRequest; +import org.apache.fineract.integrationtests.common.FineractFeignClientHelper; import org.apache.fineract.integrationtests.common.Utils; import org.apache.fineract.integrationtests.common.accounting.Account; @@ -35,99 +43,85 @@ public final class ProvisioningHelper { private static final SecureRandom rand = new SecureRandom(); - private ProvisioningHelper() { - - } + private ProvisioningHelper() {} - // TODO: Rewrite to use fineract-client instead! - // Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long, - // org.apache.fineract.client.models.PostLoansLoanIdRequest) - @Deprecated(forRemoval = true) - @SuppressFBWarnings(value = { - "DMI_RANDOM_USED_ONLY_ONCE" }, justification = "False positive for random object created and used only once") - public static Map createProvisioingCriteriaJson(ArrayList loanProducts, ArrayList categories, Account liability, - Account expense) { - final HashMap map = new HashMap<>(); - map.put("loanProducts", addLoanProducts(loanProducts)); - map.put("definitions", addProvisioningCategories(categories, liability, expense)); + public static PostProvisioningCriteriaRequest buildProvisioningCriteriaRequest(List loanProductIds, + List categories, Account liability, Account expense) { DateFormat simple = new SimpleDateFormat("dd MMMM yyyy", Locale.US); - String formattedString = simple.format(Date.from(Utils.getLocalDateOfTenant().atStartOfDay(Utils.getZoneIdOfTenant()).toInstant())); + String formattedDate = simple.format(Date.from(Utils.getLocalDateOfTenant().atStartOfDay(Utils.getZoneIdOfTenant()).toInstant())); + String criteriaName = "General Provisioning Criteria" + formattedDate + rand.nextLong(); - String criteriaName = "General Provisioning Criteria" + formattedString + rand.nextLong(); - map.put("criteriaName", criteriaName); - map.put("locale", "en"); - return map; - } + List definitions = buildDefinitions(categories, liability, expense); - // TODO: Rewrite to use fineract-client instead! - // Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long, - // org.apache.fineract.client.models.PostLoansLoanIdRequest) - @Deprecated(forRemoval = true) - public static String createProvisioningEntryJson() { - final HashMap map = new HashMap<>(); - map.put("createjournalentries", Boolean.FALSE); - map.put("locale", "en"); - map.put("dateFormat", "dd MMMM yyyy"); - DateFormat simple = new SimpleDateFormat("dd MMMM yyyy", Locale.US); - map.put("date", simple.format(Date.from(Utils.getLocalDateOfTenant().atStartOfDay(Utils.getZoneIdOfTenant()).toInstant()))); - String provisioningEntryCreateJson = new Gson().toJson(map); - return provisioningEntryCreateJson; + return new PostProvisioningCriteriaRequest().criteriaName(criteriaName).loanProducts(buildLoanProducts(loanProductIds)) + .definitions(definitions); } - // TODO: Rewrite to use fineract-client instead! - // Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long, - // org.apache.fineract.client.models.PostLoansLoanIdRequest) - @Deprecated(forRemoval = true) - public static String createProvisioningEntryJsonWithJournalsEnabled() { - final HashMap map = new HashMap<>(); - map.put("createjournalentries", Boolean.TRUE); - map.put("locale", "en"); - map.put("dateFormat", "dd MMMM yyyy"); + public static PutProvisioningCriteriaRequest buildUpdateProvisioningCriteriaRequest(List loanProductIds, + List categories, Account liability, Account expense) { DateFormat simple = new SimpleDateFormat("dd MMMM yyyy", Locale.US); - map.put("date", simple.format(Date.from(Utils.getLocalDateOfTenant().atStartOfDay(Utils.getZoneIdOfTenant()).toInstant()))); - String provisioningEntryCreateJson = new Gson().toJson(map); - return provisioningEntryCreateJson; + String formattedDate = simple.format(Date.from(Utils.getLocalDateOfTenant().atStartOfDay(Utils.getZoneIdOfTenant()).toInstant())); + String criteriaName = "General Provisioning Criteria" + formattedDate + rand.nextLong(); + + return new PutProvisioningCriteriaRequest().criteriaName(criteriaName).loanProducts(buildLoanProducts(loanProductIds)) + .definitions(buildDefinitions(categories, liability, expense)); } - // TODO: Rewrite to use fineract-client instead! - // Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long, - // org.apache.fineract.client.models.PostLoansLoanIdRequest) - @Deprecated(forRemoval = true) - private static ArrayList> addLoanProducts(ArrayList loanProducts) { - ArrayList> list = new ArrayList<>(); - for (int i = 0; i < loanProducts.size(); i++) { - HashMap map = new HashMap<>(); - map.put("id", loanProducts.get(i)); - list.add(map); + private static List buildLoanProducts(List loanProductIds) { + List list = new ArrayList<>(); + for (Integer id : loanProductIds) { + LoanProductData product = new LoanProductData(); + product.setId(id.longValue()); + list.add(product); } return list; } - // TODO: Rewrite to use fineract-client instead! - // Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long, - // org.apache.fineract.client.models.PostLoansLoanIdRequest) - @Deprecated(forRemoval = true) - public static ArrayList> addProvisioningCategories(ArrayList categories, Account liability, Account expense) { - ArrayList> list = new ArrayList<>(); - int minStart = 0; - int maxStart = 30; + private static List buildDefinitions(List categories, Account liability, + Account expense) { + List definitions = new ArrayList<>(); + for (int i = 0; i < categories.size(); i++) { + ProvisioningCategoryData category = categories.get(i); + definitions.add(new ProvisioningCriteriaDefinitionData().categoryId(category.getId()).categoryName(category.getCategoryName()) + .minAge((long) ((i * 30) + 1)).maxAge(i == categories.size() - 1 ? 90000L : (long) ((i + 1) * 30)) + .provisioningPercentage(BigDecimal.valueOf((i + 1) * 5.5)).liabilityAccount(liability.getAccountID().longValue()) + .expenseAccount(expense.getAccountID().longValue())); + } + return definitions; + } + public static PostProvisioningCriteriaResponse createProvisioningCriteria(List loanProductIds, + List categories, Account liability, Account expense) { + DateFormat simple = new SimpleDateFormat("dd MMMM yyyy", Locale.US); + String formattedDate = simple.format(Date.from(Utils.getLocalDateOfTenant().atStartOfDay(Utils.getZoneIdOfTenant()).toInstant())); + String criteriaName = "General Provisioning Criteria" + formattedDate + rand.nextLong(); + + List definitions = new ArrayList<>(); for (int i = 0; i < categories.size(); i++) { - HashMap map = new HashMap<>(); - HashMap category = (HashMap) categories.get(i); - map.put("categoryId", category.get("id")); - map.put("categoryName", category.get("categoryName")); - map.put("minAge", (i * 30) + 1); - if (i == categories.size() - 1) { - map.put("maxAge", 90000); - } else { - map.put("maxAge", (i + 1) * 30); - } - map.put("provisioningPercentage", Float.valueOf((float) ((i + 1) * 5.5))); - map.put("liabilityAccount", liability.getAccountID()); - map.put("expenseAccount", expense.getAccountID()); - list.add(map); + ProvisioningCategoryData category = categories.get(i); + definitions.add(new ProvisioningCriteriaDefinitionData().categoryId(category.getId()).categoryName(category.getCategoryName()) + .minAge((long) ((i * 30) + 1)).maxAge(i == categories.size() - 1 ? 90000L : (long) ((i + 1) * 30)) + .provisioningPercentage(BigDecimal.valueOf((i + 1) * 5.5)).liabilityAccount(liability.getAccountID().longValue()) + .expenseAccount(expense.getAccountID().longValue())); } - return list; + + final PostProvisioningCriteriaRequest request = new PostProvisioningCriteriaRequest().criteriaName(criteriaName) + .loanProducts(buildLoanProducts(loanProductIds)).definitions(definitions); + + return ok(() -> FineractFeignClientHelper.getFineractFeignClient().provisioningCriteria().createProvisioningCriteria(request)); + } + + public static ProvisionEntryRequest createProvisioningEntryRequest() { + return createProvisioningEntryRequest(false); + } + + public static ProvisionEntryRequest createProvisioningEntryRequestWithJournalsEnabled() { + return createProvisioningEntryRequest(true); + } + + private static ProvisionEntryRequest createProvisioningEntryRequest(boolean createJournalEntries) { + DateFormat simple = new SimpleDateFormat("dd MMMM yyyy", Locale.US); + return new ProvisionEntryRequest().createjournalentries(createJournalEntries).locale("en").dateFormat("dd MMMM yyyy") + .date(simple.format(Date.from(Utils.getLocalDateOfTenant().atStartOfDay(Utils.getZoneIdOfTenant()).toInstant()))); } } diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/provisioning/ProvisioningTransactionHelper.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/provisioning/ProvisioningTransactionHelper.java index 143a20a2229..0adcfd8fc05 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/provisioning/ProvisioningTransactionHelper.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/provisioning/ProvisioningTransactionHelper.java @@ -18,117 +18,72 @@ */ package org.apache.fineract.integrationtests.common.provisioning; -import io.restassured.specification.RequestSpecification; -import io.restassured.specification.ResponseSpecification; -import java.util.ArrayList; -import java.util.Map; +import static org.apache.fineract.client.feign.util.FeignCalls.ok; + +import java.util.List; +import org.apache.fineract.client.models.DeleteProvisioningCriteriaResponse; +import org.apache.fineract.client.models.GetProvisioningCriteriaCriteriaIdResponse; +import org.apache.fineract.client.models.PageLoanProductProvisioningEntryData; import org.apache.fineract.client.models.PageProvisioningEntryData; -import org.apache.fineract.client.util.Calls; -import org.apache.fineract.integrationtests.common.FineractClientHelper; -import org.apache.fineract.integrationtests.common.Utils; +import org.apache.fineract.client.models.PostProvisioningCriteriaRequest; +import org.apache.fineract.client.models.PostProvisioningCriteriaResponse; +import org.apache.fineract.client.models.PostProvisioningEntriesResponse; +import org.apache.fineract.client.models.ProvisionEntryRequest; +import org.apache.fineract.client.models.ProvisioningCategoryData; +import org.apache.fineract.client.models.ProvisioningEntryData; +import org.apache.fineract.client.models.PutProvisioningCriteriaRequest; +import org.apache.fineract.client.models.PutProvisioningCriteriaResponse; +import org.apache.fineract.client.models.PutProvisioningEntriesRequest; +import org.apache.fineract.client.models.PutProvisioningEntriesResponse; +import org.apache.fineract.integrationtests.common.FineractFeignClientHelper; public class ProvisioningTransactionHelper { - private static final String PROVISIONING_CATEGORY_URL = "/fineract-provider/api/v1/provisioningcategory?" + Utils.TENANT_IDENTIFIER; - - private static final String CREATE_PROVISIONING_CRITERIA_URL = "/fineract-provider/api/v1/provisioningcriteria?" - + Utils.TENANT_IDENTIFIER; - private static final String CREATE_PROVISIONING_ENTRY_URL = "/fineract-provider/api/v1/provisioningentries?" + Utils.TENANT_IDENTIFIER; - - private final RequestSpecification requestSpec; - private final ResponseSpecification responseSpec; + public ProvisioningTransactionHelper() {} - // TODO: Rewrite to use fineract-client instead! - // Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long, - // org.apache.fineract.client.models.PostLoansLoanIdRequest) - @Deprecated(forRemoval = true) - public ProvisioningTransactionHelper(RequestSpecification requestSpec, ResponseSpecification responeSpec) { - this.requestSpec = requestSpec; - this.responseSpec = responeSpec; + public List retrieveAllProvisioningCategories() { + return ok(() -> FineractFeignClientHelper.getFineractFeignClient().provisioningCategory().retrieveAll10()); } - // TODO: Rewrite to use fineract-client instead! - // Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long, - // org.apache.fineract.client.models.PostLoansLoanIdRequest) - @Deprecated(forRemoval = true) - public ArrayList retrieveAllProvisioningCategories() { - return Utils.performServerGet(requestSpec, responseSpec, PROVISIONING_CATEGORY_URL, ""); + public PostProvisioningCriteriaResponse createProvisioningCriteria(final PostProvisioningCriteriaRequest request) { + return ok(() -> FineractFeignClientHelper.getFineractFeignClient().provisioningCriteria().createProvisioningCriteria(request)); } - // TODO: Rewrite to use fineract-client instead! - // Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long, - // org.apache.fineract.client.models.PostLoansLoanIdRequest) - @Deprecated(forRemoval = true) - public Integer createProvisioningCriteria(final String provsioningCriteriaJson) { - return Utils.performServerPost(this.requestSpec, this.responseSpec, CREATE_PROVISIONING_CRITERIA_URL, provsioningCriteriaJson, - "resourceId"); + public GetProvisioningCriteriaCriteriaIdResponse retrieveProvisioningCriteria(final Long criteriaId) { + return ok(() -> FineractFeignClientHelper.getFineractFeignClient().provisioningCriteria().retrieveProvisioningCriteria(criteriaId)); } - // TODO: Rewrite to use fineract-client instead! - // Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long, - // org.apache.fineract.client.models.PostLoansLoanIdRequest) - @Deprecated(forRemoval = true) - public Map retrieveProvisioningCriteria(final Integer criteriaId) { - String url = "/fineract-provider/api/v1/provisioningcriteria/" + criteriaId + "?" + Utils.TENANT_IDENTIFIER; - return Utils.performServerGet(requestSpec, responseSpec, url, ""); + public PutProvisioningCriteriaResponse updateProvisioningCriteria(final Long criteriaId, final PutProvisioningCriteriaRequest request) { + return ok(() -> FineractFeignClientHelper.getFineractFeignClient().provisioningCriteria().updateProvisioningCriteria(criteriaId, + request)); } - // TODO: Rewrite to use fineract-client instead! - // Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long, - // org.apache.fineract.client.models.PostLoansLoanIdRequest) - @Deprecated(forRemoval = true) - public Integer updateProvisioningCriteria(final Integer criteriaId, final String provsioningCriteriaJson) { - String url = "/fineract-provider/api/v1/provisioningcriteria/" + criteriaId + "?" + Utils.TENANT_IDENTIFIER; - return Utils.performServerPut(this.requestSpec, this.responseSpec, url, provsioningCriteriaJson, "resourceId"); + public DeleteProvisioningCriteriaResponse deleteProvisioningCriteria(final Long criteriaId) { + return ok(() -> FineractFeignClientHelper.getFineractFeignClient().provisioningCriteria().deleteProvisioningCriteria(criteriaId)); } - // TODO: Rewrite to use fineract-client instead! - // Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long, - // org.apache.fineract.client.models.PostLoansLoanIdRequest) - @Deprecated(forRemoval = true) - public Integer deleteProvisioningCriteria(final Integer criteriaId) { - String url = "/fineract-provider/api/v1/provisioningcriteria/" + criteriaId + "?" + Utils.TENANT_IDENTIFIER; - return Utils.performServerDelete(this.requestSpec, this.responseSpec, url, "resourceId"); + public PostProvisioningEntriesResponse createProvisioningEntries(final ProvisionEntryRequest request) { + return ok(() -> FineractFeignClientHelper.getFineractFeignClient().provisioningEntries().createProvisioningEntries(request)); } - // TODO: Rewrite to use fineract-client instead! - // Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long, - // org.apache.fineract.client.models.PostLoansLoanIdRequest) - @Deprecated(forRemoval = true) - public Integer createProvisioningEntries(final String provsioningCriteriaJson) { - return Utils.performServerPost(this.requestSpec, this.responseSpec, CREATE_PROVISIONING_ENTRY_URL, provsioningCriteriaJson, - "resourceId"); + public PutProvisioningEntriesResponse updateProvisioningEntry(final String command, final Long entryId, + PutProvisioningEntriesRequest request) { + return ok(() -> FineractFeignClientHelper.getFineractFeignClient().provisioningEntries().modifyProvisioningEntry(entryId, command, + request)); } - // TODO: Rewrite to use fineract-client instead! - // Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long, - // org.apache.fineract.client.models.PostLoansLoanIdRequest) - @Deprecated(forRemoval = true) - public Integer updateProvisioningEntry(final String command, final Integer entryId, String jsonBody) { - String url = "/fineract-provider/api/v1/provisioningentries/" + entryId + "?command=" + command + "&" + Utils.TENANT_IDENTIFIER; - return Utils.performServerPost(requestSpec, responseSpec, url, jsonBody, "resourceId"); + public ProvisioningEntryData retrieveProvisioningEntry(final Long provisioningEntry) { + return ok(() -> FineractFeignClientHelper.getFineractFeignClient().provisioningEntries() + .retrieveOneProvisioningEntry(provisioningEntry)); } - // TODO: Rewrite to use fineract-client instead! - // Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long, - // org.apache.fineract.client.models.PostLoansLoanIdRequest) - @Deprecated(forRemoval = true) - public Map retrieveProvisioningEntry(final Integer provisioningEntry) { - String url = "/fineract-provider/api/v1/provisioningentries/" + provisioningEntry + "?" + Utils.TENANT_IDENTIFIER; - return Utils.performServerGet(requestSpec, responseSpec, url, ""); - } - - // TODO: Rewrite to use fineract-client instead! - // Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long, - // org.apache.fineract.client.models.PostLoansLoanIdRequest) - @Deprecated(forRemoval = true) - public Map retrieveProvisioningEntries(final Integer provisioningEntry) { - String url = "/fineract-provider/api/v1/provisioningentries/entries?entryId=" + provisioningEntry + "&" + Utils.TENANT_IDENTIFIER; - return Utils.performServerGet(requestSpec, responseSpec, url, ""); + public PageLoanProductProvisioningEntryData retrieveProvisioningEntries(final Long provisioningEntry) { + return ok(() -> FineractFeignClientHelper.getFineractFeignClient().provisioningEntries() + .retrieveProvisioningEntriesLoanProducts(provisioningEntry, null, null, null, null, null)); } public PageProvisioningEntryData retrieveAllProvisioningEntries() { - return Calls.ok(FineractClientHelper.getFineractClient().provisioningEntries.retrieveAllProvisioningEntries(null, null)); + return ok(() -> FineractFeignClientHelper.getFineractFeignClient().provisioningEntries() + .retrieveAllProvisioningEntries((Integer) null, (Integer) null)); } - }