Merge pull request #826 from Vishwa1311/MIFOSX-1026_1

[MIFOSX-1026] JUnit Test Cases for Global Configuration
This commit is contained in:
Vishwas Babu A J
2014-03-28 19:31:58 -07:00
2 changed files with 200 additions and 0 deletions
@@ -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<HashMap> 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<HashMap> 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"));
}
}
@@ -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<HashMap> 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<String, String> map = new HashMap<String, String>();
map.put("value", value);
System.out.println("map : " + map);
return new Gson().toJson(map);
}
public static String updateGlobalConfigUpdateEnabledFlagAsJSON(final Boolean enabled) {
final HashMap<String, Boolean> map = new HashMap<String, Boolean>();
map.put("enabled", enabled);
System.out.println("map : " + map);
return new Gson().toJson(map);
}
public static String updateIsCacheEnabledGlobalConfigUpdateAsJSON(final String cacheType) {
final HashMap<String, String> map = new HashMap<String, String>();
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;
}
}