Tuesday, February 5, 2008

Woke Up Late Today

Suffering from reading lots of material about dynamic class loading and interfaces, so instead of taking 682, I am taking 600 - looks like everyone is in the late mood today since the train arrived late at Tustin too.

[write what the boyos have done]

Gluing the KWDT class and the code that Freeman and Latisha have written ... and in the end I decided not to use dynamic class loading.

This is the basic of KWDT [link to the implementation of kwdt].

In nutshell, to handle pressing of button object.
String AUT = "app";
String objtype = "button";
...
Class c = Class.forName("com.fnis.application."+AUT+".object."+objtype);
button uiObj = (button) c.newInstance("login");
uiObj.press();
But, a problem arises since the code needs to handle the object based on the type of action:
String action = "validateenabled";
...
if (action.eq("press")) {
uiObj.press();
}
else if (action.eq("validateenabled")) {
uiObj.validateenabled();
}
else {
// action not handled yet
throw ...
}
It is apparent that the code needs to have a lot of "if .. else ..." statements to cover each action, and to minimize the branch statement, I settled for Reflection. It cuts the "if ... else ..." statements down to nothing.
import java.lang.reflect.*;

String AUT = "app";
String objtype = "button";
String action = "validateenabled";

Class c = Class.forName("lib.applications."+AUT+".object."+objtype.toLowerCase());
Constructor ct = c.getConstructor();

Object arglist[] = new Object[6];
arglist[0] = window;
arglist[1] = objName;
arglist[2] = data;
arglist[3] = expectedResult;
arglist[4] = timeout;

Object obj = ct.newInstance(arglist);
Method m =c.getDeclaredMethod(action);
Hopefully, using Reflection won't kill the performance of the test code.

No comments: