[MIFOSX-1047] Updated Test Cases for Scheduler Jobs
This commit is contained in:
+20
-15
@@ -47,7 +47,7 @@ public class GlobalConfigurationTest {
|
|||||||
configId.toString());
|
configId.toString());
|
||||||
Assert.assertNotNull(configDataBefore);
|
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 = this.globalConfigurationHelper.updateValueForGlobalConfiguration(this.requestSpec, this.responseSpec,
|
||||||
configId.toString(), value.toString());
|
configId.toString(), value.toString());
|
||||||
@@ -83,21 +83,26 @@ public class GlobalConfigurationTest {
|
|||||||
public void testGlobalConfigurationIsCacheEnabled() {
|
public void testGlobalConfigurationIsCacheEnabled() {
|
||||||
this.globalConfigurationHelper = new GlobalConfigurationHelper(this.requestSpec, this.responseSpec);
|
this.globalConfigurationHelper = new GlobalConfigurationHelper(this.requestSpec, this.responseSpec);
|
||||||
|
|
||||||
// Retrieving Is Cache Enabled Global Configuration details
|
for (Integer cacheType = 1; cacheType <= 2; cacheType++) {
|
||||||
final ArrayList<HashMap> isCacheGlobalConfig = this.globalConfigurationHelper.getGlobalConfigurationIsCacheEnabled(
|
// Retrieving Is Cache Enabled Global Configuration details
|
||||||
this.requestSpec, this.responseSpec);
|
final ArrayList<HashMap> isCacheGlobalConfig = this.globalConfigurationHelper.getGlobalConfigurationIsCacheEnabled(
|
||||||
Assert.assertNotNull(isCacheGlobalConfig);
|
this.requestSpec, this.responseSpec);
|
||||||
Integer cacheType = Utils.randomValueGenerator(0, 1);
|
Assert.assertNotNull(isCacheGlobalConfig);
|
||||||
Boolean enabled = (Boolean) isCacheGlobalConfig.get(cacheType).get("enabled");
|
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) {
|
Integer cacheTypeId = (Integer) cacheTypeAsHashMap.get("id");
|
||||||
cacheType = 1;
|
|
||||||
} else if (cacheType == 1 && enabled == true) {
|
if (cacheTypeCode.compareTo("No cache") == 0 && enabled == true) {
|
||||||
cacheType = 0;
|
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.RequestSpecification;
|
||||||
import com.jayway.restassured.specification.ResponseSpecification;
|
import com.jayway.restassured.specification.ResponseSpecification;
|
||||||
|
|
||||||
@SuppressWarnings({ "unused", "rawtypes", "unchecked", "static-access" })
|
@SuppressWarnings({ "rawtypes", "unchecked", "static-access" })
|
||||||
public class SchedulerJobsTest {
|
public class SchedulerJobsTest {
|
||||||
|
|
||||||
private ResponseSpecification responseSpec;
|
private ResponseSpecification responseSpec;
|
||||||
private RequestSpecification requestSpec;
|
private RequestSpecification requestSpec;
|
||||||
|
private ResponseSpecification responseSpecForSchedulerJob;
|
||||||
private SchedulerJobHelper schedulerJobHelper;
|
private SchedulerJobHelper schedulerJobHelper;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
@@ -27,35 +28,62 @@ public class SchedulerJobsTest {
|
|||||||
Utils.initializeRESTAssured();
|
Utils.initializeRESTAssured();
|
||||||
this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
|
this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
|
||||||
this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
|
this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
|
||||||
|
this.requestSpec.header("X-Mifos-Platform-TenantId", "default");
|
||||||
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
|
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
|
||||||
|
this.responseSpecForSchedulerJob = new ResponseSpecBuilder().expectStatusCode(202).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSchedulerJobs() {
|
public void testSchedulerJobs() {
|
||||||
this.schedulerJobHelper = new SchedulerJobHelper(this.requestSpec, this.responseSpec);
|
this.schedulerJobHelper = new SchedulerJobHelper(this.requestSpec, this.responseSpec);
|
||||||
|
|
||||||
|
// Retrieving All Scheduler Jobs
|
||||||
ArrayList<HashMap> allSchedulerJobsData = this.schedulerJobHelper.getAllSchedulerJobs(this.requestSpec, this.responseSpec);
|
ArrayList<HashMap> allSchedulerJobsData = this.schedulerJobHelper.getAllSchedulerJobs(this.requestSpec, this.responseSpec);
|
||||||
Assert.assertNotNull(allSchedulerJobsData);
|
Assert.assertNotNull(allSchedulerJobsData);
|
||||||
|
|
||||||
Integer jobId = Utils.randomValueGenerator(1, 9);
|
// Retrieving Status of Scheduler
|
||||||
|
|
||||||
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"));
|
|
||||||
|
|
||||||
HashMap schedulerStatus = this.schedulerJobHelper.getSchedulerStatus(this.requestSpec, this.responseSpec);
|
HashMap schedulerStatus = this.schedulerJobHelper.getSchedulerStatus(this.requestSpec, this.responseSpec);
|
||||||
Boolean status = (Boolean) schedulerStatus.get("active");
|
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"));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+28
@@ -41,6 +41,12 @@ public class SchedulerJobHelper {
|
|||||||
return response;
|
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,
|
public static HashMap updateSchedulerJob(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||||
final String jobId, final String active) {
|
final String jobId, final String active) {
|
||||||
final String UPDATE_SCHEDULER_JOB_URL = "/mifosng-provider/api/v1/jobs/" + jobId + "?tenantIdentifier=default";
|
final String UPDATE_SCHEDULER_JOB_URL = "/mifosng-provider/api/v1/jobs/" + jobId + "?tenantIdentifier=default";
|
||||||
@@ -57,4 +63,26 @@ public class SchedulerJobHelper {
|
|||||||
return new Gson().toJson(map);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+2
-6
@@ -23,7 +23,7 @@ public class Utils {
|
|||||||
|
|
||||||
public static final String TENANT_IDENTIFIER = "tenantIdentifier=default";
|
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() {
|
public static void initializeRESTAssured() {
|
||||||
RestAssured.baseURI = "https://localhost";
|
RestAssured.baseURI = "https://localhost";
|
||||||
@@ -57,6 +57,7 @@ public class Utils {
|
|||||||
final String postURL, final String jsonBodyToSend, final String jsonAttributeToGetBack) {
|
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)
|
final String json = given().spec(requestSpec).body(jsonBodyToSend).expect().spec(responseSpec).log().ifError().when().post(postURL)
|
||||||
.andReturn().asString();
|
.andReturn().asString();
|
||||||
|
if (jsonAttributeToGetBack == null) { return (T) json; }
|
||||||
return (T) from(json).get(jsonAttributeToGetBack);
|
return (T) from(json).get(jsonAttributeToGetBack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,9 +105,4 @@ public class Utils {
|
|||||||
return randomStringGenerator(prefix, 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