Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
*.class

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.ear
*.md
*.png

# exclude jar for gradle wrapper
!gradle/wrapper/*.jar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

# build files
**/target
target
.gradle
build

Expand All @@ -26,7 +24,10 @@ build
/.openapi-generator/
/.openapi-generator-ignore
/.travis.yml
/git_push.sh
/.idea
/git_push.sh
/api
/docs
/gradle
gradle.properties
.DS_Store
25 changes: 25 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Test Workflow

on:
pull_request:

jobs:
build-and-test:
runs-on: ubuntu-latest
environment: dev

steps:
- uses: actions/checkout@v2

- name: Build Docker image
run: docker build -t java .

- name: Run tests using Docker
run: |
docker run \
-e VOUCHERIFY_HOST=${{ vars.VOUCHERIFY_HOST }} \
-e X_APP_ID=${{ secrets.X_APP_ID }} \
-e X_APP_TOKEN=${{ secrets.X_APP_TOKEN }} \
-e X_MANAGEMENT_ID=${{ secrets.X_MANAGEMENT_ID }} \
-e X_MANAGEMENT_TOKEN=${{ secrets.X_MANAGEMENT_TOKEN }} \
java
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ build


# Other
/.github/
/.github/workflows/maven.yml
/.openapi-generator/
/.openapi-generator-ignore
/.travis.yml
/git_push.sh
/.env
/.idea
*.idea
gradle.properties

4 changes: 1 addition & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ RUN apt-get update && \

WORKDIR /app

COPY .env .
COPY pom.xml .
COPY ./src ./src
COPY . .

RUN mvn test

45 changes: 4 additions & 41 deletions src/test/java/io/voucherify/ManagementTest.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package io.voucherify;

import io.voucherify.data.VoucherifyStore;
import io.voucherify.helpers.JsonHelper;

import org.junit.jupiter.api.*;
import org.junit.jupiter.api.Order;

import io.voucherify.client.ApiClient;
import io.voucherify.client.api.ManagementApi;
import io.voucherify.client.model.*;
import io.voucherify.client.model.ManagementProjectsCustomEventSchemasCreateResponseBody.ObjectEnum;
import io.voucherify.client.model.ManagementProjectsMetadataSchemaDefinition.TypeEnum;

import static org.junit.jupiter.api.Assertions.assertEquals;
Expand All @@ -19,11 +15,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.io.InputStream;
import java.util.Properties;
import java.io.FileInputStream;
import java.io.IOException;

@org.junit.jupiter.api.Order(14)
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
Expand All @@ -32,45 +23,17 @@ public class ManagementTest {
public static ManagementApi managementApi = null;
public static String projectId = null;
public static String clusterId = null;
private static Properties properties = new Properties();
private static InputStream input = null;

@BeforeAll
public static void beforeAll() {
try {
// Load properties from .env file if it exists
try {
String dir = System.getProperty("user.dir");
input = new FileInputStream(dir + "/.env");
properties.load(input);
} catch (IOException ex) {
System.out.println("[INFO] No .env file found, using environment variables");
ex.printStackTrace();
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
System.err.println("[WARN] Failed to close .env file: " + e.getMessage());
}
}
}

defaultClient = Utils.getClient();
managementApi = new ManagementApi(defaultClient);

// Get VOUCHERIFY_HOST from environment variables or .env file
String voucherifyHost = System.getenv("VOUCHERIFY_HOST");
if ((voucherifyHost == null || voucherifyHost.isEmpty()) && properties != null) {
voucherifyHost = properties.getProperty("VOUCHERIFY_HOST");
}

if (voucherifyHost != null && !voucherifyHost.isEmpty()) {
// Extract cluster ID from host (e.g., https://dev2.api.voucherify.io -> dev2)
String[] parts = voucherifyHost.split("//");
if (parts.length > 1) {
clusterId = parts[1].split("\\.")[0];
}
// Extract cluster ID from host (e.g., https://dev2.api.voucherify.io -> dev2)
String[] parts = defaultClient.getBasePath().split("//");
if (parts.length > 1) {
clusterId = parts[1].split("\\.")[0];
}

// Default to 'eu1' if clusterId couldn't be determined or is too short
Expand Down
49 changes: 32 additions & 17 deletions src/test/java/io/voucherify/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import io.voucherify.client.ApiClient;
import io.voucherify.client.Configuration;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Optional;
import java.util.Properties;

public class Utils {
Expand All @@ -29,30 +31,43 @@ public static String getAlphaNumericString(int n) {

public static ApiClient getClient() {
Properties properties = new Properties();
InputStream input = null;

try {
String dir = System.getProperty("user.dir");
input = new FileInputStream(dir + "/.env");
InputStream input = Files.newInputStream(Paths.get(dir + "/.env"));
properties.load(input);
} catch (IOException ex) {
ex.printStackTrace();
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
System.out.println("[INFO] Missing .env file");
}

String voucherifyHost = Optional
.ofNullable(System.getenv("VOUCHERIFY_HOST"))
.orElse(properties.getProperty("VOUCHERIFY_HOST"));

String xAppId = Optional
.ofNullable(System.getenv("X_APP_ID"))
.orElse(properties.getProperty("X_APP_ID"));

String xAppToken = Optional
.ofNullable(System.getenv("X_APP_TOKEN"))
.orElse(properties.getProperty("X_APP_TOKEN"));

String xManagementId = Optional
.ofNullable(System.getenv("X_MANAGEMENT_ID"))
.orElse(properties.getProperty("X_MANAGEMENT_ID"));

String xManagementToken = Optional
.ofNullable(System.getenv("X_MANAGEMENT_TOKEN"))
.orElse(properties.getProperty("X_MANAGEMENT_TOKEN"));

System.out.println("[INFO] Using HOST " + voucherifyHost);

ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setBasePath(properties.getProperty("VOUCHERIFY_HOST"));
defaultClient.setAuthentication("X-App-Id", properties.getProperty("X_APP_ID"));
defaultClient.setAuthentication("X-App-Token", properties.getProperty("X_APP_TOKEN"));
defaultClient.setAuthentication("X-Management-Id", properties.getProperty("X_MANAGEMENT_ID"));
defaultClient.setAuthentication("X-Management-Token", properties.getProperty("X_MANAGEMENT_TOKEN"));
defaultClient.setBasePath(voucherifyHost);
defaultClient.setAuthentication("X-App-Id", xAppId);
defaultClient.setAuthentication("X-App-Token", xAppToken);
defaultClient.setAuthentication("X-Management-Id", xManagementId);
defaultClient.setAuthentication("X-Management-Token", xManagementToken);

return defaultClient;
}
Expand Down
Loading