diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/GlobalConfigurationTest.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/GlobalConfigurationTest.java new file mode 100644 index 000000000..25a6bb7bf --- /dev/null +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/GlobalConfigurationTest.java @@ -0,0 +1,105 @@ +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.Utils; +import org.mifosplatform.integrationtests.common.GlobalConfigurationHelper; + +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({ "rawtypes", "unchecked", "static-access" }) +public class GlobalConfigurationTest { + + private ResponseSpecification responseSpec; + private RequestSpecification requestSpec; + private GlobalConfigurationHelper globalConfigurationHelper; + + @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 testGlobalConfigurations() { + this.globalConfigurationHelper = new GlobalConfigurationHelper(this.requestSpec, this.responseSpec); + + // Retrieving All Global Configuration details + final ArrayList globalConfig = this.globalConfigurationHelper.getAllGlobalConfigurations(this.requestSpec, + this.responseSpec); + Assert.assertNotNull(globalConfig); + + // Updating Value for penalty-wait-period Global Configuration + Integer configId = (Integer) globalConfig.get(7).get("id"); + Assert.assertNotNull(configId); + + HashMap configDataBefore = this.globalConfigurationHelper.getGlobalConfigurationById(this.requestSpec, this.responseSpec, + configId.toString()); + Assert.assertNotNull(configDataBefore); + + Integer value = this.globalConfigurationHelper.randomValueGenerator(1, 5); + + configId = this.globalConfigurationHelper.updateValueForGlobalConfiguration(this.requestSpec, this.responseSpec, + configId.toString(), value.toString()); + Assert.assertNotNull(configId); + + HashMap configDataAfter = this.globalConfigurationHelper.getGlobalConfigurationById(this.requestSpec, this.responseSpec, + configId.toString()); + + // Verifying Value for penalty-wait-period after Updation + Assert.assertEquals("Verifying Global Config Value after Updation", value, configDataAfter.get("value")); + + // Updating Enabled Flag for maker-checker Global Configuration + configId = (Integer) globalConfig.get(0).get("id"); + Assert.assertNotNull(configId); + + configDataBefore = this.globalConfigurationHelper.getGlobalConfigurationById(this.requestSpec, this.responseSpec, + configId.toString()); + Assert.assertNotNull(configDataBefore); + + Boolean enabled = (Boolean) globalConfig.get(0).get("enabled"); + + if (enabled == true) { + enabled = false; + } else { + enabled = true; + } + + configId = this.globalConfigurationHelper.updateEnabledFlagForGlobalConfiguration(this.requestSpec, this.responseSpec, + configId.toString(), enabled); + + configDataAfter = this.globalConfigurationHelper.getGlobalConfigurationById(this.requestSpec, this.responseSpec, + configId.toString()); + + // Verifying Enabled Flag for maker-checker after Updation + Assert.assertEquals("Verifying Enabled Flag Global Config after Updation", enabled, configDataAfter.get("enabled")); + + } + + @Test + public void testGlobalConfigurationIsCacheEnabled() { + this.globalConfigurationHelper = new GlobalConfigurationHelper(this.requestSpec, this.responseSpec); + + // Retrieving Is Cache Enabled Global Configuration details + final ArrayList isCacheGlobalConfig = this.globalConfigurationHelper.getGlobalConfigurationIsCacheEnabled( + this.requestSpec, this.responseSpec); + Assert.assertNotNull(isCacheGlobalConfig); + + Integer cacheType = this.globalConfigurationHelper.randomValueGenerator(1, 2); + + 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/common/GlobalConfigurationHelper.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/GlobalConfigurationHelper.java new file mode 100644 index 000000000..8884475c4 --- /dev/null +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/GlobalConfigurationHelper.java @@ -0,0 +1,95 @@ +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 GlobalConfigurationHelper { + + private final RequestSpecification requestSpec; + private final ResponseSpecification responseSpec; + + public GlobalConfigurationHelper(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { + this.requestSpec = requestSpec; + this.responseSpec = responseSpec; + } + + public static ArrayList getAllGlobalConfigurations(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { + final String GET_ALL_GLOBAL_CONFIG_URL = "/mifosng-provider/api/v1/configurations?tenantIdentifier=default"; + System.out.println("------------------------ RETRIEVING ALL GLOBAL CONFIGURATIONS -------------------------"); + final HashMap response = Utils.performServerGet(requestSpec, responseSpec, GET_ALL_GLOBAL_CONFIG_URL, ""); + return (ArrayList) response.get("globalConfiguration"); + } + + public static HashMap getGlobalConfigurationById(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final String configId) { + final String GET_GLOBAL_CONFIG_BY_ID_URL = "/mifosng-provider/api/v1/configurations/" + configId + "?tenantIdentifier=default"; + System.out.println("------------------------ RETRIEVING GLOBAL CONFIGURATION BY ID -------------------------"); + return Utils.performServerGet(requestSpec, responseSpec, GET_GLOBAL_CONFIG_BY_ID_URL, ""); + } + + public static Integer updateValueForGlobalConfiguration(final RequestSpecification requestSpec, + final ResponseSpecification responseSpec, final String configId, final String value) { + final String GLOBAL_CONFIG_UPDATE_URL = "/mifosng-provider/api/v1/configurations/" + configId + "?tenantIdentifier=default"; + System.out.println("---------------------------------UPDATE VALUE FOR GLOBAL CONFIG---------------------------------------------"); + return Utils.performServerPut(requestSpec, responseSpec, GLOBAL_CONFIG_UPDATE_URL, updateGlobalConfigUpdateValueAsJSON(value), + "resourceId"); + } + + public static Integer updateEnabledFlagForGlobalConfiguration(final RequestSpecification requestSpec, + final ResponseSpecification responseSpec, final String configId, final Boolean enabled) { + final String GLOBAL_CONFIG_UPDATE_URL = "/mifosng-provider/api/v1/configurations/" + configId + "?tenantIdentifier=default"; + System.out + .println("---------------------------------UPDATE GLOBAL CONFIG FOR ENABLED FLAG---------------------------------------------"); + return Utils.performServerPut(requestSpec, responseSpec, GLOBAL_CONFIG_UPDATE_URL, + updateGlobalConfigUpdateEnabledFlagAsJSON(enabled), "resourceId"); + } + + public static ArrayList getGlobalConfigurationIsCacheEnabled(final RequestSpecification requestSpec, + final ResponseSpecification responseSpec) { + final String GET_IS_CACHE_GLOBAL_CONFIG_URL = "/mifosng-provider/api/v1/caches?tenantIdentifier=default"; + System.out.println("------------------------ RETRIEVING IS CACHE ENABLED GLOBAL CONFIGURATION -------------------------"); + final ArrayList response = Utils.performServerGet(requestSpec, responseSpec, GET_IS_CACHE_GLOBAL_CONFIG_URL, ""); + return response; + } + + public static HashMap updateIsCacheEnabledForGlobalConfiguration(final RequestSpecification requestSpec, + final ResponseSpecification responseSpec, final String cacheType) { + final String IS_CACHE_GLOBAL_CONFIG_UPDATE_URL = "/mifosng-provider/api/v1/caches?tenantIdentifier=default"; + System.out.println("------------------UPDATE GLOBAL CONFIG FOR IS CACHE ENABLED----------------------"); + return Utils.performServerPut(requestSpec, responseSpec, IS_CACHE_GLOBAL_CONFIG_UPDATE_URL, + updateIsCacheEnabledGlobalConfigUpdateAsJSON(cacheType), "changes"); + } + + public static String updateGlobalConfigUpdateValueAsJSON(final String value) { + final HashMap map = new HashMap(); + map.put("value", value); + System.out.println("map : " + map); + return new Gson().toJson(map); + } + + public static String updateGlobalConfigUpdateEnabledFlagAsJSON(final Boolean enabled) { + final HashMap map = new HashMap(); + map.put("enabled", enabled); + System.out.println("map : " + map); + return new Gson().toJson(map); + } + + public static String updateIsCacheEnabledGlobalConfigUpdateAsJSON(final String cacheType) { + final HashMap map = new HashMap(); + map.put("cacheType", cacheType); + System.out.println("map : " + map); + 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