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"); + } +}