下面列出了org.junit.jupiter.api.extension.ConditionEvaluationResult#disabled() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
// Check if the minimal version of Java is used for running the tests.
final JavaVersion cVersion = JavaVersion.fromQualifier(System.getProperty("java.specification.version"));
if (cVersion == null) {
return ConditionEvaluationResult.disabled("You must use JDK " + SARLVersion.MINIMAL_JDK_VERSION_FOR_SARL_COMPILATION_ENVIRONMENT + " or higher for running the tests.");
}
final JavaVersion mVersion = JavaVersion.fromQualifier(SARLVersion.MINIMAL_JDK_VERSION_FOR_SARL_COMPILATION_ENVIRONMENT);
if (mVersion == null || !cVersion.isAtLeast(mVersion)) {
return ConditionEvaluationResult.disabled("You must use JDK " + SARLVersion.MINIMAL_JDK_VERSION_FOR_SARL_COMPILATION_ENVIRONMENT + " or higher for running the tests.");
}
final JavaVersion xVersion = JavaVersion.fromQualifier(SARLVersion.INCOMPATIBLE_JDK_VERSION_FOR_SARL_COMPILATION_ENVIRONMENT);
// If null the max version that is specified into the SARL configuration is not yey supported by Xtext enumeration
if (xVersion != null && cVersion.isAtLeast(xVersion)) {
return ConditionEvaluationResult.disabled("You must use JDK strictly below " + SARLVersion.INCOMPATIBLE_JDK_VERSION_FOR_SARL_COMPILATION_ENVIRONMENT + " for running the tests.");
}
return ConditionEvaluationResult.enabled("supported version of JDK");
}
@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
Properties properties = new Properties();
try {
properties.load(DisabledOnQAEnvironmentExtension.class.getClassLoader()
.getResourceAsStream("application.properties"));
if ("qa".equalsIgnoreCase(properties.getProperty("env"))) {
String reason = String.format("The test '%s' is disabled on QA environment", context.getDisplayName());
System.out.println(reason);
return ConditionEvaluationResult.disabled(reason);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
return ConditionEvaluationResult.enabled("Test enabled");
}
@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
Optional<OnServicePresentCondition> annotation = context.getElement().map(e -> e.getAnnotation(OnServicePresentCondition.class));
if (!annotation.isPresent()) {
return ConditionEvaluationResult.enabled("Condition not found!");
}
OnServicePresentCondition condition = annotation.get();
try {
KubernetesClient client = getKubernetesClient(context);
String namespace = Strings.isNotNullOrEmpty(condition.namespace()) ? condition.namespace() : client.getNamespace();
Service service = getKubernetesClient(context).services().inNamespace(namespace).withName(condition.value()).get();
if (service != null) {
return ConditionEvaluationResult.enabled("Found service:" + condition.value() + " in namespace:" + namespace + " .");
} else {
return ConditionEvaluationResult.disabled("Could not find service:" + condition.value() + " in namespace:" + namespace + " .");
}
} catch (Throwable t) {
return ConditionEvaluationResult.disabled("Could not lookup for service.");
}
}
@Override
public ConditionEvaluationResult evaluateExecutionCondition(
ExtensionContext context) {
Optional<AnnotatedElement> element = context.getElement();
ConditionEvaluationResult out = ConditionEvaluationResult
.enabled("@DisabledOnOs is not present");
Optional<DisabledOnOs> disabledOnOs = AnnotationUtils
.findAnnotation(element, DisabledOnOs.class);
if (disabledOnOs.isPresent()) {
Os myOs = Os.determine();
if (Arrays.asList(disabledOnOs.get().value()).contains(myOs)) {
out = ConditionEvaluationResult
.disabled("Test is disabled on " + myOs);
} else {
out = ConditionEvaluationResult
.enabled("Test is not disabled on " + myOs);
}
}
System.out.println("--> " + out.getReason().get());
return out;
}
@Override
public ConditionEvaluationResult evaluate(TestExtensionContext context) {
Properties props = new Properties();
String env = "";
try {
props.load(ConnectionUtil.class.getResourceAsStream("/application.properties"));
env = props.getProperty("env");
} catch (IOException e) {
e.printStackTrace();
}
Optional<DisabledOnEnvironment> disabled = AnnotationSupport.findAnnotation(context.getElement().get(), DisabledOnEnvironment.class);
if (disabled.isPresent()) {
String[] envs = disabled.get().value();
if (Arrays.asList(envs).contains(env)) {
return ConditionEvaluationResult.disabled("Disabled on environment " + env);
}
}
return ConditionEvaluationResult.enabled("Enabled on environment "+env);
}
@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
// Search for the @DisabledWeekdays annotation from the TestExtensionContext
Optional<AnnotatedElement> contextElement = context.getElement();
AnnotatedElement annotatedElement = contextElement.orElse(null);
if (annotatedElement == null) return null;
DisabledWeekdays weekdayAnnotation = annotatedElement.getAnnotation(DisabledWeekdays.class);
// Determine whether the test should be disabled
boolean weekdayToday = IntStream.of(weekdayAnnotation.value())
.anyMatch(day -> day == Calendar.getInstance().get(Calendar.DAY_OF_WEEK));
// Return a ConditionEvaluationResult based on the outcome of the boolean weekdayToday
return weekdayToday ?
ConditionEvaluationResult.disabled("I spare you today.") :
ConditionEvaluationResult.enabled("Don't spare you on other days though >:(");
}
@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
Optional<EnabledOnGitVersions> maybe = findAnnotation(context.getElement(), EnabledOnGitVersions.class);
if (maybe.isPresent()) {
final EnabledOnGitVersions annotation = maybe.get();
final Version gitVersion = fetchGitVersion();
if (noneSpecified(annotation)) {
return ConditionEvaluationResult.enabled("Version requirements not provided. Running by default.");
}
if (atLeast(annotation.from(), gitVersion) && atMost(annotation.through(), gitVersion)) {
return ConditionEvaluationResult.enabled(
format("Git version %s satisfies %s", gitVersion, criteria(annotation))
);
} else {
return ConditionEvaluationResult.disabled(
format("Git version %s does not satisfy %s", gitVersion, criteria(annotation))
);
}
}
return ConditionEvaluationResult.enabled("Version requirements not provided. Running by default.");
}
@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
Optional<RequireSystemProperty> annotation = AnnotationSupport.findAnnotation(context.getElement(), RequireSystemProperty.class);
if (annotation.isPresent()) {
for (String propertyKey : annotation.get().value()) {
String propertyValue = System.getProperty(propertyKey);
if (propertyValue == null || propertyValue.isEmpty()) {
return ConditionEvaluationResult.disabled(String.format("System property '%s' not set. Skipping test.", propertyKey));
}
}
return ConditionEvaluationResult.enabled("All required system properties present. Continuing test.");
}
return ConditionEvaluationResult.enabled("No RequireSystemProperty annotation found. Continuing test.");
}
@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
try {
VersionInfo version = getKubernetesClient(context).getVersion();
String message = "Found version:" + version.getMajor() + "." + version.getMinor();
LOGGER.info(message);
return ConditionEvaluationResult.enabled(message);
} catch (Throwable t) {
String reason = "Could not communicate with KubernetesExtension API server.";
LOGGER.error(reason);
return ConditionEvaluationResult.disabled(reason);
}
}
private ConditionEvaluationResult evaluate(Testcontainers testcontainers) {
if (testcontainers.disabledWithoutDocker()) {
if (isDockerAvailable()) {
return ConditionEvaluationResult.enabled("Docker is available");
}
return ConditionEvaluationResult.disabled("disabledWithoutDocker is true and Docker is not available");
}
return ConditionEvaluationResult.enabled("disabledWithoutDocker is false");
}
@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
if (IS_IAM_ENABLED) {
return ConditionEvaluationResult.disabled("Test is not supported when using IAM.");
} else {
return ConditionEvaluationResult.enabled("Test enabled.");
}
}
@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
if (context.getRequiredTestMethod().getName().equals(testMethodToSkip)) {
return ConditionEvaluationResult.disabled("Disabled by InjectableExtension.");
}
return ConditionEvaluationResult.enabled("");
}
@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
Optional<AssumeConnection> annotation = findAnnotation(context.getElement(), AssumeConnection.class);
if (annotation.isPresent()) {
String uri = annotation.get().uri();
ConnectionChecker checker = new ConnectionChecker(uri);
if (!checker.connect()) {
return ConditionEvaluationResult.disabled(String.format("Could not connect to '%s'. Skipping test!", uri));
} else {
return ConditionEvaluationResult.enabled(String.format("Successfully connected to '%s'. Continuing test!", uri));
}
}
return ConditionEvaluationResult.enabled("No AssumeConnection annotation found. Continuing test.");
}
@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
boolean monday = Calendar.getInstance().get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY;
return monday ?
ConditionEvaluationResult.disabled("I spare you on Mondays.") :
ConditionEvaluationResult.enabled("Don't spare you on other days though >:(");
}
@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
Optional<Kubernetes> annotation = findAnnotation(context.getElement(), Kubernetes.class);
if (annotation.isPresent()) {
ClusterType cluster = annotation.get().type();
MultinodeCluster multinode = annotation.get().multinode();
if (!io.enmasse.systemtest.platform.Kubernetes.getInstance().getCluster().toString().equals(cluster.toString().toLowerCase()) &&
(multinode == MultinodeCluster.WHATEVER || multinode == io.enmasse.systemtest.platform.Kubernetes.getInstance().isClusterMultinode())) {
return ConditionEvaluationResult.disabled("Test is not supported on current cluster");
} else {
return ConditionEvaluationResult.enabled("Test is supported on current cluster");
}
}
return ConditionEvaluationResult.enabled("No rule set, test is enabled");
}
@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext extensionContext) {
KubeClusterResource clusterResource = KubeClusterResource.getInstance();
if (clusterResource.cluster() instanceof OpenShift || clusterResource.cluster() instanceof Minishift) {
return ConditionEvaluationResult.enabled("Test is enabled");
} else {
LOGGER.info("{} is @OpenShiftOnly, but the running cluster is not OpenShift: Ignoring {}",
extensionContext.getDisplayName(),
extensionContext.getDisplayName()
);
return ConditionEvaluationResult.disabled("Test is disabled");
}
}
@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
Optional<OnCustomResourcePresentCondition> annotation = context.getElement().map(e -> e.getAnnotation(OnCustomResourcePresentCondition.class));
if (!annotation.isPresent()) {
return ConditionEvaluationResult.enabled("Condition not found!");
}
OnCustomResourcePresentCondition condition = annotation.get();
try {
String apiVersion = condition.apiVersion();
String kind = condition.kind();
String plural = Strings.isNotNullOrEmpty(condition.plural()) ? condition.plural() : Pluralize.FUNCTION.apply(kind).toLowerCase();
String name = condition.name();
String namespace = condition.namespace();
KubernetesClient client = getKubernetesClient(context);
Config config = client.getConfiguration();
OkHttpClient http = client.adapt(OkHttpClient.class);
List<String> parts = new ArrayList<>();
parts.add(config.getMasterUrl());
parts.add("apis");
parts.add(apiVersion);
if (Strings.isNotNullOrEmpty(namespace)) {
parts.add("namespaces");
parts.add(namespace);
}
parts.add(plural);
if (Strings.isNotNullOrEmpty(name)) {
parts.add(name);
}
parts.add(plural);
String requestUrl = URLUtils.join(parts.stream().toArray(s->new String[s]));
Request request = new Request.Builder().get().url(requestUrl).build();
Response response = http.newCall(request).execute();
if (!response.isSuccessful()) {
return ConditionEvaluationResult.disabled("Could not lookup custom resource.");
}
//TODO: Add support for cases where name() is empty. In this case the result will be a list.
//We need to check if empty.
return ConditionEvaluationResult.enabled("Found resource with apiVersion:" + apiVersion + " kind:" + kind + " namespace: " + (Strings.isNullOrEmpty(namespace) ? "any" : namespace) + " name: " + (Strings.isNullOrEmpty(name) ? "any" : name));
} catch (Throwable t) {
return ConditionEvaluationResult.disabled("Could not lookup for service.");
}
}
@Override
public ConditionEvaluationResult evaluateExecutionCondition(final ExtensionContext context) {
return isActive() ? ConditionEvaluationResult.enabled("provider is active")
: ConditionEvaluationResult.disabled("provider is disabled");
}
@VisibleForTesting
static ConditionEvaluationResult evaluateExecutionCondition(final boolean headless) {
return headless
? ConditionEvaluationResult.disabled("Test disabled in headless graphics environment")
: ConditionEvaluationResult.enabled(null);
}
/**
* Whether to run this test.
* <p>Enabled by default, unless explicitly disabled
* from command line ({@code -Dcalcite.test.cassandra=false}) or running on incompatible JDK
* version (see below).
*
* <p>As of this wiring Cassandra 4.x is not yet released and we're using 3.x
* (which fails on JDK11+). All cassandra tests will be skipped if
* running on JDK11+.
*
* @see <a href="https://issues.apache.org/jira/browse/CASSANDRA-9608">CASSANDRA-9608</a>
* @return {@code true} if test is compatible with current environment,
* {@code false} otherwise
*/
@Override public ConditionEvaluationResult evaluateExecutionCondition(
final ExtensionContext context) {
boolean enabled = CalciteSystemProperty.TEST_CASSANDRA.value();
Bug.upgrade("remove JDK version check once current adapter supports Cassandra 4.x");
boolean compatibleJdk = TestUtil.getJavaMajorVersion() < 11;
if (enabled && compatibleJdk) {
return ConditionEvaluationResult.enabled("Cassandra enabled");
}
return ConditionEvaluationResult.disabled("Cassandra tests disabled");
}