use of com.axway.ats.core.reflect.MethodFinder in project ats-framework by Axway.
the class Test_MethodFinder method findMethodConstructorMethodListNegative.
@Test(expected = NoSuchMethodException.class)
public void findMethodConstructorMethodListNegative() throws NoSuchMethodException, AmbiguousMethodException {
MethodFinder methodFinder = new MethodFinder("methods", Arrays.asList(FileInputStream.class.getDeclaredMethods()));
//one argument
methodFinder.findMethod(new Class<?>[] { Integer.class, Integer.class, Integer.class });
}
use of com.axway.ats.core.reflect.MethodFinder in project ats-framework by Axway.
the class UiDriver method getCustomDriver.
/**
* This method allows you to load your own driver implementation which you can use as any other UI Engine driver
* @param driverClassName the full class name of the custom driver class
* @param parameterTypes the parameters that the constructor requires
* @param constructorArguments the arguments, which will be passed to the constructor
* @return new UiDriver instance
*/
@PublicAtsApi
public static UiDriver getCustomDriver(String driverClassName, Class<?>[] parameterTypes, Object[] constructorArguments) throws Exception {
UiDriver driver = null;
try {
Class<?> clss = Class.forName(driverClassName);
Constructor<?> constructor = new MethodFinder(clss).findConstructor(parameterTypes);
driver = (UiDriver) constructor.newInstance(constructorArguments);
} catch (Exception e) {
throw new Exception("Error while loading custom driver '" + driverClassName + "'", e);
}
return driver;
}
use of com.axway.ats.core.reflect.MethodFinder in project ats-framework by Axway.
the class ActionMethodContainer method add.
/**
* Add a new action method
*
* @param actionMethod the action method to add
* @return
* @throws ActionAlreadyDefinedException if the new action has the exact same arguments of an existing one
*/
public boolean add(ActionMethod actionMethod) throws ActionAlreadyDefinedException {
// if there is at least one method check for ambiguity
if (actionMethods.size() > 0) {
Class<?>[] newMethodParamTypes = actionMethod.getMethod().getParameterTypes();
//find the action method implementation based on the arguments
MethodFinder methodFinder = new MethodFinder("methods for action " + actionName, getMethods(), customComparisonRules);
//get the most specific method which accepts these parameters
try {
Method mostSpecificMethod = methodFinder.findMethod(newMethodParamTypes);
//then we have ambiguity, which should not be allowed
if (Arrays.equals(newMethodParamTypes, mostSpecificMethod.getParameterTypes())) {
throw new ActionAlreadyDefinedException(actionName, componentName, mostSpecificMethod);
}
} catch (NoSuchMethodException e) {
//method which accepts there argument does not exist, we can safely add it
} catch (AmbiguousMethodException e) {
//unless they are exactly the same, which we don't allow to happen
throw new RuntimeException("AmbiguousMethodException caught while searching for action methods");
}
}
//add the action method
return actionMethods.add(actionMethod);
}
use of com.axway.ats.core.reflect.MethodFinder in project ats-framework by Axway.
the class Test_MethodFinder method findMethodConstructorMethodListNegativeAmbigous.
@Test(expected = AmbiguousMethodException.class)
public void findMethodConstructorMethodListNegativeAmbigous() throws NoSuchMethodException, AmbiguousMethodException {
MethodFinder methodFinder = new MethodFinder("ambiguous", Arrays.asList(MethodFinderTester.class.getDeclaredMethods()));
//no arguments
methodFinder.findMethod("ambiguousMethod", new Class<?>[] { Void.TYPE });
}
use of com.axway.ats.core.reflect.MethodFinder in project ats-framework by Axway.
the class Test_MethodFinder method findMethodWithNamePositive.
@Test
public void findMethodWithNamePositive() throws NoSuchMethodException, AmbiguousMethodException {
MethodFinder methodFinder = new MethodFinder(FileInputStream.class);
//null argument
assertNotNull(methodFinder.findMethod("close", null));
//one argument
assertNotNull(methodFinder.findMethod("read", new Class<?>[] { (new byte[] {}).getClass() }));
//several arguments
assertNotNull(methodFinder.findMethod("read", new Class<?>[] { (new byte[] {}).getClass(), Integer.TYPE, Integer.TYPE }));
//unboxing
assertNotNull(methodFinder.findMethod("read", new Class<?>[] { (new byte[] {}).getClass(), Integer.class, Integer.class }));
//widening conversion
assertNotNull(methodFinder.findMethod("read", new Class<?>[] { (new byte[] {}).getClass(), Byte.class, Short.TYPE }));
}
Aggregations