diff --git a/integration-tests/README.md b/integration-tests/README.md new file mode 100644 index 00000000000..effb78fa6e4 --- /dev/null +++ b/integration-tests/README.md @@ -0,0 +1,17 @@ +# Run integration tests + +## Prerequisites +- A running Fineract instance is required + +## Default configuration +- `BACKEND_PROTOCOL=https` +- `BACKEND_HOST=localhost` +- `BACKEND_PORT=8443` +- `BACKEND_USERNAME=mifos` +- `BACKEND_PASSWORD=password` +- `BACKEND_TENANT=default` + +## To override default values +- To override any of the default value, just add new value with the same key as environment variable +- Example: + - `BACKEND_PROTOCOL=http` diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/ConfigProperties.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/ConfigProperties.java new file mode 100644 index 00000000000..00c12b9e892 --- /dev/null +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/ConfigProperties.java @@ -0,0 +1,36 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.integrationtests; + +public class ConfigProperties { + + public static class Backend { + + public static final String PROTOCOL = getValueFromEnvOrDefault("BACKEND_PROTOCOL", "https"); + public static final String HOST = getValueFromEnvOrDefault("BACKEND_HOST", "localhost"); + public static final Integer PORT = Integer.parseInt(getValueFromEnvOrDefault("BACKEND_PORT", "8443")); + public static final String USERNAME = getValueFromEnvOrDefault("BACKEND_USERNAME", "mifos"); + public static final String PASSWORD = getValueFromEnvOrDefault("BACKEND_PASSWORD", "password"); + public static final String TENANT = getValueFromEnvOrDefault("BACKEND_TENANT", "default"); + } + + private static String getValueFromEnvOrDefault(final String key, final String defaultValue) { + return System.getenv(key) == null ? defaultValue : System.getenv(key); + } +} diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/client/IntegrationTest.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/client/IntegrationTest.java index 2b127acbca2..d987a571825 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/client/IntegrationTest.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/client/IntegrationTest.java @@ -38,6 +38,7 @@ import okhttp3.logging.HttpLoggingInterceptor.Level; import org.apache.fineract.client.util.Calls; import org.apache.fineract.client.util.FineractClient; +import org.apache.fineract.integrationtests.ConfigProperties; import org.junit.jupiter.api.MethodOrderer; import org.junit.jupiter.api.TestInstance; import org.junit.jupiter.api.TestInstance.Lifecycle; @@ -62,15 +63,20 @@ public abstract class IntegrationTest { protected FineractClient fineract() { if (fineract == null) { - fineract = newFineract("mifos", "password"); + fineract = newFineract(ConfigProperties.Backend.USERNAME, ConfigProperties.Backend.PASSWORD); } return fineract; } + private String buildURI() { + return ConfigProperties.Backend.PROTOCOL + "://" + ConfigProperties.Backend.HOST + ":" + ConfigProperties.Backend.PORT + + "/fineract-provider/api/"; + } + protected FineractClient newFineract(String username, String password) { - String url = System.getProperty("fineract.it.url", "https://localhost:8443/fineract-provider/api/"); + String url = System.getProperty("fineract.it.url", buildURI()); // insecure(true) should *ONLY* ever be used for https://localhost:8443, NOT in real clients!! - FineractClient.Builder builder = FineractClient.builder().insecure(true).baseURL(url).tenant("default") + FineractClient.Builder builder = FineractClient.builder().insecure(true).baseURL(url).tenant(ConfigProperties.Backend.TENANT) .basicAuth(username, password).logging(Level.NONE); customizeFineractClient(builder); return builder.build(); diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/Utils.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/Utils.java index 0c1f986c8a0..45b8e46662a 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/Utils.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/Utils.java @@ -66,6 +66,7 @@ import java.util.function.Supplier; import org.apache.commons.lang3.StringUtils; import org.apache.fineract.infrastructure.core.service.DateUtils; +import org.apache.fineract.integrationtests.ConfigProperties; import org.apache.http.conn.HttpHostConnectException; import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; @@ -79,7 +80,7 @@ public final class Utils { public static final String TENANT_PARAM_NAME = "tenantIdentifier"; - public static final String DEFAULT_TENANT = "default"; + public static final String DEFAULT_TENANT = ConfigProperties.Backend.TENANT; public static final String TENANT_IDENTIFIER = TENANT_PARAM_NAME + '=' + DEFAULT_TENANT; private static final String LOGIN_URL = "/fineract-provider/api/v1/authentication?" + TENANT_IDENTIFIER; public static final String TENANT_TIME_ZONE = "Asia/Kolkata"; @@ -101,8 +102,8 @@ public final class Utils { private Utils() {} public static void initializeRESTAssured() { - RestAssured.baseURI = "https://localhost"; - RestAssured.port = 8443; + RestAssured.baseURI = ConfigProperties.Backend.PROTOCOL + "://" + ConfigProperties.Backend.HOST; + RestAssured.port = ConfigProperties.Backend.PORT; RestAssured.keyStore("src/main/resources/keystore.jks", "openmf"); RestAssured.useRelaxedHTTPSValidation(); } @@ -176,7 +177,7 @@ private static void sleep(int seconds) { } public static String loginIntoServerAndGetBase64EncodedAuthenticationKey() { - return loginIntoServerAndGetBase64EncodedAuthenticationKey("mifos", "password"); + return loginIntoServerAndGetBase64EncodedAuthenticationKey(ConfigProperties.Backend.USERNAME, ConfigProperties.Backend.PASSWORD); } public static String loginIntoServerAndGetBase64EncodedAuthenticationKey(String username, String password) { diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/variableinstallments/VariableIntallmentsTransactionHelper.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/variableinstallments/VariableIntallmentsTransactionHelper.java index fe8eda984ce..377be6b6b67 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/variableinstallments/VariableIntallmentsTransactionHelper.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/variableinstallments/VariableIntallmentsTransactionHelper.java @@ -22,12 +22,14 @@ import io.restassured.specification.ResponseSpecification; import java.util.HashMap; import java.util.Map; +import org.apache.fineract.integrationtests.ConfigProperties; import org.apache.fineract.integrationtests.common.Utils; @SuppressWarnings("rawtypes") public class VariableIntallmentsTransactionHelper { - private static final String URL = "https://localhost:8443/fineract-provider/api/v1/loans/"; + private static final String URL = ConfigProperties.Backend.PROTOCOL + "://" + ConfigProperties.Backend.HOST + ":" + + ConfigProperties.Backend.PORT + "/fineract-provider/api/v1/loans/"; private final RequestSpecification requestSpec; private final ResponseSpecification responseSpec;