API helper
public class ApiHelper
{
private ApiHelper(){ }
private static ApiHelper apiHelper;
public static ApiHelper getInstance()
{
if(apiHelper==null){
apiHelper=new ApiHelper();
}
return apiHelper;
}
public ArrayList getMethodSignature(String classPath) throws ApiTestException { try
{
StringBuffer methodSignature=new StringBuffer("");
ArrayList methodList = new ArrayList();
Class inputClass = Class.forName(classPath);
//Method methArr []= inputClass.getDeclaredMethods();
Method methArr []= inputClass.getMethods();
boolean isCompattible=true;
for (int i=0;i
isCompattible=true;
methodSignature.append(methArr[i].getName()+"(");
Class methodArgs[]= methArr[i].getParameterTypes();
for (int k = 0; k
if (methodArgs[k].isPrimitive() argName.endsWith(".Long") argName.endsWith(".Integer") argName.endsWith(".Float") argName.endsWith(".Double") argName.endsWith(".Boolean") argName.endsWith(".String") argName.endsWith(".Timestamp") argName.endsWith(".Date")){
if (methodArgs[k].isPrimitive()){
log4Debug.debug("----------- data type is Primitive -------------");
if (k==(methodArgs.length-1))
methodSignature.append(methodArgs[k].getName());
else
methodSignature.append(methodArgs[k].getName()+",");
}
else
{
log4Debug.debug("----------- data type is not primitive -------------");
String argType = methodArgs[k].getName();
int lastIndex = argType.lastIndexOf(".");
if (k==(methodArgs.length-1))
methodSignature.append(argType.subSequence(lastIndex+1,argType.length()));
else
methodSignature.append(argType.subSequence(lastIndex+1,argType.length())+",");
}
}
else{ log4Debug.debug("----------- method is not compattible -------------");
i sCompattible = false;
}
}
if (!isCompattible){
methodSignature = new StringBuffer("non-compattitable");
} else{
methodSignature.append(")");
}
log4Debug.debug("----------- method signature is : ",methodSignature);
methodList.add(i,methodSignature.toString());
}
return methodList;
}
catch(ClassNotFoundException classNotFoundException){
log4Debug.debug(" =====class not found =======",classNotFoundException); throw new ApiTestException("Class not found "+ classNotFoundException.getMessage()); } } public String getReturnType(int methodPosition,String classPath) throws ApiTestException { Method selectedMethod = null; try { Class inputClass = Class.forName(classPath); Method methArr [] = inputClass.getMethods(); selectedMethod = methArr[methodPosition]; } catch(ClassNotFoundException classNotFoundException){ log4Debug.debug(" =====class not found =======",classNotFoundException); throw new ApiTestException(classNotFoundException.getMessage()); } return selectedMethod.getReturnType().toString(); } public int getNoOfArguments(int methodPosition,String classPath) throws ApiTestException { Method selectedMethod = null; try { Class inputClass = Class.forName(classPath); Method methArr [] = inputClass.getMethods(); selectedMethod = methArr[methodPosition]; log4Debug.debug("===selected method name ========",selectedMethod.getName()); } catch(ClassNotFoundException classNotFoundException){ log4Debug.debug(" =====class not found =======",classNotFoundException); throw new ApiTestException(classNotFoundException.getMessage()); } return selectedMethod.getParameterTypes().length; } public String[] getParameterName(String methodName){ CommonProperties commonProperties = CommonPropertiesFactory.getInstance().getCommonProperties("AperturaCT"); String paramName = commonProperties.getProperty(methodName); String param[]=null; if(paramName!=null){ param=paramName.split(","); } return param; } public Object[] convertArguments(int methodPosition,String arguments,String classPath) throws ApiTestException{
try { Class inputClass = Class.forName(classPath); Method methArr []= inputClass.getMethods(); Method selectedMethod = methArr[methodPosition]; log4Debug.debug("return type is : ",selectedMethod.getReturnType()); String args[] = arguments.split("\\^"); log4Debug.debug("=======argument length=======",String.valueOf(args.length)); Class methodArgs[]= selectedMethod.getParameterTypes(); Object objArr[]=new Object[methodArgs.length]; for (int k = 0; k
No comments:
Post a Comment