Integration tests for Savings Dormancy Tracking feature

This commit is contained in:
Adi Narayana Raju
2016-05-10 17:51:09 +05:30
parent f3f6f4bf8f
commit a4aee1a3c0
5 changed files with 228 additions and 5 deletions
@@ -34,6 +34,7 @@ import java.util.Locale;
import org.apache.fineract.integrationtests.common.ClientHelper; import org.apache.fineract.integrationtests.common.ClientHelper;
import org.apache.fineract.integrationtests.common.CommonConstants; import org.apache.fineract.integrationtests.common.CommonConstants;
import org.apache.fineract.integrationtests.common.SchedulerJobHelper;
import org.apache.fineract.integrationtests.common.TaxComponentHelper; import org.apache.fineract.integrationtests.common.TaxComponentHelper;
import org.apache.fineract.integrationtests.common.TaxGroupHelper; import org.apache.fineract.integrationtests.common.TaxGroupHelper;
import org.apache.fineract.integrationtests.common.Utils; import org.apache.fineract.integrationtests.common.Utils;
@@ -42,6 +43,8 @@ import org.apache.fineract.integrationtests.common.savings.SavingsAccountHelper;
import org.apache.fineract.integrationtests.common.savings.SavingsProductHelper; import org.apache.fineract.integrationtests.common.savings.SavingsProductHelper;
import org.apache.fineract.integrationtests.common.savings.SavingsStatusChecker; import org.apache.fineract.integrationtests.common.savings.SavingsStatusChecker;
import org.joda.time.LocalDate; import org.joda.time.LocalDate;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@@ -806,7 +809,7 @@ public class ClientSavingsIntegrationTest {
final String percentage = "10"; final String percentage = "10";
final Integer taxGroupId = createTaxGroup(percentage); final Integer taxGroupId = createTaxGroup(percentage);
final Integer savingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE, final Integer savingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE,
minBalanceForInterestCalculation, minRequiredBalance, enforceMinRequiredBalance, allowOverdraft, String.valueOf(taxGroupId)); minBalanceForInterestCalculation, minRequiredBalance, enforceMinRequiredBalance, allowOverdraft, String.valueOf(taxGroupId), false);
Assert.assertNotNull(savingsProductID); Assert.assertNotNull(savingsProductID);
final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(clientID, savingsProductID, ACCOUNT_TYPE_INDIVIDUAL); final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(clientID, savingsProductID, ACCOUNT_TYPE_INDIVIDUAL);
@@ -854,7 +857,7 @@ public class ClientSavingsIntegrationTest {
final String percentage = "10"; final String percentage = "10";
final Integer taxGroupId = createTaxGroup(percentage); final Integer taxGroupId = createTaxGroup(percentage);
final Integer savingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE, final Integer savingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE,
minBalanceForInterestCalculation, minRequiredBalance, enforceMinRequiredBalance, allowOverdraft, String.valueOf(taxGroupId)); minBalanceForInterestCalculation, minRequiredBalance, enforceMinRequiredBalance, allowOverdraft, String.valueOf(taxGroupId), false);
Assert.assertNotNull(savingsProductID); Assert.assertNotNull(savingsProductID);
final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(clientID, savingsProductID, ACCOUNT_TYPE_INDIVIDUAL); final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(clientID, savingsProductID, ACCOUNT_TYPE_INDIVIDUAL);
@@ -890,6 +893,152 @@ public class ClientSavingsIntegrationTest {
Assert.assertEquals(expected, actual, 1); Assert.assertEquals(expected, actual, 1);
} }
@Test
public void testSavingsAccount_DormancyTracking() {
this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec);
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
Assert.assertNotNull(clientID);
final String minBalanceForInterestCalculation = null;
final String minRequiredBalance = null;
final String enforceMinRequiredBalance = "false";
final boolean allowOverdraft = false;
final String percentage = "10";
final Integer taxGroupId = createTaxGroup(percentage);
final Integer savingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE,
minBalanceForInterestCalculation, minRequiredBalance, enforceMinRequiredBalance, allowOverdraft, String.valueOf(taxGroupId), true);
Assert.assertNotNull(savingsProductID);
final Integer savingsChargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec,
ChargesHelper.getSavingsNoActivityFeeJSON());
Assert.assertNotNull(savingsChargeId);
ArrayList<Integer> savingsList = new ArrayList<>();
for(int i=0; i< 5; i++){
final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(clientID, savingsProductID, ACCOUNT_TYPE_INDIVIDUAL);
Assert.assertNotNull(savingsProductID);
HashMap modifications = this.savingsAccountHelper.updateSavingsAccount(clientID, savingsProductID, savingsId,
ACCOUNT_TYPE_INDIVIDUAL);
Assert.assertTrue(modifications.containsKey("submittedOnDate"));
this.savingsAccountHelper.addChargesForSavings(savingsId, savingsChargeId);
HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsId);
SavingsStatusChecker.verifySavingsIsPending(savingsStatusHashMap);
savingsStatusHashMap = this.savingsAccountHelper.approveSavings(savingsId);
SavingsStatusChecker.verifySavingsIsApproved(savingsStatusHashMap);
savingsStatusHashMap = this.savingsAccountHelper.activateSavings(savingsId);
SavingsStatusChecker.verifySavingsIsActive(savingsStatusHashMap);
savingsList.add(savingsId);
}
final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(clientID, savingsProductID, ACCOUNT_TYPE_INDIVIDUAL);
Assert.assertNotNull(savingsProductID);
HashMap modifications = this.savingsAccountHelper.updateSavingsAccount(clientID, savingsProductID, savingsId,
ACCOUNT_TYPE_INDIVIDUAL);
Assert.assertTrue(modifications.containsKey("submittedOnDate"));
HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsId);
SavingsStatusChecker.verifySavingsIsPending(savingsStatusHashMap);
savingsList.add(savingsId);
final DateTimeFormatter formatter = DateTimeFormat.forPattern("dd MMMM yyyy");
LocalDate transactionDate = new LocalDate();
for(int i=0; i< 4; i++){
String TRANSACTION_DATE = formatter.print(transactionDate);
Integer depositTransactionId = (Integer) this.savingsAccountHelper.depositToSavingsAccount(savingsList.get(i), DEPOSIT_AMOUNT,
TRANSACTION_DATE, CommonConstants.RESPONSE_RESOURCE_ID);
transactionDate = transactionDate.minusDays(30);
}
SchedulerJobHelper jobHelper = new SchedulerJobHelper(this.requestSpec, this.responseSpec);
try {
jobHelper.executeJob("Update Savings Dormant Accounts");
} catch (InterruptedException e) {
e.printStackTrace();
}
//VERIFY WITHIN PROVIDED RANGE DOESN'T INACTIVATE
savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsList.get(0));
SavingsStatusChecker.verifySavingsIsActive(savingsStatusHashMap);
savingsStatusHashMap = SavingsStatusChecker.getSubStatusOfSavings(this.requestSpec, this.responseSpec, savingsList.get(0));
SavingsStatusChecker.verifySavingsSubStatusNone(savingsStatusHashMap);
HashMap summary = this.savingsAccountHelper.getSavingsSummary(savingsList.get(0));
Float balance = 3000f;
Float chargeAmt = 0f;
balance -= chargeAmt;
assertEquals("Verifying account Balance", balance, summary.get("accountBalance"));
//VERIFY INACTIVE
savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsList.get(1));
SavingsStatusChecker.verifySavingsIsActive(savingsStatusHashMap);
savingsStatusHashMap = SavingsStatusChecker.getSubStatusOfSavings(this.requestSpec, this.responseSpec, savingsList.get(1));
SavingsStatusChecker.verifySavingsSubStatusInactive(savingsStatusHashMap);
summary = this.savingsAccountHelper.getSavingsSummary(savingsList.get(1));
balance = 3000f;
chargeAmt = 100f;
balance -= chargeAmt;
assertEquals("Verifying account Balance", balance, summary.get("accountBalance"));
String TRANSACTION_DATE = formatter.print(new LocalDate());
Integer depositTransactionId = (Integer) this.savingsAccountHelper.depositToSavingsAccount(savingsList.get(1), DEPOSIT_AMOUNT,
TRANSACTION_DATE, CommonConstants.RESPONSE_RESOURCE_ID);
savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsList.get(1));
SavingsStatusChecker.verifySavingsIsActive(savingsStatusHashMap);
savingsStatusHashMap = SavingsStatusChecker.getSubStatusOfSavings(this.requestSpec, this.responseSpec, savingsList.get(1));
SavingsStatusChecker.verifySavingsSubStatusNone(savingsStatusHashMap);
//VERIFY DORMANT
savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsList.get(2));
SavingsStatusChecker.verifySavingsIsActive(savingsStatusHashMap);
savingsStatusHashMap = SavingsStatusChecker.getSubStatusOfSavings(this.requestSpec, this.responseSpec, savingsList.get(2));
SavingsStatusChecker.verifySavingsSubStatusDormant(savingsStatusHashMap);
summary = this.savingsAccountHelper.getSavingsSummary(savingsList.get(2));
balance = 3000f;
chargeAmt = 100f;
balance -= chargeAmt;
assertEquals("Verifying account Balance", balance, summary.get("accountBalance"));
TRANSACTION_DATE = formatter.print(new LocalDate());
depositTransactionId = (Integer) this.savingsAccountHelper.depositToSavingsAccount(savingsList.get(2), DEPOSIT_AMOUNT,
TRANSACTION_DATE, CommonConstants.RESPONSE_RESOURCE_ID);
savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsList.get(2));
SavingsStatusChecker.verifySavingsIsActive(savingsStatusHashMap);
savingsStatusHashMap = SavingsStatusChecker.getSubStatusOfSavings(this.requestSpec, this.responseSpec, savingsList.get(2));
SavingsStatusChecker.verifySavingsSubStatusNone(savingsStatusHashMap);
//VERIFY ESCHEAT DUE TO OLD TRANSACTION
savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsList.get(3));
SavingsStatusChecker.verifySavingsAccountIsClosed(savingsStatusHashMap);
savingsStatusHashMap = SavingsStatusChecker.getSubStatusOfSavings(this.requestSpec, this.responseSpec, savingsList.get(3));
SavingsStatusChecker.verifySavingsSubStatusEscheat(savingsStatusHashMap);
summary = this.savingsAccountHelper.getSavingsSummary(savingsList.get(3));
assertEquals("Verifying account Balance", 2900f, summary.get("accountBalance"));
//VERIFY ESCHEAT DUE NO TRANSACTION FROM ACTIVATION
savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsList.get(4));
SavingsStatusChecker.verifySavingsAccountIsClosed(savingsStatusHashMap);
savingsStatusHashMap = SavingsStatusChecker.getSubStatusOfSavings(this.requestSpec, this.responseSpec, savingsList.get(4));
SavingsStatusChecker.verifySavingsSubStatusEscheat(savingsStatusHashMap);
summary = this.savingsAccountHelper.getSavingsSummary(savingsList.get(4));
assertEquals("Verifying account Balance", 900f, summary.get("accountBalance"));
//VERIFY NON ACTIVE ACCOUNTS ARE NOT AFFECTED
savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsList.get(5));
SavingsStatusChecker.verifySavingsIsPending(savingsStatusHashMap);
savingsStatusHashMap = SavingsStatusChecker.getSubStatusOfSavings(this.requestSpec, this.responseSpec, savingsList.get(5));
SavingsStatusChecker.verifySavingsSubStatusNone(savingsStatusHashMap);
}
private HashMap activateSavingsAccount(final Integer savingsId, final String activationDate) { private HashMap activateSavingsAccount(final Integer savingsId, final String activationDate) {
@@ -902,18 +1051,21 @@ public class ClientSavingsIntegrationTest {
String enforceMinRequiredBalance, final boolean allowOverdraft) { String enforceMinRequiredBalance, final boolean allowOverdraft) {
final String taxGroupId = null; final String taxGroupId = null;
return createSavingsProduct(requestSpec, responseSpec, minOpenningBalance, minBalanceForInterestCalculation, minRequiredBalance, return createSavingsProduct(requestSpec, responseSpec, minOpenningBalance, minBalanceForInterestCalculation, minRequiredBalance,
enforceMinRequiredBalance, allowOverdraft, taxGroupId); enforceMinRequiredBalance, allowOverdraft, taxGroupId, false);
} }
private Integer createSavingsProduct(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, private Integer createSavingsProduct(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
final String minOpenningBalance, String minBalanceForInterestCalculation, String minRequiredBalance, final String minOpenningBalance, String minBalanceForInterestCalculation, String minRequiredBalance,
String enforceMinRequiredBalance, final boolean allowOverdraft, final String taxGroupId) { String enforceMinRequiredBalance, final boolean allowOverdraft, final String taxGroupId, boolean withDormancy) {
System.out.println("------------------------------CREATING NEW SAVINGS PRODUCT ---------------------------------------"); System.out.println("------------------------------CREATING NEW SAVINGS PRODUCT ---------------------------------------");
SavingsProductHelper savingsProductHelper = new SavingsProductHelper(); SavingsProductHelper savingsProductHelper = new SavingsProductHelper();
if (allowOverdraft) { if (allowOverdraft) {
final String overDraftLimit = "2000.0"; final String overDraftLimit = "2000.0";
savingsProductHelper = savingsProductHelper.withOverDraft(overDraftLimit); savingsProductHelper = savingsProductHelper.withOverDraft(overDraftLimit);
} }
if(withDormancy){
savingsProductHelper = savingsProductHelper.withDormancy();
}
final String savingsProductJSON = savingsProductHelper final String savingsProductJSON = savingsProductHelper
// //
@@ -48,6 +48,7 @@ public class ChargesHelper {
private static final Integer CHARGE_OVERDUE_INSTALLMENT_FEE = 9; private static final Integer CHARGE_OVERDUE_INSTALLMENT_FEE = 9;
private static final Integer CHARGE_OVERDRAFT_FEE = 10; private static final Integer CHARGE_OVERDRAFT_FEE = 10;
private static final Integer WEEKLY_FEE = 11; private static final Integer WEEKLY_FEE = 11;
private static final Integer CHARGE_SAVINGS_NO_ACTIVITY_FEE = 16;
private static final Integer CHARGE_CLIENT_SPECIFIED_DUE_DATE = 1; private static final Integer CHARGE_CLIENT_SPECIFIED_DUE_DATE = 1;
@@ -88,6 +89,14 @@ public class ChargesHelper {
return chargesCreateJson; return chargesCreateJson;
} }
public static String getSavingsNoActivityFeeJSON() {
final HashMap<String, Object> map = populateDefaultsForSavings();
map.put("chargeTimeType", CHARGE_SAVINGS_NO_ACTIVITY_FEE);
String chargesCreateJson = new Gson().toJson(map);
System.out.println(chargesCreateJson);
return chargesCreateJson;
}
public static String getSavingsWithdrawalFeeJSON() { public static String getSavingsWithdrawalFeeJSON() {
final HashMap<String, Object> map = populateDefaultsForSavings(); final HashMap<String, Object> map = populateDefaultsForSavings();
map.put("chargeTimeType", CHARGE_WITHDRAWAL_FEE); map.put("chargeTimeType", CHARGE_WITHDRAWAL_FEE);
@@ -27,6 +27,8 @@ public class SavingsApplicationTestBuilder {
private static final String LOCALE = "en_GB"; private static final String LOCALE = "en_GB";
private String submittedOnDate = ""; private String submittedOnDate = "";
private HashMap<String, String> addParams = null;
public String build(final String ID, final String savingsProductId, final String accountType) { public String build(final String ID, final String savingsProductId, final String accountType) {
@@ -40,6 +42,9 @@ public class SavingsApplicationTestBuilder {
map.put("productId", savingsProductId); map.put("productId", savingsProductId);
map.put("locale", LOCALE); map.put("locale", LOCALE);
map.put("submittedOnDate", this.submittedOnDate); map.put("submittedOnDate", this.submittedOnDate);
if(addParams!=null && addParams.size() > 0){
map.putAll(addParams);
}
String savingsApplicationJSON = new Gson().toJson(map); String savingsApplicationJSON = new Gson().toJson(map);
System.out.println(savingsApplicationJSON); System.out.println(savingsApplicationJSON);
return savingsApplicationJSON; return savingsApplicationJSON;
@@ -49,4 +54,10 @@ public class SavingsApplicationTestBuilder {
this.submittedOnDate = savingsApplicationSubmittedDate; this.submittedOnDate = savingsApplicationSubmittedDate;
return this; return this;
} }
public SavingsApplicationTestBuilder withParams(
HashMap<String, String> params) {
this.addParams = params;
return this;
}
} }
@@ -88,6 +88,10 @@ public class SavingsProductHelper {
private String enforceMinRequiredBalance = "false"; private String enforceMinRequiredBalance = "false";
private Boolean withHoldTax = false; private Boolean withHoldTax = false;
private String taxGroupId = null; private String taxGroupId = null;
private boolean isDormancyTrackingActive = false;
private String daysToInactive = null;
private String daysToDormancy = null;
private String daysToEscheat = null;
public String build() { public String build() {
final HashMap<String, String> map = new HashMap<>(); final HashMap<String, String> map = new HashMap<>();
@@ -130,6 +134,13 @@ public class SavingsProductHelper {
if (this.accountingRule.equals(CASH_BASED)) { if (this.accountingRule.equals(CASH_BASED)) {
map.putAll(getAccountMappingForCashBased()); map.putAll(getAccountMappingForCashBased());
} }
if(this.isDormancyTrackingActive){
map.put("isDormancyTrackingActive", Boolean.toString(this.isDormancyTrackingActive));
map.put("daysToInactive", this.daysToInactive);
map.put("daysToDormancy", this.daysToDormancy);
map.put("daysToEscheat", this.daysToEscheat);
}
String savingsProductCreateJson = new Gson().toJson(map); String savingsProductCreateJson = new Gson().toJson(map);
System.out.println(savingsProductCreateJson); System.out.println(savingsProductCreateJson);
return savingsProductCreateJson; return savingsProductCreateJson;
@@ -263,4 +274,13 @@ public class SavingsProductHelper {
assertEquals("ERROR IN CREATING THE Savings Product", generatedProductID, responseSavingsProductID); assertEquals("ERROR IN CREATING THE Savings Product", generatedProductID, responseSavingsProductID);
} }
public SavingsProductHelper withDormancy() {
this.isDormancyTrackingActive = true;
this.daysToInactive = "30";
this.daysToDormancy = "60";
this.daysToEscheat = "90";
return this;
}
} }
@@ -80,7 +80,38 @@ public class SavingsStatusChecker {
return Utils.performServerGet(requestSpec, responseSpec, url, "status"); return Utils.performServerGet(requestSpec, responseSpec, url, "status");
} }
private static boolean getStatus(final HashMap savingsStatusMap, final String nameOfSavingsStatusString) { public static HashMap getSubStatusOfSavings(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
final Integer savingsID) {
final String url = SAVINGS_ACCOUNT_URL+"/" + savingsID + "?"+Utils.TENANT_IDENTIFIER;
return Utils.performServerGet(requestSpec, responseSpec, url, "subStatus");
}
private static boolean getStatus(final HashMap savingsStatusMap, final String nameOfSavingsStatusString) {
return (Boolean) savingsStatusMap.get(nameOfSavingsStatusString); return (Boolean) savingsStatusMap.get(nameOfSavingsStatusString);
} }
public static void verifySavingsSubStatusInactive(HashMap savingsStatusHashMap) {
System.out.println("\n-------------------------------------- VERIFYING SAVINGS APPLICATION IS ACTIVE ------------------------------------");
assertTrue("UNEXPECTED SAVINGS ACCOUNT SUB STATUS", getStatus(savingsStatusHashMap, "inactive"));
System.out.println("Savings Application Sub Status:" + savingsStatusHashMap + "\n");
}
public static void verifySavingsSubStatusDormant(HashMap savingsStatusHashMap) {
System.out.println("\n-------------------------------------- VERIFYING SAVINGS APPLICATION IS ACTIVE ------------------------------------");
assertTrue("UNEXPECTED SAVINGS ACCOUNT SUB STATUS", getStatus(savingsStatusHashMap, "dormant"));
System.out.println("Savings Application Sub Status:" + savingsStatusHashMap + "\n");
}
public static void verifySavingsSubStatusEscheat(HashMap savingsStatusHashMap) {
System.out.println("\n-------------------------------------- VERIFYING SAVINGS APPLICATION IS ACTIVE ------------------------------------");
assertTrue("UNEXPECTED SAVINGS ACCOUNT SUB STATUS", getStatus(savingsStatusHashMap, "escheat"));
System.out.println("Savings Application Sub Status:" + savingsStatusHashMap + "\n");
}
public static void verifySavingsSubStatusNone(HashMap savingsStatusHashMap) {
System.out.println("\n-------------------------------------- VERIFYING SAVINGS APPLICATION IS ACTIVE ------------------------------------");
assertTrue("UNEXPECTED SAVINGS ACCOUNT SUB STATUS", getStatus(savingsStatusHashMap, "none"));
System.out.println("Savings Application Sub Status:" + savingsStatusHashMap + "\n");
}
} }