DeathGun44 commented on code in PR #6084:
URL: https://github.com/apache/fineract/pull/6084#discussion_r3525733391
##########
integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanAccountDisbursementToSavingsWithAutoDownPaymentTest.java:
##########
@@ -101,170 +115,90 @@ public void
loanDisbursementToSavingsWithAutoDownPaymentAndStandingInstructionsT
installment(250.0, false, "15 April 2023")//
);
- // verify Disbursement Transaction is account transfer
- verifyTransactionIsAccountTransfer(LocalDate.of(2023, 3, 1),
1000.0f, loanId.intValue(), "disbursement");
+ verifyTransactionIsAccountTransfer(LocalDate.of(2023, Month.MARCH,
1), 1000.0, loanId, "disbursement");
- // verify Down payment Transaction is account transfer
- verifyTransactionIsAccountTransfer(LocalDate.of(2023, 3, 1),
250.0f, loanId.intValue(), "downPayment");
+ verifyTransactionIsAccountTransfer(LocalDate.of(2023, Month.MARCH,
1), 250.0, loanId, "downPayment");
- // verify savings transactions
- verifySavingsTransactions(savingsAccountId, savingsAccountHelper);
+ verifySavingsTransactions(savingsAccountId);
verifyBusinessEvent();
- disableLoanBalanceChangedBusinessEvent();
+
externalEventHelper.disableBusinessEvent(LOAN_BALANCE_CHANGED_EVENT);
});
}
- private void verifySavingsTransactions(final Integer savingsId, final
SavingsAccountHelper savingsAccountHelper) {
- Map<String, Object> queryParams = new HashMap<>();
- SavingsAccountTransactionsSearchResponse transactionsResponse =
savingsAccountHelper.searchSavingsTransactions(savingsId,
- queryParams);
+ private void verifySavingsTransactions(final Long savingsId) {
+ SavingsAccountData savingsAccount =
savingsHelper.getSavingsDetails(savingsId);
+ List<SavingsAccountTransactionData> pageItemsList =
savingsAccount.getTransactions();
- Assertions.assertNotNull(transactionsResponse);
- assertEquals(2, transactionsResponse.getTotal());
- Assertions.assertNotNull(transactionsResponse.getContent());
- List<GetSavingsAccountTransactionsPageItem> pageItemsList =
List.copyOf(transactionsResponse.getContent());
+ Assertions.assertNotNull(pageItemsList);
assertEquals(2, pageItemsList.size());
- // check withdrawal
- GetSavingsAccountTransactionsPageItem withDrawalTransaction =
pageItemsList.get(0);
+ SavingsAccountTransactionData withDrawalTransaction =
pageItemsList.get(0);
assertEquals("savingsAccountTransactionType.withdrawal",
withDrawalTransaction.getTransactionType().getCode());
assertTrue(MathUtil.isEqualTo(BigDecimal.valueOf(250),
withDrawalTransaction.getAmount()));
- assertEquals("DEBIT", withDrawalTransaction.getEntryType().getValue());
+ assertEquals(SavingsAccountTransactionData.EntryTypeEnum.DEBIT,
withDrawalTransaction.getEntryType());
assertTrue(MathUtil.isEqualTo(BigDecimal.valueOf(750),
withDrawalTransaction.getRunningBalance()));
- // check deposit
- GetSavingsAccountTransactionsPageItem depositTransaction =
pageItemsList.get(1);
+ SavingsAccountTransactionData depositTransaction =
pageItemsList.get(1);
assertEquals("savingsAccountTransactionType.deposit",
depositTransaction.getTransactionType().getCode());
assertTrue(MathUtil.isEqualTo(BigDecimal.valueOf(1000),
depositTransaction.getAmount()));
- assertEquals("CREDIT", depositTransaction.getEntryType().getValue());
+ assertEquals(SavingsAccountTransactionData.EntryTypeEnum.CREDIT,
depositTransaction.getEntryType());
assertTrue(MathUtil.isEqualTo(BigDecimal.valueOf(1000),
depositTransaction.getRunningBalance()));
-
}
private void mapLiabilityTransferFinancialActivity(Long loanProductId) {
- FinancialActivityAccountHelper financialActivityAccountHelper = new
FinancialActivityAccountHelper(requestSpec);
- GetLoanProductsProductIdResponse getLoanProductsProductIdResponse =
loanProductHelper.retrieveLoanProductById(loanProductId);
- Integer financialActivityAccountId = (Integer)
financialActivityAccountHelper.createFinancialActivityAccount(
-
AccountingConstants.FinancialActivity.LIABILITY_TRANSFER.getValue(),
-
getLoanProductsProductIdResponse.getAccountingMappings().getFundSourceAccount().getId().intValue(),
responseSpec,
- CommonConstants.RESPONSE_RESOURCE_ID);
- assertNotNull(financialActivityAccountId);
- }
-
- private Long createLoanWithLinkedAccountAndStandingInstructions(final
Integer clientID, final Long loanProductID,
- final Integer savingsId, final String externalId) {
-
- String loanApplicationJSON = new
LoanApplicationTestBuilder().withPrincipal("1000").withLoanTermFrequency("45")
-
.withLoanTermFrequencyAsDays().withNumberOfRepayments("3").withRepaymentEveryAfter("15").withRepaymentFrequencyTypeAsDays()
-
.withInterestRatePerPeriod("0").withInterestTypeAsDecliningBalance().withAmortizationTypeAsEqualPrincipalPayments()
-
.withInterestCalculationPeriodTypeSameAsRepaymentPeriod().withExpectedDisbursementDate("01
March 2023")
- .withSubmittedOnDate("01 March
2023").withLoanType("individual").withExternalId(externalId)
-
.withCreateStandingInstructionAtDisbursement().build(clientID.toString(),
loanProductID.toString(), savingsId.toString());
-
- final Integer loanId =
loanTransactionHelper.getLoanId(loanApplicationJSON);
- loanTransactionHelper.approveLoan("01 March 2023", "1000", loanId,
null);
- return loanId.longValue();
+ Long fundSourceAccountId =
retrieveLoanProduct(loanProductId).getAccountingMappings().getFundSourceAccount().getId();
+ PostFinancialActivityAccountsResponse response =
financialActivityAccountHelper
+ .createFinancialActivityAccount(new
PostFinancialActivityAccountsRequest()
+ .financialActivityId((long)
AccountingConstants.FinancialActivity.LIABILITY_TRANSFER.getValue())
+ .glAccountId(fundSourceAccountId));
+ assertNotNull(response.getResourceId());
}
- private Integer createApproveActivateSavingsAccountDailyPosting(final
Integer clientID, final String startDate,
- final SavingsAccountHelper savingsAccountHelper) {
- final Integer savingsProductID = createSavingsProductDailyPosting();
- assertNotNull(savingsProductID);
- return
savingsAccountHelper.createApproveActivateSavingsAccount(clientID,
savingsProductID, startDate);
+ private Long createApproveActivateSavingsAccountDailyPosting(final Long
clientId, final String startDate) {
+ final Long savingsProductId = createSavingsProductDailyPosting();
+ assertNotNull(savingsProductId);
+ return savingsHelper.createApproveActivateSavings(clientId,
savingsProductId, startDate);
}
- private Integer createSavingsProductDailyPosting() {
- SavingsProductHelper savingsProductHelper = new SavingsProductHelper();
- final String savingsProductJSON =
savingsProductHelper.withInterestCompoundingPeriodTypeAsDaily()
-
.withInterestPostingPeriodTypeAsMonthly().withInterestCalculationPeriodTypeAsDailyBalance().build();
- return SavingsProductHelper.createSavingsProduct(savingsProductJSON,
requestSpec, responseSpec);
+ private Long createSavingsProductDailyPosting() {
+ return
savingsProductHelper.createSavingsProduct(SavingsRequestBuilders.defaultSavingsProduct()).getResourceId();
}
private Long
createLoanProductWithMultiDisbursalAndRepaymentsWithEnableDownPayment() {
- boolean multiDisburseEnabled = true;
PostLoanProductsRequest product =
createOnePeriod30DaysLongNoInterestPeriodicAccrualProduct();
- product.setMultiDisburseLoan(multiDisburseEnabled);
+ product.setMultiDisburseLoan(true);
product.setNumberOfRepayments(3);
product.setRepaymentEvery(15);
-
- if (!multiDisburseEnabled) {
- product.disallowExpectedDisbursements(null);
- product.setAllowApprovedDisbursedAmountsOverApplied(null);
- product.overAppliedCalculationType(null);
- product.overAppliedNumber(null);
- }
-
product.setEnableDownPayment(true);
product.setDisbursedAmountPercentageForDownPayment(DOWN_PAYMENT_PERCENTAGE);
product.setEnableAutoRepaymentForDownPayment(true);
-
- PostLoanProductsResponse loanProductResponse =
loanProductHelper.createLoanProduct(product);
- GetLoanProductsProductIdResponse getLoanProductsProductIdResponse =
loanProductHelper
- .retrieveLoanProductById(loanProductResponse.getResourceId());
- assertNotNull(getLoanProductsProductIdResponse);
- return loanProductResponse.getResourceId();
-
+ return createLoanProduct(product);
}
- private void verifyTransactionIsAccountTransfer(final LocalDate
transactionDate, final Float transactionAmount, final Integer loanID,
+ private void verifyTransactionIsAccountTransfer(final LocalDate
transactionDate, final double transactionAmount, final Long loanId,
final String transactionOfType) {
- ArrayList<HashMap> transactions = (ArrayList<HashMap>)
loanTransactionHelper.getLoanTransactions(requestSpec, responseSpec, loanID);
+ GetLoansLoanIdResponse loanDetails = getLoanDetails(loanId);
boolean isTransactionFound = false;
- for (int i = 0; i < transactions.size(); i++) {
- HashMap transactionType = (HashMap)
transactions.get(i).get("type");
- boolean isTransaction = (Boolean)
transactionType.get(transactionOfType);
-
- if (isTransaction) {
- ArrayList<Integer> transactionDateAsArray =
(ArrayList<Integer>) transactions.get(i).get("date");
- LocalDate transactionEntryDate =
LocalDate.of(transactionDateAsArray.get(0), transactionDateAsArray.get(1),
- transactionDateAsArray.get(2));
-
- if (transactionDate.isEqual(transactionEntryDate)) {
- isTransactionFound = true;
- assertEquals(transactionAmount,
Float.valueOf(String.valueOf(transactions.get(i).get("amount"))),
- "Mismatch in transaction amounts");
-
- // verify transfer details
- assertNotNull(transactions.get(i).get("transfer"));
-
- final HashMap<String, Object> actualTransferMap =
(HashMap) transactions.get(i).get("transfer");
-
- assertEquals(transactionAmount,
Float.valueOf(String.valueOf(actualTransferMap.get("transferAmount"))));
-
- ArrayList<Integer> transferDate = (ArrayList<Integer>)
actualTransferMap.get("transferDate");
-
- LocalDate dateOfTransfer =
LocalDate.of(transferDate.get(0), transferDate.get(1), transferDate.get(2));
- assertTrue(transactionDate.isEqual(dateOfTransfer));
-
- break;
- }
+ for (var transaction : loanDetails.getTransactions()) {
+ GetLoansLoanIdLoanTransactionEnumData type = transaction.getType();
+ boolean isTransaction = switch (transactionOfType) {
+ case "disbursement" ->
Boolean.TRUE.equals(type.getDisbursement());
+ case "downPayment" ->
"loanTransactionType.downPayment".equals(type.getCode());
+ default -> false;
+ };
+ if (isTransaction &&
transactionDate.equals(transaction.getDate())) {
+ isTransactionFound = true;
+ assertEquals(transactionAmount,
Utils.getDoubleValue(transaction.getAmount()), "Mismatch in transaction
amounts");
Review Comment:
Agreed, real regression. Restored the full check via raw JSON , it now
asserts the transfer object and its transferAmount/transferDate.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]