1 package test.utils.bytecode; 2 3 import junit.framework.TestCase; 4 import junit.framework.Test; 5 import junit.framework.TestSuite; 6 7 import java.io.IOException ; 8 import java.lang.reflect.Method ; 9 import java.lang.reflect.Constructor ; 10 11 import org.apache.axis.utils.bytecode.ChainedParamReader; 12 13 20 public class TestChainedParamReader extends TestCase{ 21 private TestDerivedClass test =null; 22 private ChainedParamReader reader; 23 public TestChainedParamReader(String name) { 24 super(name); 25 } 26 public static Test suite() { 27 return new TestSuite(TestChainedParamReader.class); 28 } 29 30 protected void setup() { 31 test = this.new TestDerivedClass(1); 32 } 33 34 public void testGetMethodParameters(){ 35 try { 36 reader = new ChainedParamReader(TestDerivedClass.class); 37 } catch (IOException e) { 38 fail("failed to setup paramreader:" + e.getMessage()); 39 } 40 assertTrue("should not be null", reader != null); 41 try { 43 Method method1 = TestDerivedClass.class.getMethod("method1", new Class [] {Boolean.TYPE}); 44 String [] params = reader.getParameterNames(method1); 45 assertTrue("one parameter only",params.length == 1); 46 assertTrue("It is 'boolValue'", params[0].equals("boolValue")); 47 48 Method method2 = TestDerivedClass.class.getMethod("method2", new Class [] {Boolean.TYPE}); 49 params = reader.getParameterNames(method2); 50 assertTrue("one parameter only",params.length == 1); 51 assertTrue("It is 'boolValue'", params[0].equals("boolValue")); 52 method2= TestDerivedClass.class.getMethod("method2", new Class [] {Integer.TYPE}); 53 params = reader.getParameterNames(method2); 54 assertTrue("one parameter only",params.length == 1); 55 assertTrue("It is 'intValue'", params[0].equals("intValue")); 56 57 } catch (NoSuchMethodException e) { 58 fail(e.toString()); 59 } catch (SecurityException e) { 60 fail(e.toString()); 61 } 62 63 } 64 65 public void testGetConstructorParameters() { 66 try { 67 reader = new ChainedParamReader(TestDerivedClass.class); 68 assertTrue("should not be null", reader != null); 69 Constructor ctor = TestDerivedClass.class.getConstructor(new Class [] { 70 TestChainedParamReader.class, Integer.TYPE}); 71 72 String [] params = reader.getParameterNames(ctor); 73 assertTrue("params is not null" , params.length == 2); 74 assertTrue("param name is 'in'", params[1].equals("in")); 75 } 76 catch (IOException e) { 77 fail("failed to setup paramreader:" + e.getMessage()); 78 } 79 catch (NoSuchMethodException e) { 80 fail(e.getMessage()); 81 } 82 83 } 84 85 public void testGetInheritedMethodParameters() { 86 try { 87 reader = new ChainedParamReader(TestDerivedClass.class); 88 Method method3 = TestDerivedClass.class.getMethod("subClassInherit", new Class [] {Integer.TYPE}); 89 String [] params = reader.getParameterNames(method3); 90 assertTrue("It should find inherited method", params != null); 91 } catch (IOException e) { 92 fail("failed to setup paramreader:" + e.getMessage()); 93 } catch (NoSuchMethodException e) { 94 fail(e.toString()); 95 } 96 } 97 98 class TestBaseClass { 99 public void subClassInherit(int intValue) { 100 } 101 } 102 class TestDerivedClass extends TestBaseClass{ 103 public TestDerivedClass() { 104 } 105 public TestDerivedClass(int in) { 106 } 107 public void method1(boolean boolValue) { 108 } 109 public void method2(int intValue) { 110 } 111 public void method2(boolean boolValue) { 112 } 113 } 114 } 115 116 | Popular Tags |