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 {
@@ -50,7 +49,6 @@ 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,8 +96,8 @@ 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));
} }
@@ -118,21 +117,20 @@ 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,
List<HashMap> createTranches) {
final String proposedAmount = "5000"; final String proposedAmount = "5000";
final String approvalAmount = "2000"; final String approvalAmount = "2000";
final String approveDate = "1 March 2014"; final String approveDate = "1 March 2014";
@@ -142,22 +140,16 @@ public class LoanApplicationApprovalTest {
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
.println("-----------------------------------LOAN CREATED WITH LOANID-------------------------------------------------"
+ 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,
expectedDisbursementDate, approvalAmount, loanID,
approveTranches);
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap); LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap); LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
System.out System.out
@@ -165,14 +157,12 @@ public class LoanApplicationApprovalTest {
} }
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";
@@ -197,64 +187,51 @@ public class LoanApplicationApprovalTest {
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-------------------------------------------------"
final Integer loanID = applyForLoanApplicationWithTranches(clientID,
loanProductID, proposedAmount, createTranches);
System.out
.println("-----------------------------------LOAN CREATED WITH LOANID-------------------------------------------------"
+ loanID); + loanID);
HashMap<String, Object> loanStatusHashMap = LoanStatusChecker HashMap<String, Object> loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID);
.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID);
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap); LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
System.out System.out.println("-----------------------------------APPROVE LOAN-----------------------------------------------------------");
.println("-----------------------------------APPROVE LOAN-----------------------------------------------------------"); this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpecForStatusCode400);
this.loanTransactionHelper = new LoanTransactionHelper(
this.requestSpec, this.responseSpecForStatusCode400);
/* Tranches with same expected disbursement date */ /* Tranches with same expected disbursement date */
List<HashMap<String, Object>> error = this.loanTransactionHelper List<HashMap<String, Object>> error = this.loanTransactionHelper.approveLoanForTranches(approveDate, expectedDisbursementDate,
.approveLoanForTranches(approveDate, expectedDisbursementDate, approvalAmount2, loanID, approveTranche2, CommonConstants.RESPONSE_ERROR);
approvalAmount2, loanID, approveTranche2, assertEquals("validation.msg.loan.expectedDisbursementDate.disbursement.date.must.be.unique.for.tranches",
CommonConstants.RESPONSE_ERROR);
assertEquals(
"validation.msg.loan.expectedDisbursementDate.disbursement.date.must.be.unique.for.tranches",
error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE)); error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
/* Sum of tranches is greater than approved amount */ /* Sum of tranches is greater than approved amount */
error = this.loanTransactionHelper.approveLoanForTranches(approveDate, error = this.loanTransactionHelper.approveLoanForTranches(approveDate, expectedDisbursementDate, approvalAmount4, loanID,
expectedDisbursementDate, approvalAmount4, loanID,
approveTranche4, CommonConstants.RESPONSE_ERROR); approveTranche4, CommonConstants.RESPONSE_ERROR);
assertEquals( assertEquals("validation.msg.loan.principal.sum.of.multi.disburse.amounts.must.be.equal.to.or.lesser.than.approved.principal",
"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)); error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
this.loanTransactionHelper = new LoanTransactionHelper( this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpecForStatusCode403);
this.requestSpec, this.responseSpecForStatusCode403);
/* Sum of tranches exceeds the proposed amount */ /* Sum of tranches exceeds the proposed amount */
error = this.loanTransactionHelper.approveLoanForTranches(approveDate, error = this.loanTransactionHelper.approveLoanForTranches(approveDate, expectedDisbursementDate, approvalAmount1, loanID,
expectedDisbursementDate, approvalAmount1, loanID,
approveTranche1, CommonConstants.RESPONSE_ERROR); approveTranche1, CommonConstants.RESPONSE_ERROR);
assertEquals( assertEquals("error.msg.loan.approval.amount.can't.be.greater.than.loan.amount.demanded",
"error.msg.loan.approval.amount.can't.be.greater.than.loan.amount.demanded",
error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE)); error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
/* No. of tranches exceeds the max tranche count at product level */ /* 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, approvalAmount3, loanID,
approveTranche3, CommonConstants.RESPONSE_ERROR); approveTranche3, CommonConstants.RESPONSE_ERROR);
assertEquals("error.msg.disbursementData.exceeding.max.tranche.count", assertEquals("error.msg.disbursementData.exceeding.max.tranche.count", error.get(0)
error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE)); .get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
/* If tranches are not specified for a multi-disburse loan */ /* If tranches are not specified for a multi-disburse loan */
error = this.loanTransactionHelper.approveLoanForTranches(approveDate, /**
expectedDisbursementDate, approvalAmount5, loanID, * error =
approveTranche5, CommonConstants.RESPONSE_ERROR); * this.loanTransactionHelper.approveLoanForTranches(approveDate,
assertEquals("error.msg.disbursementData.required", * expectedDisbursementDate, approvalAmount5, loanID, approveTranche5,
error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE)); * 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) {
@@ -265,11 +242,9 @@ 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 System.out.println("--------------------------------APPLYING FOR LOAN APPLICATION--------------------------------");
.println("--------------------------------APPLYING FOR LOAN APPLICATION--------------------------------");
final String loanApplicationJSON = new LoanApplicationTestBuilder() final String loanApplicationJSON = new LoanApplicationTestBuilder()
// //
.withPrincipal(principal) .withPrincipal(principal)
@@ -278,8 +253,7 @@ public class LoanApplicationApprovalTest {
// //
.withLoanTermFrequencyAsMonths() .withLoanTermFrequencyAsMonths()
// //
.withNumberOfRepayments("5").withRepaymentEveryAfter("1") .withNumberOfRepayments("5").withRepaymentEveryAfter("1").withRepaymentFrequencyTypeAsMonths() //
.withRepaymentFrequencyTypeAsMonths() //
.withInterestRatePerPeriod("2") // .withInterestRatePerPeriod("2") //
.withExpectedDisbursementDate("1 March 2014") // .withExpectedDisbursementDate("1 March 2014") //
.withTranches(tranches) // .withTranches(tranches) //