make SchedulerJobsTest preserve scheduler and job states (FINERACT-922)
This commit is contained in:
+21
-2
@@ -27,10 +27,13 @@ import io.restassured.builder.RequestSpecBuilder;
|
|||||||
import io.restassured.http.ContentType;
|
import io.restassured.http.ContentType;
|
||||||
import io.restassured.specification.RequestSpecification;
|
import io.restassured.specification.RequestSpecification;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import org.apache.fineract.infrastructure.jobs.service.JobName;
|
||||||
import org.apache.fineract.integrationtests.common.SchedulerJobHelper;
|
import org.apache.fineract.integrationtests.common.SchedulerJobHelper;
|
||||||
import org.apache.fineract.integrationtests.common.Utils;
|
import org.apache.fineract.integrationtests.common.Utils;
|
||||||
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -39,6 +42,8 @@ public class SchedulerJobsTest {
|
|||||||
|
|
||||||
private RequestSpecification requestSpec;
|
private RequestSpecification requestSpec;
|
||||||
private SchedulerJobHelper schedulerJobHelper;
|
private SchedulerJobHelper schedulerJobHelper;
|
||||||
|
private Boolean originalSchedulerStatus;
|
||||||
|
private final Map<Integer, Boolean> originalJobStatus = new HashMap<>();
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
@@ -47,6 +52,20 @@ public class SchedulerJobsTest {
|
|||||||
requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
|
requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
|
||||||
requestSpec.header("Fineract-Platform-TenantId", "default");
|
requestSpec.header("Fineract-Platform-TenantId", "default");
|
||||||
schedulerJobHelper = new SchedulerJobHelper(requestSpec);
|
schedulerJobHelper = new SchedulerJobHelper(requestSpec);
|
||||||
|
originalSchedulerStatus = schedulerJobHelper.getSchedulerStatus();
|
||||||
|
for (Integer jobId : schedulerJobHelper.getAllSchedulerJobIds()) {
|
||||||
|
Map<String, Object> schedulerJob = schedulerJobHelper.getSchedulerJobById(jobId);
|
||||||
|
Boolean active = (Boolean) schedulerJob.get("active");
|
||||||
|
originalJobStatus.put(jobId, active);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() {
|
||||||
|
schedulerJobHelper.updateSchedulerStatus(originalSchedulerStatus);
|
||||||
|
for (int jobId = 1; jobId < JobName.values().length; jobId++) {
|
||||||
|
schedulerJobHelper.updateSchedulerJob(jobId, originalJobStatus.get(jobId));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // FINERACT-926
|
@Test // FINERACT-926
|
||||||
@@ -54,7 +73,7 @@ public class SchedulerJobsTest {
|
|||||||
// must start scheduler and make job active to have nextRunTime (which is a
|
// must start scheduler and make job active to have nextRunTime (which is a
|
||||||
// java.util.Date)
|
// java.util.Date)
|
||||||
schedulerJobHelper.updateSchedulerStatus(true);
|
schedulerJobHelper.updateSchedulerStatus(true);
|
||||||
schedulerJobHelper.updateSchedulerJob(1, "true");
|
schedulerJobHelper.updateSchedulerJob(1, true);
|
||||||
String nextRunTimeText = await().until(
|
String nextRunTimeText = await().until(
|
||||||
() -> (String) schedulerJobHelper.getSchedulerJobById(1).get("nextRunTime"),
|
() -> (String) schedulerJobHelper.getSchedulerJobById(1).get("nextRunTime"),
|
||||||
nextRunTime -> nextRunTime != null);
|
nextRunTime -> nextRunTime != null);
|
||||||
@@ -93,7 +112,7 @@ public class SchedulerJobsTest {
|
|||||||
active = !active;
|
active = !active;
|
||||||
|
|
||||||
// Updating Scheduler Job
|
// Updating Scheduler Job
|
||||||
Map<String, Object> changes = schedulerJobHelper.updateSchedulerJob(jobId, active.toString());
|
Map<String, Object> changes = schedulerJobHelper.updateSchedulerJob(jobId, active);
|
||||||
|
|
||||||
// Verifying Scheduler Job updates
|
// Verifying Scheduler Job updates
|
||||||
assertEquals("Verifying Scheduler Job Updates", active, changes.get("active"));
|
assertEquals("Verifying Scheduler Job Updates", active, changes.get("active"));
|
||||||
|
|||||||
+3
-3
@@ -88,7 +88,7 @@ public class SchedulerJobHelper {
|
|||||||
Utils.performServerPost(requestSpec, response202Spec, UPDATE_SCHEDULER_STATUS_URL, runSchedulerJobAsJSON(), null);
|
Utils.performServerPost(requestSpec, response202Spec, UPDATE_SCHEDULER_STATUS_URL, runSchedulerJobAsJSON(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, Object> updateSchedulerJob(int jobId, final String active) {
|
public Map<String, Object> updateSchedulerJob(int jobId, final boolean active) {
|
||||||
final String UPDATE_SCHEDULER_JOB_URL = "/fineract-provider/api/v1/jobs/" + jobId + "?" + Utils.TENANT_IDENTIFIER;
|
final String UPDATE_SCHEDULER_JOB_URL = "/fineract-provider/api/v1/jobs/" + jobId + "?" + Utils.TENANT_IDENTIFIER;
|
||||||
LOG.info("------------------------ UPDATING SCHEDULER JOB -------------------------");
|
LOG.info("------------------------ UPDATING SCHEDULER JOB -------------------------");
|
||||||
final Map<String, Object> response = Utils.performServerPut(requestSpec, response200Spec, UPDATE_SCHEDULER_JOB_URL,
|
final Map<String, Object> response = Utils.performServerPut(requestSpec, response200Spec, UPDATE_SCHEDULER_JOB_URL,
|
||||||
@@ -96,9 +96,9 @@ public class SchedulerJobHelper {
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String updateSchedulerJobAsJSON(final String active) {
|
private static String updateSchedulerJobAsJSON(final boolean active) {
|
||||||
final Map<String, String> map = new HashMap<>();
|
final Map<String, String> map = new HashMap<>();
|
||||||
map.put("active", active);
|
map.put("active", Boolean.toString(active));
|
||||||
LOG.info("map : {}" , map);
|
LOG.info("map : {}" , map);
|
||||||
return new Gson().toJson(map);
|
return new Gson().toJson(map);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user