Merge pull request #1171 from MegaAlex/currencyTestSuite
Looks good (y)
This commit is contained in:
+32
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* 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 org.junit.Before;
|
||||
import org.mifosplatform.integrationtests.common.Utils;
|
||||
import org.mifosplatform.integrationtests.common.savings.SavingsAccountHelper;
|
||||
|
||||
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;
|
||||
|
||||
public class CurrencyIntegrationTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
private SavingsAccountHelper savingsAccountHelper;
|
||||
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* 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.organisation;
|
||||
|
||||
public class Currency {
|
||||
|
||||
String code;
|
||||
String name;
|
||||
Integer decimalPlaces;
|
||||
String displaySymbol;
|
||||
String nameCode;
|
||||
String displayLabel;
|
||||
|
||||
public Currency(String code, String name, Integer decimalPlaces, String displaySymbol,
|
||||
String nameCode, String displayLabel) {
|
||||
this.code = code;
|
||||
this.name = name;
|
||||
this.decimalPlaces = decimalPlaces;
|
||||
this.displaySymbol = displaySymbol;
|
||||
this.nameCode = nameCode;
|
||||
this.displayLabel = displayLabel;
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return (this.code != null && this.code.length() == 3) &&
|
||||
(this.name != null && this.name.length() > 0) &&
|
||||
(this.decimalPlaces != null && this.decimalPlaces >= 0) &&
|
||||
(this.nameCode != null && this.nameCode.startsWith("currency.")) &&
|
||||
(this.displayLabel != null && this.displayLabel.length() > 0);
|
||||
|
||||
}
|
||||
}
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
/**
|
||||
* 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.organisation;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.mifosplatform.integrationtests.common.Utils;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
import static com.jayway.restassured.RestAssured.given;
|
||||
|
||||
public class CurrencyHelper {
|
||||
|
||||
private static final String CURRENCY_URL = "/mifosng-provider/api/v1/currencies?" + Utils.TENANT_IDENTIFIER;
|
||||
private static final String CURRENCY_URL_SELECTED = CURRENCY_URL + "&fields=selectedCurrencyOptions";
|
||||
|
||||
private static final List<String> permittedCurrencyArray = Arrays.asList("currencyOptions",
|
||||
"selectedCurrencyOptions");
|
||||
|
||||
private static final List<String> permittedCurrencyArraySelected = Arrays.asList("selectedCurrencyOptions");
|
||||
|
||||
private final RequestSpecification requestSpec;
|
||||
private final ResponseSpecification responseSpec;
|
||||
|
||||
public CurrencyHelper(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
this.requestSpec = requestSpec;
|
||||
this.responseSpec = responseSpec;
|
||||
}
|
||||
|
||||
public ArrayList<Currency> getPermittedCurrencies() {
|
||||
return getCurrencies(CURRENCY_URL, permittedCurrencyArray);
|
||||
}
|
||||
|
||||
public ArrayList<Currency> getSelectedCurrencies() {
|
||||
return getCurrencies(CURRENCY_URL_SELECTED, permittedCurrencyArraySelected);
|
||||
}
|
||||
|
||||
|
||||
private ArrayList<Currency> getCurrencies(final String getUrl, final List<String> permittedCurrencyArrays) {
|
||||
System.out.println("--------------------------------- GET CURRENCY OPTIONS -------------------------------");
|
||||
final String json = given().spec(requestSpec).expect().spec(responseSpec).log().ifError().when()
|
||||
.get(getUrl).andReturn().asString();
|
||||
final Gson gson = new Gson();
|
||||
Assert.notNull(json);
|
||||
final ArrayList<Currency> currencyList = new ArrayList<Currency>();
|
||||
final Type typeOfHashMap = new TypeToken<Map<String, List<Currency>>>() { }.getType();
|
||||
final Map<String, List<Currency>> responseMap = gson.fromJson(json, typeOfHashMap);
|
||||
for(Map.Entry<String, List<Currency>> entry : responseMap.entrySet()) {
|
||||
Assert.isTrue(permittedCurrencyArrays.contains(entry.getKey()));
|
||||
for(Currency currency : entry.getValue()) {
|
||||
currencyList.add(currency);
|
||||
}
|
||||
}
|
||||
return currencyList;
|
||||
}
|
||||
|
||||
public List<String> updateCurrencies(final List<String> currencies) {
|
||||
System.out.println("--------------------------------- UPDATE CURRENCY OPTIONS -------------------------------");
|
||||
final String json = given().spec(requestSpec).body(getUpdateJSON(currencies)).expect().spec(responseSpec).log().ifError().when()
|
||||
.put(CURRENCY_URL).andReturn().asString();
|
||||
final Gson gson = new Gson();
|
||||
Assert.notNull(json);
|
||||
final Type typeOfHashMap = new TypeToken<Map<String,Map<String, List<String>>>>() { }.getType();
|
||||
final Map<String,Map<String, List<String>>> responseMap = gson.fromJson(json, typeOfHashMap);
|
||||
return responseMap.get("changes").get("currencies");
|
||||
}
|
||||
|
||||
private String getUpdateJSON(final List<String> currencies) {
|
||||
final HashMap<String, List<String>> map = new HashMap<>();
|
||||
map.put("currencies", currencies);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user