Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test appstack from main #23

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
9 changes: 7 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ on:
required: true
default: 'java'
type: string
artifact-prefix:
description: Artifact prefix
required: false
default: ''
type: string
jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -34,10 +39,10 @@ jobs:
rm interface-application.yaml
sed -i -e "/###APP_CONFIG###/r interface-app-config.yaml" -e "//d" interface.yaml
rm interface-app-config.yaml
zip -r ./appstackfor${{ inputs.type }}.zip . -x "*.git*" -x "java/*" -x "images/*" -x "listing/*" -x ".github/*" -x "*.md" -x "troubleshooting/*" -x "tutorials/*" -x "screenshots/*" -x "*.md"
zip -r ./appstackfor${{ inputs.type }}.zip . -x "*.git*" -x "java/*" -x "test/*" -x "images/*" -x "listing/*" -x ".github/*" -x "*.md" -x "troubleshooting/*" -x "tutorials/*" -x "screenshots/*" -x "*.md"
ls -lai
- name: upload-artifact
uses: actions/upload-artifact@v3
with:
name: appstackfor${{ inputs.type }}
name: ${{ inputs.artifact-prefix }}appstackfor${{ inputs.type }}
path: ./appstackfor${{ inputs.type }}.zip
49 changes: 49 additions & 0 deletions .github/workflows/run-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: 'Test appstack'
on:
workflow_dispatch:
inputs:
branch:
description: Branch name
required: true
default: 'main'
type: string
type:
description: Stack type
required: true
default: 'java'
type: string
jobs:
call-workflow-passing-data:
uses: ./.github/workflows/build.yml
with:
branch: ${{github.ref_name}}
type: 'java'
artifact-prefix: ${{github.sha}}_
run-test:
needs: call-workflow-passing-data
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v3
with:
ref: ${{ inputs.branch }}
- name: download-artifact
uses: actions/download-artifact@v2
with:
name: ${{github.sha}}_appstackfor${{ inputs.type }}
path: ./test
- name: install-java
uses: actions/setup-java@v3
with:
distribution: 'oracle'
java-version: '17'
- name: run-test
env:
OCI_TENANCY_OCID: ${{ secrets.OCI_TENANCY_OCID }}
OCI_COMPARTMENT_OCID: ${{ secrets.OCI_COMPARTMENT_OCID }}
OCI_USER_OCID: ${{ secrets.OCI_USER_OCID }}
OCI_PRIVATE_KEY_PEM: ${{ secrets.OCI_PRIVATE_KEY_PEM }}
OCI_FINGERPRINT: ${{ secrets.OCI_FINGERPRINT }}
run: |
cd test
java -jar appstack-test.jar appstackfor${{ inputs.type }}.zip input-${{ inputs.type }}.json
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.DS_Store
.DS_Store
appstack-test/target/**
appstack-test/.vscode/**
124 changes: 124 additions & 0 deletions appstack-test/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>oracle.appstack</groupId>
<artifactId>appstack-test</artifactId>
<version>1.0-SNAPSHOT</version>

<name>appstack-test</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<oci.version>3.25.2</oci.version>
</properties>

<dependencies>
<dependency>
<groupId>com.oracle.oci.sdk</groupId>
<artifactId>oci-java-sdk-common</artifactId>
<version>${oci.version}</version>
</dependency>
<dependency>
<groupId>com.oracle.oci.sdk</groupId>
<artifactId>oci-java-sdk-core</artifactId>
<version>${oci.version}</version>
</dependency>
<dependency>
<groupId>com.oracle.oci.sdk</groupId>
<artifactId>oci-java-sdk-resourcemanager</artifactId>
<version>${oci.version}</version>
</dependency>
<dependency>
<groupId>com.oracle.oci.sdk</groupId>
<artifactId>oci-java-sdk-common-httpclient-jersey</artifactId>
<version>${oci.version}</version>
</dependency>
<dependency>
<groupId>com.oracle.oci.sdk</groupId>
<artifactId>oci-java-sdk-artifacts</artifactId>
<version>${oci.version}</version>
</dependency>
<dependency>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
<version>2.1.2</version>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>oracle.appstack.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
32 changes: 32 additions & 0 deletions appstack-test/src/main/java/oracle/appstack/App.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package oracle.appstack;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Base64;

public class App {
public static void main(String[] args) {
if (args.length != 2) {
System.out.println("Wrong number of parameter.");
System.exit(-2);
}
try (FileInputStream zipFileInputStream = new FileInputStream(
args[0])) {
String testInput = args[1];
byte[] bytes = zipFileInputStream.readAllBytes();
String zipFileBase64Encoded = Base64.getEncoder().encodeToString(bytes);

TestRunner testRunner = new TestRunner(zipFileBase64Encoded);
String deployResult = testRunner.runTestSuite(testInput);
System.out.println(deployResult);
if (deployResult != "SUCCEDED") {
System.exit(-1);
}

} catch (IOException ex) {
ex.printStackTrace();
System.exit(-1);
}

}
}
55 changes: 55 additions & 0 deletions appstack-test/src/main/java/oracle/appstack/TestInput.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package oracle.appstack;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import jakarta.json.JsonObject;
import jakarta.json.JsonValue;
import jakarta.json.JsonValue.ValueType;
import jakarta.json.JsonString;

public class TestInput {
private Map<String, String> variables;
private List<String> testUrls;
private String testName;

private TestInput() {
variables = new HashMap<>();
testUrls = new ArrayList<>();
}

public Map<String, String> getVariables() {
return variables;
}

public List<String> getTestUrls() {
return testUrls;
}

public String getTestName() {
return this.testName;
}

public static TestInput fromJsonObject(JsonObject jsonObject) {
TestInput testInput = new TestInput();
if (jsonObject.containsKey("test-name")) {
testInput.testName = jsonObject.getString("test-name");
}
if (jsonObject.containsKey("variables")) {
JsonObject variables = jsonObject.getJsonObject("variables");
for (String key : variables.keySet()) {
testInput.getVariables().put(key, variables.getString(key));
}
}
if (jsonObject.containsKey("test_urls")) {
for (JsonValue item : jsonObject.getJsonArray("test_urls")) {
if (item.getValueType() == ValueType.STRING)
testInput.getTestUrls().add(((JsonString) item).getString());
}
}
return testInput;
}

}
43 changes: 43 additions & 0 deletions appstack-test/src/main/java/oracle/appstack/TestInputList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package oracle.appstack;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import jakarta.json.Json;
import jakarta.json.JsonValue;
import jakarta.json.stream.JsonParser;
import jakarta.json.stream.JsonParser.Event;

public class TestInputList {

private List<TestInput> input;

private TestInputList() {
input = new ArrayList<>();
}

public static TestInputList fromJsonFile(String fileName) throws IOException {
TestInputList testInputList = new TestInputList();
try (FileInputStream fileInputStream = new FileInputStream(fileName);
JsonParser jsonParser = Json.createParser(fileInputStream)) {
if (jsonParser.hasNext()) {
if (jsonParser.next() == Event.START_ARRAY) {
for (JsonValue item : jsonParser.getArray()) {
TestInput testInput = TestInput.fromJsonObject(item.asJsonObject());
testInputList.input.add(testInput);
}
}
}
return testInputList;
} catch (IOException ex) {
throw ex;
}
}

public List<TestInput> getTestInputList() {
return this.input;
}

}
Loading