FINERACT-1593: Bugfixes for Client Address creation

This commit is contained in:
Arnold Galovics
2022-04-26 13:48:23 +02:00
committed by Arnold Gálovics
parent df5718ad04
commit 9d212ba471
16 changed files with 434 additions and 258 deletions
@@ -18,6 +18,7 @@
*/
package org.apache.fineract.integrationtests;
import static org.apache.fineract.integrationtests.client.IntegrationTest.assertThat;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
@@ -29,122 +30,133 @@ import io.restassured.specification.ResponseSpecification;
import java.security.SecureRandom;
import java.util.HashMap;
import java.util.List;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.fineract.client.models.GetClientClientIdAddressesResponse;
import org.apache.fineract.client.models.GlobalConfigurationPropertyData;
import org.apache.fineract.client.models.PostClientClientIdAddressesRequest;
import org.apache.fineract.client.models.PostClientClientIdAddressesResponse;
import org.apache.fineract.client.models.PostClientsAddressRequest;
import org.apache.fineract.client.models.PostClientsRequest;
import org.apache.fineract.integrationtests.common.ClientHelper;
import org.apache.fineract.integrationtests.common.GlobalConfigurationHelper;
import org.apache.fineract.integrationtests.common.Utils;
import org.apache.fineract.integrationtests.common.system.CodeHelper;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
public class ClientTest {
private static final SecureRandom rand = new SecureRandom();
private ResponseSpecification responseSpec;
private RequestSpecification requestSpec;
private ClientHelper clientHelper;
private static final SecureRandom rand = new SecureRandom();
@BeforeEach
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();
this.clientHelper = new ClientHelper(this.requestSpec, this.responseSpec);
requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
clientHelper = new ClientHelper(requestSpec, responseSpec);
}
@AfterEach
public void tearDown() {
GlobalConfigurationHelper.resetAllDefaultGlobalConfigurations(requestSpec, responseSpec);
GlobalConfigurationHelper.verifyAllDefaultGlobalConfigurations(requestSpec, responseSpec);
}
@Test
public void testClientStatus() {
final Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec);
ClientHelper.verifyClientCreatedOnServer(this.requestSpec, this.responseSpec, clientId);
// Assertions.assertNotNull(clientId);
final Integer clientId = ClientHelper.createClient(requestSpec, responseSpec);
ClientHelper.verifyClientCreatedOnServer(requestSpec, responseSpec, clientId);
HashMap<String, Object> status = ClientHelper.getClientStatus(requestSpec, responseSpec, String.valueOf(clientId));
ClientStatusChecker.verifyClientIsActive(status);
HashMap<String, Object> clientStatusHashMap = this.clientHelper.closeClient(clientId);
HashMap<String, Object> clientStatusHashMap = clientHelper.closeClient(clientId);
ClientStatusChecker.verifyClientClosed(clientStatusHashMap);
clientStatusHashMap = this.clientHelper.reactivateClient(clientId);
clientStatusHashMap = clientHelper.reactivateClient(clientId);
ClientStatusChecker.verifyClientPending(clientStatusHashMap);
clientStatusHashMap = this.clientHelper.rejectClient(clientId);
clientStatusHashMap = clientHelper.rejectClient(clientId);
ClientStatusChecker.verifyClientRejected(clientStatusHashMap);
clientStatusHashMap = this.clientHelper.activateClient(clientId);
clientStatusHashMap = clientHelper.activateClient(clientId);
ClientStatusChecker.verifyClientActiavted(clientStatusHashMap);
clientStatusHashMap = this.clientHelper.closeClient(clientId);
clientStatusHashMap = clientHelper.closeClient(clientId);
ClientStatusChecker.verifyClientClosed(clientStatusHashMap);
clientStatusHashMap = this.clientHelper.reactivateClient(clientId);
clientStatusHashMap = clientHelper.reactivateClient(clientId);
ClientStatusChecker.verifyClientPending(clientStatusHashMap);
clientStatusHashMap = this.clientHelper.withdrawClient(clientId);
clientStatusHashMap = clientHelper.withdrawClient(clientId);
ClientStatusChecker.verifyClientWithdrawn(clientStatusHashMap);
}
@Test
public void testClientAsPersonStatus() {
final Integer clientId = ClientHelper.createClientAsPerson(this.requestSpec, this.responseSpec);
ClientHelper.verifyClientCreatedOnServer(this.requestSpec, this.responseSpec, clientId);
// Assertions.assertNotNull(clientId);
final Integer clientId = ClientHelper.createClientAsPerson(requestSpec, responseSpec);
ClientHelper.verifyClientCreatedOnServer(requestSpec, responseSpec, clientId);
HashMap<String, Object> status = ClientHelper.getClientStatus(requestSpec, responseSpec, String.valueOf(clientId));
ClientStatusChecker.verifyClientIsActive(status);
HashMap<String, Object> clientStatusHashMap = this.clientHelper.closeClient(clientId);
HashMap<String, Object> clientStatusHashMap = clientHelper.closeClient(clientId);
ClientStatusChecker.verifyClientClosed(clientStatusHashMap);
clientStatusHashMap = this.clientHelper.reactivateClient(clientId);
clientStatusHashMap = clientHelper.reactivateClient(clientId);
ClientStatusChecker.verifyClientPending(clientStatusHashMap);
clientStatusHashMap = this.clientHelper.rejectClient(clientId);
clientStatusHashMap = clientHelper.rejectClient(clientId);
ClientStatusChecker.verifyClientRejected(clientStatusHashMap);
clientStatusHashMap = this.clientHelper.activateClient(clientId);
clientStatusHashMap = clientHelper.activateClient(clientId);
ClientStatusChecker.verifyClientActiavted(clientStatusHashMap);
clientStatusHashMap = this.clientHelper.closeClient(clientId);
clientStatusHashMap = clientHelper.closeClient(clientId);
ClientStatusChecker.verifyClientClosed(clientStatusHashMap);
clientStatusHashMap = this.clientHelper.reactivateClient(clientId);
clientStatusHashMap = clientHelper.reactivateClient(clientId);
ClientStatusChecker.verifyClientPending(clientStatusHashMap);
clientStatusHashMap = this.clientHelper.withdrawClient(clientId);
clientStatusHashMap = clientHelper.withdrawClient(clientId);
ClientStatusChecker.verifyClientWithdrawn(clientStatusHashMap);
}
@Test
public void testClientAsEntityStatus() {
final Integer clientId = ClientHelper.createClientAsEntity(this.requestSpec, this.responseSpec);
ClientHelper.verifyClientCreatedOnServer(this.requestSpec, this.responseSpec, clientId);
// Assertions.assertNotNull(clientId);
final Integer clientId = ClientHelper.createClientAsEntity(requestSpec, responseSpec);
ClientHelper.verifyClientCreatedOnServer(requestSpec, responseSpec, clientId);
HashMap<String, Object> status = ClientHelper.getClientStatus(requestSpec, responseSpec, String.valueOf(clientId));
ClientStatusChecker.verifyClientIsActive(status);
HashMap<String, Object> clientStatusHashMap = this.clientHelper.closeClient(clientId);
HashMap<String, Object> clientStatusHashMap = clientHelper.closeClient(clientId);
ClientStatusChecker.verifyClientClosed(clientStatusHashMap);
clientStatusHashMap = this.clientHelper.reactivateClient(clientId);
clientStatusHashMap = clientHelper.reactivateClient(clientId);
ClientStatusChecker.verifyClientPending(clientStatusHashMap);
clientStatusHashMap = this.clientHelper.rejectClient(clientId);
clientStatusHashMap = clientHelper.rejectClient(clientId);
ClientStatusChecker.verifyClientRejected(clientStatusHashMap);
clientStatusHashMap = this.clientHelper.activateClient(clientId);
clientStatusHashMap = clientHelper.activateClient(clientId);
ClientStatusChecker.verifyClientActiavted(clientStatusHashMap);
clientStatusHashMap = this.clientHelper.closeClient(clientId);
clientStatusHashMap = clientHelper.closeClient(clientId);
ClientStatusChecker.verifyClientClosed(clientStatusHashMap);
clientStatusHashMap = this.clientHelper.reactivateClient(clientId);
clientStatusHashMap = clientHelper.reactivateClient(clientId);
ClientStatusChecker.verifyClientPending(clientStatusHashMap);
clientStatusHashMap = this.clientHelper.withdrawClient(clientId);
clientStatusHashMap = clientHelper.withdrawClient(clientId);
ClientStatusChecker.verifyClientWithdrawn(clientStatusHashMap);
}
@@ -157,11 +169,11 @@ public class ClientTest {
// Add a few clients to the server and activate a random amount of them
for (int i = 0; i < 15; i++) {
final Integer clientId = ClientHelper.createClientAsEntity(this.requestSpec, this.responseSpec);
final Integer clientId = ClientHelper.createClientAsEntity(requestSpec, responseSpec);
if (rand.nextInt(10) % 2 == 0) {
// Takes Client to pending status
this.clientHelper.closeClient(clientId);
this.clientHelper.reactivateClient(clientId);
clientHelper.closeClient(clientId);
clientHelper.reactivateClient(clientId);
}
// Other clients stay in Active status
}
@@ -182,4 +194,73 @@ public class ClientTest {
}
}
@Test
public void testClientAddressCreationWorks() {
// given
GlobalConfigurationPropertyData addressEnabledConfig = GlobalConfigurationHelper.getGlobalConfigurationByName(requestSpec,
responseSpec, "Enable-Address");
Long configId = addressEnabledConfig.getId();
GlobalConfigurationHelper.updateEnabledFlagForGlobalConfiguration(requestSpec, responseSpec, configId, true);
GlobalConfigurationPropertyData updatedAddressEnabledConfig = GlobalConfigurationHelper.getGlobalConfigurationByName(requestSpec,
responseSpec, "Enable-Address");
boolean isAddressEnabled = BooleanUtils.toBoolean(updatedAddressEnabledConfig.getEnabled());
assertThat(isAddressEnabled).isTrue();
Integer addressTypeId = CodeHelper.createAddressTypeCodeValue(requestSpec, responseSpec,
Utils.randomNameGenerator("Residential address", 4), 0);
Integer countryId = CodeHelper.createCountryCodeValue(requestSpec, responseSpec, Utils.randomNameGenerator("Hungary", 4), 0);
Integer stateId = CodeHelper.createStateCodeValue(requestSpec, responseSpec, Utils.randomNameGenerator("Budapest", 4), 0);
String city = "Budapest";
boolean addressIsActive = true;
long postalCode = 1000L;
// when
PostClientsAddressRequest addressRequest = new PostClientsAddressRequest().postalCode(postalCode).city(city).countryId(countryId)
.stateProvinceId(stateId).addressTypeId(addressTypeId.longValue()).isActive(addressIsActive);
PostClientsRequest request = ClientHelper.defaultClientCreationRequest().address(List.of(addressRequest));
final Integer clientId = ClientHelper.createClient(requestSpec, responseSpec, request);
// then
ClientHelper.verifyClientCreatedOnServer(requestSpec, responseSpec, clientId);
List<GetClientClientIdAddressesResponse> clientAddresses = ClientHelper.getClientAddresses(requestSpec, responseSpec, clientId);
GetClientClientIdAddressesResponse addressResponse = clientAddresses.get(0);
assertThat(addressResponse.getCity()).isEqualTo(city);
assertThat(addressResponse.getCountryId()).isEqualTo(countryId);
assertThat(addressResponse.getStateProvinceId()).isEqualTo(stateId);
assertThat(addressResponse.getAddressTypeId()).isEqualTo(addressTypeId);
assertThat(addressResponse.getIsActive()).isEqualTo(addressIsActive);
assertThat(addressResponse.getPostalCode()).isEqualTo(postalCode);
}
@Test
public void testClientAddressCreationWorksAfterClientIsCreated() {
// given
Integer addressTypeId = CodeHelper.createAddressTypeCodeValue(requestSpec, responseSpec,
Utils.randomNameGenerator("Residential address", 4), 0);
Integer countryId = CodeHelper.createCountryCodeValue(requestSpec, responseSpec, Utils.randomNameGenerator("Hungary", 4), 0);
Integer stateId = CodeHelper.createStateCodeValue(requestSpec, responseSpec, Utils.randomNameGenerator("Budapest", 4), 0);
String city = "Budapest";
boolean addressIsActive = true;
long postalCode = 1000L;
PostClientsRequest clientRequest = ClientHelper.defaultClientCreationRequest();
final Integer clientId = ClientHelper.createClient(requestSpec, responseSpec, clientRequest);
// when
PostClientClientIdAddressesRequest request = new PostClientClientIdAddressesRequest().postalCode(postalCode).city(city)
.countryId(countryId).stateProvinceId(stateId).isActive(addressIsActive);
PostClientClientIdAddressesResponse response = ClientHelper.createClientAddress(requestSpec, responseSpec, clientId.longValue(),
addressTypeId, request);
// then
assertThat(response.getResourceId()).isNotNull();
List<GetClientClientIdAddressesResponse> clientAddresses = ClientHelper.getClientAddresses(requestSpec, responseSpec, clientId);
GetClientClientIdAddressesResponse addressResponse = clientAddresses.get(0);
assertThat(addressResponse.getCity()).isEqualTo(city);
assertThat(addressResponse.getCountryId()).isEqualTo(countryId);
assertThat(addressResponse.getStateProvinceId()).isEqualTo(stateId);
assertThat(addressResponse.getAddressTypeId()).isEqualTo(addressTypeId);
assertThat(addressResponse.getIsActive()).isEqualTo(addressIsActive);
assertThat(addressResponse.getPostalCode()).isEqualTo(postalCode);
}
}
@@ -20,6 +20,7 @@ package org.apache.fineract.integrationtests.common;
import static org.junit.jupiter.api.Assertions.assertEquals;
import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import io.restassured.specification.RequestSpecification;
import io.restassured.specification.ResponseSpecification;
@@ -33,19 +34,23 @@ import java.util.LinkedHashMap;
import java.util.List;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.fineract.client.models.GetClientClientIdAddressesResponse;
import org.apache.fineract.client.models.GetClientsClientIdResponse;
import org.apache.fineract.client.models.PostClientClientIdAddressesRequest;
import org.apache.fineract.client.models.PostClientClientIdAddressesResponse;
import org.apache.fineract.client.models.PostClientsRequest;
import org.apache.fineract.client.util.JSON;
import org.apache.fineract.infrastructure.bulkimport.data.GlobalEntityType;
import org.apache.fineract.integrationtests.common.system.CodeHelper;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Slf4j
@RequiredArgsConstructor
public class ClientHelper {
private static final Logger LOG = LoggerFactory.getLogger(ClientHelper.class);
private final RequestSpecification requestSpec;
private final ResponseSpecification responseSpec;
private static final String CREATE_CLIENT_URL = "/fineract-provider/api/v1/clients?" + Utils.TENANT_IDENTIFIER;
private static final String CLIENT_URL = "/fineract-provider/api/v1/clients";
private static final String CLOSE_CLIENT_COMMAND = "close";
@@ -67,9 +72,16 @@ public class ClientHelper {
public static final String DATE_FORMAT = "dd MMMM yyyy";
public static final String DATE_TIME_FORMAT = "dd MMMM yyyy HH:mm";
public ClientHelper(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
this.requestSpec = requestSpec;
this.responseSpec = responseSpec;
private static final Gson GSON = new JSON().getGson();
private final RequestSpecification requestSpec;
private final ResponseSpecification responseSpec;
public static Integer createClient(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
PostClientsRequest request) {
log.info("---------------------------------CREATING A CLIENT---------------------------------------------");
String requestBody = GSON.toJson(request);
return Utils.performServerPost(requestSpec, responseSpec, CREATE_CLIENT_URL, requestBody, "clientId");
}
public static Integer createClient(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
@@ -83,11 +95,21 @@ public class ClientHelper {
public static Integer createClient(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
final String activationDate, final String officeId) {
LOG.info("---------------------------------CREATING A CLIENT---------------------------------------------");
log.info("---------------------------------CREATING A CLIENT---------------------------------------------");
return Utils.performServerPost(requestSpec, responseSpec, CREATE_CLIENT_URL, getTestClientAsJSON(activationDate, officeId),
"clientId");
}
public static PostClientClientIdAddressesResponse createClientAddress(final RequestSpecification requestSpec,
final ResponseSpecification responseSpec, long clientId, long addressTypeId, PostClientClientIdAddressesRequest request) {
final String CREATE_CLIENT_ADDRESS_URL = "/fineract-provider/api/v1/client/" + clientId + "/addresses?type=" + addressTypeId + "&"
+ Utils.TENANT_IDENTIFIER;
log.info("---------------------------------CREATING A CLIENT ADDRESS ---------------------------------------------");
String requestBody = GSON.toJson(request);
String response = Utils.performServerPost(requestSpec, responseSpec, CREATE_CLIENT_ADDRESS_URL, requestBody);
return GSON.fromJson(response, PostClientClientIdAddressesResponse.class);
}
public static Integer createClientPending(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
return createClientPending(requestSpec, responseSpec, "04 March 2014");
}
@@ -99,20 +121,20 @@ public class ClientHelper {
public static Integer createClientPending(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
final String submittedOnDate, final String officeId) {
LOG.info("---------------------------------CREATING A CLIENT IN PENDING---------------------------------------------");
log.info("---------------------------------CREATING A CLIENT IN PENDING---------------------------------------------");
return Utils.performServerPost(requestSpec, responseSpec, CREATE_CLIENT_URL, getTestClientAsJSONPending(submittedOnDate, officeId),
"clientId");
}
public Object createClientPendingWithError(final String jsonAttributeToGetBack) {
LOG.info("---------------------------------CREATING A CLIENT IN PENDING WITH ERROR---------------------------------------------");
log.info("---------------------------------CREATING A CLIENT IN PENDING WITH ERROR---------------------------------------------");
return Utils.performServerPost(this.requestSpec, this.responseSpec, CREATE_CLIENT_URL,
getTestClientAsJSONPending("04 March 2014", "1"), jsonAttributeToGetBack);
}
public static Integer createClientPendingWithDatatable(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
final String registeredTableName) {
LOG.info("-------------------------- CREATING A CLIENT IN PENDING WITH DATATABLES --------------------------------");
log.info("-------------------------- CREATING A CLIENT IN PENDING WITH DATATABLES --------------------------------");
return Utils.performServerPost(requestSpec, responseSpec, CREATE_CLIENT_URL,
getTestPendingClientWithDatatableAsJson(registeredTableName), "clientId");
}
@@ -129,7 +151,7 @@ public class ClientHelper {
public static Integer createClientAsPerson(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
final String activationDate, final String officeId) {
LOG.info(
log.info(
"---------------------------------CREATING A CLIENT NON PERSON(ORGANISATION)---------------------------------------------");
return Utils.performServerPost(requestSpec, responseSpec, CREATE_CLIENT_URL, getTestPersonClientAsJSON(activationDate, officeId),
"clientId");
@@ -151,7 +173,7 @@ public class ClientHelper {
Integer soleProprietorCodeValueId = (Integer) CodeHelper.retrieveOrCreateCodeValue(constitutionCodeId, requestSpec, responseSpec)
.get("id");
LOG.info(
log.info(
"---------------------------------CREATING A CLIENT NON PERSON(ORGANISATION)---------------------------------------------");
return Utils.performServerPost(requestSpec, responseSpec, CREATE_CLIENT_URL,
getTestEntityClientAsJSON(activationDate, officeId, soleProprietorCodeValueId), "clientId");
@@ -161,7 +183,7 @@ public class ClientHelper {
final Integer clientType, String jsonAttributeToGetBack) {
final String activationDate = "04 March 2011";
final String officeId = "1";
LOG.info(
log.info(
"---------------------------------CREATING A CLIENT BASED ON ACCOUNT PREFERENCE---------------------------------------------");
return Utils.performServerPost(requestSpec, responseSpec, CREATE_CLIENT_URL,
getTestClientWithClientTypeAsJSON(activationDate, officeId, clientType.toString()), jsonAttributeToGetBack);
@@ -172,7 +194,7 @@ public class ClientHelper {
final String CLIENT_ASSIGN_STAFF_URL = "/fineract-provider/api/v1/clients/" + clientId + "?" + Utils.TENANT_IDENTIFIER
+ "&command=assignStaff";
LOG.info("---------------------------------CREATING A CLIENT---------------------------------------------");
log.info("---------------------------------CREATING A CLIENT---------------------------------------------");
return Utils.performServerPost(requestSpec, responseSpec, CLIENT_ASSIGN_STAFF_URL, assignStaffToClientAsJson(staffId), "changes");
}
@@ -192,8 +214,8 @@ public class ClientHelper {
map.put("locale", "en");
map.put("active", "true");
map.put("activationDate", dateOfJoining);
LOG.info("map : {}", map);
return new Gson().toJson(map);
log.info("map : {}", map);
return GSON.toJson(map);
}
public static String getTestClientAsJSONPending(final String submittedOnDate, final String officeId) {
@@ -207,8 +229,8 @@ public class ClientHelper {
map.put("locale", "en");
map.put("active", "false");
map.put("submittedOnDate", submittedOnDate);
LOG.info("map : {}", map);
return new Gson().toJson(map);
log.info("map : {}", map);
return GSON.toJson(map);
}
public static String getTestPendingClientWithDatatableAsJson(final String registeredTableName) {
@@ -223,7 +245,7 @@ public class ClientHelper {
map.put("active", "false");
map.put("submittedOnDate", "04 March 2014");
String requestJson = getTestDatatableAsJson(map, registeredTableName);
LOG.info("map : {}", requestJson);
log.info("map : {}", requestJson);
return requestJson;
}
@@ -241,7 +263,7 @@ public class ClientHelper {
datatableMap.put("data", dataMap);
datatablesListMap.add(datatableMap);
map.put("datatables", datatablesListMap);
return new Gson().toJson(map);
return GSON.toJson(map);
}
public static String getTestPersonClientAsJSON(final String dateOfJoining, final String officeId) {
@@ -255,8 +277,8 @@ public class ClientHelper {
map.put("activationDate", dateOfJoining);
map.put("legalFormId", 1);
LOG.info("map : {}", map);
return new Gson().toJson(map);
log.info("map : {}", map);
return GSON.toJson(map);
}
public static String getTestEntityClientAsJSON(final String dateOfJoining, final String officeId,
@@ -275,8 +297,8 @@ public class ClientHelper {
clientNonPersonMap.put("constitutionId", soleProprietorCodeValueId);
map.put("clientNonPersonDetails", clientNonPersonMap);
LOG.info("map : {}", map);
return new Gson().toJson(map);
log.info("map : {}", map);
return GSON.toJson(map);
}
public static String getTestClientWithClientTypeAsJSON(final String dateOfJoining, final String officeId, final String clientType) {
@@ -291,31 +313,44 @@ public class ClientHelper {
map.put("active", "true");
map.put("activationDate", dateOfJoining);
map.put("clientTypeId", clientType);
LOG.info("map : {}", map);
return new Gson().toJson(map);
log.info("map : {}", map);
return GSON.toJson(map);
}
public static String assignStaffToClientAsJson(final String staffId) {
final HashMap<String, String> map = new HashMap<>();
map.put("staffId", staffId);
LOG.info("map : {}", map);
return new Gson().toJson(map);
log.info("map : {}", map);
return GSON.toJson(map);
}
public static void verifyClientCreatedOnServer(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
final Integer generatedClientID) {
LOG.info("------------------------------CHECK CLIENT DETAILS------------------------------------\n");
final String CLIENT_URL = "/fineract-provider/api/v1/clients/" + generatedClientID + "?" + Utils.TENANT_IDENTIFIER;
final Integer clientId) {
log.info("------------------------------CHECK CLIENT DETAILS------------------------------------\n");
final String CLIENT_URL = "/fineract-provider/api/v1/clients/" + clientId + "?" + Utils.TENANT_IDENTIFIER;
final Integer responseClientID = Utils.performServerGet(requestSpec, responseSpec, CLIENT_URL, "id");
assertEquals(generatedClientID, responseClientID, "ERROR IN CREATING THE CLIENT");
assertEquals(clientId, responseClientID, "ERROR IN CREATING THE CLIENT");
}
public static GetClientsClientIdResponse getClient(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
final int clientId) {
String clientResponseStr = (String) getClient(requestSpec, responseSpec, Integer.toString(clientId), null);
return GSON.fromJson(clientResponseStr, GetClientsClientIdResponse.class);
}
public static List<GetClientClientIdAddressesResponse> getClientAddresses(final RequestSpecification requestSpec,
final ResponseSpecification responseSpec, final int clientId) {
final String GET_CLIENT_ADDRESSES_URL = "/fineract-provider/api/v1/client/" + clientId + "/addresses?" + Utils.TENANT_IDENTIFIER;
log.info("---------------------------------GET A CLIENT'S ADDRESSES ---------------------------------------------");
String clientResponseStr = Utils.performServerGet(requestSpec, responseSpec, GET_CLIENT_ADDRESSES_URL);
return GSON.fromJson(clientResponseStr, new TypeToken<List<GetClientClientIdAddressesResponse>>() {}.getType());
}
public static Object getClient(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, final String clientId,
final String jsonReturn) {
final String GET_CLIENT_URL = "/fineract-provider/api/v1/clients/" + clientId + "?" + Utils.TENANT_IDENTIFIER;
LOG.info("---------------------------------GET A CLIENT---------------------------------------------");
log.info("---------------------------------GET A CLIENT---------------------------------------------");
return Utils.performServerGet(requestSpec, responseSpec, GET_CLIENT_URL, jsonReturn);
}
/* Client status is a map.So adding SuppressWarnings */
@@ -346,8 +381,8 @@ public class ClientHelper {
map.put("dateFormat", CommonConstants.DATE_FORMAT);
map.put("closureDate", CREATED_DATE_PLUS_ONE);
String clientJson = new Gson().toJson(map);
LOG.info(clientJson);
String clientJson = GSON.toJson(map);
log.info(clientJson);
return clientJson;
}
@@ -357,8 +392,8 @@ public class ClientHelper {
map.put("locale", CommonConstants.LOCALE);
map.put("dateFormat", CommonConstants.DATE_FORMAT);
map.put("reactivationDate", CREATED_DATE_PLUS_ONE);
String clientJson = new Gson().toJson(map);
LOG.info(clientJson);
String clientJson = GSON.toJson(map);
log.info(clientJson);
return clientJson;
}
@@ -368,8 +403,8 @@ public class ClientHelper {
map.put("locale", CommonConstants.LOCALE);
map.put("dateFormat", CommonConstants.DATE_FORMAT);
map.put("reopenedDate", date);
String clientJson = new Gson().toJson(map);
LOG.info(clientJson);
String clientJson = GSON.toJson(map);
log.info(clientJson);
return clientJson;
}
@@ -379,8 +414,8 @@ public class ClientHelper {
map.put("locale", CommonConstants.LOCALE);
map.put("dateFormat", CommonConstants.DATE_FORMAT);
map.put("reopenedDate", date);
String clientJson = new Gson().toJson(map);
LOG.info(clientJson);
String clientJson = GSON.toJson(map);
log.info(clientJson);
return clientJson;
}
@@ -401,8 +436,8 @@ public class ClientHelper {
map.put("dateFormat", CommonConstants.DATE_FORMAT);
map.put("rejectionDate", CREATED_DATE_PLUS_ONE);
map.put("rejectionReasonId", rejectionReasonId.toString());
String clientJson = new Gson().toJson(map);
LOG.info(clientJson);
String clientJson = GSON.toJson(map);
log.info(clientJson);
return clientJson;
}
@@ -412,8 +447,8 @@ public class ClientHelper {
map.put("locale", CommonConstants.LOCALE);
map.put("dateFormat", CommonConstants.DATE_FORMAT);
map.put("activationDate", date);
String clientJson = new Gson().toJson(map);
LOG.info(clientJson);
String clientJson = GSON.toJson(map);
log.info(clientJson);
return clientJson;
}
@@ -433,8 +468,8 @@ public class ClientHelper {
map.put("dateFormat", CommonConstants.DATE_FORMAT);
map.put("withdrawalDate", CREATED_DATE_PLUS_ONE);
map.put("withdrawalReasonId", withdrawalReasonId.toString());
String clientJson = new Gson().toJson(map);
LOG.info(clientJson);
String clientJson = GSON.toJson(map);
log.info(clientJson);
return clientJson;
}
@@ -446,7 +481,7 @@ public class ClientHelper {
map.put("dueDate", dueDate);
map.put("chargeId", chargeId);
map.put("amount", "200");
String json = new Gson().toJson(map);
String json = GSON.toJson(map);
return json;
}
@@ -456,8 +491,8 @@ public class ClientHelper {
map.put("dateFormat", DATE_FORMAT);
map.put("transactionDate", date);
map.put("amount", amount);
String json = new Gson().toJson(map);
LOG.info("{}", json);
String json = GSON.toJson(map);
log.info("{}", json);
return json;
}
@@ -466,34 +501,34 @@ public class ClientHelper {
map.put("locale", "en_GB");
map.put("amount", amount);
map.put("clientChargeId", clientChargeId);
String json = new Gson().toJson(map);
LOG.info("{}", json);
String json = GSON.toJson(map);
log.info("{}", json);
return json;
}
public HashMap<String, Object> closeClient(final Integer clientId) {
LOG.info("--------------------------------- CLOSE CLIENT -------------------------------");
log.info("--------------------------------- CLOSE CLIENT -------------------------------");
return performClientActions(createClientOperationURL(CLOSE_CLIENT_COMMAND, clientId), getCloseClientAsJSON(), clientId);
}
public HashMap<String, Object> reactivateClient(final Integer clientId) {
LOG.info("--------------------------------- REACTIVATE CLIENT -------------------------------");
log.info("--------------------------------- REACTIVATE CLIENT -------------------------------");
return performClientActions(createClientOperationURL(REACTIVATE_CLIENT_COMMAND, clientId), getReactivateClientAsJSON(), clientId);
}
public HashMap<String, Object> rejectClient(final Integer clientId) {
LOG.info("--------------------------------- REJECT CLIENT -------------------------------");
log.info("--------------------------------- REJECT CLIENT -------------------------------");
return performClientActions(createClientOperationURL(REJECT_CLIENT_COMMAND, clientId), getRejectClientAsJSON(), clientId);
}
public HashMap<String, Object> activateClient(final Integer clientId) {
LOG.info("--------------------------------- ACTIVATE CLIENT -------------------------------");
log.info("--------------------------------- ACTIVATE CLIENT -------------------------------");
return performClientActions(createClientOperationURL(ACTIVATE_CLIENT_COMMAND, clientId),
getActivateClientAsJSON(CREATED_DATE_PLUS_ONE), clientId);
}
public HashMap<String, Object> withdrawClient(final Integer clientId) {
LOG.info("--------------------------------- WITHDRAWN CLIENT -------------------------------");
log.info("--------------------------------- WITHDRAWN CLIENT -------------------------------");
return performClientActions(createClientOperationURL(WITHDRAW_CLIENT_COMMAND, clientId), getWithdrawClientAsJSON(), clientId);
}
@@ -502,39 +537,39 @@ public class ClientHelper {
}
public HashMap<String, Object> undoReject(final Integer clientId) {
LOG.info("--------------------------------- UNDO REJECT CLIENT -------------------------------");
log.info("--------------------------------- UNDO REJECT CLIENT -------------------------------");
return performClientActions(createClientOperationURL(UNDOREJECT_CLIENT_COMMAND, clientId),
getUndoRejectClientAsJSON(CREATED_DATE_PLUS_TWO), clientId);
}
public HashMap<String, Object> undoWithdrawn(final Integer clientId) {
LOG.info("--------------------------------- UNDO WITHDRAWN CLIENT -------------------------------");
log.info("--------------------------------- UNDO WITHDRAWN CLIENT -------------------------------");
return performClientActions(createClientOperationURL(UNDOWITHDRAWN_CLIENT_COMMAND, clientId),
getUndoWithdrawnClientAsJSON(CREATED_DATE_PLUS_TWO), clientId);
}
public ArrayList<HashMap<String, Object>> undoRejectedclient(final Integer clientId, final String jsonAttributeToGetBack,
final String rejectedDate) {
LOG.info("----------------------------------UNDO REJECT CLIENT ----------------------------------");
log.info("----------------------------------UNDO REJECT CLIENT ----------------------------------");
return performClientActionsWithValidationErrors(createClientOperationURL(UNDOREJECT_CLIENT_COMMAND, clientId),
getUndoRejectClientAsJSON(rejectedDate), jsonAttributeToGetBack);
}
public ArrayList<HashMap<String, Object>> undoWithdrawclient(final Integer clientId, final String jsonAttributeToGetBack,
final String rejectedDate) {
LOG.info("----------------------------------UNDO WITHDRAW CLIENT ----------------------------------");
log.info("----------------------------------UNDO WITHDRAW CLIENT ----------------------------------");
return performClientActionsWithValidationErrors(createClientOperationURL(UNDOWITHDRAWN_CLIENT_COMMAND, clientId),
getUndoWithdrawnClientAsJSON(rejectedDate), jsonAttributeToGetBack);
}
public ArrayList<HashMap<String, Object>> activateClient(final Integer clientId, final String jsonAttributeToGetBack) {
LOG.info("--------------------------------- ACTIVATE CLIENT -------------------------------");
log.info("--------------------------------- ACTIVATE CLIENT -------------------------------");
return performClientActionsWithValidationErrors(createClientOperationURL(ACTIVATE_CLIENT_COMMAND, clientId),
getActivateClientAsJSON(CREATED_DATE_PLUS_ONE), jsonAttributeToGetBack);
}
public HashMap<String, Object> activateClientWithDiffDateOption(final Integer clientId, final String activationDate) {
LOG.info("--------------------------------- ACTIVATE CLIENT -------------------------------");
log.info("--------------------------------- ACTIVATE CLIENT -------------------------------");
return performClientActions(createClientOperationURL(ACTIVATE_CLIENT_COMMAND, clientId), getActivateClientAsJSON(activationDate),
clientId);
}
@@ -553,7 +588,7 @@ public class ClientHelper {
public static Integer addChargesForClient(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
final Integer clientId, final String request) {
LOG.info("--------------------------------- ADD CHARGES FOR Client --------------------------------");
log.info("--------------------------------- ADD CHARGES FOR Client --------------------------------");
final String ADD_CHARGES_URL = "/fineract-provider/api/v1/clients/" + clientId + "/charges?" + Utils.TENANT_IDENTIFIER;
final HashMap<?, ?> response = Utils.performServerPost(requestSpec, responseSpec, ADD_CHARGES_URL, request, "");
return (Integer) response.get("resourceId");
@@ -561,7 +596,7 @@ public class ClientHelper {
public static String payChargesForClients(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
final Integer clientId, final Integer clientChargeId, final String json) {
LOG.info("--------------------------------- PAY CHARGES FOR CLIENT --------------------------------");
log.info("--------------------------------- PAY CHARGES FOR CLIENT --------------------------------");
final String CHARGES_URL = "/fineract-provider/api/v1/clients/" + clientId + "/charges/" + clientChargeId + "?command=paycharge&"
+ Utils.TENANT_IDENTIFIER;
final HashMap<?, ?> response = Utils.performServerPost(requestSpec, responseSpec, CHARGES_URL, json, "");
@@ -570,7 +605,7 @@ public class ClientHelper {
public static String waiveChargesForClients(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
final Integer clientId, final Integer clientChargeId, final String json) {
LOG.info("--------------------------------- WAIVE CHARGES FOR CLIENT --------------------------------");
log.info("--------------------------------- WAIVE CHARGES FOR CLIENT --------------------------------");
final String CHARGES_URL = "/fineract-provider/api/v1/clients/" + clientId + "/charges/" + clientChargeId + "?command=waive&"
+ Utils.TENANT_IDENTIFIER;
@@ -580,7 +615,7 @@ public class ClientHelper {
public static Integer revertClientChargeTransaction(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
final String clientId, String clientChargeId) {
LOG.info("---------------------------------UNDO TRANSACTION---------------------------------------------");
log.info("---------------------------------UNDO TRANSACTION---------------------------------------------");
final String CHARGES_URL = "/fineract-provider/api/v1/clients/" + clientId + "/transactions/" + clientChargeId + "?command=undo&"
+ Utils.TENANT_IDENTIFIER;
@@ -591,7 +626,7 @@ public class ClientHelper {
public static Object getClientCharge(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
final String clientId, final String clientChargeId) {
LOG.info("---------------------------------GET CLIENT CHARGE---------------------------------------------");
log.info("---------------------------------GET CLIENT CHARGE---------------------------------------------");
final String CHARGES_URL = "/fineract-provider/api/v1/clients/" + clientId + "/charges/" + clientChargeId + "?"
+ Utils.TENANT_IDENTIFIER;
return Utils.performServerGet(requestSpec, responseSpec, CHARGES_URL, "amountOutstanding");
@@ -599,7 +634,7 @@ public class ClientHelper {
public static Boolean getClientTransactions(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
final String clientId, final String transactionId) {
LOG.info("---------------------------------GET CLIENT CHARGE TRANSACTIONS---------------------------------------------");
log.info("---------------------------------GET CLIENT CHARGE TRANSACTIONS---------------------------------------------");
final String CHARGES_URL = "/fineract-provider/api/v1/clients/" + clientId + "/transactions/" + transactionId + "?"
+ Utils.TENANT_IDENTIFIER;
return Utils.performServerGet(requestSpec, responseSpec, CHARGES_URL, "reversed");
@@ -636,4 +671,9 @@ public class ClientHelper {
return (List) responseClients.get("pageItems");
}
public static PostClientsRequest defaultClientCreationRequest() {
return new PostClientsRequest().officeId(1).legalFormId(LEGALFORM_ID_PERSON)
.firstname(Utils.randomNameGenerator("Client_FirstName_", 5)).lastname(Utils.randomNameGenerator("Client_LastName_", 5))
.externalId(randomIDGenerator("ID_", 7)).dateFormat(DATE_FORMAT).locale("en").active(true).activationDate("04 March 2011");
}
}
@@ -23,26 +23,25 @@ import io.restassured.specification.RequestSpecification;
import io.restassured.specification.ResponseSpecification;
import java.util.ArrayList;
import java.util.HashMap;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.fineract.client.models.GlobalConfigurationPropertyData;
import org.apache.fineract.client.util.JSON;
import org.junit.jupiter.api.Assertions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@SuppressWarnings({ "unused", "rawtypes" })
@Slf4j
@RequiredArgsConstructor
public class GlobalConfigurationHelper {
private static final Logger LOG = LoggerFactory.getLogger(GlobalConfigurationHelper.class);
private static final Gson GSON = new JSON().getGson();
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<HashMap> getAllGlobalConfigurations(final RequestSpecification requestSpec,
final ResponseSpecification responseSpec) {
final String GET_ALL_GLOBAL_CONFIG_URL = "/fineract-provider/api/v1/configurations?" + Utils.TENANT_IDENTIFIER;
LOG.info("------------------------ RETRIEVING ALL GLOBAL CONFIGURATIONS -------------------------");
log.info("------------------------ RETRIEVING ALL GLOBAL CONFIGURATIONS -------------------------");
final HashMap<String, ArrayList<HashMap>> response = Utils.performServerGet(requestSpec, responseSpec, GET_ALL_GLOBAL_CONFIG_URL,
"");
return response.get("globalConfiguration");
@@ -51,10 +50,20 @@ public class GlobalConfigurationHelper {
public static HashMap getGlobalConfigurationById(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
final String configId) {
final String GET_GLOBAL_CONFIG_BY_ID_URL = "/fineract-provider/api/v1/configurations/" + configId + "?" + Utils.TENANT_IDENTIFIER;
LOG.info("------------------------ RETRIEVING GLOBAL CONFIGURATION BY ID -------------------------");
log.info("------------------------ RETRIEVING GLOBAL CONFIGURATION BY ID -------------------------");
return Utils.performServerGet(requestSpec, responseSpec, GET_GLOBAL_CONFIG_BY_ID_URL, "");
}
public static GlobalConfigurationPropertyData getGlobalConfigurationByName(final RequestSpecification requestSpec,
final ResponseSpecification responseSpec, final String name) {
final String GET_GLOBAL_CONFIG_BY_NAME_URL = "/fineract-provider/api/v1/configurations/name/" + name + "?"
+ Utils.TENANT_IDENTIFIER;
log.info("------------------------ RETRIEVING GLOBAL CONFIGURATION BY NAME -------------------------");
String response = Utils.performServerGet(requestSpec, responseSpec, GET_GLOBAL_CONFIG_BY_NAME_URL);
return GSON.fromJson(response, GlobalConfigurationPropertyData.class);
}
// TODO: This is quite a bad pattern and adds a lot of time to individual test executions
public static void resetAllDefaultGlobalConfigurations(final RequestSpecification requestSpec,
final ResponseSpecification responseSpec) {
@@ -437,15 +446,30 @@ public class GlobalConfigurationHelper {
public static Integer updateValueForGlobalConfiguration(final RequestSpecification requestSpec,
final ResponseSpecification responseSpec, final String configId, final String value) {
final String GLOBAL_CONFIG_UPDATE_URL = "/fineract-provider/api/v1/configurations/" + configId + "?" + Utils.TENANT_IDENTIFIER;
LOG.info("---------------------------------UPDATE VALUE FOR GLOBAL CONFIG---------------------------------------------");
log.info("---------------------------------UPDATE VALUE FOR GLOBAL CONFIG---------------------------------------------");
return Utils.performServerPut(requestSpec, responseSpec, GLOBAL_CONFIG_UPDATE_URL, updateGlobalConfigUpdateValueAsJSON(value),
"resourceId");
}
public static Integer updateValueForGlobalConfiguration(final RequestSpecification requestSpec,
final ResponseSpecification responseSpec, final String configId, final int value) {
return updateValueForGlobalConfiguration(requestSpec, responseSpec, configId, Integer.toString(value));
}
public static Integer updateEnabledFlagForGlobalConfiguration(final RequestSpecification requestSpec,
final ResponseSpecification responseSpec, final String configId, final Boolean enabled) {
final ResponseSpecification responseSpec, final long configId, final boolean enabled) {
final String GLOBAL_CONFIG_UPDATE_URL = "/fineract-provider/api/v1/configurations/" + configId + "?" + Utils.TENANT_IDENTIFIER;
LOG.info("---------------------------------UPDATE GLOBAL CONFIG FOR ENABLED FLAG---------------------------------------------");
log.info("---------------------------------UPDATE GLOBAL CONFIG FOR ENABLED FLAG---------------------------------------------");
return Utils.performServerPut(requestSpec, responseSpec, GLOBAL_CONFIG_UPDATE_URL,
updateGlobalConfigUpdateEnabledFlagAsJSON(enabled), "resourceId");
}
// Deprecated because it's using configId as a String
@Deprecated
public static Integer updateEnabledFlagForGlobalConfiguration(final RequestSpecification requestSpec,
final ResponseSpecification responseSpec, final String configId, final boolean enabled) {
final String GLOBAL_CONFIG_UPDATE_URL = "/fineract-provider/api/v1/configurations/" + configId + "?" + Utils.TENANT_IDENTIFIER;
log.info("---------------------------------UPDATE GLOBAL CONFIG FOR ENABLED FLAG---------------------------------------------");
return Utils.performServerPut(requestSpec, responseSpec, GLOBAL_CONFIG_UPDATE_URL,
updateGlobalConfigUpdateEnabledFlagAsJSON(enabled), "resourceId");
}
@@ -453,7 +477,7 @@ public class GlobalConfigurationHelper {
public static ArrayList getGlobalConfigurationIsCacheEnabled(final RequestSpecification requestSpec,
final ResponseSpecification responseSpec) {
final String GET_IS_CACHE_GLOBAL_CONFIG_URL = "/fineract-provider/api/v1/caches?" + Utils.TENANT_IDENTIFIER;
LOG.info("------------------------ RETRIEVING IS CACHE ENABLED GLOBAL CONFIGURATION -------------------------");
log.info("------------------------ RETRIEVING IS CACHE ENABLED GLOBAL CONFIGURATION -------------------------");
final ArrayList<HashMap> response = Utils.performServerGet(requestSpec, responseSpec, GET_IS_CACHE_GLOBAL_CONFIG_URL, "");
return response;
}
@@ -461,7 +485,7 @@ public class GlobalConfigurationHelper {
public static HashMap updateIsCacheEnabledForGlobalConfiguration(final RequestSpecification requestSpec,
final ResponseSpecification responseSpec, final String cacheType) {
final String IS_CACHE_GLOBAL_CONFIG_UPDATE_URL = "/fineract-provider/api/v1/caches?" + Utils.TENANT_IDENTIFIER;
LOG.info("------------------UPDATE GLOBAL CONFIG FOR IS CACHE ENABLED----------------------");
log.info("------------------UPDATE GLOBAL CONFIG FOR IS CACHE ENABLED----------------------");
return Utils.performServerPut(requestSpec, responseSpec, IS_CACHE_GLOBAL_CONFIG_UPDATE_URL,
updateIsCacheEnabledGlobalConfigUpdateAsJSON(cacheType), "changes");
}
@@ -470,7 +494,7 @@ public class GlobalConfigurationHelper {
final ResponseSpecification responseSpec, final Integer configId, final String value, final String enabled,
final String jsonAttributeToGetBack) {
final String UPDATE_URL = "/fineract-provider/api/v1/configurations/" + configId + "?" + Utils.TENANT_IDENTIFIER;
LOG.info("------------------UPDATE GLOBAL CONFIG FOR FORCE PASSWORD RESET DAYS----------------------");
log.info("------------------UPDATE GLOBAL CONFIG FOR FORCE PASSWORD RESET DAYS----------------------");
return Utils.performServerPut(requestSpec, responseSpec, UPDATE_URL, updatePasswordResetDaysGlobalConfigAsJSON(value, enabled),
jsonAttributeToGetBack);
}
@@ -478,8 +502,8 @@ public class GlobalConfigurationHelper {
public static String updateGlobalConfigUpdateValueAsJSON(final String value) {
final HashMap<String, String> map = new HashMap<>();
map.put("value", value);
LOG.info("map : {}", map);
return new Gson().toJson(map);
log.info("map : {}", map);
return GSON.toJson(map);
}
public static String updatePasswordResetDaysGlobalConfigAsJSON(final String value, final String enabled) {
@@ -488,21 +512,21 @@ public class GlobalConfigurationHelper {
map.put("value", value);
}
map.put("enabled", enabled);
LOG.info("map : {}", map);
log.info("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);
LOG.info("map : {}", map);
log.info("map : {}", map);
return new Gson().toJson(map);
}
public static String updateIsCacheEnabledGlobalConfigUpdateAsJSON(final String cacheType) {
final HashMap<String, String> map = new HashMap<>();
map.put("cacheType", cacheType);
LOG.info("map : {}", map);
log.info("map : {}", map);
return new Gson().toJson(map);
}
@@ -138,6 +138,11 @@ public final class Utils {
}
}
public static String performServerGet(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
final String url) {
return performServerGet(requestSpec, responseSpec, url, null);
}
public static <T> T performServerGet(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
final String getURL, final String jsonAttributeToGetBack) {
final String json = given().spec(requestSpec).expect().spec(responseSpec).log().ifError().when().get(getURL).andReturn().asString();
@@ -157,6 +162,11 @@ public final class Utils {
return given().spec(requestSpec).expect().spec(responseSpec).log().ifError().when().get(getURL).andReturn().asByteArray();
}
public static String performServerPost(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
final String postURL, final String jsonBodyToSend) {
return performServerPost(requestSpec, responseSpec, postURL, jsonBodyToSend, null);
}
public static <T> T performServerPost(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
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)
@@ -31,6 +31,10 @@ import org.apache.fineract.integrationtests.common.Utils;
public final class CodeHelper {
private static final String COUNTRY_CODE_NAME = "COUNTRY";
private static final String STATE_CODE_NAME = "STATE";
private static final String ADDRESS_TYPE_CODE_NAME = "ADDRESS_TYPE";
private CodeHelper() {
}
@@ -150,6 +154,32 @@ public final class CodeHelper {
}
public static Integer createAddressTypeCodeValue(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
final String addressTypeName, final Integer position) {
HashMap<String, Object> code = getCodeByName(requestSpec, responseSpec, ADDRESS_TYPE_CODE_NAME);
Integer countryCode = (Integer) code.get("id");
return createCodeValue(requestSpec, responseSpec, countryCode, addressTypeName, position);
}
public static Integer createStateCodeValue(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
final String stateName, final Integer position) {
HashMap<String, Object> code = getCodeByName(requestSpec, responseSpec, STATE_CODE_NAME);
Integer countryCode = (Integer) code.get("id");
return createCodeValue(requestSpec, responseSpec, countryCode, stateName, position);
}
public static Integer createCountryCodeValue(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
final String countryName, final Integer position) {
HashMap<String, Object> code = getCodeByName(requestSpec, responseSpec, COUNTRY_CODE_NAME);
Integer countryCode = (Integer) code.get("id");
return createCodeValue(requestSpec, responseSpec, countryCode, countryName, position);
}
public static Integer createCodeValue(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
final Integer codeId, final String codeValueName, final Integer position) {
return (Integer) createCodeValue(requestSpec, responseSpec, codeId, codeValueName, position, SUBRESPONSE_ID_ATTRIBUTE_NAME);
}
public static Object createCodeValue(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
final Integer codeId, final String codeValueName, final Integer position, final String jsonAttributeToGetback) {
String description = null;