diff options
Diffstat (limited to 'controlloop/common/rules-test/src/main/java/org/onap/policy/controlloop/common/rules/test')
3 files changed, 24 insertions, 29 deletions
diff --git a/controlloop/common/rules-test/src/main/java/org/onap/policy/controlloop/common/rules/test/BaseTest.java b/controlloop/common/rules-test/src/main/java/org/onap/policy/controlloop/common/rules/test/BaseTest.java index 771df1b63..c2e10dff6 100644 --- a/controlloop/common/rules-test/src/main/java/org/onap/policy/controlloop/common/rules/test/BaseTest.java +++ b/controlloop/common/rules-test/src/main/java/org/onap/policy/controlloop/common/rules/test/BaseTest.java @@ -21,7 +21,7 @@ package org.onap.policy.controlloop.common.rules.test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.Collections; import java.util.List; @@ -36,7 +36,7 @@ import lombok.Getter; import lombok.Setter; import org.apache.commons.collections.MapUtils; import org.awaitility.Awaitility; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.onap.policy.appc.Request; import org.onap.policy.appclcm.AppcLcmDmaapWrapper; import org.onap.policy.common.utils.coder.Coder; diff --git a/controlloop/common/rules-test/src/main/java/org/onap/policy/controlloop/common/rules/test/NamedRunner.java b/controlloop/common/rules-test/src/main/java/org/onap/policy/controlloop/common/rules/test/NamedRunner.java index 5642f35fd..4a974878e 100644 --- a/controlloop/common/rules-test/src/main/java/org/onap/policy/controlloop/common/rules/test/NamedRunner.java +++ b/controlloop/common/rules-test/src/main/java/org/onap/policy/controlloop/common/rules/test/NamedRunner.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,36 +21,29 @@ package org.onap.policy.controlloop.common.rules.test; -import org.junit.Ignore; -import org.junit.runner.notification.RunNotifier; -import org.junit.runners.BlockJUnit4ClassRunner; -import org.junit.runners.model.FrameworkMethod; -import org.junit.runners.model.InitializationError; +import org.junit.jupiter.api.extension.ConditionEvaluationResult; +import org.junit.jupiter.api.extension.ExecutionCondition; +import org.junit.jupiter.api.extension.ExtensionContext; /** * Runs tests listed via the {@link TestNames} annotation. */ -public class NamedRunner extends BlockJUnit4ClassRunner { - - /** - * Constructs the object. - */ - public NamedRunner(Class<?> testClass) throws InitializationError { - super(testClass); - } +public class NamedRunner implements ExecutionCondition { @Override - protected void runChild(final FrameworkMethod method, RunNotifier notifier) { - var description = describeChild(method); - - if (method.getAnnotation(Ignore.class) != null) { - notifier.fireTestIgnored(description); - - } else if (!isNamed(description.getTestClass(), method.getName())) { - notifier.fireTestIgnored(description); - + public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext extensionContext) { + var testClass = extensionContext.getTestClass(); + if (testClass.isEmpty()) { + return ConditionEvaluationResult.enabled("Empty"); + } + var method = extensionContext.getDisplayName().replace("()", ""); + if (testClass.get().getSimpleName().equals(method)) { + return ConditionEvaluationResult.enabled("Class"); + } + if (isNamed(testClass.get(), method)) { + return ConditionEvaluationResult.enabled("OK"); } else { - runLeaf(methodBlock(method), description, notifier); + return ConditionEvaluationResult.disabled("Disabled"); } } @@ -61,7 +55,7 @@ public class NamedRunner extends BlockJUnit4ClassRunner { * @return {@code true} if the test is in the list, {@code false} otherwise */ private boolean isNamed(Class<?> testClass, String testName) { - TestNames annot = testClass.getAnnotation(TestNames.class); + var annot = testClass.getAnnotation(TestNames.class); if (annot == null) { // no annotation - everything passes return true; diff --git a/controlloop/common/rules-test/src/main/java/org/onap/policy/controlloop/common/rules/test/Rules.java b/controlloop/common/rules-test/src/main/java/org/onap/policy/controlloop/common/rules/test/Rules.java index 111f00800..8272205d2 100644 --- a/controlloop/common/rules-test/src/main/java/org/onap/policy/controlloop/common/rules/test/Rules.java +++ b/controlloop/common/rules-test/src/main/java/org/onap/policy/controlloop/common/rules/test/Rules.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2020-2022 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,9 +22,9 @@ package org.onap.policy.controlloop.common.rules.test; import static org.awaitility.Awaitility.await; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.File; import java.io.FileNotFoundException; |