remove warnings on unchecked types and unused imports. Add IntegrationTest to end of test name.

This commit is contained in:
Keith Woodlock
2013-04-02 15:16:47 +01:00
parent 1a5ef94def
commit 41b31ded07
9 changed files with 331 additions and 5070 deletions
@@ -0,0 +1,126 @@
package org.mifosplatform.integrationtests;
import static junit.framework.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.Utils;
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;
/**
* Client Loan Integration Test for checking Loan Disbursement with Waive
* Interest and Write-Off.
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public class LoanWithWaiveInterestAndWriteOffIntegrationTest {
ResponseSpecification responseSpec;
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";
@Before
public void setup() {
requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
}
@Test
public void checkClientLoanCreateAndDisburseFlow() {
// CREATE CLIENT
Integer clientID = ClientHelper.createClient(requestSpec, responseSpec, DATE_OF_JOINING);
ClientHelper.verifyClientCreatedOnServer(requestSpec, responseSpec, clientID);
// CREATE LOAN PRODUCT
Integer loanProductID = createLoanProduct();
// APPLY FOR LOAN
Integer loanID = applyForLoanApplication(clientID, loanProductID);
HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(requestSpec, responseSpec, loanID);
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
System.out.println("-----------------------------------APPROVE LOAN-----------------------------------------");
loanStatusHashMap = LoanTransactionHelper.approveLoan(requestSpec, responseSpec, "28 September 2010", loanID);
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
// UNDO APPROVAL
loanStatusHashMap = LoanTransactionHelper.undoApproval(requestSpec, responseSpec, loanID);
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
System.out.println("-----------------------------------RE-APPROVE LOAN-----------------------------------------");
loanStatusHashMap = LoanTransactionHelper.approveLoan(requestSpec, responseSpec, "1 October 2010", loanID);
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
// DISBURSE
loanStatusHashMap = LoanTransactionHelper.disburseLoan(requestSpec, responseSpec, 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);
verifyRepaymentScheduleEntryFor(7, 1000.0f, loanID);
// WRITE OFF LOAN AND CHECK ACCOUNT IS CLOSED
LoanStatusChecker.verifyLoanAccountIsClosed(LoanTransactionHelper.writeOffLoan(requestSpec, responseSpec, "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(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);
}
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()
.withAmortizationTypeAsEqualInstallments().withInterestCalculationPeriodTypeSameAsRepaymentPeriod()
.withExpectedDisbursementDate(EXPECTED_DISBURSAL_DATE).withSubmittedOnDate(LOAN_APPLICATION_SUBMISSION_DATE)
.build(clientID.toString(), loanProductID.toString());
return LoanTransactionHelper.getLoanId(requestSpec, responseSpec, loanApplicationJSON);
}
}
@@ -1,34 +1,29 @@
package org.mifosplatform.integrationtests.common;
import java.util.HashMap;
import java.util.Random;
import junit.framework.Assert;
import com.google.gson.Gson;
import com.jayway.restassured.specification.RequestSpecification;
import com.jayway.restassured.specification.ResponseSpecification;
import java.util.HashMap;
import java.util.Random;
import static com.jayway.restassured.RestAssured.given;
import static com.jayway.restassured.RestAssured.post;
import static com.jayway.restassured.path.json.JsonPath.from;
import junit.framework.Assert;
public class ClientHelper {
private static final String CREATE_CLIENT_URL = "/mifosng-provider/api/v1/clients?tenantIdentifier=default";
public static Integer createClient(RequestSpecification requestSpec, ResponseSpecification responseSpec) {
return createClient(requestSpec,responseSpec,"04 March 2012");
public static Integer createClient(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
return createClient(requestSpec, responseSpec, "04 March 2012");
}
public static Integer createClient(RequestSpecification requestSpec, ResponseSpecification responseSpec,String dateOfJoining) {
public static Integer createClient(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
final String dateOfJoining) {
System.out.println("---------------------------------CREATING A CLIENT---------------------------------------------");
return Utils.performServerPost(requestSpec, responseSpec, CREATE_CLIENT_URL, getTestClientAsJSON(dateOfJoining), "clientId");
}
public static String getTestClientAsJSON(String dateOfJoining) {
public static String getTestClientAsJSON(final String dateOfJoining) {
HashMap<String, String> map = new HashMap<String, String>();
map.put("officeId", "1");
map.put("firstname", randomNameGenerator("Client_FirstName_", 5));
@@ -37,15 +32,16 @@ public class ClientHelper {
map.put("dateFormat", "dd MMMM yyyy");
map.put("locale", "en");
map.put("joinedDate", dateOfJoining);
System.out.println("map : "+map);
System.out.println("map : " + map);
return new Gson().toJson(map);
}
public static void verifyClientCreatedOnServer(RequestSpecification requestSpec, ResponseSpecification responseSpec, Integer generatedClientID) {
public static void verifyClientCreatedOnServer(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
final Integer generatedClientID) {
System.out.println("------------------------------CHECK CLIENT DETAILS------------------------------------\n");
String CLIENT_URL="/mifosng-provider/api/v1/clients/" + generatedClientID + "?tenantIdentifier=default";
String CLIENT_URL = "/mifosng-provider/api/v1/clients/" + generatedClientID + "?tenantIdentifier=default";
Integer responseClientID = Utils.performServerGet(requestSpec, responseSpec, CLIENT_URL, "id");
Assert.assertEquals(generatedClientID,responseClientID);
Assert.assertEquals(generatedClientID, responseClientID);
}
private static String randomStringGenerator(final String prefix, final int len, final String sourceSetString) {
@@ -54,7 +50,7 @@ public class ClientHelper {
StringBuilder sb = new StringBuilder(len);
for (int i = 0; i < len; i++)
sb.append((sourceSetString).charAt(rnd.nextInt(lengthOfSource)));
return (prefix+(sb.toString()));
return (prefix + (sb.toString()));
}
public static String randomNameGenerator(final String prefix, final int lenOfRandomSuffix) {
@@ -64,8 +60,4 @@ public class ClientHelper {
private static String randomIDGenerator(final String prefix, final int lenOfRandomSuffix) {
return randomStringGenerator(prefix, lenOfRandomSuffix, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
}
}
}
@@ -1,48 +1,50 @@
package org.mifosplatform.integrationtests.common;
import com.google.gson.Gson;
import java.util.HashMap;
import com.google.gson.Gson;
public class LoanApplicationTestBuilder {
private static final String DAYS = "0";
private static final String WEEKS = "1";
private static final String MONTHS = "2";
private static final String YEARS = "3";
private static final String DECLINING_BALANCE = "0";
private static final String FLAT_BALANCE = "1";
private static final String EQUAL_PRINCIPLE_PAYMENTS="0";
private static final String EQUAL_INSTALLMENTS="1";
private static final String CALCULATION_PERIOD_SAME_AS_REPAYMENT_PERIOD="1";
private static final String MIFOS_STANDARD_STRATEGY ="1";
private static final String EQUAL_PRINCIPLE_PAYMENTS = "0";
private static final String EQUAL_INSTALLMENTS = "1";
private static final String CALCULATION_PERIOD_SAME_AS_REPAYMENT_PERIOD = "1";
private static final String MIFOS_STANDARD_STRATEGY = "1";
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 interestRate = "2";
private String interestRateFrequencyType = "0";
private String interestType = "";
private String amortizationType = "";
private String interestCalculationPeriodType = CALCULATION_PERIOD_SAME_AS_REPAYMENT_PERIOD;
private String transactionProcessingID = MIFOS_STANDARD_STRATEGY;
private final String transactionProcessingID = MIFOS_STANDARD_STRATEGY;
private String expectedDisbursmentDate = "";
private String submittedOndate = "";
public String build(String clientID, String loanProductId){
public String build(final String clientID, final String loanProductId) {
HashMap<String, String> map = new HashMap<String, String>();
map.put("dateFormat", "dd MMMM yyyy");
map.put("locale", "en_GB");
map.put("clientId", clientID);
map.put("productId",loanProductId);
map.put("productId", loanProductId);
map.put("principal", principal);
map.put("loanTermFrequency",loanTermFrequency);
map.put("loanTermFrequencyType", "2");
map.put("loanTermFrequency", loanTermFrequency);
map.put("loanTermFrequencyType", "2"); // FIXME - Should this be using
// loanTermFrequencyType value?
map.put("numberOfRepayments", numberOfRepayment);
map.put("repaymentEvery", repaymentPeriod);
map.put("repaymentFrequencyType", repaymentFrequencyType);
@@ -57,101 +59,113 @@ public class LoanApplicationTestBuilder {
return new Gson().toJson(map);
}
public LoanApplicationTestBuilder withPrincipal(String principalAmount){
public LoanApplicationTestBuilder withPrincipal(final String principalAmount) {
this.principal = principalAmount;
return this;
}
public LoanApplicationTestBuilder withLoanTermFrequency(String loanToBePayedDuration){
this.loanTermFrequency= loanToBePayedDuration;
public LoanApplicationTestBuilder withLoanTermFrequency(final String loanToBePayedDuration) {
this.loanTermFrequency = loanToBePayedDuration;
return this;
}
public LoanApplicationTestBuilder withLoanTermFrequencyAsDays(){
this.loanTermFrequencyType=DAYS;
public LoanApplicationTestBuilder withLoanTermFrequencyAsDays() {
this.loanTermFrequencyType = DAYS;
return this;
}
public LoanApplicationTestBuilder withLoanTermFrequencyAsMonths(){
this.loanTermFrequencyType=MONTHS;
public LoanApplicationTestBuilder withLoanTermFrequencyAsMonths() {
this.loanTermFrequencyType = MONTHS;
return this;
}
public LoanApplicationTestBuilder withLoanTermFrequencyAsWeeks(){
this.loanTermFrequencyType=WEEKS;
public LoanApplicationTestBuilder withLoanTermFrequencyAsWeeks() {
this.loanTermFrequencyType = WEEKS;
return this;
}
public LoanApplicationTestBuilder withLoanTermFrequencyAsYears(){
this.loanTermFrequencyType=YEARS;
public LoanApplicationTestBuilder withLoanTermFrequencyAsYears() {
this.loanTermFrequencyType = YEARS;
return this;
}
public LoanApplicationTestBuilder withNumberOfRepayments(String numberOfRepayments){
this.numberOfRepayment= numberOfRepayments;
public LoanApplicationTestBuilder withNumberOfRepayments(final String numberOfRepayments) {
this.numberOfRepayment = numberOfRepayments;
return this;
}
public LoanApplicationTestBuilder withRepaymentEveryAfter(String repaymentPeriod){
this.repaymentPeriod=repaymentPeriod;
public LoanApplicationTestBuilder withRepaymentEveryAfter(final String repaymentPeriod) {
this.repaymentPeriod = repaymentPeriod;
return this;
}
public LoanApplicationTestBuilder withRepaymentFrequencyTypeAsDays(){
public LoanApplicationTestBuilder withRepaymentFrequencyTypeAsDays() {
this.repaymentFrequencyType = DAYS;
return this;
}
public LoanApplicationTestBuilder withRepaymentFrequencyTypeAsMonths(){
public LoanApplicationTestBuilder withRepaymentFrequencyTypeAsMonths() {
this.repaymentFrequencyType = MONTHS;
return this;
}
public LoanApplicationTestBuilder withRepaymentFrequencyTypeAsWeeks(){
public LoanApplicationTestBuilder withRepaymentFrequencyTypeAsWeeks() {
this.repaymentFrequencyType = WEEKS;
return this;
}
public LoanApplicationTestBuilder withInterestRatePerPeriod(String interestRate){
this.interestRate=interestRate;
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;
}
public LoanApplicationTestBuilder withInterestTypeAsDecliningBalance(){
this.interestType=DECLINING_BALANCE;
public LoanApplicationTestBuilder withInterestRatePerPeriod(final String interestRate) {
this.interestRate = interestRate;
return this;
}
public LoanApplicationTestBuilder withAmortizationTypeAsEqualInstallments(){
this.amortizationType=EQUAL_INSTALLMENTS;
public LoanApplicationTestBuilder withInterestRateFrequencyTypeAsMonths() {
this.interestRateFrequencyType = MONTHS;
return this;
}
public LoanApplicationTestBuilder withAmortizationTypeAsEqualPrincipalPayments(){
this.amortizationType=EQUAL_PRINCIPLE_PAYMENTS;
public LoanApplicationTestBuilder withInterestRateFrequencyTypeAsYears() {
this.interestRateFrequencyType = YEARS;
return this;
}
public LoanApplicationTestBuilder withInterestCalculationPeriodTypeSameAsRepaymentPeriod(){
this.interestCalculationPeriodType=CALCULATION_PERIOD_SAME_AS_REPAYMENT_PERIOD;
public LoanApplicationTestBuilder withInterestTypeAsFlatBalance() {
this.interestType = FLAT_BALANCE;
return this;
}
public LoanApplicationTestBuilder withInterestCalculationPeriodTypeAsDays(){
this.interestCalculationPeriodType=DAYS;
public LoanApplicationTestBuilder withInterestTypeAsDecliningBalance() {
this.interestType = DECLINING_BALANCE;
return this;
}
public LoanApplicationTestBuilder withExpectedDisbursementDate(String expectedDisbursementDate){
this.expectedDisbursmentDate=expectedDisbursementDate;
public LoanApplicationTestBuilder withAmortizationTypeAsEqualInstallments() {
this.amortizationType = EQUAL_INSTALLMENTS;
return this;
}
public LoanApplicationTestBuilder withSubmittedOnDate(String loanApplicationSubmittedDate){
this.submittedOndate=loanApplicationSubmittedDate;
public LoanApplicationTestBuilder withAmortizationTypeAsEqualPrincipalPayments() {
this.amortizationType = EQUAL_PRINCIPLE_PAYMENTS;
return this;
}
public LoanApplicationTestBuilder withInterestCalculationPeriodTypeSameAsRepaymentPeriod() {
this.interestCalculationPeriodType = CALCULATION_PERIOD_SAME_AS_REPAYMENT_PERIOD;
return this;
}
public LoanApplicationTestBuilder withInterestCalculationPeriodTypeAsDays() {
this.interestCalculationPeriodType = DAYS;
return this;
}
public LoanApplicationTestBuilder withExpectedDisbursementDate(final String expectedDisbursementDate) {
this.expectedDisbursmentDate = expectedDisbursementDate;
return this;
}
public LoanApplicationTestBuilder withSubmittedOnDate(final String loanApplicationSubmittedDate) {
this.submittedOndate = loanApplicationSubmittedDate;
return this;
}
}
@@ -1,9 +1,9 @@
package org.mifosplatform.integrationtests.common;
import com.google.gson.Gson;
import java.util.HashMap;
import com.google.gson.Gson;
public class LoanProductTestBuilder {
private static final String LOCALE = "en_GB";
private static final String DIGITS_AFTER_DECIMAL = "2";
@@ -18,9 +18,9 @@ public class LoanProductTestBuilder {
private static final String DECLINING_BALANCE="0";
private static final String FLAT_BALANCE="1";
private static final String MIFOS_STANDARD_STRATEGY ="1";
private static final String HEAVENS_FAMILY_STRATEGY ="2";
private static final String CREO_CORE_STRATEGY ="3";
private static final String RBI_INDIA_STRATEGY ="4";
// private static final String HEAVENS_FAMILY_STRATEGY ="2";
// private static final String CREO_CORE_STRATEGY ="3";
// private static final String RBI_INDIA_STRATEGY ="4";
private static final String NONE ="1";
private static final String CASH_BASED ="2";
private static final String ACCRUAL_BASED ="3";
@@ -36,9 +36,9 @@ public class LoanProductTestBuilder {
private String interestType = FLAT_BALANCE;
private String interestCalculationPeriodType=CALCULATION_PERIOD_SAME_AS_REPAYMENT_PERIOD;
private String inArrearsTolerance="0";
private String transactionProcessingStrategy=MIFOS_STANDARD_STRATEGY;
private final String transactionProcessingStrategy=MIFOS_STANDARD_STRATEGY;
private String accountingRule =NONE;
private String currencyCode = INR;
private final String currencyCode = INR;
private String amortizationType= EQUAL_INSTALLMENTS;
public String build() {
@@ -1,52 +1,50 @@
package org.mifosplatform.integrationtests.common;
import com.jayway.restassured.specification.RequestSpecification;
import com.jayway.restassured.specification.ResponseSpecification;
import junit.framework.Assert;
import java.util.HashMap;
import static com.jayway.restassured.RestAssured.given;
import static com.jayway.restassured.path.json.JsonPath.from;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.HashMap;
import junit.framework.Assert;
import com.jayway.restassured.specification.RequestSpecification;
import com.jayway.restassured.specification.ResponseSpecification;
@SuppressWarnings("rawtypes")
public class LoanStatusChecker {
public static void verifyLoanIsApproved(HashMap loanStatusHashMap) {
public static void verifyLoanIsApproved(final HashMap loanStatusHashMap) {
assertFalse(getStatus(loanStatusHashMap, "pendingApproval"));
}
public static void verifyLoanIsWaitingForDisbursal(HashMap loanStatusHashMap) {
public static void verifyLoanIsWaitingForDisbursal(final HashMap loanStatusHashMap) {
assertTrue(getStatus(loanStatusHashMap, "waitingForDisbursal"));
}
public static void verifyLoanIsPending(HashMap loanStatusHashMap) {
public static void verifyLoanIsPending(final HashMap loanStatusHashMap) {
assertTrue(getStatus(loanStatusHashMap, "pendingApproval"));
}
public static void verifyLoanIsActive(HashMap loanStatusHashMap) {
public static void verifyLoanIsActive(final HashMap loanStatusHashMap) {
assertTrue(getStatus(loanStatusHashMap, "active"));
}
public static void verifyLoanNeedsApproval(HashMap loanStatusHashMap) {
public static void verifyLoanNeedsApproval(final HashMap loanStatusHashMap) {
assertTrue(getStatus(loanStatusHashMap, "pendingApproval"));
}
public static void verifyLoanAccountIsClosed(HashMap loanStatusHashMap){
public static void verifyLoanAccountIsClosed(final HashMap loanStatusHashMap) {
Assert.assertTrue(getStatus(loanStatusHashMap, "closed"));
}
public static HashMap getStatusOfLoan(RequestSpecification requestSpec, ResponseSpecification responseSpec, Integer loanID){
String url = "/mifosng-provider/api/v1/loans/" + loanID + "?tenantIdentifier=default";
public static HashMap getStatusOfLoan(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
final Integer loanID) {
String url = "/mifosng-provider/api/v1/loans/" + loanID + "?tenantIdentifier=default";
return Utils.performServerGet(requestSpec, responseSpec, url, "status");
}
private static boolean getStatus(HashMap loanStatusMap, String nameOfLoanStatusString){
return (Boolean)loanStatusMap.get(nameOfLoanStatusString);
private static boolean getStatus(final HashMap loanStatusMap, final String nameOfLoanStatusString) {
return (Boolean) loanStatusMap.get(nameOfLoanStatusString);
}
}
@@ -1,12 +1,13 @@
package org.mifosplatform.integrationtests.common;
import java.util.ArrayList;
import java.util.HashMap;
import com.google.gson.Gson;
import com.jayway.restassured.specification.RequestSpecification;
import com.jayway.restassured.specification.ResponseSpecification;
import java.util.ArrayList;
import java.util.HashMap;
@SuppressWarnings("rawtypes")
public class LoanTransactionHelper {
private static final String CREATE_LOAN_PRODUCT_URL = "/mifosng-provider/api/v1/loanproducts?tenantIdentifier=default";
@@ -18,49 +19,60 @@ public class LoanTransactionHelper {
private static final String WAIVE_INTEREST_COMMAND = "waiveinterest";
private static final String MAKE_REPAYMENT_COMMAND = "repayment";
public static Integer getLoanProductId(RequestSpecification requestSpec, ResponseSpecification responseSpec, String loanProductJSON) {
public static Integer getLoanProductId(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
final String loanProductJSON) {
return Utils.performServerPost(requestSpec, responseSpec, CREATE_LOAN_PRODUCT_URL, loanProductJSON, "resourceId");
}
public static Integer getLoanId(RequestSpecification requestSpec, ResponseSpecification responseSpec, String loanApplicationJSON) {
public static Integer getLoanId(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
final String loanApplicationJSON) {
return Utils.performServerPost(requestSpec, responseSpec, APPLY_LOAN_URL, loanApplicationJSON, "loanId");
}
public static ArrayList getLoanRepaymentSchedule(RequestSpecification requestSpec, ResponseSpecification responseSpec,final Integer loanID){
String URL = "/mifosng-provider/api/v1/loans/" + loanID +"?associations=repaymentSchedule&tenantIdentifier=default";
public static 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(RequestSpecification requestSpec, ResponseSpecification responseSpec, String approvalDate, Integer loanID) {
return performLoanTransaction(requestSpec, responseSpec, createLoanOperationURL(APPROVE_LOAN_COMMAND, loanID), getApproveLoanAsJSON(approvalDate));
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),
getApproveLoanAsJSON(approvalDate));
}
public static HashMap undoApproval(RequestSpecification requestSpec, ResponseSpecification responseSpec, Integer loanID) {
public static HashMap undoApproval(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
final Integer loanID) {
String undoBodyJson = "{'note':'UNDO APPROVAL'}";
return performLoanTransaction(requestSpec, responseSpec, createLoanOperationURL(UNDO_APPROVAL_LOAN_COMMAND, loanID), undoBodyJson);
}
public static HashMap disburseLoan(RequestSpecification requestSpec, ResponseSpecification responseSpec, String date, Integer loanID) {
return performLoanTransaction(requestSpec, responseSpec, createLoanOperationURL(DISBURSE_LOAN_COMMAND, loanID), getDisburseLoanAsJSON(date));
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),
getDisburseLoanAsJSON(date));
}
public static HashMap writeOffLoan(RequestSpecification requestSpec, ResponseSpecification responseSpec, String date, Integer loanID) {
return performLoanTransaction(requestSpec, responseSpec, createLoanTransactionURL(WRITE_OFF_LOAN_COMMAND, loanID), getWriteOffBodyAsJSON(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),
getWriteOffBodyAsJSON(date));
}
public static HashMap waiveInterest(RequestSpecification requestSpec, ResponseSpecification responseSpec, String date,String amountToBeWaived, Integer loanID) {
return performLoanTransaction(requestSpec, responseSpec, createLoanTransactionURL(WAIVE_INTEREST_COMMAND,loanID), getWaiveBodyAsJSON(date, amountToBeWaived));
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),
getWaiveBodyAsJSON(date, amountToBeWaived));
}
public static HashMap makeRepayment(RequestSpecification requestSpec, ResponseSpecification responseSpec, String date,Float amountToBePaid, Integer loanID) {
return performLoanTransaction(requestSpec, responseSpec, createLoanTransactionURL(MAKE_REPAYMENT_COMMAND,loanID), getRepaymentBodyAsJSON(date,amountToBePaid));
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),
getRepaymentBodyAsJSON(date, amountToBePaid));
}
public static String getDisburseLoanAsJSON(String actualDisbursementDate) {
public static String getDisburseLoanAsJSON(final String actualDisbursementDate) {
HashMap<String, String> map = new HashMap<String, String>();
map.put("locale", "en");
map.put("dateFormat", "dd MMMM yyyy");
@@ -69,7 +81,7 @@ public class LoanTransactionHelper {
return new Gson().toJson(map);
}
public static String getApproveLoanAsJSON(String approvalDate) {
public static String getApproveLoanAsJSON(final String approvalDate) {
HashMap<String, String> map = new HashMap<String, String>();
map.put("locale", "en");
map.put("dateFormat", "dd MMMM yyyy");
@@ -78,7 +90,7 @@ public class LoanTransactionHelper {
return new Gson().toJson(map);
}
public static String getRepaymentBodyAsJSON(String transactionDate, Float transactionAmount) {
public static 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");
@@ -88,7 +100,7 @@ public class LoanTransactionHelper {
return new Gson().toJson(map);
}
public static String getWriteOffBodyAsJSON(String transactionDate) {
public static String getWriteOffBodyAsJSON(final String transactionDate) {
HashMap<String, String> map = new HashMap<String, String>();
map.put("dateFormat", "dd MMMM yyyy");
map.put("locale", "en");
@@ -97,7 +109,7 @@ public class LoanTransactionHelper {
return new Gson().toJson(map);
}
public static String getWaiveBodyAsJSON(String transactionDate, String amountToBeWaived) {
public static 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");
@@ -128,19 +140,18 @@ public class LoanTransactionHelper {
return new Gson().toJson(map);
}
private static String createLoanOperationURL(String command, Integer loanID) {
private static String createLoanOperationURL(final String command, final Integer loanID) {
return "/mifosng-provider/api/v1/loans/" + loanID + "?command=" + command + "&tenantIdentifier=default";
}
private static String createLoanTransactionURL(String command, Integer loanID) {
return "/mifosng-provider/api/v1/loans/" + loanID + "/transactions?command="+command+"&tenantIdentifier=default";
private static String createLoanTransactionURL(final String command, final Integer loanID) {
return "/mifosng-provider/api/v1/loans/" + loanID + "/transactions?command=" + command + "&tenantIdentifier=default";
}
private static HashMap performLoanTransaction(RequestSpecification requestSpec, ResponseSpecification responseSpec, String postURLForLoanTransaction, String jsonToBeSent) {
private static HashMap performLoanTransaction(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
final String postURLForLoanTransaction, final String jsonToBeSent) {
HashMap response = Utils.performServerPost(requestSpec, responseSpec, postURLForLoanTransaction, jsonToBeSent, "changes");
return (HashMap) response.get("status");
}
}
}
@@ -1,16 +1,16 @@
package org.mifosplatform.integrationtests.common;
import static com.jayway.restassured.RestAssured.given;
import static com.jayway.restassured.path.json.JsonPath.from;
import com.jayway.restassured.RestAssured;
import com.jayway.restassured.path.json.JsonPath;
import com.jayway.restassured.specification.RequestSpecification;
import com.jayway.restassured.specification.ResponseSpecification;
import static com.jayway.restassured.RestAssured.given;
import static com.jayway.restassured.RestAssured.post;
import static com.jayway.restassured.path.json.JsonPath.from;
@SuppressWarnings("unchecked")
public class Utils {
private static final String LOGIN_URL = "/mifosng-provider/api/v1/authentication?username=mifos&password=password&tenantIdentifier=default";
public static String loginIntoServerAndGetBase64EncodedAuthenticationKey() {
@@ -19,21 +19,15 @@ public class Utils {
return JsonPath.with(json).get("base64EncodedAuthenticationKey");
}
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();
final String getURL, final String jsonAttributeToGetBack) {
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)
final String postURL, final String jsonBodyToSend, final String jsonAttributeToGetBack) {
String json = given().spec(requestSpec).body(jsonBodyToSend).expect().spec(responseSpec).log().ifError().when().post(postURL)
.andReturn().asString();
return (T) from(json).get(jsonAttributeToGetBack);
}