DeathGun44 commented on code in PR #6084:
URL: https://github.com/apache/fineract/pull/6084#discussion_r3525735430


##########
integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanRescheduleWithAdvancePaymentTest.java:
##########
@@ -294,73 +233,63 @@ private void 
createLoanProductWithInterestRecalculationForTestMultipleAdvancePay
         LOG.info(
                 "---------------------------------CREATING LOAN PRODUCT WITH 
RECALULATION ENABLED ------------------------------------------");
 
-        final String interestRecalculationCompoundingMethod = 
LoanProductTestBuilder.RECALCULATION_COMPOUNDING_METHOD_NONE;
-        final String rescheduleStrategyMethod = 
LoanProductTestBuilder.RECALCULATION_STRATEGY_REDUCE_NUMBER_OF_INSTALLMENTS;
-        final String recalculationRestFrequencyType = 
LoanProductTestBuilder.RECALCULATION_FREQUENCY_TYPE_DAILY;
-        final String recalculationRestFrequencyInterval = "0";
-        final String preCloseInterestCalculationStrategy = 
LoanProductTestBuilder.INTEREST_APPLICABLE_STRATEGY_ON_PRE_CLOSE_DATE;
-        final String recalculationCompoundingFrequencyType = null;
-        final String recalculationCompoundingFrequencyInterval = null;
-        final Integer recalculationCompoundingFrequencyOnDayType = null;
-        final Integer recalculationCompoundingFrequencyDayOfWeekType = null;
-        final Integer recalculationRestFrequencyOnDayType = null;
-        final Integer recalculationRestFrequencyDayOfWeekType = null;
-
-        final String loanProductJSON = new 
LoanProductTestBuilder().withPrincipal(loanPrincipalAmount)
-                
.withNumberOfRepayments(numberOfRepayments).withinterestRatePerPeriod(interestRatePerPeriod)
-                
.withInterestRateFrequencyTypeAsYear().withInterestTypeAsDecliningBalance().withInterestCalculationPeriodTypeAsDays()
-                
.withInterestRecalculationDetails(interestRecalculationCompoundingMethod, 
rescheduleStrategyMethod,
-                        preCloseInterestCalculationStrategy)
-                
.withInterestRecalculationRestFrequencyDetails(recalculationRestFrequencyType, 
recalculationRestFrequencyInterval,
-                        recalculationRestFrequencyOnDayType, 
recalculationRestFrequencyDayOfWeekType)
-                
.withInterestRecalculationCompoundingFrequencyDetails(recalculationCompoundingFrequencyType,
-                        recalculationCompoundingFrequencyInterval, 
recalculationCompoundingFrequencyOnDayType,
-                        recalculationCompoundingFrequencyDayOfWeekType)
-                .withInstallmentAmountInMultiplesOf("10").build(null);
-
-        this.loanProductId = 
this.loanTransactionHelper.getLoanProductId(loanProductJSON);
+        PostLoanProductsRequest product = 
twelveMonthInterestRecalculationProduct()//
+                .principal(loanPrincipalAmount)//
+                .interestRatePerPeriod(interestRatePerPeriod)//
+                .installmentAmountInMultiplesOf(10);
+
+        this.loanProductId = createLoanProduct(product);
         LOG.info("Successfully created loan product  (ID:{}) ", 
this.loanProductId);
     }
 
     private void createLoanEntityForTestMultipleAdvancePaymentWithReschedule() 
{
-        String firstRepaymentDate = "03 January 2022";
-        String submittedDate = "29 November 2021";
+        String submittedDate = "2021-11-29";
 
         LOG.info("---------------------------------NEW LOAN 
APPLICATION------------------------------------------");
 
-        final String loanApplicationJSON = new 
LoanApplicationTestBuilder().withPrincipal("15000").withLoanTermFrequency("12")
-                
.withLoanTermFrequencyAsMonths().withNumberOfRepayments("12").withRepaymentEveryAfter("1")
-                
.withRepaymentFrequencyTypeAsMonths().withAmortizationTypeAsEqualInstallments().withInterestCalculationPeriodTypeAsDays()
-                
.withInterestRatePerPeriod("12").withInterestTypeAsDecliningBalance().withSubmittedOnDate(submittedDate)
-                
.withExpectedDisbursementDate(submittedDate).withFirstRepaymentDate(firstRepaymentDate)
-                
.withRepaymentStrategy(LoanApplicationTestBuilder.INTEREST_PRINCIPAL_PENALTIES_FEES_ORDER_STRATEGY)
-                
.withinterestChargedFromDate(submittedDate).build(this.clientId.toString(), 
this.loanProductId.toString(), null);
-
-        this.loanId = 
this.loanTransactionHelper.getLoanId(loanApplicationJSON);
+        PostLoansRequest applyRequest = applyLoanRequest(this.clientId, 
this.loanProductId, submittedDate, 15000.0, 12, req -> {
+            req.loanTermFrequency(12);
+            
req.loanTermFrequencyType(LoanTestData.RepaymentFrequencyType.MONTHS);
+            req.repaymentEvery(1);
+            
req.repaymentFrequencyType(LoanTestData.RepaymentFrequencyType.MONTHS);
+            req.interestRatePerPeriod(BigDecimal.valueOf(12));
+            
req.interestCalculationPeriodType(LoanTestData.InterestCalculationPeriodType.DAILY);
+            req.interestType(LoanTestData.InterestType.DECLINING_BALANCE);
+            
req.amortizationType(LoanTestData.AmortizationType.EQUAL_INSTALLMENTS);
+            
req.transactionProcessingStrategyCode(LoanProductTestBuilder.INTEREST_PRINCIPAL_PENALTIES_FEES_ORDER_STRATEGY);
+            req.dateFormat(LoanTestData.ISO_DATE_PATTERN);
+            req.submittedOnDate(submittedDate);
+            req.expectedDisbursementDate(submittedDate);
+            req.repaymentsStartingFromDate(LocalDate.of(2022, Month.JANUARY, 
3));
+        });
+
+        this.loanId = applyForLoan(applyRequest);
 
         LOG.info("Sucessfully created loan (ID: {} )", this.loanId);
 
-        this.approveLoanApplication(submittedDate);
-        this.disburseLoan(submittedDate);
+        approveLoan(this.loanId,
+                new 
org.apache.fineract.client.models.PostLoansLoanIdRequest().approvedLoanAmount(BigDecimal.valueOf(15000))
+                        
.approvedOnDate(submittedDate).dateFormat(LoanTestData.ISO_DATE_PATTERN).locale(LoanTestData.LOCALE));
+        disburseLoan(this.loanId,
+                new 
org.apache.fineract.client.models.PostLoansLoanIdRequest().actualDisbursementDate(submittedDate)
+                        
.transactionAmount(getLoanDetails(this.loanId).getNetDisbursalAmount()).dateFormat(LoanTestData.ISO_DATE_PATTERN)
+                        .locale(LoanTestData.LOCALE));
+        LOG.info("Successfully disbursed loan (ID: {} )", this.loanId);
     }
 
     private void doMultipleAdvancePaymentsAndVerifySchedule() {
 
         LOG.info("-------------Make Advance repayment 1-----------");
-        this.loanTransactionHelper.makeRepayment("02 December 2021", 
Float.parseFloat("1"), this.loanId);
+        addRepaymentForLoan(this.loanId, 1.0, "02 December 2021");
 
         LOG.info("-------------Make Advance repayment 2-----------");
-        this.loanTransactionHelper.makeRepayment("03 December 2021", 
Float.parseFloat("1"), this.loanId);
-
-        final Map repaymentSchedule = (Map) 
this.loanTransactionHelper.getLoanDetailExcludeFutureSchedule(requestSpec, 
generalResponseSpec,
-                this.loanId, "repaymentSchedule");
+        addRepaymentForLoan(this.loanId, 1.0, "03 December 2021");
 
-        final ArrayList periods = (ArrayList) repaymentSchedule.get("periods");
-        HashMap period = (HashMap) periods.get(3);
+        GetLoansLoanIdRepaymentPeriod period = 
getLoanDetails(this.loanId).getRepaymentSchedule().getPeriods().get(3);
         LOG.info("period  {}", period);
 
-        assertEquals(new ArrayList<>(Arrays.asList(2022, 1, 3)), 
period.get("dueDate"), "Checking for Due Date for 1st Month");
-        assertEquals(period.get("principalDue"), Float.parseFloat("1177.12"));
-        assertEquals(period.get("interestDue"), Float.parseFloat("152.88"));
+        assertEquals(LocalDate.of(2022, Month.JANUARY, 3), 
period.getDueDate(), "Checking for Due Date for 1st Month");
+        assertEquals(0, 
BigDecimal.valueOf(1177.13).compareTo(period.getPrincipalDue()));

Review Comment:
   I checked against a live server the API genuinely returns 1177.13 / 152.87 
here (reverting to 1177.12 fails the test), so the values seem correct. Both 
still sum to the 1330.00 EMI.



-- 
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]

Reply via email to