|
|
@ -26,6 +26,7 @@ import org.junit.Test; |
|
|
|
import test.annotation.EmptySpringAnnotation; |
|
|
|
import test.annotation.EmptySpringAnnotation; |
|
|
|
import test.annotation.transaction.Tx; |
|
|
|
import test.annotation.transaction.Tx; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.aop.framework.ProxyFactory; |
|
|
|
import org.springframework.tests.sample.beans.TestBean; |
|
|
|
import org.springframework.tests.sample.beans.TestBean; |
|
|
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.*; |
|
|
|
import static org.junit.Assert.*; |
|
|
@ -73,7 +74,7 @@ public class TigerAspectJExpressionPointcutTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testMatchVarargs() throws SecurityException, NoSuchMethodException { |
|
|
|
public void testMatchVarargs() throws Exception { |
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unused") |
|
|
|
@SuppressWarnings("unused") |
|
|
|
class MyTemplate { |
|
|
|
class MyTemplate { |
|
|
@ -99,19 +100,19 @@ public class TigerAspectJExpressionPointcutTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testMatchAnnotationOnClassWithAtWithin() throws SecurityException, NoSuchMethodException { |
|
|
|
public void testMatchAnnotationOnClassWithAtWithin() throws Exception { |
|
|
|
String expression = "@within(test.annotation.transaction.Tx)"; |
|
|
|
String expression = "@within(test.annotation.transaction.Tx)"; |
|
|
|
testMatchAnnotationOnClass(expression); |
|
|
|
testMatchAnnotationOnClass(expression); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testMatchAnnotationOnClassWithoutBinding() throws SecurityException, NoSuchMethodException { |
|
|
|
public void testMatchAnnotationOnClassWithoutBinding() throws Exception { |
|
|
|
String expression = "within(@test.annotation.transaction.Tx *)"; |
|
|
|
String expression = "within(@test.annotation.transaction.Tx *)"; |
|
|
|
testMatchAnnotationOnClass(expression); |
|
|
|
testMatchAnnotationOnClass(expression); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testMatchAnnotationOnClassWithSubpackageWildcard() throws SecurityException, NoSuchMethodException { |
|
|
|
public void testMatchAnnotationOnClassWithSubpackageWildcard() throws Exception { |
|
|
|
String expression = "within(@(test.annotation..*) *)"; |
|
|
|
String expression = "within(@(test.annotation..*) *)"; |
|
|
|
AspectJExpressionPointcut springAnnotatedPc = testMatchAnnotationOnClass(expression); |
|
|
|
AspectJExpressionPointcut springAnnotatedPc = testMatchAnnotationOnClass(expression); |
|
|
|
assertFalse(springAnnotatedPc.matches(TestBean.class.getMethod("setName", String.class), TestBean.class)); |
|
|
|
assertFalse(springAnnotatedPc.matches(TestBean.class.getMethod("setName", String.class), TestBean.class)); |
|
|
@ -123,12 +124,12 @@ public class TigerAspectJExpressionPointcutTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testMatchAnnotationOnClassWithExactPackageWildcard() throws SecurityException, NoSuchMethodException { |
|
|
|
public void testMatchAnnotationOnClassWithExactPackageWildcard() throws Exception { |
|
|
|
String expression = "within(@(test.annotation.transaction.*) *)"; |
|
|
|
String expression = "within(@(test.annotation.transaction.*) *)"; |
|
|
|
testMatchAnnotationOnClass(expression); |
|
|
|
testMatchAnnotationOnClass(expression); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private AspectJExpressionPointcut testMatchAnnotationOnClass(String expression) throws SecurityException, NoSuchMethodException { |
|
|
|
private AspectJExpressionPointcut testMatchAnnotationOnClass(String expression) throws Exception { |
|
|
|
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut(); |
|
|
|
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut(); |
|
|
|
ajexp.setExpression(expression); |
|
|
|
ajexp.setExpression(expression); |
|
|
|
|
|
|
|
|
|
|
@ -141,7 +142,7 @@ public class TigerAspectJExpressionPointcutTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testAnnotationOnMethodWithFQN() throws SecurityException, NoSuchMethodException { |
|
|
|
public void testAnnotationOnMethodWithFQN() throws Exception { |
|
|
|
String expression = "@annotation(test.annotation.transaction.Tx)"; |
|
|
|
String expression = "@annotation(test.annotation.transaction.Tx)"; |
|
|
|
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut(); |
|
|
|
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut(); |
|
|
|
ajexp.setExpression(expression); |
|
|
|
ajexp.setExpression(expression); |
|
|
@ -155,7 +156,31 @@ public class TigerAspectJExpressionPointcutTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testAnnotationOnMethodWithWildcard() throws SecurityException, NoSuchMethodException { |
|
|
|
public void testAnnotationOnCglibProxyMethod() throws Exception { |
|
|
|
|
|
|
|
String expression = "@annotation(test.annotation.transaction.Tx)"; |
|
|
|
|
|
|
|
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut(); |
|
|
|
|
|
|
|
ajexp.setExpression(expression); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ProxyFactory factory = new ProxyFactory(new BeanA()); |
|
|
|
|
|
|
|
factory.setProxyTargetClass(true); |
|
|
|
|
|
|
|
BeanA proxy = (BeanA) factory.getProxy(); |
|
|
|
|
|
|
|
assertTrue(ajexp.matches(BeanA.class.getMethod("getAge"), proxy.getClass())); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void testAnnotationOnDynamicProxyMethod() throws Exception { |
|
|
|
|
|
|
|
String expression = "@annotation(test.annotation.transaction.Tx)"; |
|
|
|
|
|
|
|
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut(); |
|
|
|
|
|
|
|
ajexp.setExpression(expression); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ProxyFactory factory = new ProxyFactory(new BeanA()); |
|
|
|
|
|
|
|
factory.setProxyTargetClass(false); |
|
|
|
|
|
|
|
IBeanA proxy = (IBeanA) factory.getProxy(); |
|
|
|
|
|
|
|
assertTrue(ajexp.matches(IBeanA.class.getMethod("getAge"), proxy.getClass())); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void testAnnotationOnMethodWithWildcard() throws Exception { |
|
|
|
String expression = "execution(@(test.annotation..*) * *(..))"; |
|
|
|
String expression = "execution(@(test.annotation..*) * *(..))"; |
|
|
|
AspectJExpressionPointcut anySpringMethodAnnotation = new AspectJExpressionPointcut(); |
|
|
|
AspectJExpressionPointcut anySpringMethodAnnotation = new AspectJExpressionPointcut(); |
|
|
|
anySpringMethodAnnotation.setExpression(expression); |
|
|
|
anySpringMethodAnnotation.setExpression(expression); |
|
|
@ -171,7 +196,7 @@ public class TigerAspectJExpressionPointcutTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testAnnotationOnMethodArgumentsWithFQN() throws SecurityException, NoSuchMethodException { |
|
|
|
public void testAnnotationOnMethodArgumentsWithFQN() throws Exception { |
|
|
|
String expression = "@args(*, test.annotation.EmptySpringAnnotation))"; |
|
|
|
String expression = "@args(*, test.annotation.EmptySpringAnnotation))"; |
|
|
|
AspectJExpressionPointcut takesSpringAnnotatedArgument2 = new AspectJExpressionPointcut(); |
|
|
|
AspectJExpressionPointcut takesSpringAnnotatedArgument2 = new AspectJExpressionPointcut(); |
|
|
|
takesSpringAnnotatedArgument2.setExpression(expression); |
|
|
|
takesSpringAnnotatedArgument2.setExpression(expression); |
|
|
@ -201,7 +226,7 @@ public class TigerAspectJExpressionPointcutTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testAnnotationOnMethodArgumentsWithWildcards() throws SecurityException, NoSuchMethodException { |
|
|
|
public void testAnnotationOnMethodArgumentsWithWildcards() throws Exception { |
|
|
|
String expression = "execution(* *(*, @(test..*) *))"; |
|
|
|
String expression = "execution(* *(*, @(test..*) *))"; |
|
|
|
AspectJExpressionPointcut takesSpringAnnotatedArgument2 = new AspectJExpressionPointcut(); |
|
|
|
AspectJExpressionPointcut takesSpringAnnotatedArgument2 = new AspectJExpressionPointcut(); |
|
|
|
takesSpringAnnotatedArgument2.setExpression(expression); |
|
|
|
takesSpringAnnotatedArgument2.setExpression(expression); |
|
|
@ -266,7 +291,14 @@ public class TigerAspectJExpressionPointcutTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static class BeanA { |
|
|
|
interface IBeanA { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Tx |
|
|
|
|
|
|
|
int getAge(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static class BeanA implements IBeanA { |
|
|
|
|
|
|
|
|
|
|
|
private String name; |
|
|
|
private String name; |
|
|
|
|
|
|
|
|
|
|
@ -277,6 +309,7 @@ public class TigerAspectJExpressionPointcutTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Tx |
|
|
|
@Tx |
|
|
|
|
|
|
|
@Override |
|
|
|
public int getAge() { |
|
|
|
public int getAge() { |
|
|
|
return age; |
|
|
|
return age; |
|
|
|
} |
|
|
|
} |
|
|
|