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:
Michael Vorburger
2020-05-03 19:49:27 +02:00
committed by Michael Vorburger ⛑️
parent 85bf8dc3e9
commit 2212675af4
3 changed files with 22 additions and 30 deletions
@@ -25,7 +25,6 @@ import static org.junit.Assert.assertNotNull;
import io.restassured.builder.RequestSpecBuilder;
import io.restassured.http.ContentType;
import io.restassured.specification.RequestSpecification;
import io.restassured.specification.ResponseSpecification;
import java.util.List;
import java.util.Map;
import org.apache.fineract.integrationtests.common.SchedulerJobHelper;
@@ -37,7 +36,6 @@ import org.junit.Test;
@SuppressWarnings({ "rawtypes", "unchecked", "static-access" })
public class SchedulerJobsTest {
private ResponseSpecification responseSpec;
private RequestSpecification requestSpec;
private SchedulerJobHelper schedulerJobHelper;
@@ -51,7 +49,7 @@ public class SchedulerJobsTest {
}
@Test
public void testGetAndUpdateSchedulerStatus() throws InterruptedException {
public void testFlippingSchedulerStatus() throws InterruptedException {
// Retrieving Status of Scheduler
Boolean schedulerStatus = this.schedulerJobHelper.getSchedulerStatus();
if (schedulerStatus == true) {
@@ -71,15 +69,14 @@ public class SchedulerJobsTest {
@Ignore // TODO FINERACT-852
public void testSchedulerJobs() throws InterruptedException {
// Retrieving All Scheduler Jobs
List<Map> allSchedulerJobsData = this.schedulerJobHelper.getAllSchedulerJobs(this.requestSpec, this.responseSpec);
List<Map> allSchedulerJobsData = this.schedulerJobHelper.getAllSchedulerJobs();
assertNotNull(allSchedulerJobsData);
for (Integer jobIndex = 0; jobIndex < allSchedulerJobsData.size(); jobIndex++) {
Integer jobId = (Integer) allSchedulerJobsData.get(jobIndex).get("jobId");
// 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);
Boolean active = (Boolean) schedulerJob.get("active");
@@ -91,8 +88,7 @@ public class SchedulerJobsTest {
}
// Updating Scheduler Job
Map changes = this.schedulerJobHelper.updateSchedulerJob(this.requestSpec, this.responseSpec, jobId.toString(),
active.toString());
Map changes = this.schedulerJobHelper.updateSchedulerJob(jobId.toString(), active.toString());
// Verifying Scheduler Job updates
assertEquals("Verifying Scheduler Job Updates", active, changes.get("active"));
@@ -100,18 +96,17 @@ public class SchedulerJobsTest {
this.schedulerJobHelper.runSchedulerJob(this.requestSpec, jobId.toString());
// Retrieving Scheduler Job by ID
schedulerJob = this.schedulerJobHelper.getSchedulerJobById(this.requestSpec, this.responseSpec, jobId.toString());
schedulerJob = this.schedulerJobHelper.getSchedulerJobById(jobId.toString());
assertNotNull(schedulerJob);
// Waiting for Job to complete
while ((Boolean) schedulerJob.get("currentlyRunning") == true) {
Thread.sleep(15000);
schedulerJob = this.schedulerJobHelper.getSchedulerJobById(this.requestSpec, this.responseSpec, jobId.toString());
Thread.sleep(500);
schedulerJob = this.schedulerJobHelper.getSchedulerJobById(jobId.toString());
assertNotNull(schedulerJob);
System.out.println("Job " +jobId.toString() +" is Still Running");
}
List<Map> jobHistoryData = this.schedulerJobHelper.getSchedulerJobHistory(this.requestSpec, this.responseSpec,
jobId.toString());
List<Map> jobHistoryData = this.schedulerJobHelper.getSchedulerJobHistory(jobId.toString());
// Verifying the Status of the Recently executed Scheduler Job
assertFalse("Job History is empty :( Was it too slow? Failures in background job?", jobHistoryData.isEmpty());
@@ -772,12 +772,12 @@ public class SchedulerJobsTestResults {
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);
while ((Boolean) schedulerJob.get("currentlyRunning") == true) {
Thread.sleep(15000);
schedulerJob = this.schedulerJobHelper.getSchedulerJobById(this.requestSpec, this.responseSpec, jobId.toString());
schedulerJob = this.schedulerJobHelper.getSchedulerJobById(jobId.toString());
Assert.assertNotNull(schedulerJob);
}
@@ -47,18 +47,17 @@ public class SchedulerJobHelper {
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;
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;
}
public static HashMap getSchedulerJobById(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
final String jobId) {
public HashMap getSchedulerJobById(final String jobId) {
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 -------------------------");
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;
}
@@ -75,11 +74,10 @@ public class SchedulerJobHelper {
Utils.performServerPost(requestSpec, response202Spec, UPDATE_SCHEDULER_STATUS_URL, runSchedulerJobAsJSON(), null);
}
public static Map updateSchedulerJob(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
final String jobId, final String active) {
public Map updateSchedulerJob(final String jobId, final String active) {
final String UPDATE_SCHEDULER_JOB_URL = "/fineract-provider/api/v1/jobs/" + jobId + "?" + Utils.TENANT_IDENTIFIER;
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");
return response;
}
@@ -91,11 +89,10 @@ public class SchedulerJobHelper {
return new Gson().toJson(map);
}
public static List getSchedulerJobHistory(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
final String jobId) {
public List getSchedulerJobHistory(final String jobId) {
final String GET_SCHEDULER_STATUS_URL = "/fineract-provider/api/v1/jobs/" + jobId + "/runhistory?" + Utils.TENANT_IDENTIFIER;
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");
}
@@ -114,7 +111,7 @@ public class SchedulerJobHelper {
}
public void executeJob(String jobName) throws InterruptedException {
List<Map> allSchedulerJobsData = getAllSchedulerJobs(this.requestSpec, this.response200Spec);
List<Map> allSchedulerJobsData = getAllSchedulerJobs();
Assert.assertNotNull(allSchedulerJobsData);
for (Integer jobIndex = 0; jobIndex < allSchedulerJobsData.size(); jobIndex++) {
@@ -125,18 +122,18 @@ public class SchedulerJobHelper {
runSchedulerJob(this.requestSpec, jobId.toString());
// Retrieving Scheduler Job by ID
Map schedulerJob = getSchedulerJobById(this.requestSpec, this.response200Spec, jobId.toString());
Map schedulerJob = getSchedulerJobById(jobId.toString());
Assert.assertNotNull(schedulerJob);
// Waiting for Job to complete
while ((Boolean) schedulerJob.get("currentlyRunning") == true) {
Thread.sleep(15000);
schedulerJob = getSchedulerJobById(this.requestSpec, this.response200Spec, jobId.toString());
schedulerJob = getSchedulerJobById(jobId.toString());
Assert.assertNotNull(schedulerJob);
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());