Skip to content

Commit 6bf0dee

Browse files
committed
FINERACT-2541: added e2e test for validation of owner to owner transfer functionality
1 parent babe420 commit 6bf0dee

6 files changed

Lines changed: 281 additions & 65 deletions

File tree

fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/data/AssetExternalizationErrorMessage.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public enum AssetExternalizationErrorMessage {
3131
LOAN_CLOSED_OBLIGATIONS_MET_INVALID("Loan status CLOSED_OBLIGATIONS_MET is not valid for transfer."), //
3232
LOAN_SUBMITTED_AND_PENDING_APPROVAL_INVALID("Loan status SUBMITTED_AND_PENDING_APPROVAL is not valid for transfer."), //
3333
LOAN_APPROVED_INVALID("Loan status APPROVED is not valid for transfer."), //
34+
ALREADY_IN_PROGRESS("This loan cannot be sold, there is already an in progress transfer"), //
3435
INVALID_REQUEST("The request was invalid. This typically will happen due to validation errors which are provided."); //
3536

3637
public final String value;

fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/assetexternalization/AssetExternalizationStepDef.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ private void createAssetExternalizationRequestByLoanId(DataTable table, String t
159159
} else if ((transferData.get(0).equals(TRANSACTION_TYPE_SALE) || transferData.get(0).equals(TRANSACTION_TYPE_INTERMEDIARY_SALE))) {
160160
String ownerExternalId;
161161
if (regenerateOwner) {
162+
// For owner-to-owner transfers: preserve the current owner as previous owner
163+
String currentOwner = testContext().get(TestContextKey.ASSET_EXTERNALIZATION_OWNER_EXTERNAL_ID);
164+
if (currentOwner != null && !transferData.get(0).equals(TRANSACTION_TYPE_INTERMEDIARY_SALE)) {
165+
testContext().set(TestContextKey.ASSET_EXTERNALIZATION_PREVIOUS_OWNER_EXTERNAL_ID, currentOwner);
166+
}
162167
ownerExternalId = Utils.randomStringGenerator(OWNER_EXTERNAL_ID_PREFIX, 10);
163168
} else {
164169
ownerExternalId = testContext().get(TestContextKey.ASSET_EXTERNALIZATION_OWNER_EXTERNAL_ID);
@@ -369,13 +374,20 @@ private void checkExternalAssetDetails(Long loanId, String loanExternalId, PageE
369374
previousAssetOwner = null;
370375
transferExternalId = testContext().get(TestContextKey.ASSET_EXTERNALIZATION_SALES_TRANSFER_EXTERNAL_ID_FROM_RESPONSE);
371376
}
372-
} else { // in case transfer has previous intermediarySale transfer
377+
} else { // in case transfer has previous intermediarySale or owner-to-owner transfer
373378
if (transactionType.equalsIgnoreCase(TRANSACTION_TYPE_SALE)
374379
&& (status.equals(ExternalTransferData.StatusEnum.ACTIVE.getValue())
375380
|| status.equals(ExternalTransferData.StatusEnum.PENDING.getValue()))) {
376381
ownerExternalId = ownerExternalIdStored;
377382
previousAssetOwner = intermediarySaleAssetOwner;
378383
transferExternalId = testContext().get(TestContextKey.ASSET_EXTERNALIZATION_SALES_TRANSFER_EXTERNAL_ID_FROM_RESPONSE);
384+
} else if (transactionType.equalsIgnoreCase(TRANSACTION_TYPE_SALE)
385+
&& (status.equals(ExternalTransferData.StatusEnum.DECLINED.getValue())
386+
|| status.equals(ExternalTransferData.StatusEnum.CANCELLED.getValue()))) {
387+
// DECLINED and CANCELLED records have previousOwner = null in the API response
388+
ownerExternalId = ownerExternalIdStored;
389+
previousAssetOwner = null;
390+
transferExternalId = testContext().get(TestContextKey.ASSET_EXTERNALIZATION_SALES_TRANSFER_EXTERNAL_ID_FROM_RESPONSE);
379391
} else if (transactionType.equalsIgnoreCase(TRANSACTION_TYPE_BUYBACK)
380392
&& (status.equals(ExternalTransferData.StatusEnum.BUYBACK.getValue())
381393
|| status.equals(ExternalTransferData.StatusEnum.BUYBACK_INTERMEDIATE.getValue()))) {

fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/loan/LoanRepaymentStepDef.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,13 @@ public void makeLoanRepaymentAndCheckOwner(String repaymentType, String transact
104104
makeRepayment(repaymentType, transactionDate, transactionAmount, transferExternalOwnerId);
105105
}
106106

107+
@And("Customer makes {string} repayment on {string} with {double} EUR transaction amount and check previous external owner")
108+
public void makeLoanRepaymentAndCheckPreviousOwner(String repaymentType, String transactionDate, double transactionAmount)
109+
throws IOException {
110+
String previousOwnerId = testContext().get(TestContextKey.ASSET_EXTERNALIZATION_PREVIOUS_OWNER_EXTERNAL_ID);
111+
makeRepayment(repaymentType, transactionDate, transactionAmount, previousOwnerId);
112+
}
113+
107114
private void makeRepayment(String repaymentType, String transactionDate, double transactionAmount, String transferExternalOwnerId)
108115
throws IOException {
109116
eventStore.reset();

fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/loan/LoanStepDef.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,14 @@ public void createTransactionWithAutoIdempotencyKeyWithExternalOwner(String tran
389389
transactionAmount, transferExternalOwnerId);
390390
}
391391

392+
@When("Customer makes {string} transaction with {string} payment type on {string} with {double} EUR transaction amount and system-generated Idempotency key and check previous external owner")
393+
public void createTransactionWithAutoIdempotencyKeyWithPreviousExternalOwner(String transactionTypeInput, String transactionPaymentType,
394+
String transactionDate, double transactionAmount) throws IOException {
395+
String previousOwnerId = testContext().get(TestContextKey.ASSET_EXTERNALIZATION_PREVIOUS_OWNER_EXTERNAL_ID);
396+
createTransactionWithAutoIdempotencyKeyAndWithExternalOwner(transactionTypeInput, transactionPaymentType, transactionDate,
397+
transactionAmount, previousOwnerId);
398+
}
399+
392400
@When("Customer makes {string} transaction with {string} payment type on {string} with {double} EUR transaction amount and system-generated Idempotency key and interestRefundCalculation {booleanValue}")
393401
public void createTransactionWithAutoIdempotencyKeyAndWithInterestRefundCalculationFlagProvided(final String transactionTypeInput,
394402
final String transactionPaymentType, final String transactionDate, final double transactionAmount,

fineract-e2e-tests-runner/src/test/resources/features/AssetExternalization-Part1.feature

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1811,67 +1811,3 @@ Feature: Asset Externalization - Part1
18111811

18121812
When Loan Pay-off is made on "26 June 2025"
18131813
Then Loan's all installments have obligations met
1814-
1815-
Scenario: Verify that when a loan with PENDING owner-to-owner SALES is fully paid asset transfer is DECLINED and original owner remains active
1816-
When Admin sets the business date to "1 May 2023"
1817-
When Admin creates a client with random data
1818-
When Admin creates a new default Loan with date: "1 May 2023"
1819-
And Admin successfully approves the loan on "1 May 2023" with "1000" amount and expected disbursement date on "1 May 2023"
1820-
When Admin successfully disburse the loan on "1 May 2023" with "1000" EUR transaction amount
1821-
Then Loan status will be "ACTIVE"
1822-
When Admin makes asset externalization request by Loan ID with unique ownerExternalId, system-generated transferExternalId and the following data:
1823-
| Transaction type | settlementDate | purchasePriceRatio |
1824-
| sale | 2023-05-21 | 1 |
1825-
Then Asset externalization response has the correct Loan ID, transferExternalId
1826-
When Admin sets the business date to "22 May 2023"
1827-
When Admin runs inline COB job for Loan
1828-
Then LoanOwnershipTransferBusinessEvent is created
1829-
Then LoanAccountSnapshotBusinessEvent is created
1830-
Then Fetching Asset externalization details by loan id gives numberOfElements: 2 with correct ownerExternalId and the following data:
1831-
| settlementDate | purchasePriceRatio | status | effectiveFrom | effectiveTo | Transaction type |
1832-
| 2023-05-21 | 1 | PENDING | 2023-05-01 | 2023-05-21 | SALE |
1833-
| 2023-05-21 | 1 | ACTIVE | 2023-05-22 | 9999-12-31 | SALE |
1834-
When Admin sets the business date to "25 May 2023"
1835-
When Admin makes asset externalization request by Loan ID with unique ownerExternalId, system-generated transferExternalId and the following data:
1836-
| Transaction type | settlementDate | purchasePriceRatio |
1837-
| sale | 2023-06-14 | 1 |
1838-
Then Asset externalization response has the correct Loan ID, transferExternalId
1839-
When Admin sets the business date to "28 May 2023"
1840-
And Customer makes "AUTOPAY" repayment on "28 May 2023" with 1000 EUR transaction amount
1841-
Then Loan status will be "CLOSED_OBLIGATIONS_MET"
1842-
Then Fetching Asset externalization details by loan id gives numberOfElements: 4 with correct ownerExternalId and the following data:
1843-
| settlementDate | purchasePriceRatio | status | effectiveFrom | effectiveTo | Transaction type |
1844-
| 2023-06-14 | 1 | DECLINED | 2023-05-28 | 2023-05-28 | SALE |
1845-
Then LoanOwnershipTransferBusinessEvent with transfer status: "DECLINED" and transfer status reason "BALANCE_ZERO" is created
1846-
1847-
Scenario: Verify that when a loan with PENDING owner-to-owner SALES is overpaid asset transfer is DECLINED and original owner remains active
1848-
When Admin sets the business date to "1 May 2023"
1849-
When Admin creates a client with random data
1850-
When Admin creates a new default Loan with date: "1 May 2023"
1851-
And Admin successfully approves the loan on "1 May 2023" with "1000" amount and expected disbursement date on "1 May 2023"
1852-
When Admin successfully disburse the loan on "1 May 2023" with "1000" EUR transaction amount
1853-
Then Loan status will be "ACTIVE"
1854-
When Admin makes asset externalization request by Loan ID with unique ownerExternalId, system-generated transferExternalId and the following data:
1855-
| Transaction type | settlementDate | purchasePriceRatio |
1856-
| sale | 2023-05-21 | 1 |
1857-
Then Asset externalization response has the correct Loan ID, transferExternalId
1858-
When Admin sets the business date to "22 May 2023"
1859-
When Admin runs inline COB job for Loan
1860-
Then LoanOwnershipTransferBusinessEvent is created
1861-
Then LoanAccountSnapshotBusinessEvent is created
1862-
Then Fetching Asset externalization details by loan id gives numberOfElements: 2 with correct ownerExternalId and the following data:
1863-
| settlementDate | purchasePriceRatio | status | effectiveFrom | effectiveTo | Transaction type |
1864-
| 2023-05-21 | 1 | PENDING | 2023-05-01 | 2023-05-21 | SALE |
1865-
| 2023-05-21 | 1 | ACTIVE | 2023-05-22 | 9999-12-31 | SALE |
1866-
When Admin sets the business date to "25 May 2023"
1867-
When Admin makes asset externalization request by Loan ID with unique ownerExternalId, system-generated transferExternalId and the following data:
1868-
| Transaction type | settlementDate | purchasePriceRatio |
1869-
| sale | 2023-06-14 | 1 |
1870-
Then Asset externalization response has the correct Loan ID, transferExternalId
1871-
When Admin sets the business date to "28 May 2023"
1872-
And Customer makes "AUTOPAY" repayment on "28 May 2023" with 1200 EUR transaction amount
1873-
Then Loan status will be "OVERPAID"
1874-
Then Fetching Asset externalization details by loan id gives numberOfElements: 4 with correct ownerExternalId and the following data:
1875-
| settlementDate | purchasePriceRatio | status | effectiveFrom | effectiveTo | Transaction type |
1876-
| 2023-06-14 | 1 | DECLINED | 2023-05-28 | 2023-05-28 | SALE |
1877-
Then LoanOwnershipTransferBusinessEvent with transfer status: "DECLINED" and transfer status reason "BALANCE_NEGATIVE" is created

0 commit comments

Comments
 (0)