FINERACT-2119: Address jobs by name
This commit is contained in:
committed by
Adam Saghy
parent
eef6a8da5e
commit
3aaa2ffe9c
+2
-2
@@ -57,8 +57,8 @@ public class InstanceModeIntegrationTest {
|
||||
responseSpec405 = new ResponseSpecBuilder().expectStatusCode(405).build();
|
||||
|
||||
schedulerJobHelper = new SchedulerJobHelper(requestSpec);
|
||||
String jobName = "Apply Annual Fee For Savings";
|
||||
jobId = schedulerJobHelper.getSchedulerJobIdByName(jobName);
|
||||
// Apply Annual Fee For Savings"
|
||||
jobId = schedulerJobHelper.getSchedulerJobIdByShortName("SA_AANF");
|
||||
}
|
||||
|
||||
@ConfigureInstanceMode(readEnabled = true, writeEnabled = false, batchWorkerEnabled = false, batchManagerEnabled = false)
|
||||
|
||||
+6
-11
@@ -59,6 +59,7 @@ public class SavingsInterestPostingJobIntegrationTest {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(SavingsInterestPostingJobIntegrationTest.class);
|
||||
public static final String ACCOUNT_TYPE_INDIVIDUAL = "INDIVIDUAL";
|
||||
public static final String POST_INTEREST_FOR_SAVINGS_JOB_SHORT_NAME = "SA_PINT";
|
||||
|
||||
private static ResponseSpecification responseSpec;
|
||||
private static RequestSpecification requestSpec;
|
||||
@@ -83,7 +84,6 @@ public class SavingsInterestPostingJobIntegrationTest {
|
||||
public void testSavingsBalanceCheckAfterDailyInterestPostingJob() {
|
||||
// client activation, savings activation and 1st transaction date
|
||||
final String startDate = "10 April 2022";
|
||||
final String jobName = "Post Interest For Savings";
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, startDate);
|
||||
Assertions.assertNotNull(clientID);
|
||||
|
||||
@@ -95,7 +95,7 @@ public class SavingsInterestPostingJobIntegrationTest {
|
||||
* Runs Post interest posting job and verify the new account created with accounting configuration set as none
|
||||
* is picked up by job
|
||||
*/
|
||||
this.scheduleJobHelper.executeAndAwaitJob(jobName);
|
||||
this.scheduleJobHelper.executeAndAwaitJobByShortName(POST_INTEREST_FOR_SAVINGS_JOB_SHORT_NAME);
|
||||
Object transactionObj = this.savingsAccountHelper.getSavingsDetails(savingsId, "transactions");
|
||||
ArrayList<HashMap<String, Object>> transactions = (ArrayList<HashMap<String, Object>>) transactionObj;
|
||||
HashMap<String, Object> interestPostingTransaction = transactions.get(transactions.size() - 48);
|
||||
@@ -108,7 +108,6 @@ public class SavingsInterestPostingJobIntegrationTest {
|
||||
@Test
|
||||
public void testSavingsDailyInterestPostingJobWithAccountingNone() {
|
||||
final String startDate = "10 April 2022";
|
||||
final String jobName = "Post Interest For Savings";
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, startDate);
|
||||
Assertions.assertNotNull(clientID);
|
||||
this.accountHelper = new AccountHelper(requestSpec, responseSpec);
|
||||
@@ -126,7 +125,6 @@ public class SavingsInterestPostingJobIntegrationTest {
|
||||
public void testDuplicateOverdraftInterestPostingJob() {
|
||||
// client activation, savings activation and 1st transaction date
|
||||
final String startDate = "01 July 2022";
|
||||
final String jobName = "Post Interest For Savings";
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, startDate);
|
||||
Assertions.assertNotNull(clientID);
|
||||
|
||||
@@ -134,7 +132,7 @@ public class SavingsInterestPostingJobIntegrationTest {
|
||||
|
||||
this.savingsAccountHelper.withdrawalFromSavingsAccount(savingsId, "1000", startDate, CommonConstants.RESPONSE_RESOURCE_ID);
|
||||
|
||||
this.scheduleJobHelper.executeAndAwaitJob(jobName);
|
||||
this.scheduleJobHelper.executeAndAwaitJobByShortName(POST_INTEREST_FOR_SAVINGS_JOB_SHORT_NAME);
|
||||
this.savingsAccountHelper.withdrawalFromSavingsAccount(savingsId, "1000", startDate, CommonConstants.RESPONSE_RESOURCE_ID);
|
||||
Object transactionObj = this.savingsAccountHelper.getSavingsDetails(savingsId, "transactions");
|
||||
ArrayList<HashMap<String, Object>> transactions = (ArrayList<HashMap<String, Object>>) transactionObj;
|
||||
@@ -155,7 +153,6 @@ public class SavingsInterestPostingJobIntegrationTest {
|
||||
BusinessDateHelper.updateBusinessDate(requestSpec, responseSpec, BusinessDateType.BUSINESS_DATE, today);
|
||||
// client activation, savings activation and 1st transaction date
|
||||
final String startDate = "10 April 2022";
|
||||
final String jobName = "Post Interest For Savings";
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, startDate);
|
||||
Assertions.assertNotNull(clientID);
|
||||
|
||||
@@ -167,7 +164,7 @@ public class SavingsInterestPostingJobIntegrationTest {
|
||||
* Runs Post interest posting job and verify the new account created with accounting configuration set as
|
||||
* none is picked up by job
|
||||
*/
|
||||
this.scheduleJobHelper.executeAndAwaitJob(jobName);
|
||||
this.scheduleJobHelper.executeAndAwaitJobByShortName(POST_INTEREST_FOR_SAVINGS_JOB_SHORT_NAME);
|
||||
Object transactionObj = this.savingsAccountHelper.getSavingsDetails(savingsId, "transactions");
|
||||
ArrayList<HashMap<String, Object>> transactions = (ArrayList<HashMap<String, Object>>) transactionObj;
|
||||
HashMap<String, Object> interestPostingTransaction = transactions.get(transactions.size() - 3);
|
||||
@@ -190,7 +187,6 @@ public class SavingsInterestPostingJobIntegrationTest {
|
||||
public void testSavingsDailyOverdraftInterestPostingJob() {
|
||||
// client activation, savings activation and 1st transaction date
|
||||
final String startDate = "10 April 2022";
|
||||
final String jobName = "Post Interest For Savings";
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, startDate);
|
||||
Assertions.assertNotNull(clientID);
|
||||
|
||||
@@ -199,7 +195,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
|
||||
this.scheduleJobHelper.executeAndAwaitJob(jobName);
|
||||
this.scheduleJobHelper.executeAndAwaitJobByShortName(POST_INTEREST_FOR_SAVINGS_JOB_SHORT_NAME);
|
||||
Object transactionObj = this.savingsAccountHelper.getSavingsDetails(savingsId, "transactions");
|
||||
ArrayList<HashMap<String, Object>> transactions = (ArrayList<HashMap<String, Object>>) transactionObj;
|
||||
HashMap<String, Object> interestPostingTransaction = transactions.get(transactions.size() - 2);
|
||||
@@ -215,7 +211,6 @@ public class SavingsInterestPostingJobIntegrationTest {
|
||||
@Test
|
||||
public void testAccountBalanceWithWithdrawalFeeAfterInterestPostingJob() {
|
||||
final String startDate = "21 June 2022";
|
||||
final String jobName = "Post Interest For Savings";
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, startDate);
|
||||
Assertions.assertNotNull(clientID);
|
||||
|
||||
@@ -227,7 +222,7 @@ public class SavingsInterestPostingJobIntegrationTest {
|
||||
Float balance = Float.parseFloat("800.0");
|
||||
assertEquals(balance, summary.get("accountBalance"), "Verifying account balance is 800");
|
||||
|
||||
this.scheduleJobHelper.executeAndAwaitJob(jobName);
|
||||
this.scheduleJobHelper.executeAndAwaitJobByShortName(POST_INTEREST_FOR_SAVINGS_JOB_SHORT_NAME);
|
||||
Object transactionObj = this.savingsAccountHelper.getSavingsDetails(savingsId, "transactions");
|
||||
ArrayList<HashMap<String, Object>> transactions = (ArrayList<HashMap<String, Object>>) transactionObj;
|
||||
HashMap<String, Object> interestPostingTransaction = transactions.get(transactions.size() - 5);
|
||||
|
||||
+73
-7
@@ -19,6 +19,7 @@
|
||||
package org.apache.fineract.integrationtests.common;
|
||||
|
||||
import static java.time.Instant.now;
|
||||
import static org.apache.fineract.infrastructure.jobs.api.SchedulerJobApiConstants.SHORT_NAME_PARAM;
|
||||
import static org.awaitility.Awaitility.await;
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
@@ -28,6 +29,7 @@ import com.google.gson.Gson;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.io.Serializable;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
@@ -37,7 +39,9 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
import org.apache.fineract.client.models.PutJobsJobIDRequest;
|
||||
import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType;
|
||||
@@ -89,6 +93,15 @@ public class SchedulerJobHelper extends IntegrationTest {
|
||||
return response;
|
||||
}
|
||||
|
||||
private Map<String, Object> getSchedulerJobByShortName(String shortName) {
|
||||
final String GET_SCHEDULER_JOB_URL = "/fineract-provider/api/v1/jobs/" + SHORT_NAME_PARAM + "/" + shortName + "?"
|
||||
+ Utils.TENANT_IDENTIFIER;
|
||||
LOG.info("------------------------ RETRIEVING SCHEDULER JOB BY SHORT NAME -------------------------");
|
||||
Map<String, Object> response = Utils.performServerGet(requestSpec, response200Spec, GET_SCHEDULER_JOB_URL, "");
|
||||
assertNotNull(response);
|
||||
return response;
|
||||
}
|
||||
|
||||
public Boolean getSchedulerStatus() {
|
||||
final String GET_SCHEDULER_STATUS_URL = "/fineract-provider/api/v1/scheduler?" + Utils.TENANT_IDENTIFIER;
|
||||
LOG.info("------------------------ RETRIEVING SCHEDULER STATUS -------------------------");
|
||||
@@ -131,6 +144,18 @@ public class SchedulerJobHelper extends IntegrationTest {
|
||||
Utils.performServerPost(requestSpec, responseSpec, RUN_SCHEDULER_JOB_URL, runSchedulerJobAsJSON(), null);
|
||||
}
|
||||
|
||||
public void runSchedulerJobByShortName(String shortName) {
|
||||
final ResponseSpecification responseSpec = new ResponseSpecBuilder().expectStatusCode(202).build();
|
||||
runSchedulerJobByShortName(shortName, responseSpec);
|
||||
}
|
||||
|
||||
public void runSchedulerJobByShortName(String shortName, ResponseSpecification responseSpec) {
|
||||
final String RUN_SCHEDULER_JOB_URL = "/fineract-provider/api/v1/jobs/" + SHORT_NAME_PARAM + "/" + shortName + "?command=executeJob&"
|
||||
+ Utils.TENANT_IDENTIFIER;
|
||||
LOG.info("------------------------ RUN SCHEDULER JOB -------------------------");
|
||||
Utils.performServerPost(requestSpec, responseSpec, RUN_SCHEDULER_JOB_URL, runSchedulerJobAsJSON(), null);
|
||||
}
|
||||
|
||||
private static String runSchedulerJobAsJSON() {
|
||||
final Map<String, String> map = new HashMap<>();
|
||||
String runSchedulerJob = new Gson().toJson(map);
|
||||
@@ -149,6 +174,16 @@ public class SchedulerJobHelper extends IntegrationTest {
|
||||
"No such named Job (see org.apache.fineract.infrastructure.jobs.service.JobName enum):" + jobName);
|
||||
}
|
||||
|
||||
public int getSchedulerJobIdByShortName(String shortName) {
|
||||
Map<String, Object> jobMap = getSchedulerJobByShortName(shortName);
|
||||
final String GET_SCHEDULER_JOB_URL = "/fineract-provider/api/v1/jobs/" + SHORT_NAME_PARAM + "/" + shortName + "?"
|
||||
+ Utils.TENANT_IDENTIFIER;
|
||||
LOG.info("------------------------ RETRIEVING SCHEDULER JOB ID BY SHORT NAME -------------------------");
|
||||
Integer response = (Integer) jobMap.get("jobId");
|
||||
assertNotNull(response);
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Launches a Job and awaits its completion.
|
||||
*
|
||||
@@ -158,23 +193,43 @@ public class SchedulerJobHelper extends IntegrationTest {
|
||||
* @author Michael Vorburger.ch
|
||||
*/
|
||||
public void executeAndAwaitJob(String jobName) {
|
||||
final Duration timeout = Duration.ofMinutes(4);
|
||||
final Duration pause = Duration.ofSeconds(2);
|
||||
DateTimeFormatter df = DateTimeFormatter.ISO_INSTANT; // FINERACT-926
|
||||
Instant beforeExecuteTime = now().truncatedTo(ChronoUnit.SECONDS);
|
||||
int jobId = getSchedulerJobIdByName(jobName);
|
||||
executeAndAwaitJob(jobId, (a) -> runSchedulerJob(jobId), () -> jobLastRunHistorySupplier(jobId));
|
||||
}
|
||||
|
||||
/**
|
||||
* Launches a Job and awaits its completion.
|
||||
*
|
||||
* @param shortName
|
||||
* shortName of Scheduler Job
|
||||
*
|
||||
* @author Michael Vorburger.ch
|
||||
*/
|
||||
public void executeAndAwaitJobByShortName(String shortName) {
|
||||
executeAndAwaitJob(shortName, (a) -> runSchedulerJobByShortName(shortName), () -> jobLastRunHistoryByShortName(shortName));
|
||||
}
|
||||
|
||||
public <T extends Serializable> void executeAndAwaitJob(T jobParam, Consumer<T> runSchedulerJob,
|
||||
Supplier<Callable<Map<String, String>>> retrievelastRunHistory) {
|
||||
// Stop the Scheduler while we manually trigger execution of job, to
|
||||
// avoid side effects and simplify debugging when readings logs
|
||||
updateSchedulerStatus(false);
|
||||
|
||||
Instant beforeExecuteTime = now().truncatedTo(ChronoUnit.SECONDS);
|
||||
// Executing Scheduler Job
|
||||
int jobId = getSchedulerJobIdByName(jobName);
|
||||
runSchedulerJob(jobId);
|
||||
runSchedulerJob.accept(jobParam);
|
||||
|
||||
awaitJob(beforeExecuteTime, retrievelastRunHistory);
|
||||
}
|
||||
|
||||
private void awaitJob(Instant beforeExecuteTime, Supplier<Callable<Map<String, String>>> retrieveLastRunHistory) {
|
||||
final Duration timeout = Duration.ofMinutes(4);
|
||||
final Duration pause = Duration.ofSeconds(2);
|
||||
DateTimeFormatter df = DateTimeFormatter.ISO_INSTANT; // FINERACT-926
|
||||
// Await JobDetailData.lastRunHistory [JobDetailHistoryData]
|
||||
// jobRunStartTime >= beforeExecuteTime (or timeout)
|
||||
// jobRunEndTime to be both set and >= jobRunStartTime (or timeout)
|
||||
Map<String, String> finalLastRunHistory = await().atMost(timeout).pollInterval(pause).until(jobLastRunHistorySupplier(jobId),
|
||||
Map<String, String> finalLastRunHistory = await().atMost(timeout).pollInterval(pause).until(retrieveLastRunHistory.get(),
|
||||
lastRunHistory -> {
|
||||
String jobRunStartText = lastRunHistory.get("jobRunStartTime");
|
||||
if (jobRunStartText == null) {
|
||||
@@ -223,4 +278,15 @@ public class SchedulerJobHelper extends IntegrationTest {
|
||||
return (Map<String, String>) job.get("lastRunHistory");
|
||||
};
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Callable<Map<String, String>> jobLastRunHistoryByShortName(String shortName) {
|
||||
return () -> {
|
||||
Map<String, Object> job = getSchedulerJobByShortName(shortName);
|
||||
if (job == null) {
|
||||
return null;
|
||||
}
|
||||
return (Map<String, String>) job.get("lastRunHistory");
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user