FINERACT-2247: New command processing - Currency Management (org.apache.fineract.organisation.monetary)
This commit is contained in:
committed by
Aleksandar Vidakovic
parent
0629bb2d48
commit
4c3da5b06a
+23
-31
@@ -18,17 +18,20 @@
|
||||
*/
|
||||
package org.apache.fineract.integrationtests;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import org.apache.fineract.integrationtests.common.CurrenciesHelper;
|
||||
import org.apache.fineract.integrationtests.common.CurrencyDomain;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -52,43 +55,32 @@ public class CurrenciesTest {
|
||||
CurrencyDomain currency = CurrenciesHelper.getCurrencybyCode(requestSpec, responseSpec, "USD");
|
||||
CurrencyDomain usd = CurrencyDomain.create("USD", "US Dollar", 2, "$", "currency.USD", "US Dollar ($)").build();
|
||||
|
||||
Assertions.assertTrue(currency.getDecimalPlaces() >= 0);
|
||||
Assertions.assertNotNull(currency.getName());
|
||||
Assertions.assertNotNull(currency.getDisplaySymbol());
|
||||
Assertions.assertNotNull(currency.getDisplayLabel());
|
||||
Assertions.assertNotNull(currency.getNameCode());
|
||||
assertNotNull(currency);
|
||||
assertTrue(currency.getDecimalPlaces() >= 0);
|
||||
assertNotNull(currency.getName());
|
||||
assertNotNull(currency.getDisplaySymbol());
|
||||
assertNotNull(currency.getDisplayLabel());
|
||||
assertNotNull(currency.getNameCode());
|
||||
|
||||
Assertions.assertEquals(usd, currency);
|
||||
assertEquals(usd, currency);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateCurrencySelection() {
|
||||
var currenciestoUpdate = List.of("KES", "BND", "LBP", "GHC", "USD", "INR");
|
||||
|
||||
// Test updation
|
||||
ArrayList<String> currenciestoUpdate = new ArrayList<String>();
|
||||
currenciestoUpdate.add("KES");
|
||||
currenciestoUpdate.add("BND");
|
||||
currenciestoUpdate.add("LBP");
|
||||
currenciestoUpdate.add("GHC");
|
||||
currenciestoUpdate.add("USD");
|
||||
currenciestoUpdate.add("INR");
|
||||
var currenciesOutput = CurrenciesHelper.updateSelectedCurrencies(this.requestSpec, this.responseSpec, currenciestoUpdate);
|
||||
|
||||
ArrayList<String> currenciesOutput = CurrenciesHelper.updateSelectedCurrencies(this.requestSpec, this.responseSpec,
|
||||
currenciestoUpdate);
|
||||
Assertions.assertNotNull(currenciesOutput);
|
||||
assertNotNull(currenciesOutput);
|
||||
assertEquals(currenciestoUpdate, currenciesOutput, "Verifying returned currencies match after update");
|
||||
|
||||
Assertions.assertEquals(currenciestoUpdate, currenciesOutput, "Verifying Do Outputed Currencies Match after Updation");
|
||||
var currenciesBeforeUpdate = currenciestoUpdate.stream()
|
||||
.map(currency -> CurrenciesHelper.getCurrencybyCode(requestSpec, responseSpec, currency)).filter(Objects::nonNull).sorted()
|
||||
.toList();
|
||||
|
||||
// Test that output matches updation
|
||||
ArrayList<CurrencyDomain> currenciesBeforeUpdate = new ArrayList<CurrencyDomain>();
|
||||
for (String e : currenciestoUpdate) {
|
||||
currenciesBeforeUpdate.add(CurrenciesHelper.getCurrencybyCode(requestSpec, responseSpec, e));
|
||||
}
|
||||
Collections.sort(currenciesBeforeUpdate);
|
||||
var currenciesAfterUpdate = CurrenciesHelper.getSelectedCurrencies(requestSpec, responseSpec);
|
||||
|
||||
ArrayList<CurrencyDomain> currenciesAfterUpdate = CurrenciesHelper.getSelectedCurrencies(requestSpec, responseSpec);
|
||||
Assertions.assertNotNull(currenciesAfterUpdate);
|
||||
|
||||
Assertions.assertEquals(currenciesBeforeUpdate, currenciesAfterUpdate, "Verifying Do Selected Currencies Match after Updation");
|
||||
assertNotNull(currenciesAfterUpdate);
|
||||
assertEquals(currenciesBeforeUpdate, currenciesAfterUpdate, "Verifying selected currencies match after update");
|
||||
}
|
||||
}
|
||||
|
||||
+26
-26
@@ -24,6 +24,8 @@ import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -41,15 +43,13 @@ public final class CurrenciesHelper {
|
||||
// Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long,
|
||||
// org.apache.fineract.client.models.PostLoansLoanIdRequest)
|
||||
@Deprecated(forRemoval = true)
|
||||
public static ArrayList<CurrencyDomain> getAllCurrencies(final RequestSpecification requestSpec,
|
||||
final ResponseSpecification responseSpec) {
|
||||
final String GET_ALL_CURRENCIES_URL = CURRENCIES_URL + "?" + Utils.TENANT_IDENTIFIER;
|
||||
public static List<CurrencyDomain> getAllCurrencies(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
LOG.info("------------------------ 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");
|
||||
HashMap response = Utils.performServerGet(requestSpec, responseSpec, CURRENCIES_URL + "?" + Utils.TENANT_IDENTIFIER, "");
|
||||
var selectedCurrencyOptions = (ArrayList<HashMap>) response.get("selectedCurrencyOptions");
|
||||
var currencyOptions = (ArrayList<HashMap>) response.get("currencyOptions");
|
||||
currencyOptions.addAll(selectedCurrencyOptions);
|
||||
final String jsonData = new Gson().toJson(new ArrayList<HashMap>(selectedCurrencyOptions));
|
||||
var jsonData = new Gson().toJson(selectedCurrencyOptions);
|
||||
return new Gson().fromJson(jsonData, new TypeToken<ArrayList<CurrencyDomain>>() {}.getType());
|
||||
}
|
||||
|
||||
@@ -57,12 +57,12 @@ public final class CurrenciesHelper {
|
||||
// Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long,
|
||||
// org.apache.fineract.client.models.PostLoansLoanIdRequest)
|
||||
@Deprecated(forRemoval = true)
|
||||
public static ArrayList<CurrencyDomain> getSelectedCurrencies(final RequestSpecification requestSpec,
|
||||
public static List<CurrencyDomain> getSelectedCurrencies(final RequestSpecification requestSpec,
|
||||
final ResponseSpecification responseSpec) {
|
||||
final String GET_ALL_SELECTED_CURRENCIES_URL = CURRENCIES_URL + "?fields=selectedCurrencyOptions" + "&" + Utils.TENANT_IDENTIFIER;
|
||||
LOG.info("------------------------ 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"));
|
||||
HashMap response = Utils.performServerGet(requestSpec, responseSpec,
|
||||
CURRENCIES_URL + "?fields=selectedCurrencyOptions" + "&" + Utils.TENANT_IDENTIFIER, "");
|
||||
var jsonData = new Gson().toJson(response.get("selectedCurrencyOptions"));
|
||||
return new Gson().fromJson(jsonData, new TypeToken<ArrayList<CurrencyDomain>>() {}.getType());
|
||||
}
|
||||
|
||||
@@ -72,10 +72,10 @@ public final class CurrenciesHelper {
|
||||
@Deprecated(forRemoval = true)
|
||||
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;
|
||||
var currencies = getAllCurrencies(requestSpec, responseSpec);
|
||||
for (var currency : currencies) {
|
||||
if (currency.getCode().equals(code)) {
|
||||
return currency;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@@ -85,22 +85,22 @@ public final class CurrenciesHelper {
|
||||
// Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long,
|
||||
// org.apache.fineract.client.models.PostLoansLoanIdRequest)
|
||||
@Deprecated(forRemoval = true)
|
||||
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;
|
||||
LOG.info("---------------------------------UPDATE SELECTED CURRENCIES LIST---------------------------------------------");
|
||||
HashMap hash = Utils.performServerPut(requestSpec, responseSpec, CURRENCIES_UPDATE_URL, currenciesToJSON(currencies), "changes");
|
||||
return (ArrayList<String>) hash.get("currencies");
|
||||
public static List<String> updateSelectedCurrencies(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final List<String> currencies) {
|
||||
LOG.info(
|
||||
"---------------------------------UPDATE SELECTED CURRENCIES LIST (deprecated)---------------------------------------------");
|
||||
// TODO: this nested "changes" map makes no sense whatsover... in the future just use "currencies" (straight
|
||||
// forward, no nesting, no complexity)
|
||||
Map changes = Utils.performServerPut(requestSpec, responseSpec, CURRENCIES_URL + "?" + Utils.TENANT_IDENTIFIER,
|
||||
currenciesToJSON(currencies), "changes");
|
||||
return (List<String>) changes.get("currencies");
|
||||
}
|
||||
|
||||
// TODO: Rewrite to use fineract-client instead!
|
||||
// Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long,
|
||||
// org.apache.fineract.client.models.PostLoansLoanIdRequest)
|
||||
@Deprecated(forRemoval = true)
|
||||
private static String currenciesToJSON(final ArrayList<String> currencies) {
|
||||
HashMap map = new HashMap<>();
|
||||
map.put("currencies", currencies);
|
||||
LOG.info("map : {}", map);
|
||||
return new Gson().toJson(map);
|
||||
private static String currenciesToJSON(final List<String> currencies) {
|
||||
return new Gson().toJson(Map.of("currencies", currencies));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user