Search in sources :

Example 1 with IRule

use of com.qaprosoft.carina.core.foundation.rule.IRule in project carina by qaprosoft.

the class ExpectedSkipManager method collectRules.

/**
 * Collect rules based on tests and its context
 *
 * @param testMethod Method
 * @param context ITestContext
 * @return rules list
 */
private List<Class<? extends IRule>> collectRules(Method testMethod, ITestContext context) {
    List<Class<? extends IRule>> rules = new ArrayList<>();
    // collect rules from current class and method
    ExpectedSkip classSkipAnnotation = testMethod.getDeclaringClass().getAnnotation(ExpectedSkip.class);
    ExpectedSkip methodSkipAnnotation = testMethod.getAnnotation(ExpectedSkip.class);
    rules.addAll(getRulesFromAnnotation(classSkipAnnotation));
    rules.addAll(getRulesFromAnnotation(methodSkipAnnotation));
    // analyze all dependent methods and collect rules
    ITestNGMethod[] methods = context.getAllTestMethods();
    for (ITestNGMethod iTestNGMethod : methods) {
        if (iTestNGMethod.getMethodName().equalsIgnoreCase(testMethod.getName())) {
            String[] methodsDep = iTestNGMethod.getMethodsDependedUpon();
            for (String method : methodsDep) {
                rules.addAll(getDependentMethodsRules(method));
            }
        }
    }
    return rules;
}
Also used : ITestNGMethod(org.testng.ITestNGMethod) ArrayList(java.util.ArrayList) IRule(com.qaprosoft.carina.core.foundation.rule.IRule)

Example 2 with IRule

use of com.qaprosoft.carina.core.foundation.rule.IRule in project carina by zebrunner.

the class ExpectedSkipManager method getDependentMethodsRules.

/**
 * Get rules from dependent methods and their classes
 *
 * @param methodName String
 * @return rules list
 */
private List<Class<? extends IRule>> getDependentMethodsRules(String methodName) {
    int indexDot = methodName.lastIndexOf(".");
    String clazz = methodName.substring(0, indexDot);
    String shortName = methodName.substring(indexDot + 1);
    List<Class<? extends IRule>> rules = new ArrayList<>();
    try {
        LOGGER.debug("Extracted class name: ".concat(clazz));
        Class<?> testClass = Class.forName(clazz);
        // this class
        if (testClass.isAnnotationPresent(ExpectedSkip.class)) {
            LOGGER.debug("Class is annotated with @ExpectedSkip: ".concat(clazz));
            rules.addAll(Arrays.asList(testClass.getAnnotation(ExpectedSkip.class).rules()));
        }
        Method[] methods = testClass.getDeclaredMethods();
        // verify if dependent method is marked as expected skip
        for (Method method : methods) {
            if (shortName.equalsIgnoreCase(method.getName()) && method.isAnnotationPresent(ExpectedSkip.class)) {
                LOGGER.debug("Method is annotated with @ExpectedSkip: ".concat(methodName));
                rules.addAll(Arrays.asList(method.getAnnotation(ExpectedSkip.class).rules()));
            }
        }
    } catch (ClassNotFoundException e) {
        LOGGER.error("Error during class initialization: ".concat(e.getMessage()));
    }
    return rules;
}
Also used : ArrayList(java.util.ArrayList) ITestNGMethod(org.testng.ITestNGMethod) Method(java.lang.reflect.Method) IRule(com.qaprosoft.carina.core.foundation.rule.IRule)

Example 3 with IRule

use of com.qaprosoft.carina.core.foundation.rule.IRule in project carina by zebrunner.

the class ExpectedSkipManager method collectRules.

/**
 * Collect rules based on tests and its context
 *
 * @param testMethod Method
 * @param context ITestContext
 * @return rules list
 */
private List<Class<? extends IRule>> collectRules(Method testMethod, ITestContext context) {
    List<Class<? extends IRule>> rules = new ArrayList<>();
    // collect rules from current class and method
    ExpectedSkip classSkipAnnotation = testMethod.getDeclaringClass().getAnnotation(ExpectedSkip.class);
    ExpectedSkip methodSkipAnnotation = testMethod.getAnnotation(ExpectedSkip.class);
    rules.addAll(getRulesFromAnnotation(classSkipAnnotation));
    rules.addAll(getRulesFromAnnotation(methodSkipAnnotation));
    // analyze all dependent methods and collect rules
    ITestNGMethod[] methods = context.getAllTestMethods();
    for (ITestNGMethod iTestNGMethod : methods) {
        if (iTestNGMethod.getMethodName().equalsIgnoreCase(testMethod.getName())) {
            String[] methodsDep = iTestNGMethod.getMethodsDependedUpon();
            for (String method : methodsDep) {
                rules.addAll(getDependentMethodsRules(method));
            }
        }
    }
    return rules;
}
Also used : ITestNGMethod(org.testng.ITestNGMethod) ArrayList(java.util.ArrayList) IRule(com.qaprosoft.carina.core.foundation.rule.IRule)

Example 4 with IRule

use of com.qaprosoft.carina.core.foundation.rule.IRule in project carina by qaprosoft.

the class ExpectedSkipManager method getDependentMethodsRules.

/**
 * Get rules from dependent methods and their classes
 *
 * @param methodName String
 * @return rules list
 */
private List<Class<? extends IRule>> getDependentMethodsRules(String methodName) {
    int indexDot = methodName.lastIndexOf(".");
    String clazz = methodName.substring(0, indexDot);
    String shortName = methodName.substring(indexDot + 1);
    List<Class<? extends IRule>> rules = new ArrayList<>();
    try {
        LOGGER.debug("Extracted class name: ".concat(clazz));
        Class<?> testClass = Class.forName(clazz);
        // this class
        if (testClass.isAnnotationPresent(ExpectedSkip.class)) {
            LOGGER.debug("Class is annotated with @ExpectedSkip: ".concat(clazz));
            rules.addAll(Arrays.asList(testClass.getAnnotation(ExpectedSkip.class).rules()));
        }
        Method[] methods = testClass.getDeclaredMethods();
        // verify if dependent method is marked as expected skip
        for (Method method : methods) {
            if (shortName.equalsIgnoreCase(method.getName()) && method.isAnnotationPresent(ExpectedSkip.class)) {
                LOGGER.debug("Method is annotated with @ExpectedSkip: ".concat(methodName));
                rules.addAll(Arrays.asList(method.getAnnotation(ExpectedSkip.class).rules()));
            }
        }
    } catch (ClassNotFoundException e) {
        LOGGER.error("Error during class initialization: ".concat(e.getMessage()));
    }
    return rules;
}
Also used : ArrayList(java.util.ArrayList) ITestNGMethod(org.testng.ITestNGMethod) Method(java.lang.reflect.Method) IRule(com.qaprosoft.carina.core.foundation.rule.IRule)

Aggregations

IRule (com.qaprosoft.carina.core.foundation.rule.IRule)4 ArrayList (java.util.ArrayList)4 ITestNGMethod (org.testng.ITestNGMethod)4 Method (java.lang.reflect.Method)2