1 22 package org.jboss.test.aop.stress.simple; 23 24 import java.lang.reflect.Field ; 25 import java.lang.reflect.Method ; 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 36 public class SimpleReflectToJavassistTestCase extends ScenarioTest 37 { 38 39 public static void main(String [] args) 40 { 41 junit.textui.TestRunner.run(SimpleReflectToJavassistTestCase.class); 42 } 43 44 45 public SimpleReflectToJavassistTestCase(String name) throws Exception 46 { 47 super(name); 48 } 49 50 public void testException() throws Exception 51 { 52 boolean exception = false; 53 try 54 { 55 super.runner.executeScenario(new ExceptionScenario()); 56 } 57 catch (Exception e) 58 { 59 exception = true; 60 } 61 62 assertTrue(exception); 63 } 64 65 public void testAnnotationsUnderStress() throws Exception 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 78 { 79 if (thread == 0 && loop == 1) 80 { 81 System.out.println("Throwing exception!!!!"); 82 throw new Exception ("Thrown Exception"); 83 } 84 } 85 86 } 87 private class SimpleClassToJavassistScenario implements Scenario 88 { 89 public void execute(int thread, int loop) throws Exception 90 { 91 Class 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 99 { 100 Class pojo = LargePojo.class; 101 Method m = pojo.getMethod("method", new Class [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 109 { 110 Class pojo = LargePojo.class; 111 Field f = pojo.getField("field"); 112 ReflectToJavassist.fieldToJavassist(f); 113 } 114 } 115 } 116 | Popular Tags |