Skip to content

Commit

Permalink
FINERACT-2081: Integration test configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
adamsaghy authored and galovics committed Jun 11, 2024
1 parent a6b69ec commit d502dfa
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 8 deletions.
17 changes: 17 additions & 0 deletions integration-tests/README.md
Original file line number Diff line number Diff line change
@@ -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`
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";
Expand All @@ -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();
}
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit d502dfa

Please sign in to comment.