From 63610b3c50750b5a6ffdb2618246eb3f4da2623a Mon Sep 17 00:00:00 2001 From: Raman Kansal Date: Tue, 6 Aug 2013 09:33:12 +0530 Subject: [PATCH] Raman - Added Group Loan test --- .../GroupLoanIntegrationTest.java | 118 ++++++++++++++++++ .../integrationtests/GroupTest.java | 2 +- .../loans/LoanApplicationTestBuilder.java | 7 +- 3 files changed, 124 insertions(+), 3 deletions(-) create mode 100644 mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/GroupLoanIntegrationTest.java diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/GroupLoanIntegrationTest.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/GroupLoanIntegrationTest.java new file mode 100644 index 000000000..8e216d82b --- /dev/null +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/GroupLoanIntegrationTest.java @@ -0,0 +1,118 @@ +package org.mifosplatform.integrationtests; + +import static org.junit.Assert.assertEquals; + +import java.lang.System; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; + +import org.junit.Before; +import org.junit.Test; +import org.mifosplatform.integrationtests.common.ClientHelper; +import org.mifosplatform.integrationtests.common.GroupHelper; +import org.mifosplatform.integrationtests.common.Utils; +import org.mifosplatform.integrationtests.common.loans.LoanApplicationTestBuilder; +import org.mifosplatform.integrationtests.common.loans.LoanProductTestBuilder; +import org.mifosplatform.integrationtests.common.loans.LoanTransactionHelper; + +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; + +/** + * Group Loan Integration Test for checking Loan Application Repayment + * Schedule. + */ +@SuppressWarnings({ "rawtypes", "unchecked" }) +public class GroupLoanIntegrationTest { + + private ResponseSpecification responseSpec; + private RequestSpecification requestSpec; + private LoanTransactionHelper loanTransactionHelper; + + @Before + public void setup() { + Utils.initializeRESTAssured(); + requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build(); + requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); + responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); + } + + @Test + public void checkGroupLoanCreateAndDisburseFlow() { + loanTransactionHelper = new LoanTransactionHelper(requestSpec, responseSpec); + + Integer clientID = ClientHelper.createClient(requestSpec, responseSpec); + Integer groupID = GroupHelper.createGroup(requestSpec, responseSpec,true); + groupID = GroupHelper.associateClient(requestSpec, responseSpec, groupID.toString(),clientID.toString()); + + Integer loanProductID = createLoanProduct(); + Integer loanID = applyForLoanApplication(groupID, loanProductID); + ArrayList loanSchedule = loanTransactionHelper.getLoanRepaymentSchedule(requestSpec, responseSpec, loanID); + verifyLoanRepaymentSchedule(loanSchedule); + + } + + private Integer createLoanProduct() { + System.out.println("------------------------------CREATING NEW LOAN PRODUCT ---------------------------------------"); + String loanProductJSON = new LoanProductTestBuilder() // + .withPrincipal("12,000.00") // + .withNumberOfRepayments("4") // + .withRepaymentAfterEvery("1") // + .withRepaymentTypeAsMonth() // + .withinterestRatePerPeriod("1") // + .withInterestRateFrequencyTypeAsMonths() // + .withAmortizationTypeAsEqualInstallments() // + .withInterestTypeAsDecliningBalance() // + .build(); + return loanTransactionHelper.getLoanProductId(loanProductJSON); + } + + private Integer applyForLoanApplication(final Integer groupID, 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") // + .withAmortizationTypeAsEqualInstallments() // + .withInterestTypeAsDecliningBalance() // + .withInterestCalculationPeriodTypeSameAsRepaymentPeriod() // + .withExpectedDisbursementDate("20 September 2011") // + .withSubmittedOnDate("20 September 2011") // + .withLoanType("group") + .build(groupID.toString(), loanProductID.toString()); + System.out.println(loanApplicationJSON); + return loanTransactionHelper.getLoanId(loanApplicationJSON); + } + + 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.71"), 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.1"), 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.7"), loanSchedule.get(4).get("principalDue")); + assertEquals("Checking for Interest Due for 4th Month", new Float("61.79"), loanSchedule.get(4).get("interestOriginalDue")); + } +} \ No newline at end of file diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/GroupTest.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/GroupTest.java index 877cbbba2..8785a2b6a 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/GroupTest.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/GroupTest.java @@ -60,7 +60,7 @@ public class GroupTest { GroupHelper.verifyGroupDetails(requestSpec, responseSpec, groupID,"name",updatedGroupName); groupID = GroupHelper.createGroup(requestSpec, responseSpec); - Integer groupID2 = GroupHelper.deleteGroup(requestSpec, responseSpec, groupID.toString()); + GroupHelper.deleteGroup(requestSpec, responseSpec, groupID.toString()); GroupHelper.verifyGroupDeleted(requestSpec, responseSpec, groupID); } } \ No newline at end of file diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/loans/LoanApplicationTestBuilder.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/loans/LoanApplicationTestBuilder.java index b1b0de92a..f9bd1894b 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/loans/LoanApplicationTestBuilder.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/loans/LoanApplicationTestBuilder.java @@ -33,12 +33,15 @@ public class LoanApplicationTestBuilder { private String submittedOnDate = ""; private String loanType = "individual"; - public String build(final String clientID, final String loanProductId) { + public String build(final String ID, final String loanProductId) { HashMap map = new HashMap(); map.put("dateFormat", "dd MMMM yyyy"); map.put("locale", "en_GB"); - map.put("clientId", clientID); + if (loanType == "group") + map.put("groupId", ID); + else + map.put("clientId", ID); map.put("productId", loanProductId); map.put("principal", principal); map.put("loanTermFrequency", loanTermFrequency);