Refactoring

This commit is contained in:
Priti
2013-04-02 17:09:07 +05:30
parent be32e0b7eb
commit a70712d8fc
7 changed files with 43 additions and 54 deletions
@@ -38,11 +38,11 @@ public class ClientLoanIntegrationTest {
@Test
public void checkClientLoanCreateAndDisburseFlow(){
Integer clientID = ClientBuilder.createClient(requestSpec, responseSpec);
ClientBuilder.verifyClientCreatedOnServer(requestSpec, responseSpec, clientID);
Integer clientID = ClientHelper.createClient(requestSpec, responseSpec);
ClientHelper.verifyClientCreatedOnServer(requestSpec, responseSpec, clientID);
Integer loanProductID = createLoanProduct();
Integer loanID= applyForLoanApplication(clientID, loanProductID);
Integer loanID = applyForLoanApplication(clientID, loanProductID);
ArrayList <HashMap> loanSchedule = LoanTransactionHelper.getLoanRepaymentSchedule(requestSpec, responseSpec, loanID);
verifyLoanRepaymentSchedule(loanSchedule);
@@ -81,7 +81,7 @@ public class ClientLoanIntegrationTest {
.withInterestCalculationPeriodTypeSameAsRepaymentPeriod()
.withExpectedDisbursementDate("20 September 2011")
.withSubmittedOnDate("20 September 2011")
.Build(clientID.toString(),loanProductID.toString());
.build(clientID.toString(), loanProductID.toString());
return LoanTransactionHelper.getLoanId(requestSpec, responseSpec, loanApplicationJSON);
}
@@ -1,25 +1,19 @@
package org.mifosplatform.integrationtests;
import static com.jayway.restassured.RestAssured.given;
import static com.jayway.restassured.RestAssured.post;
import static com.jayway.restassured.path.json.JsonPath.from;
import static junit.framework.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.HashMap;
import org.junit.Before;
import org.junit.Test;
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 java.util.ArrayList;
import java.util.HashMap;
import static junit.framework.Assert.assertEquals;
/**
* Client Loan Integration Test for checking Loan Disbursement with Waive Interest and Write-Off.
*/
@@ -55,8 +49,8 @@ public class LoanWithWaiveInterestAndWriteOff {
@Test
public void checkClientLoanCreateAndDisburseFlow(){
//CREATE CLIENT
Integer clientID = ClientBuilder.createClient(requestSpec, responseSpec, DATE_OF_JOINING);
ClientBuilder.verifyClientCreatedOnServer(requestSpec, responseSpec, clientID);
Integer clientID = ClientHelper.createClient(requestSpec, responseSpec, DATE_OF_JOINING);
ClientHelper.verifyClientCreatedOnServer(requestSpec, responseSpec, clientID);
//CREATE LOAN PRODUCT
Integer loanProductID = createLoanProduct();
@@ -66,7 +60,6 @@ public class LoanWithWaiveInterestAndWriteOff {
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
//APPROVE LOAN
System.out.println("-----------------------------------APPROVE LOAN-----------------------------------------");
loanStatusHashMap = LoanTransactionHelper.approveLoan(requestSpec, responseSpec, "28 September 2010", loanID);
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
@@ -76,8 +69,7 @@ public class LoanWithWaiveInterestAndWriteOff {
loanStatusHashMap = LoanTransactionHelper.undoApproval(requestSpec, responseSpec, loanID);
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
//RE-APPROVE LOAN ON 1 OCTOBER 2010
System.out.println("-----------------------------------APPROVE LOAN-----------------------------------------");
System.out.println("-----------------------------------RE-APPROVE LOAN-----------------------------------------");
loanStatusHashMap = LoanTransactionHelper.approveLoan(requestSpec, responseSpec, "1 October 2010", loanID);
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
@@ -107,10 +99,9 @@ public class LoanWithWaiveInterestAndWriteOff {
}
private void verifyRepaymentScheduleEntryFor(int repaymentNumber, float expectedPrincipalOutstanding ,Integer loanID) {
private void verifyRepaymentScheduleEntryFor(int repaymentNumber, float expectedPrincipalOutstanding, Integer loanID) {
System.out.println("---------------------------GETTING LOAN REPAYMENT SCHEDULE--------------------------------");
ArrayList<HashMap> repaymentPeriods = LoanTransactionHelper.getLoanRepaymentSchedule(requestSpec, responseSpec, loanID);
System.out.println("**********RESPOSE : "+repaymentPeriods);
assertEquals(expectedPrincipalOutstanding,repaymentPeriods.get(repaymentNumber).get("principalLoanBalanceOutstanding"));
}
@@ -147,7 +138,7 @@ public class LoanWithWaiveInterestAndWriteOff {
.withInterestCalculationPeriodTypeSameAsRepaymentPeriod()
.withExpectedDisbursementDate(EXPECTED_DISBURSAL_DATE)
.withSubmittedOnDate(LOAN_APPLICATION_SUBMISSION_DATE)
.Build(clientID.toString(), loanProductID.toString());
.build(clientID.toString(), loanProductID.toString());
return LoanTransactionHelper.getLoanId(requestSpec,responseSpec,loanApplicationJSON);
}
}
@@ -17,30 +17,24 @@ public class LoanApplicationTestBuilder {
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 clientID="0";
private String loanProductId = "0";
private String loanTermFrequency = "";
private String loanTermFrequencyType=""; //0=Days, 1=Weeks, 2=Months, 3=Years
private String loanTermFrequencyType = "";
private String numberOfRepayment = "0";
private String repaymentPeriod = "0";
private String repaymentFrequencyType = ""; //0=Days, 1=Weeks, 2=Months
private String repaymentFrequencyType = "";
// 12 % per Year Declining Balance
// interest rate per Interest_frequency interest type
private String interestRate = "2";
private String interestRateFrequencyType="0"; //2=Per month, 3=Per year
private String interestType= ""; //0=Declining Balance, 1=Flat
private String amortizationType =""; //0=Equal principle payments, 1=Equal installments
private String interestCalculationPeriodType =CALCULATION_PERIOD_SAME_AS_REPAYMENT_PERIOD;
private String transactionProcessingID= MIFOS_STANDARD_STRATEGY;
private String expectedDisbursmentDate="";
private String submittedOndate ="";
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 String expectedDisbursmentDate = "";
private String submittedOndate = "";
public String build(String clientID, String loanProductId){
public String Build(String clientID, String loanProductId){
this.clientID = clientID;
this.loanProductId = loanProductId;
HashMap<String, String> map = new HashMap<String, String>();
map.put("dateFormat", "dd MMMM yyyy");
map.put("locale", "en_GB");
@@ -26,7 +26,7 @@ public class LoanProductTestBuilder {
private static final String ACCRUAL_BASED ="3";
private String nameOfLoanProduct = ClientBuilder.randomNameGenerator("LOAN_PRODUCT_", 6);
private String nameOfLoanProduct = ClientHelper.randomNameGenerator("LOAN_PRODUCT_", 6);
private String principal = "10000.00";
private String numberOfRepayments = "0";
private String repaymentFrequency = WEEK;
@@ -13,10 +13,6 @@ import static org.junit.Assert.assertTrue;
public class LoanStatusChecker {
private static boolean getStatus(HashMap loanStatusMap, String nameOfLoanStatusString){
return (Boolean)loanStatusMap.get(nameOfLoanStatusString);
}
public static void verifyLoanIsApproved(HashMap loanStatusHashMap) {
assertFalse(getStatus(loanStatusHashMap, "pendingApproval"));
}
@@ -45,4 +41,12 @@ public class LoanStatusChecker {
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);
}
}
@@ -7,8 +7,6 @@ import com.jayway.restassured.specification.ResponseSpecification;
import java.util.ArrayList;
import java.util.HashMap;
import static com.jayway.restassured.RestAssured.given;
public class LoanTransactionHelper {
private static final String CREATE_LOAN_PRODUCT_URL = "/mifosng-provider/api/v1/loanproducts?tenantIdentifier=default";
@@ -13,6 +13,13 @@ import static com.jayway.restassured.path.json.JsonPath.from;
public class Utils {
private static final String LOGIN_URL = "/mifosng-provider/api/v1/authentication?username=mifos&password=password&tenantIdentifier=default";
public static String loginIntoServerAndGetBase64EncodedAuthenticationKey() {
System.out.println("-----------------------------------LOGIN-----------------------------------------");
String json = RestAssured.post(LOGIN_URL).asString();
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)
@@ -31,9 +38,4 @@ public class Utils {
return (T) from(json).get(jsonAttributeToGetBack);
}
public static String loginIntoServerAndGetBase64EncodedAuthenticationKey() {
System.out.println("-----------------------------------LOGIN-----------------------------------------");
String json = RestAssured.post(LOGIN_URL).asString();
return JsonPath.with(json).get("base64EncodedAuthenticationKey");
}
}