From 419f127cd806788d0a6d7f1f43b656e98451a8b9 Mon Sep 17 00:00:00 2001 From: Priti Date: Mon, 1 Apr 2013 16:46:14 +0530 Subject: [PATCH] [Priti/Sailee] Refactoring 1. Created common package 2. Moved test files to IntegrationTest 3. Moved all helpers to Common package --- .../ClientLoanIntegrationTest.java | 2517 ++++++++++++++++ .../LoanWithWaiveInterestAndWriteOff.java | 2596 +++++++++++++++++ .../common/LoanApplicationTestBuilder.java | 163 ++ .../common/LoanProductTestBuilder.java | 166 ++ .../common/LoanStatusChecker.java | 39 + .../integrationtests/common/Utils.java | 113 + 6 files changed, 5594 insertions(+) create mode 100644 mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/ClientLoanIntegrationTest.java create mode 100644 mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/LoanWithWaiveInterestAndWriteOff.java create mode 100644 mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/LoanApplicationTestBuilder.java create mode 100644 mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/LoanProductTestBuilder.java create mode 100644 mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/LoanStatusChecker.java create mode 100644 mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/Utils.java diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/ClientLoanIntegrationTest.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/ClientLoanIntegrationTest.java new file mode 100644 index 000000000..b42154336 --- /dev/null +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/ClientLoanIntegrationTest.java @@ -0,0 +1,2517 @@ +package org.mifosplatform.integrationtests; + +import static com.jayway.restassured.RestAssured.given; +import static com.jayway.restassured.RestAssured.post; +import static com.jayway.restassured.path.json.JsonPath.from; +import static junit.framework.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; + + +import org.junit.Before; +import org.junit.Test; + +import com.google.gson.Gson; +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; +import org.mifosplatform.integrationtests.common.LoanApplicationTestBuilder; +import org.mifosplatform.integrationtests.common.LoanProductTestBuilder; +import org.mifosplatform.integrationtests.common.Utils; + +/** + * Client Loan Integration Test for checking Loan Application Repayment Schedule. + */ +@SuppressWarnings({ "rawtypes", "unchecked" }) +public class ClientLoanIntegrationTest { + + ResponseSpecification responseSpec; + RequestSpecification requestSpec; + + @Before + public void setup() { + requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build(); + requestSpec.header("Authorization","Basic "+ Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); + responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); + } + + @Test + public void checkClientLoanCreateAndDisburseFlow(){ + + Integer clientID = Utils.createClient(requestSpec, responseSpec); + checkClientCreatedOnServer(clientID); + + Integer loanProductID = createLoanProduct(); + applyForLoanApplication(clientID, loanProductID); + + ArrayList loanSchedule = getLoanRepaymentSchedule(loanProductID); + verifyLoanRepaymentSchedule(loanSchedule); + + } + + private void checkClientCreatedOnServer(final Integer generatedClientID) { + System.out.println("------------------------------CHECK CLIENT DETAILS------------------------------------\n"); + given().spec(requestSpec) + .expect().spec(responseSpec) + .when().get("/mifosng-provider/api/v1/clients/" + generatedClientID + "?tenantIdentifier=default"); + } + + private Integer createLoanProduct() { + System.out.println("------------------------------CREATING NEW LOAN PRODUCT ---------------------------------------"); + String loanProductJSON = new LoanProductTestBuilder() + .withPrincipal("12,000.00") + .withNumberOfRepayments("4") + .withRepaymentAfterEvery("1") + .withRepaymentTypeAsMonth() + .withinterestRatePerPeriod("2") + .withInterestRateFrequencyTypeAsMonths() + .withAmortizationTypeAsEqualInstallments() + .withInterestTypeAsDecliningBalance() + .withinterestRatePerPeriod("1") + .build(); + String json = given().spec(requestSpec).body(loanProductJSON) + .expect().spec(responseSpec) + .when().post("/mifosng-provider/api/v1/loanproducts?tenantIdentifier=default") + .andReturn().asString(); + return from(json).get("resourceId"); + } + + private void applyForLoanApplication(final Integer clientID, final Integer loanProductID) { + System.out.println("--------------------------------APPLYING FOR LOAN APPLICATION--------------------------------"); + String loanApplicationJSON = new LoanApplicationTestBuilder() + .withPrincipal("12,000.00") + .withLoanTermFrequency("4") + .withLoanTermFrequencyAsMonths() + .withNumberOfRepayments("4") + .withRepaymentEveryAfter("1") + .withRepaymentFrequencyTypeAsMonths() + .withInterestRatePerPeriod("2") + .withInterestRateFrequencyTypeAsMonths() + .withAmortizationTypeAsEqualInstallments() + .withInterestTypeAsDecliningBalance() + .withInterestCalculationPeriodTypeSameAsRepaymentPeriod() + .withExpectedDisbursementDate("20 September 2011") + .withSubmittedOnDate("20 September 2011") + .Build(clientID.toString(),loanProductID.toString()); + given().spec(requestSpec).body(loanApplicationJSON) + .expect().spec(responseSpec) + .when().post("/mifosng-provider/api/v1/loans?tenantIdentifier=default"); + } + + private ArrayList getLoanRepaymentSchedule(final Integer productID) + { + System.out.println("---------------------------GETTING LOAN REPAYMENT SCHEDULE--------------------------------"); + String json = given().spec(requestSpec).body(getLoanCalculationBodyAsJSON(productID.toString())) + .expect().spec(responseSpec) + .when().post("/mifosng-provider/api/v1/loans?command=calculateLoanSchedule&tenantIdentifier=default").andReturn().asString(); + return from(json).get("periods"); + } + + private void verifyLoanRepaymentSchedule(final ArrayList loanSchedule) { + System.out.println("--------------------VERIFYING THE PRINCIPAL DUES,INTEREST DUE AND DUE DATE--------------------------"); + + assertEquals("Checking for Due Date for 1st Month",new ArrayList(Arrays.asList(2011, 10, 20)),loanSchedule.get(1).get("dueDate")); + assertEquals("Checking for Principal Due for 1st Month", new Float("2911.49"), loanSchedule.get(1).get("principalOriginalDue")); + assertEquals("Checking for Interest Due for 1st Month",new Float("240.00"),loanSchedule.get(1).get("interestOriginalDue")); + + assertEquals("Checking for Due Date for 2nd Month",new ArrayList(Arrays.asList(2011,11,20)),loanSchedule.get(2).get("dueDate")); + assertEquals("Checking for Principal Due for 2nd Month", new Float("2969.72"), loanSchedule.get(2).get("principalDue")); + assertEquals("Checking for Interest Due for 2nd Month",new Float("181.77"),loanSchedule.get(2).get("interestOriginalDue")); + + assertEquals("Checking for Due Date for 3rd Month",new ArrayList(Arrays.asList(2011,12,20)),loanSchedule.get(3).get("dueDate")); + assertEquals("Checking for Principal Due for 3rd Month", new Float("3029.11"), loanSchedule.get(3).get("principalDue")); + assertEquals("Checking for Interest Due for 3rd Month",new Float("122.38"),loanSchedule.get(3).get("interestOriginalDue")); + + assertEquals("Checking for Due Date for 4th Month",new ArrayList(Arrays.asList(2012,1,20)),loanSchedule.get(4).get("dueDate")); + assertEquals("Checking for Principal Due for 4th Month", new Float("3089.68"), loanSchedule.get(4).get("principalDue")); + assertEquals("Checking for Interest Due for 4th Month",new Float("61.79"),loanSchedule.get(4).get("interestOriginalDue")); + } + + + + + private String getLoanCalculationBodyAsJSON(final String productID){ + HashMap map = new HashMap(); + map.put("dateFormat", "dd MMMM yyyy"); + map.put("locale", "en_GB"); + map.put("productId", productID); + map.put("principal", "12,000.00"); + map.put("loanTermFrequency", "4"); + map.put("loanTermFrequencyType", "2"); + map.put("numberOfRepayments", "4"); + map.put("repaymentEvery", "1"); + map.put("repaymentFrequencyType", "2"); + map.put("interestRateFrequencyType", "2"); + map.put("interestRatePerPeriod", "2"); + map.put("amortizationType", "1"); + map.put("interestType", "0"); + map.put("interestCalculationPeriodType", "1"); + map.put("expectedDisbursementDate", "20 September 2011"); + map.put("transactionProcessingStrategyId", "1"); + return new Gson().toJson(map); + } + + +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/LoanWithWaiveInterestAndWriteOff.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/LoanWithWaiveInterestAndWriteOff.java new file mode 100644 index 000000000..10a9ae6a6 --- /dev/null +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/LoanWithWaiveInterestAndWriteOff.java @@ -0,0 +1,2596 @@ +package org.mifosplatform.integrationtests; + +import static com.jayway.restassured.RestAssured.given; +import static com.jayway.restassured.RestAssured.post; +import static com.jayway.restassured.path.json.JsonPath.from; +import static junit.framework.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.HashMap; + +import org.junit.Before; +import org.junit.Test; + +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; +import org.mifosplatform.integrationtests.common.LoanApplicationTestBuilder; +import org.mifosplatform.integrationtests.common.LoanProductTestBuilder; +import org.mifosplatform.integrationtests.common.LoanStatusChecker; +import org.mifosplatform.integrationtests.common.Utils; + +/** + * Client Loan Integration Test for checking Loan Disbursement with Waive Interest and Write-Off. + */ +@SuppressWarnings({ "rawtypes", "unchecked" }) +public class LoanWithWaiveInterestAndWriteOff { + + ResponseSpecification responseSpec; + RequestSpecification requestSpec; + final String + LP_PRINCIPAL = "12,000.00", + LP_REPAYMENTS ="2", + LP_REPAYMENT_PERIOD="6", + LP_INTEREST_RATE="1", + + PRINCIPAL="4,500.00", + LOAN_TERM_FREQUENCY="18", + NUMBER_OF_REPAYMENTS="9", + REPAYMENT_PERIOD="2", + DISBURSEMENT_DATE="30 October 2010", + LOAN_APPLICATION_SUBMISSION_DATE="23 September 2010", + EXPECTED_DISBURSAL_DATE="28 October 2010", + RATE_OF_INTEREST_PER_PERIOD="2", + DATE_OF_JOINING = "04 March 2009", + INTEREST_VALUE_AMOUNT = "40.00"; + + @Before + public void setup() { + requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build(); + requestSpec.header("Authorization","Basic "+ Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); + responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); + } + + @Test + public void checkClientLoanCreateAndDisburseFlow(){ + //CREATE CLIENT + Integer clientID = Utils.createClient(requestSpec, responseSpec, DATE_OF_JOINING); + verifyClientCreatedOnServer(clientID); + + //CREATE LOAN PRODUCT + Integer loanProductID = createLoanProduct(); + //APPLY FOR LOAN + Integer loanID = applyForLoanApplication(clientID, loanProductID); + HashMap loanStatusHashMap = getStatusOfLoan(loanID); + + LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap); + + //APPROVE LOAN + loanStatusHashMap = approveLoan("28 September 2010", loanID); + LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap); + LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap); + + //UNDO APPROVAL + loanStatusHashMap = undoApproval(loanID); + LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap); + + //RE-APPROVE LOAN ON 1 OCTOBER 2010 + loanStatusHashMap = approveLoan("1 October 2010", loanID); + LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap); + LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap); + + //DISBURSE + loanStatusHashMap = disburseLoan(loanID); + System.out.println("DISBURSE "+loanStatusHashMap); + LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap); + + //PERFORM REPAYMENTS AND CHECK LOAN STATUS + verifyRepaymentScheduleEntryFor(1, 4000.0F,loanID); + makeRepayment(540.0f, "1 January 2011", loanID); + makeRepayment(540.0f, "1 March 2011", loanID); + waiveInterest("1 May 2011", loanID); + makeRepayment(500.0f, "1 May 2011", loanID); + makeRepayment(540.0f, "1 July 2011", loanID); + waiveInterest("1 September 2011", loanID); + makeRepayment(500.0f, "1 September 2011", loanID); + makeRepayment(540.0f, "1 November 2011", loanID); + waiveInterest("1 January 2012", loanID); + makeRepayment(500.0f, "1 January 2012", loanID); + verifyRepaymentScheduleEntryFor(7,1000.0f,loanID); + + //WRITE OFF LOAN AND CHECK ACCOUNT IS CLOSED + LoanStatusChecker.verifyLoanAccountIsClosed(writeOffLoan("1 March 2012", loanID)); + + } + + private void verifyRepaymentScheduleEntryFor(int repaymentNumber, float expectedPrincipalOutstanding ,Integer loanID) { + ArrayList repaymentPeriods = getLoanRepaymentSchedule(loanID); + assertEquals(repaymentPeriods.get(repaymentNumber).get("principalLoanBalanceOutstanding"), expectedPrincipalOutstanding); + + } + + private HashMap writeOffLoan(String transactionDate, Integer loanID){ + System.out.println("--------------------LOAN WRITTEN OFF ON "+transactionDate+"-------------------------------\n"); + String json = given().spec(requestSpec).body(Utils.getWriteOffBodyAsJSON(transactionDate)) + .expect().spec(responseSpec).log().ifError() + .when().post("/mifosng-provider/api/v1/loans/" + loanID + "/transactions?command=writeoff&tenantIdentifier=default") + .andReturn().asString(); + HashMap response = from(json).get("changes"); + return (HashMap)response.get("status"); + } + + private void waiveInterest(String transactionDate, Integer loanID){ + System.out.println("--------------------Waive INTEREST On "+transactionDate+"-------------------------------\n"); + given().spec(requestSpec).body(Utils.getWaiveBodyAsJSON(transactionDate, INTEREST_VALUE_AMOUNT)) + .expect().spec(responseSpec).log().ifError() + .when().post("/mifosng-provider/api/v1/loans/" + loanID + "/transactions?command=waiveinterest&tenantIdentifier=default"); + } + + private void makeRepayment(Float transactionAmount, String transactionDate, Integer loanID){ + System.out.print("------------------------MADE REPAYMENT ON " + transactionDate + "---------------------------------\n"); + given().spec(requestSpec).body(Utils.getRepaymentBodyAsJSON(transactionDate, transactionAmount)) + .expect().spec(responseSpec).log().ifError() + .when().post("/mifosng-provider/api/v1/loans/" + loanID + "/transactions?command=repayment&tenantIdentifier=default"); + } + + private ArrayList getLoanRepaymentSchedule(Integer loanID) + { + System.out.println("---------------------------GETTING LOAN REPAYMENT SCHEDULE--------------------------------"); + String json = given().spec(requestSpec) + .expect().spec(responseSpec).log().ifError() + .when().get("/mifosng-provider/api/v1/loans/" + loanID +"?associations=repaymentSchedule&tenantIdentifier=default").andReturn().asString(); + HashMap repaymentSchedule = from(json).get("repaymentSchedule"); + return (ArrayList)repaymentSchedule.get("periods"); + } + + private HashMap getStatusOfLoan(Integer loanID){ + String json= given().spec(requestSpec) + .expect().spec(responseSpec).log().ifError() + .when().get("/mifosng-provider/api/v1/loans/" + loanID + "?tenantIdentifier=default") + .andReturn().asString(); + return from(json).get("status"); + } + + private HashMap undoApproval(Integer loanID){ + System.out.println("-----------------------------------UNDO LOAN APPROVAL-----------------------------------------"); + String json = given().spec(requestSpec).body("{'note':'UNDO APPROVAL'}") + .expect().spec(responseSpec).log().ifError() + .when().post("/mifosng-provider/api/v1/loans/" + loanID + "?command=undoApproval&tenantIdentifier=default") + .andReturn().asString(); + HashMap response = from(json).get("changes"); + return (HashMap)response.get("status"); + } + private HashMap disburseLoan(Integer loanID){ + System.out.println("-----------------------------------DISBURSE LOAN-----------------------------------------"); + String json = given().spec(requestSpec).body(Utils.getDisburseLoanAsJSON(DISBURSEMENT_DATE)) + .expect().spec(responseSpec).log().ifError() + .when().post("/mifosng-provider/api/v1/loans/" + loanID + "?command=disburse&tenantIdentifier=default") + .andReturn().asString(); + HashMap response = from(json).get("changes"); + return (HashMap)response.get("status"); + } + + private HashMap approveLoan(String approvalDate, Integer loanID){ + System.out.println("-----------------------------------APPROVE LOAN-----------------------------------------"); + String json =given().spec(requestSpec).body(Utils.getApproveLoanAsJSON(approvalDate)) + .expect().spec(responseSpec).log().ifError() + .when().post("/mifosng-provider/api/v1/loans/"+ loanID +"?command=approve&tenantIdentifier=default") + .andReturn().asString(); + HashMap response = from(json).get("changes"); + return (HashMap)response.get("status"); + } + + + private void verifyClientCreatedOnServer(final Integer generatedClientID) { + System.out.println("------------------------------CHECK CLIENT DETAILS------------------------------------\n"); + given().spec(requestSpec) + .expect().spec(responseSpec).log().ifError() + .when().get("/mifosng-provider/api/v1/clients/" + generatedClientID + "?tenantIdentifier=default"); + } + + private Integer createLoanProduct() { + System.out.println("------------------------------CREATING NEW LOAN PRODUCT ---------------------------------------"); + String loanProductJSON = new LoanProductTestBuilder() + .withPrincipal(LP_PRINCIPAL) + .withRepaymentTypeAsMonth() + .withRepaymentAfterEvery(LP_REPAYMENT_PERIOD) + .withNumberOfRepayments(LP_REPAYMENTS) + .withRepaymentTypeAsMonth() + .withinterestRatePerPeriod(LP_INTEREST_RATE) + .withInterestRateFrequencyTypeAsMonths() + .withAmortizationTypeAsEqualPrinciplePayment() + .withInterestTypeAsFlat() + .build(); + String json = given().spec(requestSpec).body(loanProductJSON) + .expect().spec(responseSpec).log().ifError() + .when().post("/mifosng-provider/api/v1/loanproducts?tenantIdentifier=default") + .andReturn().asString(); + return from(json).get("resourceId"); + } + + private Integer applyForLoanApplication(final Integer clientID, final Integer loanProductID) { + System.out.println("--------------------------------APPLYING FOR LOAN APPLICATION--------------------------------"); + String loanApplicationJSON = new LoanApplicationTestBuilder() + .withPrincipal(PRINCIPAL) + .withLoanTermFrequency(LOAN_TERM_FREQUENCY) + .withLoanTermFrequencyAsMonths() + .withNumberOfRepayments(NUMBER_OF_REPAYMENTS) + .withRepaymentEveryAfter(REPAYMENT_PERIOD) + .withRepaymentFrequencyTypeAsMonths() + .withInterestRateFrequencyTypeAsMonths() + .withInterestRatePerPeriod(RATE_OF_INTEREST_PER_PERIOD) + .withInterestTypeAsFlatBalance() + .withAmortizationTypeAsEqualInstallments() + .withInterestCalculationPeriodTypeSameAsRepaymentPeriod() + .withExpectedDisbursementDate(EXPECTED_DISBURSAL_DATE) + .withSubmittedOnDate(LOAN_APPLICATION_SUBMISSION_DATE) + .Build(clientID.toString(), loanProductID.toString()); + String json = given().spec(requestSpec).body(loanApplicationJSON) + .expect().spec(responseSpec).log().ifError() + .when().post("/mifosng-provider/api/v1/loans?tenantIdentifier=default") + .andReturn().asString(); + return from(json).get("loanId"); + } +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/LoanApplicationTestBuilder.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/LoanApplicationTestBuilder.java new file mode 100644 index 000000000..85a7e5e46 --- /dev/null +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/LoanApplicationTestBuilder.java @@ -0,0 +1,163 @@ +package org.mifosplatform.integrationtests.common; + +import com.google.gson.Gson; + +import java.util.HashMap; + + +public class LoanApplicationTestBuilder { + private static final String DAYS = "0"; + private static final String WEEKS = "1"; + private static final String MONTHS = "2"; + private static final String YEARS = "3"; + private static final String DECLINING_BALANCE = "0"; + private static final String FLAT_BALANCE = "1"; + private static final String EQUAL_PRINCIPLE_PAYMENTS="0"; + private static final String EQUAL_INSTALLMENTS="1"; + private static final String CALCULATION_PERIOD_SAME_AS_REPAYMENT_PERIOD="1"; + private static final String MIFOS_STANDARD_STRATEGY ="1"; + + + private String principal = "10,000"; + private String clientID="0"; + private String loanProductId = "0"; + private String loanTermFrequency = ""; + private String loanTermFrequencyType=""; //0=Days, 1=Weeks, 2=Months, 3=Years + private String numberOfRepayment = "0"; + private String repaymentPeriod = "0"; + private String repaymentFrequencyType = ""; //0=Days, 1=Weeks, 2=Months + + // 12 % per Year Declining Balance + // interest rate per Interest_frequency interest type + private String interestRate = "2"; + private String interestRateFrequencyType="0"; //2=Per month, 3=Per year + private String interestType= ""; //0=Declining Balance, 1=Flat + private String amortizationType =""; //0=Equal principle payments, 1=Equal installments + private String interestCalculationPeriodType =CALCULATION_PERIOD_SAME_AS_REPAYMENT_PERIOD; + private String transactionProcessingID= MIFOS_STANDARD_STRATEGY; + private String expectedDisbursmentDate=""; + private String submittedOndate =""; + + public String Build(String clientID, String loanProductId){ + this.clientID = clientID; + this.loanProductId = loanProductId; + HashMap map = new HashMap(); + map.put("dateFormat", "dd MMMM yyyy"); + map.put("locale", "en_GB"); + map.put("clientId", clientID); + map.put("productId",loanProductId); + map.put("principal", principal); + map.put("loanTermFrequency",loanTermFrequency); + map.put("loanTermFrequencyType", "2"); + map.put("numberOfRepayments", numberOfRepayment); + map.put("repaymentEvery", repaymentPeriod); + map.put("repaymentFrequencyType", repaymentFrequencyType); + map.put("interestRateFrequencyType", interestRateFrequencyType); + map.put("interestRatePerPeriod", interestRate); + map.put("amortizationType", amortizationType); + map.put("interestType", interestType); + map.put("interestCalculationPeriodType", interestCalculationPeriodType); + map.put("transactionProcessingStrategyId", transactionProcessingID); + map.put("expectedDisbursementDate", expectedDisbursmentDate); + map.put("submittedOnDate", submittedOndate); + return new Gson().toJson(map); + } + + public LoanApplicationTestBuilder withPrincipal(String principalAmount){ + this.principal = principalAmount; + return this; + } + + public LoanApplicationTestBuilder withLoanTermFrequency(String loanToBePayedDuration){ + this.loanTermFrequency= loanToBePayedDuration; + return this; + } + + public LoanApplicationTestBuilder withLoanTermFrequencyAsDays(){ + this.loanTermFrequencyType=DAYS; + return this; + } + public LoanApplicationTestBuilder withLoanTermFrequencyAsMonths(){ + this.loanTermFrequencyType=MONTHS; + return this; + } + public LoanApplicationTestBuilder withLoanTermFrequencyAsWeeks(){ + this.loanTermFrequencyType=WEEKS; + return this; + } + public LoanApplicationTestBuilder withLoanTermFrequencyAsYears(){ + this.loanTermFrequencyType=YEARS; + return this; + } + public LoanApplicationTestBuilder withNumberOfRepayments(String numberOfRepayments){ + this.numberOfRepayment= numberOfRepayments; + return this; + } + public LoanApplicationTestBuilder withRepaymentEveryAfter(String repaymentPeriod){ + this.repaymentPeriod=repaymentPeriod; + return this; + } + public LoanApplicationTestBuilder withRepaymentFrequencyTypeAsDays(){ + this.repaymentFrequencyType = DAYS; + return this; + } + + public LoanApplicationTestBuilder withRepaymentFrequencyTypeAsMonths(){ + this.repaymentFrequencyType = MONTHS; + return this; + } + + public LoanApplicationTestBuilder withRepaymentFrequencyTypeAsWeeks(){ + this.repaymentFrequencyType = WEEKS; + return this; + } + + public LoanApplicationTestBuilder withInterestRatePerPeriod(String interestRate){ + this.interestRate=interestRate; + return this; + } + public LoanApplicationTestBuilder withInterestRateFrequencyTypeAsMonths(){ + this.interestRateFrequencyType=MONTHS; + return this; + } + public LoanApplicationTestBuilder withInterestRateFrequencyTypeAsYears(){ + this.interestRateFrequencyType=YEARS; + return this; + } + public LoanApplicationTestBuilder withInterestTypeAsFlatBalance(){ + this.interestType=FLAT_BALANCE; + return this; + } + public LoanApplicationTestBuilder withInterestTypeAsDecliningBalance(){ + this.interestType=DECLINING_BALANCE; + return this; + } + + public LoanApplicationTestBuilder withAmortizationTypeAsEqualInstallments(){ + this.amortizationType=EQUAL_INSTALLMENTS; + return this; + } + + public LoanApplicationTestBuilder withAmortizationTypeAsEqualPrincipalPayments(){ + this.amortizationType=EQUAL_PRINCIPLE_PAYMENTS; + return this; + } + + public LoanApplicationTestBuilder withInterestCalculationPeriodTypeSameAsRepaymentPeriod(){ + this.interestCalculationPeriodType=CALCULATION_PERIOD_SAME_AS_REPAYMENT_PERIOD; + return this; + } + + public LoanApplicationTestBuilder withInterestCalculationPeriodTypeAsDays(){ + this.interestCalculationPeriodType=DAYS; + return this; + } + public LoanApplicationTestBuilder withExpectedDisbursementDate(String expectedDisbursementDate){ + this.expectedDisbursmentDate=expectedDisbursementDate; + return this; + } + public LoanApplicationTestBuilder withSubmittedOnDate(String loanApplicationSubmittedDate){ + this.submittedOndate=loanApplicationSubmittedDate; + return this; + } +} diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/LoanProductTestBuilder.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/LoanProductTestBuilder.java new file mode 100644 index 000000000..05eaa7769 --- /dev/null +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/LoanProductTestBuilder.java @@ -0,0 +1,166 @@ +package org.mifosplatform.integrationtests.common; + +import com.google.gson.Gson; + +import java.util.HashMap; + +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 DAYS = "0"; + private static final String WEEK = "1"; + private static final String MONTHS = "2"; + private static final String YEARS = "3"; + private static final String CALCULATION_PERIOD_SAME_AS_REPAYMENT_PERIOD="1"; + private static final String EQUAL_PRINCIPLE_PAYMENTS="0"; + private static final String EQUAL_INSTALLMENTS="1"; + private static final String DECLINING_BALANCE="0"; + private static final String FLAT_BALANCE="1"; + private static final String MIFOS_STANDARD_STRATEGY ="1"; + private static final String HEAVENS_FAMILY_STRATEGY ="2"; + private static final String CREO_CORE_STRATEGY ="3"; + private static final String RBI_INDIA_STRATEGY ="4"; + private static final String NONE ="1"; + private static final String CASH_BASED ="2"; + private static final String ACCRUAL_BASED ="3"; + + + private String nameOfLoanProduct = Utils.randomNameGenerator("LOAN_PRODUCT_", 6); + private String principal = "10000.00"; + private String numberOfRepayments = "0"; + private String repaymentFrequency = WEEK; + private String repaymentPeriod = "0"; + private String interestRatePerPeriod= "2"; + private String interestRateFrequencyType = MONTHS; + private String interestType = FLAT_BALANCE; + private String interestCalculationPeriodType=CALCULATION_PERIOD_SAME_AS_REPAYMENT_PERIOD; + private String inArrearsTolerance="0"; + private String transactionProcessingStrategy=MIFOS_STANDARD_STRATEGY; + private String accountingRule =NONE; + private String currencyCode = INR; + private String amortizationType= EQUAL_INSTALLMENTS; + + public String build() { + HashMap map = new HashMap(); + + map.put("name", nameOfLoanProduct); + map.put("currencyCode", currencyCode); + map.put("locale", LOCALE); + map.put("digitsAfterDecimal",DIGITS_AFTER_DECIMAL); + map.put("principal", principal); + map.put("numberOfRepayments", numberOfRepayments); + map.put("repaymentEvery",repaymentPeriod ); + map.put("repaymentFrequencyType", repaymentFrequency); + map.put("interestRatePerPeriod", interestRatePerPeriod); + map.put("interestRateFrequencyType", interestRateFrequencyType); + map.put("amortizationType",amortizationType); + map.put("interestType", interestType); + map.put("interestCalculationPeriodType", interestCalculationPeriodType); + map.put("inArrearsTolerance", inArrearsTolerance); + map.put("transactionProcessingStrategyId", transactionProcessingStrategy); + map.put("accountingRule", accountingRule); + return new Gson().toJson(map); + } + + public LoanProductTestBuilder withLoanName(String loanName){ + this.nameOfLoanProduct=loanName; + return this; + } + public LoanProductTestBuilder withPrincipal(String principal){ + this.principal = principal; + return this; + } + + public LoanProductTestBuilder withNumberOfRepayments(String numberOfRepayment){ + this.numberOfRepayments = numberOfRepayment; + return this; + } + + + public LoanProductTestBuilder withRepaymentTypeAsMonth(){ + this.repaymentFrequency = MONTHS; + return this; + } + + public LoanProductTestBuilder withRepaymentTypeAsWeek(){ + this.repaymentFrequency = WEEK; + return this; + } + + public LoanProductTestBuilder withRepaymentTypeAsDays(){ + this.repaymentFrequency = DAYS; + return this; + } + + public LoanProductTestBuilder withRepaymentAfterEvery(String repaymentAfterEvery){ + this.repaymentPeriod=repaymentAfterEvery; + return this; + } + + public LoanProductTestBuilder withInterestRateFrequencyTypeAsMonths(){ + this.interestRateFrequencyType=MONTHS; + return this; + } + + public LoanProductTestBuilder withInterestRateFrequencyTypeAsYear(){ + this.interestRateFrequencyType=YEARS; + return this; + } + + public LoanProductTestBuilder withinterestRatePerPeriod(String interestRatePerPeriod) { + this.interestRatePerPeriod=interestRatePerPeriod; + return this; + } + + public LoanProductTestBuilder withAmortizationTypeAsEqualPrinciplePayment(){ + this.amortizationType = EQUAL_PRINCIPLE_PAYMENTS; + return this; + } + + public LoanProductTestBuilder withAmortizationTypeAsEqualInstallments(){ + this.amortizationType = EQUAL_INSTALLMENTS; + return this; + } + + public LoanProductTestBuilder withInterestTypeAsFlat(){ + this.interestType=FLAT_BALANCE; + return this; + } + + public LoanProductTestBuilder withInterestTypeAsDecliningBalance (){ + this.interestType=DECLINING_BALANCE; + return this; + } + + public LoanProductTestBuilder withInterestCalculationPeriodTypeAsDays (){ + this.interestCalculationPeriodType=DAYS; + return this; + } + + public LoanProductTestBuilder withInterestCalculationPeriodTypeAsRepaymentPeriod (){ + this.interestCalculationPeriodType=CALCULATION_PERIOD_SAME_AS_REPAYMENT_PERIOD; + return this; + } + + public LoanProductTestBuilder withInArrearsTolerance (String amountCanBeWaved){ + this.inArrearsTolerance = amountCanBeWaved; + return this; + } + + public LoanProductTestBuilder withAccountingRuleAsNone (){ + this.accountingRule= NONE; + return this; + } + + public LoanProductTestBuilder withAccountingRuleAsCashBased (){ + this.accountingRule= CASH_BASED; + return this; + } + + public LoanProductTestBuilder withAccountingRuleAsAccrualBased (){ + this.accountingRule= ACCRUAL_BASED; + return this; + } + +} diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/LoanStatusChecker.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/LoanStatusChecker.java new file mode 100644 index 000000000..5f6a9a243 --- /dev/null +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/LoanStatusChecker.java @@ -0,0 +1,39 @@ +package org.mifosplatform.integrationtests.common; + +import junit.framework.Assert; + +import java.util.HashMap; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class LoanStatusChecker { + + private static boolean getStatus(HashMap loanStatusMap, String nameOfLoanStatusString){ + return (Boolean)loanStatusMap.get(nameOfLoanStatusString); + } + + public static void verifyLoanIsApproved(HashMap loanStatusHashMap) { + assertFalse(getStatus(loanStatusHashMap, "pendingApproval")); + } + + public static void verifyLoanIsWaitingForDisbursal(HashMap loanStatusHashMap) { + assertTrue(getStatus(loanStatusHashMap, "waitingForDisbursal")); + } + + public static void verifyLoanIsPending(HashMap loanStatusHashMap) { + assertTrue(getStatus(loanStatusHashMap, "pendingApproval")); + } + + public static void verifyLoanIsActive(HashMap loanStatusHashMap) { + assertTrue(getStatus(loanStatusHashMap, "active")); + } + + public static void verifyLoanNeedsApproval(HashMap loanStatusHashMap) { + assertTrue(getStatus(loanStatusHashMap, "pendingApproval")); + } + + public static void verifyLoanAccountIsClosed(HashMap loanStatusHashMap){ + Assert.assertTrue(getStatus(loanStatusHashMap, "closed")); + } +} diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/Utils.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/Utils.java new file mode 100644 index 000000000..61eec5f42 --- /dev/null +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/Utils.java @@ -0,0 +1,113 @@ +package org.mifosplatform.integrationtests.common; + +import com.google.gson.Gson; +import com.jayway.restassured.path.json.JsonPath; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; + +import java.util.HashMap; +import java.util.Random; + +import static com.jayway.restassured.RestAssured.given; +import static com.jayway.restassured.RestAssured.post; +import static com.jayway.restassured.path.json.JsonPath.from; + +public class Utils { + + public static String randomStringGenerator(final String prefix, final int len, final String sourceSetString) { + int lengthOfSource = sourceSetString.length(); + Random rnd = new Random(); + StringBuilder sb = new StringBuilder(len); + for (int i = 0; i < len; i++) + sb.append((sourceSetString).charAt(rnd.nextInt(lengthOfSource))); + return (prefix+(sb.toString())); + } + + public static String randomNameGenerator(final String prefix, final int lenOfRandomSuffix) { + return randomStringGenerator(prefix, lenOfRandomSuffix, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + } + + public static String randomIDGenerator(final String prefix, final int lenOfRandomSuffix) { + return randomStringGenerator(prefix, lenOfRandomSuffix, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + } + + public static String getTestClientAsJSON(String dateOfJoining) { + HashMap map = new HashMap(); + map.put("officeId", "1"); + map.put("firstname", Utils.randomNameGenerator("Client_FirstName_", 5)); + map.put("lastname", Utils.randomNameGenerator("Client_LastName_", 4)); + map.put("externalId", Utils.randomIDGenerator("ID_", 7)); + map.put("dateFormat", "dd MMMM yyyy"); + map.put("locale", "en"); + map.put("joinedDate", dateOfJoining); + System.out.println("map : "+map); + return new Gson().toJson(map); + } + + public static String getDisburseLoanAsJSON(String actualDisbursementDate){ + HashMap map = new HashMap(); + map.put("locale","en"); + map.put("dateFormat","dd MMMM yyyy"); + map.put("actualDisbursementDate",actualDisbursementDate); + map.put("note", "DISBURSE NOTE"); + return new Gson().toJson(map); + } + + public static String getApproveLoanAsJSON(String approvalDate){ + HashMap map = new HashMap(); + map.put("locale","en"); + map.put("dateFormat","dd MMMM yyyy"); + map.put("approvedOnDate",approvalDate); + map.put("note", "Approval NOTE"); + return new Gson().toJson(map); + } + + public static String getRepaymentBodyAsJSON(String transactionDate,Float transactionAmount){ + HashMap map = new HashMap(); + map.put("locale","en"); + map.put("dateFormat","dd MMMM yyyy"); + map.put("transactionDate",transactionDate); + map.put("transactionAmount",transactionAmount.toString()); + map.put("note", "Repayment Made!!!"); + return new Gson().toJson(map); + } + + public static String getWriteOffBodyAsJSON(String transactionDate){ + HashMap map = new HashMap(); + map.put("dateFormat","dd MMMM yyyy"); + map.put("locale","en"); + map.put("note", " LOAN WRITE OFF!!!"); + map.put("transactionDate",transactionDate); + return new Gson().toJson(map); + } + public static String getWaiveBodyAsJSON(String transactionDate,String amountToBeWaived){ + HashMap map = new HashMap(); + map.put("locale","en"); + map.put("dateFormat","dd MMMM yyyy"); + map.put("transactionDate",transactionDate); + map.put("transactionAmount",amountToBeWaived); + map.put("note", " Interest Waived!!!"); + return new Gson().toJson(map); + } + + + public static Integer createClient(RequestSpecification requestSpec, ResponseSpecification responseSpec) { + return createClient(requestSpec,responseSpec,"04 March 2012"); + + } + public static Integer createClient(RequestSpecification requestSpec, ResponseSpecification responseSpec,String dateOfJoining) { + System.out.println("---------------------------------CREATING A CLIENT---------------------------------------------"); + String json = given().spec(requestSpec).body(getTestClientAsJSON(dateOfJoining)) + .expect().spec(responseSpec) + .when().post("/mifosng-provider/api/v1/clients?tenantIdentifier=default") + .andReturn().asString(); + + return from(json).get("clientId"); + } + + public static String loginIntoServerAndGetBase64EncodedAuthenticationKey() { + System.out.println("-----------------------------------LOGIN-----------------------------------------"); + String json = post("/mifosng-provider/api/v1/authentication?username=mifos&password=password&tenantIdentifier=default").asString(); + return JsonPath.with(json).get("base64EncodedAuthenticationKey"); + } +}