fixing more failing test cases

This commit is contained in:
Vishwas Babu A J
2015-03-04 23:39:03 +05:30
parent d00f793f99
commit 221cb1c17d
@@ -5,21 +5,14 @@
*/ */
package org.mifosplatform.integrationtests; package org.mifosplatform.integrationtests;
import static org.junit.Assert.assertEquals;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals;
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.ClientHelper; import org.mifosplatform.integrationtests.common.ClientHelper;
import org.mifosplatform.integrationtests.common.CommonConstants; import org.mifosplatform.integrationtests.common.CommonConstants;
import org.mifosplatform.integrationtests.common.Utils; import org.mifosplatform.integrationtests.common.Utils;
@@ -28,6 +21,12 @@ import org.mifosplatform.integrationtests.common.loans.LoanProductTestBuilder;
import org.mifosplatform.integrationtests.common.loans.LoanStatusChecker; import org.mifosplatform.integrationtests.common.loans.LoanStatusChecker;
import org.mifosplatform.integrationtests.common.loans.LoanTransactionHelper; 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;
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public class LoanApplicationApprovalTest { public class LoanApplicationApprovalTest {
@@ -49,8 +48,7 @@ public class LoanApplicationApprovalTest {
} }
/* /*
* Positive test case: Approved amount non zero is less than proposed amount * Positive test case: Approved amount non zero is less than proposed amount
*
*/ */
@Test @Test
public void loanApplicationApprovedAmountLessThanProposedAmount() { public void loanApplicationApprovedAmountLessThanProposedAmount() {
@@ -68,14 +66,15 @@ public class LoanApplicationApprovalTest {
final String expectedDisbursementDate = null; final String expectedDisbursementDate = null;
List<HashMap> approveTranches = null; List<HashMap> approveTranches = null;
loanStatusHashMap = this.loanTransactionHelper.approveLoanWithApproveAmount(approveDate,expectedDisbursementDate, approvalAmount, loanID, approveTranches); loanStatusHashMap = this.loanTransactionHelper.approveLoanWithApproveAmount(approveDate, expectedDisbursementDate, approvalAmount,
loanID, approveTranches);
LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap); LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
} }
/* /*
* Negative test case: Approved amount non zero is greater than proposed amount * Negative test case: Approved amount non zero is greater than proposed
* * amount
*/ */
@Test @Test
public void loanApplicationApprovedAmountGreaterThanProposedAmount() { public void loanApplicationApprovedAmountGreaterThanProposedAmount() {
@@ -97,18 +96,18 @@ public class LoanApplicationApprovalTest {
List<HashMap> error = (List<HashMap>) this.loanTransactionHelper.approveLoan(approveDate, approvalAmount, loanID, List<HashMap> error = (List<HashMap>) this.loanTransactionHelper.approveLoan(approveDate, approvalAmount, loanID,
CommonConstants.RESPONSE_ERROR); CommonConstants.RESPONSE_ERROR);
assertEquals("error.msg.loan.approval.amount.can't.be.greater.than.loan.amount.demanded", error assertEquals("error.msg.loan.approval.amount.can't.be.greater.than.loan.amount.demanded",
.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE)); error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
} }
private HashMap createTrancheDetail(final String date, final String amount) { private HashMap createTrancheDetail(final String date, final String amount) {
HashMap<String, Object> detail = new HashMap<>(); HashMap<String, Object> detail = new HashMap<>();
detail.put("expectedDisbursementDate", date); detail.put("expectedDisbursementDate", date);
detail.put("principal", amount); detail.put("principal", amount);
return detail; return detail;
} }
@Test @Test
public void loanApplicationApprovalAndValidationForMultiDisburseLoans() { public void loanApplicationApprovalAndValidationForMultiDisburseLoans() {
@@ -118,144 +117,122 @@ public class LoanApplicationApprovalTest {
createTranches.add(createTrancheDetail("23 March 2014", "4000")); createTranches.add(createTrancheDetail("23 March 2014", "4000"));
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2014"); final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2014");
System.out.println("---------------------------------CLIENT CREATED WITH ID---------------------------------------------------"+clientID); System.out.println("---------------------------------CLIENT CREATED WITH ID---------------------------------------------------"
+ clientID);
final Integer loanProductID = this.loanTransactionHelper.getLoanProductId(new LoanProductTestBuilder() final Integer loanProductID = this.loanTransactionHelper.getLoanProductId(new LoanProductTestBuilder()
.withInterestTypeAsDecliningBalance(). .withInterestTypeAsDecliningBalance().withTranches(true).build(null));
withTranches(true).build(null)); System.out.println("----------------------------------LOAN PRODUCT CREATED WITH ID-------------------------------------------"
System.out.println("----------------------------------LOAN PRODUCT CREATED WITH ID-------------------------------------------"+loanProductID); + loanProductID);
this.trancheLoansApprovedAmountLesserThanProposedAmount(clientID, loanProductID, createTranches); this.trancheLoansApprovedAmountLesserThanProposedAmount(clientID, loanProductID, createTranches);
this.trancheLoansApprovalValidation(clientID, loanProductID, createTranches); this.trancheLoansApprovalValidation(clientID, loanProductID, createTranches);
} }
private void trancheLoansApprovedAmountLesserThanProposedAmount( private void trancheLoansApprovedAmountLesserThanProposedAmount(Integer clientID, Integer loanProductID, List<HashMap> createTranches) {
Integer clientID, Integer loanProductID, final String proposedAmount = "5000";
List<HashMap> createTranches) { final String approvalAmount = "2000";
final String proposedAmount = "5000"; final String approveDate = "1 March 2014";
final String approvalAmount = "2000"; final String expectedDisbursementDate = "1 March 2014";
final String approveDate = "1 March 2014";
final String expectedDisbursementDate = "1 March 2014";
List<HashMap> approveTranches = new ArrayList<>(); List<HashMap> approveTranches = new ArrayList<>();
approveTranches.add(createTrancheDetail("1 March 2014", "1000")); approveTranches.add(createTrancheDetail("1 March 2014", "1000"));
approveTranches.add(createTrancheDetail("23 March 2014", "1000")); approveTranches.add(createTrancheDetail("23 March 2014", "1000"));
final Integer loanID = applyForLoanApplicationWithTranches(clientID, final Integer loanID = applyForLoanApplicationWithTranches(clientID, loanProductID, proposedAmount, createTranches);
loanProductID, proposedAmount, createTranches); System.out.println("-----------------------------------LOAN CREATED WITH LOANID-------------------------------------------------"
System.out + loanID);
.println("-----------------------------------LOAN CREATED WITH LOANID-------------------------------------------------"
+ loanID);
HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan( HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID);
this.requestSpec, this.responseSpec, loanID); LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
System.out System.out.println("-----------------------------------APPROVE LOAN-----------------------------------------------------------");
.println("-----------------------------------APPROVE LOAN-----------------------------------------------------------"); loanStatusHashMap = this.loanTransactionHelper.approveLoanWithApproveAmount(approveDate, expectedDisbursementDate, approvalAmount,
loanStatusHashMap = this.loanTransactionHelper loanID, approveTranches);
.approveLoanWithApproveAmount(approveDate, LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
expectedDisbursementDate, approvalAmount, loanID, LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
approveTranches); System.out
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap); .println("-----------------------------------MULTI DISBURSAL LOAN APPROVED SUCCESSFULLY---------------------------------------");
LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
System.out
.println("-----------------------------------MULTI DISBURSAL LOAN APPROVED SUCCESSFULLY---------------------------------------");
} }
private void trancheLoansApprovalValidation(Integer clientID, private void trancheLoansApprovalValidation(Integer clientID, Integer loanProductID, List<HashMap> createTranches) {
Integer loanProductID, List<HashMap> createTranches) { final String proposedAmount = "5000";
final String proposedAmount = "5000"; final String approvalAmount1 = "10000";
final String approvalAmount1 = "10000"; final String approvalAmount2 = "3000";
final String approvalAmount2 = "3000"; final String approvalAmount3 = "400";
final String approvalAmount3 = "400"; final String approvalAmount4 = "200";
final String approvalAmount4 = "200";
final String approvalAmount5 = "400";
final String approveDate = "1 March 2014"; final String approveDate = "1 March 2014";
final String expectedDisbursementDate = "1 March 2014"; final String expectedDisbursementDate = "1 March 2014";
List<HashMap> approveTranche1 = new ArrayList<>(); List<HashMap> approveTranche1 = new ArrayList<>();
approveTranche1.add(createTrancheDetail("1 March 2014", "5000")); approveTranche1.add(createTrancheDetail("1 March 2014", "5000"));
approveTranche1.add(createTrancheDetail("23 March 2014", "5000")); approveTranche1.add(createTrancheDetail("23 March 2014", "5000"));
List<HashMap> approveTranche2 = new ArrayList<>(); List<HashMap> approveTranche2 = new ArrayList<>();
approveTranche2.add(createTrancheDetail("1 March 2014", "1000")); approveTranche2.add(createTrancheDetail("1 March 2014", "1000"));
approveTranche2.add(createTrancheDetail("23 March 2014", "1000")); approveTranche2.add(createTrancheDetail("23 March 2014", "1000"));
approveTranche2.add(createTrancheDetail("23 March 2014", "1000")); approveTranche2.add(createTrancheDetail("23 March 2014", "1000"));
List<HashMap> approveTranche3 = new ArrayList<>(); List<HashMap> approveTranche3 = new ArrayList<>();
approveTranche3.add(createTrancheDetail("1 March 2014", "100")); approveTranche3.add(createTrancheDetail("1 March 2014", "100"));
approveTranche3.add(createTrancheDetail("23 March 2014", "100")); approveTranche3.add(createTrancheDetail("23 March 2014", "100"));
approveTranche3.add(createTrancheDetail("24 March 2014", "100")); approveTranche3.add(createTrancheDetail("24 March 2014", "100"));
approveTranche3.add(createTrancheDetail("25 March 2014", "100")); approveTranche3.add(createTrancheDetail("25 March 2014", "100"));
List<HashMap> approveTranche4 = new ArrayList<>(); List<HashMap> approveTranche4 = new ArrayList<>();
approveTranche4.add(createTrancheDetail("1 March 2014", "100")); approveTranche4.add(createTrancheDetail("1 March 2014", "100"));
approveTranche4.add(createTrancheDetail("23 March 2014", "100")); approveTranche4.add(createTrancheDetail("23 March 2014", "100"));
approveTranche4.add(createTrancheDetail("24 March 2014", "100")); approveTranche4.add(createTrancheDetail("24 March 2014", "100"));
List<HashMap> approveTranche5 = new ArrayList<>(); final Integer loanID = applyForLoanApplicationWithTranches(clientID, loanProductID, proposedAmount, createTranches);
System.out.println("-----------------------------------LOAN CREATED WITH LOANID-------------------------------------------------"
+ loanID);
final Integer loanID = applyForLoanApplicationWithTranches(clientID, HashMap<String, Object> loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID);
loanProductID, proposedAmount, createTranches); LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
System.out
.println("-----------------------------------LOAN CREATED WITH LOANID-------------------------------------------------"
+ loanID);
HashMap<String, Object> loanStatusHashMap = LoanStatusChecker System.out.println("-----------------------------------APPROVE LOAN-----------------------------------------------------------");
.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID); this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpecForStatusCode400);
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
System.out /* Tranches with same expected disbursement date */
.println("-----------------------------------APPROVE LOAN-----------------------------------------------------------"); List<HashMap<String, Object>> error = this.loanTransactionHelper.approveLoanForTranches(approveDate, expectedDisbursementDate,
this.loanTransactionHelper = new LoanTransactionHelper( approvalAmount2, loanID, approveTranche2, CommonConstants.RESPONSE_ERROR);
this.requestSpec, this.responseSpecForStatusCode400); assertEquals("validation.msg.loan.expectedDisbursementDate.disbursement.date.must.be.unique.for.tranches",
error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
/* Tranches with same expected disbursement date */ /* Sum of tranches is greater than approved amount */
List<HashMap<String, Object>> error = this.loanTransactionHelper error = this.loanTransactionHelper.approveLoanForTranches(approveDate, expectedDisbursementDate, approvalAmount4, loanID,
.approveLoanForTranches(approveDate, expectedDisbursementDate, approveTranche4, CommonConstants.RESPONSE_ERROR);
approvalAmount2, loanID, approveTranche2, assertEquals("validation.msg.loan.principal.sum.of.multi.disburse.amounts.must.be.equal.to.or.lesser.than.approved.principal",
CommonConstants.RESPONSE_ERROR); error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
assertEquals(
"validation.msg.loan.expectedDisbursementDate.disbursement.date.must.be.unique.for.tranches",
error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
/* Sum of tranches is greater than approved amount */ this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpecForStatusCode403);
error = this.loanTransactionHelper.approveLoanForTranches(approveDate,
expectedDisbursementDate, approvalAmount4, loanID,
approveTranche4, CommonConstants.RESPONSE_ERROR);
assertEquals(
"validation.msg.loan.principal.sum.of.multi.disburse.amounts.must.be.equal.to.or.lesser.than.approved.principal",
error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
this.loanTransactionHelper = new LoanTransactionHelper( /* Sum of tranches exceeds the proposed amount */
this.requestSpec, this.responseSpecForStatusCode403); error = this.loanTransactionHelper.approveLoanForTranches(approveDate, expectedDisbursementDate, approvalAmount1, loanID,
approveTranche1, CommonConstants.RESPONSE_ERROR);
assertEquals("error.msg.loan.approval.amount.can't.be.greater.than.loan.amount.demanded",
error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
/* Sum of tranches exceeds the proposed amount */ /* No. of tranches exceeds the max tranche count at product level */
error = this.loanTransactionHelper.approveLoanForTranches(approveDate, error = this.loanTransactionHelper.approveLoanForTranches(approveDate, expectedDisbursementDate, approvalAmount3, loanID,
expectedDisbursementDate, approvalAmount1, loanID, approveTranche3, CommonConstants.RESPONSE_ERROR);
approveTranche1, CommonConstants.RESPONSE_ERROR); assertEquals("error.msg.disbursementData.exceeding.max.tranche.count", error.get(0)
assertEquals( .get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
"error.msg.loan.approval.amount.can't.be.greater.than.loan.amount.demanded",
error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
/* No. of tranches exceeds the max tranche count at product level */ /* If tranches are not specified for a multi-disburse loan */
error = this.loanTransactionHelper.approveLoanForTranches(approveDate, /**
expectedDisbursementDate, approvalAmount3, loanID, * error =
approveTranche3, CommonConstants.RESPONSE_ERROR); * this.loanTransactionHelper.approveLoanForTranches(approveDate,
assertEquals("error.msg.disbursementData.exceeding.max.tranche.count", * expectedDisbursementDate, approvalAmount5, loanID, approveTranche5,
error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE)); * CommonConstants.RESPONSE_ERROR);
* assertEquals("error.msg.disbursementData.required",
/* If tranches are not specified for a multi-disburse loan */ * error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
error = this.loanTransactionHelper.approveLoanForTranches(approveDate, **/
expectedDisbursementDate, approvalAmount5, loanID, }
approveTranche5, CommonConstants.RESPONSE_ERROR);
assertEquals("error.msg.disbursementData.required",
error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
}
private Integer applyForLoanApplication(final Integer clientID, final Integer loanProductID, final String proposedAmount) { private Integer applyForLoanApplication(final Integer clientID, final Integer loanProductID, final String proposedAmount) {
final String loanApplication = new LoanApplicationTestBuilder().withPrincipal(proposedAmount).withLoanTermFrequency("5") final String loanApplication = new LoanApplicationTestBuilder().withPrincipal(proposedAmount).withLoanTermFrequency("5")
@@ -265,29 +242,26 @@ public class LoanApplicationApprovalTest {
return this.loanTransactionHelper.getLoanId(loanApplication); return this.loanTransactionHelper.getLoanId(loanApplication);
} }
private Integer applyForLoanApplicationWithTranches(final Integer clientID, private Integer applyForLoanApplicationWithTranches(final Integer clientID, final Integer loanProductID, String principal,
final Integer loanProductID, String principal, List<HashMap> tranches) {
List<HashMap> tranches) { System.out.println("--------------------------------APPLYING FOR LOAN APPLICATION--------------------------------");
System.out final String loanApplicationJSON = new LoanApplicationTestBuilder()
.println("--------------------------------APPLYING FOR LOAN APPLICATION--------------------------------"); //
final String loanApplicationJSON = new LoanApplicationTestBuilder() .withPrincipal(principal)
// //
.withPrincipal(principal) .withLoanTermFrequency("5")
// //
.withLoanTermFrequency("5") .withLoanTermFrequencyAsMonths()
// //
.withLoanTermFrequencyAsMonths() .withNumberOfRepayments("5").withRepaymentEveryAfter("1").withRepaymentFrequencyTypeAsMonths() //
// .withInterestRatePerPeriod("2") //
.withNumberOfRepayments("5").withRepaymentEveryAfter("1") .withExpectedDisbursementDate("1 March 2014") //
.withRepaymentFrequencyTypeAsMonths() // .withTranches(tranches) //
.withInterestRatePerPeriod("2") // .withInterestTypeAsDecliningBalance() //
.withExpectedDisbursementDate("1 March 2014") // .withSubmittedOnDate("1 March 2014") //
.withTranches(tranches) // .build(clientID.toString(), loanProductID.toString(), null);
.withInterestTypeAsDecliningBalance() //
.withSubmittedOnDate("1 March 2014") //
.build(clientID.toString(), loanProductID.toString(), null);
return this.loanTransactionHelper.getLoanId(loanApplicationJSON); return this.loanTransactionHelper.getLoanId(loanApplicationJSON);
} }
} }