From 53842362205ff96b2d9ff4dcf4fe531f8629648b Mon Sep 17 00:00:00 2001 From: Dhruv Sonagara <78945411+dhruvsonagara@users.noreply.github.com> Date: Sun, 25 Aug 2024 12:48:39 +0530 Subject: [PATCH] FINERACT-2115: Create account transfers validation tests (#4011) * FINERACT-2115 Create credit bureau and account transfers validation tests * Added account trasnfer validation TCs and updated accot trasnfer helper class * Updated the spotless changes * Removed the unnescessary code and updated the account transfer validation tests * Added the test cases for invalid date format for the account transfer test * Updated the code according to the right response code for account transfer negative TC --- .../integrationtests/AccountTransferTest.java | 450 ++++++++++++++++++ .../common/savings/AccountTransferHelper.java | 52 ++ 2 files changed, 502 insertions(+) diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/AccountTransferTest.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/AccountTransferTest.java index 8d61a0b85..52824bbb3 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/AccountTransferTest.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/AccountTransferTest.java @@ -70,12 +70,19 @@ public class AccountTransferTest { public static final String MINIMUM_OPENING_BALANCE = "30000.0"; public static final String ACCOUNT_TYPE_INDIVIDUAL = "INDIVIDUAL"; public static final String ACCOUNT_TRANSFER_AMOUNT = "15000.0"; + public static final String ACCOUNT_TRANSFER_NEGATIVE_AMOUNT = "-15000.0"; public static final String ACCOUNT_TRANSFER_AMOUNT_ADJUST = "3000.0"; + public static final String ACCOUNT_TRANSFER_LARGE_AMOUNT = "100000.0"; + public static final String ACCOUNT_TRANSFER_NEGATIVE_AMOUNT_ADJUST = "-3000.0"; public static final String FROM_LOAN_ACCOUNT_TYPE = "1"; + public static final String INVALID_LOAN_ACCOUNT_TYPE = "999"; public static final String FROM_SAVINGS_ACCOUNT_TYPE = "2"; + public static final String INVALID_SAVINGS_ACCOUNT_TYPE = "999"; public static final String TO_LOAN_ACCOUNT_TYPE = "1"; public static final String TO_SAVINGS_ACCOUNT_TYPE = "2"; + public static final Integer INVALID_LOAN_ID = 123123123; + public static final String LOAN_APPROVAL_DATE = "10 January 2013"; public static final String LOAN_APPROVAL_DATE_PLUS_ONE = "11 January 2013"; public static final String LOAN_DISBURSAL_DATE = "10 January 2013"; @@ -456,6 +463,449 @@ public class AccountTransferTest { } + @Test + public void testTransferWithNegativeAmount() { + final Account assetAccount = this.accountHelper.createAssetAccount(); + final Account incomeAccount = this.accountHelper.createIncomeAccount(); + final Account expenseAccount = this.accountHelper.createExpenseAccount(); + final Account liabilityAccount = this.accountHelper.createLiabilityAccount(); + + final Account loanAssetAccount = this.accountHelper.createAssetAccount(); + final Account loanIncomeAccount = this.accountHelper.createIncomeAccount(); + final Account loanExpenseAccount = this.accountHelper.createExpenseAccount(); + final Account overpaymentAccount = this.accountHelper.createLiabilityAccount(); + + this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec); + this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec); + this.accountTransferHelper = new AccountTransferHelper(this.requestSpec, this.responseSpec); + + OfficeHelper officeHelper = new OfficeHelper(this.requestSpec, this.responseSpec); + Integer toOfficeId = officeHelper.createOffice("01 January 2011"); + Assertions.assertNotNull(toOfficeId); + + // Creating Loan Account to which fund to be Transferred + final Integer toClientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2011", + String.valueOf(toOfficeId)); + Assertions.assertNotNull(toClientID); + + final Integer toSavingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE, assetAccount, + incomeAccount, expenseAccount, liabilityAccount); + Assertions.assertNotNull(toSavingsProductID); + + final Integer toSavingsID = this.savingsAccountHelper.applyForSavingsApplication(toClientID, toSavingsProductID, + ACCOUNT_TYPE_INDIVIDUAL); + Assertions.assertNotNull(toSavingsID); + + HashMap toSavingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, toSavingsID); + SavingsStatusChecker.verifySavingsIsPending(toSavingsStatusHashMap); + + toSavingsStatusHashMap = this.savingsAccountHelper.approveSavings(toSavingsID); + SavingsStatusChecker.verifySavingsIsApproved(toSavingsStatusHashMap); + + toSavingsStatusHashMap = this.savingsAccountHelper.activateSavings(toSavingsID); + SavingsStatusChecker.verifySavingsIsActive(toSavingsStatusHashMap); + + Integer fromOfficeId = officeHelper.createOffice("01 January 2011"); + Assertions.assertNotNull(fromOfficeId); + + // Creating Savings Account from which the Fund has to be Transferred + final Integer fromClientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2011", + String.valueOf(fromOfficeId)); + Assertions.assertNotNull(fromClientID); + + final Integer loanProductID = createLoanProduct(loanAssetAccount, loanIncomeAccount, loanExpenseAccount, overpaymentAccount); + Assertions.assertNotNull(loanProductID); + + final Integer loanID = applyForLoanApplication(fromClientID, loanProductID); + Assertions.assertNotNull(loanID); + + HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID); + LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap); + + loanStatusHashMap = this.loanTransactionHelper.approveLoan(LOAN_APPROVAL_DATE, loanID); + LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap); + + String loanDetails = this.loanTransactionHelper.getLoanDetails(this.requestSpec, this.responseSpec, loanID); + loanStatusHashMap = this.loanTransactionHelper.disburseLoanWithNetDisbursalAmount(LOAN_DISBURSAL_DATE, loanID, + JsonPath.from(loanDetails).get("netDisbursalAmount").toString()); + LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap); + + final Integer fromSavingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE, + assetAccount, incomeAccount, expenseAccount, liabilityAccount); + Assertions.assertNotNull(fromSavingsProductID); + + final Integer fromSavingsID = this.savingsAccountHelper.applyForSavingsApplication(fromClientID, fromSavingsProductID, + ACCOUNT_TYPE_INDIVIDUAL); + Assertions.assertNotNull(fromSavingsID); + + HashMap fromSavingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, fromSavingsID); + SavingsStatusChecker.verifySavingsIsPending(fromSavingsStatusHashMap); + + fromSavingsStatusHashMap = this.savingsAccountHelper.approveSavings(fromSavingsID); + SavingsStatusChecker.verifySavingsIsApproved(fromSavingsStatusHashMap); + + fromSavingsStatusHashMap = this.savingsAccountHelper.activateSavings(fromSavingsID); + SavingsStatusChecker.verifySavingsIsActive(fromSavingsStatusHashMap); + + final HashMap toSavingsSummaryBefore = this.savingsAccountHelper.getSavingsSummary(toSavingsID); + + Float fromSavingsBalance = Float.valueOf(MINIMUM_OPENING_BALANCE); + + Object accountTransfer = this.accountTransferHelper.invalidAccountTransfer(fromClientID, fromSavingsID, fromClientID, loanID, + FROM_SAVINGS_ACCOUNT_TYPE, TO_LOAN_ACCOUNT_TYPE, ACCOUNT_TRANSFER_NEGATIVE_AMOUNT); + } + + @Test + public void testTransferWithInsufficientBalance() { + final Account assetAccount = this.accountHelper.createAssetAccount(); + final Account incomeAccount = this.accountHelper.createIncomeAccount(); + final Account expenseAccount = this.accountHelper.createExpenseAccount(); + final Account liabilityAccount = this.accountHelper.createLiabilityAccount(); + + final Account loanAssetAccount = this.accountHelper.createAssetAccount(); + final Account loanIncomeAccount = this.accountHelper.createIncomeAccount(); + final Account loanExpenseAccount = this.accountHelper.createExpenseAccount(); + final Account overpaymentAccount = this.accountHelper.createLiabilityAccount(); + + this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec); + this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec); + this.accountTransferHelper = new AccountTransferHelper(this.requestSpec, this.responseSpec); + + OfficeHelper officeHelper = new OfficeHelper(this.requestSpec, this.responseSpec); + Integer toOfficeId = officeHelper.createOffice("01 January 2011"); + Assertions.assertNotNull(toOfficeId); + + // Creating Loan Account to which fund to be Transferred + final Integer toClientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2011", + String.valueOf(toOfficeId)); + Assertions.assertNotNull(toClientID); + + final Integer toSavingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE, assetAccount, + incomeAccount, expenseAccount, liabilityAccount); + Assertions.assertNotNull(toSavingsProductID); + + final Integer toSavingsID = this.savingsAccountHelper.applyForSavingsApplication(toClientID, toSavingsProductID, + ACCOUNT_TYPE_INDIVIDUAL); + Assertions.assertNotNull(toSavingsID); + + HashMap toSavingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, toSavingsID); + SavingsStatusChecker.verifySavingsIsPending(toSavingsStatusHashMap); + + toSavingsStatusHashMap = this.savingsAccountHelper.approveSavings(toSavingsID); + SavingsStatusChecker.verifySavingsIsApproved(toSavingsStatusHashMap); + + toSavingsStatusHashMap = this.savingsAccountHelper.activateSavings(toSavingsID); + SavingsStatusChecker.verifySavingsIsActive(toSavingsStatusHashMap); + + Integer fromOfficeId = officeHelper.createOffice("01 January 2011"); + Assertions.assertNotNull(fromOfficeId); + + // Creating Savings Account from which the Fund has to be Transferred + final Integer fromClientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2011", + String.valueOf(fromOfficeId)); + Assertions.assertNotNull(fromClientID); + + final Integer loanProductID = createLoanProduct(loanAssetAccount, loanIncomeAccount, loanExpenseAccount, overpaymentAccount); + Assertions.assertNotNull(loanProductID); + + final Integer loanID = applyForLoanApplication(fromClientID, loanProductID); + Assertions.assertNotNull(loanID); + + HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID); + LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap); + + loanStatusHashMap = this.loanTransactionHelper.approveLoan(LOAN_APPROVAL_DATE, loanID); + LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap); + + String loanDetails = this.loanTransactionHelper.getLoanDetails(this.requestSpec, this.responseSpec, loanID); + loanStatusHashMap = this.loanTransactionHelper.disburseLoanWithNetDisbursalAmount(LOAN_DISBURSAL_DATE, loanID, + JsonPath.from(loanDetails).get("netDisbursalAmount").toString()); + LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap); + + final Integer fromSavingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE, + assetAccount, incomeAccount, expenseAccount, liabilityAccount); + Assertions.assertNotNull(fromSavingsProductID); + + final Integer fromSavingsID = this.savingsAccountHelper.applyForSavingsApplication(fromClientID, fromSavingsProductID, + ACCOUNT_TYPE_INDIVIDUAL); + Assertions.assertNotNull(fromSavingsID); + + HashMap fromSavingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, fromSavingsID); + SavingsStatusChecker.verifySavingsIsPending(fromSavingsStatusHashMap); + + fromSavingsStatusHashMap = this.savingsAccountHelper.approveSavings(fromSavingsID); + SavingsStatusChecker.verifySavingsIsApproved(fromSavingsStatusHashMap); + + fromSavingsStatusHashMap = this.savingsAccountHelper.activateSavings(fromSavingsID); + SavingsStatusChecker.verifySavingsIsActive(fromSavingsStatusHashMap); + + final HashMap toSavingsSummaryBefore = this.savingsAccountHelper.getSavingsSummary(toSavingsID); + + Float fromSavingsBalance = Float.valueOf(MINIMUM_OPENING_BALANCE); + + Object accountTransfer = this.accountTransferHelper.insufficientBalanceAccountTransfer(fromClientID, fromSavingsID, fromClientID, + loanID, FROM_SAVINGS_ACCOUNT_TYPE, TO_LOAN_ACCOUNT_TYPE, ACCOUNT_TRANSFER_LARGE_AMOUNT); + + } + + @Test + public void testTransferToInvalidAccountTypes() { + final Account assetAccount = this.accountHelper.createAssetAccount(); + final Account incomeAccount = this.accountHelper.createIncomeAccount(); + final Account expenseAccount = this.accountHelper.createExpenseAccount(); + final Account liabilityAccount = this.accountHelper.createLiabilityAccount(); + + final Account loanAssetAccount = this.accountHelper.createAssetAccount(); + final Account loanIncomeAccount = this.accountHelper.createIncomeAccount(); + final Account loanExpenseAccount = this.accountHelper.createExpenseAccount(); + final Account overpaymentAccount = this.accountHelper.createLiabilityAccount(); + + this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec); + this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec); + this.accountTransferHelper = new AccountTransferHelper(this.requestSpec, this.responseSpec); + + OfficeHelper officeHelper = new OfficeHelper(this.requestSpec, this.responseSpec); + Integer toOfficeId = officeHelper.createOffice("01 January 2011"); + Assertions.assertNotNull(toOfficeId); + + // Creating Loan Account to which fund to be Transferred + final Integer toClientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2011", + String.valueOf(toOfficeId)); + Assertions.assertNotNull(toClientID); + + final Integer toSavingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE, assetAccount, + incomeAccount, expenseAccount, liabilityAccount); + Assertions.assertNotNull(toSavingsProductID); + + final Integer toSavingsID = this.savingsAccountHelper.applyForSavingsApplication(toClientID, toSavingsProductID, + ACCOUNT_TYPE_INDIVIDUAL); + Assertions.assertNotNull(toSavingsID); + + HashMap toSavingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, toSavingsID); + SavingsStatusChecker.verifySavingsIsPending(toSavingsStatusHashMap); + + toSavingsStatusHashMap = this.savingsAccountHelper.approveSavings(toSavingsID); + SavingsStatusChecker.verifySavingsIsApproved(toSavingsStatusHashMap); + + toSavingsStatusHashMap = this.savingsAccountHelper.activateSavings(toSavingsID); + SavingsStatusChecker.verifySavingsIsActive(toSavingsStatusHashMap); + + Integer fromOfficeId = officeHelper.createOffice("01 January 2011"); + Assertions.assertNotNull(fromOfficeId); + + // Creating Savings Account from which the Fund has to be Transferred + final Integer fromClientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2011", + String.valueOf(fromOfficeId)); + Assertions.assertNotNull(fromClientID); + + final Integer loanProductID = createLoanProduct(loanAssetAccount, loanIncomeAccount, loanExpenseAccount, overpaymentAccount); + Assertions.assertNotNull(loanProductID); + + final Integer loanID = applyForLoanApplication(fromClientID, loanProductID); + Assertions.assertNotNull(loanID); + + HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID); + LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap); + + loanStatusHashMap = this.loanTransactionHelper.approveLoan(LOAN_APPROVAL_DATE, loanID); + LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap); + + String loanDetails = this.loanTransactionHelper.getLoanDetails(this.requestSpec, this.responseSpec, loanID); + loanStatusHashMap = this.loanTransactionHelper.disburseLoanWithNetDisbursalAmount(LOAN_DISBURSAL_DATE, loanID, + JsonPath.from(loanDetails).get("netDisbursalAmount").toString()); + LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap); + + final Integer fromSavingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE, + assetAccount, incomeAccount, expenseAccount, liabilityAccount); + Assertions.assertNotNull(fromSavingsProductID); + + final Integer fromSavingsID = this.savingsAccountHelper.applyForSavingsApplication(fromClientID, fromSavingsProductID, + ACCOUNT_TYPE_INDIVIDUAL); + Assertions.assertNotNull(fromSavingsID); + + HashMap fromSavingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, fromSavingsID); + SavingsStatusChecker.verifySavingsIsPending(fromSavingsStatusHashMap); + + fromSavingsStatusHashMap = this.savingsAccountHelper.approveSavings(fromSavingsID); + SavingsStatusChecker.verifySavingsIsApproved(fromSavingsStatusHashMap); + + fromSavingsStatusHashMap = this.savingsAccountHelper.activateSavings(fromSavingsID); + SavingsStatusChecker.verifySavingsIsActive(fromSavingsStatusHashMap); + + final HashMap toSavingsSummaryBefore = this.savingsAccountHelper.getSavingsSummary(toSavingsID); + + Float fromSavingsBalance = Float.valueOf(MINIMUM_OPENING_BALANCE); + + Object accountTransfer = this.accountTransferHelper.invalidAccountTransfer(fromClientID, fromSavingsID, fromClientID, loanID, + INVALID_SAVINGS_ACCOUNT_TYPE, INVALID_LOAN_ACCOUNT_TYPE, ACCOUNT_TRANSFER_AMOUNT); + + } + + @Test + public void testTransferToNonExistentAccount() { + final Account assetAccount = this.accountHelper.createAssetAccount(); + final Account incomeAccount = this.accountHelper.createIncomeAccount(); + final Account expenseAccount = this.accountHelper.createExpenseAccount(); + final Account liabilityAccount = this.accountHelper.createLiabilityAccount(); + + final Account loanAssetAccount = this.accountHelper.createAssetAccount(); + final Account loanIncomeAccount = this.accountHelper.createIncomeAccount(); + final Account loanExpenseAccount = this.accountHelper.createExpenseAccount(); + final Account overpaymentAccount = this.accountHelper.createLiabilityAccount(); + + this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec); + this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec); + this.accountTransferHelper = new AccountTransferHelper(this.requestSpec, this.responseSpec); + + OfficeHelper officeHelper = new OfficeHelper(this.requestSpec, this.responseSpec); + Integer toOfficeId = officeHelper.createOffice("01 January 2011"); + Assertions.assertNotNull(toOfficeId); + + // Creating Loan Account to which fund to be Transferred + final Integer toClientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2011", + String.valueOf(toOfficeId)); + Assertions.assertNotNull(toClientID); + + final Integer toSavingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE, assetAccount, + incomeAccount, expenseAccount, liabilityAccount); + Assertions.assertNotNull(toSavingsProductID); + + final Integer toSavingsID = this.savingsAccountHelper.applyForSavingsApplication(toClientID, toSavingsProductID, + ACCOUNT_TYPE_INDIVIDUAL); + Assertions.assertNotNull(toSavingsID); + + HashMap toSavingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, toSavingsID); + SavingsStatusChecker.verifySavingsIsPending(toSavingsStatusHashMap); + + toSavingsStatusHashMap = this.savingsAccountHelper.approveSavings(toSavingsID); + SavingsStatusChecker.verifySavingsIsApproved(toSavingsStatusHashMap); + + toSavingsStatusHashMap = this.savingsAccountHelper.activateSavings(toSavingsID); + SavingsStatusChecker.verifySavingsIsActive(toSavingsStatusHashMap); + + Integer fromOfficeId = officeHelper.createOffice("01 January 2011"); + Assertions.assertNotNull(fromOfficeId); + + // Creating Savings Account from which the Fund has to be Transferred + final Integer fromClientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2011", + String.valueOf(fromOfficeId)); + Assertions.assertNotNull(fromClientID); + + final Integer loanProductID = createLoanProduct(loanAssetAccount, loanIncomeAccount, loanExpenseAccount, overpaymentAccount); + Assertions.assertNotNull(loanProductID); + + final Integer loanID = applyForLoanApplication(fromClientID, loanProductID); + Assertions.assertNotNull(loanID); + + HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID); + LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap); + + loanStatusHashMap = this.loanTransactionHelper.approveLoan(LOAN_APPROVAL_DATE, loanID); + LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap); + + String loanDetails = this.loanTransactionHelper.getLoanDetails(this.requestSpec, this.responseSpec, loanID); + loanStatusHashMap = this.loanTransactionHelper.disburseLoanWithNetDisbursalAmount(LOAN_DISBURSAL_DATE, loanID, + JsonPath.from(loanDetails).get("netDisbursalAmount").toString()); + LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap); + + final Integer fromSavingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE, + assetAccount, incomeAccount, expenseAccount, liabilityAccount); + Assertions.assertNotNull(fromSavingsProductID); + + final Integer fromSavingsID = this.savingsAccountHelper.applyForSavingsApplication(fromClientID, fromSavingsProductID, + ACCOUNT_TYPE_INDIVIDUAL); + Assertions.assertNotNull(fromSavingsID); + + HashMap fromSavingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, fromSavingsID); + SavingsStatusChecker.verifySavingsIsPending(fromSavingsStatusHashMap); + + fromSavingsStatusHashMap = this.savingsAccountHelper.approveSavings(fromSavingsID); + SavingsStatusChecker.verifySavingsIsApproved(fromSavingsStatusHashMap); + + fromSavingsStatusHashMap = this.savingsAccountHelper.activateSavings(fromSavingsID); + SavingsStatusChecker.verifySavingsIsActive(fromSavingsStatusHashMap); + + final HashMap toSavingsSummaryBefore = this.savingsAccountHelper.getSavingsSummary(toSavingsID); + + Float fromSavingsBalance = Float.valueOf(MINIMUM_OPENING_BALANCE); + Object accountTransfer = this.accountTransferHelper.nonExistentAccountTransfer(fromClientID, fromSavingsID, fromClientID, + INVALID_LOAN_ID, FROM_SAVINGS_ACCOUNT_TYPE, TO_LOAN_ACCOUNT_TYPE, ACCOUNT_TRANSFER_AMOUNT); + + } + + @Test + public void testFromSavingsToSavingsAccountTransferWithInvalidTransferDate() { + this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec); + this.accountTransferHelper = new AccountTransferHelper(this.requestSpec, this.responseSpec); + + final Account assetAccount = this.accountHelper.createAssetAccount(); + final Account incomeAccount = this.accountHelper.createIncomeAccount(); + final Account expenseAccount = this.accountHelper.createExpenseAccount(); + final Account liabilityAccount = this.accountHelper.createLiabilityAccount(); + + OfficeHelper officeHelper = new OfficeHelper(this.requestSpec, this.responseSpec); + Integer toOfficeId = officeHelper.createOffice("01 January 2011"); + Assertions.assertNotNull(toOfficeId); + + // Creating Savings Account to which fund to be Transferred + final Integer toClientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2011", + String.valueOf(toOfficeId)); + Assertions.assertNotNull(toClientID); + + final Integer toSavingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE, assetAccount, + incomeAccount, expenseAccount, liabilityAccount); + Assertions.assertNotNull(toSavingsProductID); + + final Integer toSavingsID = this.savingsAccountHelper.applyForSavingsApplication(toClientID, toSavingsProductID, + ACCOUNT_TYPE_INDIVIDUAL); + Assertions.assertNotNull(toSavingsProductID); + + HashMap toSavingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, toSavingsID); + SavingsStatusChecker.verifySavingsIsPending(toSavingsStatusHashMap); + + toSavingsStatusHashMap = this.savingsAccountHelper.approveSavings(toSavingsID); + SavingsStatusChecker.verifySavingsIsApproved(toSavingsStatusHashMap); + + toSavingsStatusHashMap = this.savingsAccountHelper.activateSavings(toSavingsID); + SavingsStatusChecker.verifySavingsIsActive(toSavingsStatusHashMap); + + final HashMap toSavingsSummaryBefore = this.savingsAccountHelper.getSavingsSummary(toSavingsID); + + Integer fromOfficeId = officeHelper.createOffice("01 January 2011"); + Assertions.assertNotNull(fromOfficeId); + + // Creating Savings Account from which the Fund has to be Transferred + final Integer fromClientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2011", + String.valueOf(fromOfficeId)); + Assertions.assertNotNull(fromClientID); + + final Integer fromSavingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE, + assetAccount, incomeAccount, expenseAccount, liabilityAccount); + Assertions.assertNotNull(fromSavingsProductID); + + final Integer fromSavingsID = this.savingsAccountHelper.applyForSavingsApplication(fromClientID, fromSavingsProductID, + ACCOUNT_TYPE_INDIVIDUAL); + Assertions.assertNotNull(fromSavingsID); + + HashMap fromSavingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, fromSavingsID); + SavingsStatusChecker.verifySavingsIsPending(fromSavingsStatusHashMap); + + fromSavingsStatusHashMap = this.savingsAccountHelper.approveSavings(fromSavingsID); + SavingsStatusChecker.verifySavingsIsApproved(fromSavingsStatusHashMap); + + fromSavingsStatusHashMap = this.savingsAccountHelper.activateSavings(fromSavingsID); + SavingsStatusChecker.verifySavingsIsActive(fromSavingsStatusHashMap); + + final HashMap fromSavingsSummaryBefore = this.savingsAccountHelper.getSavingsSummary(fromSavingsID); + + Float fromSavingsBalance = Float.valueOf(MINIMUM_OPENING_BALANCE); + Float toSavingsBalance = Float.valueOf(MINIMUM_OPENING_BALANCE); + + Object accountTransfer = this.accountTransferHelper.accountTransferWithInvalidDate(fromClientID, fromSavingsID, fromClientID, + toSavingsID, FROM_SAVINGS_ACCOUNT_TYPE, TO_SAVINGS_ACCOUNT_TYPE, ACCOUNT_TRANSFER_AMOUNT); + + } + private Integer createSavingsProduct(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, final String minOpenningBalance, final Account... accounts) { LOG.info("------------------------------CREATING NEW SAVINGS PRODUCT ---------------------------------------"); diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/savings/AccountTransferHelper.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/savings/AccountTransferHelper.java index 9368fb510..752ce199a 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/savings/AccountTransferHelper.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/savings/AccountTransferHelper.java @@ -19,6 +19,7 @@ package org.apache.fineract.integrationtests.common.savings; import com.google.gson.Gson; +import io.restassured.builder.ResponseSpecBuilder; import io.restassured.specification.RequestSpecification; import io.restassured.specification.ResponseSpecification; import java.util.HashMap; @@ -35,6 +36,7 @@ public class AccountTransferHelper { private static final String OFFICE_ID = "1"; private static final String TRANSFER_DESCRIPTION = "Transfer"; public static final String ACCOUNT_TRANSFER_DATE = "01 March 2013"; + public static final String ACCOUNT_TRANSFER_INVALID_DATE = "01 05 2013"; private String transferDate = ""; private String officeId = OFFICE_ID; @@ -86,6 +88,56 @@ public class AccountTransferHelper { accountTransferJSON, "savingsId"); } + public Object nonExistentAccountTransfer(final Integer fromClientId, final Integer fromAccountId, final Integer toClientId, + final Integer toAccountId, final String fromAccountType, final String toAccountType, final String transferAmount) { + LOG.info("--------------------------------ACCOUNT TRANSFER--------------------------------"); + this.responseSpec = new ResponseSpecBuilder().expectStatusCode(404).build(); + final String accountTransferJSON = new AccountTransferHelper(this.requestSpec, this.responseSpec) // + .withTransferOnDate(ACCOUNT_TRANSFER_DATE) // + .build(fromAccountId.toString(), fromClientId.toString(), toAccountId.toString(), toClientId.toString(), fromAccountType, + toAccountType, transferAmount); + + return Utils.performServerPost(this.requestSpec, this.responseSpec, ACCOUNT_TRANSFER_URL + "?" + Utils.TENANT_IDENTIFIER, + accountTransferJSON, "savingsId"); + } + + public Object insufficientBalanceAccountTransfer(final Integer fromClientId, final Integer fromAccountId, final Integer toClientId, + final Integer toAccountId, final String fromAccountType, final String toAccountType, final String transferAmount) { + LOG.info("--------------------------------ACCOUNT TRANSFER--------------------------------"); + this.responseSpec = new ResponseSpecBuilder().expectStatusCode(403).build(); + final String accountTransferJSON = new AccountTransferHelper(this.requestSpec, this.responseSpec) // + .withTransferOnDate(ACCOUNT_TRANSFER_DATE) // + .build(fromAccountId.toString(), fromClientId.toString(), toAccountId.toString(), toClientId.toString(), fromAccountType, + toAccountType, transferAmount); + + return Utils.performServerPost(this.requestSpec, this.responseSpec, ACCOUNT_TRANSFER_URL + "?" + Utils.TENANT_IDENTIFIER, + accountTransferJSON, "savingsId"); + } + + public Object invalidAccountTransfer(final Integer fromClientId, final Integer fromAccountId, final Integer toClientId, + final Integer toAccountId, final String fromAccountType, final String toAccountType, final String transferAmount) { + LOG.info("--------------------------------ACCOUNT TRANSFER--------------------------------"); + this.responseSpec = new ResponseSpecBuilder().expectStatusCode(400).build(); + final String accountTransferJSON = new AccountTransferHelper(this.requestSpec, this.responseSpec) // + .withTransferOnDate(ACCOUNT_TRANSFER_DATE) // + .build(fromAccountId.toString(), fromClientId.toString(), toAccountId.toString(), toClientId.toString(), fromAccountType, + toAccountType, transferAmount); + + return Utils.performServerPost(this.requestSpec, this.responseSpec, ACCOUNT_TRANSFER_URL + "?" + Utils.TENANT_IDENTIFIER, + accountTransferJSON, "savingsId"); + } + + public Object accountTransferWithInvalidDate(final Integer fromClientId, final Integer fromAccountId, final Integer toClientId, + final Integer toAccountId, final String fromAccountType, final String toAccountType, final String transferAmount) { + LOG.info("--------------------------------ACCOUNT TRANSFER--------------------------------"); + final String accountTransferJSON = new AccountTransferHelper(this.requestSpec, this.responseSpec) // + .withTransferOnDate(ACCOUNT_TRANSFER_INVALID_DATE) // + .build(fromAccountId.toString(), fromClientId.toString(), toAccountId.toString(), toClientId.toString(), fromAccountType, + toAccountType, transferAmount); + return Utils.performServerPost(this.requestSpec, this.responseSpec, ACCOUNT_TRANSFER_URL + "?" + Utils.TENANT_IDENTIFIER, + accountTransferJSON, "savingsId"); + } + public Integer refundLoanByTransfer(final String date, final Integer fromClientId, final Integer fromAccountId, final Integer toClientId, final Integer toAccountId, final String fromAccountType, final String toAccountType, final String transferAmount) {