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;
}
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;
}
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;
}
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;
}
Aggregations