Aman-Mittal commented on code in PR #5403:
URL: https://github.com/apache/fineract/pull/5403#discussion_r2747209726
##########
integration-tests/src/test/java/org/apache/fineract/integrationtests/common/shares/ShareAccountIntegrationTests.java:
##########
@@ -983,6 +983,319 @@ public void testCreateShareAccountWithCharges() {
Assertions.assertEquals("0",
String.valueOf(summaryMap.get("totalPendingForApprovalShares")));
}
+ @Test
+ @SuppressWarnings("unchecked")
+ public void testAdditionalSharesAfterRejectedTransaction() {
+ // FINERACT-2457: Share transaction chronological validation should
ignore rejected/reversed transactions
+ shareProductHelper = new ShareProductHelper();
+ final Integer productId = createShareProduct();
+ Assertions.assertNotNull(productId);
+ final Integer clientId = ClientHelper.createClient(this.requestSpec,
this.responseSpec);
+ Assertions.assertNotNull(clientId);
+ Integer savingsAccountId =
SavingsAccountHelper.openSavingsAccount(requestSpec, responseSpec, clientId,
"1000");
+ Assertions.assertNotNull(savingsAccountId);
+
+ String activationCharge =
ChargesHelper.getShareAccountActivationChargeJson();
+ Integer activationChargeId = ChargesHelper.createCharges(requestSpec,
responseSpec, activationCharge);
+ String purchaseCharge =
ChargesHelper.getShareAccountPurchaseChargeJson();
+ Integer purchaseChargeId = ChargesHelper.createCharges(requestSpec,
responseSpec, purchaseCharge);
+ String redeemCharge = ChargesHelper.getShareAccountRedeemChargeJson();
+ Integer redeemChargeId = ChargesHelper.createCharges(requestSpec,
responseSpec, redeemCharge);
+
+ List<Map<String, Object>> charges = new ArrayList<>();
+ charges.add(createCharge(activationChargeId, "2"));
+ charges.add(createCharge(purchaseChargeId, "2"));
+ charges.add(createCharge(redeemChargeId, "1"));
+
+ final Integer shareAccountId = createShareAccount(clientId, productId,
savingsAccountId, charges);
+ Assertions.assertNotNull(shareAccountId);
+
+ // Update share account with initial shares on 01 March 2016
+ Map<String, Object> shareAccountDataForUpdate = new HashMap<>();
+ shareAccountDataForUpdate.put("requestedShares", 25);
+ shareAccountDataForUpdate.put("applicationDate", "01 March 2016");
+ shareAccountDataForUpdate.put("dateFormat", "dd MMMM yyyy");
+ shareAccountDataForUpdate.put("locale", "en_GB");
+ shareAccountDataForUpdate.put("charges", charges);
+ String updateShareAccountJsonString = new
Gson().toJson(shareAccountDataForUpdate);
+ ShareAccountTransactionHelper.updateShareAccount(shareAccountId,
updateShareAccountJsonString, requestSpec, responseSpec);
+
+ // Approve share Account
+ Map<String, Object> approveMap = new HashMap<>();
+ approveMap.put("note", "Share Account Approval Note");
+ approveMap.put("dateFormat", "dd MMMM yyyy");
+ approveMap.put("approvedDate", "01 March 2016");
+ approveMap.put("locale", "en");
+ String approve = new Gson().toJson(approveMap);
+ ShareAccountTransactionHelper.postCommand("approve", shareAccountId,
approve, requestSpec, responseSpec);
+
+ // Activate share account
+ Map<String, Object> activateMap = new HashMap<>();
+ activateMap.put("dateFormat", "dd MMMM yyyy");
+ activateMap.put("activatedDate", "01 March 2016");
+ activateMap.put("locale", "en");
+ String activateJson = new Gson().toJson(activateMap);
+ ShareAccountTransactionHelper.postCommand("activate", shareAccountId,
activateJson, requestSpec, responseSpec);
+
+ Map<String, Object> shareAccountData =
ShareAccountTransactionHelper.retrieveShareAccount(shareAccountId, requestSpec,
+ responseSpec);
+ Map<String, Object> statusMap = (Map<String, Object>)
shareAccountData.get("status");
+ Assertions.assertEquals("shareAccountStatusType.active",
String.valueOf(statusMap.get("code")));
+
+ // Apply additional shares on 15 April 2016
+ Map<String, Object> additionalSharesRequestMap = new HashMap<>();
+ additionalSharesRequestMap.put("requestedDate", "15 April 2016");
+ additionalSharesRequestMap.put("dateFormat", "dd MMMM yyyy");
+ additionalSharesRequestMap.put("locale", "en");
+ additionalSharesRequestMap.put("requestedShares", "20");
+ String additionalSharesRequestJson = new
Gson().toJson(additionalSharesRequestMap);
+ ShareAccountTransactionHelper.postCommand("applyadditionalshares",
shareAccountId, additionalSharesRequestJson, requestSpec,
+ responseSpec);
+
+ shareAccountData =
ShareAccountTransactionHelper.retrieveShareAccount(shareAccountId, requestSpec,
responseSpec);
+ List<Map<String, Object>> transactions = (List<Map<String, Object>>)
shareAccountData.get("purchasedShares");
+ Assertions.assertNotNull(transactions);
+
+ // Find and reject the additional shares request (15 April 2016)
+ String additionalSharesRequestId = null;
+ DateFormat simple = new SimpleDateFormat("dd MMMM yyyy");
+ for (Map<String, Object> transaction : transactions) {
+ Map<String, Object> transactionTypeMap = (Map<String, Object>)
transaction.get("type");
+ List<Integer> dateList = (List<Integer>)
transaction.get("purchasedDate");
+ Calendar cal = Calendar.getInstance();
+ cal.set(dateList.get(0), dateList.get(1) - 1, dateList.get(2));
+ Date date = cal.getTime();
+ String transactionType = (String) transactionTypeMap.get("code");
+ String transactionDate = simple.format(date);
+
+ if (transactionType.equals("purchasedSharesType.purchased") &&
transactionDate.equals("15 April 2016")) {
+ additionalSharesRequestId =
String.valueOf(transaction.get("id"));
+ break;
+ }
+ }
+
+ Assertions.assertNotNull(additionalSharesRequestId, "Additional shares
request for 15 April 2016 should exist");
+
+ // Reject the additional shares request
+ Map<String, List<Map<String, Object>>> rejectMap = new HashMap<>();
+ List<Map<String, Object>> list = new ArrayList<>();
+ Map<String, Object> idsMap = new HashMap<>();
+ idsMap.put("id", additionalSharesRequestId);
+ list.add(idsMap);
+ rejectMap.put("requestedShares", list);
+ String rejectJson = new Gson().toJson(rejectMap);
+ ShareAccountTransactionHelper.postCommand("rejectadditionalshares",
shareAccountId, rejectJson, requestSpec, responseSpec);
+
+ // Verify transaction is rejected
+ shareAccountData =
ShareAccountTransactionHelper.retrieveShareAccount(shareAccountId, requestSpec,
responseSpec);
+ transactions = (List<Map<String, Object>>)
shareAccountData.get("purchasedShares");
+
+ boolean rejectedTransactionFound = false;
+ for (Map<String, Object> transaction : transactions) {
+ Map<String, Object> transactionTypeMap = (Map<String, Object>)
transaction.get("type");
+ List<Integer> dateList = (List<Integer>)
transaction.get("purchasedDate");
+ Calendar cal = Calendar.getInstance();
+ cal.set(dateList.get(0), dateList.get(1) - 1, dateList.get(2));
+ Date date = cal.getTime();
+ String transactionType = (String) transactionTypeMap.get("code");
+ String transactionDate = simple.format(date);
+
+ if (transactionType.equals("purchasedSharesType.purchased") &&
transactionDate.equals("15 April 2016")) {
+ Map<String, Object> transactionStatusMap = (Map<String,
Object>) transaction.get("status");
+ Assertions.assertEquals("purchasedSharesStatusType.rejected",
String.valueOf(transactionStatusMap.get("code")));
+ rejectedTransactionFound = true;
+ break;
+ }
+ }
+ Assertions.assertTrue(rejectedTransactionFound, "Rejected transaction
for 15 April 2016 should exist");
+
+ // Now try to apply additional shares with a date BEFORE the rejected
transaction (10 April 2016)
+ // This should succeed because rejected transactions should be ignored
in chronological validation
+ Map<String, Object> newAdditionalSharesRequestMap = new HashMap<>();
+ newAdditionalSharesRequestMap.put("requestedDate", "10 April 2016");
+ newAdditionalSharesRequestMap.put("dateFormat", "dd MMMM yyyy");
+ newAdditionalSharesRequestMap.put("locale", "en");
+ newAdditionalSharesRequestMap.put("requestedShares", "15");
+ String newAdditionalSharesRequestJson = new
Gson().toJson(newAdditionalSharesRequestMap);
+
+ // This should NOT fail with the fix in place
+ ShareAccountTransactionHelper.postCommand("applyadditionalshares",
shareAccountId, newAdditionalSharesRequestJson, requestSpec,
+ responseSpec);
+
+ // Verify the new transaction was successfully added
+ shareAccountData =
ShareAccountTransactionHelper.retrieveShareAccount(shareAccountId, requestSpec,
responseSpec);
+ transactions = (List<Map<String, Object>>)
shareAccountData.get("purchasedShares");
+
+ boolean newTransactionFound = false;
+ for (Map<String, Object> transaction : transactions) {
+ Map<String, Object> transactionTypeMap = (Map<String, Object>)
transaction.get("type");
+ List<Integer> dateList = (List<Integer>)
transaction.get("purchasedDate");
+ Calendar cal = Calendar.getInstance();
+ cal.set(dateList.get(0), dateList.get(1) - 1, dateList.get(2));
+ Date date = cal.getTime();
+ String transactionType = (String) transactionTypeMap.get("code");
+ String transactionDate = simple.format(date);
+
+ if (transactionType.equals("purchasedSharesType.purchased") &&
transactionDate.equals("10 April 2016")) {
+ Assertions.assertEquals("15",
String.valueOf(transaction.get("numberOfShares")));
+ Map<String, Object> transactionStatusMap = (Map<String,
Object>) transaction.get("status");
+ Assertions.assertEquals("purchasedSharesStatusType.applied",
String.valueOf(transactionStatusMap.get("code")));
+ newTransactionFound = true;
+ break;
+ }
+ }
+ Assertions.assertTrue(newTransactionFound, "New transaction for 10
April 2016 should be successfully created");
+ }
+
+ @Test
+ @SuppressWarnings("unchecked")
+ public void testAccountClosureBeforeRejectedTransaction() {
+ // FINERACT-2457: Account closure validation should ignore
rejected/reversed transactions
+ shareProductHelper = new ShareProductHelper();
+ final Integer productId = createShareProduct();
+ Assertions.assertNotNull(productId);
+ final Integer clientId = ClientHelper.createClient(this.requestSpec,
this.responseSpec);
+ Assertions.assertNotNull(clientId);
+ Integer savingsAccountId =
SavingsAccountHelper.openSavingsAccount(requestSpec, responseSpec, clientId,
"1000");
+ Assertions.assertNotNull(savingsAccountId);
+
+ String activationCharge =
ChargesHelper.getShareAccountActivationChargeJson();
+ Integer activationChargeId = ChargesHelper.createCharges(requestSpec,
responseSpec, activationCharge);
+ String purchaseCharge =
ChargesHelper.getShareAccountPurchaseChargeJson();
+ Integer purchaseChargeId = ChargesHelper.createCharges(requestSpec,
responseSpec, purchaseCharge);
+ String redeemCharge = ChargesHelper.getShareAccountRedeemChargeJson();
+ Integer redeemChargeId = ChargesHelper.createCharges(requestSpec,
responseSpec, redeemCharge);
+
+ List<Map<String, Object>> charges = new ArrayList<>();
+ charges.add(createCharge(activationChargeId, "2"));
+ charges.add(createCharge(purchaseChargeId, "2"));
+ charges.add(createCharge(redeemChargeId, "1"));
+
+ final Integer shareAccountId = createShareAccount(clientId, productId,
savingsAccountId, charges);
+ Assertions.assertNotNull(shareAccountId);
+
+ // Update share account with initial shares on 01 March 2016
+ Map<String, Object> shareAccountDataForUpdate = new HashMap<>();
+ shareAccountDataForUpdate.put("requestedShares", 25);
+ shareAccountDataForUpdate.put("applicationDate", "01 March 2016");
+ shareAccountDataForUpdate.put("dateFormat", "dd MMMM yyyy");
+ shareAccountDataForUpdate.put("locale", "en_GB");
+ shareAccountDataForUpdate.put("charges", charges);
+ String updateShareAccountJsonString = new
Gson().toJson(shareAccountDataForUpdate);
+ ShareAccountTransactionHelper.updateShareAccount(shareAccountId,
updateShareAccountJsonString, requestSpec, responseSpec);
+
+ // Approve share Account
+ Map<String, Object> approveMap = new HashMap<>();
Review Comment:
This Share Account Approval Note logic seems to be duplicated in both tests,
i think a helper function can be extracted especially this part
Map<String, Object> approveMap = new HashMap<>();
approveMap.put("note", "Share Account Approval Note");
approveMap.put("dateFormat", "dd MMMM yyyy");
approveMap.put("approvedDate", "01 March 2016");
approveMap.put("locale", "en");
String approve = new Gson().toJson(approveMap);
ShareAccountTransactionHelper.postCommand("approve", ...);
Map<String, Object> activateMap = new HashMap<>();
activateMap.put("dateFormat", "dd MMMM yyyy");
activateMap.put("activatedDate", "01 March 2016");
activateMap.put("locale", "en");
String activateJson = new Gson().toJson(activateMap);
ShareAccountTransactionHelper.postCommand("activate", ...);
for (Map<String, Object> transaction : transactions) {
Map<String, Object> transactionTypeMap = (Map<String, Object>)
transaction.get("type");
List<Integer> dateList = (List<Integer>)
transaction.get("purchasedDate");
Calendar cal = Calendar.getInstance();
cal.set(dateList.get(0), dateList.get(1) - 1, dateList.get(2));
Date date = cal.getTime();
String transactionType = (String) transactionTypeMap.get("code");
String transactionDate = simple.format(date);
if (transactionType.equals(...) && transactionDate.equals(...)) {
...
break;
}
}
Map<String, List<Map<String, Object>>> rejectMap = new HashMap<>();
List<Map<String, Object>> list = new ArrayList<>();
Map<String, Object> idsMap = new HashMap<>();
idsMap.put("id", additionalSharesRequestId);
list.add(idsMap);
rejectMap.put("requestedShares", list);
String rejectJson = new Gson().toJson(rejectMap);
ShareAccountTransactionHelper.postCommand("rejectadditionalshares", ...);
--
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]