1 22 package org.jboss.test.aop.callerargs; 23 24 import org.jboss.test.aop.AOPTestWithSetup; 25 26 31 public class CallerArgsTestCase extends AOPTestWithSetup 32 { 33 public CallerArgsTestCase(String name) 34 { 35 super(name); 36 } 37 38 public static void main(String [] args) 39 { 40 junit.textui.TestRunner.run(CallerArgsTestCase.class); 41 } 42 43 public void testExecutionAdvisedClass() throws Exception 44 { 45 System.out.println("TESTING EXECUTION ADVISED"); 46 ExecutionInterceptor.intercepted = false; 47 AdvisedPOJO.voidStaticNoArgsMethod(); 48 if (!ExecutionInterceptor.intercepted) throw new RuntimeException ("Did not intercept"); 49 if (ExecutionInterceptor.argsLength != 0) throw new RuntimeException ("Args length should have been 0"); 50 51 ExecutionInterceptor.intercepted = false; 52 int ret = AdvisedPOJO.intStaticArgsMethod(3); 53 if (ret != 6) throw new RuntimeException ("Expected 6 as return value"); 54 if (!ExecutionInterceptor.intercepted) throw new RuntimeException ("Did not intercept"); 55 if (ExecutionInterceptor.argsLength != 1) throw new RuntimeException ("Args length should have been 1"); 56 if (((Integer )ExecutionInterceptor.args[0]).intValue() != 3) throw new RuntimeException ("Args[0] should have been 3"); 57 58 ExecutionInterceptor.intercepted = false; 59 AdvisedPOJO pojo = new AdvisedPOJO(); 60 if (!ExecutionInterceptor.intercepted) throw new RuntimeException ("Did not intercept"); 61 if (ExecutionInterceptor.argsLength != 0) throw new RuntimeException ("Args length should have been 0"); 62 63 ExecutionInterceptor.intercepted = false; 64 pojo.voidNoArgsMethod(); 65 if (!ExecutionInterceptor.intercepted) throw new RuntimeException ("Did not intercept"); 66 if (ExecutionInterceptor.argsLength != 0) throw new RuntimeException ("Args length should have been 0"); 67 68 ExecutionInterceptor.intercepted = false; 69 AdvisedPOJO pojo2 = new AdvisedPOJO(10, 100); 70 if (!ExecutionInterceptor.intercepted) throw new RuntimeException ("Did not intercept"); 71 if(pojo2.i != 10) throw new RuntimeException ("Expected pojo.i to be 10"); 72 if(pojo2.j != 100) throw new RuntimeException ("Expected pojo.i to be 100"); 73 if (ExecutionInterceptor.argsLength != 2) throw new RuntimeException ("Args length should have been 2"); 74 if (((Integer )ExecutionInterceptor.args[0]).intValue() != 10) throw new RuntimeException ("Args[0] should have been 10"); 75 if (((Integer )ExecutionInterceptor.args[1]).intValue() != 100) throw new RuntimeException ("Args[1] should have been 100"); 76 77 ExecutionInterceptor.intercepted = false; 78 ret = pojo2.intArgsMethod(20, 100); 79 if (!ExecutionInterceptor.intercepted) throw new RuntimeException ("Did not intercept"); 80 if (ret != 2000)throw new RuntimeException ("Expected 2000 as return value"); 81 if (((Integer )ExecutionInterceptor.args[0]).intValue() != 20) throw new RuntimeException ("Args[0] should have been 20"); 82 if (((Integer )ExecutionInterceptor.args[1]).intValue() != 100) throw new RuntimeException ("Args[1] should have been 100"); 83 } 84 85 public void testCallerCallingNotAdvisedClass() throws Exception 86 { 87 System.out.println("TESTING CALLING NOT ADVISED"); 88 NotAdvisedPOJOCaller caller = new NotAdvisedPOJOCaller(); 89 caller.method(); 90 NotAdvisedPOJOCaller.staticMethod(); 91 } 92 93 public void testCallerCallingAdvisedClass() throws Exception 94 { 95 System.out.println("TESTING CALLING ADVISED"); 96 AdvisedPOJOCaller caller = new AdvisedPOJOCaller(); 97 caller.method(); 98 AdvisedPOJOCaller.staticMethod(); 99 } 100 101 public void testPreparedCaller() throws Exception 102 { 103 System.out.println("TESTING CALLING PREPARED"); 104 PreparedPOJOCaller caller = new PreparedPOJOCaller(); 105 caller.method(); 106 PreparedPOJOCaller.staticMethod(); 107 } 108 109 } 110 | Popular Tags |