Java Code Examples for org.junit.jupiter.api.extension.ConditionEvaluationResult#enabled()
The following examples show how to use
org.junit.jupiter.api.extension.ConditionEvaluationResult#enabled() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ServicePresentCondition.java From dekorate with Apache License 2.0 | 6 votes |
@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."); } }
Example 2
Source File: AssumeOpenshiftCondition.java From enmasse with Apache License 2.0 | 6 votes |
@Override public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { Optional<OpenShift> annotation = findAnnotation(context.getElement(), OpenShift.class); if (annotation.isPresent()) { var version = annotation.get().version(); var type = annotation.get().type(); var multinode = type.equals(ClusterType.CRC) ? MultinodeCluster.NO : annotation.get().multinode(); if ((Kubernetes.getInstance().getCluster().toString().equals(ClusterType.OPENSHIFT.toString().toLowerCase()) || Kubernetes.getInstance().getCluster().toString().equals(ClusterType.CRC.toString().toLowerCase())) && (version == OpenShiftVersion.WHATEVER || version == Kubernetes.getInstance().getOcpVersion()) && (multinode == MultinodeCluster.WHATEVER || multinode == Kubernetes.getInstance().isClusterMultinode())) { return ConditionEvaluationResult.enabled("Test is supported on current cluster"); } else { return ConditionEvaluationResult.disabled("Test is not supported on current cluster"); } } return ConditionEvaluationResult.enabled("No rule set, test is enabled"); }
Example 3
Source File: DisabledOnEnvironmentCondition.java From tutorials with MIT License | 6 votes |
@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); }
Example 4
Source File: DisabledOnQAEnvironmentExtension.java From tutorials with MIT License | 6 votes |
@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"); }
Example 5
Source File: OsCondition.java From Mastering-Software-Testing-with-JUnit-5 with MIT License | 6 votes |
@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; }
Example 6
Source File: DisabledOnWeekday.java From JUnit-5-Quick-Start-Guide-and-Framework-Support with MIT License | 6 votes |
@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 >:("); }
Example 7
Source File: RequireIPv6Condition.java From grpc-spring-boot-starter with MIT License | 6 votes |
@Override public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { if (ipv6Result == null) { boolean result = false; try { result = hasIPv6Loopback(); } catch (SocketException e) { log.warn("Could not determine presence of IPv6 loopback address", e); } if (result) { ipv6Result = ConditionEvaluationResult.enabled("Found IPv6 loopback"); } else { ipv6Result = ConditionEvaluationResult.disabled("Could not find IPv6 loopback"); } } return ipv6Result; }
Example 8
Source File: AssumeConnectionCondition.java From code-examples with MIT License | 5 votes |
@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."); }
Example 9
Source File: OpenShiftOnlyCondition.java From strimzi-kafka-operator with Apache License 2.0 | 5 votes |
@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"); } }
Example 10
Source File: DisabledByFormula.java From demo-junit-5 with Creative Commons Zero v1.0 Universal | 5 votes |
@Override public ConditionEvaluationResult evaluateExecutionCondition( ExtensionContext context) { return formula.evaluate() // disable when formula is true ? ConditionEvaluationResult.disabled(message) : ConditionEvaluationResult.enabled("Not '" + message + "'"); }
Example 11
Source File: IamAuthCondition.java From java-cloudant with Apache License 2.0 | 5 votes |
@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."); } }
Example 12
Source File: OsCondition.java From demo-junit-5 with Creative Commons Zero v1.0 Universal | 5 votes |
private ConditionEvaluationResult disabledIfOn(OS[] disabledOnOs) { OS os = OS.determine(); if (Arrays.asList(disabledOnOs).contains(os)) return ConditionEvaluationResult.disabled("Test is disabled on " + os + "."); else return ConditionEvaluationResult.enabled("Test is not disabled in " + os + "."); }
Example 13
Source File: VaultVersionExtension.java From spring-vault with Apache License 2.0 | 5 votes |
@Override public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { Optional<RequiresVaultVersion> optional = AnnotationUtils.findAnnotation(context.getElement(), RequiresVaultVersion.class); if (!optional.isPresent()) { return ENABLED_BY_DEFAULT; } ExtensionContext.Store store = context.getStore(VAULT); Version runningVersion = store.getOrComputeIfAbsent(Version.class, versionClass -> { VaultInitializer initializer = new VaultInitializer(); initializer.initialize(); return initializer.prepare().getVersion(); }, Version.class); RequiresVaultVersion requiredVersion = optional.get(); Version required = Version.parse(requiredVersion.value()); if (runningVersion.isGreaterThanOrEqualTo(required)) { return ConditionEvaluationResult .enabled(String.format("@VaultVersion check passed current Vault version is %s", runningVersion)); } return ConditionEvaluationResult.disabled(String.format( "@VaultVersion requires since version %s, current Vault version is %s", required, runningVersion)); }
Example 14
Source File: EnvironmentExtension.java From tutorials with MIT License | 5 votes |
@Override public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { Properties props = new Properties(); try { props.load(EnvironmentExtension.class.getResourceAsStream("application.properties")); String env = props.getProperty("env"); if ("qa".equalsIgnoreCase(env)) { return ConditionEvaluationResult.disabled("Test disabled on QA environment"); } } catch (IOException e) { e.printStackTrace(); } return ConditionEvaluationResult.enabled("Test enabled on QA environment"); }
Example 15
Source File: InjectExtensionsTest.java From junit5-extensions with MIT License | 5 votes |
@Override public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { if (context.getRequiredTestMethod().getName().equals(testMethodToSkip)) { return ConditionEvaluationResult.disabled("Disabled by InjectableExtension."); } return ConditionEvaluationResult.enabled(""); }
Example 16
Source File: DisableOnMacCondition.java From cssfx with Apache License 2.0 | 5 votes |
@Override public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { final String osName = System.getProperty("os.name"); final String cleanOsName = osName .replaceAll("\\s", "") .toLowerCase(Locale.ENGLISH); if(cleanOsName.contains(MAC_OS)) { return ConditionEvaluationResult.disabled("Test disabled on JVM running on " + osName); } else { return ConditionEvaluationResult.enabled("Test enabled, running on " + osName); } }
Example 17
Source File: KubernetesExtension.java From dekorate with Apache License 2.0 | 5 votes |
@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); } }
Example 18
Source File: AssumeKubernetesCondition.java From enmasse with Apache License 2.0 | 5 votes |
@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"); }
Example 19
Source File: EnvironmentalContext.java From component-runtime with Apache License 2.0 | 4 votes |
@Override public ConditionEvaluationResult evaluateExecutionCondition(final ExtensionContext context) { return isActive() ? ConditionEvaluationResult.enabled("provider is active") : ConditionEvaluationResult.disabled("provider is disabled"); }
Example 20
Source File: CustomResourceCondition.java From dekorate with Apache License 2.0 | 4 votes |
@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."); } }