Skip to content

Commit 1e17873

Browse files
MarianaDmytrivBinariksadamsaghy
authored andcommitted
FINERACT-2343: added e2e tests for business date and currency validation
1 parent 56f0b83 commit 1e17873

File tree

5 files changed

+178
-0
lines changed

5 files changed

+178
-0
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,26 @@ public static String dateFailureErrorCodeMsg() {
5959
return "Loan has a wrong http status";
6060
}
6161

62+
public static String setIncorrectBusinessDateFailure() {
63+
return "Wrong local date fields.";
64+
}
65+
66+
public static String setIncorrectBusinessDateMandatoryFailure() {
67+
return "The parameter 'date' is mandatory: '${validatedValue}'.";
68+
}
69+
70+
public static String setCurrencyEmptyValueFailure() {
71+
return "The parameter 'currencies' cannot be empty.";
72+
}
73+
74+
public static String setCurrencyIncorrectValueFailure(String value) {
75+
return String.format("Currency with identifier %s does not exist", value);
76+
}
77+
78+
public static String setCurrencyNullValueMandatoryFailure() {
79+
return "The parameter 'currencies' is mandatory.";
80+
}
81+
6282
public static String disburseDateFailure(Integer loanId) {
6383
String loanIdStr = parseLoanIdToString(loanId);
6484
return String.format("The date on which a loan with identifier : %s is disbursed cannot be in the future.", loanIdStr);

fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/common/BusinessDateStepDef.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,24 @@
1818
*/
1919
package org.apache.fineract.test.stepdef.common;
2020

21+
import static java.util.Arrays.asList;
2122
import static org.assertj.core.api.Assertions.assertThat;
2223

24+
import com.google.gson.Gson;
2325
import io.cucumber.java.en.Then;
2426
import io.cucumber.java.en.When;
2527
import java.io.IOException;
2628
import java.time.LocalDate;
2729
import java.time.format.DateTimeFormatter;
30+
import java.util.List;
2831
import org.apache.fineract.client.models.BusinessDateResponse;
32+
import org.apache.fineract.client.models.BusinessDateUpdateRequest;
2933
import org.apache.fineract.client.services.BusinessDateManagementApi;
34+
import org.apache.fineract.client.util.JSON;
3035
import org.apache.fineract.test.helper.BusinessDateHelper;
3136
import org.apache.fineract.test.helper.ErrorHelper;
37+
import org.apache.fineract.test.helper.ErrorMessageHelper;
38+
import org.apache.fineract.test.helper.ErrorResponse;
3239
import org.apache.fineract.test.stepdef.AbstractStepDef;
3340
import org.springframework.beans.factory.annotation.Autowired;
3441
import retrofit2.Response;
@@ -41,6 +48,8 @@ public class BusinessDateStepDef extends AbstractStepDef {
4148
@Autowired
4249
private BusinessDateManagementApi businessDateManagementApi;
4350

51+
private static final Gson GSON = new JSON().getGson();
52+
4453
@When("Admin sets the business date to {string}")
4554
public void setBusinessDate(String businessDate) throws IOException {
4655
businessDateHelper.setBusinessDate(businessDate);
@@ -61,4 +70,44 @@ public void checkBusinessDate(String businessDate) throws IOException {
6170

6271
assertThat(businessDateResponse.body().getDate()).isEqualTo(localDate);
6372
}
73+
74+
@Then("Set incorrect business date value {string} outcomes with an error")
75+
public void setIncorrectBusinessDateFailure(String businessDate) throws IOException {
76+
BusinessDateUpdateRequest businessDateRequest = businessDateHelper.defaultBusinessDateRequest().date(businessDate);
77+
78+
Response<BusinessDateResponse> businessDateRequestResponse = businessDateManagementApi.updateBusinessDate(null, businessDateRequest)
79+
.execute();
80+
final ErrorResponse errorDetails = ErrorResponse.from(businessDateRequestResponse);
81+
assertThat(errorDetails.getHttpStatusCode()).as(ErrorMessageHelper.setIncorrectBusinessDateFailure()).isEqualTo(400);
82+
assertThat(errorDetails.getSingleError().getDeveloperMessage()).isEqualTo(ErrorMessageHelper.setIncorrectBusinessDateFailure());
83+
}
84+
85+
@Then("Set incorrect business date with empty value {string} outcomes with an error")
86+
public void setNullOrEmptyBusinessDateFailure(String businessDate) throws IOException {
87+
BusinessDateUpdateRequest businessDateRequest = businessDateHelper.defaultBusinessDateRequest();
88+
if (businessDate.equals("null")) {
89+
businessDateRequest.date(null);
90+
} else {
91+
businessDateRequest.date(businessDate);
92+
}
93+
Response<BusinessDateResponse> businessDateRequestResponse = businessDateManagementApi.updateBusinessDate(null, businessDateRequest)
94+
.execute();
95+
Integer httpStatusCodeExpected = 400;
96+
97+
String errorBody = businessDateRequestResponse.errorBody().string();
98+
ErrorResponse errorResponse = GSON.fromJson(errorBody, ErrorResponse.class);
99+
Integer httpStatusCodeActual = errorResponse.getHttpStatusCode();
100+
List<String> developerMessagesActual = errorResponse.getErrors().stream().map(ErrorResponse.Error::getDeveloperMessage).toList();
101+
102+
List<String> developerMessagesExpected = asList(ErrorMessageHelper.setIncorrectBusinessDateMandatoryFailure(),
103+
ErrorMessageHelper.setIncorrectBusinessDateFailure());
104+
105+
assertThat(httpStatusCodeActual)
106+
.as(ErrorMessageHelper.wrongErrorCodeInFailedChargeAdjustment(httpStatusCodeActual, httpStatusCodeExpected))
107+
.isEqualTo(httpStatusCodeExpected);
108+
assertThat(developerMessagesActual)
109+
.as(ErrorMessageHelper.wrongErrorMessage(developerMessagesActual.toString(), developerMessagesExpected.toString()))
110+
.containsAll(developerMessagesExpected);
111+
}
112+
64113
}

fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/common/GlobalConfigurationStepDef.java

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,21 @@
1818
*/
1919
package org.apache.fineract.test.stepdef.common;
2020

21+
import static java.util.Arrays.asList;
22+
import static org.assertj.core.api.Assertions.assertThat;
23+
24+
import com.google.gson.Gson;
2125
import io.cucumber.java.en.Given;
2226
import io.cucumber.java.en.When;
2327
import java.io.IOException;
28+
import java.util.Collections;
29+
import java.util.List;
30+
import org.apache.fineract.client.models.CurrencyUpdateRequest;
31+
import org.apache.fineract.client.services.CurrencyApi;
2432
import org.apache.fineract.client.services.DefaultApi;
33+
import org.apache.fineract.client.util.JSON;
34+
import org.apache.fineract.test.helper.ErrorMessageHelper;
35+
import org.apache.fineract.test.helper.ErrorResponse;
2536
import org.apache.fineract.test.helper.GlobalConfigurationHelper;
2637
import org.springframework.beans.factory.annotation.Autowired;
2738

@@ -32,6 +43,11 @@ public class GlobalConfigurationStepDef {
3243
@Autowired
3344
private DefaultApi defaultApi;
3445

46+
@Autowired
47+
private CurrencyApi currencyApi;
48+
49+
private static final Gson GSON = new JSON().getGson();
50+
3551
@Given("Global configuration {string} is disabled")
3652
public void disableGlobalConfiguration(String configKey) throws IOException {
3753
globalConfigurationHelper.disableGlobalConfiguration(configKey, 0L);
@@ -51,6 +67,56 @@ public void setGlobalConfigValueString(String configKey, String configValue) thr
5167
public void setGlobalConfigValueStringDefaultApi(String configKey, String configValue) throws IOException {
5268
Long configValueLong = Long.valueOf(configValue);
5369
defaultApi.updateGlobalConfiguration(configKey, configValueLong);
70+
}
71+
72+
@When("Update currency with incorrect empty value outcomes with an error")
73+
public void updateCurrencyEmptyValueFailure() throws IOException {
74+
var request = new CurrencyUpdateRequest();
75+
var currencyResponse = currencyApi.updateCurrencies(request.currencies(Collections.emptyList())).execute();
76+
final ErrorResponse errorDetails = ErrorResponse.from(currencyResponse);
77+
assertThat(errorDetails.getHttpStatusCode()).as(ErrorMessageHelper.setCurrencyEmptyValueFailure()).isEqualTo(400);
78+
assertThat(errorDetails.getSingleError().getDeveloperMessage()).isEqualTo(ErrorMessageHelper.setCurrencyEmptyValueFailure());
79+
}
80+
81+
@When("Update currency with incorrect null value outcomes with an error")
82+
public void updateCurrencyIncorrectNullValueFailure() throws IOException {
83+
var request = new CurrencyUpdateRequest();
84+
var currencyResponse = currencyApi.updateCurrencies(request.currencies(Collections.singletonList(null))).execute();
85+
final ErrorResponse errorDetails = ErrorResponse.from(currencyResponse);
86+
assertThat(errorDetails.getHttpStatusCode()).as(ErrorMessageHelper.setCurrencyIncorrectValueFailure("null")).isEqualTo(404);
87+
assertThat(errorDetails.getSingleError().getDeveloperMessage())
88+
.isEqualTo(ErrorMessageHelper.setCurrencyIncorrectValueFailure("null"));
89+
}
90+
91+
@When("Update currency as NULL value outcomes with an error")
92+
public void updateCurrencyNullValueFailure() throws IOException {
93+
var request = new CurrencyUpdateRequest();
94+
var currencyResponse = currencyApi.updateCurrencies(request.currencies(null)).execute();
95+
Integer httpStatusCodeExpected = 400;
96+
97+
String errorBody = currencyResponse.errorBody().string();
98+
ErrorResponse errorResponse = GSON.fromJson(errorBody, ErrorResponse.class);
99+
Integer httpStatusCodeActual = errorResponse.getHttpStatusCode();
100+
List<String> developerMessagesActual = errorResponse.getErrors().stream().map(ErrorResponse.Error::getDeveloperMessage).toList();
101+
102+
List<String> developerMessagesExpected = asList(ErrorMessageHelper.setCurrencyEmptyValueFailure(),
103+
ErrorMessageHelper.setCurrencyNullValueMandatoryFailure());
104+
105+
assertThat(httpStatusCodeActual)
106+
.as(ErrorMessageHelper.wrongErrorCodeInFailedChargeAdjustment(httpStatusCodeActual, httpStatusCodeExpected))
107+
.isEqualTo(httpStatusCodeExpected);
108+
assertThat(developerMessagesActual)
109+
.as(ErrorMessageHelper.wrongErrorMessage(developerMessagesActual.toString(), developerMessagesExpected.toString()))
110+
.containsAll(developerMessagesExpected);
111+
}
54112

113+
@When("Update currency as {string} value outcomes with an error")
114+
public void updateCurrencyIncorrectValueFailure(String currency) throws IOException {
115+
var request = new CurrencyUpdateRequest();
116+
var currencyResponse = currencyApi.updateCurrencies(request.currencies(Collections.singletonList(currency))).execute();
117+
final ErrorResponse errorDetails = ErrorResponse.from(currencyResponse);
118+
assertThat(errorDetails.getHttpStatusCode()).as(ErrorMessageHelper.setCurrencyIncorrectValueFailure(currency)).isEqualTo(404);
119+
assertThat(errorDetails.getSingleError().getDeveloperMessage())
120+
.isEqualTo(ErrorMessageHelper.setCurrencyIncorrectValueFailure(currency));
55121
}
56122
}

fineract-e2e-tests-runner/src/test/resources/features/BusinessDate.feature

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,28 @@ Feature: BusinessDate
2626
When Admin sets the business date to "10 July 2022"
2727
When Admin runs the Increase Business Date by 1 day job
2828
Then Admin checks that the business date is correctly set to "11 July 2022"
29+
30+
@TestRailId:C3953
31+
Scenario: Verify set incorrect business date with empty value handled correct with accordance error message - UC1
32+
When Set incorrect business date with empty value "null" outcomes with an error
33+
34+
@TestRailId:C3954
35+
Scenario: Verify set incorrect business date with null value handled correct with accordance error message - UC2
36+
When Set incorrect business date with empty value "" outcomes with an error
37+
38+
@TestRailId:C3955
39+
Scenario: Verify set incorrect business date value handled correct with accordance error message - UC3
40+
When Set incorrect business date value "15" outcomes with an error
41+
42+
@TestRailId:C3956
43+
Scenario: Verify set incorrect business date value handled correct with accordance error message - UC4
44+
When Set incorrect business date value "11 15 2025" outcomes with an error
45+
46+
@TestRailId:C_3957
47+
Scenario: Verify set incorrect business date value handled correct with accordance error message - UC5
48+
When Set incorrect business date value "August 12 2025" outcomes with an error
49+
50+
@TestRailId:C3958
51+
Scenario: Verify set incorrect business date value handled correct with accordance error message - UC6
52+
When Set incorrect business date value "33 August 2025" outcomes with an error
53+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
@ConfigurationFeature
2+
Feature: Configuration
3+
4+
@TestRailId:C3959
5+
Scenario: Verify update currency with empty value handled correct with accordance error message - UC1
6+
When Update currency with incorrect empty value outcomes with an error
7+
8+
@TestRailId:C3960
9+
Scenario: Verify update currency with null value handled correct with accordance error message - UC2
10+
When Update currency with incorrect null value outcomes with an error
11+
12+
@TestRailId:C3961
13+
Scenario: Verify update currency as NULL value handled correct with accordance error message - UC3
14+
When Update currency as NULL value outcomes with an error
15+
16+
@TestRailId:C3962
17+
Scenario: Verify update currency with incorrect value handled correct with accordance error message - UC4
18+
When Update currency as "string" value outcomes with an error

0 commit comments

Comments
 (0)