1 22 package org.jboss.test.aop.precedence; 23 24 import junit.framework.Test; 25 import junit.framework.TestSuite; 26 27 import java.util.ArrayList ; 28 29 import org.jboss.test.aop.AOPTestWithSetup; 30 31 37 public class PrecedenceTester extends AOPTestWithSetup 38 { 39 final static String [] 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 [] 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 [] 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 [] 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 name) 90 { 91 super(name); 92 } 93 94 public void testPrecedence() throws Exception 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 [] expected) 126 { 127 ArrayList 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 )intercepted.get(i)); 133 } 134 } 135 136 } 137 | Popular Tags |