From 3789b60f0bf6879626488ebe693492a9227764f6 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Sun, 22 Jan 2023 16:53:50 +0100 Subject: [PATCH] Properly ignore tests if no backends are configured --- external-sop/build.gradle | 4 +-- .../sop/external/AbstractExternalSOPTest.java | 36 +++++++++---------- .../ExternalArmorDearmorRoundTripTest.java | 2 ++ .../ExternalDecryptWithSessionKeyTest.java | 2 ++ ...ternalDetachedSignVerifyRoundTripTest.java | 2 ++ .../ExternalEncryptDecryptRoundTripTest.java | 2 ++ .../sop/external/ExternalExtractCertTest.java | 2 ++ .../sop/external/ExternalGenerateKeyTest.java | 2 ++ ...alInlineSignDetachVerifyRoundTripTest.java | 2 ++ .../ExternalInlineSignVerifyTest.java | 2 ++ .../sop/external/ExternalVersionTest.java | 2 ++ 11 files changed, 37 insertions(+), 21 deletions(-) diff --git a/external-sop/build.gradle b/external-sop/build.gradle index 0f5055b..37bd8f3 100644 --- a/external-sop/build.gradle +++ b/external-sop/build.gradle @@ -16,6 +16,7 @@ dependencies { testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion" testImplementation "org.junit.jupiter:junit-jupiter-params:$junitVersion" testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion" + // Read json config file testImplementation "com.google.code.gson:gson:2.10.1" api project(":sop-java") @@ -23,9 +24,6 @@ dependencies { api "org.slf4j:slf4j-api:$slf4jVersion" testImplementation "ch.qos.logback:logback-classic:$logbackVersion" - // Compare version strings - implementation 'org.apache.maven:maven-artifact:3.6.3' - // @Nonnull, @Nullable... implementation "com.google.code.findbugs:jsr305:$jsrVersion" } diff --git a/external-sop/src/test/java/sop/external/AbstractExternalSOPTest.java b/external-sop/src/test/java/sop/external/AbstractExternalSOPTest.java index 3661d2a..824990f 100644 --- a/external-sop/src/test/java/sop/external/AbstractExternalSOPTest.java +++ b/external-sop/src/test/java/sop/external/AbstractExternalSOPTest.java @@ -17,32 +17,28 @@ import java.util.List; import java.util.Properties; import java.util.stream.Stream; -import static org.junit.jupiter.api.Assumptions.assumeFalse; -import static org.junit.jupiter.api.Assumptions.assumeTrue; - public abstract class AbstractExternalSOPTest { private static final List backends = new ArrayList<>(); static { TestSuite suite = readConfiguration(); - assumeTrue(suite != null); - assumeFalse(suite.backends.isEmpty()); - - for (TestSubject subject : suite.backends) { - if (!new File(subject.sop).exists()) { - continue; - } - - Properties env = new Properties(); - if (subject.env != null) { - for (Var var : subject.env) { - env.put(var.key, var.value); + if (suite != null && !suite.backends.isEmpty()) { + for (TestSubject subject : suite.backends) { + if (!new File(subject.sop).exists()) { + continue; } - } - SOP sop = new ExternalSOP(subject.sop, env); - backends.add(Arguments.of(Named.of(subject.name, sop))); + Properties env = new Properties(); + if (subject.env != null) { + for (Var var : subject.env) { + env.put(var.key, var.value); + } + } + + SOP sop = new ExternalSOP(subject.sop, env); + backends.add(Arguments.of(Named.of(subject.name, sop))); + } } } @@ -62,6 +58,10 @@ public abstract class AbstractExternalSOPTest { return suite; } + public static boolean hasBackends() { + return !backends.isEmpty(); + } + // JSON DTOs public static class TestSuite { diff --git a/external-sop/src/test/java/sop/external/ExternalArmorDearmorRoundTripTest.java b/external-sop/src/test/java/sop/external/ExternalArmorDearmorRoundTripTest.java index d6e4402..dec48f4 100644 --- a/external-sop/src/test/java/sop/external/ExternalArmorDearmorRoundTripTest.java +++ b/external-sop/src/test/java/sop/external/ExternalArmorDearmorRoundTripTest.java @@ -4,6 +4,7 @@ package sop.external; +import org.junit.jupiter.api.condition.EnabledIf; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; import sop.SOP; @@ -17,6 +18,7 @@ import static sop.external.JUtils.arrayStartsWith; import static sop.external.JUtils.assertArrayStartsWith; import static sop.external.JUtils.assertAsciiArmorEquals; +@EnabledIf("sop.external.AbstractExternalSOPTest#hasBackends") public class ExternalArmorDearmorRoundTripTest extends AbstractExternalSOPTest { private static final String BEGIN_PGP_PRIVATE_KEY_BLOCK = "-----BEGIN PGP PRIVATE KEY BLOCK-----\n"; diff --git a/external-sop/src/test/java/sop/external/ExternalDecryptWithSessionKeyTest.java b/external-sop/src/test/java/sop/external/ExternalDecryptWithSessionKeyTest.java index 7a5e4f6..8a7ff56 100644 --- a/external-sop/src/test/java/sop/external/ExternalDecryptWithSessionKeyTest.java +++ b/external-sop/src/test/java/sop/external/ExternalDecryptWithSessionKeyTest.java @@ -4,6 +4,7 @@ package sop.external; +import org.junit.jupiter.api.condition.EnabledIf; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; import sop.ByteArrayAndResult; @@ -17,6 +18,7 @@ import java.nio.charset.StandardCharsets; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; +@EnabledIf("sop.external.AbstractExternalSOPTest#hasBackends") public class ExternalDecryptWithSessionKeyTest extends AbstractExternalSOPTest { private static final String CIPHERTEXT = "-----BEGIN PGP MESSAGE-----\n" + diff --git a/external-sop/src/test/java/sop/external/ExternalDetachedSignVerifyRoundTripTest.java b/external-sop/src/test/java/sop/external/ExternalDetachedSignVerifyRoundTripTest.java index 8e87b00..ddee99a 100644 --- a/external-sop/src/test/java/sop/external/ExternalDetachedSignVerifyRoundTripTest.java +++ b/external-sop/src/test/java/sop/external/ExternalDetachedSignVerifyRoundTripTest.java @@ -4,6 +4,7 @@ package sop.external; +import org.junit.jupiter.api.condition.EnabledIf; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; import sop.SOP; @@ -21,6 +22,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static sop.external.JUtils.assertArrayStartsWith; import static sop.external.JUtils.assertSignedBy; +@EnabledIf("sop.external.AbstractExternalSOPTest#hasBackends") public class ExternalDetachedSignVerifyRoundTripTest extends AbstractExternalSOPTest { private static final String BEGIN_PGP_SIGNATURE = "-----BEGIN PGP SIGNATURE-----\n"; diff --git a/external-sop/src/test/java/sop/external/ExternalEncryptDecryptRoundTripTest.java b/external-sop/src/test/java/sop/external/ExternalEncryptDecryptRoundTripTest.java index 2b505a4..4692f21 100644 --- a/external-sop/src/test/java/sop/external/ExternalEncryptDecryptRoundTripTest.java +++ b/external-sop/src/test/java/sop/external/ExternalEncryptDecryptRoundTripTest.java @@ -4,6 +4,7 @@ package sop.external; +import org.junit.jupiter.api.condition.EnabledIf; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; import sop.ByteArrayAndResult; @@ -26,6 +27,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; +@EnabledIf("sop.external.AbstractExternalSOPTest#hasBackends") public class ExternalEncryptDecryptRoundTripTest extends AbstractExternalSOPTest { @ParameterizedTest diff --git a/external-sop/src/test/java/sop/external/ExternalExtractCertTest.java b/external-sop/src/test/java/sop/external/ExternalExtractCertTest.java index 39a661b..19866ee 100644 --- a/external-sop/src/test/java/sop/external/ExternalExtractCertTest.java +++ b/external-sop/src/test/java/sop/external/ExternalExtractCertTest.java @@ -4,6 +4,7 @@ package sop.external; +import org.junit.jupiter.api.condition.EnabledIf; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; import sop.SOP; @@ -17,6 +18,7 @@ import static sop.external.JUtils.arrayStartsWith; import static sop.external.JUtils.assertArrayStartsWith; import static sop.external.JUtils.assertAsciiArmorEquals; +@EnabledIf("sop.external.AbstractExternalSOPTest#hasBackends") public class ExternalExtractCertTest extends AbstractExternalSOPTest { private static final String BEGIN_PGP_PUBLIC_KEY_BLOCK = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n"; diff --git a/external-sop/src/test/java/sop/external/ExternalGenerateKeyTest.java b/external-sop/src/test/java/sop/external/ExternalGenerateKeyTest.java index 7839c60..2525014 100644 --- a/external-sop/src/test/java/sop/external/ExternalGenerateKeyTest.java +++ b/external-sop/src/test/java/sop/external/ExternalGenerateKeyTest.java @@ -4,6 +4,7 @@ package sop.external; +import org.junit.jupiter.api.condition.EnabledIf; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; import sop.SOP; @@ -15,6 +16,7 @@ import java.nio.charset.StandardCharsets; import static org.junit.jupiter.api.Assertions.assertFalse; import static sop.external.JUtils.assertArrayStartsWith; +@EnabledIf("sop.external.AbstractExternalSOPTest#hasBackends") public class ExternalGenerateKeyTest extends AbstractExternalSOPTest { private static final Charset UTF8 = StandardCharsets.UTF_8; diff --git a/external-sop/src/test/java/sop/external/ExternalInlineSignDetachVerifyRoundTripTest.java b/external-sop/src/test/java/sop/external/ExternalInlineSignDetachVerifyRoundTripTest.java index a1e84b1..bc77534 100644 --- a/external-sop/src/test/java/sop/external/ExternalInlineSignDetachVerifyRoundTripTest.java +++ b/external-sop/src/test/java/sop/external/ExternalInlineSignDetachVerifyRoundTripTest.java @@ -4,6 +4,7 @@ package sop.external; +import org.junit.jupiter.api.condition.EnabledIf; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; import sop.ByteArrayAndResult; @@ -20,6 +21,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static sop.external.JUtils.arrayStartsWith; import static sop.external.JUtils.assertArrayStartsWith; +@EnabledIf("sop.external.AbstractExternalSOPTest#hasBackends") public class ExternalInlineSignDetachVerifyRoundTripTest extends AbstractExternalSOPTest { private static final byte[] BEGIN_PGP_SIGNATURE = "-----BEGIN PGP SIGNATURE-----\n".getBytes(StandardCharsets.UTF_8); diff --git a/external-sop/src/test/java/sop/external/ExternalInlineSignVerifyTest.java b/external-sop/src/test/java/sop/external/ExternalInlineSignVerifyTest.java index e6ee329..22916d6 100644 --- a/external-sop/src/test/java/sop/external/ExternalInlineSignVerifyTest.java +++ b/external-sop/src/test/java/sop/external/ExternalInlineSignVerifyTest.java @@ -4,6 +4,7 @@ package sop.external; +import org.junit.jupiter.api.condition.EnabledIf; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; import sop.ByteArrayAndResult; @@ -22,6 +23,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; import static sop.external.JUtils.assertSignedBy; +@EnabledIf("sop.external.AbstractExternalSOPTest#hasBackends") public class ExternalInlineSignVerifyTest extends AbstractExternalSOPTest { private static final String BEGIN_PGP_MESSAGE = "-----BEGIN PGP MESSAGE-----\n"; diff --git a/external-sop/src/test/java/sop/external/ExternalVersionTest.java b/external-sop/src/test/java/sop/external/ExternalVersionTest.java index 0415d03..4b1f87c 100644 --- a/external-sop/src/test/java/sop/external/ExternalVersionTest.java +++ b/external-sop/src/test/java/sop/external/ExternalVersionTest.java @@ -4,6 +4,7 @@ package sop.external; +import org.junit.jupiter.api.condition.EnabledIf; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; import sop.SOP; @@ -12,6 +13,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; +@EnabledIf("sop.external.AbstractExternalSOPTest#hasBackends") public class ExternalVersionTest extends AbstractExternalSOPTest { @ParameterizedTest