KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > aop > invoketarget > InvokeTargetTestCase


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.invoketarget;
23
24 import org.jboss.test.aop.AOPTestWithSetup;
25
26 import junit.framework.Test;
27 import junit.framework.TestSuite;
28 import junit.textui.TestRunner;
29
30 /**
31  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
32  * @version $Revision: 46058 $
33  */

34 public class InvokeTargetTestCase extends AOPTestWithSetup
35 {
36
37    public static void main(String JavaDoc[] args)
38    {
39       TestRunner.run(suite());
40    }
41
42    public static Test suite()
43    {
44       TestSuite suite = new TestSuite("ProxyTester");
45       suite.addTestSuite(InvokeTargetTestCase.class);
46       return suite;
47    }
48
49    public InvokeTargetTestCase(String JavaDoc name)
50    {
51       super(name);
52    }
53    
54    public void testExecution() throws Exception JavaDoc
55    {
56       BypassInterceptor.invocations = 0;
57       CountingInterceptor.invocations = 0;
58       POJO pojo = new POJO("Test");
59       assertEquals("Test", pojo.plain); //not advised
60

61       //2 invocations for both of these since we have constructor and construction advices
62
assertEquals(2, BypassInterceptor.invocations);
63       assertEquals(2, CountingInterceptor.invocations);
64       
65       BypassInterceptor.invocations = 0;
66       CountingInterceptor.invocations = 0;
67       pojo.i = 5;
68       assertEquals(1, BypassInterceptor.invocations);
69       assertEquals(1, CountingInterceptor.invocations);
70
71       BypassInterceptor.invocations = 0;
72       CountingInterceptor.invocations = 0;
73       int i = pojo.i;
74       assertEquals(5, i);
75       assertEquals(1, BypassInterceptor.invocations);
76       assertEquals(1, CountingInterceptor.invocations);
77       
78       BypassInterceptor.invocations = 0;
79       CountingInterceptor.invocations = 0;
80       pojo.s = "Blah";
81       assertEquals(1, BypassInterceptor.invocations);
82       assertEquals(1, CountingInterceptor.invocations);
83
84       BypassInterceptor.invocations = 0;
85       CountingInterceptor.invocations = 0;
86       String JavaDoc str = pojo.s;
87       assertEquals("Blah", str);
88       assertEquals(1, BypassInterceptor.invocations);
89       assertEquals(1, CountingInterceptor.invocations);
90       
91       BypassInterceptor.invocations = 0;
92       CountingInterceptor.invocations = 0;
93       pojo.test();
94       assertEquals(1, BypassInterceptor.invocations);
95       assertEquals(1, CountingInterceptor.invocations);
96       
97       BypassInterceptor.invocations = 0;
98       CountingInterceptor.invocations = 0;
99       String JavaDoc s = pojo.echo("Hello");
100       assertEquals("Hello", s);
101       assertEquals(1, BypassInterceptor.invocations);
102       assertEquals(1, CountingInterceptor.invocations);
103       
104       BypassInterceptor.invocations = 0;
105       CountingInterceptor.invocations = 0;
106       i = pojo.echo(100);
107       assertEquals(100, i);
108       assertEquals(1, BypassInterceptor.invocations);
109       assertEquals(1, CountingInterceptor.invocations);
110    }
111    
112    public void testConstructorCaller()
113    {
114       CallingPOJO pojo = new CallingPOJO();
115    }
116    
117    public void testStaticMethodCaller()
118    {
119       CallingPOJO.testStatic();
120    }
121    
122    public void testMethodCaller()
123    {
124       CallingPOJO pojo = new CallingPOJO();
125       pojo.test();
126    }
127 }
128
Popular Tags