http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/4b1ec9ef/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/ClientHelper.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/ClientHelper.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/ClientHelper.java new file mode 100755 index 0000000..fa46249 --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/ClientHelper.java @@ -0,0 +1,442 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.integrationtests.common; + +import static org.junit.Assert.assertEquals; + +import java.util.HashMap; + +import org.apache.fineract.infrastructure.codes.domain.CodeValue; +import org.apache.fineract.integrationtests.common.system.CodeHelper; + +import com.google.gson.Gson; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; + +public class ClientHelper { + + 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"; + private static final String REACTIVATE_CLIENT_COMMAND = "reactivate"; + private static final String REJECT_CLIENT_COMMAND = "reject"; + private static final String ACTIVATE_CLIENT_COMMAND = "activate"; + private static final String WITHDRAW_CLIENT_COMMAND = "withdraw"; + + public static final String CREATED_DATE = "27 November 2014"; + public static final String CREATED_DATE_PLUS_ONE = "28 November 2014"; + public static final String CREATED_DATE_MINUS_ONE = "27 November 2014"; + public static final String TRANSACTION_DATE = "01 March 2013"; + public static final String LAST_TRANSACTION_DATE = "01 March 2013"; + public static final String DATE_FORMAT = "dd MMMM yyyy"; + + public ClientHelper(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { + this.requestSpec = requestSpec; + this.responseSpec = responseSpec; + } + + public static Integer createClient(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { + return createClient(requestSpec, responseSpec, "04 March 2011"); + } + + public static Integer createClient(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final String activationDate) { + return createClient(requestSpec, responseSpec, activationDate, "1"); + } + + public static Integer createClient(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final String activationDate, final String officeId) { + System.out.println("---------------------------------CREATING A CLIENT---------------------------------------------"); + return Utils.performServerPost(requestSpec, responseSpec, CREATE_CLIENT_URL, getTestClientAsJSON(activationDate, officeId), + "clientId"); + } + + public static Integer createClientAsPerson(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { + return createClientAsPerson(requestSpec, responseSpec, "04 March 2011"); + } + + public static Integer createClientAsPerson(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final String activationDate) { + return createClientAsPerson(requestSpec, responseSpec, activationDate, "1"); + } + + public static Integer createClientAsPerson(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final String activationDate, final String officeId) { + + System.out.println("---------------------------------CREATING A CLIENT NON PERSON(ORGANISATION)---------------------------------------------"); + return Utils.performServerPost(requestSpec, responseSpec, CREATE_CLIENT_URL, getTestPersonClientAsJSON(activationDate, officeId), + "clientId"); + } + + public static Integer createClientAsEntity(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { + return createClientAsEntity(requestSpec, responseSpec, "04 March 2011"); + } + + public static Integer createClientAsEntity(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final String activationDate) { + return createClientAsEntity(requestSpec, responseSpec, activationDate, "1"); + } + + public static Integer createClientAsEntity(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final String activationDate, final String officeId) { + + Integer constitutionCodeId = (Integer) CodeHelper.getCodeByName(requestSpec, responseSpec, "Constitution").get("id"); + Integer soleProprietorCodeValueId = (Integer) CodeHelper.retrieveOrCreateCodeValue(constitutionCodeId, requestSpec, responseSpec).get("id"); + + System.out.println("---------------------------------CREATING A CLIENT NON PERSON(ORGANISATION)---------------------------------------------"); + return Utils.performServerPost(requestSpec, responseSpec, CREATE_CLIENT_URL, getTestEntityClientAsJSON(activationDate, officeId, soleProprietorCodeValueId), + "clientId"); + } + + public static Integer createClientForAccountPreference(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final Integer clientType, String jsonAttributeToGetBack) { + final String activationDate = "04 March 2011"; + final String officeId = "1"; + System.out.println( + "---------------------------------CREATING A CLIENT BASED ON ACCOUNT PREFERENCE---------------------------------------------"); + return Utils.performServerPost(requestSpec, responseSpec, CREATE_CLIENT_URL, + getTestClientWithClientTypeAsJSON(activationDate, officeId, clientType.toString()), jsonAttributeToGetBack); + } + + public static Object assignStaffToClient(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final String clientId, final String staffId) { + final String CLIENT_ASSIGN_STAFF_URL = "/fineract-provider/api/v1/clients/" + clientId + "?" + Utils.TENANT_IDENTIFIER + + "&command=assignStaff"; + + System.out.println("---------------------------------CREATING A CLIENT---------------------------------------------"); + return Utils.performServerPost(requestSpec, responseSpec, CLIENT_ASSIGN_STAFF_URL, assignStaffToClientAsJson(staffId), "changes"); + } + + public static Integer getClientsStaffId(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final String clientId) { + return (Integer) getClient(requestSpec, responseSpec, clientId, "staffId"); + } + + public static String getTestClientAsJSON(final String dateOfJoining, final String officeId) { + final HashMap<String, String> map = new HashMap<>(); + map.put("officeId", officeId); + map.put("firstname", Utils.randomNameGenerator("Client_FirstName_", 5)); + map.put("lastname", Utils.randomNameGenerator("Client_LastName_", 4)); + map.put("externalId", randomIDGenerator("ID_", 7)); + map.put("dateFormat", DATE_FORMAT); + map.put("locale", "en"); + map.put("active", "true"); + map.put("activationDate", dateOfJoining); + System.out.println("map : " + map); + return new Gson().toJson(map); + } + + public static String getTestPersonClientAsJSON(final String dateOfJoining, final String officeId) { + final HashMap<String, Object> map = new HashMap<>(); + map.put("officeId", officeId); + map.put("fullname", Utils.randomNameGenerator("Client_FullName_", 5)); + map.put("externalId", randomIDGenerator("ID_", 7)); + map.put("dateFormat", DATE_FORMAT); + map.put("locale", "en"); + map.put("active", "true"); + map.put("activationDate", dateOfJoining); + map.put("legalFormId", 1); + + System.out.println("map : " + map); + return new Gson().toJson(map); + } + + public static String getTestEntityClientAsJSON(final String dateOfJoining, final String officeId, final Integer soleProprietorCodeValueId) { + final HashMap<String, Object> map = new HashMap<>(); + map.put("officeId", officeId); + map.put("fullname", Utils.randomNameGenerator("Client_FullName_", 5)); + map.put("externalId", randomIDGenerator("ID_", 7)); + map.put("dateFormat", DATE_FORMAT); + map.put("locale", "en"); + map.put("active", "true"); + map.put("activationDate", dateOfJoining); + map.put("legalFormId", 2); + + final HashMap<String, Object> clientNonPersonMap = new HashMap<>(); + clientNonPersonMap.put("constitutionId", soleProprietorCodeValueId); + map.put("clientNonPersonDetails", clientNonPersonMap); + + System.out.println("map : " + map); + return new Gson().toJson(map); + } + + public static String getTestClientWithClientTypeAsJSON(final String dateOfJoining, final String officeId, final String clientType) { + final HashMap<String, String> map = new HashMap<>(); + map.put("officeId", officeId); + map.put("firstname", Utils.randomNameGenerator("Client_FirstName_", 5)); + map.put("lastname", Utils.randomNameGenerator("Client_LastName_", 4)); + map.put("externalId", randomIDGenerator("ID_", 7)); + map.put("dateFormat", DATE_FORMAT); + map.put("locale", "en"); + map.put("active", "true"); + map.put("activationDate", dateOfJoining); + map.put("clientTypeId", clientType); + System.out.println("map : " + map); + return new Gson().toJson(map); + } + + public static String assignStaffToClientAsJson(final String staffId) { + final HashMap<String, String> map = new HashMap<>(); + map.put("staffId", staffId); + System.out.println("map : " + map); + return new Gson().toJson(map); + } + + public static void verifyClientCreatedOnServer(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final Integer generatedClientID) { + System.out.println("------------------------------CHECK CLIENT DETAILS------------------------------------\n"); + final String CLIENT_URL = "/fineract-provider/api/v1/clients/" + generatedClientID + "?" + Utils.TENANT_IDENTIFIER; + final Integer responseClientID = Utils.performServerGet(requestSpec, responseSpec, CLIENT_URL, "id"); + assertEquals("ERROR IN CREATING THE CLIENT", generatedClientID, responseClientID); + } + + 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; + System.out.println("---------------------------------GET A CLIENT---------------------------------------------"); + return Utils.performServerGet(requestSpec, responseSpec, GET_CLIENT_URL, jsonReturn); + + } + + /* Client status is a map.So adding SuppressWarnings */ + @SuppressWarnings("unchecked") + public static HashMap<String, Object> getClientStatus(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final String clientId) { + return (HashMap<String, Object>) getClient(requestSpec, responseSpec, clientId, "status"); + } + + private static String randomIDGenerator(final String prefix, final int lenOfRandomSuffix) { + return Utils.randomStringGenerator(prefix, lenOfRandomSuffix, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + } + + private String getCloseClientAsJSON() { + final HashMap<String, String> map = new HashMap<>(); + + /* Retrieve Code id for the Code "ClientClosureReason" */ + String codeName = "ClientClosureReason"; + HashMap<String, Object> code = CodeHelper.getCodeByName(this.requestSpec, this.responseSpec, codeName); + Integer clientClosureCodeId = (Integer) code.get("id"); + + /* Retrieve/Create Code Values for the Code "ClientClosureReason" */ + HashMap<String, Object> codeValue = CodeHelper.retrieveOrCreateCodeValue(clientClosureCodeId, this.requestSpec, this.responseSpec); + Integer closureReasonId = (Integer) codeValue.get("id"); + + map.put("closureReasonId", closureReasonId.toString()); + map.put("locale", CommonConstants.locale); + map.put("dateFormat", CommonConstants.dateFormat); + map.put("closureDate", CREATED_DATE_PLUS_ONE); + + String clientJson = new Gson().toJson(map); + System.out.println(clientJson); + return clientJson; + + } + + private String getReactivateClientAsJSON() { + final HashMap<String, String> map = new HashMap<>(); + map.put("locale", CommonConstants.locale); + map.put("dateFormat", CommonConstants.dateFormat); + map.put("reactivationDate", CREATED_DATE_PLUS_ONE); + String clientJson = new Gson().toJson(map); + System.out.println(clientJson); + return clientJson; + + } + + private String getRejectClientAsJSON() { + final HashMap<String, String> map = new HashMap<>(); + /* Retrieve Code id for the Code "ClientRejectReason" */ + String codeName = "ClientRejectReason"; + HashMap<String, Object> code = CodeHelper.getCodeByName(this.requestSpec, this.responseSpec, codeName); + Integer clientRejectionReasonCodeId = (Integer) code.get("id"); + + /* Retrieve/Create Code Values for the Code "ClientRejectReason" */ + HashMap<String, Object> codeValue = CodeHelper.retrieveOrCreateCodeValue(clientRejectionReasonCodeId, this.requestSpec, + this.responseSpec); + Integer rejectionReasonId = (Integer) codeValue.get("id"); + + map.put("locale", CommonConstants.locale); + map.put("dateFormat", CommonConstants.dateFormat); + map.put("rejectionDate", CREATED_DATE_PLUS_ONE); + map.put("rejectionReasonId", rejectionReasonId.toString()); + String clientJson = new Gson().toJson(map); + System.out.println(clientJson); + return clientJson; + + } + + private String getActivateClientAsJSON() { + final HashMap<String, String> map = new HashMap<>(); + map.put("locale", CommonConstants.locale); + map.put("dateFormat", CommonConstants.dateFormat); + map.put("activationDate", CREATED_DATE_PLUS_ONE); + String clientJson = new Gson().toJson(map); + System.out.println(clientJson); + return clientJson; + + } + + private String getWithdrawClientAsJSON() { + final HashMap<String, String> map = new HashMap<>(); + /* Retrieve Code id for the Code "ClientWithdrawReason" */ + String codeName = "ClientWithdrawReason"; + HashMap<String, Object> code = CodeHelper.getCodeByName(this.requestSpec, this.responseSpec, codeName); + Integer clientWithdrawReasonCodeId = (Integer) code.get("id"); + + /* Retrieve/Create Code Values for the Code "ClientWithdrawReason" */ + HashMap<String, Object> codeValue = CodeHelper.retrieveOrCreateCodeValue(clientWithdrawReasonCodeId, this.requestSpec, + this.responseSpec); + Integer withdrawalReasonId = (Integer) codeValue.get("id"); + + map.put("locale", CommonConstants.locale); + map.put("dateFormat", CommonConstants.dateFormat); + map.put("withdrawalDate", CREATED_DATE_PLUS_ONE); + map.put("withdrawalReasonId", withdrawalReasonId.toString()); + String clientJson = new Gson().toJson(map); + System.out.println(clientJson); + return clientJson; + + } + + public static String getSpecifiedDueDateChargesClientAsJSON(final String chargeId, final String dueDate) { + final HashMap<String, String> map = new HashMap<>(); + map.put("locale", "en_GB"); + map.put("dateFormat", DATE_FORMAT); + map.put("dueDate", dueDate); + map.put("chargeId", chargeId); + map.put("amount", "200"); + String json = new Gson().toJson(map); + return json; + } + + public static String getPayChargeJSON(final String date, String amount) { + final HashMap<String, String> map = new HashMap<>(); + map.put("locale", "en_GB"); + map.put("dateFormat", DATE_FORMAT); + map.put("transactionDate", date); + map.put("amount", amount); + String json = new Gson().toJson(map); + System.out.println(json); + return json; + } + + public static String getWaiveChargeJSON(final String amount, String clientChargeId) { + final HashMap<String, String> map = new HashMap<>(); + map.put("locale", "en_GB"); + map.put("amount", amount); + map.put("clientChargeId", clientChargeId); + String json = new Gson().toJson(map); + System.out.println(json); + return json; + } + + public HashMap<String, Object> closeClient(final Integer clientId) { + System.out.println("--------------------------------- CLOSE CLIENT -------------------------------"); + return performClientActions(createClientOperationURL(CLOSE_CLIENT_COMMAND, clientId), getCloseClientAsJSON(), clientId); + } + + public HashMap<String, Object> reactivateClient(final Integer clientId) { + System.out.println("--------------------------------- REACTIVATE CLIENT -------------------------------"); + return performClientActions(createClientOperationURL(REACTIVATE_CLIENT_COMMAND, clientId), getReactivateClientAsJSON(), clientId); + } + + public HashMap<String, Object> rejectClient(final Integer clientId) { + System.out.println("--------------------------------- REJECT CLIENT -------------------------------"); + return performClientActions(createClientOperationURL(REJECT_CLIENT_COMMAND, clientId), getRejectClientAsJSON(), clientId); + } + + public HashMap<String, Object> activateClient(final Integer clientId) { + System.out.println("--------------------------------- ACTIVATE CLIENT -------------------------------"); + return performClientActions(createClientOperationURL(ACTIVATE_CLIENT_COMMAND, clientId), getActivateClientAsJSON(), clientId); + } + + public HashMap<String, Object> withdrawClient(final Integer clientId) { + System.out.println("--------------------------------- WITHDRAWN CLIENT -------------------------------"); + return performClientActions(createClientOperationURL(WITHDRAW_CLIENT_COMMAND, clientId), getWithdrawClientAsJSON(), clientId); + } + + private String createClientOperationURL(final String command, final Integer clientId) { + return CLIENT_URL + "/" + clientId + "?command=" + command + "&" + Utils.TENANT_IDENTIFIER; + } + + private HashMap<String, Object> performClientActions(final String postURLForClient, final String jsonToBeSent, final Integer clientId) { + Utils.performServerPost(this.requestSpec, this.responseSpec, postURLForClient, jsonToBeSent, CommonConstants.RESPONSE_STATUS); + HashMap<String, Object> response = ClientHelper.getClientStatus(requestSpec, responseSpec, String.valueOf(clientId)); + + return response; + } + + public static Integer addChargesForClient(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final Integer clientId, final String request) { + System.out.println("--------------------------------- 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"); + } + + public static String payChargesForClients(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final Integer clientId, final Integer clientChargeId, final String json) { + System.out.println("--------------------------------- 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, ""); + return response.get("transactionId") != null ? response.get("transactionId").toString() : null; + } + + public static String waiveChargesForClients(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final Integer clientId, final Integer clientChargeId, final String json) { + System.out.println("--------------------------------- WAIVE CHARGES FOR CLIENT --------------------------------"); + final String CHARGES_URL = "/fineract-provider/api/v1/clients/" + clientId + "/charges/" + clientChargeId + "?command=waive&" + + Utils.TENANT_IDENTIFIER; + + final HashMap<?, ?> response = Utils.performServerPost(requestSpec, responseSpec, CHARGES_URL, json, ""); + return response.get("transactionId").toString(); + } + + public static Integer revertClientChargeTransaction(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final String clientId, String clientChargeId) { + System.out.println("---------------------------------UNDO TRANSACTION---------------------------------------------"); + final String CHARGES_URL = "/fineract-provider/api/v1/clients/" + clientId + "/transactions/" + clientChargeId + "?command=undo&" + + Utils.TENANT_IDENTIFIER; + + final HashMap<?, ?> response = Utils.performServerPost(requestSpec, responseSpec, CHARGES_URL, "", ""); + return (Integer) response.get("resourceId"); + + } + + public static Object getClientCharge(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final String clientId, final String clientChargeId) { + System.out.println("---------------------------------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"); + } + + public static Boolean getClientTransactions(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final String clientId, final String transactionId) { + System.out.println("---------------------------------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"); + } + +} \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/4b1ec9ef/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/CommonConstants.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/CommonConstants.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/CommonConstants.java new file mode 100755 index 0000000..8ec47af --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/CommonConstants.java @@ -0,0 +1,31 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.integrationtests.common; + + +public interface CommonConstants { + + public final static String locale = "en"; + public static final String dateFormat = "dd MMMM yyyy"; + public static final String RESPONSE_RESOURCE_ID = "resourceId"; + public static final String RESPONSE_CHANGES = "changes"; + public static final String RESPONSE_STATUS = "status"; + public static final String RESPONSE_ERROR = "errors"; + public static final String RESPONSE_ERROR_MESSAGE_CODE = "userMessageGlobalisationCode"; +} http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/4b1ec9ef/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/CurrenciesHelper.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/CurrenciesHelper.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/CurrenciesHelper.java new file mode 100644 index 0000000..900e6bb --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/CurrenciesHelper.java @@ -0,0 +1,78 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.integrationtests.common; + +import java.util.ArrayList; +import java.util.HashMap; + +import com.google.common.reflect.TypeToken; +import com.google.gson.Gson; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; + +@SuppressWarnings({ "unused", "rawtypes", "unchecked" }) +public class CurrenciesHelper { + + private static final String CURRENCIES_URL = "/fineract-provider/api/v1/currencies"; + + public static ArrayList<CurrencyDomain> getAllCurrencies(final RequestSpecification requestSpec, + final ResponseSpecification responseSpec) { + final String GET_ALL_CURRENCIES_URL = CURRENCIES_URL + "?" + Utils.TENANT_IDENTIFIER; + System.out.println("------------------------ RETRIEVING ALL CURRENCIES -------------------------"); + final HashMap response = Utils.performServerGet(requestSpec, responseSpec, GET_ALL_CURRENCIES_URL, ""); + ArrayList<HashMap> selectedCurrencyOptions = (ArrayList<HashMap>) response.get("selectedCurrencyOptions"); + ArrayList<HashMap> currencyOptions = (ArrayList<HashMap>) response.get("currencyOptions"); + currencyOptions.addAll(selectedCurrencyOptions); + final String jsonData = new Gson().toJson(new ArrayList<HashMap>(selectedCurrencyOptions)); + return new Gson().fromJson(jsonData, new TypeToken<ArrayList<CurrencyDomain>>() {}.getType()); + } + + public static ArrayList<CurrencyDomain> getSelectedCurrencies(final RequestSpecification requestSpec, + final ResponseSpecification responseSpec) { + final String GET_ALL_SELECTED_CURRENCIES_URL = CURRENCIES_URL + "?fields=selectedCurrencyOptions" + "&" + Utils.TENANT_IDENTIFIER; + System.out.println("------------------------ RETRIEVING ALL SELECTED CURRENCIES -------------------------"); + final HashMap response = Utils.performServerGet(requestSpec, responseSpec, GET_ALL_SELECTED_CURRENCIES_URL, ""); + final String jsonData = new Gson().toJson(response.get("selectedCurrencyOptions")); + return new Gson().fromJson(jsonData, new TypeToken<ArrayList<CurrencyDomain>>() {}.getType()); + } + + public static CurrencyDomain getCurrencybyCode(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final String code) { + ArrayList<CurrencyDomain> currenciesList = getAllCurrencies(requestSpec, responseSpec); + for (CurrencyDomain e : currenciesList) { + if (e.getCode().equals(code)) return e; + } + return null; + } + + public static ArrayList<String> updateSelectedCurrencies(final RequestSpecification requestSpec, + final ResponseSpecification responseSpec, final ArrayList<String> currencies) { + final String CURRENCIES_UPDATE_URL = CURRENCIES_URL + "?" + Utils.TENANT_IDENTIFIER; + System.out.println("---------------------------------UPDATE SELECTED CURRENCIES LIST---------------------------------------------"); + HashMap hash = Utils.performServerPut(requestSpec, responseSpec, CURRENCIES_UPDATE_URL, currenciesToJSON(currencies), "changes"); + return (ArrayList<String>) hash.get("currencies"); + } + + private static String currenciesToJSON(final ArrayList<String> currencies) { + HashMap map = new HashMap<>(); + map.put("currencies", currencies); + System.out.println("map : " + map); + return new Gson().toJson(map); + } +} http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/4b1ec9ef/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/CurrencyDomain.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/CurrencyDomain.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/CurrencyDomain.java new file mode 100644 index 0000000..00cbc64 --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/CurrencyDomain.java @@ -0,0 +1,140 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.integrationtests.common; + +import com.google.gson.Gson; + +public class CurrencyDomain implements Comparable<CurrencyDomain> { + + public static class Builder { + + private String code; + private String name; + private int decimalPlaces; + private String displaySymbol; + private String nameCode; + private String displayLabel; + + private Builder(final String code, final String name, final int decimalPlaces, final String displaySymbol, final String nameCode, + final String displayLabel) { + this.code = code; + this.name = name; + this.decimalPlaces = decimalPlaces; + this.displaySymbol = displaySymbol; + this.nameCode = nameCode; + this.displayLabel = displayLabel; + } + + public CurrencyDomain build() { + return new CurrencyDomain(this.code, this.name, this.decimalPlaces, this.displaySymbol, this.nameCode, this.displayLabel); + } + } + + private String code; + private String name; + private int decimalPlaces; + private String displaySymbol; + private String nameCode; + private String displayLabel; + + CurrencyDomain() { + super(); + } + + private CurrencyDomain(final String code, final String name, final int decimalPlaces, final String displaySymbol, + final String nameCode, final String displayLabel) { + super(); + this.code = code; + this.name = name; + this.decimalPlaces = decimalPlaces; + this.displaySymbol = displaySymbol; + this.nameCode = nameCode; + this.displayLabel = displayLabel; + } + + public String getCode() { + return this.code; + } + + public int getDecimalPlaces() { + return this.decimalPlaces; + } + + public String getDisplaySymbol() { + return this.displaySymbol; + } + + public String getNameCode() { + return this.nameCode; + } + + public String getDisplayLabel() { + return this.displayLabel; + } + + public String getName() { + return this.name; + } + + public String toJSON() { + return new Gson().toJson(this); + } + + public static CurrencyDomain fromJSON(final String jsonData) { + return new Gson().fromJson(jsonData, CurrencyDomain.class); + } + + public static Builder create(final String code, final String name, final int decimalPlaces, final String displaySymbol, + final String nameCode, final String displayLabel) { + return new Builder(code, name, decimalPlaces, displaySymbol, nameCode, displayLabel); + } + + @Override + public int hashCode() { + int hash = 1; + + if (this.name != null) hash += this.name.hashCode(); + if (this.code != null) hash += this.code.hashCode(); + if (this.decimalPlaces >= 0) hash += this.decimalPlaces; + if (this.displaySymbol != null) hash += this.displaySymbol.hashCode(); + if (this.nameCode != null) hash += this.nameCode.hashCode(); + if (this.displayLabel != null) hash += this.displayLabel.hashCode(); + + return hash; + } + + @Override + public boolean equals(Object obj) { + if (obj == this) { return true; } + + if (!(obj instanceof CurrencyDomain)) return false; + + CurrencyDomain cd = (CurrencyDomain) obj; + + if (this.name.equals(cd.name) && this.code.equals(cd.code) && this.decimalPlaces == cd.decimalPlaces + && this.displaySymbol.equals(cd.displaySymbol) && this.nameCode.equals(cd.nameCode) + && this.displayLabel.equals(cd.displayLabel)) return true; + return false; + } + + @Override + public int compareTo(CurrencyDomain cd) { + return this.name.compareTo(cd.getName()); + } +} http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/4b1ec9ef/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/ExternalServicesConfigurationHelper.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/ExternalServicesConfigurationHelper.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/ExternalServicesConfigurationHelper.java new file mode 100644 index 0000000..35011db --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/ExternalServicesConfigurationHelper.java @@ -0,0 +1,64 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.integrationtests.common; + +import java.util.ArrayList; +import java.util.HashMap; + +import com.google.gson.Gson; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; + +public class ExternalServicesConfigurationHelper { + + private final RequestSpecification requestSpec; + private final ResponseSpecification responseSpec; + + public ExternalServicesConfigurationHelper(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { + this.requestSpec = requestSpec; + this.responseSpec = responseSpec; + } + + public static ArrayList<HashMap> getExternalServicesConfigurationByServiceName(final RequestSpecification requestSpec, + final ResponseSpecification responseSpec, final String serviceName) { + final String GET_EXTERNAL_SERVICES_CONFIG_BY_SERVICE_NAME_URL = "/fineract-provider/api/v1/externalservice/" + serviceName + "?" + + Utils.TENANT_IDENTIFIER; + System.out.println("------------------------ RETRIEVING GLOBAL CONFIGURATION BY ID -------------------------"); + return Utils.performServerGet(requestSpec, responseSpec, GET_EXTERNAL_SERVICES_CONFIG_BY_SERVICE_NAME_URL, ""); + } + + public static HashMap updateValueForExternaServicesConfiguration(final RequestSpecification requestSpec, + final ResponseSpecification responseSpec, final String serviceName, final String name, final String value) { + final String EXTERNAL_SERVICES_CONFIG_UPDATE_URL = "/fineract-provider/api/v1/externalservice/" + serviceName + "?" + + Utils.TENANT_IDENTIFIER; + System.out.println("---------------------------------UPDATE VALUE FOR GLOBAL CONFIG---------------------------------------------"); + HashMap map = Utils.performServerPut(requestSpec, responseSpec, EXTERNAL_SERVICES_CONFIG_UPDATE_URL, + updateExternalServicesConfigUpdateValueAsJSON(name, value), ""); + + return (HashMap) map.get("changes"); + } + + public static String updateExternalServicesConfigUpdateValueAsJSON(final String name, final String value) { + final HashMap<String, String> map = new HashMap<>(); + map.put(name, value); + System.out.println("map : " + map); + return new Gson().toJson(map); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/4b1ec9ef/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/GlobalConfigurationHelper.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/GlobalConfigurationHelper.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/GlobalConfigurationHelper.java new file mode 100644 index 0000000..d1acfb8 --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/GlobalConfigurationHelper.java @@ -0,0 +1,127 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.integrationtests.common; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +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 = "/fineract-provider/api/v1/configurations?" + Utils.TENANT_IDENTIFIER; + 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 = "/fineract-provider/api/v1/configurations/" + configId + "?" + Utils.TENANT_IDENTIFIER; + 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 = "/fineract-provider/api/v1/configurations/" + configId + "?" + Utils.TENANT_IDENTIFIER; + 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 = "/fineract-provider/api/v1/configurations/" + configId + "?" + Utils.TENANT_IDENTIFIER; + 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 = "/fineract-provider/api/v1/caches?" + Utils.TENANT_IDENTIFIER; + 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 = "/fineract-provider/api/v1/caches?" + Utils.TENANT_IDENTIFIER; + 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 Object updatePasswordResetDaysForGlobalConfiguration(final RequestSpecification requestSpec, + 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; + System.out.println("------------------UPDATE GLOBAL CONFIG FOR FORCE PASSWORD RESET DAYS----------------------"); + return Utils.performServerPut(requestSpec, responseSpec, UPDATE_URL, + updatePasswordResetDaysGlobalConfigAsJSON(value, enabled), jsonAttributeToGetBack); + } + + public static String updateGlobalConfigUpdateValueAsJSON(final String value) { + final HashMap<String, String> map = new HashMap<>(); + map.put("value", value); + System.out.println("map : " + map); + return new Gson().toJson(map); + } + + public static String updatePasswordResetDaysGlobalConfigAsJSON(final String value, final String enabled) { + final HashMap<String, String> map = new HashMap<>(); + if(value != null){ + map.put("value", value); + } + map.put("enabled", enabled); + 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<>(); + map.put("cacheType", cacheType); + System.out.println("map : " + map); + return new Gson().toJson(map); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/4b1ec9ef/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/GroupHelper.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/GroupHelper.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/GroupHelper.java new file mode 100755 index 0000000..f8a3af0 --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/GroupHelper.java @@ -0,0 +1,230 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.integrationtests.common; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import org.apache.commons.lang3.StringUtils; + +import com.google.gson.Gson; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; + +public class GroupHelper { + + private static final String CREATE_GROUP_URL = "/fineract-provider/api/v1/groups?" + Utils.TENANT_IDENTIFIER; + + public static Integer createGroup(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + @SuppressWarnings("unused") final boolean active) { + System.out.println("---------------------------------CREATING A GROUP---------------------------------------------"); + return createGroup(requestSpec, responseSpec, "04 March 2011"); + } + + public static Integer createGroup(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final String activationDate) { + System.out.println("---------------------------------CREATING A GROUP---------------------------------------------"); + return Utils.performServerPost(requestSpec, responseSpec, CREATE_GROUP_URL, getTestGroupAsJSON(true, activationDate), "groupId"); + } + + public static Integer createGroup(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { + System.out.println("---------------------------------CREATING A GROUP---------------------------------------------"); + return Utils.performServerPost(requestSpec, responseSpec, CREATE_GROUP_URL, getTestGroupAsJSON(false, ""), "groupId"); + } + + public static Integer associateClient(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final String groupId, final String clientMember) { + final String GROUP_ASSOCIATE_URL = "/fineract-provider/api/v1/groups/" + groupId + + "?command=associateClients&" + Utils.TENANT_IDENTIFIER; + System.out.println("---------------------------------Associate Client To A GROUP---------------------------------------------"); + return Utils.performServerPost(requestSpec, responseSpec, GROUP_ASSOCIATE_URL, associateClientAsJSON(clientMember), "groupId"); + } + + public static Integer disAssociateClient(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final String groupId, final String clientMember) { + final String GROUP_ASSOCIATE_URL = "/fineract-provider/api/v1/groups/" + groupId + + "?command=disassociateClients&" + Utils.TENANT_IDENTIFIER; + System.out.println("---------------------------------Disassociate Client To A GROUP---------------------------------------------"); + return Utils.performServerPost(requestSpec, responseSpec, GROUP_ASSOCIATE_URL, associateClientAsJSON(clientMember), "groupId"); + } + + public static Integer activateGroup(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final String groupId) { + final String GROUP_ASSOCIATE_URL = "/fineract-provider/api/v1/groups/" + groupId + "?command=activate&" + Utils.TENANT_IDENTIFIER; + System.out.println("---------------------------------Activate A GROUP---------------------------------------------"); + return Utils.performServerPost(requestSpec, responseSpec, GROUP_ASSOCIATE_URL, activateGroupAsJSON(""), "groupId"); + } + + public static Integer updateGroup(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, final String name, + final String groupId) { + final String GROUP_ASSOCIATE_URL = "/fineract-provider/api/v1/groups/" + groupId + "?" + Utils.TENANT_IDENTIFIER; + System.out.println("---------------------------------UPDATE GROUP---------------------------------------------"); + return Utils.performServerPut(requestSpec, responseSpec, GROUP_ASSOCIATE_URL, updateGroupAsJSON(name), "groupId"); + } + + public static Integer deleteGroup(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, final String groupId) { + final String GROUP_ASSOCIATE_URL = "/fineract-provider/api/v1/groups/" + groupId + "?" + Utils.TENANT_IDENTIFIER; + System.out.println("---------------------------------DELETE GROUP---------------------------------------------"); + return Utils.performServerDelete(requestSpec, responseSpec, GROUP_ASSOCIATE_URL, "groupId"); + } + + + public static Object assignStaff(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, final String groupId,final Long staffId){ + final String GROUP_ASSIGN_STAFF_URL = "/fineract-provider/api/v1/groups/" + groupId + "?" + Utils.TENANT_IDENTIFIER + "&command=assignStaff"; + System.out.println("---------------------------------DELETE GROUP---------------------------------------------"); + return Utils.performServerPost(requestSpec, responseSpec, GROUP_ASSIGN_STAFF_URL,assignStaffAsJSON(staffId),"changes"); + } + public static Object assignStaffInheritStaffForClientAccounts(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, final String groupId,final String staffId){ + final String GROUP_ASSIGN_STAFF_URL = "/fineract-provider/api/v1/groups/" + groupId + "?" + Utils.TENANT_IDENTIFIER + "&command=assignStaff"; + System.out.println("---------------------------------DELETE GROUP---------------------------------------------"); + return Utils.performServerPost(requestSpec, responseSpec, GROUP_ASSIGN_STAFF_URL,assignStaffAndInheritStaffForClientAccountsAsJSON(staffId),"changes"); + } + + + public static String getTestGroupAsJSON(final boolean active, final String activationDate) { + final HashMap<String, String> map = new HashMap<>(); + map.put("officeId", "1"); + map.put("name", randomNameGenerator("Group_Name_", 5)); + map.put("externalId", randomIDGenerator("ID_", 7)); + map.put("dateFormat", "dd MMMM yyyy"); + map.put("locale", "en"); + if (active) { + map.put("active", "true"); + map.put("activationDate", activationDate); + } else { + map.put("active", "false"); + map.put("submittedOnDate", "04 March 2011"); + System.out.println("defaulting to inactive group: 04 March 2011"); + } + + System.out.println("map : " + map); + return new Gson().toJson(map); + } + + public static String associateClientAsJSON(final String clientMember) { + final HashMap<String, List<String>> map = new HashMap<String, List<String>>(); + final List<String> list = new ArrayList<>(); + list.add(clientMember); + map.put("clientMembers", list); + System.out.println("map : " + map); + return new Gson().toJson(map); + } + + public static String activateGroupAsJSON(final String activationDate) { + final HashMap<String, String> map = new HashMap<>(); + map.put("dateFormat", "dd MMMM yyyy"); + map.put("locale", "en"); + if (StringUtils.isNotEmpty(activationDate)) { + map.put("activationDate", activationDate); + } else { + map.put("activationDate", "04 March 2011"); + System.out.println("defaulting to fixed date: 04 March 2011"); + } + System.out.println("map : " + map); + return new Gson().toJson(map); + } + + public static String updateGroupAsJSON(final String name) { + final HashMap<String, String> map = new HashMap<>(); + map.put("name", name); + System.out.println("map : " + map); + return new Gson().toJson(map); + } + public static String assignStaffAsJSON(final Long staffId) { + final HashMap<String, Object> map = new HashMap<>(); + map.put("staffId", staffId); + System.out.println("map : " + map); + return new Gson().toJson(map); + } + public static String assignStaffAndInheritStaffForClientAccountsAsJSON(final String staffId) { + final HashMap<String, String> map = new HashMap<>(); + map.put("staffId", staffId); + map.put("inheritStaffForClientAccounts","true"); + System.out.println("map : " + map); + return new Gson().toJson(map); + } + + + public static void verifyGroupCreatedOnServer(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final Integer generatedGroupID) { + System.out.println("------------------------------CHECK GROUP DETAILS------------------------------------\n"); + final String GROUP_URL = "/fineract-provider/api/v1/groups/" + generatedGroupID + "?" + Utils.TENANT_IDENTIFIER; + final Integer responseGroupID = Utils.performServerGet(requestSpec, responseSpec, GROUP_URL, "id"); + assertEquals("ERROR IN CREATING THE GROUP", generatedGroupID, responseGroupID); + } + + public static void verifyGroupDetails(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final Integer generatedGroupID, final String field, final String expectedValue) { + System.out.println("------------------------------CHECK GROUP DETAILS------------------------------------\n"); + final String GROUP_URL = "/fineract-provider/api/v1/groups/" + generatedGroupID + "?" + Utils.TENANT_IDENTIFIER; + final String responseValue = Utils.performServerGet(requestSpec, responseSpec, GROUP_URL, field); + assertEquals("ERROR IN CREATING THE GROUP", expectedValue, responseValue); + } + + public static void verifyGroupActivatedOnServer(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final Integer generatedGroupID, final boolean generatedGroupStatus) { + System.out.println("------------------------------CHECK GROUP STATUS------------------------------------\n"); + final String GROUP_URL = "/fineract-provider/api/v1/groups/" + generatedGroupID + "?" + Utils.TENANT_IDENTIFIER; + final Boolean responseGroupStatus = Utils.performServerGet(requestSpec, responseSpec, GROUP_URL, "active"); + assertEquals("ERROR IN ACTIVATING THE GROUP", generatedGroupStatus, responseGroupStatus); + } + + public static void verifyGroupMembers(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final Integer generatedGroupID, final Integer groupMember) { + List<String> list = new ArrayList<>(); + System.out.println("------------------------------CHECK GROUP MEMBERS------------------------------------\n"); + final String GROUP_URL = "/fineract-provider/api/v1/groups/" + generatedGroupID + + "?associations=clientMembers&" + Utils.TENANT_IDENTIFIER; + list = Utils.performServerGet(requestSpec, responseSpec, GROUP_URL, "clientMembers"); + assertTrue("ERROR IN GROUP MEMBER", list.toString().contains("id=" + groupMember.toString())); + } + + public static void verifyEmptyGroupMembers(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final Integer generatedGroupID) { + List<String> list = new ArrayList<>(); + System.out.println("------------------------------CHECK EMPTY GROUP MEMBER LIST------------------------------------\n"); + final String GROUP_URL = "/fineract-provider/api/v1/groups/" + generatedGroupID + + "?associations=clientMembers&" + Utils.TENANT_IDENTIFIER; + list = Utils.performServerGet(requestSpec, responseSpec, GROUP_URL, "clientMembers"); + assertEquals("GROUP MEMBER LIST NOT EMPTY", list, null); + } + + public static void verifyGroupDeleted(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final Integer generatedGroupID) { + List<String> list = new ArrayList<>(); + System.out.println("------------------------------CHECK GROUP DELETED------------------------------------\n"); + final String GROUP_URL = "/fineract-provider/api/v1/groups/?" + Utils.TENANT_IDENTIFIER; + list = Utils.performServerGet(requestSpec, responseSpec, GROUP_URL, "pageItems"); + + assertFalse("GROUP NOT DELETED", list.toString().contains("id=" + generatedGroupID.toString())); + } + + public static String randomNameGenerator(final String prefix, final int lenOfRandomSuffix) { + return Utils.randomStringGenerator(prefix, lenOfRandomSuffix); + } + + private static String randomIDGenerator(final String prefix, final int lenOfRandomSuffix) { + return Utils.randomStringGenerator(prefix, lenOfRandomSuffix, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/4b1ec9ef/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/HolidayHelper.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/HolidayHelper.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/HolidayHelper.java new file mode 100644 index 0000000..d8b90ad --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/HolidayHelper.java @@ -0,0 +1,92 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.integrationtests.common; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import org.apache.fineract.integrationtests.common.Utils; + +import com.google.gson.Gson; +import com.jayway.restassured.specification.RequestSender; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; + +@SuppressWarnings({ "unused", "rawtypes" }) +public class HolidayHelper { + + private static final String HOLIDAYS_URL = "/fineract-provider/api/v1/holidays"; + private static final String CREATE_HOLIDAY_URL = HOLIDAYS_URL + "?" + Utils.TENANT_IDENTIFIER; + + private static final String OFFICE_ID = "1"; + + private final RequestSpecification requestSpec; + private final ResponseSpecification responseSpec; + + public HolidayHelper(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { + this.requestSpec = requestSpec; + this.responseSpec = responseSpec; + } + + public static String getCreateHolidayDataAsJSON() { + final HashMap<String, Object> map = new HashMap<>(); + List<HashMap<String, String>> offices = new ArrayList<HashMap<String, String>>(); + HashMap<String, String> officeMap = new HashMap<>(); + officeMap.put("officeId", OFFICE_ID); + offices.add(officeMap); + + map.put("offices", offices); + map.put("locale", "en"); + map.put("dateFormat", "dd MMMM yyyy"); + map.put("name", Utils.randomNameGenerator("HOLIDAY_", 5)); + map.put("fromDate", "01 April 2013"); + map.put("toDate", "01 April 2013"); + map.put("repaymentsRescheduledTo", "08 April 2013"); + + String HolidayCreateJson = new Gson().toJson(map); + System.out.println(HolidayCreateJson); + return HolidayCreateJson; + } + + public static String getActivateHolidayDataAsJSON() { + final HashMap<String, String> map = new HashMap<>(); + String activateHoliday = new Gson().toJson(map); + System.out.println(activateHoliday); + return activateHoliday; + } + + public static Integer createHolidays(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { + return Utils.performServerPost(requestSpec, responseSpec, CREATE_HOLIDAY_URL, getCreateHolidayDataAsJSON(), "resourceId"); + } + + public static Integer activateHolidays(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, final String holidayID) { + final String ACTIVATE_HOLIDAY_URL = HOLIDAYS_URL + "/" + holidayID + "?command=activate&" + Utils.TENANT_IDENTIFIER; + return Utils.performServerPost(requestSpec, responseSpec, ACTIVATE_HOLIDAY_URL, getActivateHolidayDataAsJSON(), "resourceId"); + } + + public static HashMap getHolidayById(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final String holidayID) { + final String GET_HOLIDAY_BY_ID_URL = HOLIDAYS_URL + "/" + holidayID + "?" + Utils.TENANT_IDENTIFIER; + System.out.println("------------------------ RETRIEVING HOLIDAY BY ID -------------------------"); + final HashMap response = Utils.performServerGet(requestSpec, responseSpec, GET_HOLIDAY_BY_ID_URL, ""); + return response; + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/4b1ec9ef/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/HookHelper.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/HookHelper.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/HookHelper.java new file mode 100644 index 0000000..c2ca23f --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/HookHelper.java @@ -0,0 +1,103 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.integrationtests.common; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.HashMap; + +import com.google.gson.Gson; +import com.jayway.restassured.builder.ResponseSpecBuilder; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; + +public class HookHelper { + + private final RequestSpecification requestSpec; + private final ResponseSpecification responseSpec; + + private static final String CREATE_HOOK_URL = "/fineract-provider/api/v1/hooks?" + Utils.TENANT_IDENTIFIER; + + public HookHelper(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { + this.requestSpec = requestSpec; + this.responseSpec = responseSpec; + } + + public Integer createHook(final String payloadURL) { + System.out.println("---------------------------------CREATING A HOOK---------------------------------------------"); + return Utils.performServerPost(requestSpec, responseSpec, CREATE_HOOK_URL, getTestHookAsJson(payloadURL), + "resourceId"); + } + + public String getTestHookAsJson(final String payloadURL) { + final HashMap<String, Object> map = new HashMap<>(); + map.put("name", "Web"); + map.put("displayName", Utils.randomNameGenerator("Hook_DisplayName_", 5)); + map.put("isActive", "true"); + final HashMap<String, String> config = new HashMap<>(); + config.put("Content Type", "json"); + config.put("Payload URL", payloadURL); + map.put("config", config); + final ArrayList<HashMap<String, String>> events = new ArrayList<>(); + final HashMap<String, String> createOfficeEvent = new HashMap<>(); + createOfficeEvent.put("actionName", "CREATE"); + createOfficeEvent.put("entityName", "OFFICE"); + events.add(createOfficeEvent); + map.put("events", events); + System.out.println("map : " + map); + return new Gson().toJson(map); + } + + public Integer updateHook(final String payloadURL, final Long hookId) { + System.out.println("---------------------------------UPDATING HOOK---------------------------------------------"); + final String UPDATE_HOOK_URL = "/fineract-provider/api/v1/hooks/" + hookId + "?" + Utils.TENANT_IDENTIFIER; + return Utils.performServerPut(this.requestSpec, this.responseSpec, UPDATE_HOOK_URL, getTestHookAsJson(payloadURL), "resourceId"); + } + + public Integer deleteHook(final Long hookId) { + System.out.println("---------------------------------DELETING HOOK---------------------------------------------"); + final String DELETE_HOOK_URL = "/fineract-provider/api/v1/hooks/" + hookId + "?" + Utils.TENANT_IDENTIFIER; + return Utils.performServerDelete(this.requestSpec, this.responseSpec, DELETE_HOOK_URL, "resourceId"); + } + + public void verifyHookCreatedOnServer(final Long hookId) { + System.out.println("------------------------------CHECK CREATE HOOK DETAILS------------------------------------\n"); + final String GET_URL = "/fineract-provider/api/v1/hooks/" + hookId + "?" + Utils.TENANT_IDENTIFIER; + final Integer responseHookId = Utils.performServerGet(this.requestSpec, this.responseSpec, GET_URL, "id"); + assertEquals(hookId.toString(), responseHookId.toString()); + } + + public void verifyUpdateHook(final String updateURL, final Long hookId) { + System.out.println("------------------------------CHECK UPDATE HOOK DETAILS------------------------------------\n"); + final String GET_URL = "/fineract-provider/api/v1/hooks/" + hookId + "?" + Utils.TENANT_IDENTIFIER; + ArrayList map = Utils.performServerGet(this.requestSpec, this.responseSpec, GET_URL, "config"); + HashMap<String, String> hash = (HashMap<String, String>) map.get(1); + assertEquals(updateURL, hash.get("fieldValue")); + } + + public void verifyDeleteHook(final Long hookId) { + System.out.println("------------------------------CHECK DELETE HOOK DETAILS------------------------------------\n"); + final String GET_URL = "/fineract-provider/api/v1/hooks/" + hookId + "?" + Utils.TENANT_IDENTIFIER; + ResponseSpecification responseSpec404 = new ResponseSpecBuilder().expectStatusCode(404).build(); + ArrayList array = Utils.performServerGet(this.requestSpec, responseSpec404, GET_URL, "errors"); + HashMap<String, String> map = (HashMap<String, String>)array.get(0); + assertEquals("error.msg.hook.identifier.not.found",map.get("userMessageGlobalisationCode")); + } +} http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/4b1ec9ef/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/ImageHelper.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/ImageHelper.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/ImageHelper.java new file mode 100644 index 0000000..c076740 --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/ImageHelper.java @@ -0,0 +1,73 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.integrationtests.common; + +import org.apache.http.HttpHeaders; + +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; + +public class ImageHelper { + + private static final String STAFF_IMAGE_URL = "/fineract-provider/api/v1/staff/"; + private static final String IMAGES_URI = "/images"; + + public static Integer createImageForStaff(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + Integer staffId) { + System.out.println("---------------------------------CREATING AN IMAGE FOR STAFF---------------------------------------------"); + String URL = STAFF_IMAGE_URL + staffId + IMAGES_URI + "?" + Utils.TENANT_IDENTIFIER; + return Utils.performServerPost(requestSpec, responseSpec, URL, generateImageAsText(), "resourceId"); + } + + public static Integer updateImageForStaff(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + Integer staffId) { + System.out.println("---------------------------------UPDATING AN IMAGE FOR STAFF---------------------------------------------"); + String URL = STAFF_IMAGE_URL + staffId + IMAGES_URI + "?" + Utils.TENANT_IDENTIFIER; + return Utils.performServerPut(requestSpec, responseSpec, URL, generateImageAsText(), "resourceId"); + } + + public static String getStaffImageAsText(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + Integer staffId) { + System.out.println("---------------------------------RETRIEVING STAFF IMAGE---------------------------------------------"); + String URL = STAFF_IMAGE_URL + staffId + IMAGES_URI + "?" + Utils.TENANT_IDENTIFIER; + requestSpec.header(HttpHeaders.ACCEPT, "text/plain"); + return Utils.performGetTextResponse(requestSpec, responseSpec, URL); + } + + public static byte[] getStaffImageAsBinary(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + Integer staffId) { + System.out.println("---------------------------------RETRIEVING STAFF IMAGE---------------------------------------------"); + String URL = STAFF_IMAGE_URL + staffId + IMAGES_URI + "?" + Utils.TENANT_IDENTIFIER; + requestSpec.header(HttpHeaders.ACCEPT, "application/octet-stream"); + return Utils.performGetBinaryResponse(requestSpec, responseSpec, URL); + } + + public static Integer deleteStaffImage(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, Integer staffId) { + System.out.println("---------------------------------RETRIEVING STAFF IMAGE---------------------------------------------"); + String URL = STAFF_IMAGE_URL + staffId + IMAGES_URI + "?" + Utils.TENANT_IDENTIFIER; + return Utils.performServerDelete(requestSpec, responseSpec, URL, "resourceId"); + } + + private static String generateImageAsText() { + return "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJ\n" + + "bWFnZVJlYWR5ccllPAAAAJ1JREFUeNpi+P//PwMIA4E9EG8E4idQDGLbw+WhiiqA+D8OXAFVAzbp\n" + + "DxBvB2JLIGaGYkuoGEjOhhFIHAbij0BdPgxYACMj42ogJQpifwBiXSDeC8JIbt4LxSC5DyxQjTeB\n" + + "+BeaYb+Q5EBOAVutCzMJHUNNPADzzDokiYdAfAmJvwLkGeTgWQfyKZICS6hYBTwc0QL8ORSjBDhA\n" + "gAEAOg13B6R/SAgAAAAASUVORK5CYII="; + } +} http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/4b1ec9ef/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/LoanRescheduleRequestHelper.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/LoanRescheduleRequestHelper.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/LoanRescheduleRequestHelper.java new file mode 100644 index 0000000..7e10e9d --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/LoanRescheduleRequestHelper.java @@ -0,0 +1,66 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.integrationtests.common; + +import static org.junit.Assert.assertEquals; + +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; + +public class LoanRescheduleRequestHelper { + private final RequestSpecification requestSpec; + private final ResponseSpecification responseSpec; + + private static final String LOAN_RESCHEDULE_REQUEST_URL = "/fineract-provider/api/v1/rescheduleloans"; + + public LoanRescheduleRequestHelper(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { + this.requestSpec = requestSpec; + this.responseSpec = responseSpec; + } + + public Integer createLoanRescheduleRequest(final String requestJSON) { + final String URL = LOAN_RESCHEDULE_REQUEST_URL + "?" + Utils.TENANT_IDENTIFIER; + return Utils.performServerPost(this.requestSpec, this.responseSpec, URL, requestJSON, "resourceId"); + } + + public Integer rejectLoanRescheduleRequest(final Integer requestId, final String requestJSON) { + final String URL = LOAN_RESCHEDULE_REQUEST_URL + "/" + requestId + "?" + Utils.TENANT_IDENTIFIER + "&command=reject"; + + return Utils.performServerPost(this.requestSpec, this.responseSpec, URL, requestJSON, "resourceId"); + } + + public Integer approveLoanRescheduleRequest(final Integer requestId, final String requestJSON) { + final String URL = LOAN_RESCHEDULE_REQUEST_URL + "/" + requestId + "?" + Utils.TENANT_IDENTIFIER + "&command=approve"; + + return Utils.performServerPost(this.requestSpec, this.responseSpec, URL, requestJSON, "resourceId"); + } + + public Object getLoanRescheduleRequest(final Integer requestId, final String param) { + final String URL = LOAN_RESCHEDULE_REQUEST_URL + "/" + requestId + "?" + Utils.TENANT_IDENTIFIER; + + return Utils.performServerGet(requestSpec, responseSpec, URL, param); + } + + public void verifyCreationOfLoanRescheduleRequest(final Integer requestId) { + final String URL = LOAN_RESCHEDULE_REQUEST_URL + "/" + requestId + "?" + Utils.TENANT_IDENTIFIER; + + final Integer id = Utils.performServerGet(requestSpec, responseSpec, URL, "id"); + assertEquals("ERROR IN CREATING LOAN RESCHEDULE REQUEST", requestId, id); + } +} http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/4b1ec9ef/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/OfficeDomain.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/OfficeDomain.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/OfficeDomain.java new file mode 100644 index 0000000..1032b24 --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/OfficeDomain.java @@ -0,0 +1,153 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.integrationtests.common; + +import com.google.gson.Gson; + +public class OfficeDomain { + + public static class Builder { + + private int id; + private String name; + private String nameDecorated; + private String externalId; + private String[] openingDate; + private String hierarchy; + + private Builder(final int id, final String name, + final String nameDecorated, final String externalId, + final String[] openingDate, final String hierarchy) { + this.id = id; + this.name = name; + this.nameDecorated = nameDecorated; + this.externalId = externalId; + this.openingDate = openingDate; + this.hierarchy = hierarchy; + } + + public OfficeDomain build() { + return new OfficeDomain(this.id, this.name, this.nameDecorated, + this.externalId, this.openingDate, this.hierarchy); + } + } + + private int id; + private String name; + private String nameDecorated; + private String externalId; + private String[] openingDate; + private String hierarchy; + + OfficeDomain() { + super(); + } + + private OfficeDomain(final int id, final String name, + final String nameDecorated, final String externalId, + final String[] openingDate, final String hierarchy) { + super(); + this.id = id; + this.name = name; + this.nameDecorated = nameDecorated; + this.externalId = externalId; + this.openingDate = openingDate; + this.hierarchy = hierarchy; + } + + public String toJSON() { + return new Gson().toJson(this); + } + + public static OfficeDomain fromJSON(final String jsonData) { + return new Gson().fromJson(jsonData, OfficeDomain.class); + } + + public static Builder create(final int id, final String name, + final String nameDecorated, final String externalId, + final String[] openingDate, final String hierarchy) { + return new Builder(id, name, nameDecorated, externalId, openingDate, + hierarchy); + } + + public int getId() { + return this.id; + } + + public String getName() { + return this.name; + } + + public String getNameDecorated() { + return this.nameDecorated; + } + + public String getExternalId() { + return this.externalId; + } + + public String[] getOpeningDate() { + return this.openingDate; + } + + public String getHierarchy() { + return this.hierarchy; + } + + @Override + public int hashCode() { + int hash = 1; + + if (this.id > 0) + hash += this.id; + if (this.name != null) + hash += this.name.hashCode(); + if (this.nameDecorated != null) + hash += this.nameDecorated.hashCode(); + if (this.externalId != null) + hash += this.externalId.hashCode(); + if (this.openingDate != null) + hash += this.openingDate.hashCode(); + if (this.hierarchy != null) + hash += this.hierarchy.hashCode(); + + return hash; + } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + + if (!(obj instanceof OfficeDomain)) + return false; + + OfficeDomain od = (OfficeDomain) obj; + + if (this.id == od.getId() && this.name.equals(od.getName()) + && this.nameDecorated.equals(od.getName()) + && this.externalId.equals(od.getExternalId()) + && this.openingDate.equals(od.getOpeningDate()) + && this.hierarchy.equals(od.getHierarchy())) + return true; + + return false; + } +} \ No newline at end of file
