}
// ============ advised class tests =============
public void testAdvisedClassExpression() throws Exception {
ClassInfo otherType = JavaClassInfo.getClassInfo(String.class);
assertFalse(new ExpressionInfo("execution(void test.expression.Target.modifiers1())", NAMESPACE)
.getAdvisedClassFilterExpression().match(new ExpressionContext(PointcutType.ANY, otherType, null)));
assertTrue(new ExpressionInfo("execution(void test.expression.Target.modifiers1())", NAMESPACE)
.getAdvisedClassFilterExpression()
.match(new ExpressionContext(PointcutType.ANY, s_declaringType, null)));
assertTrue(new ExpressionInfo("call(void test.expression.Target.modifiers1())", NAMESPACE)
.getAdvisedClassFilterExpression()
.match(new ExpressionContext(PointcutType.ANY, s_declaringType, null)));
assertTrue(new ExpressionInfo("set(int test.expression.Target.modifier1)", NAMESPACE)
.getAdvisedClassFilterExpression()
.match(new ExpressionContext(PointcutType.ANY, s_declaringType, null)));
assertTrue(new ExpressionInfo("get(int test.expression.Target.modifier1)", NAMESPACE)
.getAdvisedClassFilterExpression()
.match(new ExpressionContext(PointcutType.ANY, s_declaringType, null)));
assertTrue(new ExpressionInfo("handler(java.lang.Exception) && within(test.expression.Target)", NAMESPACE)
.getAdvisedClassFilterExpression()
.match(new ExpressionContext(PointcutType.ANY, s_declaringType, null)));
assertTrue(new ExpressionInfo("handler(java.lang.Exception) && within(test.expression.Target)", NAMESPACE)
.getAdvisedClassFilterExpression()
.match(new ExpressionContext(PointcutType.ANY, s_declaringType, null)));
assertTrue(new ExpressionInfo(
"handler(java.lang.Exception) && withincode(void test.expression.Target.modifiers1())",
NAMESPACE).getAdvisedClassFilterExpression().match(
new ExpressionContext(PointcutType.ANY, s_declaringType, null)));
assertTrue(new ExpressionInfo(
"handler(java.lang.Exception) && NOT withincode(void test.expression.Target.modifiers1())",
NAMESPACE).getAdvisedClassFilterExpression()
.match(new ExpressionContext(PointcutType.ANY, otherType, null)));
assertFalse(new ExpressionInfo(
"call(void test.expression.Dummy.modifiers1()) && within(test.expression.Target)",
NAMESPACE).getAdvisedClassFilterExpression().match(
new ExpressionContext(PointcutType.ANY, s_declaringType, null)));
assertFalse(new ExpressionInfo(
"call(void test.expression.Dummy.modifiers1()) && withincode(void test.expression.Target.modifiers1())",
NAMESPACE).getAdvisedClassFilterExpression().match(
new ExpressionContext(PointcutType.ANY, s_declaringType, null)));//fails on CALL
assertFalse(new ExpressionInfo(
"call(void test.expression.Target.modifiers1()) && withincode(void test.expression.TargetNOMATCH.modifiers1())",
NAMESPACE).getAdvisedClassFilterExpression().match(
new ExpressionContext(PointcutType.ANY, s_declaringType, s_declaringType)));//fails on WITHIN
assertTrue(new ExpressionInfo(
"execution(void test.expression.Target.modifiers1()) OR execution(* java.lang.String.*(..))",
NAMESPACE).getAdvisedClassFilterExpression()
.match(new ExpressionContext(PointcutType.ANY, otherType, null)));
assertTrue(new ExpressionInfo(
"execution(void test.expression.Target.modifiers1()) OR execution(* java.lang.String.*(..))",
NAMESPACE).getAdvisedClassFilterExpression().match(
new ExpressionContext(PointcutType.ANY, s_declaringType, null)));
assertTrue(new ExpressionInfo(
"execution(void test.expression.Target.modifiers1()) AND NOT execution(* java.lang.String.*(..))",
NAMESPACE).getAdvisedClassFilterExpression().match(
new ExpressionContext(PointcutType.ANY, s_declaringType, null)));
// check that we ignore cflow
assertTrue(new ExpressionInfo(
"execution(void test.expression.Target.modifiers1()) AND cflow(execution(* *..*(..)))",
NAMESPACE).getAdvisedClassFilterExpression().match(
new ExpressionContext(PointcutType.ANY, s_declaringType, null)));
assertTrue(new ExpressionInfo(
"execution(void test.expression.Target.modifiers1()) AND NOT cflow(execution(* *..*(..)))",
NAMESPACE).getAdvisedClassFilterExpression().match(
new ExpressionContext(PointcutType.ANY, s_declaringType, null)));
assertFalse(new ExpressionInfo(
"execution(void test.expression.TargetNOMATCH.modifiers1()) AND cflow(execution(* *..*(..)))",
NAMESPACE).getAdvisedClassFilterExpression().match(
new ExpressionContext(PointcutType.ANY, s_declaringType, null)));
assertFalse(new ExpressionInfo(
"execution(void test.expression.TargetNOMATCH.modifiers1()) AND NOT cflow(execution(* *..*(..)))",
NAMESPACE).getAdvisedClassFilterExpression().match(
new ExpressionContext(PointcutType.ANY, s_declaringType, null)));
// the following should return FALSE with a good early filtering
// returning TRUE is not a problem for the early filtering but false will save time
assertFalse(new ExpressionInfo(
"execution(void test.expression.Target.modifiers1()) OR NOT execution(* java.lang.String.*(..))",
NAMESPACE).getAdvisedClassFilterExpression().match(
new ExpressionContext(PointcutType.ANY, otherType, null)));
assertFalse(new ExpressionInfo(
"execution(void test.expression.Target.modifiers1()) AND execution(* java.lang.String.*(..))",
NAMESPACE).getAdvisedClassFilterExpression().match(
new ExpressionContext(PointcutType.ANY, s_declaringType, null)));
assertFalse(new ExpressionInfo(
"execution(void test.expression.Target.modifiers1()) AND execution(* java.lang.String.*(..))",
NAMESPACE).getAdvisedClassFilterExpression().match(
new ExpressionContext(PointcutType.ANY, s_declaringType, null)));
//FIXME: since Pointcut with signature in grammar, not/NOT must be separated by a <space>
// assertTrue(new ExpressionInfo(
// "NOT(execution(void test.expression.Target.modifiers1()) OR NOT execution(* java.lang.String.*(..)))",
// NAMESPACE).getAdvisedClassFilterExpression().match(
// new ExpressionContext(PointcutType.ANY, otherType, null)));
assertTrue(new ExpressionInfo(
"NOT (execution(void test.expression.Target.modifiers1()) OR NOT execution(* java.lang.String.*(..)))",
NAMESPACE).getAdvisedClassFilterExpression()
.match(new ExpressionContext(PointcutType.ANY, otherType, null)));
}