Unstable integration test due different timezones
This commit is contained in:
committed by
Arnold Gálovics
parent
7e680729fc
commit
55949bf8b0
+24
-31
@@ -33,12 +33,17 @@ import java.text.DecimalFormatSymbols;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalTime;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
import org.apache.fineract.infrastructure.core.service.DateUtils;
|
||||
import org.apache.fineract.integrationtests.common.ClientHelper;
|
||||
import org.apache.fineract.integrationtests.common.CollateralManagementHelper;
|
||||
@@ -66,13 +71,11 @@ import org.apache.fineract.integrationtests.common.savings.SavingsProductHelper;
|
||||
import org.apache.fineract.integrationtests.common.savings.SavingsStatusChecker;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
@Order(2)
|
||||
public class AccountingScenarioIntegrationTest {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(AccountingScenarioIntegrationTest.class);
|
||||
@@ -110,13 +113,13 @@ public class AccountingScenarioIntegrationTest {
|
||||
private AccountHelper accountHelper;
|
||||
private JournalEntryHelper journalEntryHelper;
|
||||
private SavingsAccountHelper savingsAccountHelper;
|
||||
private FixedDepositProductHelper fixedDepositProductHelper;
|
||||
private FixedDepositAccountHelper fixedDepositAccountHelper;
|
||||
private RecurringDepositProductHelper recurringDepositProductHelper;
|
||||
private RecurringDepositAccountHelper recurringDepositAccountHelper;
|
||||
private SchedulerJobHelper schedulerJobHelper;
|
||||
private PeriodicAccrualAccountingHelper periodicAccrualAccountingHelper;
|
||||
|
||||
private TimeZone systemTimeZone;
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
Utils.initializeRESTAssured();
|
||||
@@ -129,6 +132,8 @@ public class AccountingScenarioIntegrationTest {
|
||||
this.journalEntryHelper = new JournalEntryHelper(requestSpec, responseSpec);
|
||||
this.schedulerJobHelper = new SchedulerJobHelper(requestSpec);
|
||||
this.periodicAccrualAccountingHelper = new PeriodicAccrualAccountingHelper(requestSpec, responseSpec);
|
||||
|
||||
this.systemTimeZone = TimeZone.getTimeZone(Utils.TENANT_TIME_ZONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -361,7 +366,6 @@ public class AccountingScenarioIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void testFixedDepositAccountingFlow() {
|
||||
this.fixedDepositProductHelper = new FixedDepositProductHelper(requestSpec, responseSpec);
|
||||
this.accountHelper = new AccountHelper(requestSpec, responseSpec);
|
||||
this.savingsAccountHelper = new SavingsAccountHelper(requestSpec, responseSpec);
|
||||
this.fixedDepositAccountHelper = new FixedDepositAccountHelper(requestSpec, responseSpec);
|
||||
@@ -440,7 +444,6 @@ public class AccountingScenarioIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void testRecurringDepositAccountingFlow() {
|
||||
this.recurringDepositProductHelper = new RecurringDepositProductHelper(requestSpec, responseSpec);
|
||||
this.accountHelper = new AccountHelper(requestSpec, responseSpec);
|
||||
this.recurringDepositAccountHelper = new RecurringDepositAccountHelper(requestSpec, responseSpec);
|
||||
|
||||
@@ -806,20 +809,14 @@ public class AccountingScenarioIntegrationTest {
|
||||
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
|
||||
LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
|
||||
|
||||
DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy", Locale.US);
|
||||
final DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("dd MMMM yyyy", Locale.US);
|
||||
|
||||
Calendar todayDate = Calendar.getInstance();
|
||||
final String currentDate = dateFormat.format(todayDate.getTime());
|
||||
final LocalDate localDate = LocalDate.now(this.systemTimeZone.toZoneId());
|
||||
final ZonedDateTime currentDate = ZonedDateTime.of(localDate, LocalTime.MIDNIGHT, this.systemTimeZone.toZoneId());
|
||||
ZonedDateTime zonedDate = currentDate.minusDays(4);
|
||||
final String LOAN_DISBURSEMENT_DATE = dateFormat.format(zonedDate);
|
||||
|
||||
todayDate.add(Calendar.DATE, -4);
|
||||
|
||||
final String LOAN_DISBURSEMENT_DATE = dateFormat.format(todayDate.getTime());
|
||||
|
||||
todayDate.add(Calendar.MONTH, 2);
|
||||
final String FIRST_REPAYMENT_DATE = dateFormat.format(todayDate.getTime());
|
||||
|
||||
todayDate = Calendar.getInstance();
|
||||
todayDate.add(Calendar.DATE, -2);
|
||||
zonedDate = currentDate.minusDays(2);
|
||||
|
||||
String loanDetails = this.loanTransactionHelper.getLoanDetails(requestSpec, responseSpec, loanID);
|
||||
loanStatusHashMap = this.loanTransactionHelper.disburseLoan(LOAN_DISBURSEMENT_DATE, loanID,
|
||||
@@ -827,10 +824,10 @@ public class AccountingScenarioIntegrationTest {
|
||||
LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap);
|
||||
|
||||
this.loanTransactionHelper.addChargesForLoan(loanID, LoanTransactionHelper.getSpecifiedDueDateChargesForLoanAsJSON(
|
||||
String.valueOf(flatSpecifiedDueDate), dateFormat.format(todayDate.getTime()), String.valueOf(PENALTY_PORTION)));
|
||||
todayDate.add(Calendar.DATE, 1);
|
||||
this.loanTransactionHelper.addChargesForLoan(loanID, LoanTransactionHelper.getSpecifiedDueDateChargesForLoanAsJSON(
|
||||
String.valueOf(flat), dateFormat.format(todayDate.getTime()), String.valueOf(FEE_PORTION)));
|
||||
String.valueOf(flatSpecifiedDueDate), dateFormat.format(zonedDate), String.valueOf(PENALTY_PORTION)));
|
||||
zonedDate = zonedDate.plusDays(1);
|
||||
this.loanTransactionHelper.addChargesForLoan(loanID, LoanTransactionHelper
|
||||
.getSpecifiedDueDateChargesForLoanAsJSON(String.valueOf(flat), dateFormat.format(zonedDate), String.valueOf(FEE_PORTION)));
|
||||
|
||||
// CHECK ACCOUNT ENTRIES
|
||||
LOG.info("Entries ......");
|
||||
@@ -865,7 +862,7 @@ public class AccountingScenarioIntegrationTest {
|
||||
float interest4Days = totalInterest / totalDaysInPeriod * 4;
|
||||
interest4Days = Float.parseFloat(numberFormat.format(interest4Days));
|
||||
|
||||
this.loanTransactionHelper.checkAccrualTransactionForRepayment(getDateAsLocalDate(currentDate), interest4Days, FEE_PORTION,
|
||||
this.loanTransactionHelper.checkAccrualTransactionForRepayment(currentDate.toLocalDate(), interest4Days, FEE_PORTION,
|
||||
PENALTY_PORTION, loanID);
|
||||
|
||||
}
|
||||
@@ -916,17 +913,15 @@ public class AccountingScenarioIntegrationTest {
|
||||
|
||||
DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy", Locale.US);
|
||||
|
||||
Calendar todayDate = Calendar.getInstance();
|
||||
final String currentDate = dateFormat.format(todayDate.getTime());
|
||||
Calendar todayDate = Calendar.getInstance(this.systemTimeZone);
|
||||
|
||||
todayDate.add(Calendar.DATE, -4);
|
||||
|
||||
final String LOAN_DISBURSEMENT_DATE = dateFormat.format(todayDate.getTime());
|
||||
|
||||
todayDate.add(Calendar.MONTH, 2);
|
||||
final String FIRST_REPAYMENT_DATE = dateFormat.format(todayDate.getTime());
|
||||
|
||||
todayDate = Calendar.getInstance();
|
||||
todayDate = Calendar.getInstance(this.systemTimeZone);
|
||||
todayDate.add(Calendar.DATE, -2);
|
||||
|
||||
String loanDetails = this.loanTransactionHelper.getLoanDetails(requestSpec, responseSpec, loanID);
|
||||
@@ -1123,10 +1118,8 @@ public class AccountingScenarioIntegrationTest {
|
||||
}
|
||||
|
||||
private LocalDate getDateAsLocalDate(String dateAsString) throws ParseException {
|
||||
DateFormat df = new SimpleDateFormat("dd MMMM yyyy", Locale.US);
|
||||
LocalDate date = LocalDate.ofInstant(df.parse(dateAsString).toInstant(), DateUtils.getDateTimeZoneOfTenant());
|
||||
|
||||
return date;
|
||||
final Date dateParsed = DateUtils.parseDate(dateAsString, "dd MMMM yyyy", null);
|
||||
return DateUtils.convertToLocalDate(dateParsed, this.systemTimeZone.toZoneId());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+23
-11
@@ -32,14 +32,20 @@ import java.text.DateFormat;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.TimeZone;
|
||||
import org.apache.fineract.integrationtests.common.ClientHelper;
|
||||
import org.apache.fineract.integrationtests.common.CollateralManagementHelper;
|
||||
import org.apache.fineract.integrationtests.common.GlobalConfigurationHelper;
|
||||
@@ -94,6 +100,8 @@ public class SchedulerJobsTestResults {
|
||||
private JournalEntryHelper journalEntryHelper;
|
||||
private StandingInstructionsHelper standingInstructionsHelper;
|
||||
|
||||
private TimeZone systemTimeZone;
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
Utils.initializeRESTAssured();
|
||||
@@ -103,6 +111,8 @@ public class SchedulerJobsTestResults {
|
||||
responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
|
||||
this.accountHelper = new AccountHelper(requestSpec, responseSpec);
|
||||
this.journalEntryHelper = new JournalEntryHelper(requestSpec, responseSpec);
|
||||
|
||||
this.systemTimeZone = TimeZone.getTimeZone(Utils.TENANT_TIME_ZONE);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
@@ -459,18 +469,20 @@ public class SchedulerJobsTestResults {
|
||||
this.savingsAccountHelper = new SavingsAccountHelper(requestSpec, responseSpec);
|
||||
this.standingInstructionsHelper = new StandingInstructionsHelper(requestSpec, responseSpec);
|
||||
|
||||
DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy", Locale.US);
|
||||
DateFormat monthDayFormat = new SimpleDateFormat("dd MMMM", Locale.US);
|
||||
final DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("dd MMMM yyyy", Locale.US);
|
||||
final DateTimeFormatter monthDayFormat = DateTimeFormatter.ofPattern("dd MMMM", Locale.US);
|
||||
|
||||
Calendar todaysDate = Calendar.getInstance();
|
||||
|
||||
final String MONTH_DAY = monthDayFormat.format(todaysDate.getTime());
|
||||
|
||||
todaysDate.add(Calendar.WEEK_OF_YEAR, -1);
|
||||
final String VALID_FROM = dateFormat.format(todaysDate.getTime());
|
||||
|
||||
todaysDate.add(Calendar.YEAR, 1);
|
||||
final String VALID_TO = dateFormat.format(todaysDate.getTime());
|
||||
// Create the LocalDate with the Zone used by default
|
||||
final LocalDate localDate = LocalDate.now(this.systemTimeZone.toZoneId());
|
||||
ZonedDateTime currentDate = ZonedDateTime.of(localDate, LocalTime.MIDNIGHT, this.systemTimeZone.toZoneId());
|
||||
// When the Stanging Instruction will be applied
|
||||
final String MONTH_DAY = monthDayFormat.format(currentDate.toLocalDate());
|
||||
// Standing Instruction valid from (One week before today)
|
||||
currentDate = currentDate.minus(Duration.ofDays(7));
|
||||
final String VALID_FROM = dateFormat.format(currentDate);
|
||||
// Standing Instruction valid to (One year after)
|
||||
currentDate = currentDate.plus(1, ChronoUnit.YEARS);
|
||||
final String VALID_TO = dateFormat.format(currentDate);
|
||||
|
||||
final Integer clientID = ClientHelper.createClient(requestSpec, responseSpec);
|
||||
Assertions.assertNotNull(clientID);
|
||||
|
||||
+12
-11
@@ -31,9 +31,9 @@ import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
@@ -70,7 +70,6 @@ public class LoanImportHandlerTest {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(LoanImportHandlerTest.class);
|
||||
private static final String CREATE_CLIENT_URL = "/fineract-provider/api/v1/clients?" + Utils.TENANT_IDENTIFIER;
|
||||
private static final String CREATE_CHARGE_URL = "/fineract-provider/api/v1/charges?" + Utils.TENANT_IDENTIFIER;
|
||||
public static final String DATE_FORMAT = "dd MMMM yyyy";
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
@@ -167,7 +166,7 @@ public class LoanImportHandlerTest {
|
||||
Assertions.assertNotNull(outcome_payment_creation, "Could not create payment type");
|
||||
|
||||
LoanTransactionHelper loanTransactionHelper = new LoanTransactionHelper(requestSpec, responseSpec);
|
||||
Workbook workbook = loanTransactionHelper.getLoanWorkbook("dd MMMM yyyy");
|
||||
Workbook workbook = loanTransactionHelper.getLoanWorkbook(DATE_FORMAT);
|
||||
|
||||
// insert dummy data into loan Sheet
|
||||
Sheet loanSheet = workbook.getSheet(TemplatePopulateImportConstants.LOANS_SHEET_NAME);
|
||||
@@ -179,11 +178,13 @@ public class LoanImportHandlerTest {
|
||||
firstLoanRow.createCell(LoanConstants.CLIENT_EXTERNAL_ID).setCellValue(externalId);
|
||||
firstLoanRow.createCell(LoanConstants.PRODUCT_COL).setCellValue(loanProductJson.getString("name"));
|
||||
firstLoanRow.createCell(LoanConstants.LOAN_OFFICER_NAME_COL).setCellValue((String) staffMap.get("displayName"));
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd MMMM yyyy", Locale.US);
|
||||
Date date = simpleDateFormat.parse("13 May 2017");
|
||||
firstLoanRow.createCell(LoanConstants.SUBMITTED_ON_DATE_COL).setCellValue(date);
|
||||
firstLoanRow.createCell(LoanConstants.APPROVED_DATE_COL).setCellValue(date);
|
||||
firstLoanRow.createCell(LoanConstants.DISBURSED_DATE_COL).setCellValue(date);
|
||||
|
||||
final DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern(DATE_FORMAT, Locale.US);
|
||||
final LocalDate localDate = LocalDate.parse("17 May 2017", dateFormat);
|
||||
|
||||
firstLoanRow.createCell(LoanConstants.SUBMITTED_ON_DATE_COL).setCellValue(localDate);
|
||||
firstLoanRow.createCell(LoanConstants.APPROVED_DATE_COL).setCellValue(localDate);
|
||||
firstLoanRow.createCell(LoanConstants.DISBURSED_DATE_COL).setCellValue(localDate);
|
||||
firstLoanRow.createCell(LoanConstants.DISBURSED_PAYMENT_TYPE_COL).setCellValue(paymentTypeName);
|
||||
firstLoanRow.createCell(LoanConstants.FUND_NAME_COL).setCellValue(fundName);
|
||||
firstLoanRow.createCell(LoanConstants.PRINCIPAL_COL).setCellValue(loanProductJson.getFloat("principal"));
|
||||
@@ -208,9 +209,9 @@ public class LoanImportHandlerTest {
|
||||
firstLoanRow.createCell(LoanConstants.GRACE_ON_PRINCIPAL_PAYMENT_COL).setCellValue(0);
|
||||
firstLoanRow.createCell(LoanConstants.GRACE_ON_INTEREST_PAYMENT_COL).setCellValue(0);
|
||||
firstLoanRow.createCell(LoanConstants.GRACE_ON_INTEREST_CHARGED_COL).setCellValue(0);
|
||||
firstLoanRow.createCell(LoanConstants.FIRST_REPAYMENT_COL).setCellValue(date);
|
||||
firstLoanRow.createCell(LoanConstants.FIRST_REPAYMENT_COL).setCellValue(localDate);
|
||||
firstLoanRow.createCell(LoanConstants.TOTAL_AMOUNT_REPAID_COL).setCellValue(6000);
|
||||
firstLoanRow.createCell(LoanConstants.LAST_REPAYMENT_DATE_COL).setCellValue(date);
|
||||
firstLoanRow.createCell(LoanConstants.LAST_REPAYMENT_DATE_COL).setCellValue(localDate);
|
||||
firstLoanRow.createCell(LoanConstants.REPAYMENT_TYPE_COL).setCellValue(paymentTypeName);
|
||||
firstLoanRow.createCell(LoanConstants.LOAN_COLLATERAL_ID).setCellValue(collaterals.get(0).get("clientCollateralId").toString());
|
||||
firstLoanRow.createCell(LoanConstants.LOAN_COLLATERAL_QUANTITY).setCellValue(collaterals.get(0).get("quantity").toString());
|
||||
|
||||
+1
-1
@@ -788,7 +788,7 @@ public class LoanTransactionHelper {
|
||||
LocalDate accrualEntryDate = LocalDate.of(accrualEntryDateAsArray.get(0), accrualEntryDateAsArray.get(1),
|
||||
accrualEntryDateAsArray.get(2));
|
||||
|
||||
if (transactionDate.equals(accrualEntryDate)) {
|
||||
if (transactionDate.isEqual(accrualEntryDate)) {
|
||||
isTransactionFound = true;
|
||||
assertEquals(interestPortion, Float.valueOf(String.valueOf(transactions.get(i).get("interestPortion"))),
|
||||
"Mismatch in transaction amounts");
|
||||
|
||||
Reference in New Issue
Block a user