From c362e0f19a983115a66a3053e43cce401b109a9b Mon Sep 17 00:00:00 2001 From: Priti Date: Thu, 28 Mar 2013 21:57:28 +0530 Subject: [PATCH 01/21] 1.Integration Test : LoanWithWaiveInterest added 2. LoanProduct Builder created 3. RandomGenerator methods moved to Util file --- .../LoanWithWaiveInterestAndWriteOff.java | 2721 +++++++++++++++++ .../testbuilder/LoanProductTestBuilder.java | 166 + .../integrationtests/testbuilder/Utils.java | 23 + 3 files changed, 2910 insertions(+) create mode 100644 mifosng-provider/src/integrationTest/java/LoanWithWaiveInterestAndWriteOff.java create mode 100644 mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/LoanProductTestBuilder.java create mode 100644 mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/Utils.java diff --git a/mifosng-provider/src/integrationTest/java/LoanWithWaiveInterestAndWriteOff.java b/mifosng-provider/src/integrationTest/java/LoanWithWaiveInterestAndWriteOff.java new file mode 100644 index 000000000..b45ee27fe --- /dev/null +++ b/mifosng-provider/src/integrationTest/java/LoanWithWaiveInterestAndWriteOff.java @@ -0,0 +1,2721 @@ +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 junit.framework.Assert; +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.path.json.JsonPath; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; +import org.mifosplatform.integrationtests.testbuilder.LoanProductTestBuilder; +import org.mifosplatform.integrationtests.testbuilder.Utils; + +/** + * Client Loan Integration Test for checking Loan Disburstment with Waive Interest and Write-Off. + */ +@SuppressWarnings({ "rawtypes", "unchecked" }) +public class LoanWithWaiveInterestAndWriteOff { + + ResponseSpecification responseSpec; + RequestSpecification requestSpec; + final String PRINCIPAL="4,500.00", + NUMBER_OF_REPAYMENTS="9", + REPAYMENT_PERIOD="2", + DISBURSEMENT_DATE="30 October 2010", + LOAN_APPLICATION_SUBMISSION_DATE="23 September 2010", + INTEREST_VALUE_AMOUNT = "40.00"; + + @Before + public void setup() { + String basicAuthKey = loginIntoServerAndGetBase64EncodedAuthenticationKey(); + + requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build(); + requestSpec.header("Authorization","Basic "+basicAuthKey); + + responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); + } + + @Test + public void checkClientLoanCreateAndDisburseFlow(){ + //CREATE CLIENT + Integer clientID = createClient(); + verifyClientCreatedOnServer(clientID); + + //CREATE LOAN PRODUCT + Integer loanProductID = createLoanProduct(); + //APPLY FOR LOAN + Integer loanID = applyForLoanApplication(clientID, loanProductID); + HashMap loanStatusHashMap = getStatusOfLoan(loanID); + verifyLoanStatusIsPending(loanStatusHashMap); + + //APPROVE LOAN + loanStatusHashMap = approveLoan("28 September 2010", loanID); + System.out.println("********************HASHMAP **************"+loanStatusHashMap); + verifyLoanIsApproved(loanStatusHashMap); + verifyLoanStatusIsWaitingForDisbursal(loanStatusHashMap); + + //UNDO APPROVAL + loanStatusHashMap = undoApproval(loanID); + verifyLoanNeedsApproval(loanStatusHashMap); + + //RE-APPROVE LOAN ON 1 OCTOBER 2010 + loanStatusHashMap = approveLoan("1 October 2010", loanID); + verifyLoanIsApproved(loanStatusHashMap); + verifyLoanStatusIsWaitingForDisbursal(loanStatusHashMap); + + //DISBURSE + loanStatusHashMap = disburseLoan(loanID); + verifyLoanStatusIsActive(loanStatusHashMap); + + //PERFORM REPAYMENTS AND CHECK LOAN STATUS + //----------------------------------------- +// verifyRepaymentScheduleEntryFor(1, 4000.0F, 200.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, 200.0F, loanID); + + //WRITE OFF LOAN AND CHECK ACCOUNT IS CLOSED + verifyLoanAccountIsClosed(writeOffLoan("1 March 2012", loanID)); + + } + + private void verifyLoanNeedsApproval(HashMap loanStatusHashMap) { + assertTrue(getStatus(loanStatusHashMap, "pendingApproval")); + } + + private void verifyLoanIsApproved(HashMap loanStatusHashMap) { + assertFalse(getStatus(loanStatusHashMap, "pendingApproval")); + } + + private void verifyLoanStatusIsWaitingForDisbursal(HashMap loanStatusHashMap) { + assertTrue(getStatus(loanStatusHashMap, "waitingForDisbursal")); + } + + private void verifyLoanStatusIsPending(HashMap loanStatusHashMap) { + assertTrue(getStatus(loanStatusHashMap, "pendingApproval")); + } + + private void verifyLoanStatusIsActive(HashMap loanStatusHashMap) { + assertTrue(getStatus(loanStatusHashMap, "active")); + } + + private void verifyRepaymentScheduleEntryFor(int repaymentNumber, float expectedPrincipal, Float expectedInterest, Integer loanID) { + ArrayList repaymentPeriods = getLoanRepaymentSchedule(loanID); + assertEquals(repaymentPeriods.get(repaymentNumber).get("principalLoanBalanceOutstanding"), expectedPrincipal); + assertEquals(repaymentPeriods.get(repaymentNumber).get("interestLoanBalanceOutstanding"), expectedInterest); + } + + private HashMap writeOffLoan(String transactionDate, Integer loanID){ + System.out.println("--------------------LOAN WRITTEN OFF ON "+transactionDate+"-------------------------------\n"); + String json = given().spec(requestSpec).body(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(getWaiveBodyAsJSON(transactionDate)) + .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(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 boolean getStatus(HashMap loanStatusMap,String nameOfLoanStatusString){ + return (Boolean)loanStatusMap.get(nameOfLoanStatusString); + } + + private void verifyLoanAccountIsClosed(HashMap loanStatusHashMap){ + Assert.assertTrue(getStatus(loanStatusHashMap, "closed")); + } + + 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(getDisburseLoanAsJSON()) + .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(getApproveLoanAsJSON(approvalDate)) + .expect().spec(responseSpec).log().ifError() + .when().post("/mifosng-provider/api/v1/loans/"+ loanID +"?command=approve&tenantIdentifier=default") + .andReturn().asString(); + System.out.println("**************CHANGES :"+from(json).get("changes")); + HashMap response = from(json).get("changes"); + return (HashMap)response.get("status"); + } + + + private 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"); + } + + private Integer createClient() { + System.out.println("---------------------------------CREATING A CLIENT---------------------------------------------"); + String json = given().spec(requestSpec).body(getTestClientAsJSON()) + .expect().spec(responseSpec).log().ifError() + .when().post("/mifosng-provider/api/v1/clients?tenantIdentifier=default") + .andReturn().asString(); + + return from(json).get("clientId"); + } + + 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(PRINCIPAL) + .withRepaymentTypeAsMonth() + .withRepaymentAfterEvery(REPAYMENT_PERIOD) + .withNumberOfRepayments(NUMBER_OF_REPAYMENTS) + .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 json = given().spec(requestSpec).body(getLoanApplicationBodyAsJSON(clientID.toString(), loanProductID.toString())) + .expect().spec(responseSpec).log().ifError() + .when().post("/mifosng-provider/api/v1/loans?tenantIdentifier=default") + .andReturn().asString(); + return from(json).get("loanId"); + } + + + private 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); + } + private String getWaiveBodyAsJSON(String transactionDate){ + HashMap map = new HashMap(); + map.put("locale","en"); + map.put("dateFormat","dd MMMM yyyy"); + map.put("transactionDate",transactionDate); + map.put("transactionAmount",INTEREST_VALUE_AMOUNT); + map.put("note", " Interest Waived!!!"); + return new Gson().toJson(map); + } + private 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); + } + private 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"); + System.out.println("***************JSON ***"+new Gson().toJson(map)); + return new Gson().toJson(map); + } + + private String getDisburseLoanAsJSON(){ + HashMap map = new HashMap(); + map.put("locale","en"); + map.put("dateFormat","dd MMMM yyyy"); + map.put("actualDisbursementDate",DISBURSEMENT_DATE); + map.put("note", "DISBURSE NOTE"); + return new Gson().toJson(map); + } + + private String getTestClientAsJSON() { + 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", "04 March 2009"); + System.out.println("map : "+map); + return new Gson().toJson(map); + } + + + private String getLoanApplicationBodyAsJSON(final String clientID,final String productID){ + HashMap map = new HashMap(); + map.put("dateFormat", "dd MMMM yyyy"); + map.put("locale", "en_GB"); + map.put("clientId", clientID); + map.put("productId", productID); + map.put("principal", PRINCIPAL); + map.put("loanTermFrequency", "4"); + map.put("loanTermFrequencyType", "2"); + map.put("numberOfRepayments", NUMBER_OF_REPAYMENTS); + map.put("repaymentEvery", REPAYMENT_PERIOD); + map.put("repaymentFrequencyType", "2"); + map.put("interestRateFrequencyType", "2"); + map.put("interestRatePerPeriod", "2"); + map.put("amortizationType", "1"); + map.put("interestType", "1"); + map.put("interestCalculationPeriodType", "1"); + map.put("transactionProcessingStrategyId", "1"); + map.put("expectedDisbursementDate", DISBURSEMENT_DATE); + map.put("submittedOnDate", LOAN_APPLICATION_SUBMISSION_DATE); + return new Gson().toJson(map); + } + + private String getLoanCalculationBodyAsJSON(String productID){ + HashMap map = new HashMap(); + map.put("dateFormat", "dd MMMM yyyy"); + map.put("locale", "en_GB"); + map.put("productId", productID); + map.put("principal", PRINCIPAL); + map.put("loanTermFrequency", "4"); + map.put("loanTermFrequencyType", "2"); + map.put("numberOfRepayments", NUMBER_OF_REPAYMENTS); + map.put("repaymentEvery", REPAYMENT_PERIOD); + map.put("repaymentFrequencyType", "2"); + map.put("interestRateFrequencyType", "2"); + map.put("interestRatePerPeriod", "2"); + map.put("amortizationType", "1"); + map.put("interestType", "1"); + map.put("interestCalculationPeriodType", "1"); + map.put("expectedDisbursementDate", DISBURSEMENT_DATE); + map.put("transactionProcessingStrategyId", "1"); + return new Gson().toJson(map); + } + + +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/LoanProductTestBuilder.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/LoanProductTestBuilder.java new file mode 100644 index 000000000..9ebd1879f --- /dev/null +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/LoanProductTestBuilder.java @@ -0,0 +1,166 @@ +package org.mifosplatform.integrationtests.testbuilder; + +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/testbuilder/Utils.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/Utils.java new file mode 100644 index 000000000..b665a44df --- /dev/null +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/Utils.java @@ -0,0 +1,23 @@ +package org.mifosplatform.integrationtests.testbuilder; + +import java.util.Random; + +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"); + } +} From b4edfc4c3405612c3d964080282b574856e1c549 Mon Sep 17 00:00:00 2001 From: Priti Date: Sat, 30 Mar 2013 11:06:02 +0530 Subject: [PATCH 02/21] Builder for LoanApplication Added --- .../LoanApplicationTestBuilder.java | 163 ++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/LoanApplicationTestBuilder.java diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/LoanApplicationTestBuilder.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/LoanApplicationTestBuilder.java new file mode 100644 index 000000000..d11b689aa --- /dev/null +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/LoanApplicationTestBuilder.java @@ -0,0 +1,163 @@ +package org.mifosplatform.integrationtests.testbuilder; + +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; + } +} From 3471475c94591adccc5aba32194e82f807859f41 Mon Sep 17 00:00:00 2001 From: Priti Date: Sat, 30 Mar 2013 11:07:21 +0530 Subject: [PATCH 03/21] LoanStatusChecker added which checks the loan status --- .../testbuilder/LoanStatusChecker.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/LoanStatusChecker.java diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/LoanStatusChecker.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/LoanStatusChecker.java new file mode 100644 index 000000000..7bd8dd0c3 --- /dev/null +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/LoanStatusChecker.java @@ -0,0 +1,39 @@ +package org.mifosplatform.integrationtests.testbuilder; + +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 verifyLoanStatusIsWaitingForDisbursal(HashMap loanStatusHashMap) { + assertTrue(getStatus(loanStatusHashMap, "waitingForDisbursal")); + } + + public static void verifyLoanStatusIsPending(HashMap loanStatusHashMap) { + assertTrue(getStatus(loanStatusHashMap, "pendingApproval")); + } + + public static void verifyLoanStatusIsActive(HashMap loanStatusHashMap) { + assertTrue(getStatus(loanStatusHashMap, "active")); + } + + private static void verifyLoanNeedsApproval(HashMap loanStatusHashMap) { + assertTrue(getStatus(loanStatusHashMap, "pendingApproval")); + } + + public static void verifyLoanAccountIsClosed(HashMap loanStatusHashMap){ + Assert.assertTrue(getStatus(loanStatusHashMap, "closed")); + } +} From ed95612b3f437534f24a71b3ebff1021b5ad7c31 Mon Sep 17 00:00:00 2001 From: Priti Date: Sat, 30 Mar 2013 11:07:58 +0530 Subject: [PATCH 04/21] common jsonCreator moved to Utils --- .../integrationtests/testbuilder/Utils.java | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/Utils.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/Utils.java index b665a44df..0bf5c7a46 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/Utils.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/Utils.java @@ -1,5 +1,8 @@ package org.mifosplatform.integrationtests.testbuilder; +import com.google.gson.Gson; + +import java.util.HashMap; import java.util.Random; public class Utils { @@ -20,4 +23,65 @@ public class Utils { 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); + } + + } From 5d4bbf191e7ec785fa32e6f3444db641a6946bbe Mon Sep 17 00:00:00 2001 From: Priti Date: Sat, 30 Mar 2013 11:08:16 +0530 Subject: [PATCH 05/21] Refactoring --- .../java/ClientLoanIntegrationTest.java | 92 +++---- .../LoanWithWaiveInterestAndWriteOff.java | 237 +++++------------- 2 files changed, 97 insertions(+), 232 deletions(-) diff --git a/mifosng-provider/src/integrationTest/java/ClientLoanIntegrationTest.java b/mifosng-provider/src/integrationTest/java/ClientLoanIntegrationTest.java index 9709cd442..1f21d8112 100644 --- a/mifosng-provider/src/integrationTest/java/ClientLoanIntegrationTest.java +++ b/mifosng-provider/src/integrationTest/java/ClientLoanIntegrationTest.java @@ -19,6 +19,9 @@ import com.jayway.restassured.http.ContentType; import com.jayway.restassured.path.json.JsonPath; import com.jayway.restassured.specification.RequestSpecification; import com.jayway.restassured.specification.ResponseSpecification; +import org.mifosplatform.integrationtests.testbuilder.LoanApplicationTestBuilder; +import org.mifosplatform.integrationtests.testbuilder.LoanProductTestBuilder; +import org.mifosplatform.integrationtests.testbuilder.Utils; /** * Client Loan Integration Test for checking Loan Application Repayment Schedule. @@ -43,12 +46,9 @@ public class ClientLoanIntegrationTest { public void checkClientLoanCreateAndDisburseFlow(){ Integer clientID = createClient(); - System.out.println("------------------------GENERATED CLIENT ID: "+clientID+"---------------------------\n"); checkClientCreatedOnServer(clientID); Integer loanProductID = createLoanProduct(); - System.out.println("-----------------------GENERATED LOAN PRODUCT ID : "+loanProductID+"---------------------------\n"); - applyForLoanApplication(clientID, loanProductID); ArrayList loanSchedule = getLoanRepaymentSchedule(loanProductID); @@ -64,7 +64,7 @@ public class ClientLoanIntegrationTest { private Integer createClient() { System.out.println("---------------------------------CREATING A CLIENT---------------------------------------------"); - String json = given().spec(requestSpec).body(getTestClientAsJSON()) + String json = given().spec(requestSpec).body(Utils.getTestClientAsJSON("4 March 2009")) .expect().spec(responseSpec) .when().post("/mifosng-provider/api/v1/clients?tenantIdentifier=default") .andReturn().asString(); @@ -81,7 +81,18 @@ public class ClientLoanIntegrationTest { private Integer createLoanProduct() { System.out.println("------------------------------CREATING NEW LOAN PRODUCT ---------------------------------------"); - String json = given().spec(requestSpec).body(getTestLoanProductAsJSON()) + 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(); @@ -90,7 +101,22 @@ public class ClientLoanIntegrationTest { private void applyForLoanApplication(final Integer clientID, final Integer loanProductID) { System.out.println("--------------------------------APPLYING FOR LOAN APPLICATION--------------------------------"); - given().spec(requestSpec).body(getLoanApplicationBodyAsJSON(clientID.toString(), loanProductID.toString())) + 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"); } @@ -125,61 +151,7 @@ public class ClientLoanIntegrationTest { } - private String getTestClientAsJSON() { - HashMap map = new HashMap(); - map.put("officeId", "1"); - map.put("firstname", randomNameGenerator("Client_FirstName_", 5)); - map.put("lastname", randomNameGenerator("Client_LastName_", 4)); - map.put("externalId", randomIDGenerator("ID_", 7)); - map.put("dateFormat", "dd MMMM yyyy"); - map.put("locale", "en"); - map.put("joinedDate", "04 March 2009"); - return new Gson().toJson(map); - } - private String getTestLoanProductAsJSON(){ - HashMap map = new HashMap(); - map.put("name", randomNameGenerator("LOAN_PRODUCT_", 6)); - map.put("currencyCode", "INR"); - map.put("locale", "en_GB"); - map.put("digitsAfterDecimal", "2"); - map.put("principal", "12,000.00"); - map.put("numberOfRepayments", "4"); - map.put("repaymentEvery", "1"); - map.put("repaymentFrequencyType", "2"); - map.put("interestRatePerPeriod", "2"); - map.put("interestRateFrequencyType", "2"); - map.put("amortizationType", "1"); - map.put("interestType", "0"); - map.put("interestCalculationPeriodType", "1"); - map.put("inArrearsTolerance", "0"); - map.put("transactionProcessingStrategyId", "1"); - map.put("accountingRule", "1") ; - return new Gson().toJson(map); - } - - private String getLoanApplicationBodyAsJSON(final String clientID,final String productID){ - HashMap map = new HashMap(); - map.put("dateFormat", "dd MMMM yyyy"); - map.put("locale", "en_GB"); - map.put("clientId", clientID); - 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("transactionProcessingStrategyId", "1"); - map.put("expectedDisbursementDate", "20 September 2011"); - map.put("submittedOnDate", "20 September 2011"); - return new Gson().toJson(map); - } private String getLoanCalculationBodyAsJSON(final String productID){ HashMap map = new HashMap(); diff --git a/mifosng-provider/src/integrationTest/java/LoanWithWaiveInterestAndWriteOff.java b/mifosng-provider/src/integrationTest/java/LoanWithWaiveInterestAndWriteOff.java index b45ee27fe..6db08a5e2 100644 --- a/mifosng-provider/src/integrationTest/java/LoanWithWaiveInterestAndWriteOff.java +++ b/mifosng-provider/src/integrationTest/java/LoanWithWaiveInterestAndWriteOff.java @@ -8,33 +8,43 @@ import static org.junit.Assert.assertTrue; import java.util.ArrayList; import java.util.HashMap; -import junit.framework.Assert; 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.path.json.JsonPath; import com.jayway.restassured.specification.RequestSpecification; import com.jayway.restassured.specification.ResponseSpecification; +import org.mifosplatform.integrationtests.testbuilder.LoanApplicationTestBuilder; import org.mifosplatform.integrationtests.testbuilder.LoanProductTestBuilder; +import org.mifosplatform.integrationtests.testbuilder.LoanStatusChecker; import org.mifosplatform.integrationtests.testbuilder.Utils; /** - * Client Loan Integration Test for checking Loan Disburstment with Waive Interest and Write-Off. + * 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 PRINCIPAL="4,500.00", + 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 @@ -50,7 +60,7 @@ public class LoanWithWaiveInterestAndWriteOff { @Test public void checkClientLoanCreateAndDisburseFlow(){ //CREATE CLIENT - Integer clientID = createClient(); + Integer clientID = createClient(DATE_OF_JOINING); verifyClientCreatedOnServer(clientID); //CREATE LOAN PRODUCT @@ -58,31 +68,30 @@ public class LoanWithWaiveInterestAndWriteOff { //APPLY FOR LOAN Integer loanID = applyForLoanApplication(clientID, loanProductID); HashMap loanStatusHashMap = getStatusOfLoan(loanID); - verifyLoanStatusIsPending(loanStatusHashMap); + + LoanStatusChecker.verifyLoanStatusIsPending(loanStatusHashMap); //APPROVE LOAN loanStatusHashMap = approveLoan("28 September 2010", loanID); - System.out.println("********************HASHMAP **************"+loanStatusHashMap); - verifyLoanIsApproved(loanStatusHashMap); - verifyLoanStatusIsWaitingForDisbursal(loanStatusHashMap); + LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap); + LoanStatusChecker.verifyLoanStatusIsWaitingForDisbursal(loanStatusHashMap); //UNDO APPROVAL loanStatusHashMap = undoApproval(loanID); - verifyLoanNeedsApproval(loanStatusHashMap); + LoanStatusChecker.verifyLoanStatusIsPending(loanStatusHashMap); //RE-APPROVE LOAN ON 1 OCTOBER 2010 loanStatusHashMap = approveLoan("1 October 2010", loanID); - verifyLoanIsApproved(loanStatusHashMap); - verifyLoanStatusIsWaitingForDisbursal(loanStatusHashMap); + LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap); + LoanStatusChecker.verifyLoanStatusIsWaitingForDisbursal(loanStatusHashMap); //DISBURSE loanStatusHashMap = disburseLoan(loanID); - verifyLoanStatusIsActive(loanStatusHashMap); + System.out.println("DISBURSE "+loanStatusHashMap); + LoanStatusChecker.verifyLoanStatusIsActive(loanStatusHashMap); //PERFORM REPAYMENTS AND CHECK LOAN STATUS - //----------------------------------------- -// verifyRepaymentScheduleEntryFor(1, 4000.0F, 200.0F, loanID); - + verifyRepaymentScheduleEntryFor(1, 4000.0F,loanID); makeRepayment(540.0f, "1 January 2011", loanID); makeRepayment(540.0f, "1 March 2011", loanID); waiveInterest("1 May 2011", loanID); @@ -93,43 +102,22 @@ public class LoanWithWaiveInterestAndWriteOff { makeRepayment(540.0f, "1 November 2011", loanID); waiveInterest("1 January 2012", loanID); makeRepayment(500.0f, "1 January 2012", loanID); - -// verifyRepaymentScheduleEntryFor(7, 1000.0F, 200.0F, loanID); + verifyRepaymentScheduleEntryFor(7,1000.0f,loanID); //WRITE OFF LOAN AND CHECK ACCOUNT IS CLOSED - verifyLoanAccountIsClosed(writeOffLoan("1 March 2012", loanID)); + LoanStatusChecker.verifyLoanAccountIsClosed(writeOffLoan("1 March 2012", loanID)); } - private void verifyLoanNeedsApproval(HashMap loanStatusHashMap) { - assertTrue(getStatus(loanStatusHashMap, "pendingApproval")); - } - - private void verifyLoanIsApproved(HashMap loanStatusHashMap) { - assertFalse(getStatus(loanStatusHashMap, "pendingApproval")); - } - - private void verifyLoanStatusIsWaitingForDisbursal(HashMap loanStatusHashMap) { - assertTrue(getStatus(loanStatusHashMap, "waitingForDisbursal")); - } - - private void verifyLoanStatusIsPending(HashMap loanStatusHashMap) { - assertTrue(getStatus(loanStatusHashMap, "pendingApproval")); - } - - private void verifyLoanStatusIsActive(HashMap loanStatusHashMap) { - assertTrue(getStatus(loanStatusHashMap, "active")); - } - - private void verifyRepaymentScheduleEntryFor(int repaymentNumber, float expectedPrincipal, Float expectedInterest, Integer loanID) { + private void verifyRepaymentScheduleEntryFor(int repaymentNumber, float expectedPrincipalOutstanding ,Integer loanID) { ArrayList repaymentPeriods = getLoanRepaymentSchedule(loanID); - assertEquals(repaymentPeriods.get(repaymentNumber).get("principalLoanBalanceOutstanding"), expectedPrincipal); - assertEquals(repaymentPeriods.get(repaymentNumber).get("interestLoanBalanceOutstanding"), expectedInterest); + 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(getWriteOffBodyAsJSON(transactionDate)) + 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(); @@ -139,14 +127,14 @@ public class LoanWithWaiveInterestAndWriteOff { private void waiveInterest(String transactionDate, Integer loanID){ System.out.println("--------------------Waive INTEREST On "+transactionDate+"-------------------------------\n"); - given().spec(requestSpec).body(getWaiveBodyAsJSON(transactionDate)) + 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(getRepaymentBodyAsJSON(transactionDate,transactionAmount)) + 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"); } @@ -161,14 +149,6 @@ public class LoanWithWaiveInterestAndWriteOff { return (ArrayList)repaymentSchedule.get("periods"); } - private boolean getStatus(HashMap loanStatusMap,String nameOfLoanStatusString){ - return (Boolean)loanStatusMap.get(nameOfLoanStatusString); - } - - private void verifyLoanAccountIsClosed(HashMap loanStatusHashMap){ - Assert.assertTrue(getStatus(loanStatusHashMap, "closed")); - } - private HashMap getStatusOfLoan(Integer loanID){ String json= given().spec(requestSpec) .expect().spec(responseSpec).log().ifError() @@ -188,7 +168,7 @@ public class LoanWithWaiveInterestAndWriteOff { } private HashMap disburseLoan(Integer loanID){ System.out.println("-----------------------------------DISBURSE LOAN-----------------------------------------"); - String json = given().spec(requestSpec).body(getDisburseLoanAsJSON()) + 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(); @@ -198,11 +178,10 @@ public class LoanWithWaiveInterestAndWriteOff { private HashMap approveLoan(String approvalDate, Integer loanID){ System.out.println("-----------------------------------APPROVE LOAN-----------------------------------------"); - String json =given().spec(requestSpec).body(getApproveLoanAsJSON(approvalDate)) + 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(); - System.out.println("**************CHANGES :"+from(json).get("changes")); HashMap response = from(json).get("changes"); return (HashMap)response.get("status"); } @@ -214,9 +193,9 @@ public class LoanWithWaiveInterestAndWriteOff { return JsonPath.with(json).get("base64EncodedAuthenticationKey"); } - private Integer createClient() { + private Integer createClient(String dateOfJoining) { System.out.println("---------------------------------CREATING A CLIENT---------------------------------------------"); - String json = given().spec(requestSpec).body(getTestClientAsJSON()) + String json = given().spec(requestSpec).body(Utils.getTestClientAsJSON(dateOfJoining)) .expect().spec(responseSpec).log().ifError() .when().post("/mifosng-provider/api/v1/clients?tenantIdentifier=default") .andReturn().asString(); @@ -234,10 +213,15 @@ public class LoanWithWaiveInterestAndWriteOff { private Integer createLoanProduct() { System.out.println("------------------------------CREATING NEW LOAN PRODUCT ---------------------------------------"); String loanProductJSON = new LoanProductTestBuilder() - .withPrincipal(PRINCIPAL) + .withPrincipal(LP_PRINCIPAL) .withRepaymentTypeAsMonth() - .withRepaymentAfterEvery(REPAYMENT_PERIOD) - .withNumberOfRepayments(NUMBER_OF_REPAYMENTS) + .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() @@ -248,118 +232,27 @@ public class LoanWithWaiveInterestAndWriteOff { private Integer applyForLoanApplication(final Integer clientID, final Integer loanProductID) { System.out.println("--------------------------------APPLYING FOR LOAN APPLICATION--------------------------------"); - String json = given().spec(requestSpec).body(getLoanApplicationBodyAsJSON(clientID.toString(), loanProductID.toString())) - .expect().spec(responseSpec).log().ifError() - .when().post("/mifosng-provider/api/v1/loans?tenantIdentifier=default") - .andReturn().asString(); + 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"); } - - - private 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); - } - private String getWaiveBodyAsJSON(String transactionDate){ - HashMap map = new HashMap(); - map.put("locale","en"); - map.put("dateFormat","dd MMMM yyyy"); - map.put("transactionDate",transactionDate); - map.put("transactionAmount",INTEREST_VALUE_AMOUNT); - map.put("note", " Interest Waived!!!"); - return new Gson().toJson(map); - } - private 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); - } - private 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"); - System.out.println("***************JSON ***"+new Gson().toJson(map)); - return new Gson().toJson(map); - } - - private String getDisburseLoanAsJSON(){ - HashMap map = new HashMap(); - map.put("locale","en"); - map.put("dateFormat","dd MMMM yyyy"); - map.put("actualDisbursementDate",DISBURSEMENT_DATE); - map.put("note", "DISBURSE NOTE"); - return new Gson().toJson(map); - } - - private String getTestClientAsJSON() { - 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", "04 March 2009"); - System.out.println("map : "+map); - return new Gson().toJson(map); - } - - - private String getLoanApplicationBodyAsJSON(final String clientID,final String productID){ - HashMap map = new HashMap(); - map.put("dateFormat", "dd MMMM yyyy"); - map.put("locale", "en_GB"); - map.put("clientId", clientID); - map.put("productId", productID); - map.put("principal", PRINCIPAL); - map.put("loanTermFrequency", "4"); - map.put("loanTermFrequencyType", "2"); - map.put("numberOfRepayments", NUMBER_OF_REPAYMENTS); - map.put("repaymentEvery", REPAYMENT_PERIOD); - map.put("repaymentFrequencyType", "2"); - map.put("interestRateFrequencyType", "2"); - map.put("interestRatePerPeriod", "2"); - map.put("amortizationType", "1"); - map.put("interestType", "1"); - map.put("interestCalculationPeriodType", "1"); - map.put("transactionProcessingStrategyId", "1"); - map.put("expectedDisbursementDate", DISBURSEMENT_DATE); - map.put("submittedOnDate", LOAN_APPLICATION_SUBMISSION_DATE); - return new Gson().toJson(map); - } - - private String getLoanCalculationBodyAsJSON(String productID){ - HashMap map = new HashMap(); - map.put("dateFormat", "dd MMMM yyyy"); - map.put("locale", "en_GB"); - map.put("productId", productID); - map.put("principal", PRINCIPAL); - map.put("loanTermFrequency", "4"); - map.put("loanTermFrequencyType", "2"); - map.put("numberOfRepayments", NUMBER_OF_REPAYMENTS); - map.put("repaymentEvery", REPAYMENT_PERIOD); - map.put("repaymentFrequencyType", "2"); - map.put("interestRateFrequencyType", "2"); - map.put("interestRatePerPeriod", "2"); - map.put("amortizationType", "1"); - map.put("interestType", "1"); - map.put("interestCalculationPeriodType", "1"); - map.put("expectedDisbursementDate", DISBURSEMENT_DATE); - map.put("transactionProcessingStrategyId", "1"); - return new Gson().toJson(map); - } - - } From 02a3934e9ff02ecbe1aa79f237b85d406590862f Mon Sep 17 00:00:00 2001 From: Priti Date: Thu, 28 Mar 2013 21:57:28 +0530 Subject: [PATCH 06/21] 1.Integration Test : LoanWithWaiveInterest added 2. LoanProduct Builder created 3. RandomGenerator methods moved to Util file --- .../LoanWithWaiveInterestAndWriteOff.java | 2721 +++++++++++++++++ .../testbuilder/LoanProductTestBuilder.java | 166 + .../integrationtests/testbuilder/Utils.java | 23 + 3 files changed, 2910 insertions(+) create mode 100644 mifosng-provider/src/integrationTest/java/LoanWithWaiveInterestAndWriteOff.java create mode 100644 mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/LoanProductTestBuilder.java create mode 100644 mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/Utils.java diff --git a/mifosng-provider/src/integrationTest/java/LoanWithWaiveInterestAndWriteOff.java b/mifosng-provider/src/integrationTest/java/LoanWithWaiveInterestAndWriteOff.java new file mode 100644 index 000000000..b45ee27fe --- /dev/null +++ b/mifosng-provider/src/integrationTest/java/LoanWithWaiveInterestAndWriteOff.java @@ -0,0 +1,2721 @@ +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 junit.framework.Assert; +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.path.json.JsonPath; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; +import org.mifosplatform.integrationtests.testbuilder.LoanProductTestBuilder; +import org.mifosplatform.integrationtests.testbuilder.Utils; + +/** + * Client Loan Integration Test for checking Loan Disburstment with Waive Interest and Write-Off. + */ +@SuppressWarnings({ "rawtypes", "unchecked" }) +public class LoanWithWaiveInterestAndWriteOff { + + ResponseSpecification responseSpec; + RequestSpecification requestSpec; + final String PRINCIPAL="4,500.00", + NUMBER_OF_REPAYMENTS="9", + REPAYMENT_PERIOD="2", + DISBURSEMENT_DATE="30 October 2010", + LOAN_APPLICATION_SUBMISSION_DATE="23 September 2010", + INTEREST_VALUE_AMOUNT = "40.00"; + + @Before + public void setup() { + String basicAuthKey = loginIntoServerAndGetBase64EncodedAuthenticationKey(); + + requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build(); + requestSpec.header("Authorization","Basic "+basicAuthKey); + + responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); + } + + @Test + public void checkClientLoanCreateAndDisburseFlow(){ + //CREATE CLIENT + Integer clientID = createClient(); + verifyClientCreatedOnServer(clientID); + + //CREATE LOAN PRODUCT + Integer loanProductID = createLoanProduct(); + //APPLY FOR LOAN + Integer loanID = applyForLoanApplication(clientID, loanProductID); + HashMap loanStatusHashMap = getStatusOfLoan(loanID); + verifyLoanStatusIsPending(loanStatusHashMap); + + //APPROVE LOAN + loanStatusHashMap = approveLoan("28 September 2010", loanID); + System.out.println("********************HASHMAP **************"+loanStatusHashMap); + verifyLoanIsApproved(loanStatusHashMap); + verifyLoanStatusIsWaitingForDisbursal(loanStatusHashMap); + + //UNDO APPROVAL + loanStatusHashMap = undoApproval(loanID); + verifyLoanNeedsApproval(loanStatusHashMap); + + //RE-APPROVE LOAN ON 1 OCTOBER 2010 + loanStatusHashMap = approveLoan("1 October 2010", loanID); + verifyLoanIsApproved(loanStatusHashMap); + verifyLoanStatusIsWaitingForDisbursal(loanStatusHashMap); + + //DISBURSE + loanStatusHashMap = disburseLoan(loanID); + verifyLoanStatusIsActive(loanStatusHashMap); + + //PERFORM REPAYMENTS AND CHECK LOAN STATUS + //----------------------------------------- +// verifyRepaymentScheduleEntryFor(1, 4000.0F, 200.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, 200.0F, loanID); + + //WRITE OFF LOAN AND CHECK ACCOUNT IS CLOSED + verifyLoanAccountIsClosed(writeOffLoan("1 March 2012", loanID)); + + } + + private void verifyLoanNeedsApproval(HashMap loanStatusHashMap) { + assertTrue(getStatus(loanStatusHashMap, "pendingApproval")); + } + + private void verifyLoanIsApproved(HashMap loanStatusHashMap) { + assertFalse(getStatus(loanStatusHashMap, "pendingApproval")); + } + + private void verifyLoanStatusIsWaitingForDisbursal(HashMap loanStatusHashMap) { + assertTrue(getStatus(loanStatusHashMap, "waitingForDisbursal")); + } + + private void verifyLoanStatusIsPending(HashMap loanStatusHashMap) { + assertTrue(getStatus(loanStatusHashMap, "pendingApproval")); + } + + private void verifyLoanStatusIsActive(HashMap loanStatusHashMap) { + assertTrue(getStatus(loanStatusHashMap, "active")); + } + + private void verifyRepaymentScheduleEntryFor(int repaymentNumber, float expectedPrincipal, Float expectedInterest, Integer loanID) { + ArrayList repaymentPeriods = getLoanRepaymentSchedule(loanID); + assertEquals(repaymentPeriods.get(repaymentNumber).get("principalLoanBalanceOutstanding"), expectedPrincipal); + assertEquals(repaymentPeriods.get(repaymentNumber).get("interestLoanBalanceOutstanding"), expectedInterest); + } + + private HashMap writeOffLoan(String transactionDate, Integer loanID){ + System.out.println("--------------------LOAN WRITTEN OFF ON "+transactionDate+"-------------------------------\n"); + String json = given().spec(requestSpec).body(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(getWaiveBodyAsJSON(transactionDate)) + .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(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 boolean getStatus(HashMap loanStatusMap,String nameOfLoanStatusString){ + return (Boolean)loanStatusMap.get(nameOfLoanStatusString); + } + + private void verifyLoanAccountIsClosed(HashMap loanStatusHashMap){ + Assert.assertTrue(getStatus(loanStatusHashMap, "closed")); + } + + 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(getDisburseLoanAsJSON()) + .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(getApproveLoanAsJSON(approvalDate)) + .expect().spec(responseSpec).log().ifError() + .when().post("/mifosng-provider/api/v1/loans/"+ loanID +"?command=approve&tenantIdentifier=default") + .andReturn().asString(); + System.out.println("**************CHANGES :"+from(json).get("changes")); + HashMap response = from(json).get("changes"); + return (HashMap)response.get("status"); + } + + + private 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"); + } + + private Integer createClient() { + System.out.println("---------------------------------CREATING A CLIENT---------------------------------------------"); + String json = given().spec(requestSpec).body(getTestClientAsJSON()) + .expect().spec(responseSpec).log().ifError() + .when().post("/mifosng-provider/api/v1/clients?tenantIdentifier=default") + .andReturn().asString(); + + return from(json).get("clientId"); + } + + 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(PRINCIPAL) + .withRepaymentTypeAsMonth() + .withRepaymentAfterEvery(REPAYMENT_PERIOD) + .withNumberOfRepayments(NUMBER_OF_REPAYMENTS) + .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 json = given().spec(requestSpec).body(getLoanApplicationBodyAsJSON(clientID.toString(), loanProductID.toString())) + .expect().spec(responseSpec).log().ifError() + .when().post("/mifosng-provider/api/v1/loans?tenantIdentifier=default") + .andReturn().asString(); + return from(json).get("loanId"); + } + + + private 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); + } + private String getWaiveBodyAsJSON(String transactionDate){ + HashMap map = new HashMap(); + map.put("locale","en"); + map.put("dateFormat","dd MMMM yyyy"); + map.put("transactionDate",transactionDate); + map.put("transactionAmount",INTEREST_VALUE_AMOUNT); + map.put("note", " Interest Waived!!!"); + return new Gson().toJson(map); + } + private 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); + } + private 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"); + System.out.println("***************JSON ***"+new Gson().toJson(map)); + return new Gson().toJson(map); + } + + private String getDisburseLoanAsJSON(){ + HashMap map = new HashMap(); + map.put("locale","en"); + map.put("dateFormat","dd MMMM yyyy"); + map.put("actualDisbursementDate",DISBURSEMENT_DATE); + map.put("note", "DISBURSE NOTE"); + return new Gson().toJson(map); + } + + private String getTestClientAsJSON() { + 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", "04 March 2009"); + System.out.println("map : "+map); + return new Gson().toJson(map); + } + + + private String getLoanApplicationBodyAsJSON(final String clientID,final String productID){ + HashMap map = new HashMap(); + map.put("dateFormat", "dd MMMM yyyy"); + map.put("locale", "en_GB"); + map.put("clientId", clientID); + map.put("productId", productID); + map.put("principal", PRINCIPAL); + map.put("loanTermFrequency", "4"); + map.put("loanTermFrequencyType", "2"); + map.put("numberOfRepayments", NUMBER_OF_REPAYMENTS); + map.put("repaymentEvery", REPAYMENT_PERIOD); + map.put("repaymentFrequencyType", "2"); + map.put("interestRateFrequencyType", "2"); + map.put("interestRatePerPeriod", "2"); + map.put("amortizationType", "1"); + map.put("interestType", "1"); + map.put("interestCalculationPeriodType", "1"); + map.put("transactionProcessingStrategyId", "1"); + map.put("expectedDisbursementDate", DISBURSEMENT_DATE); + map.put("submittedOnDate", LOAN_APPLICATION_SUBMISSION_DATE); + return new Gson().toJson(map); + } + + private String getLoanCalculationBodyAsJSON(String productID){ + HashMap map = new HashMap(); + map.put("dateFormat", "dd MMMM yyyy"); + map.put("locale", "en_GB"); + map.put("productId", productID); + map.put("principal", PRINCIPAL); + map.put("loanTermFrequency", "4"); + map.put("loanTermFrequencyType", "2"); + map.put("numberOfRepayments", NUMBER_OF_REPAYMENTS); + map.put("repaymentEvery", REPAYMENT_PERIOD); + map.put("repaymentFrequencyType", "2"); + map.put("interestRateFrequencyType", "2"); + map.put("interestRatePerPeriod", "2"); + map.put("amortizationType", "1"); + map.put("interestType", "1"); + map.put("interestCalculationPeriodType", "1"); + map.put("expectedDisbursementDate", DISBURSEMENT_DATE); + map.put("transactionProcessingStrategyId", "1"); + return new Gson().toJson(map); + } + + +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/LoanProductTestBuilder.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/LoanProductTestBuilder.java new file mode 100644 index 000000000..9ebd1879f --- /dev/null +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/LoanProductTestBuilder.java @@ -0,0 +1,166 @@ +package org.mifosplatform.integrationtests.testbuilder; + +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/testbuilder/Utils.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/Utils.java new file mode 100644 index 000000000..b665a44df --- /dev/null +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/Utils.java @@ -0,0 +1,23 @@ +package org.mifosplatform.integrationtests.testbuilder; + +import java.util.Random; + +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"); + } +} From e555666ac2ac9d32863a6736ded4ea852ec4e88a Mon Sep 17 00:00:00 2001 From: Priti Date: Sat, 30 Mar 2013 11:06:02 +0530 Subject: [PATCH 07/21] Builder for LoanApplication Added --- .../LoanApplicationTestBuilder.java | 163 ++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/LoanApplicationTestBuilder.java diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/LoanApplicationTestBuilder.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/LoanApplicationTestBuilder.java new file mode 100644 index 000000000..d11b689aa --- /dev/null +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/LoanApplicationTestBuilder.java @@ -0,0 +1,163 @@ +package org.mifosplatform.integrationtests.testbuilder; + +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; + } +} From 4a2f7a0597c6a4f6ac7a4995e8affb7d35720957 Mon Sep 17 00:00:00 2001 From: Priti Date: Sat, 30 Mar 2013 11:07:21 +0530 Subject: [PATCH 08/21] LoanStatusChecker added which checks the loan status --- .../testbuilder/LoanStatusChecker.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/LoanStatusChecker.java diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/LoanStatusChecker.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/LoanStatusChecker.java new file mode 100644 index 000000000..7bd8dd0c3 --- /dev/null +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/LoanStatusChecker.java @@ -0,0 +1,39 @@ +package org.mifosplatform.integrationtests.testbuilder; + +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 verifyLoanStatusIsWaitingForDisbursal(HashMap loanStatusHashMap) { + assertTrue(getStatus(loanStatusHashMap, "waitingForDisbursal")); + } + + public static void verifyLoanStatusIsPending(HashMap loanStatusHashMap) { + assertTrue(getStatus(loanStatusHashMap, "pendingApproval")); + } + + public static void verifyLoanStatusIsActive(HashMap loanStatusHashMap) { + assertTrue(getStatus(loanStatusHashMap, "active")); + } + + private static void verifyLoanNeedsApproval(HashMap loanStatusHashMap) { + assertTrue(getStatus(loanStatusHashMap, "pendingApproval")); + } + + public static void verifyLoanAccountIsClosed(HashMap loanStatusHashMap){ + Assert.assertTrue(getStatus(loanStatusHashMap, "closed")); + } +} From d58fa92f3eb73c5653158da09e847802e2ffd2d4 Mon Sep 17 00:00:00 2001 From: Priti Date: Sat, 30 Mar 2013 11:07:58 +0530 Subject: [PATCH 09/21] common jsonCreator moved to Utils --- .../integrationtests/testbuilder/Utils.java | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/Utils.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/Utils.java index b665a44df..0bf5c7a46 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/Utils.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/Utils.java @@ -1,5 +1,8 @@ package org.mifosplatform.integrationtests.testbuilder; +import com.google.gson.Gson; + +import java.util.HashMap; import java.util.Random; public class Utils { @@ -20,4 +23,65 @@ public class Utils { 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); + } + + } From 23ed73316d18299de58280207797fe08eac35f24 Mon Sep 17 00:00:00 2001 From: Priti Date: Sat, 30 Mar 2013 11:08:16 +0530 Subject: [PATCH 10/21] Refactoring --- .../java/ClientLoanIntegrationTest.java | 92 +++---- .../LoanWithWaiveInterestAndWriteOff.java | 237 +++++------------- 2 files changed, 97 insertions(+), 232 deletions(-) diff --git a/mifosng-provider/src/integrationTest/java/ClientLoanIntegrationTest.java b/mifosng-provider/src/integrationTest/java/ClientLoanIntegrationTest.java index 9709cd442..1f21d8112 100644 --- a/mifosng-provider/src/integrationTest/java/ClientLoanIntegrationTest.java +++ b/mifosng-provider/src/integrationTest/java/ClientLoanIntegrationTest.java @@ -19,6 +19,9 @@ import com.jayway.restassured.http.ContentType; import com.jayway.restassured.path.json.JsonPath; import com.jayway.restassured.specification.RequestSpecification; import com.jayway.restassured.specification.ResponseSpecification; +import org.mifosplatform.integrationtests.testbuilder.LoanApplicationTestBuilder; +import org.mifosplatform.integrationtests.testbuilder.LoanProductTestBuilder; +import org.mifosplatform.integrationtests.testbuilder.Utils; /** * Client Loan Integration Test for checking Loan Application Repayment Schedule. @@ -43,12 +46,9 @@ public class ClientLoanIntegrationTest { public void checkClientLoanCreateAndDisburseFlow(){ Integer clientID = createClient(); - System.out.println("------------------------GENERATED CLIENT ID: "+clientID+"---------------------------\n"); checkClientCreatedOnServer(clientID); Integer loanProductID = createLoanProduct(); - System.out.println("-----------------------GENERATED LOAN PRODUCT ID : "+loanProductID+"---------------------------\n"); - applyForLoanApplication(clientID, loanProductID); ArrayList loanSchedule = getLoanRepaymentSchedule(loanProductID); @@ -64,7 +64,7 @@ public class ClientLoanIntegrationTest { private Integer createClient() { System.out.println("---------------------------------CREATING A CLIENT---------------------------------------------"); - String json = given().spec(requestSpec).body(getTestClientAsJSON()) + String json = given().spec(requestSpec).body(Utils.getTestClientAsJSON("4 March 2009")) .expect().spec(responseSpec) .when().post("/mifosng-provider/api/v1/clients?tenantIdentifier=default") .andReturn().asString(); @@ -81,7 +81,18 @@ public class ClientLoanIntegrationTest { private Integer createLoanProduct() { System.out.println("------------------------------CREATING NEW LOAN PRODUCT ---------------------------------------"); - String json = given().spec(requestSpec).body(getTestLoanProductAsJSON()) + 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(); @@ -90,7 +101,22 @@ public class ClientLoanIntegrationTest { private void applyForLoanApplication(final Integer clientID, final Integer loanProductID) { System.out.println("--------------------------------APPLYING FOR LOAN APPLICATION--------------------------------"); - given().spec(requestSpec).body(getLoanApplicationBodyAsJSON(clientID.toString(), loanProductID.toString())) + 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"); } @@ -125,61 +151,7 @@ public class ClientLoanIntegrationTest { } - private String getTestClientAsJSON() { - HashMap map = new HashMap(); - map.put("officeId", "1"); - map.put("firstname", randomNameGenerator("Client_FirstName_", 5)); - map.put("lastname", randomNameGenerator("Client_LastName_", 4)); - map.put("externalId", randomIDGenerator("ID_", 7)); - map.put("dateFormat", "dd MMMM yyyy"); - map.put("locale", "en"); - map.put("joinedDate", "04 March 2009"); - return new Gson().toJson(map); - } - private String getTestLoanProductAsJSON(){ - HashMap map = new HashMap(); - map.put("name", randomNameGenerator("LOAN_PRODUCT_", 6)); - map.put("currencyCode", "INR"); - map.put("locale", "en_GB"); - map.put("digitsAfterDecimal", "2"); - map.put("principal", "12,000.00"); - map.put("numberOfRepayments", "4"); - map.put("repaymentEvery", "1"); - map.put("repaymentFrequencyType", "2"); - map.put("interestRatePerPeriod", "2"); - map.put("interestRateFrequencyType", "2"); - map.put("amortizationType", "1"); - map.put("interestType", "0"); - map.put("interestCalculationPeriodType", "1"); - map.put("inArrearsTolerance", "0"); - map.put("transactionProcessingStrategyId", "1"); - map.put("accountingRule", "1") ; - return new Gson().toJson(map); - } - - private String getLoanApplicationBodyAsJSON(final String clientID,final String productID){ - HashMap map = new HashMap(); - map.put("dateFormat", "dd MMMM yyyy"); - map.put("locale", "en_GB"); - map.put("clientId", clientID); - 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("transactionProcessingStrategyId", "1"); - map.put("expectedDisbursementDate", "20 September 2011"); - map.put("submittedOnDate", "20 September 2011"); - return new Gson().toJson(map); - } private String getLoanCalculationBodyAsJSON(final String productID){ HashMap map = new HashMap(); diff --git a/mifosng-provider/src/integrationTest/java/LoanWithWaiveInterestAndWriteOff.java b/mifosng-provider/src/integrationTest/java/LoanWithWaiveInterestAndWriteOff.java index b45ee27fe..6db08a5e2 100644 --- a/mifosng-provider/src/integrationTest/java/LoanWithWaiveInterestAndWriteOff.java +++ b/mifosng-provider/src/integrationTest/java/LoanWithWaiveInterestAndWriteOff.java @@ -8,33 +8,43 @@ import static org.junit.Assert.assertTrue; import java.util.ArrayList; import java.util.HashMap; -import junit.framework.Assert; 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.path.json.JsonPath; import com.jayway.restassured.specification.RequestSpecification; import com.jayway.restassured.specification.ResponseSpecification; +import org.mifosplatform.integrationtests.testbuilder.LoanApplicationTestBuilder; import org.mifosplatform.integrationtests.testbuilder.LoanProductTestBuilder; +import org.mifosplatform.integrationtests.testbuilder.LoanStatusChecker; import org.mifosplatform.integrationtests.testbuilder.Utils; /** - * Client Loan Integration Test for checking Loan Disburstment with Waive Interest and Write-Off. + * 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 PRINCIPAL="4,500.00", + 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 @@ -50,7 +60,7 @@ public class LoanWithWaiveInterestAndWriteOff { @Test public void checkClientLoanCreateAndDisburseFlow(){ //CREATE CLIENT - Integer clientID = createClient(); + Integer clientID = createClient(DATE_OF_JOINING); verifyClientCreatedOnServer(clientID); //CREATE LOAN PRODUCT @@ -58,31 +68,30 @@ public class LoanWithWaiveInterestAndWriteOff { //APPLY FOR LOAN Integer loanID = applyForLoanApplication(clientID, loanProductID); HashMap loanStatusHashMap = getStatusOfLoan(loanID); - verifyLoanStatusIsPending(loanStatusHashMap); + + LoanStatusChecker.verifyLoanStatusIsPending(loanStatusHashMap); //APPROVE LOAN loanStatusHashMap = approveLoan("28 September 2010", loanID); - System.out.println("********************HASHMAP **************"+loanStatusHashMap); - verifyLoanIsApproved(loanStatusHashMap); - verifyLoanStatusIsWaitingForDisbursal(loanStatusHashMap); + LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap); + LoanStatusChecker.verifyLoanStatusIsWaitingForDisbursal(loanStatusHashMap); //UNDO APPROVAL loanStatusHashMap = undoApproval(loanID); - verifyLoanNeedsApproval(loanStatusHashMap); + LoanStatusChecker.verifyLoanStatusIsPending(loanStatusHashMap); //RE-APPROVE LOAN ON 1 OCTOBER 2010 loanStatusHashMap = approveLoan("1 October 2010", loanID); - verifyLoanIsApproved(loanStatusHashMap); - verifyLoanStatusIsWaitingForDisbursal(loanStatusHashMap); + LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap); + LoanStatusChecker.verifyLoanStatusIsWaitingForDisbursal(loanStatusHashMap); //DISBURSE loanStatusHashMap = disburseLoan(loanID); - verifyLoanStatusIsActive(loanStatusHashMap); + System.out.println("DISBURSE "+loanStatusHashMap); + LoanStatusChecker.verifyLoanStatusIsActive(loanStatusHashMap); //PERFORM REPAYMENTS AND CHECK LOAN STATUS - //----------------------------------------- -// verifyRepaymentScheduleEntryFor(1, 4000.0F, 200.0F, loanID); - + verifyRepaymentScheduleEntryFor(1, 4000.0F,loanID); makeRepayment(540.0f, "1 January 2011", loanID); makeRepayment(540.0f, "1 March 2011", loanID); waiveInterest("1 May 2011", loanID); @@ -93,43 +102,22 @@ public class LoanWithWaiveInterestAndWriteOff { makeRepayment(540.0f, "1 November 2011", loanID); waiveInterest("1 January 2012", loanID); makeRepayment(500.0f, "1 January 2012", loanID); - -// verifyRepaymentScheduleEntryFor(7, 1000.0F, 200.0F, loanID); + verifyRepaymentScheduleEntryFor(7,1000.0f,loanID); //WRITE OFF LOAN AND CHECK ACCOUNT IS CLOSED - verifyLoanAccountIsClosed(writeOffLoan("1 March 2012", loanID)); + LoanStatusChecker.verifyLoanAccountIsClosed(writeOffLoan("1 March 2012", loanID)); } - private void verifyLoanNeedsApproval(HashMap loanStatusHashMap) { - assertTrue(getStatus(loanStatusHashMap, "pendingApproval")); - } - - private void verifyLoanIsApproved(HashMap loanStatusHashMap) { - assertFalse(getStatus(loanStatusHashMap, "pendingApproval")); - } - - private void verifyLoanStatusIsWaitingForDisbursal(HashMap loanStatusHashMap) { - assertTrue(getStatus(loanStatusHashMap, "waitingForDisbursal")); - } - - private void verifyLoanStatusIsPending(HashMap loanStatusHashMap) { - assertTrue(getStatus(loanStatusHashMap, "pendingApproval")); - } - - private void verifyLoanStatusIsActive(HashMap loanStatusHashMap) { - assertTrue(getStatus(loanStatusHashMap, "active")); - } - - private void verifyRepaymentScheduleEntryFor(int repaymentNumber, float expectedPrincipal, Float expectedInterest, Integer loanID) { + private void verifyRepaymentScheduleEntryFor(int repaymentNumber, float expectedPrincipalOutstanding ,Integer loanID) { ArrayList repaymentPeriods = getLoanRepaymentSchedule(loanID); - assertEquals(repaymentPeriods.get(repaymentNumber).get("principalLoanBalanceOutstanding"), expectedPrincipal); - assertEquals(repaymentPeriods.get(repaymentNumber).get("interestLoanBalanceOutstanding"), expectedInterest); + 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(getWriteOffBodyAsJSON(transactionDate)) + 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(); @@ -139,14 +127,14 @@ public class LoanWithWaiveInterestAndWriteOff { private void waiveInterest(String transactionDate, Integer loanID){ System.out.println("--------------------Waive INTEREST On "+transactionDate+"-------------------------------\n"); - given().spec(requestSpec).body(getWaiveBodyAsJSON(transactionDate)) + 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(getRepaymentBodyAsJSON(transactionDate,transactionAmount)) + 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"); } @@ -161,14 +149,6 @@ public class LoanWithWaiveInterestAndWriteOff { return (ArrayList)repaymentSchedule.get("periods"); } - private boolean getStatus(HashMap loanStatusMap,String nameOfLoanStatusString){ - return (Boolean)loanStatusMap.get(nameOfLoanStatusString); - } - - private void verifyLoanAccountIsClosed(HashMap loanStatusHashMap){ - Assert.assertTrue(getStatus(loanStatusHashMap, "closed")); - } - private HashMap getStatusOfLoan(Integer loanID){ String json= given().spec(requestSpec) .expect().spec(responseSpec).log().ifError() @@ -188,7 +168,7 @@ public class LoanWithWaiveInterestAndWriteOff { } private HashMap disburseLoan(Integer loanID){ System.out.println("-----------------------------------DISBURSE LOAN-----------------------------------------"); - String json = given().spec(requestSpec).body(getDisburseLoanAsJSON()) + 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(); @@ -198,11 +178,10 @@ public class LoanWithWaiveInterestAndWriteOff { private HashMap approveLoan(String approvalDate, Integer loanID){ System.out.println("-----------------------------------APPROVE LOAN-----------------------------------------"); - String json =given().spec(requestSpec).body(getApproveLoanAsJSON(approvalDate)) + 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(); - System.out.println("**************CHANGES :"+from(json).get("changes")); HashMap response = from(json).get("changes"); return (HashMap)response.get("status"); } @@ -214,9 +193,9 @@ public class LoanWithWaiveInterestAndWriteOff { return JsonPath.with(json).get("base64EncodedAuthenticationKey"); } - private Integer createClient() { + private Integer createClient(String dateOfJoining) { System.out.println("---------------------------------CREATING A CLIENT---------------------------------------------"); - String json = given().spec(requestSpec).body(getTestClientAsJSON()) + String json = given().spec(requestSpec).body(Utils.getTestClientAsJSON(dateOfJoining)) .expect().spec(responseSpec).log().ifError() .when().post("/mifosng-provider/api/v1/clients?tenantIdentifier=default") .andReturn().asString(); @@ -234,10 +213,15 @@ public class LoanWithWaiveInterestAndWriteOff { private Integer createLoanProduct() { System.out.println("------------------------------CREATING NEW LOAN PRODUCT ---------------------------------------"); String loanProductJSON = new LoanProductTestBuilder() - .withPrincipal(PRINCIPAL) + .withPrincipal(LP_PRINCIPAL) .withRepaymentTypeAsMonth() - .withRepaymentAfterEvery(REPAYMENT_PERIOD) - .withNumberOfRepayments(NUMBER_OF_REPAYMENTS) + .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() @@ -248,118 +232,27 @@ public class LoanWithWaiveInterestAndWriteOff { private Integer applyForLoanApplication(final Integer clientID, final Integer loanProductID) { System.out.println("--------------------------------APPLYING FOR LOAN APPLICATION--------------------------------"); - String json = given().spec(requestSpec).body(getLoanApplicationBodyAsJSON(clientID.toString(), loanProductID.toString())) - .expect().spec(responseSpec).log().ifError() - .when().post("/mifosng-provider/api/v1/loans?tenantIdentifier=default") - .andReturn().asString(); + 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"); } - - - private 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); - } - private String getWaiveBodyAsJSON(String transactionDate){ - HashMap map = new HashMap(); - map.put("locale","en"); - map.put("dateFormat","dd MMMM yyyy"); - map.put("transactionDate",transactionDate); - map.put("transactionAmount",INTEREST_VALUE_AMOUNT); - map.put("note", " Interest Waived!!!"); - return new Gson().toJson(map); - } - private 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); - } - private 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"); - System.out.println("***************JSON ***"+new Gson().toJson(map)); - return new Gson().toJson(map); - } - - private String getDisburseLoanAsJSON(){ - HashMap map = new HashMap(); - map.put("locale","en"); - map.put("dateFormat","dd MMMM yyyy"); - map.put("actualDisbursementDate",DISBURSEMENT_DATE); - map.put("note", "DISBURSE NOTE"); - return new Gson().toJson(map); - } - - private String getTestClientAsJSON() { - 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", "04 March 2009"); - System.out.println("map : "+map); - return new Gson().toJson(map); - } - - - private String getLoanApplicationBodyAsJSON(final String clientID,final String productID){ - HashMap map = new HashMap(); - map.put("dateFormat", "dd MMMM yyyy"); - map.put("locale", "en_GB"); - map.put("clientId", clientID); - map.put("productId", productID); - map.put("principal", PRINCIPAL); - map.put("loanTermFrequency", "4"); - map.put("loanTermFrequencyType", "2"); - map.put("numberOfRepayments", NUMBER_OF_REPAYMENTS); - map.put("repaymentEvery", REPAYMENT_PERIOD); - map.put("repaymentFrequencyType", "2"); - map.put("interestRateFrequencyType", "2"); - map.put("interestRatePerPeriod", "2"); - map.put("amortizationType", "1"); - map.put("interestType", "1"); - map.put("interestCalculationPeriodType", "1"); - map.put("transactionProcessingStrategyId", "1"); - map.put("expectedDisbursementDate", DISBURSEMENT_DATE); - map.put("submittedOnDate", LOAN_APPLICATION_SUBMISSION_DATE); - return new Gson().toJson(map); - } - - private String getLoanCalculationBodyAsJSON(String productID){ - HashMap map = new HashMap(); - map.put("dateFormat", "dd MMMM yyyy"); - map.put("locale", "en_GB"); - map.put("productId", productID); - map.put("principal", PRINCIPAL); - map.put("loanTermFrequency", "4"); - map.put("loanTermFrequencyType", "2"); - map.put("numberOfRepayments", NUMBER_OF_REPAYMENTS); - map.put("repaymentEvery", REPAYMENT_PERIOD); - map.put("repaymentFrequencyType", "2"); - map.put("interestRateFrequencyType", "2"); - map.put("interestRatePerPeriod", "2"); - map.put("amortizationType", "1"); - map.put("interestType", "1"); - map.put("interestCalculationPeriodType", "1"); - map.put("expectedDisbursementDate", DISBURSEMENT_DATE); - map.put("transactionProcessingStrategyId", "1"); - return new Gson().toJson(map); - } - - } From 419f127cd806788d0a6d7f1f43b656e98451a8b9 Mon Sep 17 00:00:00 2001 From: Priti Date: Mon, 1 Apr 2013 16:46:14 +0530 Subject: [PATCH 11/21] [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"); + } +} From f08da673f26ed2d62f9f216dfe1ca7a77f839870 Mon Sep 17 00:00:00 2001 From: Priti Date: Mon, 1 Apr 2013 16:47:24 +0530 Subject: [PATCH 12/21] [Priti/Sailee] Renamed package as common --- .../java/ClientLoanIntegrationTest.java | 2554 ---------------- .../LoanWithWaiveInterestAndWriteOff.java | 2614 ----------------- .../LoanApplicationTestBuilder.java | 163 - .../testbuilder/LoanProductTestBuilder.java | 166 -- .../testbuilder/LoanStatusChecker.java | 39 - .../integrationtests/testbuilder/Utils.java | 87 - 6 files changed, 5623 deletions(-) delete mode 100644 mifosng-provider/src/integrationTest/java/ClientLoanIntegrationTest.java delete mode 100644 mifosng-provider/src/integrationTest/java/LoanWithWaiveInterestAndWriteOff.java delete mode 100644 mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/LoanApplicationTestBuilder.java delete mode 100644 mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/LoanProductTestBuilder.java delete mode 100644 mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/LoanStatusChecker.java delete mode 100644 mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/Utils.java diff --git a/mifosng-provider/src/integrationTest/java/ClientLoanIntegrationTest.java b/mifosng-provider/src/integrationTest/java/ClientLoanIntegrationTest.java deleted file mode 100644 index 1f21d8112..000000000 --- a/mifosng-provider/src/integrationTest/java/ClientLoanIntegrationTest.java +++ /dev/null @@ -1,2554 +0,0 @@ - -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 java.util.Random; - -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.path.json.JsonPath; -import com.jayway.restassured.specification.RequestSpecification; -import com.jayway.restassured.specification.ResponseSpecification; -import org.mifosplatform.integrationtests.testbuilder.LoanApplicationTestBuilder; -import org.mifosplatform.integrationtests.testbuilder.LoanProductTestBuilder; -import org.mifosplatform.integrationtests.testbuilder.Utils; - -/** - * Client Loan Integration Test for checking Loan Application Repayment Schedule. - */ -@SuppressWarnings({ "rawtypes", "unchecked" }) -public class ClientLoanIntegrationTest { - String basicAuthKey; - ResponseSpecification responseSpec; - RequestSpecification requestSpec; - - @Before - public void setup() { - basicAuthKey = loginIntoServerAndGetBase64EncodedAuthenticationKey(); - - requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build(); - requestSpec.header("Authorization","Basic "+basicAuthKey); - - responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); - } - - @Test - public void checkClientLoanCreateAndDisburseFlow(){ - - Integer clientID = createClient(); - checkClientCreatedOnServer(clientID); - - Integer loanProductID = createLoanProduct(); - applyForLoanApplication(clientID, loanProductID); - - ArrayList loanSchedule = getLoanRepaymentSchedule(loanProductID); - verifyLoanRepaymentSchedule(loanSchedule); - - } - - private 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"); - } - - private Integer createClient() { - System.out.println("---------------------------------CREATING A CLIENT---------------------------------------------"); - String json = given().spec(requestSpec).body(Utils.getTestClientAsJSON("4 March 2009")) - .expect().spec(responseSpec) - .when().post("/mifosng-provider/api/v1/clients?tenantIdentifier=default") - .andReturn().asString(); - - return from(json).get("clientId"); - } - - 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); - } - - public String randomIDGenerator(final String prefix, final int lenOfRandomSuffix) { - return randomStringGenerator(prefix,lenOfRandomSuffix, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"); - } - - public String randomNameGenerator(final String prefix, final int lenOfRandomSuffix) { - return randomStringGenerator(prefix,lenOfRandomSuffix, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"); - } - - private 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())); - } - - - -} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/mifosng-provider/src/integrationTest/java/LoanWithWaiveInterestAndWriteOff.java b/mifosng-provider/src/integrationTest/java/LoanWithWaiveInterestAndWriteOff.java deleted file mode 100644 index 6db08a5e2..000000000 --- a/mifosng-provider/src/integrationTest/java/LoanWithWaiveInterestAndWriteOff.java +++ /dev/null @@ -1,2614 +0,0 @@ -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.path.json.JsonPath; -import com.jayway.restassured.specification.RequestSpecification; -import com.jayway.restassured.specification.ResponseSpecification; -import org.mifosplatform.integrationtests.testbuilder.LoanApplicationTestBuilder; -import org.mifosplatform.integrationtests.testbuilder.LoanProductTestBuilder; -import org.mifosplatform.integrationtests.testbuilder.LoanStatusChecker; -import org.mifosplatform.integrationtests.testbuilder.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() { - String basicAuthKey = loginIntoServerAndGetBase64EncodedAuthenticationKey(); - - requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build(); - requestSpec.header("Authorization","Basic "+basicAuthKey); - - responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); - } - - @Test - public void checkClientLoanCreateAndDisburseFlow(){ - //CREATE CLIENT - Integer clientID = createClient(DATE_OF_JOINING); - verifyClientCreatedOnServer(clientID); - - //CREATE LOAN PRODUCT - Integer loanProductID = createLoanProduct(); - //APPLY FOR LOAN - Integer loanID = applyForLoanApplication(clientID, loanProductID); - HashMap loanStatusHashMap = getStatusOfLoan(loanID); - - LoanStatusChecker.verifyLoanStatusIsPending(loanStatusHashMap); - - //APPROVE LOAN - loanStatusHashMap = approveLoan("28 September 2010", loanID); - LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap); - LoanStatusChecker.verifyLoanStatusIsWaitingForDisbursal(loanStatusHashMap); - - //UNDO APPROVAL - loanStatusHashMap = undoApproval(loanID); - LoanStatusChecker.verifyLoanStatusIsPending(loanStatusHashMap); - - //RE-APPROVE LOAN ON 1 OCTOBER 2010 - loanStatusHashMap = approveLoan("1 October 2010", loanID); - LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap); - LoanStatusChecker.verifyLoanStatusIsWaitingForDisbursal(loanStatusHashMap); - - //DISBURSE - loanStatusHashMap = disburseLoan(loanID); - System.out.println("DISBURSE "+loanStatusHashMap); - LoanStatusChecker.verifyLoanStatusIsActive(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 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"); - } - - private Integer createClient(String dateOfJoining) { - System.out.println("---------------------------------CREATING A CLIENT---------------------------------------------"); - String json = given().spec(requestSpec).body(Utils.getTestClientAsJSON(dateOfJoining)) - .expect().spec(responseSpec).log().ifError() - .when().post("/mifosng-provider/api/v1/clients?tenantIdentifier=default") - .andReturn().asString(); - - return from(json).get("clientId"); - } - - 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/testbuilder/LoanApplicationTestBuilder.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/LoanApplicationTestBuilder.java deleted file mode 100644 index d11b689aa..000000000 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/LoanApplicationTestBuilder.java +++ /dev/null @@ -1,163 +0,0 @@ -package org.mifosplatform.integrationtests.testbuilder; - -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/testbuilder/LoanProductTestBuilder.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/LoanProductTestBuilder.java deleted file mode 100644 index 9ebd1879f..000000000 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/LoanProductTestBuilder.java +++ /dev/null @@ -1,166 +0,0 @@ -package org.mifosplatform.integrationtests.testbuilder; - -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/testbuilder/LoanStatusChecker.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/LoanStatusChecker.java deleted file mode 100644 index 7bd8dd0c3..000000000 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/LoanStatusChecker.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.mifosplatform.integrationtests.testbuilder; - -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 verifyLoanStatusIsWaitingForDisbursal(HashMap loanStatusHashMap) { - assertTrue(getStatus(loanStatusHashMap, "waitingForDisbursal")); - } - - public static void verifyLoanStatusIsPending(HashMap loanStatusHashMap) { - assertTrue(getStatus(loanStatusHashMap, "pendingApproval")); - } - - public static void verifyLoanStatusIsActive(HashMap loanStatusHashMap) { - assertTrue(getStatus(loanStatusHashMap, "active")); - } - - private 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/testbuilder/Utils.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/Utils.java deleted file mode 100644 index 0bf5c7a46..000000000 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/Utils.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.mifosplatform.integrationtests.testbuilder; - -import com.google.gson.Gson; - -import java.util.HashMap; -import java.util.Random; - -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); - } - - -} From 3924fafe88e5747b9b281f9c59eb471c9f3c496f Mon Sep 17 00:00:00 2001 From: Priti Date: Mon, 1 Apr 2013 17:08:24 +0530 Subject: [PATCH 13/21] Renaming --- .../LoanWithWaiveInterestAndWriteOff.java | 2614 ----------------- .../LoanApplicationTestBuilder.java | 163 - .../testbuilder/LoanProductTestBuilder.java | 166 -- .../testbuilder/LoanStatusChecker.java | 39 - .../integrationtests/testbuilder/Utils.java | 87 - 5 files changed, 3069 deletions(-) delete mode 100644 mifosng-provider/src/integrationTest/java/LoanWithWaiveInterestAndWriteOff.java delete mode 100644 mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/LoanApplicationTestBuilder.java delete mode 100644 mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/LoanProductTestBuilder.java delete mode 100644 mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/LoanStatusChecker.java delete mode 100644 mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/Utils.java diff --git a/mifosng-provider/src/integrationTest/java/LoanWithWaiveInterestAndWriteOff.java b/mifosng-provider/src/integrationTest/java/LoanWithWaiveInterestAndWriteOff.java deleted file mode 100644 index 6db08a5e2..000000000 --- a/mifosng-provider/src/integrationTest/java/LoanWithWaiveInterestAndWriteOff.java +++ /dev/null @@ -1,2614 +0,0 @@ -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.path.json.JsonPath; -import com.jayway.restassured.specification.RequestSpecification; -import com.jayway.restassured.specification.ResponseSpecification; -import org.mifosplatform.integrationtests.testbuilder.LoanApplicationTestBuilder; -import org.mifosplatform.integrationtests.testbuilder.LoanProductTestBuilder; -import org.mifosplatform.integrationtests.testbuilder.LoanStatusChecker; -import org.mifosplatform.integrationtests.testbuilder.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() { - String basicAuthKey = loginIntoServerAndGetBase64EncodedAuthenticationKey(); - - requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build(); - requestSpec.header("Authorization","Basic "+basicAuthKey); - - responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); - } - - @Test - public void checkClientLoanCreateAndDisburseFlow(){ - //CREATE CLIENT - Integer clientID = createClient(DATE_OF_JOINING); - verifyClientCreatedOnServer(clientID); - - //CREATE LOAN PRODUCT - Integer loanProductID = createLoanProduct(); - //APPLY FOR LOAN - Integer loanID = applyForLoanApplication(clientID, loanProductID); - HashMap loanStatusHashMap = getStatusOfLoan(loanID); - - LoanStatusChecker.verifyLoanStatusIsPending(loanStatusHashMap); - - //APPROVE LOAN - loanStatusHashMap = approveLoan("28 September 2010", loanID); - LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap); - LoanStatusChecker.verifyLoanStatusIsWaitingForDisbursal(loanStatusHashMap); - - //UNDO APPROVAL - loanStatusHashMap = undoApproval(loanID); - LoanStatusChecker.verifyLoanStatusIsPending(loanStatusHashMap); - - //RE-APPROVE LOAN ON 1 OCTOBER 2010 - loanStatusHashMap = approveLoan("1 October 2010", loanID); - LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap); - LoanStatusChecker.verifyLoanStatusIsWaitingForDisbursal(loanStatusHashMap); - - //DISBURSE - loanStatusHashMap = disburseLoan(loanID); - System.out.println("DISBURSE "+loanStatusHashMap); - LoanStatusChecker.verifyLoanStatusIsActive(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 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"); - } - - private Integer createClient(String dateOfJoining) { - System.out.println("---------------------------------CREATING A CLIENT---------------------------------------------"); - String json = given().spec(requestSpec).body(Utils.getTestClientAsJSON(dateOfJoining)) - .expect().spec(responseSpec).log().ifError() - .when().post("/mifosng-provider/api/v1/clients?tenantIdentifier=default") - .andReturn().asString(); - - return from(json).get("clientId"); - } - - 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/testbuilder/LoanApplicationTestBuilder.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/LoanApplicationTestBuilder.java deleted file mode 100644 index d11b689aa..000000000 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/LoanApplicationTestBuilder.java +++ /dev/null @@ -1,163 +0,0 @@ -package org.mifosplatform.integrationtests.testbuilder; - -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/testbuilder/LoanProductTestBuilder.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/LoanProductTestBuilder.java deleted file mode 100644 index 9ebd1879f..000000000 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/LoanProductTestBuilder.java +++ /dev/null @@ -1,166 +0,0 @@ -package org.mifosplatform.integrationtests.testbuilder; - -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/testbuilder/LoanStatusChecker.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/LoanStatusChecker.java deleted file mode 100644 index 7bd8dd0c3..000000000 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/LoanStatusChecker.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.mifosplatform.integrationtests.testbuilder; - -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 verifyLoanStatusIsWaitingForDisbursal(HashMap loanStatusHashMap) { - assertTrue(getStatus(loanStatusHashMap, "waitingForDisbursal")); - } - - public static void verifyLoanStatusIsPending(HashMap loanStatusHashMap) { - assertTrue(getStatus(loanStatusHashMap, "pendingApproval")); - } - - public static void verifyLoanStatusIsActive(HashMap loanStatusHashMap) { - assertTrue(getStatus(loanStatusHashMap, "active")); - } - - private 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/testbuilder/Utils.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/Utils.java deleted file mode 100644 index 0bf5c7a46..000000000 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/testbuilder/Utils.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.mifosplatform.integrationtests.testbuilder; - -import com.google.gson.Gson; - -import java.util.HashMap; -import java.util.Random; - -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); - } - - -} From 513f6f276467882279f809e6b5cec1cc39a42f87 Mon Sep 17 00:00:00 2001 From: Priti Date: Mon, 1 Apr 2013 19:32:57 +0530 Subject: [PATCH 14/21] Refactoring --- .../ClientLoanIntegrationTest.java | 51 +------- .../LoanWithWaiveInterestAndWriteOff.java | 66 +++------- .../integrationtests/common/Utils.java | 121 ++++++++++++++++-- 3 files changed, 129 insertions(+), 109 deletions(-) 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 de77ac372..3ca6302c3 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/ClientLoanIntegrationTest.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/ClientLoanIntegrationTest.java @@ -13,7 +13,6 @@ 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; @@ -42,7 +41,7 @@ public class ClientLoanIntegrationTest { @Test public void checkClientLoanCreateAndDisburseFlow(){ Integer clientID = Utils.createClient(requestSpec, responseSpec); - checkClientCreatedOnServer(clientID); + Utils.verifyClientCreatedOnServer(requestSpec, responseSpec, clientID); Integer loanProductID = createLoanProduct(); applyForLoanApplication(clientID, loanProductID); @@ -53,14 +52,6 @@ public class ClientLoanIntegrationTest { } - - 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() @@ -74,14 +65,10 @@ public class ClientLoanIntegrationTest { .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"); + return Utils.getLoanProductId(requestSpec, responseSpec, loanProductJSON); } - private void applyForLoanApplication(final Integer clientID, final Integer loanProductID) { + private Integer applyForLoanApplication(final Integer clientID, final Integer loanProductID) { System.out.println("--------------------------------APPLYING FOR LOAN APPLICATION--------------------------------"); String loanApplicationJSON = new LoanApplicationTestBuilder() .withPrincipal("12,000.00") @@ -98,18 +85,13 @@ public class ClientLoanIntegrationTest { .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"); + return Utils.getLoanId(requestSpec, responseSpec, loanApplicationJSON); } 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"); + return Utils.getRepaymentSchedule(requestSpec,responseSpec,productID); } private void verifyLoanRepaymentSchedule(final ArrayList loanSchedule) { @@ -134,29 +116,6 @@ public class ClientLoanIntegrationTest { - - 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 index 10a9ae6a6..74ec02342 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/LoanWithWaiveInterestAndWriteOff.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/LoanWithWaiveInterestAndWriteOff.java @@ -59,7 +59,7 @@ public class LoanWithWaiveInterestAndWriteOff { public void checkClientLoanCreateAndDisburseFlow(){ //CREATE CLIENT Integer clientID = Utils.createClient(requestSpec, responseSpec, DATE_OF_JOINING); - verifyClientCreatedOnServer(clientID); + Utils.verifyClientCreatedOnServer(requestSpec, responseSpec, clientID); //CREATE LOAN PRODUCT Integer loanProductID = createLoanProduct(); @@ -113,15 +113,6 @@ public class LoanWithWaiveInterestAndWriteOff { } - 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"); @@ -155,41 +146,24 @@ public class LoanWithWaiveInterestAndWriteOff { 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"); + return Utils.approveLoan(requestSpec,responseSpec,approvalDate,loanID); } - 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 HashMap undoApproval(Integer loanID){ + System.out.println("-----------------------------------UNDO LOAN APPROVAL-----------------------------------------"); + return Utils.undoApproval(requestSpec,responseSpec,loanID); + } + + private HashMap disburseLoan(Integer loanID){ + System.out.println("-----------------------------------DISBURSE LOAN-----------------------------------------"); + return Utils.disburseLoan(requestSpec,responseSpec,loanID,DISBURSEMENT_DATE); + } + private HashMap writeOffLoan(String transactionDate, Integer loanID){ + System.out.println("--------------------LOAN WRITTEN OFF ON "+transactionDate+"-------------------------------\n"); + return Utils.writeOffLoan(requestSpec,responseSpec,transactionDate,loanID); } private Integer createLoanProduct() { @@ -205,11 +179,7 @@ public class LoanWithWaiveInterestAndWriteOff { .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"); + return Utils.getLoanProductId(requestSpec,responseSpec,loanProductJSON); } private Integer applyForLoanApplication(final Integer clientID, final Integer loanProductID) { @@ -229,11 +199,7 @@ public class LoanWithWaiveInterestAndWriteOff { .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"); + return Utils.getLoanId(requestSpec,responseSpec,loanApplicationJSON); } } 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 index 61eec5f42..5ace0eaf0 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/Utils.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/Utils.java @@ -5,6 +5,7 @@ import com.jayway.restassured.path.json.JsonPath; import com.jayway.restassured.specification.RequestSpecification; import com.jayway.restassured.specification.ResponseSpecification; +import java.util.ArrayList; import java.util.HashMap; import java.util.Random; @@ -12,7 +13,15 @@ import static com.jayway.restassured.RestAssured.given; import static com.jayway.restassured.RestAssured.post; import static com.jayway.restassured.path.json.JsonPath.from; +import junit.framework.Assert; + + public class Utils { + private static final String CREATE_LOAN_PRODUCT_URL ="/mifosng-provider/api/v1/loanproducts?tenantIdentifier=default"; + private static final String LOGIN_URL = "/mifosng-provider/api/v1/authentication?username=mifos&password=password&tenantIdentifier=default"; + private static final String CREATE_CLIENT_URL = "/mifosng-provider/api/v1/clients?tenantIdentifier=default"; + private static final String APPLY_LOAN_URL = "/mifosng-provider/api/v1/loans?tenantIdentifier=default"; + private static final String REPAYMENT_SCHEDULE_URL ="/mifosng-provider/api/v1/loans?command=calculateLoanSchedule&tenantIdentifier=default"; public static String randomStringGenerator(final String prefix, final int len, final String sourceSetString) { int lengthOfSource = sourceSetString.length(); @@ -90,24 +99,110 @@ public class Utils { return new Gson().toJson(map); } - - public static Integer createClient(RequestSpecification requestSpec, ResponseSpecification responseSpec) { - return createClient(requestSpec,responseSpec,"04 March 2012"); - + private static 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); } - 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(); + String json = post(LOGIN_URL).asString(); return JsonPath.with(json).get("base64EncodedAuthenticationKey"); } + + + + 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---------------------------------------------"); + return performServerPost(requestSpec,responseSpec,CREATE_CLIENT_URL,getTestClientAsJSON(dateOfJoining),"clientId"); + } + + + public static void verifyClientCreatedOnServer(RequestSpecification requestSpec, ResponseSpecification responseSpec, Integer generatedClientID) { + System.out.println("------------------------------CHECK CLIENT DETAILS------------------------------------\n"); + String CLIENT_URL="/mifosng-provider/api/v1/clients/" + generatedClientID + "?tenantIdentifier=default"; + Integer responseClientID = performServerGet(requestSpec,responseSpec,CLIENT_URL,"id"); + Assert.assertEquals(generatedClientID,responseClientID); + } + + public static Integer getLoanProductId(RequestSpecification requestSpec, ResponseSpecification responseSpec, String loanProductJSON) { + return performServerPost(requestSpec, responseSpec, CREATE_LOAN_PRODUCT_URL, loanProductJSON, "resourceId"); + } + + public static Integer getLoanId(RequestSpecification requestSpec, ResponseSpecification responseSpec, String loanApplicationJSON) { + return performServerPost(requestSpec, responseSpec, APPLY_LOAN_URL, loanApplicationJSON, "loanId"); + } + + + public static ArrayList getRepaymentSchedule(RequestSpecification requestSpec, ResponseSpecification responseSpec,Integer productID){ + return performServerPost(requestSpec,responseSpec,REPAYMENT_SCHEDULE_URL,getLoanCalculationBodyAsJSON(productID.toString()),"periods"); + } + + public static HashMap approveLoan(RequestSpecification requestSpec, ResponseSpecification responseSpec,String approvalDate,Integer loanID){ + String approveLoanURL ="/mifosng-provider/api/v1/loans/"+ loanID +"?command=approve&tenantIdentifier=default"; + HashMap response = performServerPost(requestSpec,responseSpec,approveLoanURL,getApproveLoanAsJSON(approvalDate),"changes"); + return (HashMap)response.get("status"); + } + + public static HashMap undoApproval(RequestSpecification requestSpec, ResponseSpecification responseSpec,Integer loanID){ + String undoBodyJson = "{'note':'UNDO APPROVAL'}"; + String approveLoanURL ="/mifosng-provider/api/v1/loans/"+ loanID +"?command=undoApproval&tenantIdentifier=default"; + HashMap response = performServerPost(requestSpec,responseSpec,approveLoanURL,undoBodyJson,"changes"); + return (HashMap)response.get("status"); + } + + public static HashMap disburseLoan(RequestSpecification requestSpec, ResponseSpecification responseSpec,Integer loanID,String date){ + String disburseBodyJson =getDisburseLoanAsJSON(date); + String disburseLoanURL ="/mifosng-provider/api/v1/loans/" + loanID + "?command=disburse&tenantIdentifier=default"; + HashMap response=performServerPost(requestSpec,responseSpec,disburseLoanURL,disburseBodyJson,"changes"); + return (HashMap)response.get("status"); + } + + public static HashMap writeOffLoan(RequestSpecification requestSpec, ResponseSpecification responseSpec,String date,Integer loanID){ + String writeOffJsonBody =getWriteOffBodyAsJSON(date); + String writeOffURL = "/mifosng-provider/api/v1/loans/" + loanID + "/transactions?command=writeoff&tenantIdentifier=default"; + HashMap response = performServerPost(requestSpec,responseSpec,writeOffURL,writeOffJsonBody,"changes"); + return (HashMap)response.get("status"); + } + + private static T performServerPost(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final String postURL, final String jsonBodyToSend, final String jsonAttributeToGetBack){ + String json = given().spec(requestSpec).body(jsonBodyToSend) + .expect().spec(responseSpec).log().ifError() + .when().post(postURL) + .andReturn().asString(); + return (T) from(json).get(jsonAttributeToGetBack); + } + + private static Integer performServerGet(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final String postURL, final String jsonAttributeToGetBack){ + String json = given().spec(requestSpec) + .expect().spec(responseSpec).log().ifError() + .when().get(postURL) + .andReturn().asString(); + return from(json).get(jsonAttributeToGetBack); + } + + } From f6fbbbb7d2432d6b4b10eeaf69dae463c86ddd1d Mon Sep 17 00:00:00 2001 From: Priti Date: Tue, 2 Apr 2013 16:27:59 +0530 Subject: [PATCH 15/21] [Priti/Sailee] Created ClientBuilder --- .../ClientLoanIntegrationTest.java | 16 +-- .../LoanWithWaiveInterestAndWriteOff.java | 101 +++++------------- .../common/ClientBuilder.java | 73 +++++++++++++ 3 files changed, 103 insertions(+), 87 deletions(-) create mode 100644 mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/ClientBuilder.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 index 3ca6302c3..a477614e8 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/ClientLoanIntegrationTest.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/ClientLoanIntegrationTest.java @@ -20,6 +20,7 @@ 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.LoanTransactionHelper; import org.mifosplatform.integrationtests.common.Utils; /** @@ -44,14 +45,13 @@ public class ClientLoanIntegrationTest { Utils.verifyClientCreatedOnServer(requestSpec, responseSpec, clientID); Integer loanProductID = createLoanProduct(); - applyForLoanApplication(clientID, loanProductID); + Integer loanID= applyForLoanApplication(clientID, loanProductID); - ArrayList loanSchedule = getLoanRepaymentSchedule(loanProductID); + ArrayList loanSchedule = LoanTransactionHelper.getLoanRepaymentSchedule(requestSpec, responseSpec, loanID); verifyLoanRepaymentSchedule(loanSchedule); } - private Integer createLoanProduct() { System.out.println("------------------------------CREATING NEW LOAN PRODUCT ---------------------------------------"); String loanProductJSON = new LoanProductTestBuilder() @@ -65,7 +65,7 @@ public class ClientLoanIntegrationTest { .withInterestTypeAsDecliningBalance() .withinterestRatePerPeriod("1") .build(); - return Utils.getLoanProductId(requestSpec, responseSpec, loanProductJSON); + return LoanTransactionHelper.getLoanProductId(requestSpec, responseSpec, loanProductJSON); } private Integer applyForLoanApplication(final Integer clientID, final Integer loanProductID) { @@ -85,13 +85,7 @@ public class ClientLoanIntegrationTest { .withExpectedDisbursementDate("20 September 2011") .withSubmittedOnDate("20 September 2011") .Build(clientID.toString(),loanProductID.toString()); - return Utils.getLoanId(requestSpec, responseSpec, loanApplicationJSON); - } - - private ArrayList getLoanRepaymentSchedule(final Integer productID) - { - System.out.println("---------------------------GETTING LOAN REPAYMENT SCHEDULE--------------------------------"); - return Utils.getRepaymentSchedule(requestSpec,responseSpec,productID); + return LoanTransactionHelper.getLoanId(requestSpec, responseSpec, loanApplicationJSON); } private void verifyLoanRepaymentSchedule(final ArrayList loanSchedule) { diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/LoanWithWaiveInterestAndWriteOff.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/LoanWithWaiveInterestAndWriteOff.java index 74ec02342..aa6bfda0f 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/LoanWithWaiveInterestAndWriteOff.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/LoanWithWaiveInterestAndWriteOff.java @@ -18,10 +18,7 @@ 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; +import org.mifosplatform.integrationtests.common.*; /** * Client Loan Integration Test for checking Loan Disbursement with Waive Interest and Write-Off. @@ -65,106 +62,58 @@ public class LoanWithWaiveInterestAndWriteOff { Integer loanProductID = createLoanProduct(); //APPLY FOR LOAN Integer loanID = applyForLoanApplication(clientID, loanProductID); - HashMap loanStatusHashMap = getStatusOfLoan(loanID); + HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(requestSpec,responseSpec,loanID); LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap); //APPROVE LOAN - loanStatusHashMap = approveLoan("28 September 2010", loanID); + System.out.println("-----------------------------------APPROVE LOAN-----------------------------------------"); + loanStatusHashMap = LoanTransactionHelper.approveLoan(requestSpec, responseSpec, "28 September 2010", loanID); LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap); LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap); //UNDO APPROVAL - loanStatusHashMap = undoApproval(loanID); + loanStatusHashMap = LoanTransactionHelper.undoApproval(requestSpec, responseSpec, loanID); LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap); //RE-APPROVE LOAN ON 1 OCTOBER 2010 - loanStatusHashMap = approveLoan("1 October 2010", loanID); + System.out.println("-----------------------------------APPROVE LOAN-----------------------------------------"); + loanStatusHashMap = LoanTransactionHelper.approveLoan(requestSpec, responseSpec, "1 October 2010", loanID); LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap); LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap); //DISBURSE - loanStatusHashMap = disburseLoan(loanID); + loanStatusHashMap = LoanTransactionHelper.disburseLoan(requestSpec, responseSpec, DISBURSEMENT_DATE, 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); + LoanTransactionHelper.makeRepayment(requestSpec,responseSpec, "1 January 2011", 540.0f, loanID); + LoanTransactionHelper.makeRepayment(requestSpec,responseSpec, "1 March 2011", 540.0f, loanID); + LoanTransactionHelper.waiveInterest(requestSpec,responseSpec, "1 May 2011",INTEREST_VALUE_AMOUNT, loanID); + LoanTransactionHelper.makeRepayment(requestSpec,responseSpec, "1 May 2011", 500.0f, loanID); + LoanTransactionHelper.makeRepayment(requestSpec,responseSpec, "1 July 2011", 540.0f, loanID); + LoanTransactionHelper.waiveInterest(requestSpec,responseSpec, "1 September 2011",INTEREST_VALUE_AMOUNT, loanID); + LoanTransactionHelper.makeRepayment(requestSpec,responseSpec, "1 September 2011", 500.0f, loanID); + LoanTransactionHelper.makeRepayment(requestSpec,responseSpec, "1 November 2011", 540.0f, loanID); + LoanTransactionHelper.waiveInterest(requestSpec,responseSpec, "1 January 2012",INTEREST_VALUE_AMOUNT, loanID); + LoanTransactionHelper.makeRepayment(requestSpec,responseSpec, "1 January 2012", 500.0f, loanID); + verifyRepaymentScheduleEntryFor(7,1000.0f,loanID); //WRITE OFF LOAN AND CHECK ACCOUNT IS CLOSED - LoanStatusChecker.verifyLoanAccountIsClosed(writeOffLoan("1 March 2012", loanID)); + LoanStatusChecker.verifyLoanAccountIsClosed(LoanTransactionHelper.writeOffLoan(requestSpec, responseSpec, "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 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"); + ArrayList repaymentPeriods = LoanTransactionHelper.getLoanRepaymentSchedule(requestSpec, responseSpec, loanID); + System.out.println("**********RESPOSE : "+repaymentPeriods); + assertEquals(expectedPrincipalOutstanding,repaymentPeriods.get(repaymentNumber).get("principalLoanBalanceOutstanding")); } - 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 approveLoan(String approvalDate, Integer loanID){ - System.out.println("-----------------------------------APPROVE LOAN-----------------------------------------"); - return Utils.approveLoan(requestSpec,responseSpec,approvalDate,loanID); - } - - - private HashMap undoApproval(Integer loanID){ - System.out.println("-----------------------------------UNDO LOAN APPROVAL-----------------------------------------"); - return Utils.undoApproval(requestSpec,responseSpec,loanID); - } - - private HashMap disburseLoan(Integer loanID){ - System.out.println("-----------------------------------DISBURSE LOAN-----------------------------------------"); - return Utils.disburseLoan(requestSpec,responseSpec,loanID,DISBURSEMENT_DATE); - } - private HashMap writeOffLoan(String transactionDate, Integer loanID){ - System.out.println("--------------------LOAN WRITTEN OFF ON "+transactionDate+"-------------------------------\n"); - return Utils.writeOffLoan(requestSpec,responseSpec,transactionDate,loanID); - } private Integer createLoanProduct() { System.out.println("------------------------------CREATING NEW LOAN PRODUCT ---------------------------------------"); @@ -179,7 +128,7 @@ public class LoanWithWaiveInterestAndWriteOff { .withAmortizationTypeAsEqualPrinciplePayment() .withInterestTypeAsFlat() .build(); - return Utils.getLoanProductId(requestSpec,responseSpec,loanProductJSON); + return LoanTransactionHelper.getLoanProductId(requestSpec,responseSpec,loanProductJSON); } private Integer applyForLoanApplication(final Integer clientID, final Integer loanProductID) { @@ -199,7 +148,7 @@ public class LoanWithWaiveInterestAndWriteOff { .withExpectedDisbursementDate(EXPECTED_DISBURSAL_DATE) .withSubmittedOnDate(LOAN_APPLICATION_SUBMISSION_DATE) .Build(clientID.toString(), loanProductID.toString()); - return Utils.getLoanId(requestSpec,responseSpec,loanApplicationJSON); + return LoanTransactionHelper.getLoanId(requestSpec,responseSpec,loanApplicationJSON); } } diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/ClientBuilder.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/ClientBuilder.java new file mode 100644 index 000000000..aac86b5be --- /dev/null +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/ClientBuilder.java @@ -0,0 +1,73 @@ +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; + +import junit.framework.Assert; + + +public class ClientBuilder { + private static final String CREATE_CLIENT_URL = "/mifosng-provider/api/v1/clients?tenantIdentifier=default"; + + + public static String getTestClientAsJSON(String dateOfJoining) { + HashMap map = new HashMap(); + map.put("officeId", "1"); + map.put("firstname", ClientBuilder.randomNameGenerator("Client_FirstName_", 5)); + map.put("lastname", ClientBuilder.randomNameGenerator("Client_LastName_", 4)); + map.put("externalId", ClientBuilder.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 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---------------------------------------------"); + return Utils.performServerPost(requestSpec, responseSpec, CREATE_CLIENT_URL, getTestClientAsJSON(dateOfJoining), "clientId"); + } + + + public static void verifyClientCreatedOnServer(RequestSpecification requestSpec, ResponseSpecification responseSpec, Integer generatedClientID) { + System.out.println("------------------------------CHECK CLIENT DETAILS------------------------------------\n"); + String CLIENT_URL="/mifosng-provider/api/v1/clients/" + generatedClientID + "?tenantIdentifier=default"; + Integer responseClientID = Utils.performServerGet(requestSpec, responseSpec, CLIENT_URL, "id"); + Assert.assertEquals(generatedClientID,responseClientID); + } + + 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"); + } + + + + +} From a66ef5cfbf3199254141ee16ca491f5a20b72f29 Mon Sep 17 00:00:00 2001 From: Priti Date: Tue, 2 Apr 2013 16:31:21 +0530 Subject: [PATCH 16/21] 1. LoanTranscations Moved out and created seperate Helper file for this 2. Client related activities are moved to ClientBuilder 3. Utils Will Have server Post/Get calls [Priti/Sailee] --- .../common/LoanTransactionHelper.java | 148 +++++++++++++ .../integrationtests/common/Utils.java | 197 ++---------------- 2 files changed, 162 insertions(+), 183 deletions(-) create mode 100644 mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/LoanTransactionHelper.java diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/LoanTransactionHelper.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/LoanTransactionHelper.java new file mode 100644 index 000000000..30a924cbe --- /dev/null +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/LoanTransactionHelper.java @@ -0,0 +1,148 @@ +package org.mifosplatform.integrationtests.common; + +import com.google.gson.Gson; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; + +import java.util.ArrayList; +import java.util.HashMap; + +import static com.jayway.restassured.RestAssured.given; + +public class LoanTransactionHelper { + + private static final String CREATE_LOAN_PRODUCT_URL = "/mifosng-provider/api/v1/loanproducts?tenantIdentifier=default"; + private static final String APPLY_LOAN_URL = "/mifosng-provider/api/v1/loans?tenantIdentifier=default"; + private static final String APPROVE_LOAN_COMMAND = "approve"; + private static final String UNDO_APPROVAL_LOAN_COMMAND = "undoApproval"; + private static final String DISBURSE_LOAN_COMMAND = "disburse"; + private static final String WRITE_OFF_LOAN_COMMAND = "writeoff"; + private static final String WAIVE_INTEREST_COMMAND = "waiveinterest"; + private static final String MAKE_REPAYMENT_COMMAND = "repayment"; + + + + + public static Integer getLoanProductId(RequestSpecification requestSpec, ResponseSpecification responseSpec, String loanProductJSON) { + return Utils.performServerPost(requestSpec, responseSpec, CREATE_LOAN_PRODUCT_URL, loanProductJSON, "resourceId"); + } + + public static Integer getLoanId(RequestSpecification requestSpec, ResponseSpecification responseSpec, String loanApplicationJSON) { + return Utils.performServerPost(requestSpec, responseSpec, APPLY_LOAN_URL, loanApplicationJSON, "loanId"); + } + + public static ArrayList getLoanRepaymentSchedule(RequestSpecification requestSpec, ResponseSpecification responseSpec,final Integer loanID){ + String URL = "/mifosng-provider/api/v1/loans/" + loanID +"?associations=repaymentSchedule&tenantIdentifier=default"; + HashMap response = Utils.performServerGet(requestSpec, responseSpec, URL, "repaymentSchedule"); + return (ArrayList) response.get("periods"); + } + + public static HashMap approveLoan(RequestSpecification requestSpec, ResponseSpecification responseSpec, String approvalDate, Integer loanID) { + return performLoanTransaction(requestSpec, responseSpec, createLoanOperationURL(APPROVE_LOAN_COMMAND, loanID), getApproveLoanAsJSON(approvalDate)); + } + + public static HashMap undoApproval(RequestSpecification requestSpec, ResponseSpecification responseSpec, Integer loanID) { + String undoBodyJson = "{'note':'UNDO APPROVAL'}"; + return performLoanTransaction(requestSpec, responseSpec, createLoanOperationURL(UNDO_APPROVAL_LOAN_COMMAND, loanID), undoBodyJson); + } + + public static HashMap disburseLoan(RequestSpecification requestSpec, ResponseSpecification responseSpec, String date, Integer loanID) { + return performLoanTransaction(requestSpec, responseSpec, createLoanOperationURL(DISBURSE_LOAN_COMMAND, loanID), getDisburseLoanAsJSON(date)); + } + + public static HashMap writeOffLoan(RequestSpecification requestSpec, ResponseSpecification responseSpec, String date, Integer loanID) { + return performLoanTransaction(requestSpec, responseSpec, createLoanTransactionURL(WRITE_OFF_LOAN_COMMAND, loanID), getWriteOffBodyAsJSON(date)); + } + + public static HashMap waiveInterest(RequestSpecification requestSpec, ResponseSpecification responseSpec, String date,String amountToBeWaived, Integer loanID) { + return performLoanTransaction(requestSpec, responseSpec, createLoanTransactionURL(WAIVE_INTEREST_COMMAND,loanID), getWaiveBodyAsJSON(date, amountToBeWaived)); + } + + public static HashMap makeRepayment(RequestSpecification requestSpec, ResponseSpecification responseSpec, String date,Float amountToBePaid, Integer loanID) { + return performLoanTransaction(requestSpec, responseSpec, createLoanTransactionURL(MAKE_REPAYMENT_COMMAND,loanID), getRepaymentBodyAsJSON(date,amountToBePaid)); + } + + 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 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", "4,500.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); + } + + + private static String createLoanOperationURL(String command, Integer loanID) { + return "/mifosng-provider/api/v1/loans/" + loanID + "?command=" + command + "&tenantIdentifier=default"; + } + + private static String createLoanTransactionURL(String command, Integer loanID) { + return "/mifosng-provider/api/v1/loans/" + loanID + "/transactions?command="+command+"&tenantIdentifier=default"; + } + + private static HashMap performLoanTransaction(RequestSpecification requestSpec, ResponseSpecification responseSpec, String postURLForLoanTransaction, String jsonToBeSent) { + + HashMap response = Utils.performServerPost(requestSpec, responseSpec, postURLForLoanTransaction, jsonToBeSent, "changes"); + return (HashMap) response.get("status"); + } + +} 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 index 5ace0eaf0..0047f5fce 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/Utils.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/Utils.java @@ -1,193 +1,29 @@ package org.mifosplatform.integrationtests.common; -import com.google.gson.Gson; +import com.jayway.restassured.RestAssured; import com.jayway.restassured.path.json.JsonPath; import com.jayway.restassured.specification.RequestSpecification; import com.jayway.restassured.specification.ResponseSpecification; -import java.util.ArrayList; -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; -import junit.framework.Assert; - public class Utils { - private static final String CREATE_LOAN_PRODUCT_URL ="/mifosng-provider/api/v1/loanproducts?tenantIdentifier=default"; private static final String LOGIN_URL = "/mifosng-provider/api/v1/authentication?username=mifos&password=password&tenantIdentifier=default"; - private static final String CREATE_CLIENT_URL = "/mifosng-provider/api/v1/clients?tenantIdentifier=default"; - private static final String APPLY_LOAN_URL = "/mifosng-provider/api/v1/loans?tenantIdentifier=default"; - private static final String REPAYMENT_SCHEDULE_URL ="/mifosng-provider/api/v1/loans?command=calculateLoanSchedule&tenantIdentifier=default"; - 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 T performServerGet(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final String getURL, final String jsonAttributeToGetBack){ + String json = given().spec(requestSpec) + .expect().spec(responseSpec).log().ifError() + .when().get(getURL) + .andReturn().asString(); + return (T) from(json).get(jsonAttributeToGetBack); } - 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); - } - - private static 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); - } - - - public static String loginIntoServerAndGetBase64EncodedAuthenticationKey() { - System.out.println("-----------------------------------LOGIN-----------------------------------------"); - String json = post(LOGIN_URL).asString(); - return JsonPath.with(json).get("base64EncodedAuthenticationKey"); - } - - - - 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---------------------------------------------"); - return performServerPost(requestSpec,responseSpec,CREATE_CLIENT_URL,getTestClientAsJSON(dateOfJoining),"clientId"); - } - - - public static void verifyClientCreatedOnServer(RequestSpecification requestSpec, ResponseSpecification responseSpec, Integer generatedClientID) { - System.out.println("------------------------------CHECK CLIENT DETAILS------------------------------------\n"); - String CLIENT_URL="/mifosng-provider/api/v1/clients/" + generatedClientID + "?tenantIdentifier=default"; - Integer responseClientID = performServerGet(requestSpec,responseSpec,CLIENT_URL,"id"); - Assert.assertEquals(generatedClientID,responseClientID); - } - - public static Integer getLoanProductId(RequestSpecification requestSpec, ResponseSpecification responseSpec, String loanProductJSON) { - return performServerPost(requestSpec, responseSpec, CREATE_LOAN_PRODUCT_URL, loanProductJSON, "resourceId"); - } - - public static Integer getLoanId(RequestSpecification requestSpec, ResponseSpecification responseSpec, String loanApplicationJSON) { - return performServerPost(requestSpec, responseSpec, APPLY_LOAN_URL, loanApplicationJSON, "loanId"); - } - - - public static ArrayList getRepaymentSchedule(RequestSpecification requestSpec, ResponseSpecification responseSpec,Integer productID){ - return performServerPost(requestSpec,responseSpec,REPAYMENT_SCHEDULE_URL,getLoanCalculationBodyAsJSON(productID.toString()),"periods"); - } - - public static HashMap approveLoan(RequestSpecification requestSpec, ResponseSpecification responseSpec,String approvalDate,Integer loanID){ - String approveLoanURL ="/mifosng-provider/api/v1/loans/"+ loanID +"?command=approve&tenantIdentifier=default"; - HashMap response = performServerPost(requestSpec,responseSpec,approveLoanURL,getApproveLoanAsJSON(approvalDate),"changes"); - return (HashMap)response.get("status"); - } - - public static HashMap undoApproval(RequestSpecification requestSpec, ResponseSpecification responseSpec,Integer loanID){ - String undoBodyJson = "{'note':'UNDO APPROVAL'}"; - String approveLoanURL ="/mifosng-provider/api/v1/loans/"+ loanID +"?command=undoApproval&tenantIdentifier=default"; - HashMap response = performServerPost(requestSpec,responseSpec,approveLoanURL,undoBodyJson,"changes"); - return (HashMap)response.get("status"); - } - - public static HashMap disburseLoan(RequestSpecification requestSpec, ResponseSpecification responseSpec,Integer loanID,String date){ - String disburseBodyJson =getDisburseLoanAsJSON(date); - String disburseLoanURL ="/mifosng-provider/api/v1/loans/" + loanID + "?command=disburse&tenantIdentifier=default"; - HashMap response=performServerPost(requestSpec,responseSpec,disburseLoanURL,disburseBodyJson,"changes"); - return (HashMap)response.get("status"); - } - - public static HashMap writeOffLoan(RequestSpecification requestSpec, ResponseSpecification responseSpec,String date,Integer loanID){ - String writeOffJsonBody =getWriteOffBodyAsJSON(date); - String writeOffURL = "/mifosng-provider/api/v1/loans/" + loanID + "/transactions?command=writeoff&tenantIdentifier=default"; - HashMap response = performServerPost(requestSpec,responseSpec,writeOffURL,writeOffJsonBody,"changes"); - return (HashMap)response.get("status"); - } - - private static T performServerPost(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, - final String postURL, final String jsonBodyToSend, final String jsonAttributeToGetBack){ + public static T performServerPost(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final String postURL, final String jsonBodyToSend, final String jsonAttributeToGetBack){ String json = given().spec(requestSpec).body(jsonBodyToSend) .expect().spec(responseSpec).log().ifError() .when().post(postURL) @@ -195,14 +31,9 @@ public class Utils { return (T) from(json).get(jsonAttributeToGetBack); } - private static Integer performServerGet(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, - final String postURL, final String jsonAttributeToGetBack){ - String json = given().spec(requestSpec) - .expect().spec(responseSpec).log().ifError() - .when().get(postURL) - .andReturn().asString(); - return from(json).get(jsonAttributeToGetBack); + public static String loginIntoServerAndGetBase64EncodedAuthenticationKey() { + System.out.println("-----------------------------------LOGIN-----------------------------------------"); + String json = RestAssured.post(LOGIN_URL).asString(); + return JsonPath.with(json).get("base64EncodedAuthenticationKey"); } - - } From be32e0b7ebfd31df7d26feabf2dfc905d973fad4 Mon Sep 17 00:00:00 2001 From: Priti Date: Tue, 2 Apr 2013 16:34:00 +0530 Subject: [PATCH 17/21] [Priti/Sailee] Refactoring --- .../ClientLoanIntegrationTest.java | 9 +++------ .../LoanWithWaiveInterestAndWriteOff.java | 4 ++-- .../common/LoanProductTestBuilder.java | 14 +++++++------- .../integrationtests/common/LoanStatusChecker.java | 9 +++++++++ 4 files changed, 21 insertions(+), 15 deletions(-) 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 a477614e8..a36c5f0a3 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/ClientLoanIntegrationTest.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/ClientLoanIntegrationTest.java @@ -18,10 +18,7 @@ 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.LoanTransactionHelper; -import org.mifosplatform.integrationtests.common.Utils; +import org.mifosplatform.integrationtests.common.*; /** * Client Loan Integration Test for checking Loan Application Repayment Schedule. @@ -41,8 +38,8 @@ public class ClientLoanIntegrationTest { @Test public void checkClientLoanCreateAndDisburseFlow(){ - Integer clientID = Utils.createClient(requestSpec, responseSpec); - Utils.verifyClientCreatedOnServer(requestSpec, responseSpec, clientID); + Integer clientID = ClientBuilder.createClient(requestSpec, responseSpec); + ClientBuilder.verifyClientCreatedOnServer(requestSpec, responseSpec, clientID); Integer loanProductID = createLoanProduct(); Integer loanID= applyForLoanApplication(clientID, loanProductID); diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/LoanWithWaiveInterestAndWriteOff.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/LoanWithWaiveInterestAndWriteOff.java index aa6bfda0f..bdbba3bd2 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/LoanWithWaiveInterestAndWriteOff.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/LoanWithWaiveInterestAndWriteOff.java @@ -55,8 +55,8 @@ public class LoanWithWaiveInterestAndWriteOff { @Test public void checkClientLoanCreateAndDisburseFlow(){ //CREATE CLIENT - Integer clientID = Utils.createClient(requestSpec, responseSpec, DATE_OF_JOINING); - Utils.verifyClientCreatedOnServer(requestSpec, responseSpec, clientID); + Integer clientID = ClientBuilder.createClient(requestSpec, responseSpec, DATE_OF_JOINING); + ClientBuilder.verifyClientCreatedOnServer(requestSpec, responseSpec, clientID); //CREATE LOAN PRODUCT Integer loanProductID = createLoanProduct(); 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 index 05eaa7769..5a5880d69 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/LoanProductTestBuilder.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/LoanProductTestBuilder.java @@ -26,7 +26,7 @@ public class LoanProductTestBuilder { private static final String ACCRUAL_BASED ="3"; - private String nameOfLoanProduct = Utils.randomNameGenerator("LOAN_PRODUCT_", 6); + private String nameOfLoanProduct = ClientBuilder.randomNameGenerator("LOAN_PRODUCT_", 6); private String principal = "10000.00"; private String numberOfRepayments = "0"; private String repaymentFrequency = WEEK; @@ -63,16 +63,16 @@ public class LoanProductTestBuilder { return new Gson().toJson(map); } - public LoanProductTestBuilder withLoanName(String loanName){ + public LoanProductTestBuilder withLoanName(final String loanName){ this.nameOfLoanProduct=loanName; return this; } - public LoanProductTestBuilder withPrincipal(String principal){ + public LoanProductTestBuilder withPrincipal(final String principal){ this.principal = principal; return this; } - public LoanProductTestBuilder withNumberOfRepayments(String numberOfRepayment){ + public LoanProductTestBuilder withNumberOfRepayments(final String numberOfRepayment){ this.numberOfRepayments = numberOfRepayment; return this; } @@ -93,7 +93,7 @@ public class LoanProductTestBuilder { return this; } - public LoanProductTestBuilder withRepaymentAfterEvery(String repaymentAfterEvery){ + public LoanProductTestBuilder withRepaymentAfterEvery(final String repaymentAfterEvery){ this.repaymentPeriod=repaymentAfterEvery; return this; } @@ -108,7 +108,7 @@ public class LoanProductTestBuilder { return this; } - public LoanProductTestBuilder withinterestRatePerPeriod(String interestRatePerPeriod) { + public LoanProductTestBuilder withinterestRatePerPeriod(final String interestRatePerPeriod) { this.interestRatePerPeriod=interestRatePerPeriod; return this; } @@ -143,7 +143,7 @@ public class LoanProductTestBuilder { return this; } - public LoanProductTestBuilder withInArrearsTolerance (String amountCanBeWaved){ + public LoanProductTestBuilder withInArrearsTolerance (final String amountCanBeWaved){ this.inArrearsTolerance = amountCanBeWaved; 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 index 5f6a9a243..7b21da6c7 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/LoanStatusChecker.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/LoanStatusChecker.java @@ -1,9 +1,13 @@ package org.mifosplatform.integrationtests.common; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; import junit.framework.Assert; import java.util.HashMap; +import static com.jayway.restassured.RestAssured.given; +import static com.jayway.restassured.path.json.JsonPath.from; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -36,4 +40,9 @@ public class LoanStatusChecker { public static void verifyLoanAccountIsClosed(HashMap loanStatusHashMap){ Assert.assertTrue(getStatus(loanStatusHashMap, "closed")); } + + public static HashMap getStatusOfLoan(RequestSpecification requestSpec, ResponseSpecification responseSpec, Integer loanID){ + String url = "/mifosng-provider/api/v1/loans/" + loanID + "?tenantIdentifier=default"; + return Utils.performServerGet(requestSpec, responseSpec, url, "status"); + } } From a70712d8fc224ccf60fc8381d5d510ea9b648f28 Mon Sep 17 00:00:00 2001 From: Priti Date: Tue, 2 Apr 2013 17:09:07 +0530 Subject: [PATCH 18/21] Refactoring --- .../ClientLoanIntegrationTest.java | 8 ++--- .../LoanWithWaiveInterestAndWriteOff.java | 33 +++++++------------ .../common/LoanApplicationTestBuilder.java | 28 +++++++--------- .../common/LoanProductTestBuilder.java | 2 +- .../common/LoanStatusChecker.java | 12 ++++--- .../common/LoanTransactionHelper.java | 2 -- .../integrationtests/common/Utils.java | 12 ++++--- 7 files changed, 43 insertions(+), 54 deletions(-) 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 a36c5f0a3..33042d405 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/ClientLoanIntegrationTest.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/ClientLoanIntegrationTest.java @@ -38,11 +38,11 @@ public class ClientLoanIntegrationTest { @Test public void checkClientLoanCreateAndDisburseFlow(){ - Integer clientID = ClientBuilder.createClient(requestSpec, responseSpec); - ClientBuilder.verifyClientCreatedOnServer(requestSpec, responseSpec, clientID); + Integer clientID = ClientHelper.createClient(requestSpec, responseSpec); + ClientHelper.verifyClientCreatedOnServer(requestSpec, responseSpec, clientID); Integer loanProductID = createLoanProduct(); - Integer loanID= applyForLoanApplication(clientID, loanProductID); + Integer loanID = applyForLoanApplication(clientID, loanProductID); ArrayList loanSchedule = LoanTransactionHelper.getLoanRepaymentSchedule(requestSpec, responseSpec, loanID); verifyLoanRepaymentSchedule(loanSchedule); @@ -81,7 +81,7 @@ public class ClientLoanIntegrationTest { .withInterestCalculationPeriodTypeSameAsRepaymentPeriod() .withExpectedDisbursementDate("20 September 2011") .withSubmittedOnDate("20 September 2011") - .Build(clientID.toString(),loanProductID.toString()); + .build(clientID.toString(), loanProductID.toString()); return LoanTransactionHelper.getLoanId(requestSpec, responseSpec, loanApplicationJSON); } diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/LoanWithWaiveInterestAndWriteOff.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/LoanWithWaiveInterestAndWriteOff.java index bdbba3bd2..975969b4a 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/LoanWithWaiveInterestAndWriteOff.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/LoanWithWaiveInterestAndWriteOff.java @@ -1,25 +1,19 @@ 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.junit.Before; +import org.junit.Test; import org.mifosplatform.integrationtests.common.*; +import java.util.ArrayList; +import java.util.HashMap; + +import static junit.framework.Assert.assertEquals; + /** * Client Loan Integration Test for checking Loan Disbursement with Waive Interest and Write-Off. */ @@ -55,8 +49,8 @@ public class LoanWithWaiveInterestAndWriteOff { @Test public void checkClientLoanCreateAndDisburseFlow(){ //CREATE CLIENT - Integer clientID = ClientBuilder.createClient(requestSpec, responseSpec, DATE_OF_JOINING); - ClientBuilder.verifyClientCreatedOnServer(requestSpec, responseSpec, clientID); + Integer clientID = ClientHelper.createClient(requestSpec, responseSpec, DATE_OF_JOINING); + ClientHelper.verifyClientCreatedOnServer(requestSpec, responseSpec, clientID); //CREATE LOAN PRODUCT Integer loanProductID = createLoanProduct(); @@ -66,7 +60,6 @@ public class LoanWithWaiveInterestAndWriteOff { LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap); - //APPROVE LOAN System.out.println("-----------------------------------APPROVE LOAN-----------------------------------------"); loanStatusHashMap = LoanTransactionHelper.approveLoan(requestSpec, responseSpec, "28 September 2010", loanID); LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap); @@ -76,8 +69,7 @@ public class LoanWithWaiveInterestAndWriteOff { loanStatusHashMap = LoanTransactionHelper.undoApproval(requestSpec, responseSpec, loanID); LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap); - //RE-APPROVE LOAN ON 1 OCTOBER 2010 - System.out.println("-----------------------------------APPROVE LOAN-----------------------------------------"); + System.out.println("-----------------------------------RE-APPROVE LOAN-----------------------------------------"); loanStatusHashMap = LoanTransactionHelper.approveLoan(requestSpec, responseSpec, "1 October 2010", loanID); LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap); LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap); @@ -107,10 +99,9 @@ public class LoanWithWaiveInterestAndWriteOff { } - private void verifyRepaymentScheduleEntryFor(int repaymentNumber, float expectedPrincipalOutstanding ,Integer loanID) { + private void verifyRepaymentScheduleEntryFor(int repaymentNumber, float expectedPrincipalOutstanding, Integer loanID) { System.out.println("---------------------------GETTING LOAN REPAYMENT SCHEDULE--------------------------------"); ArrayList repaymentPeriods = LoanTransactionHelper.getLoanRepaymentSchedule(requestSpec, responseSpec, loanID); - System.out.println("**********RESPOSE : "+repaymentPeriods); assertEquals(expectedPrincipalOutstanding,repaymentPeriods.get(repaymentNumber).get("principalLoanBalanceOutstanding")); } @@ -147,7 +138,7 @@ public class LoanWithWaiveInterestAndWriteOff { .withInterestCalculationPeriodTypeSameAsRepaymentPeriod() .withExpectedDisbursementDate(EXPECTED_DISBURSAL_DATE) .withSubmittedOnDate(LOAN_APPLICATION_SUBMISSION_DATE) - .Build(clientID.toString(), loanProductID.toString()); + .build(clientID.toString(), loanProductID.toString()); return LoanTransactionHelper.getLoanId(requestSpec,responseSpec,loanApplicationJSON); } } 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 index 85a7e5e46..4d7214a71 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/LoanApplicationTestBuilder.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/LoanApplicationTestBuilder.java @@ -17,30 +17,24 @@ public class LoanApplicationTestBuilder { 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 loanTermFrequencyType = ""; private String numberOfRepayment = "0"; private String repaymentPeriod = "0"; - private String repaymentFrequencyType = ""; //0=Days, 1=Weeks, 2=Months + private String repaymentFrequencyType = ""; - // 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 =""; + private String interestRateFrequencyType = "0"; + private String interestType = ""; + private String amortizationType = ""; + 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){ - 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"); 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 index 5a5880d69..a56134d08 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/LoanProductTestBuilder.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/LoanProductTestBuilder.java @@ -26,7 +26,7 @@ public class LoanProductTestBuilder { private static final String ACCRUAL_BASED ="3"; - private String nameOfLoanProduct = ClientBuilder.randomNameGenerator("LOAN_PRODUCT_", 6); + private String nameOfLoanProduct = ClientHelper.randomNameGenerator("LOAN_PRODUCT_", 6); private String principal = "10000.00"; private String numberOfRepayments = "0"; private String repaymentFrequency = WEEK; 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 index 7b21da6c7..947f4b287 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/LoanStatusChecker.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/LoanStatusChecker.java @@ -13,10 +13,6 @@ 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")); } @@ -45,4 +41,12 @@ public class LoanStatusChecker { String url = "/mifosng-provider/api/v1/loans/" + loanID + "?tenantIdentifier=default"; return Utils.performServerGet(requestSpec, responseSpec, url, "status"); } + + + + private static boolean getStatus(HashMap loanStatusMap, String nameOfLoanStatusString){ + return (Boolean)loanStatusMap.get(nameOfLoanStatusString); + } + + } diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/LoanTransactionHelper.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/LoanTransactionHelper.java index 30a924cbe..5c4cf3fe5 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/LoanTransactionHelper.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/LoanTransactionHelper.java @@ -7,8 +7,6 @@ import com.jayway.restassured.specification.ResponseSpecification; import java.util.ArrayList; import java.util.HashMap; -import static com.jayway.restassured.RestAssured.given; - public class LoanTransactionHelper { private static final String CREATE_LOAN_PRODUCT_URL = "/mifosng-provider/api/v1/loanproducts?tenantIdentifier=default"; 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 index 0047f5fce..edfdf82d7 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/Utils.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/Utils.java @@ -13,6 +13,13 @@ import static com.jayway.restassured.path.json.JsonPath.from; public class Utils { private static final String LOGIN_URL = "/mifosng-provider/api/v1/authentication?username=mifos&password=password&tenantIdentifier=default"; + public static String loginIntoServerAndGetBase64EncodedAuthenticationKey() { + System.out.println("-----------------------------------LOGIN-----------------------------------------"); + String json = RestAssured.post(LOGIN_URL).asString(); + return JsonPath.with(json).get("base64EncodedAuthenticationKey"); + } + + public static T performServerGet(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, final String getURL, final String jsonAttributeToGetBack){ String json = given().spec(requestSpec) @@ -31,9 +38,4 @@ public class Utils { return (T) from(json).get(jsonAttributeToGetBack); } - public static String loginIntoServerAndGetBase64EncodedAuthenticationKey() { - System.out.println("-----------------------------------LOGIN-----------------------------------------"); - String json = RestAssured.post(LOGIN_URL).asString(); - return JsonPath.with(json).get("base64EncodedAuthenticationKey"); - } } From a9a190827e223e23835f65359f448f9036d1360b Mon Sep 17 00:00:00 2001 From: Priti Date: Tue, 2 Apr 2013 17:09:30 +0530 Subject: [PATCH 19/21] ClientBuilder renamed as ClientHalper --- .../integrationtests/common/ClientHelper.java | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/ClientHelper.java diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/ClientHelper.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/ClientHelper.java new file mode 100644 index 000000000..488242e20 --- /dev/null +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/ClientHelper.java @@ -0,0 +1,71 @@ +package org.mifosplatform.integrationtests.common; + +import com.google.gson.Gson; +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; + +import junit.framework.Assert; + + +public class ClientHelper { + private static final String CREATE_CLIENT_URL = "/mifosng-provider/api/v1/clients?tenantIdentifier=default"; + + + 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---------------------------------------------"); + return Utils.performServerPost(requestSpec, responseSpec, CREATE_CLIENT_URL, getTestClientAsJSON(dateOfJoining), "clientId"); + } + + + public static String getTestClientAsJSON(String dateOfJoining) { + HashMap map = new HashMap(); + map.put("officeId", "1"); + map.put("firstname", randomNameGenerator("Client_FirstName_", 5)); + map.put("lastname", randomNameGenerator("Client_LastName_", 4)); + map.put("externalId", 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 void verifyClientCreatedOnServer(RequestSpecification requestSpec, ResponseSpecification responseSpec, Integer generatedClientID) { + System.out.println("------------------------------CHECK CLIENT DETAILS------------------------------------\n"); + String CLIENT_URL="/mifosng-provider/api/v1/clients/" + generatedClientID + "?tenantIdentifier=default"; + Integer responseClientID = Utils.performServerGet(requestSpec, responseSpec, CLIENT_URL, "id"); + Assert.assertEquals(generatedClientID,responseClientID); + } + + private 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"); + } + + private static String randomIDGenerator(final String prefix, final int lenOfRandomSuffix) { + return randomStringGenerator(prefix, lenOfRandomSuffix, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + } + + + + +} From 571174e10dc8374fd08d071964bf2c497c3fc1b5 Mon Sep 17 00:00:00 2001 From: Priti Date: Tue, 2 Apr 2013 17:12:46 +0530 Subject: [PATCH 20/21] 'out/' added to gitignore --- mifosng-provider/.gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/mifosng-provider/.gitignore b/mifosng-provider/.gitignore index e6c52c2d2..a0457e62f 100644 --- a/mifosng-provider/.gitignore +++ b/mifosng-provider/.gitignore @@ -1,4 +1,5 @@ bin +out/ build repos .classpath From 0dab99ecdbfb827ce7e52b2917d962b03cf5506a Mon Sep 17 00:00:00 2001 From: Priti Date: Tue, 2 Apr 2013 17:26:55 +0530 Subject: [PATCH 21/21] Renamed File --- .../common/ClientBuilder.java | 73 ------------------- 1 file changed, 73 deletions(-) delete mode 100644 mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/ClientBuilder.java diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/ClientBuilder.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/ClientBuilder.java deleted file mode 100644 index aac86b5be..000000000 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/ClientBuilder.java +++ /dev/null @@ -1,73 +0,0 @@ -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; - -import junit.framework.Assert; - - -public class ClientBuilder { - private static final String CREATE_CLIENT_URL = "/mifosng-provider/api/v1/clients?tenantIdentifier=default"; - - - public static String getTestClientAsJSON(String dateOfJoining) { - HashMap map = new HashMap(); - map.put("officeId", "1"); - map.put("firstname", ClientBuilder.randomNameGenerator("Client_FirstName_", 5)); - map.put("lastname", ClientBuilder.randomNameGenerator("Client_LastName_", 4)); - map.put("externalId", ClientBuilder.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 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---------------------------------------------"); - return Utils.performServerPost(requestSpec, responseSpec, CREATE_CLIENT_URL, getTestClientAsJSON(dateOfJoining), "clientId"); - } - - - public static void verifyClientCreatedOnServer(RequestSpecification requestSpec, ResponseSpecification responseSpec, Integer generatedClientID) { - System.out.println("------------------------------CHECK CLIENT DETAILS------------------------------------\n"); - String CLIENT_URL="/mifosng-provider/api/v1/clients/" + generatedClientID + "?tenantIdentifier=default"; - Integer responseClientID = Utils.performServerGet(requestSpec, responseSpec, CLIENT_URL, "id"); - Assert.assertEquals(generatedClientID,responseClientID); - } - - 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"); - } - - - - -}