diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/AccountTransferTest.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/AccountTransferTest.java new file mode 100644 index 000000000..2a0da760a --- /dev/null +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/AccountTransferTest.java @@ -0,0 +1,336 @@ +package org.mifosplatform.integrationtests; + +import static org.junit.Assert.assertEquals; + +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.HashMap; +import java.util.List; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.mifosplatform.integrationtests.common.ClientHelper; +import org.mifosplatform.integrationtests.common.CommonConstants; +import org.mifosplatform.integrationtests.common.Utils; +import org.mifosplatform.integrationtests.common.charges.ChargesHelper; +import org.mifosplatform.integrationtests.common.loans.LoanApplicationTestBuilder; +import org.mifosplatform.integrationtests.common.loans.LoanProductTestBuilder; +import org.mifosplatform.integrationtests.common.loans.LoanStatusChecker; +import org.mifosplatform.integrationtests.common.loans.LoanTransactionHelper; +import org.mifosplatform.integrationtests.common.savings.AccountTransferHelper; +import org.mifosplatform.integrationtests.common.savings.SavingsAccountHelper; +import org.mifosplatform.integrationtests.common.savings.SavingsProductHelper; +import org.mifosplatform.integrationtests.common.savings.SavingsStatusChecker; + +import com.jayway.restassured.builder.RequestSpecBuilder; +import com.jayway.restassured.builder.ResponseSpecBuilder; +import com.jayway.restassured.http.ContentType; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; + +/** + * JUnit Test Cases for Account Transfer for. + */ +@SuppressWarnings({ "rawtypes", "unused" }) +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_AMOUNT_ADJUST = "3000.0"; + public static final String FROM_LOAN_ACCOUNT_TYPE = "1"; + public static final String FROM_SAVINGS_ACCOUNT_TYPE = "2"; + public static final String TO_LOAN_ACCOUNT_TYPE = "1"; + public static final String TO_SAVINGS_ACCOUNT_TYPE = "2"; + + private final String LOAN_APPROVAL_DATE = "01 March 2013"; + private final String LOAN_DISBURSAL_DATE = "01 March 2013"; + + private ResponseSpecification responseSpec; + private RequestSpecification requestSpec; + private SavingsAccountHelper savingsAccountHelper; + private AccountTransferHelper accountTransferHelper; + private LoanTransactionHelper loanTransactionHelper; + + Float TRANSFER_AMOUNT = new Float(ACCOUNT_TRANSFER_AMOUNT); + Float TRANSFER_AMOUNT_ADJUST = new Float(ACCOUNT_TRANSFER_AMOUNT_ADJUST); + + @Before + public void setup() { + Utils.initializeRESTAssured(); + this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build(); + this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); + this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); + } + + @Test + public void testFromSavingsToSavingsAccountTransfer() { + this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec); + this.accountTransferHelper = new AccountTransferHelper(this.requestSpec, this.responseSpec); + + // Creating Savings Account to which fund to be Transferred + final Integer toClientID = ClientHelper.createClient(this.requestSpec, this.responseSpec); + Assert.assertNotNull(toClientID); + + final Integer toSavingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE); + Assert.assertNotNull(toSavingsProductID); + + final Integer toSavingsID = this.savingsAccountHelper.applyForSavingsApplication(toClientID, toSavingsProductID, + ACCOUNT_TYPE_INDIVIDUAL); + Assert.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); + + // Creating Savings Account from which the Fund has to be Transferred + final Integer fromClientID = ClientHelper.createClient(this.requestSpec, this.responseSpec); + Assert.assertNotNull(fromClientID); + + final Integer fromSavingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE); + Assert.assertNotNull(fromSavingsProductID); + + final Integer fromSavingsID = this.savingsAccountHelper.applyForSavingsApplication(fromClientID, fromSavingsProductID, + ACCOUNT_TYPE_INDIVIDUAL); + Assert.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 = new Float(MINIMUM_OPENING_BALANCE); + Float toSavingsBalance = new Float(MINIMUM_OPENING_BALANCE); + + this.accountTransferHelper.accountTransfer(fromClientID, fromSavingsID, toClientID, toSavingsID, FROM_SAVINGS_ACCOUNT_TYPE, + TO_SAVINGS_ACCOUNT_TYPE, ACCOUNT_TRANSFER_AMOUNT); + + fromSavingsBalance -= new Float(ACCOUNT_TRANSFER_AMOUNT); + toSavingsBalance += new Float(ACCOUNT_TRANSFER_AMOUNT); + + HashMap fromSavingsSummaryAfter = this.savingsAccountHelper.getSavingsSummary(fromSavingsID); + assertEquals("Verifying From Savings Account Balance after Account Transfer", fromSavingsBalance, + fromSavingsSummaryAfter.get("accountBalance")); + + HashMap toSavingsSummaryAfter = this.savingsAccountHelper.getSavingsSummary(toSavingsID); + assertEquals("Verifying To Savings Account Balance after Account Transfer", toSavingsBalance, + toSavingsSummaryAfter.get("accountBalance")); + } + + @Test + public void testFromSavingsToLoanAccountTransfer() { + this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec); + this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec); + this.accountTransferHelper = new AccountTransferHelper(this.requestSpec, this.responseSpec); + + // Creating Loan Account to which Fund to be Transferred. + final Integer toClientID = ClientHelper.createClient(this.requestSpec, this.responseSpec); + Assert.assertNotNull(toClientID); + + final Integer toLoanProductID = createLoanProduct(); + Assert.assertNotNull(toLoanProductID); + + final Integer toLoanID = applyForLoanApplication(toClientID, toLoanProductID); + Assert.assertNotNull(toLoanID); + + HashMap toLoanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, toLoanID); + LoanStatusChecker.verifyLoanIsPending(toLoanStatusHashMap); + + toLoanStatusHashMap = this.loanTransactionHelper.approveLoan(LOAN_APPROVAL_DATE, toLoanID); + LoanStatusChecker.verifyLoanIsApproved(toLoanStatusHashMap); + + toLoanStatusHashMap = this.loanTransactionHelper.disburseLoan(LOAN_DISBURSAL_DATE, toLoanID); + LoanStatusChecker.verifyLoanIsActive(toLoanStatusHashMap); + + // Creating Savings Account from which Fund to be Transferred + final Integer fromClientID = ClientHelper.createClient(this.requestSpec, this.responseSpec); + Assert.assertNotNull(fromClientID); + + final Integer fromSavingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE); + Assert.assertNotNull(fromSavingsProductID); + + final Integer fromSavingsID = this.savingsAccountHelper.applyForSavingsApplication(fromClientID, fromSavingsProductID, + ACCOUNT_TYPE_INDIVIDUAL); + Assert.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 = new Float(MINIMUM_OPENING_BALANCE); + + this.accountTransferHelper.accountTransfer(fromClientID, fromSavingsID, toClientID, toLoanID, FROM_SAVINGS_ACCOUNT_TYPE, + TO_LOAN_ACCOUNT_TYPE, ACCOUNT_TRANSFER_AMOUNT_ADJUST); + + fromSavingsBalance -= TRANSFER_AMOUNT_ADJUST; + + HashMap fromSavingsSummaryAfter = this.savingsAccountHelper.getSavingsSummary(fromSavingsID); + assertEquals("Verifying From Savings Account Balance after Account Transfer", fromSavingsBalance, + fromSavingsSummaryAfter.get("accountBalance")); + + HashMap toLoanSummaryAfter = this.loanTransactionHelper.getLoanSummary(requestSpec, responseSpec, toLoanID); + assertEquals("Verifying To Loan Repayment Amount after Account Transfer", TRANSFER_AMOUNT_ADJUST, toLoanSummaryAfter.get("totalRepayment")); + } + + @Test + public void testFromLoanToSavingsAccountTransfer() { + this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec); + this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec); + this.accountTransferHelper = new AccountTransferHelper(this.requestSpec, this.responseSpec); + + // Creating Savings Account to which Fund to be Transferred + final Integer toClientID = ClientHelper.createClient(this.requestSpec, this.responseSpec); + Assert.assertNotNull(toClientID); + + final Integer toSavingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE); + Assert.assertNotNull(toSavingsProductID); + + final Integer toSavingsID = this.savingsAccountHelper.applyForSavingsApplication(toClientID, toSavingsProductID, + ACCOUNT_TYPE_INDIVIDUAL); + Assert.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); + + // Creating Loan Account to or from which Fund to be Transferred. + final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec); + Assert.assertNotNull(clientID); + + final Integer loanProductID = createLoanProduct(); + Assert.assertNotNull(loanProductID); + + final Integer loanID = applyForLoanApplication(clientID, loanProductID); + Assert.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); + + loanStatusHashMap = this.loanTransactionHelper.disburseLoan(LOAN_DISBURSAL_DATE, loanID); + LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap); + + // Creating Savings Account from which Fund to be Transferred + final Integer fromClientId = ClientHelper.createClient(this.requestSpec, this.responseSpec); + Assert.assertNotNull(fromClientId); + + final Integer fromSavingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE); + Assert.assertNotNull(fromSavingsProductID); + + final Integer fromSavingsID = this.savingsAccountHelper.applyForSavingsApplication(fromClientId, fromSavingsProductID, + ACCOUNT_TYPE_INDIVIDUAL); + Assert.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 = new Float(MINIMUM_OPENING_BALANCE); + + this.accountTransferHelper.accountTransfer(fromClientId, fromSavingsID, clientID, loanID, FROM_SAVINGS_ACCOUNT_TYPE, + TO_LOAN_ACCOUNT_TYPE, ACCOUNT_TRANSFER_AMOUNT); + + fromSavingsBalance -= TRANSFER_AMOUNT; + + HashMap fromSavingsSummaryAfter = this.savingsAccountHelper.getSavingsSummary(fromSavingsID); + + // Verifying fromSavings Account Balance after Account Transfer + assertEquals("Verifying From Savings Account Balance after Account Transfer", fromSavingsBalance, + fromSavingsSummaryAfter.get("accountBalance")); + + Float toSavingsBalance = new Float(MINIMUM_OPENING_BALANCE); + + this.accountTransferHelper.accountTransfer(clientID, loanID, toClientID, toSavingsID, FROM_LOAN_ACCOUNT_TYPE, + TO_SAVINGS_ACCOUNT_TYPE, ACCOUNT_TRANSFER_AMOUNT_ADJUST); + + toSavingsBalance += TRANSFER_AMOUNT_ADJUST; + + HashMap toSavingsSummaryAfter = this.savingsAccountHelper.getSavingsSummary(toSavingsID); + + // Verifying toSavings Account Balance after Account Transfer + assertEquals("Verifying From Savings Account Balance after Account Transfer", toSavingsBalance, + toSavingsSummaryAfter.get("accountBalance")); + } + + private Integer createSavingsProduct(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final String minOpenningBalance) { + System.out.println("------------------------------CREATING NEW SAVINGS PRODUCT ---------------------------------------"); + SavingsProductHelper savingsProductHelper = new SavingsProductHelper(); + final String savingsProductJSON = savingsProductHelper // + .withInterestCompoundingPeriodTypeAsDaily() // + .withInterestPostingPeriodTypeAsMonthly() // + .withInterestCalculationPeriodTypeAsDailyBalance() // + .withMinimumOpenningBalance(minOpenningBalance).build(); + return SavingsProductHelper.createSavingsProduct(savingsProductJSON, requestSpec, responseSpec); + } + + private Integer createLoanProduct() { + System.out.println("------------------------------CREATING NEW LOAN PRODUCT ---------------------------------------"); + final String loanProductJSON = new LoanProductTestBuilder() // + .withPrincipal("8,000.00") // + .withNumberOfRepayments("4") // + .withRepaymentAfterEvery("1") // + .withRepaymentTypeAsMonth() // + .withinterestRatePerPeriod("1") // + .withInterestRateFrequencyTypeAsMonths() // + .withAmortizationTypeAsEqualInstallments() // + .withInterestTypeAsDecliningBalance() // + .build(); + return this.loanTransactionHelper.getLoanProductId(loanProductJSON); + } + + private Integer applyForLoanApplication(final Integer clientID, final Integer loanProductID) { + System.out.println("--------------------------------APPLYING FOR LOAN APPLICATION--------------------------------"); + final String loanApplicationJSON = new LoanApplicationTestBuilder() // + .withPrincipal("8,000.00") // + .withLoanTermFrequency("4") // + .withLoanTermFrequencyAsMonths() // + .withNumberOfRepayments("4") // + .withRepaymentEveryAfter("1") // + .withRepaymentFrequencyTypeAsMonths() // + .withInterestRatePerPeriod("2") // + .withAmortizationTypeAsEqualInstallments() // + .withInterestTypeAsDecliningBalance() // + .withInterestCalculationPeriodTypeSameAsRepaymentPeriod() // + .withExpectedDisbursementDate("10 January 2013") // + .withSubmittedOnDate("10 January 2013") // + .build(clientID.toString(), loanProductID.toString()); + return this.loanTransactionHelper.getLoanId(loanApplicationJSON); + } +} \ No newline at end of file diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/ClientSavingsIntegrationTest.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/ClientSavingsIntegrationTest.java index 7e97db0f9..2c1093252 100755 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/ClientSavingsIntegrationTest.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/ClientSavingsIntegrationTest.java @@ -377,7 +377,7 @@ public class ClientSavingsIntegrationTest { this.savingsAccountHelper.payCharge((Integer) savingsChargeForPay.get("id"), savingsId, ((Float) savingsChargeForPay.get("amount")).toString(), sdf.format(cal.getTime())); - HashMap paidCharge = this.savingsAccountHelper.getSavingsChanrge(savingsId, (Integer) savingsChargeForPay.get("id")); + HashMap paidCharge = this.savingsAccountHelper.getSavingsCharge(savingsId, (Integer) savingsChargeForPay.get("id")); assertEquals(savingsChargeForPay.get("amount"), paidCharge.get("amountPaid")); final Integer monthlyFeechargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec, @@ -390,7 +390,7 @@ public class ClientSavingsIntegrationTest { HashMap savingsChargeForWaive = charges.get(1); this.savingsAccountHelper.waiveCharge((Integer) savingsChargeForWaive.get("id"), savingsId); - HashMap waiveCharge = this.savingsAccountHelper.getSavingsChanrge(savingsId, (Integer) savingsChargeForWaive.get("id")); + HashMap waiveCharge = this.savingsAccountHelper.getSavingsCharge(savingsId, (Integer) savingsChargeForWaive.get("id")); assertEquals(savingsChargeForWaive.get("amount"), waiveCharge.get("amountWaived")); } diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/GroupSavingsIntegrationTest.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/GroupSavingsIntegrationTest.java index bb2e6488a..0bb56215b 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/GroupSavingsIntegrationTest.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/GroupSavingsIntegrationTest.java @@ -416,7 +416,7 @@ public class GroupSavingsIntegrationTest { this.savingsAccountHelper.payCharge((Integer) savingsChargeForPay.get("id"), savingsId, ((Float) savingsChargeForPay.get("amount")).toString(), sdf.format(cal.getTime())); - HashMap paidCharge = this.savingsAccountHelper.getSavingsChanrge(savingsId, (Integer) savingsChargeForPay.get("id")); + HashMap paidCharge = this.savingsAccountHelper.getSavingsCharge(savingsId, (Integer) savingsChargeForPay.get("id")); assertEquals(savingsChargeForPay.get("amount"), paidCharge.get("amountPaid")); final Integer monthlyFeechargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec, @@ -429,7 +429,7 @@ public class GroupSavingsIntegrationTest { HashMap savingsChargeForWaive = charges.get(1); this.savingsAccountHelper.waiveCharge((Integer) savingsChargeForWaive.get("id"), savingsId); - HashMap waiveCharge = this.savingsAccountHelper.getSavingsChanrge(savingsId, (Integer) savingsChargeForWaive.get("id")); + HashMap waiveCharge = this.savingsAccountHelper.getSavingsCharge(savingsId, (Integer) savingsChargeForWaive.get("id")); assertEquals(savingsChargeForWaive.get("amount"), waiveCharge.get("amountWaived")); } diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/loans/LoanTransactionHelper.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/loans/LoanTransactionHelper.java index a6d06184e..d778636e7 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/loans/LoanTransactionHelper.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/loans/LoanTransactionHelper.java @@ -47,6 +47,13 @@ public class LoanTransactionHelper { final HashMap response = Utils.performServerGet(requestSpec, responseSpec, URL, "repaymentSchedule"); return (ArrayList) response.get("periods"); } + + public HashMap getLoanSummary(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final Integer loanID) { + final String URL = "/mifosng-provider/api/v1/loans/" + loanID + "?associations=all&tenantIdentifier=default"; + final HashMap response = Utils.performServerGet(requestSpec, responseSpec, URL, "summary"); + return response; + } public HashMap approveLoan(final String approvalDate, final Integer loanID) { return performLoanTransaction(createLoanOperationURL(APPROVE_LOAN_COMMAND, loanID), getApproveLoanAsJSON(approvalDate)); diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/savings/AccountTransferHelper.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/savings/AccountTransferHelper.java new file mode 100644 index 000000000..248bafe5a --- /dev/null +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/savings/AccountTransferHelper.java @@ -0,0 +1,68 @@ +package org.mifosplatform.integrationtests.common.savings; + +import java.util.HashMap; + +import org.mifosplatform.integrationtests.common.Utils; + +import com.google.gson.Gson; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; + +public class AccountTransferHelper { + + private static final String ACCOUNT_TRANSFER_URL = "/mifosng-provider/api/v1/accounttransfers"; + private static final String LOCALE = "en_GB"; + private static final String OFFICE_ID = "1"; + private static final String TRANSFER_DESCRIPTION = "Transfer"; + private static final String ACCOUNT_TRANSFER_DATE = "01 March 2013"; + + private String transferDate = ""; + private String officeId = OFFICE_ID; + private String transferDescription = TRANSFER_DESCRIPTION; + + private RequestSpecification requestSpec; + private ResponseSpecification responseSpec; + + public AccountTransferHelper(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { + this.requestSpec = requestSpec; + this.responseSpec = responseSpec; + } + + public String build(final String fromAccountId, final String fromClientId, final String toAccountId, final String toClientId, + final String fromAccountType, final String toAccountType, final String transferAmount) { + + final HashMap map = new HashMap(); + map.put("dateFormat", "dd MMMM yyyy"); + map.put("locale", LOCALE); + map.put("fromClientId", fromClientId); + map.put("fromAccountId", fromAccountId); + map.put("fromAccountType", fromAccountType); + map.put("fromOfficeId", this.officeId); + map.put("toClientId", toClientId); + map.put("toAccountId", toAccountId); + map.put("toAccountType", toAccountType); + map.put("toOfficeId", this.officeId); + map.put("transferDate", this.transferDate); + map.put("transferAmount", transferAmount); + map.put("transferDescription", this.transferDescription); + String savingsApplicationJSON = new Gson().toJson(map); + System.out.println(savingsApplicationJSON); + return savingsApplicationJSON; + } + + public AccountTransferHelper withTransferOnDate(final String savingsAccountTransferDate) { + this.transferDate = savingsAccountTransferDate; + return this; + } + + public Integer accountTransfer(final Integer fromClientId, final Integer fromAccountId, final Integer toClientId, + final Integer toAccountId, final String fromAccountType, final String toAccountType, final String transferAmount) { + System.out.println("--------------------------------ACCOUNT TRANSFER--------------------------------"); + 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"); + } +} \ No newline at end of file diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/savings/SavingsAccountHelper.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/savings/SavingsAccountHelper.java index 31872062a..665514157 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/savings/SavingsAccountHelper.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/savings/SavingsAccountHelper.java @@ -44,11 +44,11 @@ public class SavingsAccountHelper { this.requestSpec = requestSpec; this.responseSpec = responseSpec; } - - public static String getFutureDate(){ + + public static String getFutureDate() { SimpleDateFormat sdf = new SimpleDateFormat(CommonConstants.dateFormat); Calendar calendar = Calendar.getInstance(); - calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR)+1); + calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR) + 1); return sdf.format(calendar.getTime()); } @@ -83,12 +83,14 @@ public class SavingsAccountHelper { public HashMap rejectApplication(final Integer savingsID) { System.out.println("--------------------------------- REJECT SAVINGS APPLICATION -------------------------------"); - return performSavingApplicationActions(createSavingsOperationURL(REJECT_SAVINGS_COMMAND, savingsID), getRejectedSavingsAsJSON(CREATED_DATE_PLUS_ONE)); + return performSavingApplicationActions(createSavingsOperationURL(REJECT_SAVINGS_COMMAND, savingsID), + getRejectedSavingsAsJSON(CREATED_DATE_PLUS_ONE)); } - - public List rejectApplicationWithErrorCode(final Integer savingsId,final String date){ + + public List rejectApplicationWithErrorCode(final Integer savingsId, final String date) { System.out.println("--------------------------------- REJECT SAVINGS APPLICATION -------------------------------"); - return (List)performSavingActions(createSavingsOperationURL(REJECT_SAVINGS_COMMAND, savingsId), getRejectedSavingsAsJSON(date), CommonConstants.RESPONSE_ERROR); + return (List) performSavingActions(createSavingsOperationURL(REJECT_SAVINGS_COMMAND, savingsId), getRejectedSavingsAsJSON(date), + CommonConstants.RESPONSE_ERROR); } public HashMap withdrawApplication(final Integer savingsID) { @@ -107,7 +109,7 @@ public class SavingsAccountHelper { return performSavingApplicationActions(createSavingsOperationURL(CLOSE_SAVINGS_COMMAND, savingsID), getCloseAccountJSON()); } - public Object deleteSavingsApplication(final Integer savingsId,final String jsonAttributeToGetBack) { + public Object deleteSavingsApplication(final Integer savingsId, final String jsonAttributeToGetBack) { System.out.println("---------------------------------- DELETE SAVINGS APPLICATION ----------------------------------"); return Utils.performServerDelete(this.requestSpec, this.responseSpec, SAVINGS_ACCOUNT_URL + "/" + savingsId + "?" + Utils.TENANT_IDENTIFIER, jsonAttributeToGetBack); @@ -116,17 +118,16 @@ public class SavingsAccountHelper { public Object depositToSavingsAccount(final Integer savingsID, final String amount, String date, String jsonAttributeToGetback) { System.out.println("--------------------------------- SAVINGS TRANSACTION DEPOSIT --------------------------------"); - return performSavingActions(createSavingsTransactionURL(DEPOSIT_SAVINGS_COMMAND, savingsID), + return performSavingActions(createSavingsTransactionURL(DEPOSIT_SAVINGS_COMMAND, savingsID), getSavingsTransactionJSON(amount, date), jsonAttributeToGetback); } public Object withdrawalFromSavingsAccount(final Integer savingsId, final String amount, String date, String jsonAttributeToGetback) { System.out.println("\n--------------------------------- SAVINGS TRANSACTION WITHDRAWAL --------------------------------"); - return performSavingActions(createSavingsTransactionURL(WITHDRAW_SAVINGS_COMMAND, savingsId), + return performSavingActions(createSavingsTransactionURL(WITHDRAW_SAVINGS_COMMAND, savingsId), getSavingsTransactionJSON(amount, date), jsonAttributeToGetback); } - public Integer updateSavingsAccountTransaction(final Integer savingsId, final Integer transactionId, final String amount) { System.out.println("\n--------------------------------- MODIFY SAVINGS TRANSACTION --------------------------------"); return (Integer) performSavingActions(createAdjustTransactionURL(MODIFY_TRASACTION_COMMAND, savingsId, transactionId), @@ -187,7 +188,7 @@ public class SavingsAccountHelper { System.out.println(savingsAccountApproveJson); return savingsAccountApproveJson; } - + private String getRejectedSavingsAsJSON(final String rejectedOnDate) { final HashMap map = new HashMap(); map.put("locale", CommonConstants.locale); @@ -214,7 +215,7 @@ public class SavingsAccountHelper { final HashMap map = new HashMap(); map.put("locale", CommonConstants.locale); map.put("dateFormat", CommonConstants.dateFormat); - map.put("activatedOnDate", "10 January 2013"); + map.put("activatedOnDate", "01 March 2013"); String savingsAccountActivateJson = new Gson().toJson(map); System.out.println(savingsAccountActivateJson); return savingsAccountActivateJson; @@ -307,7 +308,7 @@ public class SavingsAccountHelper { return Utils.performServerGet(requestSpec, responseSpec, URL, ""); } - public HashMap getSavingsChanrge(final Integer savingsID, final Integer savingsChargeId) { + public HashMap getSavingsCharge(final Integer savingsID, final Integer savingsChargeId) { final String URL = SAVINGS_ACCOUNT_URL + "/" + savingsID + "/charges/" + savingsChargeId + "?" + Utils.TENANT_IDENTIFIER; return Utils.performServerGet(requestSpec, responseSpec, URL, ""); }