diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/GlobalConfigurationTest.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/GlobalConfigurationTest.java index ce3e6579d..97e849e0a 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/GlobalConfigurationTest.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/GlobalConfigurationTest.java @@ -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 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")); } } \ No newline at end of file diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/SchedulerJobsTest.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/SchedulerJobsTest.java new file mode 100644 index 000000000..e15945739 --- /dev/null +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/SchedulerJobsTest.java @@ -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 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"); + + } +} \ No newline at end of file diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/GlobalConfigurationHelper.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/GlobalConfigurationHelper.java index 8884475c4..53d3fdd8c 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/GlobalConfigurationHelper.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/GlobalConfigurationHelper.java @@ -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; - } } \ No newline at end of file diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/SchedulerJobHelper.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/SchedulerJobHelper.java new file mode 100644 index 000000000..ca7139ff1 --- /dev/null +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/SchedulerJobHelper.java @@ -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 map = new HashMap(); + map.put("active", active); + System.out.println("map : " + map); + return new Gson().toJson(map); + } + +} \ No newline at end of file diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/Utils.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/Utils.java index f4a41a9a7..614301bfe 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/Utils.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/Utils.java @@ -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; + } }