forked from apache/fineract
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FINERACT-1981: Progressive loan enable backdated transactions
- Loading branch information
1 parent
fe16b61
commit 0590329
Showing
4 changed files
with
177 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
163 changes: 163 additions & 0 deletions
163
...st/java/org/apache/fineract/integrationtests/LoanTransactionBackdatedProgressiveTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.fineract.integrationtests; | ||
|
||
import com.google.gson.Gson; | ||
import java.math.BigDecimal; | ||
import java.util.HashMap; | ||
import java.util.Optional; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.fineract.client.models.GetLoansLoanIdResponse; | ||
import org.apache.fineract.client.models.GetLoansLoanIdTransactions; | ||
import org.apache.fineract.client.models.PostLoanProductsResponse; | ||
import org.apache.fineract.client.models.PostLoansLoanIdChargesChargeIdRequest; | ||
import org.apache.fineract.client.models.PostLoansLoanIdChargesChargeIdResponse; | ||
import org.apache.fineract.client.models.PostLoansLoanIdChargesRequest; | ||
import org.apache.fineract.client.models.PostLoansLoanIdChargesResponse; | ||
import org.apache.fineract.client.models.PostLoansLoanIdTransactionsRequest; | ||
import org.apache.fineract.client.models.PostLoansResponse; | ||
import org.apache.fineract.integrationtests.common.ClientHelper; | ||
import org.apache.fineract.integrationtests.common.charges.ChargesHelper; | ||
import org.apache.fineract.integrationtests.common.loans.LoanTestLifecycleExtension; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
@Slf4j | ||
@ExtendWith({ LoanTestLifecycleExtension.class }) | ||
public class LoanTransactionBackdatedProgressiveTest extends BaseLoanIntegrationTest { | ||
|
||
private Long clientId; | ||
private Long loanId; | ||
|
||
@BeforeEach | ||
public void beforeEach() { | ||
runAt("01 July 2024", () -> { | ||
clientId = clientHelper.createClient(ClientHelper.defaultClientCreationRequest()).getClientId(); | ||
final PostLoanProductsResponse loanProductsResponse = loanProductHelper.createLoanProduct(create4IProgressive()); | ||
PostLoansResponse postLoansResponse = loanTransactionHelper.applyLoan( | ||
applyPin4ProgressiveLoanRequest(clientId, loanProductsResponse.getResourceId(), "01 June 2024", 1000.0, 10.0, 4, null)); | ||
loanId = postLoansResponse.getLoanId(); | ||
loanTransactionHelper.approveLoan(loanId, approveLoanRequest(1000.0, "01 June 2024")); | ||
disburseLoan(loanId, BigDecimal.valueOf(250.0), "01 June 2024"); | ||
addRepaymentForLoan(loanId, 100.0, "10 June 2024"); | ||
}); | ||
} | ||
|
||
@Test | ||
public void testProgressiveBackdatedDisbursement() { | ||
runAt("01 July 2024", () -> { | ||
disburseLoan(loanId, BigDecimal.valueOf(250.0), "5 June 2024"); | ||
|
||
GetLoansLoanIdResponse loanDetails = loanTransactionHelper.getLoanDetails(loanId); | ||
Assertions.assertEquals(loanDetails.getDisbursementDetails().size(), 2); | ||
}); | ||
} | ||
|
||
@Test | ||
public void testProgressiveBackdatedRepayment() { | ||
runAt("01 July 2024", () -> { | ||
addRepaymentForLoan(loanId, 100.0, "5 June 2024"); | ||
|
||
GetLoansLoanIdResponse loanDetails = loanTransactionHelper.getLoanDetails(loanId); | ||
Assertions.assertTrue(loanDetails.getTransactions().size() >= 2); | ||
}); | ||
} | ||
|
||
@Test | ||
public void testProgressiveBackdatedMerchantIssuedRefund() { | ||
runAt("01 July 2024", () -> { | ||
loanTransactionHelper.makeMerchantIssuedRefund(loanId, new PostLoansLoanIdTransactionsRequest().dateFormat(DATETIME_PATTERN) | ||
.transactionDate("5 June 2024").locale("en").transactionAmount(100.0)); | ||
|
||
GetLoansLoanIdResponse loanDetails = loanTransactionHelper.getLoanDetails(loanId); | ||
Assertions.assertTrue(loanDetails.getTransactions().size() >= 2); | ||
}); | ||
} | ||
|
||
@Test | ||
public void testProgressiveBackdatedPayoutRefund() { | ||
runAt("01 July 2024", () -> { | ||
loanTransactionHelper.makePayoutRefund(loanId, new PostLoansLoanIdTransactionsRequest().dateFormat(DATETIME_PATTERN) | ||
.transactionDate("5 June 2024").locale("en").transactionAmount(100.0)); | ||
|
||
GetLoansLoanIdResponse loanDetails = loanTransactionHelper.getLoanDetails(loanId); | ||
Assertions.assertTrue(loanDetails.getTransactions().size() >= 2); | ||
}); | ||
} | ||
|
||
@Test | ||
public void testProgressiveBackdatedGoodwillCredit() { | ||
runAt("01 July 2024", () -> { | ||
loanTransactionHelper.makeGoodwillCredit(loanId, new PostLoansLoanIdTransactionsRequest().dateFormat(DATETIME_PATTERN) | ||
.transactionDate("5 June 2024").locale("en").transactionAmount(100.0)); | ||
|
||
GetLoansLoanIdResponse loanDetails = loanTransactionHelper.getLoanDetails(loanId); | ||
Assertions.assertTrue(loanDetails.getTransactions().size() >= 2); | ||
}); | ||
} | ||
|
||
@Test | ||
public void testProgressiveBackdatedCharge() { | ||
runAt("01 July 2024", () -> { | ||
Integer feeCharge = ChargesHelper.createCharges(requestSpec, responseSpec, | ||
createEurCharge(ChargesHelper.CHARGE_CALCULATION_TYPE_FLAT, "10", false)); | ||
|
||
loanTransactionHelper.addLoanCharge(loanId, new PostLoansLoanIdChargesRequest().dateFormat(DATETIME_PATTERN) | ||
.dueDate("5 June 2024").locale("en").chargeId((long) feeCharge).amount(10.0)); | ||
|
||
GetLoansLoanIdResponse loanDetails = loanTransactionHelper.getLoanDetails(loanId); | ||
Assertions.assertFalse(loanDetails.getCharges().isEmpty()); | ||
}); | ||
} | ||
|
||
@Test | ||
public void testProgressiveBackdatedChargeAdjustment() { | ||
runAt("01 July 2024", () -> { | ||
Integer feeCharge = ChargesHelper.createCharges(requestSpec, responseSpec, | ||
createEurCharge(ChargesHelper.CHARGE_CALCULATION_TYPE_FLAT, "10", false)); | ||
|
||
final PostLoansLoanIdChargesResponse addLoanChargeResponse = loanTransactionHelper.addLoanCharge(loanId, | ||
new PostLoansLoanIdChargesRequest().dateFormat(DATETIME_PATTERN).dueDate("5 June 2024").locale("en") | ||
.chargeId((long) feeCharge).amount(10.0)); | ||
|
||
final PostLoansLoanIdChargesChargeIdResponse chargeAdjustmentResponse = loanTransactionHelper.chargeAdjustment(loanId, | ||
addLoanChargeResponse.getResourceId(), new PostLoansLoanIdChargesChargeIdRequest().locale("en").amount(1.0)); | ||
chargeAdjustmentResponse.getLoanId(); | ||
|
||
GetLoansLoanIdResponse loanDetails = loanTransactionHelper.getLoanDetails(loanId); | ||
Assertions.assertFalse(loanDetails.getCharges().isEmpty()); | ||
final Optional<GetLoansLoanIdTransactions> optionalChargeAdjustmentTransaction = loanDetails.getTransactions().stream() | ||
.filter(transaction -> transaction.getType().getCode().equals("loanTransactionType.chargeAdjustment")).findFirst(); | ||
Assertions.assertTrue(optionalChargeAdjustmentTransaction.isPresent()); | ||
}); | ||
} | ||
|
||
private String createEurCharge(final Integer chargeCalculationType, final String amount, final boolean penalty) { | ||
final HashMap<String, Object> map = ChargesHelper.populateDefaultsForLoan(); | ||
map.put("currencyCode", "EUR"); | ||
map.put("chargeTimeType", 2); | ||
map.put("chargePaymentMode", 0); | ||
map.put("penalty", penalty); | ||
map.put("amount", amount); | ||
map.put("chargeCalculationType", chargeCalculationType); | ||
return new Gson().toJson(map); | ||
} | ||
} |