1 7 package com.inversoft.junit.internal; 8 9 10 import java.lang.reflect.InvocationTargetException ; 11 import java.lang.reflect.Method ; 12 13 import com.inversoft.junit.Request; 14 import com.inversoft.junit.Response; 15 import com.inversoft.junit.WebTestCase; 16 17 18 26 public class ClientCaller { 27 28 31 public static final String BEGIN_METHOD_PREFIX = "begin"; 32 33 36 public static final String END_METHOD_PREFIX = "end"; 37 38 39 47 public void callBeginMethod(WebTestCase testCase, Request request) 48 throws Throwable { 49 50 String baseName = 52 testCase.getName().substring(Constants.TEST_METHOD_PREFIX.length()); 53 String beginName = BEGIN_METHOD_PREFIX + baseName; 54 55 try { 56 Class klass = testCase.getClass(); 57 Method method = klass.getMethod(beginName, new Class [] {Request.class}); 58 59 method.invoke(testCase, new Object [] {request}); 60 } catch (InvocationTargetException ite) { 61 ite.fillInStackTrace(); 62 throw ite.getTargetException(); 63 } catch (IllegalAccessException e) { 64 e.fillInStackTrace(); 65 throw e; 66 } catch (NoSuchMethodException nsme) { 67 return; 69 } 70 } 71 72 80 public void callEndMethod(WebTestCase testCase, Response response) 81 throws Throwable { 82 83 String baseName = 85 testCase.getName().substring(Constants.TEST_METHOD_PREFIX.length()); 86 String endName = END_METHOD_PREFIX + baseName; 87 88 try { 89 Class klass = testCase.getClass(); 90 Method method = klass.getMethod(endName, new Class [] {Response.class}); 91 92 method.invoke(testCase, new Object [] {response}); 93 } catch (InvocationTargetException ite) { 94 ite.fillInStackTrace(); 95 throw ite.getTargetException(); 96 } catch (IllegalAccessException e) { 97 e.fillInStackTrace(); 98 throw e; 99 } catch (NoSuchMethodException nsme) { 100 return; 102 } 103 } 104 } 105 | Popular Tags |