Skip to content

Commit 6f8e2c3

Browse files
committed
FINERACT-2649: Migrate core LoanAccount tests to Feign
Signed-off-by: DeathGun44 <krishnamewara841@gmail.com>
1 parent 7e0b965 commit 6f8e2c3

29 files changed

Lines changed: 616 additions & 610 deletions

fineract-provider/src/test/java/org/apache/fineract/batch/command/CommandStrategyUtilsTest.java

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ public void testBuildRequestFromQueryParametersTypeConversion(String fieldName,
127127
// then
128128
assertThat(result).isNotNull();
129129
Object actualValue = getFieldValue(result, fieldName);
130-
if (expectedValue instanceof BigDecimal) {
131-
assertThat((BigDecimal) actualValue).isEqualByComparingTo((BigDecimal) expectedValue);
130+
if (expectedValue instanceof BigDecimal expectedValueAsBigDecimal) {
131+
assertThat((BigDecimal) actualValue).isEqualByComparingTo(expectedValueAsBigDecimal);
132132
} else {
133133
assertThat(actualValue).isEqualTo(expectedValue);
134134
}
@@ -240,22 +240,15 @@ public void testBuildRequestFromQueryParametersWithClassWithoutBuilder() {
240240
}
241241

242242
private Object getFieldValue(TestRequest request, String fieldName) {
243-
switch (fieldName) {
244-
case "stringField":
245-
return request.getStringField();
246-
case "integerField":
247-
return request.getIntegerField();
248-
case "longField":
249-
return request.getLongField();
250-
case "bigDecimalField":
251-
return request.getBigDecimalField();
252-
case "doubleField":
253-
return request.getDoubleField();
254-
case "booleanField":
255-
return request.getBooleanField();
256-
default:
257-
return null;
258-
}
243+
return switch (fieldName) {
244+
case "stringField" -> request.getStringField();
245+
case "integerField" -> request.getIntegerField();
246+
case "longField" -> request.getLongField();
247+
case "bigDecimalField" -> request.getBigDecimalField();
248+
case "doubleField" -> request.getDoubleField();
249+
case "booleanField" -> request.getBooleanField();
250+
default -> null;
251+
};
259252
}
260253

261254
@Data

fineract-provider/src/test/java/org/apache/fineract/portfolio/loanaccount/domain/LoanTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import java.math.BigDecimal;
2828
import java.time.LocalDate;
29+
import java.time.Month;
2930
import java.time.OffsetDateTime;
3031
import java.time.ZoneId;
3132
import java.util.Arrays;
@@ -191,7 +192,8 @@ public void testGetLastUserTransaction() {
191192
when(loanTransaction4.isNotReversed()).thenReturn(Boolean.TRUE);
192193
when(loanTransaction4.isAccrual()).thenReturn(Boolean.FALSE);
193194
when(loanTransaction4.isAccrualAdjustment()).thenReturn(Boolean.TRUE);
194-
ReflectionTestUtils.setField(loan, "loanTransactions", List.of(loanTransaction, loanTransaction2, loanTransaction3));
195+
ReflectionTestUtils.setField(loan, "loanTransactions",
196+
List.of(loanTransaction, loanTransaction2, loanTransaction3, loanTransaction4));
195197
final LoanTransaction userTransaction = loan.getLastUserTransaction();
196198
assertNotNull(userTransaction);
197199
assertEquals(loanTransaction2, userTransaction);
@@ -203,7 +205,7 @@ public void testGetLastUserTransaction() {
203205
@Test
204206
public void testTransactionComparator() {
205207
final Loan loan = new Loan();
206-
LocalDate today = LocalDate.of(2023, 10, 12);
208+
LocalDate today = LocalDate.of(2023, Month.OCTOBER, 12);
207209
OffsetDateTime now = DateUtils.getAuditOffsetDateTime();
208210

209211
LoanTransaction lt1 = new LoanTransaction();
@@ -273,7 +275,7 @@ private LoanCharge buildLoanCharge() {
273275
loanCharge.setAmountOutstanding(new BigDecimal(100));
274276
loanCharge.setChargeTime(ChargeTimeType.TRANCHE_DISBURSEMENT.getValue());
275277
loanCharge.setChargeCalculation(ChargeCalculationType.FLAT.getValue());
276-
loanCharge.setDueDate(LocalDate.of(2022, 6, 27));
278+
loanCharge.setDueDate(LocalDate.of(2022, Month.JUNE, 27));
277279
loanCharge.setChargePaymentMode(ChargePaymentMode.REGULAR.getValue());
278280
loanCharge.setPercentage(null);
279281
loanCharge.setAmountPercentageAppliedTo(null);

integration-tests/src/test/java/org/apache/fineract/integrationtests/ClientLoanChargeExternalIntegrationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public void checkNewClientLoanChargeSavesExternalId() {
5252
approveLoan(loanId, approveLoanRequest(12000.0, "20 September 2011"));
5353
disburseLoanWithNetDisbursalAmount(loanId, "20 September 2011", "12,000.00");
5454

55-
final Long chargeDefId = chargesHelper.createLoanSpecifiedDueDatePercentageAmountAndInterestFee(1.0);
55+
final Long chargeDefId = chargesHelper.createLoanSpecifiedDueDatePercentageAmountAndInterestFee(1.0).getResourceId();
5656

5757
final String externalId = "extId" + loanId.toString();
5858
PostLoansLoanIdChargesResponse chargeResponse = addLoanCharge(loanId, new PostLoansLoanIdChargesRequest().chargeId(chargeDefId)
@@ -74,7 +74,7 @@ public void checkNewClientLoanChargeFindsDuplicateExternalId() {
7474
approveLoan(loanId, approveLoanRequest(12000.0, "20 September 2011"));
7575
disburseLoanWithNetDisbursalAmount(loanId, "20 September 2011", "12,000.00");
7676

77-
final Long chargeDefId = chargesHelper.createLoanSpecifiedDueDatePercentageAmountAndInterestFee(1.0);
77+
final Long chargeDefId = chargesHelper.createLoanSpecifiedDueDatePercentageAmountAndInterestFee(1.0).getResourceId();
7878

7979
final String externalId = "extId" + loanId.toString();
8080
PostLoansLoanIdChargesResponse chargeResponse = addLoanCharge(loanId, new PostLoansLoanIdChargesRequest().chargeId(chargeDefId)

integration-tests/src/test/java/org/apache/fineract/integrationtests/ClientLoanMultipleDisbursementsIntegrationTest.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ private Long createLoanProduct(final boolean multiDisburseLoan) {
7878
return createLoanProductFromJson(loanProductJSON);
7979
}
8080

81-
private Long applyForLoanApplicationWithTranches(final Long clientID, final Long loanProductID, String principal,
81+
private Long applyForLoanApplicationWithTranches(final Long clientId, final Long loanProductID, String principal,
8282
List<HashMap> tranches, String submitDate) {
8383
LOG.info("--------------------------------APPLYING FOR LOAN APPLICATION--------------------------------");
8484
final String loanApplicationJSON = new LoanApplicationTestBuilder() //
@@ -95,7 +95,7 @@ private Long applyForLoanApplicationWithTranches(final Long clientID, final Long
9595
.withExpectedDisbursementDate(submitDate) //
9696
.withTranches(tranches) //
9797
.withSubmittedOnDate(submitDate) //
98-
.build(clientID.toString(), loanProductID.toString(), null);
98+
.build(clientId.toString(), loanProductID.toString(), null);
9999
return applyForLoanFromJson(loanApplicationJSON);
100100
}
101101

@@ -204,7 +204,8 @@ public void checkThatAllMultiDisbursalsAppearOnLoanScheduleAndOutStandingBalance
204204
assertTrue(expectedPrincipalDue.compareTo(principalDue) == 0, "Checking Principal Due is 255");
205205

206206
final BigDecimal principalLoanBalanceOutstanding = lastPeriod.getPrincipalLoanBalanceOutstanding();
207-
assertTrue(expectedPrincipalLoanBalanceOutstanding.compareTo(principalLoanBalanceOutstanding) == 0, "Checking Principal Loan Balance Outstanding is zero");
207+
assertTrue(expectedPrincipalLoanBalanceOutstanding.compareTo(principalLoanBalanceOutstanding) == 0,
208+
"Checking Principal Loan Balance Outstanding is zero");
208209
}
209210

210211
@Test
@@ -276,7 +277,8 @@ public void checkThatAllMultiDisbursalsAppearOnLoanScheduleAndOutStandingBalance
276277
assertTrue(expectedPrincipalOutstanding.compareTo(principalOutstanding) == 0, "Checking Principal Due is 2");
277278

278279
final BigDecimal principalLoanBalanceOutstanding = lastPeriod.getPrincipalLoanBalanceOutstanding();
279-
assertTrue(expectedPrincipalLoanBalanceOutstanding.compareTo(principalLoanBalanceOutstanding) == 0, "Checking Principal Loan Balance Outstanding is zero");
280+
assertTrue(expectedPrincipalLoanBalanceOutstanding.compareTo(principalLoanBalanceOutstanding) == 0,
281+
"Checking Principal Loan Balance Outstanding is zero");
280282
}
281283

282284
@Test
@@ -348,6 +350,7 @@ public void checkThatAllMultiDisbursalsAppearOnLoanScheduleAndOutStandingBalance
348350
assertTrue(expectedPrincipalOutstanding.compareTo(principalOutstanding) == 0, "Checking Principal Due is 2");
349351

350352
final BigDecimal principalLoanBalanceOutstanding = lastPeriod.getPrincipalLoanBalanceOutstanding();
351-
assertTrue(expectedPrincipalLoanBalanceOutstanding.compareTo(principalLoanBalanceOutstanding) == 0, "Checking Principal Loan Balance Outstanding is zero");
353+
assertTrue(expectedPrincipalLoanBalanceOutstanding.compareTo(principalLoanBalanceOutstanding) == 0,
354+
"Checking Principal Loan Balance Outstanding is zero");
352355
}
353356
}

integration-tests/src/test/java/org/apache/fineract/integrationtests/ClientLoanNonTrancheMultipleDisbursementsIntegrationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ private Long createLoanProduct(final boolean isInterestRecalculationEnabled) {
8989
return createLoanProductFromJson(loanProductJSON);
9090
}
9191

92-
private Long applyForLoanApplication(final Long clientID, final Long loanProductID, String principal, String submitDate,
92+
private Long applyForLoanApplication(final Long clientId, final Long loanProductID, String principal, String submitDate,
9393
String repaymentsNo) {
9494
LOG.info("--------------------------------APPLYING FOR LOAN APPLICATION--------------------------------");
9595
final String loanApplicationJSON = new LoanApplicationTestBuilder() //
@@ -106,7 +106,7 @@ private Long applyForLoanApplication(final Long clientID, final Long loanProduct
106106
.withExpectedDisbursementDate(submitDate) //
107107
.withTranches(null) //
108108
.withSubmittedOnDate(submitDate) //
109-
.build(clientID.toString(), loanProductID.toString(), null);
109+
.build(clientId.toString(), loanProductID.toString(), null);
110110
return applyForLoanFromJson(loanApplicationJSON);
111111
}
112112

integration-tests/src/test/java/org/apache/fineract/integrationtests/FloatingRateInterestRecalculationTest.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@
1818
*/
1919
package org.apache.fineract.integrationtests;
2020

21-
import static org.apache.fineract.client.feign.util.FeignCalls.ok;
2221
import static org.junit.jupiter.api.Assertions.assertNotNull;
2322
import static org.junit.jupiter.api.Assertions.assertTrue;
2423

24+
import com.google.gson.JsonObject;
25+
import com.google.gson.JsonParser;
2526
import java.math.BigDecimal;
2627
import java.util.HashMap;
2728
import java.util.List;
@@ -31,6 +32,7 @@
3132
import org.apache.fineract.client.models.GetLoansLoanIdResponse;
3233
import org.apache.fineract.client.models.PostFloatingRatesResponse;
3334
import org.apache.fineract.integrationtests.client.feign.FeignLoanTestBase;
35+
import org.apache.fineract.integrationtests.client.feign.helpers.FeignRawHttpHelper;
3436
import org.apache.fineract.integrationtests.common.Utils;
3537
import org.apache.fineract.integrationtests.common.accounting.Account;
3638
import org.apache.fineract.integrationtests.common.loans.LoanApplicationTestBuilder;
@@ -154,7 +156,8 @@ private Integer createCumulativeFloatingRateLoanProduct(Long floatingRateId, Acc
154156
loanProductMap.put("defaultDifferentialLendingRate", "0");
155157
loanProductMap.put("maxDifferentialLendingRate", "50");
156158

157-
return getLoanProductId(Utils.convertToJson(loanProductMap));
159+
String responseJson = FeignRawHttpHelper.post("/loanproducts", Utils.convertToJson(loanProductMap));
160+
return JsonParser.parseString(responseJson).getAsJsonObject().get("resourceId").getAsInt();
158161
}
159162

160163
private Long createAndDisburseLoan(Long clientId, Integer loanProductId, String disburseDateStr) {
@@ -165,7 +168,7 @@ private Long createAndDisburseLoan(Long clientId, Integer loanProductId, String
165168
.withExpectedDisbursementDate(disburseDateStr).withSubmittedOnDate(disburseDateStr).withLoanType("individual")
166169
.build(clientId.toString(), loanProductId.toString(), null);
167170

168-
com.google.gson.JsonObject jsonObject = com.google.gson.JsonParser.parseString(loanApplicationJSON).getAsJsonObject();
171+
JsonObject jsonObject = JsonParser.parseString(loanApplicationJSON).getAsJsonObject();
169172
jsonObject.remove("interestRatePerPeriod");
170173
jsonObject.addProperty("interestRateDifferential", "0");
171174
jsonObject.addProperty("isFloatingInterestRate", true);

0 commit comments

Comments
 (0)