FINERACT-1955: Timezone handling of Savings account

This commit is contained in:
jmarta
2023-10-24 16:00:57 +02:00
committed by Adam Saghy
parent 6cb8ae0ed3
commit 71afd6dead
74 changed files with 1584 additions and 1431 deletions
@@ -3008,7 +3008,7 @@ public class ClientSavingsIntegrationTest {
this.savingsProductHelper = new SavingsProductHelper();
this.scheduleJobHelper = new SchedulerJobHelper(requestSpec);
configurationForBackdatedTransaction();
LocalDate transactionDate = LocalDate.now(Utils.getZoneIdOfTenant()).minusDays(5);
LocalDate transactionDate = Utils.getLocalDateOfTenant().minusDays(5);
final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd MMMM yyyy");
String startDate = formatter.format(transactionDate);
String secondTrx = formatter.format(transactionDate.plusDays(1));
@@ -30,7 +30,6 @@ import io.restassured.specification.RequestSpecification;
import io.restassured.specification.ResponseSpecification;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
@@ -162,7 +161,7 @@ public class SavingsAccountTransactionsSearchIntegrationTest {
@Test
public void testSavingsTransactionsSearchSubmittedDateFromTo() throws JsonProcessingException {
LocalDate businessDate = LocalDate.now(ZoneId.systemDefault());
LocalDate businessDate = Utils.getLocalDateOfTenant();
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, startDate);
Assertions.assertNotNull(clientID);
final Integer savingsId = createSavingsAccountDailyPosting(clientID, startDate);
@@ -18,13 +18,13 @@
*/
package org.apache.fineract.integrationtests;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.time.format.DateTimeFormatter;
import org.apache.fineract.client.models.PostSavingsAccountsAccountIdRequest;
import org.apache.fineract.client.models.PostSavingsAccountsAccountIdResponse;
import org.apache.fineract.client.models.PostSavingsAccountsRequest;
import org.apache.fineract.client.models.PostSavingsAccountsResponse;
import org.apache.fineract.integrationtests.client.IntegrationTest;
import org.apache.fineract.integrationtests.common.Utils;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
@@ -42,8 +42,8 @@ public class SavingsAccountsTest extends IntegrationTest {
private static final Logger LOG = LoggerFactory.getLogger(SavingsAccountsTest.class);
private final String dateFormat = "dd MMMM yyyy";
private final String locale = "en";
private final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormat);
private final String formattedDate = simpleDateFormat.format(new Date());
private final DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern(dateFormat);
private final String formattedDate = dateFormatter.format(Utils.getLocalDateOfTenant());
private int savingId = 1;
@Test
@@ -27,13 +27,13 @@ import io.restassured.http.ContentType;
import io.restassured.specification.RequestSpecification;
import io.restassured.specification.ResponseSpecification;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType;
import org.apache.fineract.infrastructure.core.service.DateUtils;
import org.apache.fineract.integrationtests.common.BusinessDateHelper;
import org.apache.fineract.integrationtests.common.ClientHelper;
import org.apache.fineract.integrationtests.common.CommonConstants;
@@ -72,7 +72,7 @@ public class SavingsInterestPostingIntegrationTest {
@Test
public void testSavingsDailyInterestPosting() {
LocalDate today = LocalDate.now(ZoneId.systemDefault());
LocalDate today = Utils.getLocalDateOfTenant();
try {
GlobalConfigurationHelper.updateIsBusinessDateEnabled(requestSpec, responseSpec, true);
BusinessDateHelper.updateBusinessDate(requestSpec, responseSpec, BusinessDateType.BUSINESS_DATE, today);
@@ -100,7 +100,7 @@ public class SavingsInterestPostingIntegrationTest {
List<Integer> submittedOnDateStringList = (List<Integer>) interestPostingTransaction.get("submittedOnDate");
LocalDate submittedOnDate = submittedOnDateStringList.stream().collect(
Collectors.collectingAndThen(Collectors.toList(), list -> LocalDate.of(list.get(0), list.get(1), list.get(2))));
assertTrue(submittedOnDate.compareTo(today) == 0, "Submitted On Date check for Interest Posting transaction");
assertTrue(DateUtils.isEqual(submittedOnDate, today), "Submitted On Date check for Interest Posting transaction");
} finally {
GlobalConfigurationHelper.updateIsBusinessDateEnabled(requestSpec, responseSpec, false);
}
@@ -27,13 +27,13 @@ import io.restassured.http.ContentType;
import io.restassured.specification.RequestSpecification;
import io.restassured.specification.ResponseSpecification;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType;
import org.apache.fineract.infrastructure.core.service.DateUtils;
import org.apache.fineract.integrationtests.common.BusinessDateHelper;
import org.apache.fineract.integrationtests.common.ClientHelper;
import org.apache.fineract.integrationtests.common.CommonConstants;
@@ -149,7 +149,7 @@ public class SavingsInterestPostingJobIntegrationTest {
@Test
public void testSavingsDailyInterestPostingJob() {
LocalDate today = LocalDate.now(ZoneId.systemDefault());
LocalDate today = Utils.getLocalDateOfTenant();
try {
GlobalConfigurationHelper.updateIsBusinessDateEnabled(requestSpec, responseSpec, true);
BusinessDateHelper.updateBusinessDate(requestSpec, responseSpec, BusinessDateType.BUSINESS_DATE, today);
@@ -179,7 +179,7 @@ public class SavingsInterestPostingJobIntegrationTest {
List<Integer> submittedOnDateStringList = (List<Integer>) interestPostingTransaction.get("submittedOnDate");
LocalDate submittedOnDate = submittedOnDateStringList.stream().collect(
Collectors.collectingAndThen(Collectors.toList(), list -> LocalDate.of(list.get(0), list.get(1), list.get(2))));
assertTrue(submittedOnDate.compareTo(today) == 0, "Submitted On Date check for Interest Posting transaction");
assertTrue(DateUtils.isEqual(submittedOnDate, today), "Submitted On Date check for Interest Posting transaction");
} finally {
GlobalConfigurationHelper.updateIsBusinessDateEnabled(requestSpec, responseSpec, false);
}
@@ -198,9 +198,7 @@ public class SavingsInterestPostingJobIntegrationTest {
this.savingsAccountHelper.withdrawalFromSavingsAccount(savingsId, "10000", startDate, CommonConstants.RESPONSE_RESOURCE_ID);
/***
* Runs Post interest posting job and verify the new account created with Overdraft is posting negative interest
*/
// Runs Post interest posting job and verify the new account created with Overdraft is posting negative interest
this.scheduleJobHelper.executeAndAwaitJob(jobName);
Object transactionObj = this.savingsAccountHelper.getSavingsDetails(savingsId, "transactions");
ArrayList<HashMap<String, Object>> transactions = (ArrayList<HashMap<String, Object>>) transactionObj;
@@ -37,7 +37,6 @@ 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.format.DateTimeFormatterBuilder;
@@ -179,7 +178,7 @@ public class SchedulerJobsTestResults {
ArrayList<Integer> annualFeeDueDateAsArrayList = (ArrayList<Integer>) annualFeeDetails.get("dueDate");
LocalDate nextDueDateForAnnualFee = LocalDate.of(annualFeeDueDateAsArrayList.get(0), annualFeeDueDateAsArrayList.get(1),
annualFeeDueDateAsArrayList.get(2));
LocalDate todaysDate = LocalDate.now(ZoneId.of("Asia/Kolkata"));
LocalDate todaysDate = Utils.getLocalDateOfTenant();
Truth.assertWithMessage("Verifying that all due Annual Fees have been paid").that(nextDueDateForAnnualFee)
.isGreaterThan(todaysDate);
@@ -42,7 +42,9 @@ import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.time.temporal.ChronoField;
@@ -374,6 +376,14 @@ public final class Utils {
return dateFormat.format(dateToBeConvert.getTime());
}
public static OffsetDateTime getAuditOffsetDateTime() {
return OffsetDateTime.now(ZoneOffset.UTC);
}
public static LocalDateTime getLocalDateTimeOfSystem() {
return LocalDateTime.now(ZoneId.systemDefault());
}
public static TimeZone getTimeZoneOfTenant() {
return TimeZone.getTimeZone(TENANT_TIME_ZONE);
}
@@ -386,6 +396,10 @@ public final class Utils {
return LocalDate.now(getZoneIdOfTenant());
}
public static LocalDateTime getLocalDateTimeOfTenant() {
return LocalDateTime.now(getZoneIdOfTenant());
}
public static Date convertJsonElementAsDate(JsonElement jsonElement) {
if (jsonElement.isJsonArray()) {
JsonArray jsonArray = jsonElement.getAsJsonArray();
@@ -25,7 +25,6 @@ import com.google.gson.Gson;
import io.restassured.path.json.JsonPath;
import io.restassured.specification.RequestSpecification;
import io.restassured.specification.ResponseSpecification;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.List;
@@ -108,7 +107,7 @@ public class CampaignsHelper {
map.put("triggerType", triggerType);
if (2 == triggerType) {
map.put("recurrenceStartDate",
LocalDateTime.now(Utils.getZoneIdOfTenant()).plusMinutes(1).format(DateTimeFormatter.ofPattern(DATE_TIME_FORMAT)));
Utils.getLocalDateTimeOfTenant().plusMinutes(1).format(DateTimeFormatter.ofPattern(DATE_TIME_FORMAT)));
map.put("frequency", 1);
map.put("interval", "1");
}
@@ -136,7 +135,7 @@ public class CampaignsHelper {
map.put("triggerType", triggerType);
if (2 == triggerType) {
map.put("recurrenceStartDate",
LocalDateTime.now(Utils.getZoneIdOfTenant()).plusMinutes(1).format(DateTimeFormatter.ofPattern(DATE_TIME_FORMAT)));
Utils.getLocalDateTimeOfTenant().plusMinutes(1).format(DateTimeFormatter.ofPattern(DATE_TIME_FORMAT)));
}
map.put("campaignName", Utils.randomStringGenerator("Campaign_Name_", 5));
map.put("campaignType", 1);