Search in sources :

Example 1 with IMethodInstance

use of org.testng.IMethodInstance in project cloudstack by apache.

the class TestNGAop method intercept.

@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;
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) ITestNGMethod(org.testng.ITestNGMethod) IMethodInstance(org.testng.IMethodInstance) ITestNGMethod(org.testng.ITestNGMethod) Method(java.lang.reflect.Method) ConstructorOrMethod(org.testng.internal.ConstructorOrMethod) DB(com.cloud.utils.db.DB) ConstructorOrMethod(org.testng.internal.ConstructorOrMethod)

Example 2 with IMethodInstance

use of org.testng.IMethodInstance in project midpoint by Evolveum.

the class AlphabeticalMethodInterceptor method intercept.

@Override
public List<IMethodInstance> intercept(List<IMethodInstance> methods, ITestContext context) {
    List<Object> instanceList = Lists.newArrayList();
    Map<Object, List<IMethodInstance>> map = Maps.newHashMap();
    for (IMethodInstance mi : methods) {
        Object instance = mi.getInstance();
        if (!instanceList.contains(instance)) {
            instanceList.add(instance);
        }
        List<IMethodInstance> l = map.get(instance);
        if (l == null) {
            l = Lists.newArrayList();
            map.put(instance, l);
        }
        l.add(mi);
    }
    Comparator<IMethodInstance> comparator = new Comparator<IMethodInstance>() {

        @Override
        public int compare(IMethodInstance o1, IMethodInstance o2) {
            return o1.getMethod().getMethodName().compareTo(o2.getMethod().getMethodName());
        }
    };
    List<IMethodInstance> result = Lists.newArrayList();
    for (Object instance : instanceList) {
        List<IMethodInstance> methodlist = map.get(instance);
        IMethodInstance[] array = methodlist.toArray(new IMethodInstance[methodlist.size()]);
        Arrays.sort(array, comparator);
        result.addAll(Arrays.asList(array));
    }
    System.out.println("AlphabeticalMethodInterceptor: " + result);
    return result;
}
Also used : List(java.util.List) IMethodInstance(org.testng.IMethodInstance) Comparator(java.util.Comparator)

Aggregations

IMethodInstance (org.testng.IMethodInstance)2 DB (com.cloud.utils.db.DB)1 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)1 Method (java.lang.reflect.Method)1 Comparator (java.util.Comparator)1 List (java.util.List)1 ITestNGMethod (org.testng.ITestNGMethod)1 ConstructorOrMethod (org.testng.internal.ConstructorOrMethod)1