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;
import static org.junit.Assert.assertEquals;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.junit.Before;
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.CommonConstants;
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.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")
public class LoanApplicationApprovalTest {
@@ -49,16 +48,15 @@ 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
public void loanApplicationApprovedAmountLessThanProposedAmount() {
final String proposedAmount = "8000";
final String approvalAmount = "5000";
final String approveDate = "20 September 2012";
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2012");
final Integer loanProductID = this.loanTransactionHelper.getLoanProductId(new LoanProductTestBuilder().build(null));
final Integer loanID = applyForLoanApplication(clientID, loanProductID, proposedAmount);
@@ -68,22 +66,23 @@ public class LoanApplicationApprovalTest {
final String expectedDisbursementDate = 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);
}
/*
* 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
public void loanApplicationApprovedAmountGreaterThanProposedAmount() {
final String proposedAmount = "5000";
final String approvalAmount = "9000";
final String approveDate = "20 September 2011";
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2012");
final Integer loanProductID = this.loanTransactionHelper.getLoanProductId(new LoanProductTestBuilder().build(null));
final Integer loanID = applyForLoanApplication(clientID, loanProductID, proposedAmount);
@@ -92,171 +91,149 @@ public class LoanApplicationApprovalTest {
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpecForStatusCode403);
@SuppressWarnings("unchecked")
List<HashMap> error = (List<HashMap>) this.loanTransactionHelper.approveLoan(approveDate, approvalAmount, loanID,
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));
assertEquals("error.msg.loan.approval.amount.can't.be.greater.than.loan.amount.demanded",
error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
}
private HashMap createTrancheDetail(final String date, final String amount) {
HashMap<String, Object> detail = new HashMap<>();
detail.put("expectedDisbursementDate", date);
detail.put("principal", amount);
private HashMap createTrancheDetail(final String date, final String amount) {
HashMap<String, Object> detail = new HashMap<>();
detail.put("expectedDisbursementDate", date);
detail.put("principal", amount);
return detail;
}
return detail;
}
@Test
public void loanApplicationApprovalAndValidationForMultiDisburseLoans() {
List<HashMap> createTranches = new ArrayList<>();
createTranches.add(createTrancheDetail("1 March 2014", "1000"));
createTranches.add(createTrancheDetail("23 March 2014", "4000"));
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()
.withInterestTypeAsDecliningBalance().
withTranches(true).build(null));
System.out.println("----------------------------------LOAN PRODUCT CREATED WITH ID-------------------------------------------"+loanProductID);
this.trancheLoansApprovedAmountLesserThanProposedAmount(clientID, loanProductID, createTranches);
this.trancheLoansApprovalValidation(clientID, loanProductID, createTranches);
.withInterestTypeAsDecliningBalance().withTranches(true).build(null));
System.out.println("----------------------------------LOAN PRODUCT CREATED WITH ID-------------------------------------------"
+ loanProductID);
this.trancheLoansApprovedAmountLesserThanProposedAmount(clientID, loanProductID, createTranches);
this.trancheLoansApprovalValidation(clientID, loanProductID, createTranches);
}
private void trancheLoansApprovedAmountLesserThanProposedAmount(
Integer clientID, Integer loanProductID,
List<HashMap> createTranches) {
final String proposedAmount = "5000";
final String approvalAmount = "2000";
final String approveDate = "1 March 2014";
final String expectedDisbursementDate = "1 March 2014";
List<HashMap> approveTranches = new ArrayList<>();
approveTranches.add(createTrancheDetail("1 March 2014", "1000"));
approveTranches.add(createTrancheDetail("23 March 2014", "1000"));
private void trancheLoansApprovedAmountLesserThanProposedAmount(Integer clientID, Integer loanProductID, List<HashMap> createTranches) {
final String proposedAmount = "5000";
final String approvalAmount = "2000";
final String approveDate = "1 March 2014";
final String expectedDisbursementDate = "1 March 2014";
final Integer loanID = applyForLoanApplicationWithTranches(clientID,
loanProductID, proposedAmount, createTranches);
System.out
.println("-----------------------------------LOAN CREATED WITH LOANID-------------------------------------------------"
+ loanID);
List<HashMap> approveTranches = new ArrayList<>();
approveTranches.add(createTrancheDetail("1 March 2014", "1000"));
approveTranches.add(createTrancheDetail("23 March 2014", "1000"));
HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(
this.requestSpec, this.responseSpec, loanID);
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
final Integer loanID = applyForLoanApplicationWithTranches(clientID, loanProductID, proposedAmount, createTranches);
System.out.println("-----------------------------------LOAN CREATED WITH LOANID-------------------------------------------------"
+ loanID);
System.out
.println("-----------------------------------APPROVE LOAN-----------------------------------------------------------");
loanStatusHashMap = this.loanTransactionHelper
.approveLoanWithApproveAmount(approveDate,
expectedDisbursementDate, approvalAmount, loanID,
approveTranches);
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
System.out
.println("-----------------------------------MULTI DISBURSAL LOAN APPROVED SUCCESSFULLY---------------------------------------");
HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID);
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
}
System.out.println("-----------------------------------APPROVE LOAN-----------------------------------------------------------");
loanStatusHashMap = this.loanTransactionHelper.approveLoanWithApproveAmount(approveDate, expectedDisbursementDate, approvalAmount,
loanID, approveTranches);
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
System.out
.println("-----------------------------------MULTI DISBURSAL LOAN APPROVED SUCCESSFULLY---------------------------------------");
private void trancheLoansApprovalValidation(Integer clientID,
Integer loanProductID, List<HashMap> createTranches) {
final String proposedAmount = "5000";
final String approvalAmount1 = "10000";
final String approvalAmount2 = "3000";
final String approvalAmount3 = "400";
final String approvalAmount4 = "200";
final String approvalAmount5 = "400";
}
final String approveDate = "1 March 2014";
final String expectedDisbursementDate = "1 March 2014";
private void trancheLoansApprovalValidation(Integer clientID, Integer loanProductID, List<HashMap> createTranches) {
final String proposedAmount = "5000";
final String approvalAmount1 = "10000";
final String approvalAmount2 = "3000";
final String approvalAmount3 = "400";
final String approvalAmount4 = "200";
List<HashMap> approveTranche1 = new ArrayList<>();
approveTranche1.add(createTrancheDetail("1 March 2014", "5000"));
approveTranche1.add(createTrancheDetail("23 March 2014", "5000"));
final String approveDate = "1 March 2014";
final String expectedDisbursementDate = "1 March 2014";
List<HashMap> approveTranche2 = new ArrayList<>();
approveTranche2.add(createTrancheDetail("1 March 2014", "1000"));
approveTranche2.add(createTrancheDetail("23 March 2014", "1000"));
approveTranche2.add(createTrancheDetail("23 March 2014", "1000"));
List<HashMap> approveTranche1 = new ArrayList<>();
approveTranche1.add(createTrancheDetail("1 March 2014", "5000"));
approveTranche1.add(createTrancheDetail("23 March 2014", "5000"));
List<HashMap> approveTranche3 = new ArrayList<>();
approveTranche3.add(createTrancheDetail("1 March 2014", "100"));
approveTranche3.add(createTrancheDetail("23 March 2014", "100"));
approveTranche3.add(createTrancheDetail("24 March 2014", "100"));
approveTranche3.add(createTrancheDetail("25 March 2014", "100"));
List<HashMap> approveTranche2 = new ArrayList<>();
approveTranche2.add(createTrancheDetail("1 March 2014", "1000"));
approveTranche2.add(createTrancheDetail("23 March 2014", "1000"));
approveTranche2.add(createTrancheDetail("23 March 2014", "1000"));
List<HashMap> approveTranche4 = new ArrayList<>();
approveTranche4.add(createTrancheDetail("1 March 2014", "100"));
approveTranche4.add(createTrancheDetail("23 March 2014", "100"));
approveTranche4.add(createTrancheDetail("24 March 2014", "100"));
List<HashMap> approveTranche3 = new ArrayList<>();
approveTranche3.add(createTrancheDetail("1 March 2014", "100"));
approveTranche3.add(createTrancheDetail("23 March 2014", "100"));
approveTranche3.add(createTrancheDetail("24 March 2014", "100"));
approveTranche3.add(createTrancheDetail("25 March 2014", "100"));
List<HashMap> approveTranche5 = new ArrayList<>();
List<HashMap> approveTranche4 = new ArrayList<>();
approveTranche4.add(createTrancheDetail("1 March 2014", "100"));
approveTranche4.add(createTrancheDetail("23 March 2014", "100"));
approveTranche4.add(createTrancheDetail("24 March 2014", "100"));
final Integer loanID = applyForLoanApplicationWithTranches(clientID,
loanProductID, proposedAmount, createTranches);
System.out
.println("-----------------------------------LOAN CREATED WITH LOANID-------------------------------------------------"
+ loanID);
final Integer loanID = applyForLoanApplicationWithTranches(clientID, loanProductID, proposedAmount, createTranches);
System.out.println("-----------------------------------LOAN CREATED WITH LOANID-------------------------------------------------"
+ loanID);
HashMap<String, Object> loanStatusHashMap = LoanStatusChecker
.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID);
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
HashMap<String, Object> loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID);
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
System.out
.println("-----------------------------------APPROVE LOAN-----------------------------------------------------------");
this.loanTransactionHelper = new LoanTransactionHelper(
this.requestSpec, this.responseSpecForStatusCode400);
System.out.println("-----------------------------------APPROVE LOAN-----------------------------------------------------------");
this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpecForStatusCode400);
/* Tranches with same expected disbursement date */
List<HashMap<String, Object>> error = this.loanTransactionHelper
.approveLoanForTranches(approveDate, expectedDisbursementDate,
approvalAmount2, loanID, approveTranche2,
CommonConstants.RESPONSE_ERROR);
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 */
List<HashMap<String, Object>> error = this.loanTransactionHelper.approveLoanForTranches(approveDate, expectedDisbursementDate,
approvalAmount2, loanID, approveTranche2, CommonConstants.RESPONSE_ERROR);
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 */
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));
/* Sum of tranches is greater than approved amount */
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(
this.requestSpec, this.responseSpecForStatusCode403);
this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpecForStatusCode403);
/* Sum of tranches exceeds the proposed amount */
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 */
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));
/* No. of tranches exceeds the max tranche count at product level */
error = this.loanTransactionHelper.approveLoanForTranches(approveDate,
expectedDisbursementDate, approvalAmount3, loanID,
approveTranche3, CommonConstants.RESPONSE_ERROR);
assertEquals("error.msg.disbursementData.exceeding.max.tranche.count",
error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
/* No. of tranches exceeds the max tranche count at product level */
error = this.loanTransactionHelper.approveLoanForTranches(approveDate, expectedDisbursementDate, approvalAmount3, loanID,
approveTranche3, CommonConstants.RESPONSE_ERROR);
assertEquals("error.msg.disbursementData.exceeding.max.tranche.count", error.get(0)
.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
/* If tranches are not specified for a multi-disburse loan */
/**
* 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));
**/
}
/* If tranches are not specified for a multi-disburse loan */
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) {
final String loanApplication = new LoanApplicationTestBuilder().withPrincipal(proposedAmount).withLoanTermFrequency("5")
.withLoanTermFrequencyAsMonths().withNumberOfRepayments("5").withRepaymentEveryAfter("1")
@@ -265,29 +242,26 @@ public class LoanApplicationApprovalTest {
return this.loanTransactionHelper.getLoanId(loanApplication);
}
private Integer applyForLoanApplicationWithTranches(final Integer clientID,
final Integer loanProductID, String principal,
List<HashMap> tranches) {
System.out
.println("--------------------------------APPLYING FOR LOAN APPLICATION--------------------------------");
final String loanApplicationJSON = new LoanApplicationTestBuilder()
//
.withPrincipal(principal)
//
.withLoanTermFrequency("5")
//
.withLoanTermFrequencyAsMonths()
//
.withNumberOfRepayments("5").withRepaymentEveryAfter("1")
.withRepaymentFrequencyTypeAsMonths() //
.withInterestRatePerPeriod("2") //
.withExpectedDisbursementDate("1 March 2014") //
.withTranches(tranches) //
.withInterestTypeAsDecliningBalance() //
.withSubmittedOnDate("1 March 2014") //
.build(clientID.toString(), loanProductID.toString(), null);
private Integer applyForLoanApplicationWithTranches(final Integer clientID, final Integer loanProductID, String principal,
List<HashMap> tranches) {
System.out.println("--------------------------------APPLYING FOR LOAN APPLICATION--------------------------------");
final String loanApplicationJSON = new LoanApplicationTestBuilder()
//
.withPrincipal(principal)
//
.withLoanTermFrequency("5")
//
.withLoanTermFrequencyAsMonths()
//
.withNumberOfRepayments("5").withRepaymentEveryAfter("1").withRepaymentFrequencyTypeAsMonths() //
.withInterestRatePerPeriod("2") //
.withExpectedDisbursementDate("1 March 2014") //
.withTranches(tranches) //
.withInterestTypeAsDecliningBalance() //
.withSubmittedOnDate("1 March 2014") //
.build(clientID.toString(), loanProductID.toString(), null);
return this.loanTransactionHelper.getLoanId(loanApplicationJSON);
}
return this.loanTransactionHelper.getLoanId(loanApplicationJSON);
}
}