}
@SuppressWarnings("unchecked")
@Test
public void testSavingsAccountTransactions() {
this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec);
SavingsAccountHelper savingsAccountHelperValidationError = new SavingsAccountHelper(this.requestSpec,
new ResponseSpecBuilder().build());
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
Assert.assertNotNull(clientID);
Integer groupID = GroupHelper.createGroup(this.requestSpec, this.responseSpec, true);
Assert.assertNotNull(groupID);
groupID = GroupHelper.associateClient(this.requestSpec, this.responseSpec, groupID.toString(), clientID.toString());
Assert.assertNotNull(groupID);
final String minBalanceForInterestCalculation = null;
final String minRequiredBalance = null;
final String enforceMinRequiredBalance = "false";
final Integer savingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE,
minBalanceForInterestCalculation, minRequiredBalance, enforceMinRequiredBalance);
Assert.assertNotNull(savingsProductID);
final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(groupID, savingsProductID, ACCOUNT_TYPE_GROUP);
Assert.assertNotNull(savingsId);
HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsId);
SavingsStatusChecker.verifySavingsIsPending(savingsStatusHashMap);
savingsStatusHashMap = this.savingsAccountHelper.approveSavings(savingsId);
SavingsStatusChecker.verifySavingsIsApproved(savingsStatusHashMap);
List<HashMap> error = (List) savingsAccountHelperValidationError.withdrawalFromSavingsAccount(savingsId, "100",
SavingsAccountHelper.TRANSACTION_DATE, CommonConstants.RESPONSE_ERROR);
assertEquals("error.msg.savingsaccount.transaction.account.is.not.active",
error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
error = (List) savingsAccountHelperValidationError.depositToSavingsAccount(savingsId, "100", SavingsAccountHelper.TRANSACTION_DATE,
CommonConstants.RESPONSE_ERROR);
assertEquals("error.msg.savingsaccount.transaction.account.is.not.active",
error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
savingsStatusHashMap = this.savingsAccountHelper.activateSavings(savingsId);
SavingsStatusChecker.verifySavingsIsActive(savingsStatusHashMap);
HashMap summary = this.savingsAccountHelper.getSavingsSummary(savingsId);
Float balance = new Float(MINIMUM_OPENING_BALANCE);
assertEquals("Verifying opening Balance", balance, summary.get("accountBalance"));
Integer depositTransactionId = (Integer) this.savingsAccountHelper.depositToSavingsAccount(savingsId, DEPOSIT_AMOUNT,
SavingsAccountHelper.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, WITHDRAW_AMOUNT,
SavingsAccountHelper.TRANSACTION_DATE, CommonConstants.RESPONSE_RESOURCE_ID);
HashMap withdrawTransaction = this.savingsAccountHelper.getSavingsTransaction(savingsId, withdrawTransactionId);
balance -= new Float(WITHDRAW_AMOUNT);
assertEquals("Verifying Withdrawal Amount", new Float(WITHDRAW_AMOUNT), withdrawTransaction.get("amount"));
assertEquals("Verifying Balance after Withdrawal", balance, withdrawTransaction.get("runningBalance"));
Integer newWithdrawTransactionId = this.savingsAccountHelper.updateSavingsAccountTransaction(savingsId, withdrawTransactionId,
WITHDRAW_AMOUNT_ADJUSTED);
HashMap newWithdrawTransaction = this.savingsAccountHelper.getSavingsTransaction(savingsId, newWithdrawTransactionId);
balance = balance + new Float(WITHDRAW_AMOUNT) - new Float(WITHDRAW_AMOUNT_ADJUSTED);
assertEquals("Verifying adjusted Amount", new Float(WITHDRAW_AMOUNT_ADJUSTED), newWithdrawTransaction.get("amount"));
assertEquals("Verifying Balance after adjust", balance, newWithdrawTransaction.get("runningBalance"));
summary = this.savingsAccountHelper.getSavingsSummary(savingsId);
assertEquals("Verifying Adjusted Balance", balance, summary.get("accountBalance"));
withdrawTransaction = this.savingsAccountHelper.getSavingsTransaction(savingsId, withdrawTransactionId);
Assert.assertTrue((Boolean) withdrawTransaction.get("reversed"));
this.savingsAccountHelper.undoSavingsAccountTransaction(savingsId, newWithdrawTransactionId);
newWithdrawTransaction = this.savingsAccountHelper.getSavingsTransaction(savingsId, withdrawTransactionId);
Assert.assertTrue((Boolean) newWithdrawTransaction.get("reversed"));
summary = this.savingsAccountHelper.getSavingsSummary(savingsId);
balance += new Float(WITHDRAW_AMOUNT_ADJUSTED);
assertEquals("Verifying Balance After Undo Transaction", balance, summary.get("accountBalance"));
error = (List) savingsAccountHelperValidationError.withdrawalFromSavingsAccount(savingsId, "5000",
SavingsAccountHelper.TRANSACTION_DATE, CommonConstants.RESPONSE_ERROR);
assertEquals("error.msg.savingsaccount.transaction.insufficient.account.balance",
error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
error = (List) savingsAccountHelperValidationError.withdrawalFromSavingsAccount(savingsId, "5000",
SavingsAccountHelper.getFutureDate(), CommonConstants.RESPONSE_ERROR);
assertEquals("error.msg.savingsaccount.transaction.in.the.future", error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
error = (List) savingsAccountHelperValidationError.depositToSavingsAccount(savingsId, "5000", SavingsAccountHelper.getFutureDate(),
CommonConstants.RESPONSE_ERROR);
assertEquals("error.msg.savingsaccount.transaction.in.the.future", error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
error = (List) savingsAccountHelperValidationError.withdrawalFromSavingsAccount(savingsId, "5000",
SavingsAccountHelper.CREATED_DATE_MINUS_ONE, CommonConstants.RESPONSE_ERROR);
assertEquals("error.msg.savingsaccount.transaction.before.activation.date",
error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
error = (List) savingsAccountHelperValidationError.depositToSavingsAccount(savingsId, "5000",
SavingsAccountHelper.CREATED_DATE_MINUS_ONE, CommonConstants.RESPONSE_ERROR);
assertEquals("error.msg.savingsaccount.transaction.before.activation.date",
error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
}