KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > aop > stress > simple > SimpleReflectToJavassistTestCase


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.stress.simple;
23
24 import java.lang.reflect.Field JavaDoc;
25 import java.lang.reflect.Method JavaDoc;
26
27 import org.jboss.aop.util.ReflectToJavassist;
28 import org.jboss.test.aop.stress.Scenario;
29 import org.jboss.test.aop.stress.ScenarioTest;
30
31 /**
32  * Primarily to make sure I got everything right for the generated advisors
33  * @author <a HREF="kabir.khan@jboss.com">Kabir Khan</a>
34  * @version $Revision: 57349 $
35  */

36 public class SimpleReflectToJavassistTestCase extends ScenarioTest
37 {
38    
39    public static void main(String JavaDoc[] args)
40    {
41       junit.textui.TestRunner.run(SimpleReflectToJavassistTestCase.class);
42    }
43
44    
45    public SimpleReflectToJavassistTestCase(String JavaDoc name) throws Exception JavaDoc
46    {
47       super(name);
48    }
49
50    public void testException() throws Exception JavaDoc
51    {
52       boolean exception = false;
53       try
54       {
55          super.runner.executeScenario(new ExceptionScenario());
56       }
57       catch (Exception JavaDoc e)
58       {
59          exception = true;
60       }
61       
62       assertTrue(exception);
63    }
64    
65    public void testAnnotationsUnderStress() throws Exception JavaDoc
66    {
67       Scenario[] scenarios = new Scenario[] {
68         new SimpleClassToJavassistScenario(),
69         new SimpleFieldToJavassistScenario(),
70         new SimpleMethodToJavassistScenario()};
71       
72       super.runner.executeScenarios(scenarios);
73    }
74
75    private class ExceptionScenario implements Scenario
76    {
77       public void execute(int thread, int loop) throws Exception JavaDoc
78       {
79          if (thread == 0 && loop == 1)
80          {
81             System.out.println("Throwing exception!!!!");
82             throw new Exception JavaDoc("Thrown Exception");
83          }
84       }
85       
86    }
87    private class SimpleClassToJavassistScenario implements Scenario
88    {
89       public void execute(int thread, int loop) throws Exception JavaDoc
90       {
91          Class JavaDoc pojo = LargePojo.class;
92          ReflectToJavassist.classToJavassist(pojo);
93       }
94    }
95
96    private class SimpleMethodToJavassistScenario implements Scenario
97    {
98       public void execute(int thread, int loop) throws Exception JavaDoc
99       {
100          Class JavaDoc pojo = LargePojo.class;
101          Method JavaDoc m = pojo.getMethod("method", new Class JavaDoc[0]);
102          ReflectToJavassist.methodToJavassist(m);
103       }
104    }
105
106    private class SimpleFieldToJavassistScenario implements Scenario
107    {
108       public void execute(int thread, int loop) throws Exception JavaDoc
109       {
110          Class JavaDoc pojo = LargePojo.class;
111          Field JavaDoc f = pojo.getField("field");
112          ReflectToJavassist.fieldToJavassist(f);
113       }
114    }
115 }
116
Popular Tags