KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > aop > precedence > PrecedenceTester


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.precedence;
23
24 import junit.framework.Test;
25 import junit.framework.TestSuite;
26
27 import java.util.ArrayList JavaDoc;
28
29 import org.jboss.test.aop.AOPTestWithSetup;
30
31 /**
32  * Comment
33  *
34  * @author <a HREF="mailto:kabir.khan@jboss.org">Kabir Khan</a>
35  * @version $Revision: 45977 $
36  */

37 public class PrecedenceTester extends AOPTestWithSetup
38 {
39    //Don't list per_instance aspects for constructor
40
final static String JavaDoc[] PRECEDENCE_ALL_CONSTRUCTOR = {
41          "FirstInterceptor",
42             "FirstInterceptor2",
43             "SimpleInterceptor2",
44             "SimpleInterceptor3",
45             "TestAspect.advice",
46             "TestAspect2.advice",
47             "LastAspect.advice",
48             "LastAspect2.advice"};
49
50    final static String JavaDoc[] PRECEDENCE_ALL = {
51          "FirstInterceptor",
52             "FirstInterceptor2",
53             "SimpleInterceptor",
54             "SimpleInterceptor2",
55             "SimpleInterceptor3",
56             "TestAspect.advice",
57             "TestAspect2.advice",
58             "TestAspect3.advice",
59             "LastAspect.advice",
60             "LastAspect2.advice"};
61
62    final static String JavaDoc[] PRECEDENCE_TWO = {
63          "FirstInterceptor",
64             "FirstInterceptor2",
65             "SimpleInterceptor",
66             "TestAspect.advice",
67             "TestAspect.advice2",
68             "TestAspect.advice3",
69             "TestAspect2.advice",
70             "LastAspect.advice",
71             "LastAspect2.advice"};
72
73    final static String JavaDoc[] PRECEDENCE_THREE = {
74          "FirstInterceptor",
75             "FirstInterceptor2",
76             "TestAspect.advice",
77             "TestAspect.advice2",
78             "TestAspect.advice3",
79             "LastAspect.advice",
80             "LastAspect2.advice"};
81
82    public static Test suite()
83    {
84       TestSuite suite = new TestSuite("PrecedenceTester");
85       suite.addTestSuite(PrecedenceTester.class);
86       return suite;
87    }
88
89    public PrecedenceTester(String JavaDoc name)
90    {
91       super(name);
92    }
93
94    public void testPrecedence() throws Exception JavaDoc
95    {
96       System.out.println("*** Invoke constructor");
97       Interceptions.reset();
98       POJO pojo = new POJO();
99       checkInterceptions(PRECEDENCE_ALL_CONSTRUCTOR);
100       
101       System.out.println("*** Invoke field read");
102       Interceptions.reset();
103       int i = pojo.var;
104       checkInterceptions(PRECEDENCE_ALL);
105       
106       System.out.println("*** Invoke field write");
107       Interceptions.reset();
108       pojo.var = i + 1;
109       checkInterceptions(PRECEDENCE_ALL);
110       
111       System.out.println("*** Invoke oneMethod");
112       Interceptions.reset();
113       pojo.oneMethod();
114       checkInterceptions(PRECEDENCE_ALL);
115       
116       Interceptions.reset();
117       pojo.twoMethod();
118       checkInterceptions(PRECEDENCE_TWO);
119
120       Interceptions.reset();
121       pojo.threeMethod();
122       checkInterceptions(PRECEDENCE_THREE);
123    }
124
125    private void checkInterceptions(String JavaDoc[] expected)
126    {
127       ArrayList JavaDoc intercepted = Interceptions.intercepted;
128       assertEquals("Wrong number of interceptions", expected.length ,intercepted.size());
129       
130       for (int i = 0 ; i < expected.length ; i++)
131       {
132          assertEquals("Wrong interception at index " + i, expected[i], (String JavaDoc)intercepted.get(i));
133       }
134    }
135    
136 }
137
Popular Tags