KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > aop > override > GenAdvisorOverrideTestCase


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.override;
23
24 import junit.framework.Test;
25 import junit.framework.TestSuite;
26
27 /**
28  * These tests only work with generated advisors, and not old skool weaving
29  * @author <a HREF="kabir.khan@jboss.com">Kabir Khan</a>
30  * @version $Revision: 46033 $
31  */

32 public class GenAdvisorOverrideTestCase extends OverrideTestCase
33 {
34    //Have the same bindings as SubPOJO and SubSubPOJO, but override the methods to see that we get the
35
//same behaviour for bindings applied to inherited methods
36
SubPOJOOverrideAll subControl = new SubPOJOOverrideAll();
37    SubSubPOJOOverrideAll subSubControl = new SubSubPOJOOverrideAll();
38
39    public GenAdvisorOverrideTestCase(String JavaDoc name)
40    {
41       super(name);
42    }
43
44    public static Test suite()
45    {
46       TestSuite suite = new TestSuite("OverrideTestCase");
47       suite.addTestSuite(GenAdvisorOverrideTestCase.class);
48       return suite;
49    }
50
51    /**
52     * Sub class overriding metadata for inherited method.
53     *
54     * While the metadata gets populated the same, this does not work with traditional weaving since the
55     * class advisor is a static field within each advised class, and the method wrappers use that directly.
56     * So even though SubPOJO's advisor has the correct metadata in the advisor, the wrapper lives in POJO
57     * (since SubPOJO is inheriting the method) and will use POJO's advisor.
58     */

59    public void testSubSuperOnlyMetadata() throws Exception JavaDoc
60    {
61       System.out.println("TEST SUB SUPERONLY METADATA");
62       MetadataInterceptor.metadata = null;
63       subPojo.superOnly();
64
65       assertEquals("subpojo.superOnly", MetadataInterceptor.metadata);
66    }
67
68    public void testSubSubSuperOnlyMetadata() throws Exception JavaDoc
69    {
70       System.out.println("TEST SUB SUB SUPERONLY METADATA");
71       MetadataInterceptor.metadata = null;
72       subSubPojo.superOnly();
73
74       assertEquals("subsubpojo.superOnly", MetadataInterceptor.metadata);
75    }
76
77    /**
78     * Sub class adding to chain for inherited method.
79     *
80     * For generated advisors, each advisor has a reference to its MethodInfo structures and those of its superadvisors,
81     * so when inheriting a method we still populate the MethodInfo for that via initialising the super class of the advisor
82     * (i.e the advisor for the super class). These advisors get passed in to the adviors when populating the chains so even if that
83     * JoinPoint field cannot be found in the SubPOJO advisor declared fields, the chains still get set properly since the advisor is
84     * responsible for passing them in.
85     *
86     * In traditional weaving we only have a static field for a JoinPointInfo per advised class, so when Advisor.resolveMethodPointcut()
87     * tries to set the field it does not exist there.
88     */

89    public void testSubSuperOnlyChain() throws Exception JavaDoc
90    {
91       System.out.println("TEST SUB SUPERONLY CHAIN");
92       
93       CountingInterceptor.reset();
94       CountingAspect.reset();
95       subControl.superOnly();
96
97       assertEquals(1, CountingInterceptor.interceptions);
98       assertEquals(1, CountingAspect.interceptions);
99
100       //Test the inherited methods
101
CountingInterceptor.reset();
102       CountingAspect.reset();
103       subPojo.superOnly();
104
105       assertEquals(1, CountingInterceptor.interceptions);
106       assertEquals(1, CountingAspect.interceptions);
107
108    }
109
110    public void testSubSubSuperOnlyChain() throws Exception JavaDoc
111    {
112       System.out.println("TEST SUB SUB SUPERONLY CHAIN");
113       CountingInterceptor.reset();
114       CountingAspect.reset();
115       subSubControl.superOnly();
116
117       assertEquals(2, CountingInterceptor.interceptions);
118       assertEquals(2, CountingAspect.interceptions);
119
120       //Test the inherited methods
121
CountingInterceptor.reset();
122       CountingAspect.reset();
123       subSubPojo.superOnly();
124
125       assertEquals(2, CountingInterceptor.interceptions);
126       assertEquals(2, CountingAspect.interceptions);
127
128    }}
129
Popular Tags