diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/CurrencyIntegrationTest.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/CurrencyIntegrationTest.java new file mode 100644 index 000000000..5b5a502bd --- /dev/null +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/CurrencyIntegrationTest.java @@ -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(); + } +} diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/organisation/Currency.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/organisation/Currency.java new file mode 100644 index 000000000..3c0ee7081 --- /dev/null +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/organisation/Currency.java @@ -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); + + } +} diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/organisation/CurrencyHelper.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/organisation/CurrencyHelper.java new file mode 100644 index 000000000..453b04c3b --- /dev/null +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/organisation/CurrencyHelper.java @@ -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 permittedCurrencyArray = Arrays.asList("currencyOptions", + "selectedCurrencyOptions"); + + private static final List 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 getPermittedCurrencies() { + return getCurrencies(CURRENCY_URL, permittedCurrencyArray); + } + + public ArrayList getSelectedCurrencies() { + return getCurrencies(CURRENCY_URL_SELECTED, permittedCurrencyArraySelected); + } + + + private ArrayList getCurrencies(final String getUrl, final List 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 currencyList = new ArrayList(); + final Type typeOfHashMap = new TypeToken>>() { }.getType(); + final Map> responseMap = gson.fromJson(json, typeOfHashMap); + for(Map.Entry> entry : responseMap.entrySet()) { + Assert.isTrue(permittedCurrencyArrays.contains(entry.getKey())); + for(Currency currency : entry.getValue()) { + currencyList.add(currency); + } + } + return currencyList; + } + + public List updateCurrencies(final List 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>>>() { }.getType(); + final Map>> responseMap = gson.fromJson(json, typeOfHashMap); + return responseMap.get("changes").get("currencies"); + } + + private String getUpdateJSON(final List currencies) { + final HashMap> map = new HashMap<>(); + map.put("currencies", currencies); + return new Gson().toJson(map); + } +}