KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > aop > callerargs > CallerArgsTestCase


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.aop.callerargs;
23
24 import org.jboss.test.aop.AOPTestWithSetup;
25
26 /**
27  *
28  * @author <a HREF="kabir.khan@jboss.com">Kabir Khan</a>
29  * @version $Revision$
30  */

31 public class CallerArgsTestCase extends AOPTestWithSetup
32 {
33    public CallerArgsTestCase(String JavaDoc name)
34    {
35       super(name);
36    }
37
38    public static void main(String JavaDoc[] args)
39    {
40       junit.textui.TestRunner.run(CallerArgsTestCase.class);
41    }
42
43    public void testExecutionAdvisedClass() throws Exception JavaDoc
44    {
45       System.out.println("TESTING EXECUTION ADVISED");
46       ExecutionInterceptor.intercepted = false;
47       AdvisedPOJO.voidStaticNoArgsMethod();
48       if (!ExecutionInterceptor.intercepted) throw new RuntimeException JavaDoc("Did not intercept");
49       if (ExecutionInterceptor.argsLength != 0) throw new RuntimeException JavaDoc("Args length should have been 0");
50       
51       ExecutionInterceptor.intercepted = false;
52       int ret = AdvisedPOJO.intStaticArgsMethod(3);
53       if (ret != 6) throw new RuntimeException JavaDoc("Expected 6 as return value");
54       if (!ExecutionInterceptor.intercepted) throw new RuntimeException JavaDoc("Did not intercept");
55       if (ExecutionInterceptor.argsLength != 1) throw new RuntimeException JavaDoc("Args length should have been 1");
56       if (((Integer JavaDoc)ExecutionInterceptor.args[0]).intValue() != 3) throw new RuntimeException JavaDoc("Args[0] should have been 3");
57       
58       ExecutionInterceptor.intercepted = false;
59       AdvisedPOJO pojo = new AdvisedPOJO();
60       if (!ExecutionInterceptor.intercepted) throw new RuntimeException JavaDoc("Did not intercept");
61       if (ExecutionInterceptor.argsLength != 0) throw new RuntimeException JavaDoc("Args length should have been 0");
62       
63       ExecutionInterceptor.intercepted = false;
64       pojo.voidNoArgsMethod();
65       if (!ExecutionInterceptor.intercepted) throw new RuntimeException JavaDoc("Did not intercept");
66       if (ExecutionInterceptor.argsLength != 0) throw new RuntimeException JavaDoc("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 JavaDoc("Did not intercept");
71       if(pojo2.i != 10) throw new RuntimeException JavaDoc("Expected pojo.i to be 10");
72       if(pojo2.j != 100) throw new RuntimeException JavaDoc("Expected pojo.i to be 100");
73       if (ExecutionInterceptor.argsLength != 2) throw new RuntimeException JavaDoc("Args length should have been 2");
74       if (((Integer JavaDoc)ExecutionInterceptor.args[0]).intValue() != 10) throw new RuntimeException JavaDoc("Args[0] should have been 10");
75       if (((Integer JavaDoc)ExecutionInterceptor.args[1]).intValue() != 100) throw new RuntimeException JavaDoc("Args[1] should have been 100");
76       
77       ExecutionInterceptor.intercepted = false;
78       ret = pojo2.intArgsMethod(20, 100);
79       if (!ExecutionInterceptor.intercepted) throw new RuntimeException JavaDoc("Did not intercept");
80       if (ret != 2000)throw new RuntimeException JavaDoc("Expected 2000 as return value");
81       if (((Integer JavaDoc)ExecutionInterceptor.args[0]).intValue() != 20) throw new RuntimeException JavaDoc("Args[0] should have been 20");
82       if (((Integer JavaDoc)ExecutionInterceptor.args[1]).intValue() != 100) throw new RuntimeException JavaDoc("Args[1] should have been 100");
83    }
84    
85    public void testCallerCallingNotAdvisedClass() throws Exception JavaDoc
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 JavaDoc
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 JavaDoc
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