[MIFOSX-1047] Updated JUnit Test Cases for Scheduler Jobs

This commit is contained in:
Vishwa1311
2014-04-04 19:42:28 +05:30
parent 25c35b60d5
commit 9c4ef176ec
11 changed files with 184 additions and 15 deletions
@@ -45,8 +45,8 @@ public class AccountTransferTest {
public static final String TO_LOAN_ACCOUNT_TYPE = "1"; public static final String TO_LOAN_ACCOUNT_TYPE = "1";
public static final String TO_SAVINGS_ACCOUNT_TYPE = "2"; public static final String TO_SAVINGS_ACCOUNT_TYPE = "2";
private final String LOAN_APPROVAL_DATE = "01 March 2013"; public static final String LOAN_APPROVAL_DATE = "01 March 2013";
private final String LOAN_DISBURSAL_DATE = "01 March 2013"; public static final String LOAN_DISBURSAL_DATE = "01 March 2013";
private ResponseSpecification responseSpec; private ResponseSpecification responseSpec;
private RequestSpecification requestSpec; private RequestSpecification requestSpec;
@@ -330,7 +330,7 @@ public class AccountTransferTest {
.withInterestCalculationPeriodTypeSameAsRepaymentPeriod() // .withInterestCalculationPeriodTypeSameAsRepaymentPeriod() //
.withExpectedDisbursementDate("10 January 2013") // .withExpectedDisbursementDate("10 January 2013") //
.withSubmittedOnDate("10 January 2013") // .withSubmittedOnDate("10 January 2013") //
.build(clientID.toString(), loanProductID.toString()); .build(clientID.toString(), loanProductID.toString(), null);
return this.loanTransactionHelper.getLoanId(loanApplicationJSON); return this.loanTransactionHelper.getLoanId(loanApplicationJSON);
} }
} }
@@ -198,7 +198,7 @@ public class AccountingScenarioIntegrationTest {
.withInterestRatePerPeriod(this.LP_INTEREST_RATE).withInterestTypeAsFlatBalance() .withInterestRatePerPeriod(this.LP_INTEREST_RATE).withInterestTypeAsFlatBalance()
.withAmortizationTypeAsEqualPrincipalPayments().withInterestCalculationPeriodTypeSameAsRepaymentPeriod() .withAmortizationTypeAsEqualPrincipalPayments().withInterestCalculationPeriodTypeSameAsRepaymentPeriod()
.withExpectedDisbursementDate(this.EXPECTED_DISBURSAL_DATE).withSubmittedOnDate(this.LOAN_APPLICATION_SUBMISSION_DATE) .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); return this.loanTransactionHelper.getLoanId(loanApplicationJSON);
} }
@@ -83,7 +83,7 @@ public class ClientLoanIntegrationTest {
.withInterestCalculationPeriodTypeSameAsRepaymentPeriod() // .withInterestCalculationPeriodTypeSameAsRepaymentPeriod() //
.withExpectedDisbursementDate("20 September 2011") // .withExpectedDisbursementDate("20 September 2011") //
.withSubmittedOnDate("20 September 2011") // .withSubmittedOnDate("20 September 2011") //
.build(clientID.toString(), loanProductID.toString()); .build(clientID.toString(), loanProductID.toString(), null);
return this.loanTransactionHelper.getLoanId(loanApplicationJSON); return this.loanTransactionHelper.getLoanId(loanApplicationJSON);
} }
@@ -85,7 +85,7 @@ public class GroupLoanIntegrationTest {
.withInterestCalculationPeriodTypeSameAsRepaymentPeriod() // .withInterestCalculationPeriodTypeSameAsRepaymentPeriod() //
.withExpectedDisbursementDate("20 September 2011") // .withExpectedDisbursementDate("20 September 2011") //
.withSubmittedOnDate("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); System.out.println(loanApplicationJSON);
return this.loanTransactionHelper.getLoanId(loanApplicationJSON); return this.loanTransactionHelper.getLoanId(loanApplicationJSON);
} }
@@ -129,7 +129,7 @@ public class LoanWithWaiveInterestAndWriteOffIntegrationTest {
.withRepaymentFrequencyTypeAsMonths().withInterestRatePerPeriod(this.RATE_OF_INTEREST_PER_PERIOD) .withRepaymentFrequencyTypeAsMonths().withInterestRatePerPeriod(this.RATE_OF_INTEREST_PER_PERIOD)
.withInterestTypeAsFlatBalance().withAmortizationTypeAsEqualInstallments() .withInterestTypeAsFlatBalance().withAmortizationTypeAsEqualInstallments()
.withInterestCalculationPeriodTypeSameAsRepaymentPeriod().withExpectedDisbursementDate(this.EXPECTED_DISBURSAL_DATE) .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); return this.loanTransactionHelper.getLoanId(loanApplicationJSON);
} }
} }
@@ -53,7 +53,7 @@ public class LoanWithdrawnByApplicantIntegrationTest {
final String loanApplication = new LoanApplicationTestBuilder().withPrincipal("5000").withLoanTermFrequency("5") final String loanApplication = new LoanApplicationTestBuilder().withPrincipal("5000").withLoanTermFrequency("5")
.withLoanTermFrequencyAsMonths().withNumberOfRepayments("5").withRepaymentEveryAfter("1") .withLoanTermFrequencyAsMonths().withNumberOfRepayments("5").withRepaymentEveryAfter("1")
.withRepaymentFrequencyTypeAsMonths().withInterestRatePerPeriod("2").withExpectedDisbursementDate("04 April 2012") .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); return this.loanTransactionHelper.getLoanId(loanApplication);
} }
} }
@@ -16,6 +16,10 @@ import org.mifosplatform.integrationtests.common.CommonConstants;
import org.mifosplatform.integrationtests.common.SchedulerJobHelper; import org.mifosplatform.integrationtests.common.SchedulerJobHelper;
import org.mifosplatform.integrationtests.common.Utils; import org.mifosplatform.integrationtests.common.Utils;
import org.mifosplatform.integrationtests.common.charges.ChargesHelper; 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.SavingsAccountHelper;
import org.mifosplatform.integrationtests.common.savings.SavingsProductHelper; import org.mifosplatform.integrationtests.common.savings.SavingsProductHelper;
import org.mifosplatform.integrationtests.common.savings.SavingsStatusChecker; import org.mifosplatform.integrationtests.common.savings.SavingsStatusChecker;
@@ -34,6 +38,7 @@ public class SchedulerJobsTestResults {
private ResponseSpecification responseSpecForSchedulerJob; private ResponseSpecification responseSpecForSchedulerJob;
private SchedulerJobHelper schedulerJobHelper; private SchedulerJobHelper schedulerJobHelper;
private SavingsAccountHelper savingsAccountHelper; private SavingsAccountHelper savingsAccountHelper;
private LoanTransactionHelper loanTransactionHelper;
@Before @Before
public void setup() { public void setup() {
@@ -174,6 +179,97 @@ public class SchedulerJobsTestResults {
summaryAfter.get("accountBalance")); 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<HashMap> chargesPendingState = this.loanTransactionHelper.getLoanCharges(loanID);
Assert.assertEquals(1, chargesPendingState.size());
loanStatusHashMap = this.loanTransactionHelper.disburseLoan(AccountTransferTest.LOAN_DISBURSAL_DATE, loanID);
LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap);
ArrayList<HashMap> 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<HashMap> 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, private Integer createSavingsProduct(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
final String minOpenningBalance) { final String minOpenningBalance) {
System.out.println("------------------------------CREATING NEW SAVINGS PRODUCT ---------------------------------------"); System.out.println("------------------------------CREATING NEW SAVINGS PRODUCT ---------------------------------------");
@@ -185,4 +281,38 @@ public class SchedulerJobsTestResults {
.withMinimumOpenningBalance(minOpenningBalance).build(); .withMinimumOpenningBalance(minOpenningBalance).build();
return SavingsProductHelper.createSavingsProduct(savingsProductJSON, requestSpec, responseSpec); 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);
}
} }
@@ -118,6 +118,7 @@ public class ChargesHelper {
public static String getLoanDisbursementJSON() { public static String getLoanDisbursementJSON() {
final HashMap<String, Object> map = populateDefaultsForLoan(); final HashMap<String, Object> map = populateDefaultsForLoan();
map.put("chargeTimeType", CHARGE_DISBURSEMENT_FEE); map.put("chargeTimeType", CHARGE_DISBURSEMENT_FEE);
map.put("chargePaymentMode", ChargesHelper.CHARGE_PAYMENT_MODE_REGULAR);
String chargesCreateJson = new Gson().toJson(map); String chargesCreateJson = new Gson().toJson(map);
System.out.println(chargesCreateJson); System.out.println(chargesCreateJson);
return chargesCreateJson; return chargesCreateJson;
@@ -126,15 +127,27 @@ public class ChargesHelper {
public static String getLoanSpecifiedDueDateJSON() { public static String getLoanSpecifiedDueDateJSON() {
final HashMap<String, Object> map = populateDefaultsForLoan(); final HashMap<String, Object> map = populateDefaultsForLoan();
map.put("chargeTimeType", CHARGE_SPECIFIED_DUE_DATE); map.put("chargeTimeType", CHARGE_SPECIFIED_DUE_DATE);
map.put("chargePaymentMode", ChargesHelper.CHARGE_PAYMENT_MODE_REGULAR);
map.put("penalty", ChargesHelper.penalty); map.put("penalty", ChargesHelper.penalty);
String chargesCreateJson = new Gson().toJson(map); String chargesCreateJson = new Gson().toJson(map);
System.out.println(chargesCreateJson); System.out.println(chargesCreateJson);
return chargesCreateJson; return chargesCreateJson;
} }
public static String getLoanSpecifiedDueDateWithAccountTransferJSON() {
final HashMap<String, Object> 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() { public static String getLoanInstallmentFeeJSON() {
final HashMap<String, Object> map = populateDefaultsForLoan(); final HashMap<String, Object> map = populateDefaultsForLoan();
map.put("chargeTimeType", CHARGE_INSTALLMENT_FEE); map.put("chargeTimeType", CHARGE_INSTALLMENT_FEE);
map.put("chargePaymentMode", ChargesHelper.CHARGE_PAYMENT_MODE_REGULAR);
map.put("penalty", ChargesHelper.penalty); map.put("penalty", ChargesHelper.penalty);
String chargesCreateJson = new Gson().toJson(map); String chargesCreateJson = new Gson().toJson(map);
System.out.println(chargesCreateJson); System.out.println(chargesCreateJson);
@@ -144,6 +157,7 @@ public class ChargesHelper {
public static String getLoanOverdueFeeJSON() { public static String getLoanOverdueFeeJSON() {
final HashMap<String, Object> map = populateDefaultsForLoan(); final HashMap<String, Object> map = populateDefaultsForLoan();
map.put("penalty", ChargesHelper.penalty); map.put("penalty", ChargesHelper.penalty);
map.put("chargePaymentMode", ChargesHelper.CHARGE_PAYMENT_MODE_REGULAR);
map.put("chargeTimeType", CHARGE_OVERDUE_INSTALLMENT_FEE); map.put("chargeTimeType", CHARGE_OVERDUE_INSTALLMENT_FEE);
String chargesCreateJson = new Gson().toJson(map); String chargesCreateJson = new Gson().toJson(map);
System.out.println(chargesCreateJson); System.out.println(chargesCreateJson);
@@ -156,7 +170,6 @@ public class ChargesHelper {
map.put("amount", ChargesHelper.amount); map.put("amount", ChargesHelper.amount);
map.put("chargeAppliesTo", ChargesHelper.CHARGE_APPLIES_TO_LOAN); map.put("chargeAppliesTo", ChargesHelper.CHARGE_APPLIES_TO_LOAN);
map.put("chargeCalculationType", ChargesHelper.CHARGE_CALCULATION_TYPE_FLAT); map.put("chargeCalculationType", ChargesHelper.CHARGE_CALCULATION_TYPE_FLAT);
map.put("chargePaymentMode", ChargesHelper.CHARGE_PAYMENT_MODE_REGULAR);
map.put("currencyCode", ChargesHelper.currencyCode); map.put("currencyCode", ChargesHelper.currencyCode);
map.put("locale", CommonConstants.locale); map.put("locale", CommonConstants.locale);
map.put("monthDayFormat", ChargesHelper.monthDayFormat); map.put("monthDayFormat", ChargesHelper.monthDayFormat);
@@ -33,7 +33,7 @@ public class LoanApplicationTestBuilder {
private String submittedOnDate = ""; private String submittedOnDate = "";
private String loanType = "individual"; 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<String, String> map = new HashMap<String, String>(); final HashMap<String, String> map = new HashMap<String, String>();
map.put("dateFormat", "dd MMMM yyyy"); map.put("dateFormat", "dd MMMM yyyy");
@@ -58,6 +58,9 @@ public class LoanApplicationTestBuilder {
map.put("expectedDisbursementDate", this.expectedDisbursmentDate); map.put("expectedDisbursementDate", this.expectedDisbursmentDate);
map.put("submittedOnDate", this.submittedOnDate); map.put("submittedOnDate", this.submittedOnDate);
map.put("loanType", this.loanType); map.put("loanType", this.loanType);
if (savingsID != null) {
map.put("linkAccountId", savingsID);
}
return new Gson().toJson(map); return new Gson().toJson(map);
} }
@@ -12,7 +12,7 @@ public class LoanProductTestBuilder {
private static final String LOCALE = "en_GB"; private static final String LOCALE = "en_GB";
private static final String DIGITS_AFTER_DECIMAL = "2"; 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 DAYS = "0";
private static final String WEEK = "1"; private static final String WEEK = "1";
private static final String MONTHS = "2"; private static final String MONTHS = "2";
@@ -43,7 +43,7 @@ public class LoanProductTestBuilder {
private String inArrearsTolerance = "0"; private String inArrearsTolerance = "0";
private final String transactionProcessingStrategy = MIFOS_STANDARD_STRATEGY; private final String transactionProcessingStrategy = MIFOS_STANDARD_STRATEGY;
private String accountingRule = NONE; private String accountingRule = NONE;
private final String currencyCode = INR; private final String currencyCode = USD;
private String amortizationType = EQUAL_INSTALLMENTS; private String amortizationType = EQUAL_INSTALLMENTS;
private String minPrincipal = "1000.00"; private String minPrincipal = "1000.00";
private String maxPrincipal = "100000.00"; private String maxPrincipal = "100000.00";
@@ -47,14 +47,18 @@ public class LoanTransactionHelper {
final HashMap response = Utils.performServerGet(requestSpec, responseSpec, URL, "repaymentSchedule"); final HashMap response = Utils.performServerGet(requestSpec, responseSpec, URL, "repaymentSchedule");
return (ArrayList) response.get("periods"); return (ArrayList) response.get("periods");
} }
public HashMap getLoanSummary(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, public HashMap getLoanSummary(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, final Integer loanID) {
final Integer loanID) {
final String URL = "/mifosng-provider/api/v1/loans/" + loanID + "?associations=all&tenantIdentifier=default"; final String URL = "/mifosng-provider/api/v1/loans/" + loanID + "?associations=all&tenantIdentifier=default";
final HashMap response = Utils.performServerGet(requestSpec, responseSpec, URL, "summary"); final HashMap response = Utils.performServerGet(requestSpec, responseSpec, URL, "summary");
return response; 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) { public HashMap approveLoan(final String approvalDate, final Integer loanID) {
return performLoanTransaction(createLoanOperationURL(APPROVE_LOAN_COMMAND, loanID), getApproveLoanAsJSON(approvalDate)); return performLoanTransaction(createLoanOperationURL(APPROVE_LOAN_COMMAND, loanID), getApproveLoanAsJSON(approvalDate));
} }
@@ -94,6 +98,13 @@ public class LoanTransactionHelper {
getWithdrawLoanApplicationBodyAsJSON(date)); 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) { private String getDisburseLoanAsJSON(final String actualDisbursementDate) {
final HashMap<String, String> map = new HashMap<String, String>(); final HashMap<String, String> map = new HashMap<String, String>();
map.put("locale", "en"); map.put("locale", "en");
@@ -151,6 +162,18 @@ public class LoanTransactionHelper {
} }
public static String getSpecifiedDueDateChargesForLoanAsJSON(final String chargeId) {
final HashMap<String, String> map = new HashMap<String, String>();
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) { public String getLoanCalculationBodyAsJSON(final String productID) {
final HashMap<String, String> map = new HashMap<String, String>(); final HashMap<String, String> map = new HashMap<String, String>();
map.put("dateFormat", "dd MMMM yyyy"); map.put("dateFormat", "dd MMMM yyyy");