reset/verify all default global configurations in some integration tests (PR #671 for FINERACT-722)

Remove necessary resetting of 2 select default global configurations in FlexibleSavingsInterestPostingIntegrationTest.

Fixes issue where global configurations were affecting state between integration tests. This caused LoanReschedulingWithinCenterTest to fail on the first day of the month only because the "skip-repayment-on-first-day-of-month" configuration was modified but never reset by GlobalConfigurationTest.

Also updated other integration tests to reset and verify default global configurations.

FINERACT-722
This commit is contained in:
Michael Vorburger ⛑️
2019-12-12 09:21:45 +01:00
committed by GitHub
parent 0474f59bcf
commit cc181b5742
7 changed files with 312 additions and 2 deletions
@@ -148,7 +148,8 @@ public class FlexibleSavingsInterestPostingIntegrationTest {
// Reset configuration fields
@After
public void tearDown() {
configureInterestPosting(false, 1);
GlobalConfigurationHelper.resetAllDefaultGlobalConfigurations(this.requestSpec, this.responseSpec);
GlobalConfigurationHelper.verifyAllDefaultGlobalConfigurations(this.requestSpec, this.responseSpec);
}
}
@@ -23,6 +23,7 @@ import java.util.HashMap;
import org.apache.fineract.integrationtests.common.GlobalConfigurationHelper;
import org.apache.fineract.integrationtests.common.Utils;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -47,6 +48,12 @@ public class GlobalConfigInterestChargedFromDateSameAsDisbursalDateTest {
this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
}
@After
public void tearDown() {
GlobalConfigurationHelper.resetAllDefaultGlobalConfigurations(this.requestSpec, this.responseSpec);
GlobalConfigurationHelper.verifyAllDefaultGlobalConfigurations(this.requestSpec, this.responseSpec);
}
@SuppressWarnings( {"static-access", "rawtypes", "unchecked"})
@Test
@@ -24,6 +24,7 @@ import java.util.HashMap;
import org.apache.fineract.integrationtests.common.CommonConstants;
import org.apache.fineract.integrationtests.common.GlobalConfigurationHelper;
import org.apache.fineract.integrationtests.common.Utils;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -51,6 +52,12 @@ public class GlobalConfigurationTest {
this.httpStatusForidden = new ResponseSpecBuilder().expectStatusCode(403).build();
}
@After
public void tearDown() {
GlobalConfigurationHelper.resetAllDefaultGlobalConfigurations(this.requestSpec, this.responseSpec);
GlobalConfigurationHelper.verifyAllDefaultGlobalConfigurations(this.requestSpec, this.responseSpec);
}
@Test
public void testGlobalConfigurations() {
this.globalConfigurationHelper = new GlobalConfigurationHelper(this.requestSpec, this.responseSpec);
@@ -37,6 +37,7 @@ import org.apache.fineract.integrationtests.common.CalendarHelper;
import org.apache.fineract.integrationtests.common.CenterDomain;
import org.apache.fineract.integrationtests.common.CenterHelper;
import org.apache.fineract.integrationtests.common.ClientHelper;
import org.apache.fineract.integrationtests.common.GlobalConfigurationHelper;
import org.apache.fineract.integrationtests.common.GroupHelper;
import org.apache.fineract.integrationtests.common.OfficeHelper;
import org.apache.fineract.integrationtests.common.Utils;
@@ -71,6 +72,8 @@ public class LoanReschedulingWithinCenterTest {
this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
this.loanApplicationApprovalTest = new LoanApplicationApprovalTest();
this.generalResponseSpec = new ResponseSpecBuilder().build();
GlobalConfigurationHelper.verifyAllDefaultGlobalConfigurations(this.requestSpec, this.responseSpec);
}
@SuppressWarnings("rawtypes")
@@ -55,6 +55,7 @@ import org.apache.fineract.integrationtests.common.savings.SavingsProductHelper;
import org.apache.fineract.integrationtests.common.savings.SavingsStatusChecker;
import org.apache.fineract.portfolio.account.PortfolioAccountType;
import org.apache.fineract.portfolio.account.domain.AccountTransferType;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
@@ -105,6 +106,12 @@ public class SchedulerJobsTestResults {
this.journalEntryHelper = new JournalEntryHelper(this.requestSpec, this.responseSpec);
}
@After
public void tearDown() {
GlobalConfigurationHelper.resetAllDefaultGlobalConfigurations(this.requestSpec, this.responseSpec);
GlobalConfigurationHelper.verifyAllDefaultGlobalConfigurations(this.requestSpec, this.responseSpec);
}
@Test
public void testApplyAnnualFeeForSavingsJobOutcome() throws InterruptedException {
this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec);
@@ -32,6 +32,7 @@ import org.apache.fineract.integrationtests.common.Utils;
import org.apache.fineract.integrationtests.common.loans.LoanApplicationTestBuilder;
import org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder;
import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -61,6 +62,12 @@ public class SkipRepaymentOnMonthFirstTest {
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
}
@After
public void tearDown() {
GlobalConfigurationHelper.resetAllDefaultGlobalConfigurations(this.requestSpec, this.responseSpec);
GlobalConfigurationHelper.verifyAllDefaultGlobalConfigurations(this.requestSpec, this.responseSpec);
}
@Test
public void testSkippingRepaymentOnFirstDayOfMonth() {
this.globalConfigurationHelper = new GlobalConfigurationHelper(this.requestSpec, this.responseSpec);
@@ -26,6 +26,7 @@ import java.util.Random;
import com.google.gson.Gson;
import com.jayway.restassured.specification.RequestSpecification;
import com.jayway.restassured.specification.ResponseSpecification;
import org.junit.Assert;
@SuppressWarnings({ "unused", "rawtypes" })
public class GlobalConfigurationHelper {
@@ -38,7 +39,7 @@ public class GlobalConfigurationHelper {
this.responseSpec = responseSpec;
}
public static ArrayList getAllGlobalConfigurations(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
public static ArrayList<HashMap> getAllGlobalConfigurations(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
final String GET_ALL_GLOBAL_CONFIG_URL = "/fineract-provider/api/v1/configurations?" + Utils.TENANT_IDENTIFIER;
System.out.println("------------------------ RETRIEVING ALL GLOBAL CONFIGURATIONS -------------------------");
final HashMap response = Utils.performServerGet(requestSpec, responseSpec, GET_ALL_GLOBAL_CONFIG_URL, "");
@@ -52,6 +53,283 @@ public class GlobalConfigurationHelper {
return Utils.performServerGet(requestSpec, responseSpec, GET_GLOBAL_CONFIG_BY_ID_URL, "");
}
public static void resetAllDefaultGlobalConfigurations(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
final ArrayList<HashMap> defaults = getAllDefaultGlobalConfigurations();
for (HashMap configDefault : defaults) {
/**
* Cannot update trapDoor global configurations because
* {@link org.apache.fineract.infrastructure.configuration.exception.GlobalConfigurationPropertyCannotBeModfied}
* will be thrown.
*/
if ((Boolean)configDefault.get("trapDoor")) {
continue;
}
// Currently only values and enabled flags are modified by the integration test suite.
// If any other column is modified by the integration test suite in the future, it needs to be reset here.
final Integer configDefaultId = (Integer)configDefault.get("id");
final Integer configDefaultValue = (Integer)configDefault.get("value");
updateValueForGlobalConfiguration(requestSpec, responseSpec, configDefaultId.toString(), configDefaultValue.toString());
updateEnabledFlagForGlobalConfiguration(requestSpec, responseSpec, configDefaultId.toString(), (Boolean)configDefault.get("enabled"));
}
}
public static void verifyAllDefaultGlobalConfigurations(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
ArrayList<HashMap> expectedGlobalConfigurations = getAllDefaultGlobalConfigurations();
ArrayList<HashMap> actualGlobalConfigurations = getAllGlobalConfigurations(requestSpec, responseSpec);
// There are currently 27 global configurations.
Assert.assertEquals(27, expectedGlobalConfigurations.size());
Assert.assertEquals(27, actualGlobalConfigurations.size());
for (int i = 0; i < expectedGlobalConfigurations.size(); i++) {
HashMap expectedGlobalConfiguration = expectedGlobalConfigurations.get(i);
HashMap actualGlobalConfiguration = actualGlobalConfigurations.get(i);
Assert.assertEquals(expectedGlobalConfiguration.get("id"), actualGlobalConfiguration.get("id"));
final String assertionFailedMessage = "Assertion failed for configID:<" + expectedGlobalConfiguration.get("id") + ">";
Assert.assertEquals(assertionFailedMessage, expectedGlobalConfiguration.get("name"), actualGlobalConfiguration.get("name"));
Assert.assertEquals(assertionFailedMessage, expectedGlobalConfiguration.get("value"), actualGlobalConfiguration.get("value"));
Assert.assertEquals(assertionFailedMessage, expectedGlobalConfiguration.get("enabled"), actualGlobalConfiguration.get("enabled"));
Assert.assertEquals(assertionFailedMessage, expectedGlobalConfiguration.get("trapDoor"), actualGlobalConfiguration.get("trapDoor"));
}
}
/**
* Helper method to get the current default instance data of the /configurations endpoint.
* Used to reset and verify that no global configuration affects state between integration tests.
* @see <a href="https://issues.apache.org/jira/browse/FINERACT-722">FINERACT-722</a>
* This is a quick, fail fast and early implementation to resolve this issue.
* TODO: A more robust future solution would be isolating all integration test state using Spring Framework's
* integration test infrastructure for transaction commits and rollbacks.
*/
private static ArrayList<HashMap> getAllDefaultGlobalConfigurations() {
ArrayList<HashMap> defaults = new ArrayList<>();
HashMap<String, Object> makerCheckerDefault = new HashMap<>();
makerCheckerDefault.put("id", 1);
makerCheckerDefault.put("name", "maker-checker");
makerCheckerDefault.put("value", 0);
makerCheckerDefault.put("enabled", false);
makerCheckerDefault.put("trapDoor", false);
defaults.add(makerCheckerDefault);
HashMap<String, Object> amazonS3Default = new HashMap<>();
amazonS3Default.put("id", 4);
amazonS3Default.put("name", "amazon-S3");
amazonS3Default.put("value", 0);
amazonS3Default.put("enabled", false);
amazonS3Default.put("trapDoor", false);
defaults.add(amazonS3Default);
HashMap<String, Object> rescheduleFuturePaymentsDefault = new HashMap<>();
rescheduleFuturePaymentsDefault.put("id", 5);
rescheduleFuturePaymentsDefault.put("name", "reschedule-future-repayments");
rescheduleFuturePaymentsDefault.put("value", 0);
rescheduleFuturePaymentsDefault.put("enabled", true);
rescheduleFuturePaymentsDefault.put("trapDoor", false);
defaults.add(rescheduleFuturePaymentsDefault);
HashMap<String, Object> rescheduleRepaymentsOnHolidaysDefault = new HashMap<>();
rescheduleRepaymentsOnHolidaysDefault.put("id", 6);
rescheduleRepaymentsOnHolidaysDefault.put("name", "reschedule-repayments-on-holidays");
rescheduleRepaymentsOnHolidaysDefault.put("value", 0);
rescheduleRepaymentsOnHolidaysDefault.put("enabled", false);
rescheduleRepaymentsOnHolidaysDefault.put("trapDoor", false);
defaults.add(rescheduleRepaymentsOnHolidaysDefault);
HashMap<String, Object> allowTransactionsOnHolidayDefault = new HashMap<>();
allowTransactionsOnHolidayDefault.put("id", 7);
allowTransactionsOnHolidayDefault.put("name", "allow-transactions-on-holiday");
allowTransactionsOnHolidayDefault.put("value", 0);
allowTransactionsOnHolidayDefault.put("enabled", false);
allowTransactionsOnHolidayDefault.put("trapDoor", false);
defaults.add(allowTransactionsOnHolidayDefault);
HashMap<String, Object> allowTransactionsOnNonWorkingDayDefault = new HashMap<>();
allowTransactionsOnNonWorkingDayDefault.put("id", 8);
allowTransactionsOnNonWorkingDayDefault.put("name", "allow-transactions-on-non_workingday");
allowTransactionsOnNonWorkingDayDefault.put("value", 0);
allowTransactionsOnNonWorkingDayDefault.put("enabled", false);
allowTransactionsOnNonWorkingDayDefault.put("trapDoor", false);
defaults.add(allowTransactionsOnNonWorkingDayDefault);
HashMap<String, Object> constraintApproachForDataTablesDefault = new HashMap<>();
constraintApproachForDataTablesDefault.put("id", 9);
constraintApproachForDataTablesDefault.put("name", "constraint_approach_for_datatables");
constraintApproachForDataTablesDefault.put("value", 0);
constraintApproachForDataTablesDefault.put("enabled", false);
constraintApproachForDataTablesDefault.put("trapDoor", false);
defaults.add(constraintApproachForDataTablesDefault);
HashMap<String, Object> penaltyWaitPeriodDefault = new HashMap<>();
penaltyWaitPeriodDefault.put("id", 10);
penaltyWaitPeriodDefault.put("name", "penalty-wait-period");
penaltyWaitPeriodDefault.put("value", 2);
penaltyWaitPeriodDefault.put("enabled", true);
penaltyWaitPeriodDefault.put("trapDoor", false);
defaults.add(penaltyWaitPeriodDefault);
HashMap<String, Object> forcePasswordResetDaysDefault = new HashMap<>();
forcePasswordResetDaysDefault.put("id", 11);
forcePasswordResetDaysDefault.put("name", "force-password-reset-days");
forcePasswordResetDaysDefault.put("value", 0);
forcePasswordResetDaysDefault.put("enabled", false);
forcePasswordResetDaysDefault.put("trapDoor", false);
defaults.add(forcePasswordResetDaysDefault);
HashMap<String, Object> graceOnPenaltyPostingDefault = new HashMap<>();
graceOnPenaltyPostingDefault.put("id", 12);
graceOnPenaltyPostingDefault.put("name", "grace-on-penalty-posting");
graceOnPenaltyPostingDefault.put("value", 0);
graceOnPenaltyPostingDefault.put("enabled", true);
graceOnPenaltyPostingDefault.put("trapDoor", false);
defaults.add(graceOnPenaltyPostingDefault);
HashMap<String, Object> savingsInterestPostingCurrentPeriodEndDefault = new HashMap<>();
savingsInterestPostingCurrentPeriodEndDefault.put("id", 15);
savingsInterestPostingCurrentPeriodEndDefault.put("name", "savings-interest-posting-current-period-end");
savingsInterestPostingCurrentPeriodEndDefault.put("value", 0);
savingsInterestPostingCurrentPeriodEndDefault.put("enabled", false);
savingsInterestPostingCurrentPeriodEndDefault.put("trapDoor", false);
defaults.add(savingsInterestPostingCurrentPeriodEndDefault);
HashMap<String, Object> financialYearBeginningMonthDefault = new HashMap<>();
financialYearBeginningMonthDefault.put("id", 16);
financialYearBeginningMonthDefault.put("name", "financial-year-beginning-month");
financialYearBeginningMonthDefault.put("value", 1);
financialYearBeginningMonthDefault.put("enabled", true);
financialYearBeginningMonthDefault.put("trapDoor", false);
defaults.add(financialYearBeginningMonthDefault);
HashMap<String, Object> minClientsInGroupDefault = new HashMap<>();
minClientsInGroupDefault.put("id", 17);
minClientsInGroupDefault.put("name", "min-clients-in-group");
minClientsInGroupDefault.put("value", 5);
minClientsInGroupDefault.put("enabled", false);
minClientsInGroupDefault.put("trapDoor", false);
defaults.add(minClientsInGroupDefault);
HashMap<String, Object> maxClientsInGroupDefault = new HashMap<>();
maxClientsInGroupDefault.put("id", 18);
maxClientsInGroupDefault.put("name", "max-clients-in-group");
maxClientsInGroupDefault.put("value", 5);
maxClientsInGroupDefault.put("enabled", false);
maxClientsInGroupDefault.put("trapDoor", false);
defaults.add(maxClientsInGroupDefault);
HashMap<String, Object> meetingsMandatoryForJlgLoansDefault = new HashMap<>();
meetingsMandatoryForJlgLoansDefault.put("id", 19);
meetingsMandatoryForJlgLoansDefault.put("name", "meetings-mandatory-for-jlg-loans");
meetingsMandatoryForJlgLoansDefault.put("value", 0);
meetingsMandatoryForJlgLoansDefault.put("enabled", false);
meetingsMandatoryForJlgLoansDefault.put("trapDoor", false);
defaults.add(meetingsMandatoryForJlgLoansDefault);
HashMap<String, Object> officeSpecificProductsEnabledDefault = new HashMap<>();
officeSpecificProductsEnabledDefault.put("id", 20);
officeSpecificProductsEnabledDefault.put("name", "office-specific-products-enabled");
officeSpecificProductsEnabledDefault.put("value", 0);
officeSpecificProductsEnabledDefault.put("enabled", false);
officeSpecificProductsEnabledDefault.put("trapDoor", false);
defaults.add(officeSpecificProductsEnabledDefault);
HashMap<String, Object> restrictProductsToUserOfficeDefault = new HashMap<>();
restrictProductsToUserOfficeDefault.put("id", 21);
restrictProductsToUserOfficeDefault.put("name", "restrict-products-to-user-office");
restrictProductsToUserOfficeDefault.put("value", 0);
restrictProductsToUserOfficeDefault.put("enabled", false);
restrictProductsToUserOfficeDefault.put("trapDoor", false);
defaults.add(restrictProductsToUserOfficeDefault);
HashMap<String, Object> officeOpeningBalancesContraAccountDefault = new HashMap<>();
officeOpeningBalancesContraAccountDefault.put("id", 22);
officeOpeningBalancesContraAccountDefault.put("name", "office-opening-balances-contra-account");
officeOpeningBalancesContraAccountDefault.put("value", 0);
officeOpeningBalancesContraAccountDefault.put("enabled", true);
officeOpeningBalancesContraAccountDefault.put("trapDoor", false);
defaults.add(officeOpeningBalancesContraAccountDefault);
HashMap<String, Object> roundingModeDefault = new HashMap<>();
roundingModeDefault.put("id", 23);
roundingModeDefault.put("name", "rounding-mode");
roundingModeDefault.put("value", 6);
roundingModeDefault.put("enabled", true);
roundingModeDefault.put("trapDoor", true);
defaults.add(roundingModeDefault);
HashMap<String, Object> backDatePenaltiesEnabledDefault = new HashMap<>();
backDatePenaltiesEnabledDefault.put("id", 24);
backDatePenaltiesEnabledDefault.put("name", "backdate-penalties-enabled");
backDatePenaltiesEnabledDefault.put("value", 0);
backDatePenaltiesEnabledDefault.put("enabled", true);
backDatePenaltiesEnabledDefault.put("trapDoor", false);
defaults.add(backDatePenaltiesEnabledDefault);
HashMap<String, Object> organisationStartDateDefault = new HashMap<>();
organisationStartDateDefault.put("id", 25);
organisationStartDateDefault.put("name", "organisation-start-date");
organisationStartDateDefault.put("value", 0);
organisationStartDateDefault.put("enabled", false);
organisationStartDateDefault.put("trapDoor", false);
defaults.add(organisationStartDateDefault);
HashMap<String, Object> paymentTypeApplicableForDisbursementChargesDefault = new HashMap<>();
paymentTypeApplicableForDisbursementChargesDefault.put("id", 26);
paymentTypeApplicableForDisbursementChargesDefault.put("name", "paymenttype-applicable-for-disbursement-charges");
paymentTypeApplicableForDisbursementChargesDefault.put("value", 0);
paymentTypeApplicableForDisbursementChargesDefault.put("enabled", false);
paymentTypeApplicableForDisbursementChargesDefault.put("trapDoor", false);
defaults.add(paymentTypeApplicableForDisbursementChargesDefault);
HashMap<String, Object> interestChargedFromDateSameAsDisbursalDateDefault = new HashMap<>();
interestChargedFromDateSameAsDisbursalDateDefault.put("id", 27);
interestChargedFromDateSameAsDisbursalDateDefault.put("name", "interest-charged-from-date-same-as-disbursal-date");
interestChargedFromDateSameAsDisbursalDateDefault.put("value", 0);
interestChargedFromDateSameAsDisbursalDateDefault.put("enabled", false);
interestChargedFromDateSameAsDisbursalDateDefault.put("trapDoor", false);
defaults.add(interestChargedFromDateSameAsDisbursalDateDefault);
HashMap<String, Object> skipRepaymentOnFirstDayOfMonthDefault = new HashMap<>();
skipRepaymentOnFirstDayOfMonthDefault.put("id", 28);
skipRepaymentOnFirstDayOfMonthDefault.put("name", "skip-repayment-on-first-day-of-month");
skipRepaymentOnFirstDayOfMonthDefault.put("value", 14);
skipRepaymentOnFirstDayOfMonthDefault.put("enabled", false);
skipRepaymentOnFirstDayOfMonthDefault.put("trapDoor", false);
defaults.add(skipRepaymentOnFirstDayOfMonthDefault);
HashMap<String, Object> changeEmiIfRepaymentDateSameAsDisbursementDateDefault = new HashMap<>();
changeEmiIfRepaymentDateSameAsDisbursementDateDefault.put("id", 29);
changeEmiIfRepaymentDateSameAsDisbursementDateDefault.put("name", "change-emi-if-repaymentdate-same-as-disbursementdate");
changeEmiIfRepaymentDateSameAsDisbursementDateDefault.put("value", 0);
changeEmiIfRepaymentDateSameAsDisbursementDateDefault.put("enabled", true);
changeEmiIfRepaymentDateSameAsDisbursementDateDefault.put("trapDoor", false);
defaults.add(changeEmiIfRepaymentDateSameAsDisbursementDateDefault);
HashMap<String, Object> dailyTptLimitDefault = new HashMap<>();
dailyTptLimitDefault.put("id", 30);
dailyTptLimitDefault.put("name", "daily-tpt-limit");
dailyTptLimitDefault.put("value", 0);
dailyTptLimitDefault.put("enabled", false);
dailyTptLimitDefault.put("trapDoor", false);
defaults.add(dailyTptLimitDefault);
HashMap<String, Object> enableAddressDefault = new HashMap<>();
enableAddressDefault.put("id", 31);
enableAddressDefault.put("name", "Enable-Address");
enableAddressDefault.put("value", 0);
enableAddressDefault.put("enabled", false);
enableAddressDefault.put("trapDoor", false);
defaults.add(enableAddressDefault);
return defaults;
}
public static Integer updateValueForGlobalConfiguration(final RequestSpecification requestSpec,
final ResponseSpecification responseSpec, final String configId, final String value) {
final String GLOBAL_CONFIG_UPDATE_URL = "/fineract-provider/api/v1/configurations/" + configId + "?" + Utils.TENANT_IDENTIFIER;