try{
GroovyClassLoader gcl = new GroovyClassLoader(TestUtil.class.getClassLoader());
Class testClass = gcl.parseClass(script, "__GenRESTTestCase__");
TestSuite suite = new GroovyTestSuite();
final RoRequestBean roRequest = new RoRequestBean(request);
final RoResponseBean roResponse = new RoResponseBean(response);
Method[] m_arr = testClass.getDeclaredMethods();
for(int i=0; i<m_arr.length; i++){
/*
Test for following:
* 1. Modifier should be public
* 2. Method should not be abstract
* 3. Return type should be void
* 4. Method name should start with `test'
* 5. Method should not expect any parameter
*/
int modifiers = m_arr[i].getModifiers();
Class retType = m_arr[i].getReturnType();
String methName = m_arr[i].getName();
Class[] p_arr = m_arr[i].getParameterTypes();
if(!Modifier.isPublic(modifiers) ||
Modifier.isAbstract(modifiers) ||
!retType.equals(Void.TYPE) ||
!methName.startsWith("test") ||
p_arr.length != 0){
continue;
}
RESTTestCase test = (RESTTestCase)GroovyTestSuite.createTest(testClass, methName);
test.setRoRequestBean(roRequest);
test.setRoResponseBean(roResponse);
suite.addTest(test);
}
return suite;
}
catch(CompilationFailedException ex){
throw new TestException("", ex);