diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/AbstractJvmQuarkusTestExtension.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/AbstractJvmQuarkusTestExtension.java index 36500263f4638..a36ee0cc8ac64 100644 --- a/test-framework/junit5/src/main/java/io/quarkus/test/junit/AbstractJvmQuarkusTestExtension.java +++ b/test-framework/junit5/src/main/java/io/quarkus/test/junit/AbstractJvmQuarkusTestExtension.java @@ -14,6 +14,7 @@ import java.util.HashMap; import java.util.Map; import java.util.Optional; +import java.util.Set; import java.util.function.Consumer; import java.util.stream.Collectors; @@ -21,6 +22,8 @@ import org.jboss.jandex.Index; import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.extension.ConditionEvaluationResult; +import org.junit.jupiter.api.extension.ExecutionCondition; import org.junit.jupiter.api.extension.ExtensionContext; import io.quarkus.bootstrap.BootstrapConstants; @@ -41,7 +44,8 @@ import io.quarkus.test.common.RestorableSystemProperties; import io.quarkus.test.common.TestClassIndexer; -public class AbstractJvmQuarkusTestExtension extends AbstractQuarkusTestWithContextExtension { +public class AbstractJvmQuarkusTestExtension extends AbstractQuarkusTestWithContextExtension + implements ExecutionCondition { protected static final String TEST_LOCATION = "test-location"; protected static final String TEST_CLASS = "test-class"; @@ -267,6 +271,42 @@ private Class findTestProfileAnnotation(Class c return null; } + @Override + public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { + if (!context.getTestClass().isPresent()) { + return ConditionEvaluationResult.enabled("No test class specified"); + } + if (context.getTestInstance().isPresent()) { + return ConditionEvaluationResult.enabled("Quarkus Test Profile tags only affect classes"); + } + String tagsStr = System.getProperty("quarkus.test.profile.tags"); + if ((tagsStr == null) || tagsStr.isEmpty()) { + return ConditionEvaluationResult.enabled("No Quarkus Test Profile tags"); + } + Class testProfile = getQuarkusTestProfile(context); + if (testProfile == null) { + return ConditionEvaluationResult.disabled("Test '" + context.getRequiredTestClass() + + "' is not annotated with '@QuarkusTestProfile' but 'quarkus.profile.test.tags' was set"); + } + QuarkusTestProfile profileInstance; + try { + profileInstance = testProfile.getConstructor().newInstance(); + } catch (Exception e) { + throw new RuntimeException(e); + } + Set testProfileTags = profileInstance.tags(); + String[] tags = tagsStr.split(","); + for (String tag : tags) { + String trimmedTag = tag.trim(); + if (testProfileTags.contains(trimmedTag)) { + return ConditionEvaluationResult.enabled("Tag '" + trimmedTag + "' is present on '" + testProfile + + "' which is used on test '" + context.getRequiredTestClass()); + } + } + return ConditionEvaluationResult.disabled("Test '" + context.getRequiredTestClass() + + "' disabled because 'quarkus.profile.test.tags' don't match the tags of '" + testProfile + "'"); + } + protected static class PrepareResult { protected final AugmentAction augmentAction; protected final QuarkusTestProfile profileInstance; diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusMainTestExtension.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusMainTestExtension.java index f68b87436684b..71776250160ec 100644 --- a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusMainTestExtension.java +++ b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusMainTestExtension.java @@ -16,6 +16,8 @@ import org.junit.jupiter.api.extension.AfterEachCallback; import org.junit.jupiter.api.extension.BeforeAllCallback; import org.junit.jupiter.api.extension.BeforeEachCallback; +import org.junit.jupiter.api.extension.ConditionEvaluationResult; +import org.junit.jupiter.api.extension.ExecutionCondition; import org.junit.jupiter.api.extension.ExtensionContext; import org.junit.jupiter.api.extension.InvocationInterceptor; import org.junit.jupiter.api.extension.ParameterContext; @@ -38,7 +40,7 @@ public class QuarkusMainTestExtension extends AbstractJvmQuarkusTestExtension implements InvocationInterceptor, BeforeEachCallback, AfterEachCallback, ParameterResolver, BeforeAllCallback, - AfterAllCallback { + AfterAllCallback, ExecutionCondition { PrepareResult prepareResult; @@ -321,4 +323,9 @@ public void afterAll(ExtensionContext context) throws Exception { public void beforeAll(ExtensionContext context) throws Exception { currentTestClassStack.push(context.getRequiredTestClass()); } + + @Override + public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { + return super.evaluateExecutionCondition(context); + } } diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusTestExtension.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusTestExtension.java index 8afb99cf10bb4..91da01372bb78 100644 --- a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusTestExtension.java +++ b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusTestExtension.java @@ -24,7 +24,6 @@ import java.util.Objects; import java.util.Optional; import java.util.ServiceLoader; -import java.util.Set; import java.util.concurrent.CompletionException; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.Executors; @@ -54,8 +53,6 @@ import org.junit.jupiter.api.extension.BeforeAllCallback; import org.junit.jupiter.api.extension.BeforeEachCallback; import org.junit.jupiter.api.extension.BeforeTestExecutionCallback; -import org.junit.jupiter.api.extension.ConditionEvaluationResult; -import org.junit.jupiter.api.extension.ExecutionCondition; import org.junit.jupiter.api.extension.ExtensionContext; import org.junit.jupiter.api.extension.InvocationInterceptor; import org.junit.jupiter.api.extension.ParameterContext; @@ -105,7 +102,7 @@ public class QuarkusTestExtension extends AbstractJvmQuarkusTestExtension implements BeforeEachCallback, BeforeTestExecutionCallback, AfterTestExecutionCallback, AfterEachCallback, BeforeAllCallback, InvocationInterceptor, AfterAllCallback, - ParameterResolver, ExecutionCondition { + ParameterResolver { private static final Logger log = Logger.getLogger(QuarkusTestExtension.class); @@ -1136,42 +1133,6 @@ private boolean testMethodInvokerHandlesParamType(Object testMethodInvoker, Para } } - @Override - public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { - if (!context.getTestClass().isPresent()) { - return ConditionEvaluationResult.enabled("No test class specified"); - } - if (context.getTestInstance().isPresent()) { - return ConditionEvaluationResult.enabled("Quarkus Test Profile tags only affect classes"); - } - String tagsStr = System.getProperty("quarkus.test.profile.tags"); - if ((tagsStr == null) || tagsStr.isEmpty()) { - return ConditionEvaluationResult.enabled("No Quarkus Test Profile tags"); - } - Class testProfile = getQuarkusTestProfile(context); - if (testProfile == null) { - return ConditionEvaluationResult.disabled("Test '" + context.getRequiredTestClass() - + "' is not annotated with '@QuarkusTestProfile' but 'quarkus.profile.test.tags' was set"); - } - QuarkusTestProfile profileInstance; - try { - profileInstance = testProfile.getConstructor().newInstance(); - } catch (Exception e) { - throw new RuntimeException(e); - } - Set testProfileTags = profileInstance.tags(); - String[] tags = tagsStr.split(","); - for (String tag : tags) { - String trimmedTag = tag.trim(); - if (testProfileTags.contains(trimmedTag)) { - return ConditionEvaluationResult.enabled("Tag '" + trimmedTag + "' is present on '" + testProfile - + "' which is used on test '" + context.getRequiredTestClass()); - } - } - return ConditionEvaluationResult.disabled("Test '" + context.getRequiredTestClass() - + "' disabled because 'quarkus.profile.test.tags' don't match the tags of '" + testProfile + "'"); - } - public static class ExtensionState extends QuarkusTestExtensionState { public ExtensionState(Closeable testResourceManager, Closeable resource, Runnable clearCallbacks) {