2023-01-09 14:56:53 +01:00
|
|
|
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
package sop.external;
|
|
|
|
|
2023-01-22 16:47:44 +01:00
|
|
|
import com.google.gson.Gson;
|
|
|
|
import org.junit.jupiter.api.Named;
|
|
|
|
import org.junit.jupiter.params.provider.Arguments;
|
2023-01-09 14:56:53 +01:00
|
|
|
import sop.SOP;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.InputStream;
|
2023-01-22 16:47:44 +01:00
|
|
|
import java.io.InputStreamReader;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2023-01-09 14:56:53 +01:00
|
|
|
import java.util.Properties;
|
2023-01-22 16:47:44 +01:00
|
|
|
import java.util.stream.Stream;
|
2023-01-09 14:56:53 +01:00
|
|
|
|
2023-01-09 19:48:25 +01:00
|
|
|
import static org.junit.jupiter.api.Assumptions.assumeFalse;
|
2023-01-19 18:00:41 +01:00
|
|
|
import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
2023-01-09 19:48:25 +01:00
|
|
|
|
2023-01-09 14:56:53 +01:00
|
|
|
public abstract class AbstractExternalSOPTest {
|
|
|
|
|
2023-01-22 16:47:44 +01:00
|
|
|
private static final List<Arguments> backends = new ArrayList<>();
|
2023-01-09 14:56:53 +01:00
|
|
|
|
2023-01-22 16:47:44 +01:00
|
|
|
static {
|
|
|
|
TestSuite suite = readConfiguration();
|
|
|
|
assumeTrue(suite != null);
|
|
|
|
assumeFalse(suite.backends.isEmpty());
|
2023-01-09 14:56:53 +01:00
|
|
|
|
2023-01-22 16:47:44 +01:00
|
|
|
for (TestSubject subject : suite.backends) {
|
|
|
|
if (!new File(subject.sop).exists()) {
|
|
|
|
continue;
|
|
|
|
}
|
2023-01-09 14:56:53 +01:00
|
|
|
|
2023-01-22 16:47:44 +01:00
|
|
|
Properties env = new Properties();
|
|
|
|
if (subject.env != null) {
|
|
|
|
for (Var var : subject.env) {
|
|
|
|
env.put(var.key, var.value);
|
|
|
|
}
|
|
|
|
}
|
2023-01-09 14:56:53 +01:00
|
|
|
|
2023-01-22 16:47:44 +01:00
|
|
|
SOP sop = new ExternalSOP(subject.sop, env);
|
|
|
|
backends.add(Arguments.of(Named.of(subject.name, sop)));
|
2023-01-09 14:56:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-22 16:47:44 +01:00
|
|
|
public static Stream<Arguments> provideBackends() {
|
|
|
|
return backends.stream();
|
2023-01-09 19:48:25 +01:00
|
|
|
}
|
|
|
|
|
2023-01-22 16:47:44 +01:00
|
|
|
public static TestSuite readConfiguration() {
|
|
|
|
Gson gson = new Gson();
|
|
|
|
InputStream inputStream = AbstractExternalSOPTest.class.getResourceAsStream("config.json");
|
|
|
|
if (inputStream == null) {
|
|
|
|
return null;
|
2023-01-09 19:48:25 +01:00
|
|
|
}
|
|
|
|
|
2023-01-22 16:47:44 +01:00
|
|
|
InputStreamReader reader = new InputStreamReader(inputStream);
|
|
|
|
TestSuite suite = gson.fromJson(reader, TestSuite.class);
|
|
|
|
return suite;
|
2023-01-09 19:48:25 +01:00
|
|
|
}
|
|
|
|
|
2023-01-22 16:47:44 +01:00
|
|
|
// JSON DTOs
|
2023-01-09 14:56:53 +01:00
|
|
|
|
2023-01-22 16:47:44 +01:00
|
|
|
public static class TestSuite {
|
|
|
|
List<TestSubject> backends;
|
2023-01-09 14:56:53 +01:00
|
|
|
}
|
|
|
|
|
2023-01-22 16:47:44 +01:00
|
|
|
public static class TestSubject {
|
|
|
|
String name;
|
|
|
|
String sop;
|
|
|
|
List<Var> env;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static class Var {
|
|
|
|
String key;
|
|
|
|
String value;
|
2023-01-09 14:56:53 +01:00
|
|
|
}
|
|
|
|
}
|