[MIFOSX-1047] Updated Test Cases for Scheduler Jobs
This commit is contained in:
+20
-15
@@ -47,7 +47,7 @@ public class GlobalConfigurationTest {
|
||||
configId.toString());
|
||||
Assert.assertNotNull(configDataBefore);
|
||||
|
||||
Integer value = Utils.randomValueGenerator(1, 5);
|
||||
Integer value = (Integer) configDataBefore.get("value") + 1;
|
||||
|
||||
configId = this.globalConfigurationHelper.updateValueForGlobalConfiguration(this.requestSpec, this.responseSpec,
|
||||
configId.toString(), value.toString());
|
||||
@@ -83,21 +83,26 @@ public class GlobalConfigurationTest {
|
||||
public void testGlobalConfigurationIsCacheEnabled() {
|
||||
this.globalConfigurationHelper = new GlobalConfigurationHelper(this.requestSpec, this.responseSpec);
|
||||
|
||||
// Retrieving Is Cache Enabled Global Configuration details
|
||||
final ArrayList<HashMap> isCacheGlobalConfig = this.globalConfigurationHelper.getGlobalConfigurationIsCacheEnabled(
|
||||
this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(isCacheGlobalConfig);
|
||||
Integer cacheType = Utils.randomValueGenerator(0, 1);
|
||||
Boolean enabled = (Boolean) isCacheGlobalConfig.get(cacheType).get("enabled");
|
||||
for (Integer cacheType = 1; cacheType <= 2; cacheType++) {
|
||||
// Retrieving Is Cache Enabled Global Configuration details
|
||||
final ArrayList<HashMap> isCacheGlobalConfig = this.globalConfigurationHelper.getGlobalConfigurationIsCacheEnabled(
|
||||
this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(isCacheGlobalConfig);
|
||||
HashMap cacheTypeAsHashMap = (HashMap) isCacheGlobalConfig.get(cacheType - 1).get("cacheType");
|
||||
String cacheTypeCode = (String) cacheTypeAsHashMap.get("value");
|
||||
Boolean enabled = (Boolean) isCacheGlobalConfig.get(cacheType - 1).get("enabled");
|
||||
|
||||
if (cacheType == 0 && enabled == true) {
|
||||
cacheType = 1;
|
||||
} else if (cacheType == 1 && enabled == true) {
|
||||
cacheType = 0;
|
||||
Integer cacheTypeId = (Integer) cacheTypeAsHashMap.get("id");
|
||||
|
||||
if (cacheTypeCode.compareTo("No cache") == 0 && enabled == true) {
|
||||
cacheTypeId += 1;
|
||||
} else if (cacheTypeCode.compareTo("Single node") == 0 && enabled == true) {
|
||||
cacheTypeId -= 1;
|
||||
}
|
||||
|
||||
HashMap changes = this.globalConfigurationHelper.updateIsCacheEnabledForGlobalConfiguration(this.requestSpec,
|
||||
this.responseSpec, cacheTypeId.toString());
|
||||
Assert.assertEquals("Verifying Is Cache Enabled Global Config after Updation", cacheTypeId, changes.get("cacheType"));
|
||||
}
|
||||
cacheType += 1;
|
||||
HashMap changes = this.globalConfigurationHelper.updateIsCacheEnabledForGlobalConfiguration(this.requestSpec, this.responseSpec,
|
||||
cacheType.toString());
|
||||
Assert.assertEquals("Verifying Is Cache Enabled Global Config after Updation", cacheType, changes.get("cacheType"));
|
||||
}
|
||||
}
|
||||
+46
-18
@@ -15,11 +15,12 @@ import com.jayway.restassured.http.ContentType;
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
@SuppressWarnings({ "unused", "rawtypes", "unchecked", "static-access" })
|
||||
@SuppressWarnings({ "rawtypes", "unchecked", "static-access" })
|
||||
public class SchedulerJobsTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
private ResponseSpecification responseSpecForSchedulerJob;
|
||||
private SchedulerJobHelper schedulerJobHelper;
|
||||
|
||||
@Before
|
||||
@@ -27,35 +28,62 @@ public class SchedulerJobsTest {
|
||||
Utils.initializeRESTAssured();
|
||||
this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
|
||||
this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
|
||||
this.requestSpec.header("X-Mifos-Platform-TenantId", "default");
|
||||
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
|
||||
this.responseSpecForSchedulerJob = new ResponseSpecBuilder().expectStatusCode(202).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSchedulerJobs() {
|
||||
this.schedulerJobHelper = new SchedulerJobHelper(this.requestSpec, this.responseSpec);
|
||||
|
||||
// Retrieving All Scheduler Jobs
|
||||
ArrayList<HashMap> allSchedulerJobsData = this.schedulerJobHelper.getAllSchedulerJobs(this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(allSchedulerJobsData);
|
||||
|
||||
Integer jobId = Utils.randomValueGenerator(1, 9);
|
||||
|
||||
HashMap schedulerJob = this.schedulerJobHelper.getSchedulerJobById(this.requestSpec, this.responseSpec, jobId.toString());
|
||||
Assert.assertNotNull(schedulerJob);
|
||||
|
||||
Boolean active = (Boolean) schedulerJob.get("active");
|
||||
|
||||
if (active == true) {
|
||||
active = false;
|
||||
} else {
|
||||
active = true;
|
||||
}
|
||||
|
||||
HashMap changes = this.schedulerJobHelper.updateSchedulerJob(this.requestSpec, this.responseSpec, jobId.toString(),
|
||||
active.toString());
|
||||
Assert.assertEquals("Verifying Scheduler Job Updation", active, changes.get("active"));
|
||||
|
||||
// Retrieving Status of Scheduler
|
||||
HashMap schedulerStatus = this.schedulerJobHelper.getSchedulerStatus(this.requestSpec, this.responseSpec);
|
||||
Boolean status = (Boolean) schedulerStatus.get("active");
|
||||
if (status == true) {
|
||||
this.schedulerJobHelper.updateSchedulerStatus(this.requestSpec, this.responseSpecForSchedulerJob, "stop");
|
||||
schedulerStatus = this.schedulerJobHelper.getSchedulerStatus(this.requestSpec, this.responseSpec);
|
||||
// Verifying Status of the Scheduler after updation
|
||||
Assert.assertEquals("Verifying Scheduler Job Status", false, schedulerStatus.get("active"));
|
||||
} else {
|
||||
this.schedulerJobHelper.updateSchedulerStatus(this.requestSpec, this.responseSpecForSchedulerJob, "start");
|
||||
schedulerStatus = this.schedulerJobHelper.getSchedulerStatus(this.requestSpec, this.responseSpec);
|
||||
// Verifying Status of the Scheduler after updation
|
||||
Assert.assertEquals("Verifying Scheduler Job Status", true, schedulerStatus.get("active"));
|
||||
}
|
||||
|
||||
for (Integer jobId = 1; jobId <= 9; jobId++) {
|
||||
|
||||
// Retrieving Scheduler Job by ID
|
||||
HashMap schedulerJob = this.schedulerJobHelper.getSchedulerJobById(this.requestSpec, this.responseSpec, jobId.toString());
|
||||
Assert.assertNotNull(schedulerJob);
|
||||
|
||||
Boolean active = (Boolean) schedulerJob.get("active");
|
||||
|
||||
if (active == true) {
|
||||
active = false;
|
||||
} else {
|
||||
active = true;
|
||||
}
|
||||
|
||||
// Updating Scheduler Job
|
||||
HashMap changes = this.schedulerJobHelper.updateSchedulerJob(this.requestSpec, this.responseSpec, jobId.toString(),
|
||||
active.toString());
|
||||
// Verifying Scheduler Job updation
|
||||
Assert.assertEquals("Verifying Scheduler Job Updation", active, changes.get("active"));
|
||||
|
||||
// Executing Scheduler Job
|
||||
this.schedulerJobHelper.runSchedulerJob(this.requestSpec, this.responseSpecForSchedulerJob, jobId.toString());
|
||||
ArrayList<HashMap> jobHistoryData = this.schedulerJobHelper.getSchedulerJobHistory(this.requestSpec, this.responseSpec,
|
||||
jobId.toString());
|
||||
// Verifying the Status of the Recently executed Scheduler Job
|
||||
Assert.assertEquals("Verifying Last Scheduler Job Status", "success",
|
||||
jobHistoryData.get(((jobHistoryData.size()) - 1)).get("status"));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+29
-1
@@ -33,13 +33,19 @@ public class SchedulerJobHelper {
|
||||
final HashMap response = Utils.performServerGet(requestSpec, responseSpec, GET_SCHEDULER_JOB_BY_ID_URL, "");
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
public static HashMap getSchedulerStatus(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
final String GET_SCHEDULER_STATUS_URL = "/mifosng-provider/api/v1/scheduler?tenantIdentifier=default";
|
||||
System.out.println("------------------------ RETRIEVING SCHEDULER STATUS -------------------------");
|
||||
final HashMap response = Utils.performServerGet(requestSpec, responseSpec, GET_SCHEDULER_STATUS_URL, "");
|
||||
return response;
|
||||
}
|
||||
|
||||
public static void updateSchedulerStatus(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, final String command) {
|
||||
final String UPDATE_SCHEDULER_STATUS_URL = "/mifosng-provider/api/v1/scheduler?command=" + command;
|
||||
System.out.println("------------------------ UPDATING SCHEDULER STATUS -------------------------");
|
||||
Utils.performServerPost(requestSpec, responseSpec, UPDATE_SCHEDULER_STATUS_URL, runSchedulerJobAsJSON(), null);
|
||||
}
|
||||
|
||||
public static HashMap updateSchedulerJob(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String jobId, final String active) {
|
||||
@@ -57,4 +63,26 @@ public class SchedulerJobHelper {
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
public static ArrayList getSchedulerJobHistory(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String jobId) {
|
||||
final String GET_SCHEDULER_STATUS_URL = "/mifosng-provider/api/v1/jobs/" + jobId + "/runhistory?tenantIdentifier=default";
|
||||
System.out.println("------------------------ RETRIEVING SCHEDULER JOB HISTORY -------------------------");
|
||||
final HashMap response = Utils.performServerGet(requestSpec, responseSpec, GET_SCHEDULER_STATUS_URL, "");
|
||||
return (ArrayList) response.get("pageItems");
|
||||
}
|
||||
|
||||
public static void runSchedulerJob(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String jobId) {
|
||||
final String RUN_SCHEDULER_JOB_URL = "/mifosng-provider/api/v1/jobs/" + jobId + "?command=executeJob";
|
||||
System.out.println("------------------------ RUN SCHEDULER JOB -------------------------");
|
||||
Utils.performServerPost(requestSpec, responseSpec, RUN_SCHEDULER_JOB_URL, runSchedulerJobAsJSON(), null);
|
||||
}
|
||||
|
||||
public static String runSchedulerJobAsJSON() {
|
||||
final HashMap<String, String> map = new HashMap<String, String>();
|
||||
String runSchedulerJob = new Gson().toJson(map);
|
||||
System.out.println(runSchedulerJob);
|
||||
return runSchedulerJob;
|
||||
}
|
||||
|
||||
}
|
||||
+4
-8
@@ -22,8 +22,8 @@ import com.jayway.restassured.specification.ResponseSpecification;
|
||||
public class Utils {
|
||||
|
||||
public static final String TENANT_IDENTIFIER = "tenantIdentifier=default";
|
||||
|
||||
private static final String LOGIN_URL = "/mifosng-provider/api/v1/authentication?username=mifos&password=password&"+TENANT_IDENTIFIER;
|
||||
|
||||
private static final String LOGIN_URL = "/mifosng-provider/api/v1/authentication?username=mifos&password=password&" + TENANT_IDENTIFIER;
|
||||
|
||||
public static void initializeRESTAssured() {
|
||||
RestAssured.baseURI = "https://localhost";
|
||||
@@ -57,6 +57,7 @@ public class Utils {
|
||||
final String postURL, final String jsonBodyToSend, final String jsonAttributeToGetBack) {
|
||||
final String json = given().spec(requestSpec).body(jsonBodyToSend).expect().spec(responseSpec).log().ifError().when().post(postURL)
|
||||
.andReturn().asString();
|
||||
if (jsonAttributeToGetBack == null) { return (T) json; }
|
||||
return (T) from(json).get(jsonAttributeToGetBack);
|
||||
}
|
||||
|
||||
@@ -103,10 +104,5 @@ public class Utils {
|
||||
public static String randomNameGenerator(final String prefix, final int lenOfRandomSuffix) {
|
||||
return randomStringGenerator(prefix, lenOfRandomSuffix);
|
||||
}
|
||||
|
||||
public static int randomValueGenerator(int minValue, int maxValue) {
|
||||
Random randValue = new Random();
|
||||
int randomNum = randValue.nextInt((maxValue - minValue) + 1) + minValue;
|
||||
return randomNum;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user