Squash commits around integration tests into one.
This commit is contained in:
committed by
Keith Woodlock
parent
06cd8cd940
commit
0f6079b8e9
+195
@@ -0,0 +1,195 @@
|
||||
package org.mifosplatform.integrationtests;
|
||||
|
||||
|
||||
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.junit.Before;
|
||||
|
||||
|
||||
import org.junit.Test;
|
||||
import org.mifosplatform.integrationtests.common.*;
|
||||
import org.mifosplatform.integrationtests.common.accounting.Account;
|
||||
import org.mifosplatform.integrationtests.common.accounting.JournalEntry;
|
||||
import org.mifosplatform.integrationtests.common.accounting.AccountHelper;
|
||||
import org.mifosplatform.integrationtests.common.accounting.JournalEntryHelper;
|
||||
import org.mifosplatform.integrationtests.common.loans.LoanApplicationTestBuilder;
|
||||
import org.mifosplatform.integrationtests.common.loans.LoanProductTestBuilder;
|
||||
import org.mifosplatform.integrationtests.common.loans.LoanStatusChecker;
|
||||
import org.mifosplatform.integrationtests.common.loans.LoanTransactionHelper;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class AccountingScenario {
|
||||
private RequestSpecification requestSpec;
|
||||
private ResponseSpecification responseSpec;
|
||||
|
||||
private final String DATE_OF_JOINING = "01 January 2011";
|
||||
|
||||
private final Float LP_PRINCIPAL=10000.0f;
|
||||
private final String LP_REPAYMENTS = "5";
|
||||
private final String LP_REPAYMENT_PERIOD = "2";
|
||||
private final String LP_INTEREST_RATE="1";
|
||||
private final String EXPECTED_DISBURSAL_DATE="04 March 2011";
|
||||
private final String LOAN_APPLICATION_SUBMISSION_DATE= "3 March 2011";
|
||||
private final String LOAN_TERM_FREQUENCY= "10";
|
||||
|
||||
private final String REPAYMENT_DATE[]={"","04 May 2011","04 July 2011","04 September 2011","04 November 2011","04 January 2012"};
|
||||
private final Float REPAYMENT_AMOUNT [] = {.0f,2200.0f,3000.0f,900.0f,2000.0f,2500.0f};
|
||||
|
||||
private final Float AMOUNT_TO_BE_WAIVE = 400.0f;
|
||||
private LoanTransactionHelper loanTransactionHelper;
|
||||
private AccountHelper accountHelper;
|
||||
private JournalEntryHelper journalEntryHelper;
|
||||
|
||||
|
||||
@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();
|
||||
|
||||
loanTransactionHelper = new LoanTransactionHelper(requestSpec,responseSpec);
|
||||
accountHelper = new AccountHelper(requestSpec, responseSpec);
|
||||
journalEntryHelper = new JournalEntryHelper(requestSpec, responseSpec);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkAccountingFlow() {
|
||||
Account assetAccount = accountHelper.createAssetAccount();
|
||||
Account incomeAccount = accountHelper.createIncomeAccount();
|
||||
Account expenseAccount= accountHelper.createExpenseAccount();
|
||||
|
||||
Integer loanProductID = createLoanProduct(assetAccount,incomeAccount,expenseAccount);
|
||||
|
||||
Integer clientID = ClientHelper.createClient(requestSpec, responseSpec, DATE_OF_JOINING);
|
||||
Integer loanID = applyForLoanApplication(clientID, loanProductID);
|
||||
|
||||
HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(requestSpec, responseSpec, loanID);
|
||||
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
|
||||
|
||||
loanStatusHashMap = loanTransactionHelper.approveLoan(EXPECTED_DISBURSAL_DATE, loanID);
|
||||
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
|
||||
LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
|
||||
|
||||
loanStatusHashMap = loanTransactionHelper.disburseLoan(EXPECTED_DISBURSAL_DATE, loanID);
|
||||
LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap);
|
||||
|
||||
|
||||
//CHECK ACCOUNT ENTRIES
|
||||
System.out.println("Entries ......");
|
||||
final float PRINCIPAL_VALUE_FOR_EACH_PERIOD = 2000.0f;
|
||||
final float TOTAL_INTEREST =1000.0f;
|
||||
JournalEntry[] assetAccountInitialEntry =
|
||||
{ new JournalEntry(TOTAL_INTEREST, JournalEntry.TransactionType.DEBIT),
|
||||
new JournalEntry(LP_PRINCIPAL, JournalEntry.TransactionType.CREDIT),
|
||||
new JournalEntry(LP_PRINCIPAL, JournalEntry.TransactionType.DEBIT),
|
||||
};
|
||||
journalEntryHelper.checkJournalEntryForAssetAccount(assetAccount, EXPECTED_DISBURSAL_DATE, assetAccountInitialEntry);
|
||||
System.out.println("CHECKING INCOME: ******************************************");
|
||||
JournalEntry incomeJournalEntry = new JournalEntry(TOTAL_INTEREST, JournalEntry.TransactionType.CREDIT);
|
||||
journalEntryHelper.checkJournalEntryForIncomeAccount(incomeAccount,EXPECTED_DISBURSAL_DATE, incomeJournalEntry);
|
||||
|
||||
//MAKE 1
|
||||
System.out.println("Repayment 1 ......");
|
||||
loanTransactionHelper.makeRepayment(REPAYMENT_DATE[1], REPAYMENT_AMOUNT[1], loanID);
|
||||
float FIRST_INTEREST = 200.0f;
|
||||
float FIRST_PRINCIPAL = 2000.0f;
|
||||
float expected_value = LP_PRINCIPAL- PRINCIPAL_VALUE_FOR_EACH_PERIOD;
|
||||
loanTransactionHelper.verifyRepaymentScheduleEntryFor(1, expected_value, loanID);
|
||||
JournalEntry[] assetAccountFirstEntry=
|
||||
{ new JournalEntry(REPAYMENT_AMOUNT[1], JournalEntry.TransactionType.DEBIT),
|
||||
new JournalEntry(FIRST_INTEREST, JournalEntry.TransactionType.CREDIT),
|
||||
new JournalEntry(FIRST_PRINCIPAL, JournalEntry.TransactionType.CREDIT),
|
||||
};
|
||||
journalEntryHelper.checkJournalEntryForAssetAccount(assetAccount, REPAYMENT_DATE[1],assetAccountFirstEntry);
|
||||
System.out.println("Repayment 1 Done......");
|
||||
|
||||
//REPAYMENT 2
|
||||
System.out.println("Repayment 2 ......");
|
||||
loanTransactionHelper.makeRepayment(REPAYMENT_DATE[2], REPAYMENT_AMOUNT[2], loanID);
|
||||
float SECOND_AND_THIRD_INTEREST = 400.0f;
|
||||
float SECOND_PRINCIPAL = REPAYMENT_AMOUNT[2]-SECOND_AND_THIRD_INTEREST;
|
||||
expected_value = expected_value - PRINCIPAL_VALUE_FOR_EACH_PERIOD;
|
||||
loanTransactionHelper.verifyRepaymentScheduleEntryFor(2,expected_value,loanID);
|
||||
JournalEntry[] assetAccountSecondEntry = { new JournalEntry(REPAYMENT_AMOUNT[2], JournalEntry.TransactionType.DEBIT),
|
||||
new JournalEntry(SECOND_AND_THIRD_INTEREST, JournalEntry.TransactionType.CREDIT),
|
||||
new JournalEntry(SECOND_PRINCIPAL, JournalEntry.TransactionType.CREDIT),
|
||||
};
|
||||
journalEntryHelper.checkJournalEntryForAssetAccount(assetAccount, REPAYMENT_DATE[2], assetAccountSecondEntry);
|
||||
System.out.println("Repayment 2 Done ......");
|
||||
|
||||
//WAIVE INTEREST
|
||||
System.out.println("Waive Interest ......");
|
||||
loanTransactionHelper.waiveInterest(REPAYMENT_DATE[4], AMOUNT_TO_BE_WAIVE.toString(), loanID);
|
||||
|
||||
JournalEntry waivedEntry = new JournalEntry(AMOUNT_TO_BE_WAIVE, JournalEntry.TransactionType.CREDIT);
|
||||
journalEntryHelper.checkJournalEntryForAssetAccount(assetAccount, REPAYMENT_DATE[4],waivedEntry);
|
||||
|
||||
JournalEntry expenseJournalEntry = new JournalEntry(AMOUNT_TO_BE_WAIVE, JournalEntry.TransactionType.DEBIT);
|
||||
journalEntryHelper.checkJournalEntryForExpenseAccount(expenseAccount, REPAYMENT_DATE[4], expenseJournalEntry);
|
||||
System.out.println("Waive Interest Done......");
|
||||
|
||||
//REPAYMENT 3
|
||||
System.out.println("Repayment 3 ......");
|
||||
loanTransactionHelper.makeRepayment(REPAYMENT_DATE[3], REPAYMENT_AMOUNT[3], loanID);
|
||||
expected_value = expected_value - PRINCIPAL_VALUE_FOR_EACH_PERIOD;
|
||||
JournalEntry[] assetAccountThirdEntry = {
|
||||
new JournalEntry(REPAYMENT_AMOUNT[3], JournalEntry.TransactionType.DEBIT),
|
||||
new JournalEntry(REPAYMENT_AMOUNT[3], JournalEntry.TransactionType.CREDIT)
|
||||
};
|
||||
loanTransactionHelper.verifyRepaymentScheduleEntryFor(3, expected_value, loanID);
|
||||
journalEntryHelper.checkJournalEntryForAssetAccount(assetAccount, REPAYMENT_DATE[3], assetAccountThirdEntry);
|
||||
System.out.println("Repayment 3 Done ......");
|
||||
|
||||
//REPAYMENT 4
|
||||
System.out.println("Repayment 4 ......");
|
||||
loanTransactionHelper.makeRepayment(REPAYMENT_DATE[4], REPAYMENT_AMOUNT[4], loanID);
|
||||
expected_value = expected_value - PRINCIPAL_VALUE_FOR_EACH_PERIOD;
|
||||
loanTransactionHelper.verifyRepaymentScheduleEntryFor(4, expected_value, loanID);
|
||||
JournalEntry[] assetAccountFourthEntry = { new JournalEntry(REPAYMENT_AMOUNT[4], JournalEntry.TransactionType.DEBIT),
|
||||
new JournalEntry(REPAYMENT_AMOUNT[4], JournalEntry.TransactionType.CREDIT)
|
||||
};
|
||||
journalEntryHelper.checkJournalEntryForAssetAccount(assetAccount,REPAYMENT_DATE[4],assetAccountFourthEntry);
|
||||
System.out.println("Repayment 4 Done ......");
|
||||
|
||||
//Repayment 5
|
||||
System.out.println("Repayment 5 ......");
|
||||
JournalEntry[] assetAccountFifthEntry = { new JournalEntry(REPAYMENT_AMOUNT[5], JournalEntry.TransactionType.DEBIT),
|
||||
new JournalEntry(REPAYMENT_AMOUNT[5], JournalEntry.TransactionType.CREDIT)
|
||||
};
|
||||
expected_value = expected_value - PRINCIPAL_VALUE_FOR_EACH_PERIOD;
|
||||
loanTransactionHelper.makeRepayment(REPAYMENT_DATE[5], REPAYMENT_AMOUNT[5], loanID);
|
||||
loanTransactionHelper.verifyRepaymentScheduleEntryFor(5,expected_value,loanID);
|
||||
journalEntryHelper.checkJournalEntryForAssetAccount(assetAccount, REPAYMENT_DATE[5], assetAccountFifthEntry);
|
||||
System.out.println("Repayment 5 Done ......");
|
||||
}
|
||||
|
||||
private Integer createLoanProduct(Account ... accounts) {
|
||||
System.out.println("------------------------------CREATING NEW LOAN PRODUCT ---------------------------------------");
|
||||
String loanProductJSON = new LoanProductTestBuilder().withPrincipal(LP_PRINCIPAL.toString()).withRepaymentTypeAsMonth()
|
||||
.withRepaymentAfterEvery(LP_REPAYMENT_PERIOD).withNumberOfRepayments(LP_REPAYMENTS).withRepaymentTypeAsMonth()
|
||||
.withinterestRatePerPeriod(LP_INTEREST_RATE).withInterestRateFrequencyTypeAsMonths()
|
||||
.withAmortizationTypeAsEqualPrinciplePayment().withInterestTypeAsFlat()
|
||||
.withAccountingRuleAsAccrualBased(accounts)
|
||||
.build();
|
||||
return loanTransactionHelper.getLoanProductId(loanProductJSON);
|
||||
}
|
||||
|
||||
private Integer applyForLoanApplication(final Integer clientID, final Integer loanProductID) {
|
||||
System.out.println("--------------------------------APPLYING FOR LOAN APPLICATION--------------------------------");
|
||||
String loanApplicationJSON = new LoanApplicationTestBuilder().withPrincipal(LP_PRINCIPAL.toString()).withLoanTermFrequency(LOAN_TERM_FREQUENCY)
|
||||
.withLoanTermFrequencyAsMonths().withNumberOfRepayments(LP_REPAYMENTS).withRepaymentEveryAfter(LP_REPAYMENT_PERIOD)
|
||||
.withRepaymentFrequencyTypeAsMonths().withInterestRatePerPeriod(LP_INTEREST_RATE).withInterestTypeAsFlatBalance()
|
||||
.withAmortizationTypeAsEqualPrincipalPayments().withInterestCalculationPeriodTypeSameAsRepaymentPeriod()
|
||||
.withExpectedDisbursementDate(EXPECTED_DISBURSAL_DATE).withSubmittedOnDate(LOAN_APPLICATION_SUBMISSION_DATE)
|
||||
.build(clientID.toString(), loanProductID.toString());
|
||||
return loanTransactionHelper.getLoanId(loanApplicationJSON);
|
||||
}
|
||||
}
|
||||
|
||||
+12
-12
@@ -9,9 +9,9 @@ import java.util.HashMap;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mifosplatform.integrationtests.common.ClientHelper;
|
||||
import org.mifosplatform.integrationtests.common.LoanApplicationTestBuilder;
|
||||
import org.mifosplatform.integrationtests.common.LoanProductTestBuilder;
|
||||
import org.mifosplatform.integrationtests.common.LoanTransactionHelper;
|
||||
import org.mifosplatform.integrationtests.common.loans.LoanApplicationTestBuilder;
|
||||
import org.mifosplatform.integrationtests.common.loans.LoanProductTestBuilder;
|
||||
import org.mifosplatform.integrationtests.common.loans.LoanTransactionHelper;
|
||||
import org.mifosplatform.integrationtests.common.Utils;
|
||||
|
||||
import com.jayway.restassured.builder.RequestSpecBuilder;
|
||||
@@ -27,9 +27,9 @@ import com.jayway.restassured.specification.ResponseSpecification;
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public class ClientLoanIntegrationTest {
|
||||
|
||||
ResponseSpecification responseSpec;
|
||||
RequestSpecification requestSpec;
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
private LoanTransactionHelper loanTransactionHelper;
|
||||
@Before
|
||||
public void setup() {
|
||||
Utils.initializeRESTAssured();
|
||||
@@ -40,13 +40,13 @@ public class ClientLoanIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void checkClientLoanCreateAndDisburseFlow() {
|
||||
loanTransactionHelper = new LoanTransactionHelper(requestSpec,responseSpec);
|
||||
|
||||
Integer clientID = ClientHelper.createClient(requestSpec, responseSpec);
|
||||
ClientHelper.verifyClientCreatedOnServer(requestSpec, responseSpec, clientID);
|
||||
|
||||
Integer loanProductID = createLoanProduct();
|
||||
Integer loanID = applyForLoanApplication(clientID, loanProductID);
|
||||
|
||||
ArrayList<HashMap> loanSchedule = LoanTransactionHelper.getLoanRepaymentSchedule(requestSpec, responseSpec, loanID);
|
||||
ArrayList<HashMap> loanSchedule = loanTransactionHelper.getLoanRepaymentSchedule(requestSpec, responseSpec, loanID);
|
||||
verifyLoanRepaymentSchedule(loanSchedule);
|
||||
|
||||
}
|
||||
@@ -57,18 +57,18 @@ public class ClientLoanIntegrationTest {
|
||||
.withRepaymentAfterEvery("1").withRepaymentTypeAsMonth().withinterestRatePerPeriod("2")
|
||||
.withInterestRateFrequencyTypeAsMonths().withAmortizationTypeAsEqualInstallments().withInterestTypeAsDecliningBalance()
|
||||
.withinterestRatePerPeriod("1").build();
|
||||
return LoanTransactionHelper.getLoanProductId(requestSpec, responseSpec, loanProductJSON);
|
||||
return loanTransactionHelper.getLoanProductId(loanProductJSON);
|
||||
}
|
||||
|
||||
private Integer applyForLoanApplication(final Integer clientID, 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").withInterestRateFrequencyTypeAsMonths()
|
||||
.withRepaymentFrequencyTypeAsMonths().withInterestRatePerPeriod("2")
|
||||
.withAmortizationTypeAsEqualInstallments().withInterestTypeAsDecliningBalance()
|
||||
.withInterestCalculationPeriodTypeSameAsRepaymentPeriod().withExpectedDisbursementDate("20 September 2011")
|
||||
.withSubmittedOnDate("20 September 2011").build(clientID.toString(), loanProductID.toString());
|
||||
return LoanTransactionHelper.getLoanId(requestSpec, responseSpec, loanApplicationJSON);
|
||||
return loanTransactionHelper.getLoanId(loanApplicationJSON);
|
||||
}
|
||||
|
||||
private void verifyLoanRepaymentSchedule(final ArrayList<HashMap> loanSchedule) {
|
||||
|
||||
+49
-41
@@ -2,16 +2,15 @@ package org.mifosplatform.integrationtests;
|
||||
|
||||
//import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mifosplatform.integrationtests.common.ClientHelper;
|
||||
import org.mifosplatform.integrationtests.common.LoanApplicationTestBuilder;
|
||||
import org.mifosplatform.integrationtests.common.LoanProductTestBuilder;
|
||||
import org.mifosplatform.integrationtests.common.LoanStatusChecker;
|
||||
import org.mifosplatform.integrationtests.common.LoanTransactionHelper;
|
||||
import org.mifosplatform.integrationtests.common.loans.LoanApplicationTestBuilder;
|
||||
import org.mifosplatform.integrationtests.common.loans.LoanProductTestBuilder;
|
||||
import org.mifosplatform.integrationtests.common.loans.LoanStatusChecker;
|
||||
import org.mifosplatform.integrationtests.common.loans.LoanTransactionHelper;
|
||||
import org.mifosplatform.integrationtests.common.Utils;
|
||||
|
||||
import com.jayway.restassured.builder.RequestSpecBuilder;
|
||||
@@ -29,15 +28,15 @@ import static org.junit.Assert.assertEquals;
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public class LoanWithWaiveInterestAndWriteOffIntegrationTest {
|
||||
|
||||
ResponseSpecification responseSpec;
|
||||
RequestSpecification requestSpec;
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
|
||||
final String LP_PRINCIPAL = "12,000.00", LP_REPAYMENTS = "2", LP_REPAYMENT_PERIOD = "6", LP_INTEREST_RATE = "1",
|
||||
|
||||
PRINCIPAL = "4,500.00", LOAN_TERM_FREQUENCY = "18", NUMBER_OF_REPAYMENTS = "9", REPAYMENT_PERIOD = "2",
|
||||
DISBURSEMENT_DATE = "30 October 2010", LOAN_APPLICATION_SUBMISSION_DATE = "23 September 2010",
|
||||
EXPECTED_DISBURSAL_DATE = "28 October 2010", RATE_OF_INTEREST_PER_PERIOD = "2", DATE_OF_JOINING = "04 March 2009",
|
||||
INTEREST_VALUE_AMOUNT = "40.00";
|
||||
private final String LP_PRINCIPAL = "12,000.00", LP_REPAYMENTS = "2", LP_REPAYMENT_PERIOD = "6", LP_INTEREST_RATE = "1",
|
||||
PRINCIPAL = "4,500.00", LOAN_TERM_FREQUENCY = "18", NUMBER_OF_REPAYMENTS = "9", REPAYMENT_PERIOD = "2",
|
||||
DISBURSEMENT_DATE = "30 October 2010", LOAN_APPLICATION_SUBMISSION_DATE = "23 September 2010",
|
||||
EXPECTED_DISBURSAL_DATE = "28 October 2010", RATE_OF_INTEREST_PER_PERIOD = "2",
|
||||
DATE_OF_JOINING = "04 March 2009",INTEREST_VALUE_AMOUNT = "40.00";
|
||||
private LoanTransactionHelper loanTransactionHelper;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
@@ -45,6 +44,7 @@ public class LoanWithWaiveInterestAndWriteOffIntegrationTest {
|
||||
requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
|
||||
requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
|
||||
responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
|
||||
loanTransactionHelper = new LoanTransactionHelper(requestSpec,responseSpec);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -57,73 +57,81 @@ public class LoanWithWaiveInterestAndWriteOffIntegrationTest {
|
||||
Integer loanProductID = createLoanProduct();
|
||||
// APPLY FOR LOAN
|
||||
Integer loanID = applyForLoanApplication(clientID, loanProductID);
|
||||
HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(requestSpec, responseSpec, loanID);
|
||||
|
||||
HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(requestSpec, responseSpec, loanID);
|
||||
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
|
||||
|
||||
System.out.println("-----------------------------------APPROVE LOAN-----------------------------------------");
|
||||
loanStatusHashMap = LoanTransactionHelper.approveLoan(requestSpec, responseSpec, "28 September 2010", loanID);
|
||||
loanStatusHashMap = loanTransactionHelper.approveLoan("28 September 2010", loanID);
|
||||
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
|
||||
LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
|
||||
|
||||
// UNDO APPROVAL
|
||||
loanStatusHashMap = LoanTransactionHelper.undoApproval(requestSpec, responseSpec, loanID);
|
||||
loanStatusHashMap = loanTransactionHelper.undoApproval(loanID);
|
||||
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
|
||||
|
||||
System.out.println("-----------------------------------RE-APPROVE LOAN-----------------------------------------");
|
||||
loanStatusHashMap = LoanTransactionHelper.approveLoan(requestSpec, responseSpec, "1 October 2010", loanID);
|
||||
loanStatusHashMap = loanTransactionHelper.approveLoan("1 October 2010", loanID);
|
||||
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
|
||||
LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
|
||||
|
||||
// DISBURSE
|
||||
loanStatusHashMap = LoanTransactionHelper.disburseLoan(requestSpec, responseSpec, DISBURSEMENT_DATE, loanID);
|
||||
loanStatusHashMap = loanTransactionHelper.disburseLoan(DISBURSEMENT_DATE, loanID);
|
||||
System.out.println("DISBURSE " + loanStatusHashMap);
|
||||
LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap);
|
||||
|
||||
// PERFORM REPAYMENTS AND CHECK LOAN STATUS
|
||||
verifyRepaymentScheduleEntryFor(1, 4000.0F, loanID);
|
||||
LoanTransactionHelper.makeRepayment(requestSpec, responseSpec, "1 January 2011", 540.0f, loanID);
|
||||
LoanTransactionHelper.makeRepayment(requestSpec, responseSpec, "1 March 2011", 540.0f, loanID);
|
||||
LoanTransactionHelper.waiveInterest(requestSpec, responseSpec, "1 May 2011", INTEREST_VALUE_AMOUNT, loanID);
|
||||
LoanTransactionHelper.makeRepayment(requestSpec, responseSpec, "1 May 2011", 500.0f, loanID);
|
||||
LoanTransactionHelper.makeRepayment(requestSpec, responseSpec, "1 July 2011", 540.0f, loanID);
|
||||
LoanTransactionHelper.waiveInterest(requestSpec, responseSpec, "1 September 2011", INTEREST_VALUE_AMOUNT, loanID);
|
||||
LoanTransactionHelper.makeRepayment(requestSpec, responseSpec, "1 September 2011", 500.0f, loanID);
|
||||
LoanTransactionHelper.makeRepayment(requestSpec, responseSpec, "1 November 2011", 540.0f, loanID);
|
||||
LoanTransactionHelper.waiveInterest(requestSpec, responseSpec, "1 January 2012", INTEREST_VALUE_AMOUNT, loanID);
|
||||
LoanTransactionHelper.makeRepayment(requestSpec, responseSpec, "1 January 2012", 500.0f, loanID);
|
||||
loanTransactionHelper.verifyRepaymentScheduleEntryFor(1, 4000.0F, loanID);
|
||||
loanTransactionHelper.makeRepayment("1 January 2011", 540.0f, loanID);
|
||||
|
||||
verifyRepaymentScheduleEntryFor(7, 1000.0f, loanID);
|
||||
//UNDO DISBURSE LOAN
|
||||
loanStatusHashMap=loanTransactionHelper.undoDisbursal(loanID);
|
||||
LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
|
||||
|
||||
//DIBURSE AGAIN
|
||||
loanStatusHashMap = loanTransactionHelper.disburseLoan(DISBURSEMENT_DATE, loanID);
|
||||
System.out.println("DISBURSE " + loanStatusHashMap);
|
||||
LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap);
|
||||
|
||||
//MAKE REPAYMENTS
|
||||
final float repayment_with_interest = 540.0f;
|
||||
final float repayment_without_interest = 500.0f;
|
||||
|
||||
loanTransactionHelper.verifyRepaymentScheduleEntryFor(1, 4000.0F, loanID);
|
||||
loanTransactionHelper.makeRepayment("1 January 2011",repayment_with_interest, loanID);
|
||||
loanTransactionHelper.makeRepayment("1 March 2011", repayment_with_interest, loanID);
|
||||
loanTransactionHelper.waiveInterest("1 May 2011", INTEREST_VALUE_AMOUNT, loanID);
|
||||
loanTransactionHelper.makeRepayment("1 May 2011", repayment_without_interest, loanID);
|
||||
loanTransactionHelper.makeRepayment("1 July 2011", repayment_with_interest, loanID);
|
||||
loanTransactionHelper.waiveInterest("1 September 2011", INTEREST_VALUE_AMOUNT, loanID);
|
||||
loanTransactionHelper.makeRepayment("1 September 2011", repayment_without_interest, loanID);
|
||||
loanTransactionHelper.makeRepayment("1 November 2011", repayment_with_interest, loanID);
|
||||
loanTransactionHelper.waiveInterest("1 January 2012", INTEREST_VALUE_AMOUNT, loanID);
|
||||
loanTransactionHelper.makeRepayment("1 January 2012", repayment_without_interest, loanID);
|
||||
loanTransactionHelper.verifyRepaymentScheduleEntryFor(7, 1000.0f, loanID);
|
||||
|
||||
// WRITE OFF LOAN AND CHECK ACCOUNT IS CLOSED
|
||||
LoanStatusChecker.verifyLoanAccountIsClosed(LoanTransactionHelper.writeOffLoan(requestSpec, responseSpec, "1 March 2012", loanID));
|
||||
LoanStatusChecker.verifyLoanAccountIsClosed(loanTransactionHelper.writeOffLoan("1 March 2012", loanID));
|
||||
|
||||
}
|
||||
|
||||
private void verifyRepaymentScheduleEntryFor(final int repaymentNumber, final float expectedPrincipalOutstanding, final Integer loanID) {
|
||||
System.out.println("---------------------------GETTING LOAN REPAYMENT SCHEDULE--------------------------------");
|
||||
ArrayList<HashMap> repaymentPeriods = LoanTransactionHelper.getLoanRepaymentSchedule(requestSpec, responseSpec, loanID);
|
||||
assertEquals("Mismatch in Principal Loan Balance Outstanding ", expectedPrincipalOutstanding, repaymentPeriods.get(repaymentNumber).get("principalLoanBalanceOutstanding"));
|
||||
}
|
||||
|
||||
private Integer createLoanProduct() {
|
||||
System.out.println("------------------------------CREATING NEW LOAN PRODUCT ---------------------------------------");
|
||||
String loanProductJSON = new LoanProductTestBuilder().withPrincipal(LP_PRINCIPAL).withRepaymentTypeAsMonth()
|
||||
.withRepaymentAfterEvery(LP_REPAYMENT_PERIOD).withNumberOfRepayments(LP_REPAYMENTS).withRepaymentTypeAsMonth()
|
||||
.withinterestRatePerPeriod(LP_INTEREST_RATE).withInterestRateFrequencyTypeAsMonths()
|
||||
.withAmortizationTypeAsEqualPrinciplePayment().withInterestTypeAsFlat().build();
|
||||
return LoanTransactionHelper.getLoanProductId(requestSpec, responseSpec, loanProductJSON);
|
||||
return loanTransactionHelper.getLoanProductId(loanProductJSON);
|
||||
}
|
||||
|
||||
private Integer applyForLoanApplication(final Integer clientID, final Integer loanProductID) {
|
||||
System.out.println("--------------------------------APPLYING FOR LOAN APPLICATION--------------------------------");
|
||||
String loanApplicationJSON = new LoanApplicationTestBuilder().withPrincipal(PRINCIPAL).withLoanTermFrequency(LOAN_TERM_FREQUENCY)
|
||||
.withLoanTermFrequencyAsMonths().withNumberOfRepayments(NUMBER_OF_REPAYMENTS).withRepaymentEveryAfter(REPAYMENT_PERIOD)
|
||||
.withRepaymentFrequencyTypeAsMonths().withInterestRateFrequencyTypeAsMonths()
|
||||
.withInterestRatePerPeriod(RATE_OF_INTEREST_PER_PERIOD).withInterestTypeAsFlatBalance()
|
||||
.withRepaymentFrequencyTypeAsMonths().withInterestRatePerPeriod(RATE_OF_INTEREST_PER_PERIOD).withInterestTypeAsFlatBalance()
|
||||
.withAmortizationTypeAsEqualInstallments().withInterestCalculationPeriodTypeSameAsRepaymentPeriod()
|
||||
.withExpectedDisbursementDate(EXPECTED_DISBURSAL_DATE).withSubmittedOnDate(LOAN_APPLICATION_SUBMISSION_DATE)
|
||||
.build(clientID.toString(), loanProductID.toString());
|
||||
return LoanTransactionHelper.getLoanId(requestSpec, responseSpec, loanApplicationJSON);
|
||||
return loanTransactionHelper.getLoanId(loanApplicationJSON);
|
||||
}
|
||||
}
|
||||
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
package org.mifosplatform.integrationtests;
|
||||
|
||||
|
||||
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.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mifosplatform.integrationtests.common.*;
|
||||
import org.mifosplatform.integrationtests.common.loans.LoanApplicationTestBuilder;
|
||||
import org.mifosplatform.integrationtests.common.loans.LoanProductTestBuilder;
|
||||
import org.mifosplatform.integrationtests.common.loans.LoanStatusChecker;
|
||||
import org.mifosplatform.integrationtests.common.loans.LoanTransactionHelper;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class LoanWithdrawnByApplicant {
|
||||
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();
|
||||
|
||||
loanTransactionHelper = new LoanTransactionHelper(requestSpec,responseSpec);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loanWithdrawnByApplicant(){
|
||||
Integer clientID = ClientHelper.createClient(requestSpec,responseSpec,"01 January 2012");
|
||||
Integer loanProductID = loanTransactionHelper.getLoanProductId(new LoanProductTestBuilder().build());
|
||||
Integer loanID = applyForLoanApplication(clientID, loanProductID);
|
||||
|
||||
HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(requestSpec, responseSpec, loanID);
|
||||
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
|
||||
|
||||
loanTransactionHelper.withdrawLoanApplicationByClient("03 April 2012",loanID);
|
||||
loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(requestSpec,responseSpec,loanID);
|
||||
LoanStatusChecker.verifyLoanAccountIsNotActive(loanStatusHashMap);
|
||||
|
||||
}
|
||||
|
||||
private Integer applyForLoanApplication(Integer clientID, Integer loanProductID){
|
||||
String loanApplication = new LoanApplicationTestBuilder()
|
||||
.withPrincipal("5000").withLoanTermFrequency("5").withLoanTermFrequencyAsMonths()
|
||||
.withNumberOfRepayments("5").withRepaymentEveryAfter("1").withRepaymentFrequencyTypeAsMonths()
|
||||
.withInterestRatePerPeriod("2")
|
||||
.withExpectedDisbursementDate("04 April 2012")
|
||||
.withSubmittedOnDate("02 April 2012")
|
||||
.build(clientID.toString(),loanProductID.toString());
|
||||
return loanTransactionHelper.getLoanId(loanApplication);
|
||||
}
|
||||
}
|
||||
+2
-12
@@ -1,7 +1,6 @@
|
||||
package org.mifosplatform.integrationtests.common;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Random;
|
||||
|
||||
|
||||
import com.google.gson.Gson;
|
||||
@@ -45,20 +44,11 @@ public class ClientHelper {
|
||||
assertEquals("ERROR IN CREATING THE CLIENT",generatedClientID, responseClientID);
|
||||
}
|
||||
|
||||
private 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");
|
||||
return Utils.randomStringGenerator(prefix, lenOfRandomSuffix);
|
||||
}
|
||||
|
||||
private static String randomIDGenerator(final String prefix, final int lenOfRandomSuffix) {
|
||||
return randomStringGenerator(prefix, lenOfRandomSuffix, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||
return Utils.randomStringGenerator(prefix, lenOfRandomSuffix, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||
}
|
||||
}
|
||||
+39
-4
@@ -2,8 +2,11 @@ package org.mifosplatform.integrationtests.common;
|
||||
|
||||
import static com.jayway.restassured.RestAssured.given;
|
||||
import static com.jayway.restassured.path.json.JsonPath.from;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.http.conn.HttpHostConnectException;
|
||||
|
||||
import com.jayway.restassured.RestAssured;
|
||||
@@ -11,6 +14,10 @@ import com.jayway.restassured.path.json.JsonPath;
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Random;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class Utils {
|
||||
|
||||
@@ -27,8 +34,7 @@ public class Utils {
|
||||
try {
|
||||
System.out.println("-----------------------------------LOGIN-----------------------------------------");
|
||||
String json = RestAssured.post(LOGIN_URL).asString();
|
||||
System.out.println("JSON:****************"+json);
|
||||
// assertThat("Failed to login into mifosx platform",StringUtils.isBlank(json),is(false));
|
||||
assertThat("Failed to login into mifosx platform", StringUtils.isBlank(json), is(false));
|
||||
return JsonPath.with(json).get("base64EncodedAuthenticationKey");
|
||||
}
|
||||
catch (Exception e) {
|
||||
@@ -43,15 +49,44 @@ public class Utils {
|
||||
|
||||
public static <T> T performServerGet(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String getURL, final String jsonAttributeToGetBack) {
|
||||
String json = given().spec(requestSpec).expect().spec(responseSpec).log().ifError().when().get(getURL).andReturn().asString();
|
||||
String json = given().spec(requestSpec)
|
||||
.expect().spec(responseSpec).log().ifError()
|
||||
.when().get(getURL).andReturn().asString();
|
||||
return (T) from(json).get(jsonAttributeToGetBack);
|
||||
}
|
||||
|
||||
public static <T> T performServerPost(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String postURL, final String jsonBodyToSend, final String jsonAttributeToGetBack) {
|
||||
String json = given().spec(requestSpec).body(jsonBodyToSend).expect().spec(responseSpec).log().ifError().when().post(postURL)
|
||||
String json = given().spec(requestSpec).body(jsonBodyToSend)
|
||||
.expect().spec(responseSpec).log().ifError()
|
||||
.when().post(postURL)
|
||||
.andReturn().asString();
|
||||
return (T) from(json).get(jsonAttributeToGetBack);
|
||||
}
|
||||
|
||||
|
||||
public static String convertDateToURLFormat(String dateToBeConvert){
|
||||
SimpleDateFormat oldFormat = new SimpleDateFormat("dd MMMMMM yyyy");
|
||||
SimpleDateFormat newFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
String reformattedStr="";
|
||||
try {
|
||||
reformattedStr = newFormat.format(oldFormat.parse(dateToBeConvert));
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return reformattedStr;
|
||||
}
|
||||
|
||||
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 randomStringGenerator(final String prefix, final int len) {
|
||||
return randomStringGenerator(prefix, len, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||
}
|
||||
}
|
||||
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package org.mifosplatform.integrationtests.common.accounting;
|
||||
|
||||
public class Account {
|
||||
|
||||
public enum AccountType {
|
||||
ASSET("1"), INCOME("4"), EXPENSE("5"), LIABILITY("2"),EQUITY("3");
|
||||
|
||||
private final String accountValue ;
|
||||
|
||||
AccountType(final String accountValue){
|
||||
this.accountValue=accountValue;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return accountValue;
|
||||
}
|
||||
}
|
||||
|
||||
private final AccountType accountType;
|
||||
private final Integer accountID;
|
||||
|
||||
|
||||
public Account(Integer accountID, AccountType accountType) {
|
||||
this.accountID = accountID;
|
||||
this.accountType = accountType;
|
||||
}
|
||||
|
||||
public AccountType getAccountType(){
|
||||
return this.accountType;
|
||||
}
|
||||
|
||||
public Integer getAccountID(){
|
||||
return this.accountID;
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package org.mifosplatform.integrationtests.common.accounting;
|
||||
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
import org.mifosplatform.integrationtests.common.Utils;
|
||||
|
||||
public class AccountHelper {
|
||||
|
||||
private final String CREATE_GL_ACCOUNT_URL = "/mifosng-provider/api/v1/glaccounts?tenantIdentifier=default";
|
||||
private final String GL_ACCOUNT_ID_RESPONSE = "resourceId";
|
||||
|
||||
private RequestSpecification requestSpec;
|
||||
private ResponseSpecification responseSpec;
|
||||
|
||||
public AccountHelper(RequestSpecification requestSpec, ResponseSpecification responseSpec) {
|
||||
this.requestSpec = requestSpec;
|
||||
this.responseSpec = responseSpec;
|
||||
}
|
||||
|
||||
public Account createAssetAccount(){
|
||||
String assetAccountJSON= new GLAccountBuilder()
|
||||
.withAccountTypeAsAsset()
|
||||
.build();
|
||||
Integer accountID = Utils.performServerPost(requestSpec, responseSpec, CREATE_GL_ACCOUNT_URL, assetAccountJSON, GL_ACCOUNT_ID_RESPONSE);
|
||||
return new Account(accountID, Account.AccountType.ASSET);
|
||||
}
|
||||
public Account createIncomeAccount(){
|
||||
String assetAccountJSON= new GLAccountBuilder()
|
||||
.withAccountTypeAsIncome()
|
||||
.build();
|
||||
Integer accountID = Utils.performServerPost(requestSpec, responseSpec, CREATE_GL_ACCOUNT_URL, assetAccountJSON, GL_ACCOUNT_ID_RESPONSE);
|
||||
return new Account(accountID, Account.AccountType.INCOME);
|
||||
}
|
||||
public Account createExpenseAccount(){
|
||||
String assetAccountJSON= new GLAccountBuilder()
|
||||
.withAccountTypeAsExpense()
|
||||
.build();
|
||||
Integer accountID = Utils.performServerPost(requestSpec, responseSpec, CREATE_GL_ACCOUNT_URL, assetAccountJSON, GL_ACCOUNT_ID_RESPONSE);
|
||||
return new Account(accountID, Account.AccountType.EXPENSE);
|
||||
}
|
||||
|
||||
}
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
package org.mifosplatform.integrationtests.common.accounting;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import org.mifosplatform.integrationtests.common.ClientHelper;
|
||||
import org.mifosplatform.integrationtests.common.Utils;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class GLAccountBuilder {
|
||||
|
||||
public static final String ASSET_ACCOUNT="1";
|
||||
public static final String LIABILITY_ACCOUNT="2";
|
||||
public static final String EQUITY_ACCOUNT="3";
|
||||
public static final String INCOME_ACCOUNT="4";
|
||||
public static final String EXPENSE_ACCOUNT="5";
|
||||
|
||||
private static final String ACCOUNT_USAGE_DETAIL="1";
|
||||
private static final String ACCOUNT_USAGE_HEADER="2";
|
||||
private static final String MANUAL_ENTRIES_ALLOW="true";
|
||||
private static final String MANUAL_ENTRIES_NOT_ALLOW="false";
|
||||
|
||||
private static String name = Utils.randomStringGenerator("ACCOUNT_NAME_", 5);
|
||||
|
||||
private static String GLCode="";
|
||||
private static String accountType="";
|
||||
private static String accountUsage=ACCOUNT_USAGE_DETAIL;
|
||||
private static String manualEntriesAllowed=MANUAL_ENTRIES_ALLOW;
|
||||
private static String description = "DEFAULT_DESCRIPTION";
|
||||
|
||||
public String build(){
|
||||
HashMap<String, String> map = new HashMap<String, String>();
|
||||
map.put("name",this.name);
|
||||
map.put("glCode",this.GLCode);
|
||||
map.put("manualEntriesAllowed",this.manualEntriesAllowed);
|
||||
map.put("type",this.accountType);
|
||||
map.put("usage",this.accountUsage);
|
||||
map.put("description",this.description);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
public GLAccountBuilder withAccountTypeAsAsset(){
|
||||
this.accountType= ASSET_ACCOUNT;
|
||||
this.GLCode= Utils.randomStringGenerator("ASSET_",2);
|
||||
this.GLCode+= Calendar.getInstance().getTimeInMillis()+""; //Added unique timestamp for avoiding random collisions
|
||||
return this;
|
||||
}
|
||||
public GLAccountBuilder withAccountTypeAsLiability(){
|
||||
this.accountType=LIABILITY_ACCOUNT;
|
||||
this.GLCode=Utils.randomStringGenerator("LIABILITY_",2);
|
||||
this.GLCode+= Calendar.getInstance().getTimeInMillis()+"";
|
||||
return this;
|
||||
}
|
||||
public GLAccountBuilder withAccountTypeAsAsEquity(){
|
||||
this.accountType=EQUITY_ACCOUNT;
|
||||
this.GLCode=Utils.randomStringGenerator("EQUITY_",2);
|
||||
this.GLCode+= Calendar.getInstance().getTimeInMillis()+"";
|
||||
return this;
|
||||
}
|
||||
public GLAccountBuilder withAccountTypeAsIncome(){
|
||||
this.accountType=INCOME_ACCOUNT;
|
||||
this.GLCode=Utils.randomStringGenerator("INCOME_",2);
|
||||
this.GLCode+= Calendar.getInstance().getTimeInMillis()+"";
|
||||
return this;
|
||||
}
|
||||
public GLAccountBuilder withAccountTypeAsExpense(){
|
||||
this.accountType=EXPENSE_ACCOUNT;
|
||||
this.GLCode=Utils.randomStringGenerator("EXPENSE_",2);
|
||||
this.GLCode+= Calendar.getInstance().getTimeInMillis()+"";
|
||||
return this;
|
||||
}
|
||||
public GLAccountBuilder withAccountUsageAsHeader(){
|
||||
this.accountUsage = ACCOUNT_USAGE_HEADER;
|
||||
return this;
|
||||
}
|
||||
|
||||
public GLAccountBuilder withMaualEntriesNotAllowed(){
|
||||
this.manualEntriesAllowed = MANUAL_ENTRIES_NOT_ALLOW;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package org.mifosplatform.integrationtests.common.accounting;
|
||||
|
||||
|
||||
public class JournalEntry {
|
||||
|
||||
public enum TransactionType {
|
||||
CREDIT("CREDIT"),
|
||||
DEBIT("DEBIT");
|
||||
|
||||
private TransactionType(final String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
private final String type;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
private final Float transactionAmount;
|
||||
private final TransactionType transactionType;
|
||||
|
||||
public JournalEntry(float transactionAmount, TransactionType type){
|
||||
this.transactionAmount=transactionAmount;
|
||||
this.transactionType = type;
|
||||
}
|
||||
|
||||
public Float getTransactionAmount(){
|
||||
return this.transactionAmount;
|
||||
}
|
||||
|
||||
public String getTransactionType(){
|
||||
return this.transactionType.toString();
|
||||
}
|
||||
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
package org.mifosplatform.integrationtests.common.accounting;
|
||||
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
import org.mifosplatform.integrationtests.common.Utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class JournalEntryHelper {
|
||||
|
||||
private RequestSpecification requestSpec;
|
||||
private ResponseSpecification responseSpec;
|
||||
|
||||
public JournalEntryHelper(RequestSpecification requestSpec, ResponseSpecification responseSpec) {
|
||||
this.requestSpec = requestSpec;
|
||||
this.responseSpec = responseSpec;
|
||||
}
|
||||
|
||||
public void checkJournalEntryForExpenseAccount(Account expenseAccount, String date, JournalEntry accountEntries) {
|
||||
checkJournalEntry(expenseAccount, Utils.convertDateToURLFormat(date),accountEntries);
|
||||
}
|
||||
|
||||
|
||||
public void checkJournalEntryForAssetAccount(Account assetAccount, String date, JournalEntry... accountEntries) {
|
||||
checkJournalEntry(assetAccount,Utils.convertDateToURLFormat(date),accountEntries);
|
||||
}
|
||||
|
||||
public void checkJournalEntryForIncomeAccount(Account incomeAccount, String date, JournalEntry accountEntries) {
|
||||
checkJournalEntry(incomeAccount, Utils.convertDateToURLFormat(date), accountEntries);
|
||||
}
|
||||
|
||||
private String getEntryValueFromJournalEntry(ArrayList<HashMap> entryResponse, int entryNumber) {
|
||||
HashMap map = (HashMap) entryResponse.get(entryNumber).get("entryType");
|
||||
return (String) map.get("value");
|
||||
}
|
||||
|
||||
private Float getTransactionAmountFromJournalEntry(ArrayList<HashMap> entryResponse, int entryNumber) {
|
||||
return (Float) entryResponse.get(entryNumber).get("amount");
|
||||
}
|
||||
|
||||
private void checkJournalEntry(Account account, String date, JournalEntry... accountEntries){
|
||||
String url = createURLForGettingAccountEntries(account,date);
|
||||
ArrayList<HashMap> response = Utils.performServerGet(requestSpec, responseSpec, url, "");
|
||||
for (int i = 0; i < accountEntries.length; i++) {
|
||||
assertThat(getEntryValueFromJournalEntry(response, i), equalTo(accountEntries[i].getTransactionType()));
|
||||
assertThat(getTransactionAmountFromJournalEntry(response, i), equalTo(accountEntries[i].getTransactionAmount()));
|
||||
}
|
||||
}
|
||||
|
||||
private String createURLForGettingAccountEntries (Account account,String date){
|
||||
return new String ("/mifosng-provider/api/v1/journalentries?glAccountId=" + account.getAccountID() + "&type=" +account.getAccountType()
|
||||
+ "&fromDate=" + date + "&toDate=" + date + "&tenantIdentifier=default");
|
||||
}
|
||||
|
||||
}
|
||||
+9
-21
@@ -1,4 +1,4 @@
|
||||
package org.mifosplatform.integrationtests.common;
|
||||
package org.mifosplatform.integrationtests.common.loans;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@@ -19,20 +19,18 @@ public class LoanApplicationTestBuilder {
|
||||
|
||||
private String principal = "10,000";
|
||||
private String loanTermFrequency = "";
|
||||
// FIXME - unused variable?
|
||||
private String loanTermFrequencyType = "";
|
||||
private String numberOfRepayment = "0";
|
||||
private String repaymentPeriod = "0";
|
||||
private String repaymentFrequencyType = "";
|
||||
|
||||
private String interestRate = "2";
|
||||
private String interestRateFrequencyType = "0";
|
||||
private String interestType = "";
|
||||
private String amortizationType = "";
|
||||
private String interestType = FLAT_BALANCE;
|
||||
private String amortizationType = EQUAL_PRINCIPLE_PAYMENTS;
|
||||
private String interestCalculationPeriodType = CALCULATION_PERIOD_SAME_AS_REPAYMENT_PERIOD;
|
||||
private final String transactionProcessingID = MIFOS_STANDARD_STRATEGY;
|
||||
private String expectedDisbursmentDate = "";
|
||||
private String submittedOndate = "";
|
||||
private String submittedOnDate = "";
|
||||
|
||||
public String build(final String clientID, final String loanProductId) {
|
||||
|
||||
@@ -43,19 +41,17 @@ public class LoanApplicationTestBuilder {
|
||||
map.put("productId", loanProductId);
|
||||
map.put("principal", principal);
|
||||
map.put("loanTermFrequency", loanTermFrequency);
|
||||
map.put("loanTermFrequencyType", "2"); // FIXME - Should this be using
|
||||
// loanTermFrequencyType value?
|
||||
map.put("loanTermFrequencyType", loanTermFrequencyType); // FIXME - Should this be using
|
||||
map.put("numberOfRepayments", numberOfRepayment);
|
||||
map.put("repaymentEvery", repaymentPeriod);
|
||||
map.put("repaymentFrequencyType", repaymentFrequencyType);
|
||||
map.put("interestRateFrequencyType", interestRateFrequencyType);
|
||||
map.put("interestRatePerPeriod", interestRate);
|
||||
map.put("amortizationType", amortizationType);
|
||||
map.put("interestType", interestType);
|
||||
map.put("interestCalculationPeriodType", interestCalculationPeriodType);
|
||||
map.put("transactionProcessingStrategyId", transactionProcessingID);
|
||||
map.put("expectedDisbursementDate", expectedDisbursmentDate);
|
||||
map.put("submittedOnDate", submittedOndate);
|
||||
map.put("submittedOnDate", submittedOnDate);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
@@ -119,16 +115,6 @@ public class LoanApplicationTestBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanApplicationTestBuilder withInterestRateFrequencyTypeAsMonths() {
|
||||
this.interestRateFrequencyType = MONTHS;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanApplicationTestBuilder withInterestRateFrequencyTypeAsYears() {
|
||||
this.interestRateFrequencyType = YEARS;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanApplicationTestBuilder withInterestTypeAsFlatBalance() {
|
||||
this.interestType = FLAT_BALANCE;
|
||||
return this;
|
||||
@@ -165,7 +151,9 @@ public class LoanApplicationTestBuilder {
|
||||
}
|
||||
|
||||
public LoanApplicationTestBuilder withSubmittedOnDate(final String loanApplicationSubmittedDate) {
|
||||
this.submittedOndate = loanApplicationSubmittedDate;
|
||||
this.submittedOnDate = loanApplicationSubmittedDate;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+70
-7
@@ -1,8 +1,11 @@
|
||||
package org.mifosplatform.integrationtests.common;
|
||||
package org.mifosplatform.integrationtests.common.loans;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import org.mifosplatform.integrationtests.common.ClientHelper;
|
||||
import org.mifosplatform.integrationtests.common.accounting.Account;
|
||||
|
||||
public class LoanProductTestBuilder {
|
||||
private static final String LOCALE = "en_GB";
|
||||
@@ -28,9 +31,9 @@ public class LoanProductTestBuilder {
|
||||
|
||||
private String nameOfLoanProduct = ClientHelper.randomNameGenerator("LOAN_PRODUCT_", 6);
|
||||
private String principal = "10000.00";
|
||||
private String numberOfRepayments = "0";
|
||||
private String repaymentFrequency = WEEK;
|
||||
private String repaymentPeriod = "0";
|
||||
private String numberOfRepayments = "5";
|
||||
private String repaymentFrequency = MONTHS;
|
||||
private String repaymentPeriod = "1";
|
||||
private String interestRatePerPeriod= "2";
|
||||
private String interestRateFrequencyType = MONTHS;
|
||||
private String interestType = FLAT_BALANCE;
|
||||
@@ -42,7 +45,7 @@ public class LoanProductTestBuilder {
|
||||
private String amortizationType= EQUAL_INSTALLMENTS;
|
||||
private String minPrincipal = "1000.00";
|
||||
private String maxPrincipal = "100000.00";
|
||||
|
||||
private Account[] accountList = null;
|
||||
|
||||
public String build() {
|
||||
HashMap<String, String> map = new HashMap<String, String>();
|
||||
@@ -65,9 +68,16 @@ public class LoanProductTestBuilder {
|
||||
map.put("accountingRule", accountingRule);
|
||||
map.put("minPrincipal",minPrincipal);
|
||||
map.put("maxPrincipal",maxPrincipal);
|
||||
|
||||
if(accountingRule.equals(ACCRUAL_BASED)){
|
||||
map.putAll(getAccountMappingForAccrualBased());
|
||||
}else if(accountingRule.equals(CASH_BASED)){
|
||||
map.putAll(getAccountMappingForCashBased());
|
||||
}
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
|
||||
public LoanProductTestBuilder withMinPrincipal(final String minPrincipal){
|
||||
this.minPrincipal=minPrincipal;
|
||||
return this;
|
||||
@@ -167,14 +177,67 @@ public class LoanProductTestBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanProductTestBuilder withAccountingRuleAsCashBased (){
|
||||
public LoanProductTestBuilder withAccountingRuleAsCashBased (Account [] account_list){
|
||||
this.accountingRule= CASH_BASED;
|
||||
this.accountList = account_list;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanProductTestBuilder withAccountingRuleAsAccrualBased (){
|
||||
public LoanProductTestBuilder withAccountingRuleAsAccrualBased (Account[] account_list){
|
||||
this.accountingRule= ACCRUAL_BASED;
|
||||
this.accountList = account_list;
|
||||
return this;
|
||||
}
|
||||
|
||||
private Map<String,String> getAccountMappingForCashBased() {
|
||||
Map<String,String> map = new HashMap<String, String>();
|
||||
for (int i=0;i<this.accountList.length;i++)
|
||||
{
|
||||
if(accountList[i].getAccountType().equals(Account.AccountType.ASSET)){
|
||||
String ID = accountList[i].getAccountID().toString();
|
||||
map.put("fundSourceAccountId",ID);
|
||||
map.put("loanPortfolioAccountId",ID);
|
||||
}
|
||||
if(accountList[i].getAccountType().equals(Account.AccountType.INCOME)){
|
||||
String ID = accountList[i].getAccountID().toString();
|
||||
map.put("interestOnLoanAccountId",ID);
|
||||
map.put("incomeFromFeeAccountId",ID);
|
||||
map.put("incomeFromPenaltyAccountId",ID);
|
||||
}
|
||||
if(accountList[i].getAccountType().equals(Account.AccountType.EXPENSE)){
|
||||
String ID = accountList[i].getAccountID().toString();
|
||||
map.put("writeOffAccountId",ID);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
private Map<String, String> getAccountMappingForAccrualBased() {
|
||||
Map<String,String> map = new HashMap<String, String>();
|
||||
for (int i=0;i<this.accountList.length;i++)
|
||||
{
|
||||
if(accountList[i].getAccountType().equals(Account.AccountType.ASSET)){
|
||||
String ID = accountList[i].getAccountID().toString();
|
||||
map.put("fundSourceAccountId",ID);
|
||||
map.put("loanPortfolioAccountId",ID);
|
||||
map.put("receivableInterestAccountId",ID);
|
||||
map.put("receivableFeeAccountId",ID);
|
||||
map.put("receivablePenaltyAccountId",ID);
|
||||
|
||||
}
|
||||
if(accountList[i].getAccountType().equals(Account.AccountType.INCOME)){
|
||||
String ID = accountList[i].getAccountID().toString();
|
||||
map.put("interestOnLoanAccountId",ID);
|
||||
map.put("incomeFromFeeAccountId",ID);
|
||||
map.put("incomeFromPenaltyAccountId",ID);
|
||||
}
|
||||
if(accountList[i].getAccountType().equals(Account.AccountType.EXPENSE)){
|
||||
String ID = accountList[i].getAccountID().toString();
|
||||
map.put("writeOffAccountId",ID);
|
||||
}
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
}
|
||||
+6
-5
@@ -1,4 +1,4 @@
|
||||
package org.mifosplatform.integrationtests.common;
|
||||
package org.mifosplatform.integrationtests.common.loans;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@@ -7,6 +7,7 @@ import java.util.HashMap;
|
||||
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
import org.mifosplatform.integrationtests.common.Utils;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class LoanStatusChecker {
|
||||
@@ -27,14 +28,14 @@ public class LoanStatusChecker {
|
||||
assertTrue(getStatus(loanStatusHashMap, "active"));
|
||||
}
|
||||
|
||||
public static void verifyLoanNeedsApproval(final HashMap loanStatusHashMap) {
|
||||
assertTrue(getStatus(loanStatusHashMap, "pendingApproval"));
|
||||
}
|
||||
|
||||
public static void verifyLoanAccountIsClosed(final HashMap loanStatusHashMap) {
|
||||
assertTrue(getStatus(loanStatusHashMap, "closed"));
|
||||
}
|
||||
|
||||
public static void verifyLoanAccountIsNotActive(final HashMap loanStatusHashMap) {
|
||||
assertFalse(getStatus(loanStatusHashMap, "active"));
|
||||
}
|
||||
|
||||
public static HashMap getStatusOfLoan(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final Integer loanID) {
|
||||
String url = "/mifosng-provider/api/v1/loans/" + loanID + "?tenantIdentifier=default";
|
||||
+67
-34
@@ -1,4 +1,4 @@
|
||||
package org.mifosplatform.integrationtests.common;
|
||||
package org.mifosplatform.integrationtests.common.loans;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -6,73 +6,92 @@ import java.util.HashMap;
|
||||
import com.google.gson.Gson;
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
import org.mifosplatform.integrationtests.common.Utils;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class LoanTransactionHelper {
|
||||
|
||||
private RequestSpecification requestSpec;
|
||||
private ResponseSpecification responseSpec;
|
||||
|
||||
private static final String CREATE_LOAN_PRODUCT_URL = "/mifosng-provider/api/v1/loanproducts?tenantIdentifier=default";
|
||||
private static final String APPLY_LOAN_URL = "/mifosng-provider/api/v1/loans?tenantIdentifier=default";
|
||||
private static final String APPROVE_LOAN_COMMAND = "approve";
|
||||
private static final String UNDO_APPROVAL_LOAN_COMMAND = "undoApproval";
|
||||
private static final String DISBURSE_LOAN_COMMAND = "disburse";
|
||||
private static final String UNDO_DISBURSE_LOAN_COMMAND = "undoDisbursal";
|
||||
private static final String WRITE_OFF_LOAN_COMMAND = "writeoff";
|
||||
private static final String WAIVE_INTEREST_COMMAND = "waiveinterest";
|
||||
private static final String MAKE_REPAYMENT_COMMAND = "repayment";
|
||||
private static final String WITHDRAW_LOAN_APPLICATION_COMMAND = "withdrawnByApplicant";
|
||||
|
||||
public static Integer getLoanProductId(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String loanProductJSON) {
|
||||
|
||||
public LoanTransactionHelper(RequestSpecification requestSpec,ResponseSpecification responseSpec){
|
||||
this.requestSpec = requestSpec;
|
||||
this.responseSpec = responseSpec;
|
||||
}
|
||||
public Integer getLoanProductId(final String loanProductJSON) {
|
||||
return Utils.performServerPost(requestSpec, responseSpec, CREATE_LOAN_PRODUCT_URL, loanProductJSON, "resourceId");
|
||||
}
|
||||
|
||||
public static Integer getLoanId(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String loanApplicationJSON) {
|
||||
public Integer getLoanId(final String loanApplicationJSON) {
|
||||
return Utils.performServerPost(requestSpec, responseSpec, APPLY_LOAN_URL, loanApplicationJSON, "loanId");
|
||||
}
|
||||
|
||||
public static ArrayList getLoanRepaymentSchedule(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
public ArrayList getLoanRepaymentSchedule(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final Integer loanID) {
|
||||
String URL = "/mifosng-provider/api/v1/loans/" + loanID + "?associations=repaymentSchedule&tenantIdentifier=default";
|
||||
HashMap response = Utils.performServerGet(requestSpec, responseSpec, URL, "repaymentSchedule");
|
||||
return (ArrayList) response.get("periods");
|
||||
}
|
||||
|
||||
public static HashMap approveLoan(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String approvalDate, final Integer loanID) {
|
||||
return performLoanTransaction(requestSpec, responseSpec, createLoanOperationURL(APPROVE_LOAN_COMMAND, loanID),
|
||||
public HashMap approveLoan(final String approvalDate, final Integer loanID) {
|
||||
return performLoanTransaction(createLoanOperationURL(APPROVE_LOAN_COMMAND, loanID),
|
||||
getApproveLoanAsJSON(approvalDate));
|
||||
}
|
||||
|
||||
public static HashMap undoApproval(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final Integer loanID) {
|
||||
public HashMap undoApproval(final Integer loanID) {
|
||||
String undoBodyJson = "{'note':'UNDO APPROVAL'}";
|
||||
return performLoanTransaction(requestSpec, responseSpec, createLoanOperationURL(UNDO_APPROVAL_LOAN_COMMAND, loanID), undoBodyJson);
|
||||
return performLoanTransaction(createLoanOperationURL(UNDO_APPROVAL_LOAN_COMMAND, loanID), undoBodyJson);
|
||||
}
|
||||
|
||||
public static HashMap disburseLoan(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, final String date,
|
||||
final Integer loanID) {
|
||||
return performLoanTransaction(requestSpec, responseSpec, createLoanOperationURL(DISBURSE_LOAN_COMMAND, loanID),
|
||||
public HashMap disburseLoan(final String date,
|
||||
final Integer loanID) {
|
||||
return performLoanTransaction(createLoanOperationURL(DISBURSE_LOAN_COMMAND, loanID),
|
||||
getDisburseLoanAsJSON(date));
|
||||
}
|
||||
|
||||
public static HashMap writeOffLoan(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, final String date,
|
||||
final Integer loanID) {
|
||||
return performLoanTransaction(requestSpec, responseSpec, createLoanTransactionURL(WRITE_OFF_LOAN_COMMAND, loanID),
|
||||
public HashMap undoDisbursal(final Integer loanID){
|
||||
String undoDisburseJson = "{'note' : 'UNDO DISBURSAL'}";
|
||||
System.out.println("IN DISBURSE LOAN");
|
||||
String url =createLoanOperationURL(UNDO_DISBURSE_LOAN_COMMAND,loanID);
|
||||
System.out.println("IN DISBURSE LOAN URL " + url);
|
||||
return performLoanTransaction(createLoanOperationURL(UNDO_DISBURSE_LOAN_COMMAND, loanID), undoDisburseJson);
|
||||
}
|
||||
public HashMap writeOffLoan(final String date,
|
||||
final Integer loanID) {
|
||||
return performLoanTransaction(createLoanTransactionURL(WRITE_OFF_LOAN_COMMAND, loanID),
|
||||
getWriteOffBodyAsJSON(date));
|
||||
}
|
||||
|
||||
public static HashMap waiveInterest(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String date, final String amountToBeWaived, final Integer loanID) {
|
||||
return performLoanTransaction(requestSpec, responseSpec, createLoanTransactionURL(WAIVE_INTEREST_COMMAND, loanID),
|
||||
public HashMap waiveInterest(final String date, final String amountToBeWaived, final Integer loanID) {
|
||||
return performLoanTransaction(createLoanTransactionURL(WAIVE_INTEREST_COMMAND, loanID),
|
||||
getWaiveBodyAsJSON(date, amountToBeWaived));
|
||||
}
|
||||
|
||||
public static HashMap makeRepayment(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String date, final Float amountToBePaid, final Integer loanID) {
|
||||
return performLoanTransaction(requestSpec, responseSpec, createLoanTransactionURL(MAKE_REPAYMENT_COMMAND, loanID),
|
||||
public HashMap makeRepayment(final String date, final Float amountToBePaid, final Integer loanID) {
|
||||
return performLoanTransaction(createLoanTransactionURL(MAKE_REPAYMENT_COMMAND, loanID),
|
||||
getRepaymentBodyAsJSON(date, amountToBePaid));
|
||||
}
|
||||
|
||||
public static String getDisburseLoanAsJSON(final String actualDisbursementDate) {
|
||||
public HashMap withdrawLoanApplicationByClient(final String date, final Integer loanID) {
|
||||
return performLoanTransaction(createLoanOperationURL(WITHDRAW_LOAN_APPLICATION_COMMAND,loanID),
|
||||
getWithdrawLoanApplicationBodyAsJSON(date));
|
||||
}
|
||||
|
||||
private String getDisburseLoanAsJSON(final String actualDisbursementDate) {
|
||||
HashMap<String, String> map = new HashMap<String, String>();
|
||||
map.put("locale", "en");
|
||||
map.put("dateFormat", "dd MMMM yyyy");
|
||||
@@ -81,7 +100,7 @@ public class LoanTransactionHelper {
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
public static String getApproveLoanAsJSON(final String approvalDate) {
|
||||
private String getApproveLoanAsJSON(final String approvalDate) {
|
||||
HashMap<String, String> map = new HashMap<String, String>();
|
||||
map.put("locale", "en");
|
||||
map.put("dateFormat", "dd MMMM yyyy");
|
||||
@@ -90,7 +109,7 @@ public class LoanTransactionHelper {
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
public static String getRepaymentBodyAsJSON(final String transactionDate, final Float transactionAmount) {
|
||||
private String getRepaymentBodyAsJSON(final String transactionDate, final Float transactionAmount) {
|
||||
HashMap<String, String> map = new HashMap<String, String>();
|
||||
map.put("locale", "en");
|
||||
map.put("dateFormat", "dd MMMM yyyy");
|
||||
@@ -100,7 +119,7 @@ public class LoanTransactionHelper {
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
public static String getWriteOffBodyAsJSON(final String transactionDate) {
|
||||
private String getWriteOffBodyAsJSON(final String transactionDate) {
|
||||
HashMap<String, String> map = new HashMap<String, String>();
|
||||
map.put("dateFormat", "dd MMMM yyyy");
|
||||
map.put("locale", "en");
|
||||
@@ -109,7 +128,7 @@ public class LoanTransactionHelper {
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
public static String getWaiveBodyAsJSON(final String transactionDate, final String amountToBeWaived) {
|
||||
private String getWaiveBodyAsJSON(final String transactionDate, final String amountToBeWaived) {
|
||||
HashMap<String, String> map = new HashMap<String, String>();
|
||||
map.put("locale", "en");
|
||||
map.put("dateFormat", "dd MMMM yyyy");
|
||||
@@ -119,7 +138,16 @@ public class LoanTransactionHelper {
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
public static String getLoanCalculationBodyAsJSON(final String productID) {
|
||||
private String getWithdrawLoanApplicationBodyAsJSON(final String withdrawDate){
|
||||
HashMap<String, String> map = new HashMap<String, String>();
|
||||
map.put("locale", "en");
|
||||
map.put("dateFormat", "dd MMMM yyyy");
|
||||
map.put("withdrawnOnDate", withdrawDate);
|
||||
map.put("note", " Loan Withdrawn By Client!!!");
|
||||
return new Gson().toJson(map);
|
||||
|
||||
}
|
||||
public String getLoanCalculationBodyAsJSON(final String productID) {
|
||||
HashMap<String, String> map = new HashMap<String, String>();
|
||||
map.put("dateFormat", "dd MMMM yyyy");
|
||||
map.put("locale", "en_GB");
|
||||
@@ -140,18 +168,23 @@ public class LoanTransactionHelper {
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
private static String createLoanOperationURL(final String command, final Integer loanID) {
|
||||
private String createLoanOperationURL(final String command, final Integer loanID) {
|
||||
return "/mifosng-provider/api/v1/loans/" + loanID + "?command=" + command + "&tenantIdentifier=default";
|
||||
}
|
||||
|
||||
private static String createLoanTransactionURL(final String command, final Integer loanID) {
|
||||
private String createLoanTransactionURL(final String command, final Integer loanID) {
|
||||
return "/mifosng-provider/api/v1/loans/" + loanID + "/transactions?command=" + command + "&tenantIdentifier=default";
|
||||
}
|
||||
|
||||
private static HashMap performLoanTransaction(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String postURLForLoanTransaction, final String jsonToBeSent) {
|
||||
private HashMap performLoanTransaction(final String postURLForLoanTransaction, final String jsonToBeSent) {
|
||||
|
||||
HashMap response = Utils.performServerPost(requestSpec, responseSpec, postURLForLoanTransaction, jsonToBeSent, "changes");
|
||||
return (HashMap) response.get("status");
|
||||
}
|
||||
|
||||
public void verifyRepaymentScheduleEntryFor(final int repaymentNumber, final float expectedPrincipalOutstanding, final Integer loanID) {
|
||||
System.out.println("---------------------------GETTING LOAN REPAYMENT SCHEDULE--------------------------------");
|
||||
ArrayList<HashMap> repaymentPeriods = getLoanRepaymentSchedule(requestSpec, responseSpec, loanID);
|
||||
assertEquals("Mismatch in Principal Loan Balance Outstanding ", expectedPrincipalOutstanding, repaymentPeriods.get(repaymentNumber).get("principalLoanBalanceOutstanding"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user