diff options
author | Sonsino, Ofir (os0695) <os0695@intl.att.com> | 2018-08-12 14:51:28 +0300 |
---|---|---|
committer | Sonsino, Ofir (os0695) <os0695@intl.att.com> | 2018-08-12 15:02:57 +0300 |
commit | 4a4dcc5185f8ba5a28c7f9fef509f32c0c2389e6 (patch) | |
tree | 23e55ee7e1ad9b91bcc3ef1dbe1fb7b183f8b2b6 /vid-automation/src/main/java/vid/automation/test/infra/FeatureTogglingTestngTransformer.java | |
parent | 661a24fd57de02869a9771761e0fcba7eb77d121 (diff) |
vid-automation selenium tests
Change-Id: I6c1b0a0cf3bbfa4314c81f0cc72507db805ec632
Issue-ID: VID-281
Signed-off-by: Sonsino, Ofir (os0695) <os0695@intl.att.com>
Diffstat (limited to 'vid-automation/src/main/java/vid/automation/test/infra/FeatureTogglingTestngTransformer.java')
-rw-r--r-- | vid-automation/src/main/java/vid/automation/test/infra/FeatureTogglingTestngTransformer.java | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/vid-automation/src/main/java/vid/automation/test/infra/FeatureTogglingTestngTransformer.java b/vid-automation/src/main/java/vid/automation/test/infra/FeatureTogglingTestngTransformer.java new file mode 100644 index 000000000..46794da10 --- /dev/null +++ b/vid-automation/src/main/java/vid/automation/test/infra/FeatureTogglingTestngTransformer.java @@ -0,0 +1,76 @@ +package vid.automation.test.infra; + +import org.testng.IAnnotationTransformer; +import org.testng.annotations.ITestAnnotation; +import org.togglz.core.context.StaticFeatureManagerProvider; + +import java.lang.reflect.AnnotatedElement; +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; + +/* +In order to skip test classes regards the state of feature flag we add this listener to our testng configuration +There are 2 ways to annotate that tests required featureFlags to be active : +In method level - with @FeatureTogglingTest on the test method and list of Required Feature flags on +In Class level - with @FeatureTogglingTest on the test class and list of Required Feature flags on +For each test annotation of method level, we check if the test shall whole class shall run regards the features flag test. +Pay attention that this listener shall be configured in the testng.xml (or command line) +It can't be used as Listener annotation of base class +*/ +public class FeatureTogglingTestngTransformer implements IAnnotationTransformer { + + @Override + public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) { + + if (testMethod!=null) { + try { + + if (!annotation.getEnabled()) { + return; + } + + if (isIgnoreTest(testMethod)) { + disableTest(annotation, testMethod.getDeclaringClass().getName()); + return; + } + + if (isIgnoreTest(testMethod.getDeclaringClass())) { + disableTest(annotation, testMethod.getDeclaringClass().getName()); + return; + } + + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + private boolean isIgnoreTest(AnnotatedElement annotatedElement) { + + return (annotatedElement.isAnnotationPresent(FeatureTogglingTest.class) && + shallDisableTest(annotatedElement.getAnnotation(FeatureTogglingTest.class))); + + } + + private boolean shallDisableTest(FeatureTogglingTest featureTogglingTest) { + if (featureTogglingTest.value().length==0) { + return false; + } + if (new StaticFeatureManagerProvider().getFeatureManager()==null) { + FeaturesTogglingConfiguration.initializeFeatureManager(); + } + for (Features feature : featureTogglingTest.value()) { + if (!(feature.isActive()==featureTogglingTest.flagActive())) { + return true; + } + } + return false; + } + + private void disableTest(ITestAnnotation annotation, String name) { + System.out.println("Ignore "+ name+" due to feature flags configuration"); + annotation.setEnabled(false); + } + +} + |