KickJava   Java API By Example, From Geeks To Geeks.

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


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 junit.framework.Assert;
25
26 /**
27  *
28  * @author <a HREF="kabir.khan@jboss.com">Kabir Khan</a>
29  * @version $Revision: 46058 $
30  */

31 public class CallingPOJO
32 {
33    public CallingPOJO()
34    {
35       BypassInterceptor.invocations = 0;
36       CountingInterceptor.invocations = 0;
37       CalledPOJO pojo = new CalledPOJO("Test");
38       Assert.assertEquals("Test", pojo.plain); //not advised
39

40       Assert.assertEquals(1, BypassInterceptor.invocations);
41       Assert.assertEquals(1, CountingInterceptor.invocations);
42       
43       BypassInterceptor.invocations = 0;
44       CountingInterceptor.invocations = 0;
45       pojo.test();
46       Assert.assertEquals(1, BypassInterceptor.invocations);
47       Assert.assertEquals(1, CountingInterceptor.invocations);
48       
49       BypassInterceptor.invocations = 0;
50       CountingInterceptor.invocations = 0;
51       String JavaDoc s = pojo.echo("Hello");
52       Assert.assertEquals("Hello", s);
53       Assert.assertEquals(1, BypassInterceptor.invocations);
54       Assert.assertEquals(1, CountingInterceptor.invocations);
55       
56       BypassInterceptor.invocations = 0;
57       CountingInterceptor.invocations = 0;
58       int i = pojo.echo(100);
59       Assert.assertEquals(100, i);
60       Assert.assertEquals(1, BypassInterceptor.invocations);
61       Assert.assertEquals(1, CountingInterceptor.invocations);
62    }
63
64    public static void testStatic()
65    {
66       BypassInterceptor.invocations = 0;
67       CountingInterceptor.invocations = 0;
68       CalledPOJO pojo = new CalledPOJO("Test");
69       Assert.assertEquals("Test", pojo.plain); //not advised
70

71       Assert.assertEquals(1, BypassInterceptor.invocations);
72       Assert.assertEquals(1, CountingInterceptor.invocations);
73       
74       BypassInterceptor.invocations = 0;
75       CountingInterceptor.invocations = 0;
76       pojo.test();
77       Assert.assertEquals(1, BypassInterceptor.invocations);
78       Assert.assertEquals(1, CountingInterceptor.invocations);
79       
80       BypassInterceptor.invocations = 0;
81       CountingInterceptor.invocations = 0;
82       String JavaDoc s = pojo.echo("Hello");
83       Assert.assertEquals("Hello", s);
84       Assert.assertEquals(1, BypassInterceptor.invocations);
85       Assert.assertEquals(1, CountingInterceptor.invocations);
86       
87       BypassInterceptor.invocations = 0;
88       CountingInterceptor.invocations = 0;
89       int i = pojo.echo(100);
90       Assert.assertEquals(100, i);
91       Assert.assertEquals(1, BypassInterceptor.invocations);
92       Assert.assertEquals(1, CountingInterceptor.invocations);
93    }
94
95    public void test()
96    {
97       BypassInterceptor.invocations = 0;
98       CountingInterceptor.invocations = 0;
99       CalledPOJO pojo = new CalledPOJO("Test");
100       Assert.assertEquals("Test", pojo.plain); //not advised
101

102       Assert.assertEquals(1, BypassInterceptor.invocations);
103       Assert.assertEquals(1, CountingInterceptor.invocations);
104       
105       BypassInterceptor.invocations = 0;
106       CountingInterceptor.invocations = 0;
107       pojo.test();
108       Assert.assertEquals(1, BypassInterceptor.invocations);
109       Assert.assertEquals(1, CountingInterceptor.invocations);
110       
111       BypassInterceptor.invocations = 0;
112       CountingInterceptor.invocations = 0;
113       String JavaDoc s = pojo.echo("Hello");
114       Assert.assertEquals("Hello", s);
115       Assert.assertEquals(1, BypassInterceptor.invocations);
116       Assert.assertEquals(1, CountingInterceptor.invocations);
117       
118       BypassInterceptor.invocations = 0;
119       CountingInterceptor.invocations = 0;
120       int i = pojo.echo(100);
121       Assert.assertEquals(100, i);
122       Assert.assertEquals(1, BypassInterceptor.invocations);
123       Assert.assertEquals(1, CountingInterceptor.invocations);
124    }
125
126 }
127
Popular Tags