+81
@@ -0,0 +1,81 @@
|
||||
/**
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
package org.mifosplatform.integrationtests;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mifosplatform.integrationtests.common.CurrenciesHelper;
|
||||
import org.mifosplatform.integrationtests.common.CurrencyDomain;
|
||||
import org.mifosplatform.integrationtests.common.Utils;
|
||||
|
||||
import com.jayway.restassured.builder.RequestSpecBuilder;
|
||||
import com.jayway.restassured.builder.ResponseSpecBuilder;
|
||||
import com.jayway.restassured.http.ContentType;
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
@SuppressWarnings({ "unused", "rawtypes" })
|
||||
public class CurrenciesTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
Utils.initializeRESTAssured();
|
||||
this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
|
||||
this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
|
||||
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCurrency() {
|
||||
|
||||
CurrencyDomain currency = CurrenciesHelper.getCurrencybyCode(requestSpec, responseSpec, "USD");
|
||||
CurrencyDomain usd = CurrencyDomain.create("USD", "US Dollar", 2, "$", "currency.USD", "US Dollar ($)").build();
|
||||
|
||||
Assert.assertTrue(currency.getDecimalPlaces() >= 0);
|
||||
Assert.assertNotNull(currency.getName());
|
||||
Assert.assertNotNull(currency.getDisplaySymbol());
|
||||
Assert.assertNotNull(currency.getDisplayLabel());
|
||||
Assert.assertNotNull(currency.getNameCode());
|
||||
|
||||
Assert.assertEquals(usd, currency);
|
||||
}
|
||||
|
||||
public void testCurrencySelection() {
|
||||
|
||||
// Test updation
|
||||
ArrayList<String> currenciestoUpdate = new ArrayList<String>();
|
||||
currenciestoUpdate.add("KES");
|
||||
currenciestoUpdate.add("BND");
|
||||
currenciestoUpdate.add("LBP");
|
||||
currenciestoUpdate.add("GHC");
|
||||
currenciestoUpdate.add("USD");
|
||||
|
||||
ArrayList<String> currenciesOutput = CurrenciesHelper.updateSelectedCurrencies(this.requestSpec, this.responseSpec,
|
||||
currenciestoUpdate);
|
||||
Assert.assertNotNull(currenciesOutput);
|
||||
|
||||
Assert.assertEquals("Verifying Do Outputed Currencies Match after Updation", currenciestoUpdate, currenciesOutput);
|
||||
|
||||
// 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);
|
||||
|
||||
ArrayList<CurrencyDomain> currenciesAfterUpdate = CurrenciesHelper.getSelectedCurrencies(requestSpec, responseSpec);
|
||||
Assert.assertNotNull(currenciesAfterUpdate);
|
||||
|
||||
Assert.assertEquals("Verifying Do Selected Currencies Match after Updation", currenciesBeforeUpdate, currenciesAfterUpdate);
|
||||
}
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
/**
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
package org.mifosplatform.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 = "/mifosng-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---------------------------------------------");
|
||||
return (ArrayList<String>) Utils.performServerPut(requestSpec, responseSpec, CURRENCIES_UPDATE_URL, currenciesToJSON(currencies),
|
||||
"currencies");
|
||||
}
|
||||
|
||||
private static String currenciesToJSON(final ArrayList<String> currencies) {
|
||||
HashMap map = new HashMap<>();
|
||||
for (String e : currencies) {
|
||||
map.put("currencies", e);
|
||||
}
|
||||
System.out.println("map : " + map);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
}
|
||||
+127
@@ -0,0 +1,127 @@
|
||||
/**
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
package org.mifosplatform.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());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user