Skip to content

Commit 4876c9e

Browse files
edk12564adamsaghy
authored andcommitted
FINERACT-2165: Refactored Currency Tests to use Cucumber
- Eliminated old CurrenciesTest, CurrenciesHelper, and CurrencyDomain due to implementing RestAssured client and JUnit - Created test steps and Gherkin that covers same items as old tests but in E2E-core and E2E-runner. - Updated ErrorMessageHelper to handle Currency errors. - Fixed bug in CenterDomain.java that was causing compilation issues. CurrenciesDomain was improperly being imported and not used anywhere.
1 parent 8c26034 commit 4876c9e

File tree

8 files changed

+171
-352
lines changed

8 files changed

+171
-352
lines changed

fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/helper/ErrorMessageHelper.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,19 @@ public static String setCurrencyNullValueMandatoryFailure() {
7777
return "The parameter 'currencies' is mandatory.";
7878
}
7979

80+
public static String currencyNotFound(String currencyCode) {
81+
return String.format("Currency with code '%s' not found in currency options", currencyCode);
82+
}
83+
84+
public static String wrongCurrencyField(String currencyCode, String fieldName, Object actual, Object expected) {
85+
return String.format("Wrong %s for currency '%s'. Actual value is: %s - But expected value is: %s", fieldName, currencyCode, actual,
86+
expected);
87+
}
88+
89+
public static String wrongSelectedCurrencies(List<String> actual, List<String> expected) {
90+
return String.format("Wrong selected currencies. Actual value is: %s - But expected value is: %s", actual, expected);
91+
}
92+
8093
public static String disburseDateFailure(Integer loanId) {
8194
String loanIdStr = parseLoanIdToString(loanId);
8295
return String.format("The date on which a loan with identifier : %s is disbursed cannot be in the future.", loanIdStr);
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.fineract.test.stepdef.common;
20+
21+
import static org.apache.fineract.client.feign.util.FeignCalls.ok;
22+
import static org.assertj.core.api.Assertions.assertThat;
23+
24+
import io.cucumber.datatable.DataTable;
25+
import io.cucumber.java.en.And;
26+
import io.cucumber.java.en.Then;
27+
import io.cucumber.java.en.When;
28+
import java.util.ArrayList;
29+
import java.util.Arrays;
30+
import java.util.List;
31+
import java.util.Map;
32+
import lombok.RequiredArgsConstructor;
33+
import org.apache.fineract.client.feign.FineractFeignClient;
34+
import org.apache.fineract.client.models.CurrencyConfigurationData;
35+
import org.apache.fineract.client.models.CurrencyData;
36+
import org.apache.fineract.client.models.CurrencyUpdateRequest;
37+
import org.apache.fineract.client.models.CurrencyUpdateResponse;
38+
import org.apache.fineract.test.helper.ErrorMessageHelper;
39+
import org.apache.fineract.test.stepdef.AbstractStepDef;
40+
import org.apache.fineract.test.support.TestContextKey;
41+
42+
@RequiredArgsConstructor
43+
public class CurrencyStepDef extends AbstractStepDef {
44+
45+
private static final List<String> DEFAULT_CURRENCIES = Arrays.asList("EUR", "USD");
46+
private final FineractFeignClient fineractClient;
47+
48+
@When("Admin retrieves currency configuration")
49+
public void adminRetrievesCurrencyConfiguration() {
50+
51+
CurrencyConfigurationData response = ok(() -> fineractClient.currency().retrieveCurrencies());
52+
testContext().set(TestContextKey.GET_CURRENCIES_RESPONSE, response);
53+
54+
}
55+
56+
@Then("Currency {string} has the following properties:")
57+
public void currencyHasFollowingProperties(String currencyCode, DataTable table) {
58+
59+
CurrencyConfigurationData config = testContext().get(TestContextKey.GET_CURRENCIES_RESPONSE);
60+
61+
List<CurrencyData> allCurrencies = new ArrayList<>();
62+
if (config.getSelectedCurrencyOptions() != null) {
63+
allCurrencies.addAll(config.getSelectedCurrencyOptions());
64+
}
65+
if (config.getCurrencyOptions() != null) {
66+
allCurrencies.addAll(config.getCurrencyOptions());
67+
}
68+
69+
Map<String, String> expected = table.asMaps().get(0);
70+
String expectedName = expected.get("name");
71+
String expectedSymbol = expected.get("symbol");
72+
int expectedDecimalPlaces = Integer.parseInt(expected.get("decimalPlaces"));
73+
74+
CurrencyData currency = allCurrencies.stream().filter(c -> currencyCode.equals(c.getCode())).findFirst().orElse(null);
75+
76+
assertThat(currency).as(ErrorMessageHelper.currencyNotFound(currencyCode)).isNotNull();
77+
assertThat(currency.getName()).as(ErrorMessageHelper.wrongCurrencyField(currencyCode, "name", currency.getName(), expectedName))
78+
.isEqualTo(expectedName);
79+
assertThat(currency.getDisplaySymbol())
80+
.as(ErrorMessageHelper.wrongCurrencyField(currencyCode, "displaySymbol", currency.getDisplaySymbol(), expectedSymbol))
81+
.isEqualTo(expectedSymbol);
82+
assertThat(currency.getDecimalPlaces()).as(
83+
ErrorMessageHelper.wrongCurrencyField(currencyCode, "decimalPlaces", currency.getDecimalPlaces(), expectedDecimalPlaces))
84+
.isEqualTo(expectedDecimalPlaces);
85+
assertThat(currency.getNameCode())
86+
.as(ErrorMessageHelper.wrongCurrencyField(currencyCode, "nameCode", currency.getNameCode(), "currency." + currencyCode))
87+
.isEqualTo("currency." + currencyCode);
88+
assertThat(currency.getDisplayLabel()).as(ErrorMessageHelper.wrongCurrencyField(currencyCode, "displayLabel",
89+
currency.getDisplayLabel(), expectedName + " (" + expectedSymbol + ")"))
90+
.isEqualTo(expectedName + " (" + expectedSymbol + ")");
91+
92+
}
93+
94+
@When("Admin updates selected currencies to {string}")
95+
public void adminUpdatesSelectedCurrencies(String currencyCodes) {
96+
97+
List<String> currencies = Arrays.asList(currencyCodes.split(","));
98+
CurrencyUpdateRequest request = new CurrencyUpdateRequest().currencies(currencies);
99+
CurrencyUpdateResponse response = ok(() -> fineractClient.currency().updateCurrencies(request, Map.of()));
100+
testContext().set(TestContextKey.PUT_CURRENCIES_RESPONSE, response);
101+
102+
}
103+
104+
@Then("The returned currency list matches {string}")
105+
public void returnedCurrencyListMatches(String expectedCodes) {
106+
107+
List<String> expected = Arrays.asList(expectedCodes.split(","));
108+
CurrencyUpdateResponse response = testContext().get(TestContextKey.PUT_CURRENCIES_RESPONSE);
109+
110+
assertThat(response).as(ErrorMessageHelper.idNull()).isNotNull();
111+
assertThat(response.getCurrencies()).as(ErrorMessageHelper.wrongSelectedCurrencies(response.getCurrencies(), expected))
112+
.isEqualTo(expected);
113+
114+
}
115+
116+
@Then("The selected currencies contain {string}")
117+
public void selectedCurrenciesContain(String expectedCodes) {
118+
119+
List<String> expected = Arrays.asList(expectedCodes.split(","));
120+
CurrencyConfigurationData config = testContext().get(TestContextKey.GET_CURRENCIES_RESPONSE);
121+
122+
assertThat(config.getSelectedCurrencyOptions()).as(ErrorMessageHelper.idNull()).isNotNull();
123+
124+
List<String> selectedCodes = config.getSelectedCurrencyOptions().stream().map(CurrencyData::getCode).sorted().toList();
125+
List<String> expectedSorted = expected.stream().sorted().toList();
126+
127+
assertThat(selectedCodes).as(ErrorMessageHelper.wrongSelectedCurrencies(selectedCodes, expectedSorted)).isEqualTo(expectedSorted);
128+
129+
}
130+
131+
@And("Admin resets selected currencies to default")
132+
public void adminResetsSelectedCurrenciesToDefault() {
133+
134+
CurrencyUpdateRequest request = new CurrencyUpdateRequest().currencies(DEFAULT_CURRENCIES);
135+
ok(() -> fineractClient.currency().updateCurrencies(request, Map.of()));
136+
137+
}
138+
}

fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/support/TestContextKey.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ public abstract class TestContextKey {
221221
public static final String LOAN_CHARGEBACK_RESPONSE = "loanChargebackResponse";
222222
public static final String LOAN_CHARGE_ADJUSTMENT_RESPONSE = "loanChargeAdjustmentResponse";
223223
public static final String PUT_CURRENCIES_RESPONSE = "putCurrenciesResponse";
224+
public static final String GET_CURRENCIES_RESPONSE = "getCurrenciesResponse";
224225
public static final String BATCH_API_CALL_RESPONSE = "batchApiCallResponse";
225226
public static final String BATCH_API_CALL_IDEMPOTENCY_KEY = "batchApiIdempotencyKey";
226227
public static final String BATCH_API_CALL_IDEMPOTENCY_KEY_2 = "batchApiIdempotencyKey2";
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
@CurrencyFeature
2+
Feature: Currency
3+
4+
@TestRailId:C3963
5+
Scenario: Verify USD currency properties are correct
6+
When Admin retrieves currency configuration
7+
Then Currency "USD" has the following properties:
8+
| name | symbol | decimalPlaces |
9+
| US Dollar | $ | 2 |
10+
11+
@TestRailId:C3964
12+
Scenario: Verify updating selected currencies works correctly
13+
When Admin updates selected currencies to "EUR,KES,BND,LBP,GHC,USD,INR"
14+
Then The returned currency list matches "EUR,KES,BND,LBP,GHC,USD,INR"
15+
When Admin retrieves currency configuration
16+
Then The selected currencies contain "EUR,KES,BND,LBP,GHC,USD,INR"
17+
And Admin resets selected currencies to default

integration-tests/src/test/java/org/apache/fineract/integrationtests/CurrenciesTest.java

Lines changed: 0 additions & 86 deletions
This file was deleted.

integration-tests/src/test/java/org/apache/fineract/integrationtests/common/CenterDomain.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ public String toJSON() {
110110
return new Gson().toJson(this);
111111
}
112112

113-
public static CurrencyDomain fromJSON(final String jsonData) {
114-
return new Gson().fromJson(jsonData, CurrencyDomain.class);
113+
public static CenterDomain fromJSON(final String jsonData) {
114+
return new Gson().fromJson(jsonData, CenterDomain.class);
115115
}
116116

117117
public static Builder create(final Integer id, final Integer statusid, final String statuscode, final String statusvalue,

integration-tests/src/test/java/org/apache/fineract/integrationtests/common/CurrenciesHelper.java

Lines changed: 0 additions & 106 deletions
This file was deleted.

0 commit comments

Comments
 (0)