MIFOSX-1554 : added min balance check only for withdrawal transactions
This commit is contained in:
+81
-12
@@ -185,10 +185,75 @@ public class ClientSavingsIntegrationTest {
|
|||||||
savingsAccountErrorData.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
savingsAccountErrorData.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||||
|
|
||||||
withdrawBalance = "true";
|
withdrawBalance = "true";
|
||||||
savingsStatusHashMap = this.savingsAccountHelper.closeSavingsAccount(savingsId, withdrawBalance);
|
savingsStatusHashMap = this.savingsAccountHelper.closeSavingsAccount(savingsId, withdrawBalance);
|
||||||
SavingsStatusChecker.verifySavingsAccountIsClosed(savingsStatusHashMap);
|
SavingsStatusChecker.verifySavingsAccountIsClosed(savingsStatusHashMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Test
|
||||||
|
public void testSavingsAccount_WITH_ENFORCE_MIN_BALANCE() {
|
||||||
|
this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec);
|
||||||
|
final ResponseSpecification errorResponse = new ResponseSpecBuilder().expectStatusCode(403).build();
|
||||||
|
final SavingsAccountHelper validationErrorHelper = new SavingsAccountHelper(this.requestSpec, errorResponse);
|
||||||
|
|
||||||
|
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
|
||||||
|
Assert.assertNotNull(clientID);
|
||||||
|
final String minBalanceForInterestCalculation = null;
|
||||||
|
final String minRequiredBalance = "1500.0";
|
||||||
|
final String enforceMinRequiredBalance = "true";
|
||||||
|
final boolean allowOverdraft = false;
|
||||||
|
final Integer savingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE,
|
||||||
|
minBalanceForInterestCalculation, minRequiredBalance, enforceMinRequiredBalance, allowOverdraft);
|
||||||
|
Assert.assertNotNull(savingsProductID);
|
||||||
|
|
||||||
|
final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(clientID, savingsProductID, ACCOUNT_TYPE_INDIVIDUAL);
|
||||||
|
Assert.assertNotNull(savingsProductID);
|
||||||
|
|
||||||
|
HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsId);
|
||||||
|
SavingsStatusChecker.verifySavingsIsPending(savingsStatusHashMap);
|
||||||
|
|
||||||
|
final Integer savingsActivationChargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec,
|
||||||
|
ChargesHelper.getSavingsActivationFeeJSON());
|
||||||
|
Assert.assertNotNull(savingsActivationChargeId);
|
||||||
|
|
||||||
|
this.savingsAccountHelper.addChargesForSavings(savingsId, savingsActivationChargeId);
|
||||||
|
|
||||||
|
savingsStatusHashMap = this.savingsAccountHelper.approveSavings(savingsId);
|
||||||
|
SavingsStatusChecker.verifySavingsIsApproved(savingsStatusHashMap);
|
||||||
|
|
||||||
|
savingsStatusHashMap = this.savingsAccountHelper.activateSavings(savingsId);
|
||||||
|
SavingsStatusChecker.verifySavingsIsActive(savingsStatusHashMap);
|
||||||
|
|
||||||
|
HashMap summary = this.savingsAccountHelper.getSavingsSummary(savingsId);
|
||||||
|
Float balance = new Float(MINIMUM_OPENING_BALANCE);
|
||||||
|
Float chargeAmt = 100f;
|
||||||
|
balance -= chargeAmt;
|
||||||
|
assertEquals("Verifying opening Balance", balance, summary.get("accountBalance"));
|
||||||
|
|
||||||
|
DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy");
|
||||||
|
Calendar todaysDate = Calendar.getInstance();
|
||||||
|
final String TRANSACTION_DATE = dateFormat.format(todaysDate.getTime());
|
||||||
|
final String withdrawAmt = "800";
|
||||||
|
ArrayList<HashMap> savingsAccountErrorData = (ArrayList<HashMap>) validationErrorHelper.withdrawalFromSavingsAccount(savingsId,
|
||||||
|
withdrawAmt, TRANSACTION_DATE, CommonConstants.RESPONSE_ERROR);
|
||||||
|
assertEquals("error.msg.savingsaccount.transaction.insufficient.account.balance",
|
||||||
|
savingsAccountErrorData.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||||
|
|
||||||
|
Integer depositTransactionId = (Integer) this.savingsAccountHelper.depositToSavingsAccount(savingsId, DEPOSIT_AMOUNT,
|
||||||
|
TRANSACTION_DATE, CommonConstants.RESPONSE_RESOURCE_ID);
|
||||||
|
HashMap depositTransaction = this.savingsAccountHelper.getSavingsTransaction(savingsId, depositTransactionId);
|
||||||
|
balance += new Float(DEPOSIT_AMOUNT);
|
||||||
|
assertEquals("Verifying Deposit Amount", new Float(DEPOSIT_AMOUNT), depositTransaction.get("amount"));
|
||||||
|
assertEquals("Verifying Balance after Deposit", balance, depositTransaction.get("runningBalance"));
|
||||||
|
|
||||||
|
Integer withdrawTransactionId = (Integer) this.savingsAccountHelper.withdrawalFromSavingsAccount(savingsId, withdrawAmt,
|
||||||
|
TRANSACTION_DATE, CommonConstants.RESPONSE_RESOURCE_ID);
|
||||||
|
HashMap withdrawTransaction = this.savingsAccountHelper.getSavingsTransaction(savingsId, withdrawTransactionId);
|
||||||
|
balance -= new Float(withdrawAmt);
|
||||||
|
assertEquals("Verifying Withdrawal Amount", new Float(withdrawAmt), withdrawTransaction.get("amount"));
|
||||||
|
assertEquals("Verifying Balance after Withdrawal", balance, withdrawTransaction.get("runningBalance"));
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Test
|
@Test
|
||||||
public void testSavingsAccount_DELETE_APPLICATION() {
|
public void testSavingsAccount_DELETE_APPLICATION() {
|
||||||
@@ -521,7 +586,7 @@ public class ClientSavingsIntegrationTest {
|
|||||||
this.savingsAccountHelper.addChargesForSavings(savingsId, weeklyFeeId);
|
this.savingsAccountHelper.addChargesForSavings(savingsId, weeklyFeeId);
|
||||||
charges = this.savingsAccountHelper.getSavingsCharges(savingsId);
|
charges = this.savingsAccountHelper.getSavingsCharges(savingsId);
|
||||||
Assert.assertEquals(3, charges.size());
|
Assert.assertEquals(3, charges.size());
|
||||||
|
|
||||||
savingsChargeForPay = charges.get(2);
|
savingsChargeForPay = charges.get(2);
|
||||||
final Integer weeklySavingsFeeId = (Integer) savingsChargeForPay.get("id");
|
final Integer weeklySavingsFeeId = (Integer) savingsChargeForPay.get("id");
|
||||||
|
|
||||||
@@ -529,7 +594,7 @@ public class ClientSavingsIntegrationTest {
|
|||||||
CommonConstants.RESPONSE_ERROR);
|
CommonConstants.RESPONSE_ERROR);
|
||||||
assertEquals("validation.msg.savingsaccountcharge.inactivation.of.charge.not.allowed.when.charge.is.due", savingsAccountErrorData
|
assertEquals("validation.msg.savingsaccountcharge.inactivation.of.charge.not.allowed.when.charge.is.due", savingsAccountErrorData
|
||||||
.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||||
|
|
||||||
cal = Calendar.getInstance();
|
cal = Calendar.getInstance();
|
||||||
dates = (List) savingsChargeForPay.get("dueDate");
|
dates = (List) savingsChargeForPay.get("dueDate");
|
||||||
cal.set(Calendar.YEAR, (Integer) dates.get(0));
|
cal.set(Calendar.YEAR, (Integer) dates.get(0));
|
||||||
@@ -686,7 +751,7 @@ public class ClientSavingsIntegrationTest {
|
|||||||
interestPosted = new Float(decimalFormat.format(interestPosted));
|
interestPosted = new Float(decimalFormat.format(interestPosted));
|
||||||
actualInterestPosted = new Float(decimalFormat.format(actualInterestPosted));
|
actualInterestPosted = new Float(decimalFormat.format(actualInterestPosted));
|
||||||
assertEquals("Verifying interest posted", interestPosted, actualInterestPosted);
|
assertEquals("Verifying interest posted", interestPosted, actualInterestPosted);
|
||||||
|
|
||||||
todaysDate = Calendar.getInstance();
|
todaysDate = Calendar.getInstance();
|
||||||
final String CLOSEDON_DATE = dateFormat.format(todaysDate.getTime());
|
final String CLOSEDON_DATE = dateFormat.format(todaysDate.getTime());
|
||||||
String withdrawBalance = "false";
|
String withdrawBalance = "false";
|
||||||
@@ -710,14 +775,18 @@ public class ClientSavingsIntegrationTest {
|
|||||||
final String overDraftLimit = "2000.0";
|
final String overDraftLimit = "2000.0";
|
||||||
savingsProductHelper = savingsProductHelper.withOverDraft(overDraftLimit);
|
savingsProductHelper = savingsProductHelper.withOverDraft(overDraftLimit);
|
||||||
}
|
}
|
||||||
|
|
||||||
final String savingsProductJSON = savingsProductHelper //
|
final String savingsProductJSON = savingsProductHelper
|
||||||
.withInterestCompoundingPeriodTypeAsDaily() //
|
//
|
||||||
.withInterestPostingPeriodTypeAsMonthly() //
|
.withInterestCompoundingPeriodTypeAsDaily()
|
||||||
.withInterestCalculationPeriodTypeAsDailyBalance() //
|
//
|
||||||
.withMinBalanceForInterestCalculation(minBalanceForInterestCalculation)//
|
.withInterestPostingPeriodTypeAsMonthly()
|
||||||
.withMinRequiredBalance(minRequiredBalance)
|
//
|
||||||
.withEnforceMinRequiredBalance(enforceMinRequiredBalance)
|
.withInterestCalculationPeriodTypeAsDailyBalance()
|
||||||
|
//
|
||||||
|
.withMinBalanceForInterestCalculation(minBalanceForInterestCalculation)
|
||||||
|
//
|
||||||
|
.withMinRequiredBalance(minRequiredBalance).withEnforceMinRequiredBalance(enforceMinRequiredBalance)
|
||||||
.withMinimumOpenningBalance(minOpenningBalance).build();
|
.withMinimumOpenningBalance(minOpenningBalance).build();
|
||||||
return SavingsProductHelper.createSavingsProduct(savingsProductJSON, requestSpec, responseSpec);
|
return SavingsProductHelper.createSavingsProduct(savingsProductJSON, requestSpec, responseSpec);
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-2
@@ -845,18 +845,19 @@ public class SavingsAccount extends AbstractPersistable<Long> {
|
|||||||
public void validateAccountBalanceDoesNotBecomeNegative(final BigDecimal transactionAmount, final boolean isWithdrawBalance) {
|
public void validateAccountBalanceDoesNotBecomeNegative(final BigDecimal transactionAmount, final boolean isWithdrawBalance) {
|
||||||
final List<SavingsAccountTransaction> transactionsSortedByDate = retreiveListOfTransactions();
|
final List<SavingsAccountTransaction> transactionsSortedByDate = retreiveListOfTransactions();
|
||||||
Money runningBalance = Money.zero(this.currency);
|
Money runningBalance = Money.zero(this.currency);
|
||||||
|
|
||||||
for (final SavingsAccountTransaction transaction : transactionsSortedByDate) {
|
for (final SavingsAccountTransaction transaction : transactionsSortedByDate) {
|
||||||
if (transaction.isNotReversed() && transaction.isCredit()) {
|
if (transaction.isNotReversed() && transaction.isCredit()) {
|
||||||
runningBalance = runningBalance.plus(transaction.getAmount(this.currency));
|
runningBalance = runningBalance.plus(transaction.getAmount(this.currency));
|
||||||
} else if (transaction.isNotReversed() && transaction.isDebit()) {
|
} else if (transaction.isNotReversed() && transaction.isDebit()) {
|
||||||
runningBalance = runningBalance.minus(transaction.getAmount(this.currency));
|
runningBalance = runningBalance.minus(transaction.getAmount(this.currency));
|
||||||
|
} else {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
final BigDecimal withdrawalFee = null;
|
final BigDecimal withdrawalFee = null;
|
||||||
// deal with potential minRequiredBalance and
|
// deal with potential minRequiredBalance and
|
||||||
// enforceMinRequiredBalance
|
// enforceMinRequiredBalance
|
||||||
if (!isWithdrawBalance && this.minRequiredBalance != null && this.enforceMinRequiredBalance) {
|
if (!isWithdrawBalance && this.minRequiredBalance != null && this.enforceMinRequiredBalance && transaction.isWithdrawal()) {
|
||||||
if (runningBalance.minus(this.minRequiredBalance).isLessThanZero()) { throw new InsufficientAccountBalanceException(
|
if (runningBalance.minus(this.minRequiredBalance).isLessThanZero()) { throw new InsufficientAccountBalanceException(
|
||||||
"transactionAmount", getAccountBalance(), withdrawalFee, transactionAmount); }
|
"transactionAmount", getAccountBalance(), withdrawalFee, transactionAmount); }
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-2
@@ -226,9 +226,16 @@ public class SavingsAccountAssembler {
|
|||||||
boolean enforceMinRequiredBalance = false;
|
boolean enforceMinRequiredBalance = false;
|
||||||
if (command.parameterExists(enforceMinRequiredBalanceParamName)) {
|
if (command.parameterExists(enforceMinRequiredBalanceParamName)) {
|
||||||
enforceMinRequiredBalance = command.booleanPrimitiveValueOfParameterNamed(enforceMinRequiredBalanceParamName);
|
enforceMinRequiredBalance = command.booleanPrimitiveValueOfParameterNamed(enforceMinRequiredBalanceParamName);
|
||||||
|
} else {
|
||||||
|
enforceMinRequiredBalance = product.isMinRequiredBalanceEnforced();
|
||||||
|
}
|
||||||
|
|
||||||
|
BigDecimal minRequiredBalance = null;
|
||||||
|
if (command.parameterExists(overdraftLimitParamName)) {
|
||||||
|
minRequiredBalance = command.bigDecimalValueOfParameterNamedDefaultToNullIfZero(minRequiredBalanceParamName);
|
||||||
|
} else {
|
||||||
|
minRequiredBalance = product.minRequiredBalance();
|
||||||
}
|
}
|
||||||
|
|
||||||
final BigDecimal minRequiredBalance = command.bigDecimalValueOfParameterNamedDefaultToNullIfZero(minRequiredBalanceParamName);
|
|
||||||
|
|
||||||
final SavingsAccount account = SavingsAccount.createNewApplicationForSubmittal(client, group, product, fieldOfficer, accountNo,
|
final SavingsAccount account = SavingsAccount.createNewApplicationForSubmittal(client, group, product, fieldOfficer, accountNo,
|
||||||
externalId, accountType, submittedOnDate, submittedBy, interestRate, interestCompoundingPeriodType,
|
externalId, accountType, submittedOnDate, submittedBy, interestRate, interestCompoundingPeriodType,
|
||||||
|
|||||||
Reference in New Issue
Block a user