[MIFOSX-1047] JUnit test cases for Scheduler Jobs
This commit is contained in:
+9
-4
@@ -47,7 +47,7 @@ public class GlobalConfigurationTest {
|
||||
configId.toString());
|
||||
Assert.assertNotNull(configDataBefore);
|
||||
|
||||
Integer value = this.globalConfigurationHelper.randomValueGenerator(1, 5);
|
||||
Integer value = Utils.randomValueGenerator(1, 5);
|
||||
|
||||
configId = this.globalConfigurationHelper.updateValueForGlobalConfiguration(this.requestSpec, this.responseSpec,
|
||||
configId.toString(), value.toString());
|
||||
@@ -87,12 +87,17 @@ public class GlobalConfigurationTest {
|
||||
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");
|
||||
|
||||
Integer cacheType = this.globalConfigurationHelper.randomValueGenerator(1, 2);
|
||||
|
||||
if (cacheType == 0 && enabled == true) {
|
||||
cacheType = 1;
|
||||
} else if (cacheType == 1 && enabled == true) {
|
||||
cacheType = 0;
|
||||
}
|
||||
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"));
|
||||
}
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
package org.mifosplatform.integrationtests;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mifosplatform.integrationtests.common.SchedulerJobHelper;
|
||||
import org.mifosplatform.integrationtests.common.Utils;
|
||||
|
||||
import com.jayway.restassured.builder.RequestSpecBuilder;
|
||||
import com.jayway.restassured.builder.ResponseSpecBuilder;
|
||||
import com.jayway.restassured.http.ContentType;
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
@SuppressWarnings({ "unused", "rawtypes", "unchecked", "static-access" })
|
||||
public class SchedulerJobsTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
private SchedulerJobHelper schedulerJobHelper;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
Utils.initializeRESTAssured();
|
||||
this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
|
||||
this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
|
||||
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSchedulerJobs() {
|
||||
this.schedulerJobHelper = new SchedulerJobHelper(this.requestSpec, this.responseSpec);
|
||||
|
||||
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"));
|
||||
|
||||
HashMap schedulerStatus = this.schedulerJobHelper.getSchedulerStatus(this.requestSpec, this.responseSpec);
|
||||
Boolean status = (Boolean) schedulerStatus.get("active");
|
||||
|
||||
}
|
||||
}
|
||||
-5
@@ -87,9 +87,4 @@ public class GlobalConfigurationHelper {
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
public static int randomValueGenerator(int minValue, int maxValue) {
|
||||
Random randValue = new Random();
|
||||
int randomNum = randValue.nextInt((maxValue - minValue) + 1) + minValue;
|
||||
return randomNum;
|
||||
}
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
package org.mifosplatform.integrationtests.common;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Random;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
@SuppressWarnings({ "unused", "rawtypes" })
|
||||
public class SchedulerJobHelper {
|
||||
|
||||
private final RequestSpecification requestSpec;
|
||||
private final ResponseSpecification responseSpec;
|
||||
|
||||
public SchedulerJobHelper(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
this.requestSpec = requestSpec;
|
||||
this.responseSpec = responseSpec;
|
||||
}
|
||||
|
||||
public static ArrayList getAllSchedulerJobs(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
final String GET_ALL_SCHEDULER_JOBS_URL = "/mifosng-provider/api/v1/jobs?tenantIdentifier=default";
|
||||
System.out.println("------------------------ RETRIEVING ALL SCHEDULER JOBS -------------------------");
|
||||
final ArrayList response = Utils.performServerGet(requestSpec, responseSpec, GET_ALL_SCHEDULER_JOBS_URL, "");
|
||||
return response;
|
||||
}
|
||||
|
||||
public static HashMap getSchedulerJobById(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String jobId) {
|
||||
final String GET_SCHEDULER_JOB_BY_ID_URL = "/mifosng-provider/api/v1/jobs/" + jobId + "?tenantIdentifier=default";
|
||||
System.out.println("------------------------ RETRIEVING SCHEDULER JOB BY ID -------------------------");
|
||||
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 HashMap updateSchedulerJob(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String jobId, final String active) {
|
||||
final String UPDATE_SCHEDULER_JOB_URL = "/mifosng-provider/api/v1/jobs/" + jobId + "?tenantIdentifier=default";
|
||||
System.out.println("------------------------ UPDATING SCHEDULER JOB -------------------------");
|
||||
final HashMap response = Utils.performServerPut(requestSpec, responseSpec, UPDATE_SCHEDULER_JOB_URL,
|
||||
updateSchedulerJobAsJSON(active), "changes");
|
||||
return response;
|
||||
}
|
||||
|
||||
public static String updateSchedulerJobAsJSON(final String active) {
|
||||
final HashMap<String, String> map = new HashMap<String, String>();
|
||||
map.put("active", active);
|
||||
System.out.println("map : " + map);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
}
|
||||
+6
@@ -103,4 +103,10 @@ 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