second step to clean up in SchedulerJobsTest (re. FINERACT-922)
do more un-static-ify SchedulerJobHelper This does NOT, yet, fix FINERACT-922.
This commit is contained in:
committed by
Michael Vorburger ⛑️
parent
85bf8dc3e9
commit
2212675af4
+8
-13
@@ -25,7 +25,6 @@ import static org.junit.Assert.assertNotNull;
|
|||||||
import io.restassured.builder.RequestSpecBuilder;
|
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 io.restassured.specification.ResponseSpecification;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import org.apache.fineract.integrationtests.common.SchedulerJobHelper;
|
import org.apache.fineract.integrationtests.common.SchedulerJobHelper;
|
||||||
@@ -37,7 +36,6 @@ import org.junit.Test;
|
|||||||
@SuppressWarnings({ "rawtypes", "unchecked", "static-access" })
|
@SuppressWarnings({ "rawtypes", "unchecked", "static-access" })
|
||||||
public class SchedulerJobsTest {
|
public class SchedulerJobsTest {
|
||||||
|
|
||||||
private ResponseSpecification responseSpec;
|
|
||||||
private RequestSpecification requestSpec;
|
private RequestSpecification requestSpec;
|
||||||
private SchedulerJobHelper schedulerJobHelper;
|
private SchedulerJobHelper schedulerJobHelper;
|
||||||
|
|
||||||
@@ -51,7 +49,7 @@ public class SchedulerJobsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetAndUpdateSchedulerStatus() throws InterruptedException {
|
public void testFlippingSchedulerStatus() throws InterruptedException {
|
||||||
// Retrieving Status of Scheduler
|
// Retrieving Status of Scheduler
|
||||||
Boolean schedulerStatus = this.schedulerJobHelper.getSchedulerStatus();
|
Boolean schedulerStatus = this.schedulerJobHelper.getSchedulerStatus();
|
||||||
if (schedulerStatus == true) {
|
if (schedulerStatus == true) {
|
||||||
@@ -71,15 +69,14 @@ public class SchedulerJobsTest {
|
|||||||
@Ignore // TODO FINERACT-852
|
@Ignore // TODO FINERACT-852
|
||||||
public void testSchedulerJobs() throws InterruptedException {
|
public void testSchedulerJobs() throws InterruptedException {
|
||||||
// Retrieving All Scheduler Jobs
|
// Retrieving All Scheduler Jobs
|
||||||
List<Map> allSchedulerJobsData = this.schedulerJobHelper.getAllSchedulerJobs(this.requestSpec, this.responseSpec);
|
List<Map> allSchedulerJobsData = this.schedulerJobHelper.getAllSchedulerJobs();
|
||||||
assertNotNull(allSchedulerJobsData);
|
assertNotNull(allSchedulerJobsData);
|
||||||
|
|
||||||
for (Integer jobIndex = 0; jobIndex < allSchedulerJobsData.size(); jobIndex++) {
|
for (Integer jobIndex = 0; jobIndex < allSchedulerJobsData.size(); jobIndex++) {
|
||||||
|
|
||||||
Integer jobId = (Integer) allSchedulerJobsData.get(jobIndex).get("jobId");
|
Integer jobId = (Integer) allSchedulerJobsData.get(jobIndex).get("jobId");
|
||||||
|
|
||||||
// Retrieving Scheduler Job by ID
|
// Retrieving Scheduler Job by ID
|
||||||
Map schedulerJob = this.schedulerJobHelper.getSchedulerJobById(this.requestSpec, this.responseSpec, jobId.toString());
|
Map schedulerJob = this.schedulerJobHelper.getSchedulerJobById(jobId.toString());
|
||||||
assertNotNull(schedulerJob);
|
assertNotNull(schedulerJob);
|
||||||
|
|
||||||
Boolean active = (Boolean) schedulerJob.get("active");
|
Boolean active = (Boolean) schedulerJob.get("active");
|
||||||
@@ -91,8 +88,7 @@ public class SchedulerJobsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Updating Scheduler Job
|
// Updating Scheduler Job
|
||||||
Map changes = this.schedulerJobHelper.updateSchedulerJob(this.requestSpec, this.responseSpec, jobId.toString(),
|
Map changes = this.schedulerJobHelper.updateSchedulerJob(jobId.toString(), active.toString());
|
||||||
active.toString());
|
|
||||||
// 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"));
|
||||||
|
|
||||||
@@ -100,18 +96,17 @@ public class SchedulerJobsTest {
|
|||||||
this.schedulerJobHelper.runSchedulerJob(this.requestSpec, jobId.toString());
|
this.schedulerJobHelper.runSchedulerJob(this.requestSpec, jobId.toString());
|
||||||
|
|
||||||
// Retrieving Scheduler Job by ID
|
// Retrieving Scheduler Job by ID
|
||||||
schedulerJob = this.schedulerJobHelper.getSchedulerJobById(this.requestSpec, this.responseSpec, jobId.toString());
|
schedulerJob = this.schedulerJobHelper.getSchedulerJobById(jobId.toString());
|
||||||
assertNotNull(schedulerJob);
|
assertNotNull(schedulerJob);
|
||||||
|
|
||||||
// Waiting for Job to complete
|
// Waiting for Job to complete
|
||||||
while ((Boolean) schedulerJob.get("currentlyRunning") == true) {
|
while ((Boolean) schedulerJob.get("currentlyRunning") == true) {
|
||||||
Thread.sleep(15000);
|
Thread.sleep(500);
|
||||||
schedulerJob = this.schedulerJobHelper.getSchedulerJobById(this.requestSpec, this.responseSpec, jobId.toString());
|
schedulerJob = this.schedulerJobHelper.getSchedulerJobById(jobId.toString());
|
||||||
assertNotNull(schedulerJob);
|
assertNotNull(schedulerJob);
|
||||||
System.out.println("Job " +jobId.toString() +" is Still Running");
|
System.out.println("Job " +jobId.toString() +" is Still Running");
|
||||||
}
|
}
|
||||||
List<Map> jobHistoryData = this.schedulerJobHelper.getSchedulerJobHistory(this.requestSpec, this.responseSpec,
|
List<Map> jobHistoryData = this.schedulerJobHelper.getSchedulerJobHistory(jobId.toString());
|
||||||
jobId.toString());
|
|
||||||
|
|
||||||
// Verifying the Status of the Recently executed Scheduler Job
|
// Verifying the Status of the Recently executed Scheduler Job
|
||||||
assertFalse("Job History is empty :( Was it too slow? Failures in background job?", jobHistoryData.isEmpty());
|
assertFalse("Job History is empty :( Was it too slow? Failures in background job?", jobHistoryData.isEmpty());
|
||||||
|
|||||||
+2
-2
@@ -772,12 +772,12 @@ public class SchedulerJobsTestResults {
|
|||||||
|
|
||||||
this.schedulerJobHelper.executeJob(JobName);
|
this.schedulerJobHelper.executeJob(JobName);
|
||||||
|
|
||||||
HashMap schedulerJob = this.schedulerJobHelper.getSchedulerJobById(this.requestSpec, this.responseSpec, jobId.toString());
|
HashMap schedulerJob = this.schedulerJobHelper.getSchedulerJobById(jobId.toString());
|
||||||
|
|
||||||
Assert.assertNotNull(schedulerJob);
|
Assert.assertNotNull(schedulerJob);
|
||||||
while ((Boolean) schedulerJob.get("currentlyRunning") == true) {
|
while ((Boolean) schedulerJob.get("currentlyRunning") == true) {
|
||||||
Thread.sleep(15000);
|
Thread.sleep(15000);
|
||||||
schedulerJob = this.schedulerJobHelper.getSchedulerJobById(this.requestSpec, this.responseSpec, jobId.toString());
|
schedulerJob = this.schedulerJobHelper.getSchedulerJobById(jobId.toString());
|
||||||
Assert.assertNotNull(schedulerJob);
|
Assert.assertNotNull(schedulerJob);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+12
-15
@@ -47,18 +47,17 @@ public class SchedulerJobHelper {
|
|||||||
this.response202Spec = responseSpec;
|
this.response202Spec = responseSpec;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List getAllSchedulerJobs(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
public List getAllSchedulerJobs() {
|
||||||
final String GET_ALL_SCHEDULER_JOBS_URL = "/fineract-provider/api/v1/jobs?" + Utils.TENANT_IDENTIFIER;
|
final String GET_ALL_SCHEDULER_JOBS_URL = "/fineract-provider/api/v1/jobs?" + Utils.TENANT_IDENTIFIER;
|
||||||
System.out.println("------------------------ RETRIEVING ALL SCHEDULER JOBS -------------------------");
|
System.out.println("------------------------ RETRIEVING ALL SCHEDULER JOBS -------------------------");
|
||||||
final ArrayList response = Utils.performServerGet(requestSpec, responseSpec, GET_ALL_SCHEDULER_JOBS_URL, "");
|
final ArrayList response = Utils.performServerGet(requestSpec, response200Spec, GET_ALL_SCHEDULER_JOBS_URL, "");
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HashMap getSchedulerJobById(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
public HashMap getSchedulerJobById(final String jobId) {
|
||||||
final String jobId) {
|
|
||||||
final String GET_SCHEDULER_JOB_BY_ID_URL = "/fineract-provider/api/v1/jobs/" + jobId + "?" + Utils.TENANT_IDENTIFIER;
|
final String GET_SCHEDULER_JOB_BY_ID_URL = "/fineract-provider/api/v1/jobs/" + jobId + "?" + Utils.TENANT_IDENTIFIER;
|
||||||
System.out.println("------------------------ RETRIEVING SCHEDULER JOB BY ID -------------------------");
|
System.out.println("------------------------ RETRIEVING SCHEDULER JOB BY ID -------------------------");
|
||||||
final HashMap response = Utils.performServerGet(requestSpec, responseSpec, GET_SCHEDULER_JOB_BY_ID_URL, "");
|
final HashMap response = Utils.performServerGet(requestSpec, response200Spec, GET_SCHEDULER_JOB_BY_ID_URL, "");
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,11 +74,10 @@ public class SchedulerJobHelper {
|
|||||||
Utils.performServerPost(requestSpec, response202Spec, UPDATE_SCHEDULER_STATUS_URL, runSchedulerJobAsJSON(), null);
|
Utils.performServerPost(requestSpec, response202Spec, UPDATE_SCHEDULER_STATUS_URL, runSchedulerJobAsJSON(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map updateSchedulerJob(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
public Map updateSchedulerJob(final String jobId, final String active) {
|
||||||
final String jobId, final String 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;
|
||||||
System.out.println("------------------------ UPDATING SCHEDULER JOB -------------------------");
|
System.out.println("------------------------ UPDATING SCHEDULER JOB -------------------------");
|
||||||
final Map response = Utils.performServerPut(requestSpec, responseSpec, UPDATE_SCHEDULER_JOB_URL,
|
final Map response = Utils.performServerPut(requestSpec, response200Spec, UPDATE_SCHEDULER_JOB_URL,
|
||||||
updateSchedulerJobAsJSON(active), "changes");
|
updateSchedulerJobAsJSON(active), "changes");
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
@@ -91,11 +89,10 @@ public class SchedulerJobHelper {
|
|||||||
return new Gson().toJson(map);
|
return new Gson().toJson(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List getSchedulerJobHistory(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
public List getSchedulerJobHistory(final String jobId) {
|
||||||
final String jobId) {
|
|
||||||
final String GET_SCHEDULER_STATUS_URL = "/fineract-provider/api/v1/jobs/" + jobId + "/runhistory?" + Utils.TENANT_IDENTIFIER;
|
final String GET_SCHEDULER_STATUS_URL = "/fineract-provider/api/v1/jobs/" + jobId + "/runhistory?" + Utils.TENANT_IDENTIFIER;
|
||||||
System.out.println("------------------------ RETRIEVING SCHEDULER JOB HISTORY -------------------------");
|
System.out.println("------------------------ RETRIEVING SCHEDULER JOB HISTORY -------------------------");
|
||||||
final Map response = Utils.performServerGet(requestSpec, responseSpec, GET_SCHEDULER_STATUS_URL, "");
|
final Map response = Utils.performServerGet(requestSpec, response200Spec, GET_SCHEDULER_STATUS_URL, "");
|
||||||
return (ArrayList) response.get("pageItems");
|
return (ArrayList) response.get("pageItems");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,7 +111,7 @@ public class SchedulerJobHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void executeJob(String jobName) throws InterruptedException {
|
public void executeJob(String jobName) throws InterruptedException {
|
||||||
List<Map> allSchedulerJobsData = getAllSchedulerJobs(this.requestSpec, this.response200Spec);
|
List<Map> allSchedulerJobsData = getAllSchedulerJobs();
|
||||||
Assert.assertNotNull(allSchedulerJobsData);
|
Assert.assertNotNull(allSchedulerJobsData);
|
||||||
|
|
||||||
for (Integer jobIndex = 0; jobIndex < allSchedulerJobsData.size(); jobIndex++) {
|
for (Integer jobIndex = 0; jobIndex < allSchedulerJobsData.size(); jobIndex++) {
|
||||||
@@ -125,18 +122,18 @@ public class SchedulerJobHelper {
|
|||||||
runSchedulerJob(this.requestSpec, jobId.toString());
|
runSchedulerJob(this.requestSpec, jobId.toString());
|
||||||
|
|
||||||
// Retrieving Scheduler Job by ID
|
// Retrieving Scheduler Job by ID
|
||||||
Map schedulerJob = getSchedulerJobById(this.requestSpec, this.response200Spec, jobId.toString());
|
Map schedulerJob = getSchedulerJobById(jobId.toString());
|
||||||
Assert.assertNotNull(schedulerJob);
|
Assert.assertNotNull(schedulerJob);
|
||||||
|
|
||||||
// Waiting for Job to complete
|
// Waiting for Job to complete
|
||||||
while ((Boolean) schedulerJob.get("currentlyRunning") == true) {
|
while ((Boolean) schedulerJob.get("currentlyRunning") == true) {
|
||||||
Thread.sleep(15000);
|
Thread.sleep(15000);
|
||||||
schedulerJob = getSchedulerJobById(this.requestSpec, this.response200Spec, jobId.toString());
|
schedulerJob = getSchedulerJobById(jobId.toString());
|
||||||
Assert.assertNotNull(schedulerJob);
|
Assert.assertNotNull(schedulerJob);
|
||||||
System.out.println("Job is Still Running");
|
System.out.println("Job is Still Running");
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Map> jobHistoryData = getSchedulerJobHistory(this.requestSpec, this.response200Spec, jobId.toString());
|
List<Map> jobHistoryData = getSchedulerJobHistory(jobId.toString());
|
||||||
|
|
||||||
Assert.assertFalse("Job History is empty :( Was it too slow? Failures in background job?", jobHistoryData.isEmpty());
|
Assert.assertFalse("Job History is empty :( Was it too slow? Failures in background job?", jobHistoryData.isEmpty());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user