26
26
import test .annotation .EmptySpringAnnotation ;
27
27
import test .annotation .transaction .Tx ;
28
28
29
+ import org .springframework .aop .framework .ProxyFactory ;
29
30
import org .springframework .tests .sample .beans .TestBean ;
30
31
31
32
import static org .junit .Assert .*;
@@ -73,7 +74,7 @@ public void testMatchGenericArgument() {
73
74
}
74
75
75
76
@ Test
76
- public void testMatchVarargs () throws SecurityException , NoSuchMethodException {
77
+ public void testMatchVarargs () throws Exception {
77
78
78
79
@ SuppressWarnings ("unused" )
79
80
class MyTemplate {
@@ -99,19 +100,19 @@ public int queryForInt(String sql, Object... params) {
99
100
}
100
101
101
102
@ Test
102
- public void testMatchAnnotationOnClassWithAtWithin () throws SecurityException , NoSuchMethodException {
103
+ public void testMatchAnnotationOnClassWithAtWithin () throws Exception {
103
104
String expression = "@within(test.annotation.transaction.Tx)" ;
104
105
testMatchAnnotationOnClass (expression );
105
106
}
106
107
107
108
@ Test
108
- public void testMatchAnnotationOnClassWithoutBinding () throws SecurityException , NoSuchMethodException {
109
+ public void testMatchAnnotationOnClassWithoutBinding () throws Exception {
109
110
String expression = "within(@test.annotation.transaction.Tx *)" ;
110
111
testMatchAnnotationOnClass (expression );
111
112
}
112
113
113
114
@ Test
114
- public void testMatchAnnotationOnClassWithSubpackageWildcard () throws SecurityException , NoSuchMethodException {
115
+ public void testMatchAnnotationOnClassWithSubpackageWildcard () throws Exception {
115
116
String expression = "within(@(test.annotation..*) *)" ;
116
117
AspectJExpressionPointcut springAnnotatedPc = testMatchAnnotationOnClass (expression );
117
118
assertFalse (springAnnotatedPc .matches (TestBean .class .getMethod ("setName" , String .class ), TestBean .class ));
@@ -123,12 +124,12 @@ public void testMatchAnnotationOnClassWithSubpackageWildcard() throws SecurityEx
123
124
}
124
125
125
126
@ Test
126
- public void testMatchAnnotationOnClassWithExactPackageWildcard () throws SecurityException , NoSuchMethodException {
127
+ public void testMatchAnnotationOnClassWithExactPackageWildcard () throws Exception {
127
128
String expression = "within(@(test.annotation.transaction.*) *)" ;
128
129
testMatchAnnotationOnClass (expression );
129
130
}
130
131
131
- private AspectJExpressionPointcut testMatchAnnotationOnClass (String expression ) throws SecurityException , NoSuchMethodException {
132
+ private AspectJExpressionPointcut testMatchAnnotationOnClass (String expression ) throws Exception {
132
133
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut ();
133
134
ajexp .setExpression (expression );
134
135
@@ -141,7 +142,7 @@ private AspectJExpressionPointcut testMatchAnnotationOnClass(String expression)
141
142
}
142
143
143
144
@ Test
144
- public void testAnnotationOnMethodWithFQN () throws SecurityException , NoSuchMethodException {
145
+ public void testAnnotationOnMethodWithFQN () throws Exception {
145
146
String expression = "@annotation(test.annotation.transaction.Tx)" ;
146
147
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut ();
147
148
ajexp .setExpression (expression );
@@ -155,7 +156,31 @@ public void testAnnotationOnMethodWithFQN() throws SecurityException, NoSuchMeth
155
156
}
156
157
157
158
@ Test
158
- public void testAnnotationOnMethodWithWildcard () throws SecurityException , NoSuchMethodException {
159
+ public void testAnnotationOnCglibProxyMethod () throws Exception {
160
+ String expression = "@annotation(test.annotation.transaction.Tx)" ;
161
+ AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut ();
162
+ ajexp .setExpression (expression );
163
+
164
+ ProxyFactory factory = new ProxyFactory (new BeanA ());
165
+ factory .setProxyTargetClass (true );
166
+ BeanA proxy = (BeanA ) factory .getProxy ();
167
+ assertTrue (ajexp .matches (BeanA .class .getMethod ("getAge" ), proxy .getClass ()));
168
+ }
169
+
170
+ @ Test
171
+ public void testAnnotationOnDynamicProxyMethod () throws Exception {
172
+ String expression = "@annotation(test.annotation.transaction.Tx)" ;
173
+ AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut ();
174
+ ajexp .setExpression (expression );
175
+
176
+ ProxyFactory factory = new ProxyFactory (new BeanA ());
177
+ factory .setProxyTargetClass (false );
178
+ IBeanA proxy = (IBeanA ) factory .getProxy ();
179
+ assertTrue (ajexp .matches (IBeanA .class .getMethod ("getAge" ), proxy .getClass ()));
180
+ }
181
+
182
+ @ Test
183
+ public void testAnnotationOnMethodWithWildcard () throws Exception {
159
184
String expression = "execution(@(test.annotation..*) * *(..))" ;
160
185
AspectJExpressionPointcut anySpringMethodAnnotation = new AspectJExpressionPointcut ();
161
186
anySpringMethodAnnotation .setExpression (expression );
@@ -171,7 +196,7 @@ public void testAnnotationOnMethodWithWildcard() throws SecurityException, NoSuc
171
196
}
172
197
173
198
@ Test
174
- public void testAnnotationOnMethodArgumentsWithFQN () throws SecurityException , NoSuchMethodException {
199
+ public void testAnnotationOnMethodArgumentsWithFQN () throws Exception {
175
200
String expression = "@args(*, test.annotation.EmptySpringAnnotation))" ;
176
201
AspectJExpressionPointcut takesSpringAnnotatedArgument2 = new AspectJExpressionPointcut ();
177
202
takesSpringAnnotatedArgument2 .setExpression (expression );
@@ -201,7 +226,7 @@ ProcessesSpringAnnotatedParameters.class, new TestBean(), new BeanA())
201
226
}
202
227
203
228
@ Test
204
- public void testAnnotationOnMethodArgumentsWithWildcards () throws SecurityException , NoSuchMethodException {
229
+ public void testAnnotationOnMethodArgumentsWithWildcards () throws Exception {
205
230
String expression = "execution(* *(*, @(test..*) *))" ;
206
231
AspectJExpressionPointcut takesSpringAnnotatedArgument2 = new AspectJExpressionPointcut ();
207
232
takesSpringAnnotatedArgument2 .setExpression (expression );
@@ -266,7 +291,14 @@ public void foo() {
266
291
}
267
292
268
293
269
- static class BeanA {
294
+ interface IBeanA {
295
+
296
+ @ Tx
297
+ int getAge ();
298
+ }
299
+
300
+
301
+ static class BeanA implements IBeanA {
270
302
271
303
private String name ;
272
304
@@ -277,6 +309,7 @@ public void setName(String name) {
277
309
}
278
310
279
311
@ Tx
312
+ @ Override
280
313
public int getAge () {
281
314
return age ;
282
315
}
0 commit comments