KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > aop > scopedextender > BaseLoadedTester


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.scopedextender;
23
24 import org.jboss.aop.Advised;
25
26 /**
27  *
28  * @author <a HREF="kabir.khan@jboss.com">Kabir Khan</a>
29  * @version $Revision: 1.1 $
30  */

31 public class BaseLoadedTester implements BaseLoadedTesterMBean
32 {
33    public void testLoaders() throws Exception JavaDoc
34    {
35       System.out.println("=============== BaseLoadedTester - LOADERS ================");
36       ClassLoader JavaDoc mine = this.getClass().getClassLoader();
37       ClassLoader JavaDoc base = Base_Base.class.getClassLoader();
38       
39       if (mine != base)
40       {
41          throw new RuntimeException JavaDoc("ClassLoaders for me and Base_Base should be the same. Mine=" + mine + "; Base_Base=" + base);
42       }
43    }
44
45    public void testMethod() throws Exception JavaDoc
46    {
47       TestUtil testUtil = new TestUtil();
48       try
49       {
50          System.out.println("=============== BaseLoadedTester - METHOD ================");
51          Base_Base base = new Base_Base();
52          
53          clear();
54          base.base();
55          String JavaDoc m = "Base_Base.base";
56          testUtil.compare(m, "BaseAspect", new String JavaDoc[]{"base"}, BaseAspect.invoked);
57          
58          clear();
59          base.overridden();
60          m = "Base_Base.overridden";
61          testUtil.compare(m, "BaseAspect", new String JavaDoc[] {"overridden"}, BaseAspect.invoked);
62          
63          Base_A1 a1 = new Base_A1();
64
65          clear();
66          a1.a1();
67          m = "Base_A1.a1";
68          testUtil.compare(m, "BaseAspect", new String JavaDoc[]{"a1", "base"}, BaseAspect.invoked);
69          
70          clear();
71          a1.overridden();
72          m = "Base_A1.overridden";
73          testUtil.compare(m, "BaseAspect", new String JavaDoc[] {"overridden"}, BaseAspect.invoked);
74          
75       }
76       catch (RuntimeException JavaDoc e)
77       {
78          // AutoGenerated
79
throw new RuntimeException JavaDoc(e);
80       }
81       
82       if (testUtil.getErrors() != null)
83       {
84          throw new RuntimeException JavaDoc(testUtil.getErrors());
85       }
86       
87       if(Advised.class.isAssignableFrom(BaseNotBaseWoven.class))
88       {
89          throw new RuntimeException JavaDoc("BaseNotBaseWoven should not be woven");
90       }
91    }
92
93    public void testConstructor() throws Exception JavaDoc
94    {
95       TestUtil testUtil = new TestUtil();
96       try
97       {
98          System.out.println("=============== BaseLoadedTester - CTOR ================");
99          
100          clear();
101          Base_Base base = new Base_Base();
102          testUtil.compare(base.getClass().getName(), "BaseAspect", new String JavaDoc[]{base.getClass().getName()}, BaseAspect.invoked);
103          
104          clear();
105          Base_A1 a1 = new Base_A1();
106          testUtil.compare(a1.getClass().getName(), "BaseAspect", new String JavaDoc[]{a1.getClass().getName()}, BaseAspect.invoked);
107       }
108       catch (RuntimeException JavaDoc e)
109       {
110          // AutoGenerated
111
throw new RuntimeException JavaDoc(e);
112       }
113       if (testUtil.getErrors() != null)
114       {
115          throw new RuntimeException JavaDoc(testUtil.getErrors());
116       }
117       if(Advised.class.isAssignableFrom(BaseNotBaseWoven.class))
118       {
119          throw new RuntimeException JavaDoc("BaseNotBaseWoven should not be woven");
120       }
121    }
122
123    public void testField() throws Exception JavaDoc
124    {
125       TestUtil testUtil = new TestUtil();
126       try
127       {
128          System.out.println("=============== BaseLoadedTester - FIELD ================");
129          Base_Base base = new Base_Base();
130          
131          clear();
132          base.base = 5;
133          String JavaDoc m = "Base_Base.base";
134          testUtil.compare(m, "BaseAspect", new String JavaDoc[]{"base"}, BaseAspect.invoked);
135          
136          clear();
137          testUtil.compare(5, base.base);
138          testUtil.compare(m, "BaseAspect", new String JavaDoc[]{"base"}, BaseAspect.invoked);
139          
140          
141          Base_A1 a1 = new Base_A1();
142
143          clear();
144          a1.a1 = 10;
145          m = "Base_A1.a1";
146          testUtil.compare(m, "BaseAspect", new String JavaDoc[]{"a1"}, BaseAspect.invoked);
147
148          clear();
149          testUtil.compare(10, a1.a1);
150          testUtil.compare(m, "BaseAspect", new String JavaDoc[]{"a1"}, BaseAspect.invoked);
151       }
152       catch (RuntimeException JavaDoc e)
153       {
154          // AutoGenerated
155
throw new RuntimeException JavaDoc(e);
156       }
157
158       if (testUtil.getErrors() != null)
159       {
160          throw new RuntimeException JavaDoc(testUtil.getErrors());
161       }
162
163       if(Advised.class.isAssignableFrom(BaseNotBaseWoven.class))
164       {
165          throw new RuntimeException JavaDoc("BaseNotBaseWoven should not be woven");
166       }
167    }
168
169
170    public void testOverriddenInterceptors() throws Exception JavaDoc
171    {
172       //Not really a test per se, the real test is in the ScopedChildNoParentDelegationTester, when deployed along with this base loaded sar
173
System.out.println("=============== BaseLoadedTester - TEST OVERRIDDEN INTERCEPTORS ================");
174       TestUtil testUtil = new TestUtil();
175       
176       Base_Base base = new Base_Base();
177       
178       clear();
179       base.differentScopes();
180       String JavaDoc m = "differentScopes";
181       testUtil.compare(m, "BaseAspect", new String JavaDoc[]{"differentScopes"}, BaseAspect.invoked);
182       testUtil.invoked(BasePerClassInterceptor.class);
183       testUtil.invoked(BasePerInstanceInterceptor.class);
184       testUtil.invoked(BasePerJoinPointInterceptor.class);
185       testUtil.invoked(BasePerClassJoinPointInterceptor.class);
186       
187       if (testUtil.getErrors() != null)
188       {
189          throw new RuntimeException JavaDoc(testUtil.getErrors());
190       }
191    }
192
193    public String JavaDoc readName()
194    {
195       return "BaseLoadedTester";
196    }
197
198    private void clear()
199    {
200       BaseAspect.invoked.clear();
201       BasePerClassInterceptor.invoked = false;
202       BasePerInstanceInterceptor.invoked = false;
203       BasePerJoinPointInterceptor.invoked = false;
204       BasePerClassJoinPointInterceptor.invoked = false;
205    }
206 }
207
Popular Tags