From 9c4ef176ec991c6d4a43f9bf8396932ff9ef94bc Mon Sep 17 00:00:00 2001 From: Vishwa1311 Date: Fri, 4 Apr 2014 19:42:28 +0530 Subject: [PATCH] [MIFOSX-1047] Updated JUnit Test Cases for Scheduler Jobs --- .../integrationtests/AccountTransferTest.java | 6 +- .../AccountingScenarioIntegrationTest.java | 2 +- .../ClientLoanIntegrationTest.java | 2 +- .../GroupLoanIntegrationTest.java | 2 +- ...iveInterestAndWriteOffIntegrationTest.java | 2 +- ...anWithdrawnByApplicantIntegrationTest.java | 2 +- .../SchedulerJobsTestResults.java | 130 ++++++++++++++++++ .../common/charges/ChargesHelper.java | 15 +- .../loans/LoanApplicationTestBuilder.java | 5 +- .../common/loans/LoanProductTestBuilder.java | 4 +- .../common/loans/LoanTransactionHelper.java | 29 +++- 11 files changed, 184 insertions(+), 15 deletions(-) diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/AccountTransferTest.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/AccountTransferTest.java index 2a0da760a..76743ed27 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/AccountTransferTest.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/AccountTransferTest.java @@ -45,8 +45,8 @@ public class AccountTransferTest { 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"; + public static final String LOAN_APPROVAL_DATE = "01 March 2013"; + public static final String LOAN_DISBURSAL_DATE = "01 March 2013"; private ResponseSpecification responseSpec; private RequestSpecification requestSpec; @@ -330,7 +330,7 @@ public class AccountTransferTest { .withInterestCalculationPeriodTypeSameAsRepaymentPeriod() // .withExpectedDisbursementDate("10 January 2013") // .withSubmittedOnDate("10 January 2013") // - .build(clientID.toString(), loanProductID.toString()); + .build(clientID.toString(), loanProductID.toString(), null); return this.loanTransactionHelper.getLoanId(loanApplicationJSON); } } \ No newline at end of file diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/AccountingScenarioIntegrationTest.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/AccountingScenarioIntegrationTest.java index ce79ea707..77f961a35 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/AccountingScenarioIntegrationTest.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/AccountingScenarioIntegrationTest.java @@ -198,7 +198,7 @@ public class AccountingScenarioIntegrationTest { .withInterestRatePerPeriod(this.LP_INTEREST_RATE).withInterestTypeAsFlatBalance() .withAmortizationTypeAsEqualPrincipalPayments().withInterestCalculationPeriodTypeSameAsRepaymentPeriod() .withExpectedDisbursementDate(this.EXPECTED_DISBURSAL_DATE).withSubmittedOnDate(this.LOAN_APPLICATION_SUBMISSION_DATE) - .withLoanType(this.INDIVIDUAL_LOAN).build(clientID.toString(), loanProductID.toString()); + .withLoanType(this.INDIVIDUAL_LOAN).build(clientID.toString(), loanProductID.toString(), null); return this.loanTransactionHelper.getLoanId(loanApplicationJSON); } diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/ClientLoanIntegrationTest.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/ClientLoanIntegrationTest.java index 1934eac5e..66f75f60d 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/ClientLoanIntegrationTest.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/ClientLoanIntegrationTest.java @@ -83,7 +83,7 @@ public class ClientLoanIntegrationTest { .withInterestCalculationPeriodTypeSameAsRepaymentPeriod() // .withExpectedDisbursementDate("20 September 2011") // .withSubmittedOnDate("20 September 2011") // - .build(clientID.toString(), loanProductID.toString()); + .build(clientID.toString(), loanProductID.toString(), null); return this.loanTransactionHelper.getLoanId(loanApplicationJSON); } diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/GroupLoanIntegrationTest.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/GroupLoanIntegrationTest.java index 3750af75f..f8e04c1e7 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/GroupLoanIntegrationTest.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/GroupLoanIntegrationTest.java @@ -85,7 +85,7 @@ public class GroupLoanIntegrationTest { .withInterestCalculationPeriodTypeSameAsRepaymentPeriod() // .withExpectedDisbursementDate("20 September 2011") // .withSubmittedOnDate("20 September 2011") // - .withLoanType("group").build(groupID.toString(), loanProductID.toString()); + .withLoanType("group").build(groupID.toString(), loanProductID.toString(), null); System.out.println(loanApplicationJSON); return this.loanTransactionHelper.getLoanId(loanApplicationJSON); } diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/LoanWithWaiveInterestAndWriteOffIntegrationTest.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/LoanWithWaiveInterestAndWriteOffIntegrationTest.java index faf3799f6..ff85ddf52 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/LoanWithWaiveInterestAndWriteOffIntegrationTest.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/LoanWithWaiveInterestAndWriteOffIntegrationTest.java @@ -129,7 +129,7 @@ public class LoanWithWaiveInterestAndWriteOffIntegrationTest { .withRepaymentFrequencyTypeAsMonths().withInterestRatePerPeriod(this.RATE_OF_INTEREST_PER_PERIOD) .withInterestTypeAsFlatBalance().withAmortizationTypeAsEqualInstallments() .withInterestCalculationPeriodTypeSameAsRepaymentPeriod().withExpectedDisbursementDate(this.EXPECTED_DISBURSAL_DATE) - .withSubmittedOnDate(this.LOAN_APPLICATION_SUBMISSION_DATE).build(clientID.toString(), loanProductID.toString()); + .withSubmittedOnDate(this.LOAN_APPLICATION_SUBMISSION_DATE).build(clientID.toString(), loanProductID.toString(), null); return this.loanTransactionHelper.getLoanId(loanApplicationJSON); } } diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/LoanWithdrawnByApplicantIntegrationTest.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/LoanWithdrawnByApplicantIntegrationTest.java index 78c77b84b..a1998bf5f 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/LoanWithdrawnByApplicantIntegrationTest.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/LoanWithdrawnByApplicantIntegrationTest.java @@ -53,7 +53,7 @@ public class LoanWithdrawnByApplicantIntegrationTest { final String loanApplication = new LoanApplicationTestBuilder().withPrincipal("5000").withLoanTermFrequency("5") .withLoanTermFrequencyAsMonths().withNumberOfRepayments("5").withRepaymentEveryAfter("1") .withRepaymentFrequencyTypeAsMonths().withInterestRatePerPeriod("2").withExpectedDisbursementDate("04 April 2012") - .withSubmittedOnDate("02 April 2012").build(clientID.toString(), loanProductID.toString()); + .withSubmittedOnDate("02 April 2012").build(clientID.toString(), loanProductID.toString(), null); return this.loanTransactionHelper.getLoanId(loanApplication); } } diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/SchedulerJobsTestResults.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/SchedulerJobsTestResults.java index fc0d0758b..59d007e82 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/SchedulerJobsTestResults.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/SchedulerJobsTestResults.java @@ -16,6 +16,10 @@ import org.mifosplatform.integrationtests.common.CommonConstants; import org.mifosplatform.integrationtests.common.SchedulerJobHelper; 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.SavingsAccountHelper; import org.mifosplatform.integrationtests.common.savings.SavingsProductHelper; import org.mifosplatform.integrationtests.common.savings.SavingsStatusChecker; @@ -34,6 +38,7 @@ public class SchedulerJobsTestResults { private ResponseSpecification responseSpecForSchedulerJob; private SchedulerJobHelper schedulerJobHelper; private SavingsAccountHelper savingsAccountHelper; + private LoanTransactionHelper loanTransactionHelper; @Before public void setup() { @@ -174,6 +179,97 @@ public class SchedulerJobsTestResults { summaryAfter.get("accountBalance")); } + @Test + public void testTransferFeeForLoansFromSavingsJobOutcome() throws InterruptedException { + this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec); + this.schedulerJobHelper = new SchedulerJobHelper(this.requestSpec, this.responseSpec); + this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec); + + final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec); + Assert.assertNotNull(clientID); + + final Integer savingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, + ClientSavingsIntegrationTest.MINIMUM_OPENING_BALANCE); + Assert.assertNotNull(savingsProductID); + + final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(clientID, savingsProductID, + ClientSavingsIntegrationTest.ACCOUNT_TYPE_INDIVIDUAL); + Assert.assertNotNull(savingsProductID); + + HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsId); + SavingsStatusChecker.verifySavingsIsPending(savingsStatusHashMap); + + savingsStatusHashMap = this.savingsAccountHelper.approveSavings(savingsId); + SavingsStatusChecker.verifySavingsIsApproved(savingsStatusHashMap); + + savingsStatusHashMap = this.savingsAccountHelper.activateSavings(savingsId); + SavingsStatusChecker.verifySavingsIsActive(savingsStatusHashMap); + + final Integer loanProductID = createLoanProduct(); + Assert.assertNotNull(loanProductID); + + final Integer loanID = applyForLoanApplication(clientID, loanProductID, savingsId); + Assert.assertNotNull(loanID); + + HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID); + LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap); + + loanStatusHashMap = this.loanTransactionHelper.approveLoan(AccountTransferTest.LOAN_APPROVAL_DATE, loanID); + LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap); + + Integer specifiedDueDateChargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec, + ChargesHelper.getLoanSpecifiedDueDateWithAccountTransferJSON()); + Assert.assertNotNull(specifiedDueDateChargeId); + + this.loanTransactionHelper.addChargesForLoan(loanID, + LoanTransactionHelper.getSpecifiedDueDateChargesForLoanAsJSON(specifiedDueDateChargeId.toString())); + ArrayList chargesPendingState = this.loanTransactionHelper.getLoanCharges(loanID); + Assert.assertEquals(1, chargesPendingState.size()); + + loanStatusHashMap = this.loanTransactionHelper.disburseLoan(AccountTransferTest.LOAN_DISBURSAL_DATE, loanID); + LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap); + + ArrayList allSchedulerJobsData = this.schedulerJobHelper.getAllSchedulerJobs(this.requestSpec, this.responseSpec); + Assert.assertNotNull(allSchedulerJobsData); + + Integer jobId = (Integer) allSchedulerJobsData.get(6).get("jobId"); + + final HashMap summaryBefore = this.savingsAccountHelper.getSavingsSummary(savingsId); + + // Executing Scheduler Job + this.schedulerJobHelper.runSchedulerJob(this.requestSpec, this.responseSpecForSchedulerJob, jobId.toString()); + ArrayList jobHistoryData = this.schedulerJobHelper.getSchedulerJobHistory(this.requestSpec, this.responseSpec, + jobId.toString()); + + // Retrieving Scheduler Job by ID + HashMap schedulerJob = this.schedulerJobHelper.getSchedulerJobById(this.requestSpec, this.responseSpec, jobId.toString()); + Assert.assertNotNull(schedulerJob); + + // Waiting for Job to complete + while ((Boolean) schedulerJob.get("currentlyRunning") == true) { + Thread.sleep(120000); + schedulerJob = this.schedulerJobHelper.getSchedulerJobById(this.requestSpec, this.responseSpec, jobId.toString()); + Assert.assertNotNull(schedulerJob); + System.out.println("Job is Still Running"); + } + + // Verifying the Status of the Recently executed Scheduler Job + Assert.assertEquals("Verifying Last Scheduler Job Status", "success", + jobHistoryData.get(((jobHistoryData.size()) - 1)).get("status")); + + final HashMap summaryAfter = this.savingsAccountHelper.getSavingsSummary(savingsId); + + final HashMap chargeData = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, specifiedDueDateChargeId); + + Float chargeAmount = (Float) chargeData.get("amount"); + + final Float balance = (Float) summaryBefore.get("accountBalance") - chargeAmount; + + Assert.assertEquals("Verifying the Balance after running Transfer Fee for Loans from Savings", balance, + (Float) summaryAfter.get("accountBalance")); + + } + private Integer createSavingsProduct(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, final String minOpenningBalance) { System.out.println("------------------------------CREATING NEW SAVINGS PRODUCT ---------------------------------------"); @@ -185,4 +281,38 @@ public class SchedulerJobsTestResults { .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("12,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, final Integer savingsID) { + System.out.println("--------------------------------APPLYING FOR LOAN APPLICATION--------------------------------"); + final String loanApplicationJSON = new LoanApplicationTestBuilder() // + .withPrincipal("12,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(), savingsID.toString()); + return this.loanTransactionHelper.getLoanId(loanApplicationJSON); + } } diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/charges/ChargesHelper.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/charges/ChargesHelper.java index b7d456941..601d9d784 100755 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/charges/ChargesHelper.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/charges/ChargesHelper.java @@ -118,6 +118,7 @@ public class ChargesHelper { public static String getLoanDisbursementJSON() { final HashMap map = populateDefaultsForLoan(); map.put("chargeTimeType", CHARGE_DISBURSEMENT_FEE); + map.put("chargePaymentMode", ChargesHelper.CHARGE_PAYMENT_MODE_REGULAR); String chargesCreateJson = new Gson().toJson(map); System.out.println(chargesCreateJson); return chargesCreateJson; @@ -126,15 +127,27 @@ public class ChargesHelper { public static String getLoanSpecifiedDueDateJSON() { final HashMap map = populateDefaultsForLoan(); map.put("chargeTimeType", CHARGE_SPECIFIED_DUE_DATE); + map.put("chargePaymentMode", ChargesHelper.CHARGE_PAYMENT_MODE_REGULAR); map.put("penalty", ChargesHelper.penalty); String chargesCreateJson = new Gson().toJson(map); System.out.println(chargesCreateJson); return chargesCreateJson; } + + public static String getLoanSpecifiedDueDateWithAccountTransferJSON() { + final HashMap map = populateDefaultsForLoan(); + map.put("chargeTimeType", CHARGE_SPECIFIED_DUE_DATE); + map.put("penalty", ChargesHelper.penalty); + map.put("chargePaymentMode", ChargesHelper.CHARGE_PAYMENT_MODE_ACCOUNT_TRANSFER); + String chargesCreateJson = new Gson().toJson(map); + System.out.println(chargesCreateJson); + return chargesCreateJson; + } public static String getLoanInstallmentFeeJSON() { final HashMap map = populateDefaultsForLoan(); map.put("chargeTimeType", CHARGE_INSTALLMENT_FEE); + map.put("chargePaymentMode", ChargesHelper.CHARGE_PAYMENT_MODE_REGULAR); map.put("penalty", ChargesHelper.penalty); String chargesCreateJson = new Gson().toJson(map); System.out.println(chargesCreateJson); @@ -144,6 +157,7 @@ public class ChargesHelper { public static String getLoanOverdueFeeJSON() { final HashMap map = populateDefaultsForLoan(); map.put("penalty", ChargesHelper.penalty); + map.put("chargePaymentMode", ChargesHelper.CHARGE_PAYMENT_MODE_REGULAR); map.put("chargeTimeType", CHARGE_OVERDUE_INSTALLMENT_FEE); String chargesCreateJson = new Gson().toJson(map); System.out.println(chargesCreateJson); @@ -156,7 +170,6 @@ public class ChargesHelper { map.put("amount", ChargesHelper.amount); map.put("chargeAppliesTo", ChargesHelper.CHARGE_APPLIES_TO_LOAN); map.put("chargeCalculationType", ChargesHelper.CHARGE_CALCULATION_TYPE_FLAT); - map.put("chargePaymentMode", ChargesHelper.CHARGE_PAYMENT_MODE_REGULAR); map.put("currencyCode", ChargesHelper.currencyCode); map.put("locale", CommonConstants.locale); map.put("monthDayFormat", ChargesHelper.monthDayFormat); diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/loans/LoanApplicationTestBuilder.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/loans/LoanApplicationTestBuilder.java index a45684e7e..247a257a3 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/loans/LoanApplicationTestBuilder.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/loans/LoanApplicationTestBuilder.java @@ -33,7 +33,7 @@ public class LoanApplicationTestBuilder { private String submittedOnDate = ""; private String loanType = "individual"; - public String build(final String ID, final String loanProductId) { + public String build(final String ID, final String loanProductId, final String savingsID) { final HashMap map = new HashMap(); map.put("dateFormat", "dd MMMM yyyy"); @@ -58,6 +58,9 @@ public class LoanApplicationTestBuilder { map.put("expectedDisbursementDate", this.expectedDisbursmentDate); map.put("submittedOnDate", this.submittedOnDate); map.put("loanType", this.loanType); + if (savingsID != null) { + map.put("linkAccountId", savingsID); + } return new Gson().toJson(map); } diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/loans/LoanProductTestBuilder.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/loans/LoanProductTestBuilder.java index 4c7ad4b6d..e2816db65 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/loans/LoanProductTestBuilder.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/loans/LoanProductTestBuilder.java @@ -12,7 +12,7 @@ public class LoanProductTestBuilder { private static final String LOCALE = "en_GB"; private static final String DIGITS_AFTER_DECIMAL = "2"; - private static final String INR = "INR"; + private static final String USD = "USD"; private static final String DAYS = "0"; private static final String WEEK = "1"; private static final String MONTHS = "2"; @@ -43,7 +43,7 @@ public class LoanProductTestBuilder { private String inArrearsTolerance = "0"; private final String transactionProcessingStrategy = MIFOS_STANDARD_STRATEGY; private String accountingRule = NONE; - private final String currencyCode = INR; + private final String currencyCode = USD; private String amortizationType = EQUAL_INSTALLMENTS; private String minPrincipal = "1000.00"; private String maxPrincipal = "100000.00"; 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 d778636e7..301648438 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,14 +47,18 @@ 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) { + + 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 ArrayList getLoanCharges(final Integer loanId) { + final String GET_LOAN_CHARGES_URL = "/mifosng-provider/api/v1/loans/" + loanId + "/charges?" + Utils.TENANT_IDENTIFIER; + return Utils.performServerGet(requestSpec, responseSpec, GET_LOAN_CHARGES_URL, ""); + } + public HashMap approveLoan(final String approvalDate, final Integer loanID) { return performLoanTransaction(createLoanOperationURL(APPROVE_LOAN_COMMAND, loanID), getApproveLoanAsJSON(approvalDate)); } @@ -94,6 +98,13 @@ public class LoanTransactionHelper { getWithdrawLoanApplicationBodyAsJSON(date)); } + public Integer addChargesForLoan(final Integer loanId, final String request) { + System.out.println("--------------------------------- ADD CHARGES FOR LOAN --------------------------------"); + final String ADD_CHARGES_URL = "/mifosng-provider/api/v1/loans/" + loanId + "/charges"; + final HashMap response = Utils.performServerPost(requestSpec, responseSpec, ADD_CHARGES_URL, request, ""); + return (Integer) response.get("resourceId"); + } + private String getDisburseLoanAsJSON(final String actualDisbursementDate) { final HashMap map = new HashMap(); map.put("locale", "en"); @@ -151,6 +162,18 @@ public class LoanTransactionHelper { } + public static String getSpecifiedDueDateChargesForLoanAsJSON(final String chargeId) { + final HashMap map = new HashMap(); + map.put("locale", "en_GB"); + map.put("dateFormat", "dd MMMM yyyy"); + map.put("amount", "100"); + map.put("dueDate", "12 January 2013"); + map.put("chargeId", chargeId); + String json = new Gson().toJson(map); + System.out.println(json); + return json; + } + public String getLoanCalculationBodyAsJSON(final String productID) { final HashMap map = new HashMap(); map.put("dateFormat", "dd MMMM yyyy");