FINERACT-2343: added e2e tests for business date and currency validation

This commit is contained in:
MarianaDmytrivBinariks
2025-08-14 15:35:26 +02:00
committed by Adam Saghy
parent 56f0b83d40
commit 1e1787399a
5 changed files with 178 additions and 0 deletions
@@ -59,6 +59,26 @@ public final class ErrorMessageHelper {
return "Loan has a wrong http status";
}
public static String setIncorrectBusinessDateFailure() {
return "Wrong local date fields.";
}
public static String setIncorrectBusinessDateMandatoryFailure() {
return "The parameter 'date' is mandatory: '${validatedValue}'.";
}
public static String setCurrencyEmptyValueFailure() {
return "The parameter 'currencies' cannot be empty.";
}
public static String setCurrencyIncorrectValueFailure(String value) {
return String.format("Currency with identifier %s does not exist", value);
}
public static String setCurrencyNullValueMandatoryFailure() {
return "The parameter 'currencies' is mandatory.";
}
public static String disburseDateFailure(Integer loanId) {
String loanIdStr = parseLoanIdToString(loanId);
return String.format("The date on which a loan with identifier : %s is disbursed cannot be in the future.", loanIdStr);
@@ -18,17 +18,24 @@
*/
package org.apache.fineract.test.stepdef.common;
import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;
import com.google.gson.Gson;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import java.io.IOException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;
import org.apache.fineract.client.models.BusinessDateResponse;
import org.apache.fineract.client.models.BusinessDateUpdateRequest;
import org.apache.fineract.client.services.BusinessDateManagementApi;
import org.apache.fineract.client.util.JSON;
import org.apache.fineract.test.helper.BusinessDateHelper;
import org.apache.fineract.test.helper.ErrorHelper;
import org.apache.fineract.test.helper.ErrorMessageHelper;
import org.apache.fineract.test.helper.ErrorResponse;
import org.apache.fineract.test.stepdef.AbstractStepDef;
import org.springframework.beans.factory.annotation.Autowired;
import retrofit2.Response;
@@ -41,6 +48,8 @@ public class BusinessDateStepDef extends AbstractStepDef {
@Autowired
private BusinessDateManagementApi businessDateManagementApi;
private static final Gson GSON = new JSON().getGson();
@When("Admin sets the business date to {string}")
public void setBusinessDate(String businessDate) throws IOException {
businessDateHelper.setBusinessDate(businessDate);
@@ -61,4 +70,44 @@ public class BusinessDateStepDef extends AbstractStepDef {
assertThat(businessDateResponse.body().getDate()).isEqualTo(localDate);
}
@Then("Set incorrect business date value {string} outcomes with an error")
public void setIncorrectBusinessDateFailure(String businessDate) throws IOException {
BusinessDateUpdateRequest businessDateRequest = businessDateHelper.defaultBusinessDateRequest().date(businessDate);
Response<BusinessDateResponse> businessDateRequestResponse = businessDateManagementApi.updateBusinessDate(null, businessDateRequest)
.execute();
final ErrorResponse errorDetails = ErrorResponse.from(businessDateRequestResponse);
assertThat(errorDetails.getHttpStatusCode()).as(ErrorMessageHelper.setIncorrectBusinessDateFailure()).isEqualTo(400);
assertThat(errorDetails.getSingleError().getDeveloperMessage()).isEqualTo(ErrorMessageHelper.setIncorrectBusinessDateFailure());
}
@Then("Set incorrect business date with empty value {string} outcomes with an error")
public void setNullOrEmptyBusinessDateFailure(String businessDate) throws IOException {
BusinessDateUpdateRequest businessDateRequest = businessDateHelper.defaultBusinessDateRequest();
if (businessDate.equals("null")) {
businessDateRequest.date(null);
} else {
businessDateRequest.date(businessDate);
}
Response<BusinessDateResponse> businessDateRequestResponse = businessDateManagementApi.updateBusinessDate(null, businessDateRequest)
.execute();
Integer httpStatusCodeExpected = 400;
String errorBody = businessDateRequestResponse.errorBody().string();
ErrorResponse errorResponse = GSON.fromJson(errorBody, ErrorResponse.class);
Integer httpStatusCodeActual = errorResponse.getHttpStatusCode();
List<String> developerMessagesActual = errorResponse.getErrors().stream().map(ErrorResponse.Error::getDeveloperMessage).toList();
List<String> developerMessagesExpected = asList(ErrorMessageHelper.setIncorrectBusinessDateMandatoryFailure(),
ErrorMessageHelper.setIncorrectBusinessDateFailure());
assertThat(httpStatusCodeActual)
.as(ErrorMessageHelper.wrongErrorCodeInFailedChargeAdjustment(httpStatusCodeActual, httpStatusCodeExpected))
.isEqualTo(httpStatusCodeExpected);
assertThat(developerMessagesActual)
.as(ErrorMessageHelper.wrongErrorMessage(developerMessagesActual.toString(), developerMessagesExpected.toString()))
.containsAll(developerMessagesExpected);
}
}
@@ -18,10 +18,21 @@
*/
package org.apache.fineract.test.stepdef.common;
import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;
import com.google.gson.Gson;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.When;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import org.apache.fineract.client.models.CurrencyUpdateRequest;
import org.apache.fineract.client.services.CurrencyApi;
import org.apache.fineract.client.services.DefaultApi;
import org.apache.fineract.client.util.JSON;
import org.apache.fineract.test.helper.ErrorMessageHelper;
import org.apache.fineract.test.helper.ErrorResponse;
import org.apache.fineract.test.helper.GlobalConfigurationHelper;
import org.springframework.beans.factory.annotation.Autowired;
@@ -32,6 +43,11 @@ public class GlobalConfigurationStepDef {
@Autowired
private DefaultApi defaultApi;
@Autowired
private CurrencyApi currencyApi;
private static final Gson GSON = new JSON().getGson();
@Given("Global configuration {string} is disabled")
public void disableGlobalConfiguration(String configKey) throws IOException {
globalConfigurationHelper.disableGlobalConfiguration(configKey, 0L);
@@ -51,6 +67,56 @@ public class GlobalConfigurationStepDef {
public void setGlobalConfigValueStringDefaultApi(String configKey, String configValue) throws IOException {
Long configValueLong = Long.valueOf(configValue);
defaultApi.updateGlobalConfiguration(configKey, configValueLong);
}
@When("Update currency with incorrect empty value outcomes with an error")
public void updateCurrencyEmptyValueFailure() throws IOException {
var request = new CurrencyUpdateRequest();
var currencyResponse = currencyApi.updateCurrencies(request.currencies(Collections.emptyList())).execute();
final ErrorResponse errorDetails = ErrorResponse.from(currencyResponse);
assertThat(errorDetails.getHttpStatusCode()).as(ErrorMessageHelper.setCurrencyEmptyValueFailure()).isEqualTo(400);
assertThat(errorDetails.getSingleError().getDeveloperMessage()).isEqualTo(ErrorMessageHelper.setCurrencyEmptyValueFailure());
}
@When("Update currency with incorrect null value outcomes with an error")
public void updateCurrencyIncorrectNullValueFailure() throws IOException {
var request = new CurrencyUpdateRequest();
var currencyResponse = currencyApi.updateCurrencies(request.currencies(Collections.singletonList(null))).execute();
final ErrorResponse errorDetails = ErrorResponse.from(currencyResponse);
assertThat(errorDetails.getHttpStatusCode()).as(ErrorMessageHelper.setCurrencyIncorrectValueFailure("null")).isEqualTo(404);
assertThat(errorDetails.getSingleError().getDeveloperMessage())
.isEqualTo(ErrorMessageHelper.setCurrencyIncorrectValueFailure("null"));
}
@When("Update currency as NULL value outcomes with an error")
public void updateCurrencyNullValueFailure() throws IOException {
var request = new CurrencyUpdateRequest();
var currencyResponse = currencyApi.updateCurrencies(request.currencies(null)).execute();
Integer httpStatusCodeExpected = 400;
String errorBody = currencyResponse.errorBody().string();
ErrorResponse errorResponse = GSON.fromJson(errorBody, ErrorResponse.class);
Integer httpStatusCodeActual = errorResponse.getHttpStatusCode();
List<String> developerMessagesActual = errorResponse.getErrors().stream().map(ErrorResponse.Error::getDeveloperMessage).toList();
List<String> developerMessagesExpected = asList(ErrorMessageHelper.setCurrencyEmptyValueFailure(),
ErrorMessageHelper.setCurrencyNullValueMandatoryFailure());
assertThat(httpStatusCodeActual)
.as(ErrorMessageHelper.wrongErrorCodeInFailedChargeAdjustment(httpStatusCodeActual, httpStatusCodeExpected))
.isEqualTo(httpStatusCodeExpected);
assertThat(developerMessagesActual)
.as(ErrorMessageHelper.wrongErrorMessage(developerMessagesActual.toString(), developerMessagesExpected.toString()))
.containsAll(developerMessagesExpected);
}
@When("Update currency as {string} value outcomes with an error")
public void updateCurrencyIncorrectValueFailure(String currency) throws IOException {
var request = new CurrencyUpdateRequest();
var currencyResponse = currencyApi.updateCurrencies(request.currencies(Collections.singletonList(currency))).execute();
final ErrorResponse errorDetails = ErrorResponse.from(currencyResponse);
assertThat(errorDetails.getHttpStatusCode()).as(ErrorMessageHelper.setCurrencyIncorrectValueFailure(currency)).isEqualTo(404);
assertThat(errorDetails.getSingleError().getDeveloperMessage())
.isEqualTo(ErrorMessageHelper.setCurrencyIncorrectValueFailure(currency));
}
}
@@ -26,3 +26,28 @@ Feature: BusinessDate
When Admin sets the business date to "10 July 2022"
When Admin runs the Increase Business Date by 1 day job
Then Admin checks that the business date is correctly set to "11 July 2022"
@TestRailId:C3953
Scenario: Verify set incorrect business date with empty value handled correct with accordance error message - UC1
When Set incorrect business date with empty value "null" outcomes with an error
@TestRailId:C3954
Scenario: Verify set incorrect business date with null value handled correct with accordance error message - UC2
When Set incorrect business date with empty value "" outcomes with an error
@TestRailId:C3955
Scenario: Verify set incorrect business date value handled correct with accordance error message - UC3
When Set incorrect business date value "15" outcomes with an error
@TestRailId:C3956
Scenario: Verify set incorrect business date value handled correct with accordance error message - UC4
When Set incorrect business date value "11 15 2025" outcomes with an error
@TestRailId:C_3957
Scenario: Verify set incorrect business date value handled correct with accordance error message - UC5
When Set incorrect business date value "August 12 2025" outcomes with an error
@TestRailId:C3958
Scenario: Verify set incorrect business date value handled correct with accordance error message - UC6
When Set incorrect business date value "33 August 2025" outcomes with an error
@@ -0,0 +1,18 @@
@ConfigurationFeature
Feature: Configuration
@TestRailId:C3959
Scenario: Verify update currency with empty value handled correct with accordance error message - UC1
When Update currency with incorrect empty value outcomes with an error
@TestRailId:C3960
Scenario: Verify update currency with null value handled correct with accordance error message - UC2
When Update currency with incorrect null value outcomes with an error
@TestRailId:C3961
Scenario: Verify update currency as NULL value handled correct with accordance error message - UC3
When Update currency as NULL value outcomes with an error
@TestRailId:C3962
Scenario: Verify update currency with incorrect value handled correct with accordance error message - UC4
When Update currency as "string" value outcomes with an error