类org.testng.IMethodInstance源码实例Demo

下面列出了怎么用org.testng.IMethodInstance的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: TencentKona-8   文件: TestReorderInterceptor.java
@Override
public List<IMethodInstance> intercept(final List<IMethodInstance> methods, final ITestContext context) {
    Collections.sort(methods, new Comparator<IMethodInstance>() {
        @Override
        public int compare(final IMethodInstance mi1, final IMethodInstance mi2) {
            // get test instances to order the tests.
            final Object o1 = mi1.getInstance();
            final Object o2 = mi2.getInstance();
            if (o1 instanceof ITest && o2 instanceof ITest) {
                return ((ITest)o1).getTestName().compareTo(((ITest)o2).getTestName());
            }
            // something else, don't care about the order
            return 0;
        }
    });

    return methods;
}
 
源代码2 项目: jdk8u60   文件: TestReorderInterceptor.java
@Override
public List<IMethodInstance> intercept(final List<IMethodInstance> methods, final ITestContext context) {
    Collections.sort(methods, new Comparator<IMethodInstance>() {
        @Override
        public int compare(final IMethodInstance mi1, final IMethodInstance mi2) {
            // get test instances to order the tests.
            final Object o1 = mi1.getInstance();
            final Object o2 = mi2.getInstance();
            if (o1 instanceof ITest && o2 instanceof ITest) {
                return ((ITest)o1).getTestName().compareTo(((ITest)o2).getTestName());
            }
            // something else, don't care about the order
            return 0;
        }
    });

    return methods;
}
 
源代码3 项目: openjdk-jdk8u   文件: TestReorderInterceptor.java
@Override
public List<IMethodInstance> intercept(final List<IMethodInstance> methods, final ITestContext context) {
    Collections.sort(methods, new Comparator<IMethodInstance>() {
        @Override
        public int compare(final IMethodInstance mi1, final IMethodInstance mi2) {
            // get test instances to order the tests.
            final Object o1 = mi1.getInstance();
            final Object o2 = mi2.getInstance();
            if (o1 instanceof ITest && o2 instanceof ITest) {
                return ((ITest)o1).getTestName().compareTo(((ITest)o2).getTestName());
            }
            // something else, don't care about the order
            return 0;
        }
    });

    return methods;
}
 
源代码4 项目: Selenium-Foundation   文件: PlatformInterceptor.java
/**
 * Assemble a list of methods that support the current target platform
 *
 * @param methods list of methods that are about the be run
 * @param context test context
 */
@Override
public List<IMethodInstance> intercept(List<IMethodInstance> methods, ITestContext context) {
    List<IMethodInstance> result = new ArrayList<>();
    String contextPlatform = getContextPlatform(context);

    // iterate over method list
    for (IMethodInstance thisMethod : methods) {
        Object platformConstant = resolveTargetPlatform(thisMethod);
        
        // if this method supports the current target platform
        if (TargetPlatformHandler.shouldRun(contextPlatform, (PlatformEnum) platformConstant)) {
            addMethodForPlatform(result, thisMethod, (PlatformEnum) platformConstant);
        }
    }

    if (result.isEmpty()) {
        logger.warn("No tests were found for context platform '{}'", contextPlatform);
    }

    // indicate intercept has been invoked
    context.setAttribute(INTERCEPT, Boolean.TRUE);
    return result;
}
 
@Override
public List<IMethodInstance> intercept(final List<IMethodInstance> methods, final ITestContext context) {
    Collections.sort(methods, new Comparator<IMethodInstance>() {
        @Override
        public int compare(final IMethodInstance mi1, final IMethodInstance mi2) {
            // get test instances to order the tests.
            final Object o1 = mi1.getInstance();
            final Object o2 = mi2.getInstance();
            if (o1 instanceof ITest && o2 instanceof ITest) {
                return ((ITest)o1).getTestName().compareTo(((ITest)o2).getTestName());
            }
            // something else, don't care about the order
            return 0;
        }
    });

    return methods;
}
 
源代码6 项目: openjdk-jdk9   文件: TestReorderInterceptor.java
@Override
public List<IMethodInstance> intercept(final List<IMethodInstance> methods, final ITestContext context) {
    Collections.sort(methods, new Comparator<IMethodInstance>() {
        @Override
        public int compare(final IMethodInstance mi1, final IMethodInstance mi2) {
            // get test instances to order the tests.
            final Object o1 = mi1.getInstance();
            final Object o2 = mi2.getInstance();
            if (o1 instanceof ITest && o2 instanceof ITest) {
                return ((ITest)o1).getTestName().compareTo(((ITest)o2).getTestName());
            }
            // something else, don't care about the order
            return 0;
        }
    });

    return methods;
}
 
源代码7 项目: functional-tests-core   文件: ExecutionOrder.java
@Override
public java.util.List<IMethodInstance> intercept(java.util.List<IMethodInstance> list, ITestContext iTestContext) {
    Comparator<IMethodInstance> comparator = new Comparator<IMethodInstance>() {
        private int getPriority(IMethodInstance mi) {
            int result = 0;
            int methodIndex = Integer.parseInt(mi.getMethod().getMethodName().replaceAll("\\D+", ""));
            return methodIndex;
        }

        public int compare(IMethodInstance m1, IMethodInstance m2) {
            return getPriority(m1) - getPriority(m2);
        }
    };

    IMethodInstance[] array = list.toArray(new IMethodInstance[list.size()]);
    Arrays.sort(array, comparator);
    return Arrays.asList(array);
}
 
源代码8 项目: hottub   文件: TestReorderInterceptor.java
@Override
public List<IMethodInstance> intercept(final List<IMethodInstance> methods, final ITestContext context) {
    Collections.sort(methods, new Comparator<IMethodInstance>() {
        @Override
        public int compare(final IMethodInstance mi1, final IMethodInstance mi2) {
            // get test instances to order the tests.
            final Object o1 = mi1.getInstance();
            final Object o2 = mi2.getInstance();
            if (o1 instanceof ITest && o2 instanceof ITest) {
                return ((ITest)o1).getTestName().compareTo(((ITest)o2).getTestName());
            }
            // something else, don't care about the order
            return 0;
        }
    });

    return methods;
}
 
源代码9 项目: openjdk-8-source   文件: TestReorderInterceptor.java
@Override
public List<IMethodInstance> intercept(List<IMethodInstance> methods, ITestContext context) {
    Collections.sort(methods, new Comparator<IMethodInstance>() {
        @Override
        public int compare(final IMethodInstance mi1, final IMethodInstance mi2) {
            // get test instances to order the tests.
            final Object o1 = mi1.getInstance();
            final Object o2 = mi2.getInstance();
            if (o1 instanceof ITest && o2 instanceof ITest) {
                return ((ITest)o1).getTestName().compareTo(((ITest)o2).getTestName());
            } else {
                // something else, don't care about the order
                return 0;
            }
        }
    });

    return methods;
}
 
源代码10 项目: openjdk-8   文件: TestReorderInterceptor.java
@Override
public List<IMethodInstance> intercept(List<IMethodInstance> methods, ITestContext context) {
    Collections.sort(methods, new Comparator<IMethodInstance>() {
        @Override
        public int compare(final IMethodInstance mi1, final IMethodInstance mi2) {
            // get test instances to order the tests.
            final Object o1 = mi1.getInstance();
            final Object o2 = mi2.getInstance();
            if (o1 instanceof ITest && o2 instanceof ITest) {
                return ((ITest)o1).getTestName().compareTo(((ITest)o2).getTestName());
            } else {
                // something else, don't care about the order
                return 0;
            }
        }
    });

    return methods;
}
 
源代码11 项目: qaf   文件: MethodPriorityComparator.java
private Integer getGroupOrder(IMethodInstance o) {
	if (orderedGroups == null) {
		return 0;
	}
	String groupName = (o.getMethod().getGroups() != null) && (o.getMethod().getGroups().length > 0)
			? o.getMethod().getGroups()[0] : "NONE";
	if (!orderedGroups.contains("NONE")) {
		orderedGroups = orderedGroups + ", NONE";
	}
	if (!orderedGroups.contains(groupName)) {
		orderedGroups = orderedGroups + "," + groupName;
	}

	log.debug(o.getMethod().getMethodName() + " Group: " + groupName + " Order : " + orderedGroups);

	return Integer.valueOf(orderedGroups.toUpperCase().indexOf(groupName.toUpperCase()));
}
 
源代码12 项目: jdk8u_nashorn   文件: TestReorderInterceptor.java
@Override
public List<IMethodInstance> intercept(final List<IMethodInstance> methods, final ITestContext context) {
    Collections.sort(methods, new Comparator<IMethodInstance>() {
        @Override
        public int compare(final IMethodInstance mi1, final IMethodInstance mi2) {
            // get test instances to order the tests.
            final Object o1 = mi1.getInstance();
            final Object o2 = mi2.getInstance();
            if (o1 instanceof ITest && o2 instanceof ITest) {
                return ((ITest)o1).getTestName().compareTo(((ITest)o2).getTestName());
            }
            // something else, don't care about the order
            return 0;
        }
    });

    return methods;
}
 
源代码13 项目: cloudstack   文件: TestNGAop.java
@Override
public List<IMethodInstance> intercept(List<IMethodInstance> methods, ITestContext context) {
    for (IMethodInstance methodIns : methods) {
        ITestNGMethod method = methodIns.getMethod();
        ConstructorOrMethod meth = method.getConstructorOrMethod();
        Method m = meth.getMethod();
        if (m != null) {
            DB db = m.getAnnotation(DB.class);
            if (db != null) {
                TransactionLegacy txn = TransactionLegacy.open(m.getName());
            }
        }
    }

    // TODO Auto-generated method stub
    return methods;
}
 
源代码14 项目: Selenium-Foundation   文件: PlatformInterceptor.java
/**
 * Add the specified method to the method list
 *
 * @param methodList list of methods that are about to be run
 * @param testMethod method to be added to the list
 * @param  platformConstant target platform on which to run this method
 */
@SuppressWarnings("unchecked")
private static <P extends Enum<?> & PlatformEnum> void addMethodForPlatform(List<IMethodInstance> methodList, IMethodInstance testMethod, PlatformEnum platformConstant) {
    if (platformConstant != null) {
        ITestNGMethod method = testMethod.getMethod();
        PlatformIdentity<P> identity = new PlatformIdentity<>((P) platformConstant, method.getDescription());
        testMethod.getMethod().setDescription(DataUtils.toString(identity));
    }
    methodList.add(testMethod);
}
 
@Override
public void onAfterClass(ITestClass iTestClass, IMethodInstance iMethodInstance) {

    MockInitialContextFactory.destroy();
    MicroserviceServer microserviceServer = microserviceServerMap.get(iMethodInstance.getInstance());
    if (microserviceServer != null) {
        microserviceServer.stop();
        microserviceServer.destroy();
        microserviceServerMap.remove(iMethodInstance.getInstance());
    }
}
 
源代码16 项目: qaf   文件: MethodPriorityComparator.java
private int getClassOrder(IMethodInstance mi) {
	int result = -1;
	Class<?> cls = mi.getMethod().getConstructorOrMethod().getMethod().getDeclaringClass();
	Priority classPriority = cls.getAnnotation(Priority.class);
	if (classPriority != null) {
		result = classPriority.value();
	}

	return result;
}
 
源代码17 项目: qaf   文件: MethodPriorityComparator.java
private int getMethodOrder(IMethodInstance mi) {
	int result = -1;
	Method method = mi.getMethod().getConstructorOrMethod().getMethod();
	Priority a1 = method.getAnnotation(Priority.class);

	if (a1 != null) {
		result = a1.value();
	}
	return result;
}
 
源代码18 项目: qaf   文件: QAFTestNGListener.java
public List<IMethodInstance> intercept(List<IMethodInstance> lst,
		ITestContext context) {
	logger.debug("Method Order interceptor called");
	String order = context.getCurrentXmlTest().getParameter("groupOrder");
	MethodPriorityComparator comparator = new MethodPriorityComparator(order);
	Collections.sort(lst, comparator);
	return lst;
}
 
源代码19 项目: teammates   文件: PriorityInterceptor.java
private static int getMethodPriority(IMethodInstance mi) {
    Method method = getMethod(mi);
    Priority a1 = method.getAnnotation(Priority.class);
    if (a1 != null) {
        return a1.value();
    }
    return 0;
}
 
源代码20 项目: teammates   文件: PriorityInterceptor.java
private static int getClassPriority(IMethodInstance mi) {
    Class<?> cls = getDeclaringClassOfMethod(mi);
    Priority classPriority = cls.getAnnotation(Priority.class);
    if (classPriority != null) {
        return classPriority.value();
    }
    return 0;
}
 
源代码21 项目: cloudbreak   文件: PriorityMethodInterceptor.java
public List<IMethodInstance> intercept(List<IMethodInstance> methods, ITestContext context) {
    Comparator<IMethodInstance> comparator = new Comparator<IMethodInstance>() {
        private int getPriority(IMethodInstance mi) {
            int result = 0;
            Method method = mi.getMethod().getConstructorOrMethod().getMethod();
            Priority a1 = method.getAnnotation(Priority.class);
            if (a1 != null) {
                result = a1.value();
            } else {
                Class<?> cls = method.getDeclaringClass();
                Priority classPriority = cls.getAnnotation(Priority.class);
                if (classPriority != null) {
                    result = classPriority.value();
                }
            }
            return result;
        }

        public int compare(IMethodInstance m1, IMethodInstance m2) {
            return getPriority(m1) - getPriority(m2);
        }
    };

    IMethodInstance[] array = methods.toArray(new IMethodInstance[methods.size()]);
    Arrays.sort(array, comparator);
    Arrays.stream(array).forEach(method -> LOGGER.info("###test priority: "
            + method.getMethod().getMethodName()));
    return Arrays.asList(array);
}
 
@Test
public void runAllTckTests() throws Throwable {
    TestNG testng = new TestNG();

    ObjectFactoryImpl delegate = new ObjectFactoryImpl();
    testng.setObjectFactory((IObjectFactory) (constructor, params) -> {
        if (constructor.getDeclaringClass().equals(ReactiveStreamsCdiTck.class)) {
            return tck;
        }
        else {
            return delegate.newInstance(constructor, params);
        }
    });

    testng.setUseDefaultListeners(false);
    ResultListener resultListener = new ResultListener();
    testng.addListener((ITestNGListener) resultListener);
    testng.setTestClasses(new Class[]{ ReactiveStreamsCdiTck.class });
    testng.setMethodInterceptor(new IMethodInterceptor() {
        @Override
        public List<IMethodInstance> intercept(List<IMethodInstance> methods, ITestContext context) {
            methods.sort(Comparator.comparing(m -> m.getInstance().getClass().getName()));
            return methods;
        }
    });
    testng.run();
    int total = resultListener.success.get() + resultListener.failed.get() + resultListener.skipped.get();
    System.out.println(String.format("Ran %d tests, %d passed, %d failed, %d skipped.", total, resultListener.success.get(),
        resultListener.failed.get(), resultListener.skipped.get()));
    System.out.println("Failed tests:");
    resultListener.failures.forEach(result -> {
        System.out.println(result.getInstance().getClass().getName() + "." + result.getMethod().getMethodName());
    });
    if (resultListener.failed.get() > 0) {
        if (resultListener.lastFailure.get() != null) {
            throw resultListener.lastFailure.get();
        }
        else {
            throw new Exception("Tests failed with no exception");
        }
    }
}
 
源代码23 项目: qaf   文件: MethodPriorityComparator.java
@Override
public int compare(IMethodInstance o1, IMethodInstance o2) {
	log.debug(o1.getMethod().getMethodName() + " O2: " + o2.getMethod().getMethodName() + " Order : "
			+ orderedGroups);
	String method1Name = o1.getMethod().getMethodName();
	String method2Name = o2.getMethod().getMethodName();
	Set<String> depends, o1Set, o2Set, o1Dependency, o2Dependency;

	// check method dependency
	o1Dependency = new HashSet<String>(Arrays.asList(o1.getMethod().getMethodsDependedUpon()));
	o2Dependency = new HashSet<String>(Arrays.asList(o1.getMethod().getMethodsDependedUpon()));
	if (o1Dependency.contains(method2Name)) {
		return -1;
	}
	if (o2Dependency.contains(method1Name)) {
		return 1;
	}
	// check group dependency
	o1Set = new HashSet<String>(Arrays.asList(o1.getMethod().getGroups()));
	o2Set = new HashSet<String>(Arrays.asList(o1.getMethod().getGroups()));
	o1Dependency = new HashSet<String>(Arrays.asList(o1.getMethod().getGroupsDependedUpon()));
	o2Dependency = new HashSet<String>(Arrays.asList(o1.getMethod().getGroupsDependedUpon()));

	depends = new HashSet<String>(o1Dependency);
	depends.retainAll(o2Set);
	if (!depends.isEmpty()) {
		return -1;
	}
	depends = new HashSet<String>(o2Dependency);
	depends.retainAll(o1Set);
	if (!depends.isEmpty()) {
		return 1;
	}
	int o1Priority = getGroupOrder(o1);
	int o2Priority = getGroupOrder(o2);
	if (o1Priority == o2Priority) {
		o1Priority = getClassOrder(o1);
		o2Priority = getClassOrder(o2);
		if (o1Priority == o2Priority) {
			o1Priority = getMethodOrder(o1);
			o2Priority = getMethodOrder(o2);
		}
	}
	if (o1Priority == -1) {
		o1Priority = o2Priority + 1;
	}
	if (o2Priority == -1) {
		o2Priority = o1Priority + 1;
	}
	return o1Priority - o2Priority;

}
 
源代码24 项目: teammates   文件: PriorityInterceptor.java
private static Method getMethod(IMethodInstance mi) {
    return mi.getMethod().getConstructorOrMethod().getMethod();
}
 
源代码25 项目: teammates   文件: PriorityInterceptor.java
private static Class<?> getDeclaringClassOfMethod(IMethodInstance mi) {
    return mi.getMethod().getRealClass();
}
 
源代码26 项目: teammates   文件: PriorityInterceptor.java
private static String getPackageName(IMethodInstance mi) {
    return getDeclaringClassOfMethod(mi).getPackage().getName();
}
 
源代码27 项目: teammates   文件: PriorityInterceptor.java
private static String getClassName(IMethodInstance mi) {
    return getDeclaringClassOfMethod(mi).getName();
}
 
源代码28 项目: teammates   文件: PriorityInterceptor.java
@Override
public List<IMethodInstance> intercept(List<IMethodInstance> methods, ITestContext context) {
    methods.sort(COMPARATOR);
    return methods;
}
 
源代码29 项目: Selenium-Foundation   文件: PlatformInterceptor.java
/**
 * Resolve the target platform for the associated method.
 * 
 * @param testMethod test method object
 * @return target platform constant; 'null' if test class object is not {@link PlatformTargetable}
 */
private static <P extends Enum<?> & PlatformEnum> P resolveTargetPlatform(IMethodInstance testMethod) {
    Object testObject = testMethod.getInstance();
    TargetPlatform targetPlatform = getTargetPlatform(testMethod);
    return TargetPlatformHandler.resolveTargetPlatform(testObject, targetPlatform);
}
 
源代码30 项目: Selenium-Foundation   文件: PlatformInterceptor.java
/**
 * Get the target platform annotation for the specified method
 *
 * @param testMethod method for which annotation is to be retrieved
 * @return {@link TargetPlatform} annotation; 'null' if absent
 */
private static TargetPlatform getTargetPlatform(IMethodInstance testMethod) {
    Method realMethod = testMethod.getMethod().getConstructorOrMethod().getMethod();
    return realMethod.getAnnotation(TargetPlatform.class);
}
 
 类所在包
 类方法
 同包方法