This is an automated email from the ASF dual-hosted git repository.

arnold pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract.git


The following commit(s) were added to refs/heads/develop by this push:
     new d502dfa43 FINERACT-2081: Integration test configuration
d502dfa43 is described below

commit d502dfa43718a9504a396657ddf6ff5c41c8c68a
Author: Adam Saghy <[email protected]>
AuthorDate: Fri Jun 7 01:01:50 2024 +0200

    FINERACT-2081: Integration test configuration
---
 integration-tests/README.md                        | 17 ++++++++++
 .../integrationtests/ConfigProperties.java         | 36 ++++++++++++++++++++++
 .../integrationtests/client/IntegrationTest.java   | 12 ++++++--
 .../fineract/integrationtests/common/Utils.java    |  9 +++---
 .../VariableIntallmentsTransactionHelper.java      |  4 ++-
 5 files changed, 70 insertions(+), 8 deletions(-)

diff --git a/integration-tests/README.md b/integration-tests/README.md
new file mode 100644
index 000000000..effb78fa6
--- /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 000000000..00c12b9e8
--- /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 2b127acbc..d987a5718 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 java.util.Optional;
 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 0c1f986c8..45b8e4666 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.Function;
 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 @@ import org.slf4j.LoggerFactory;
 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 @@ public final class Utils {
     }
 
     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 fe8eda984..377be6b6b 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.RequestSpecification;
 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;

Reply via email to