01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.object.bytecode.aspectwerkz;
05:
06: import com.tc.aspectwerkz.expression.ExpressionContext;
07: import com.tc.aspectwerkz.expression.ExpressionVisitor;
08: import com.tc.aspectwerkz.reflect.ClassInfo;
09:
10: import junit.framework.TestCase;
11:
12: /**
13: *
14: */
15: public class ExpressionInfoTest extends TestCase {
16:
17: private ClassInfo classInfo;
18:
19: // private SimpleMethodInfo methodInfo;
20:
21: public void setUp() throws Exception {
22: ClassInfoFactory classInfoFactory = new ClassInfoFactory();
23: classInfo = classInfoFactory
24: .getClassInfo(com.tc.object.bytecode.aspectwerkz.Target.class
25: .getName());
26: }
27:
28: // TODO: Figure out how to create a MethodInfo class out of an ASM ClassVisitor context.
29: //
30: // public void testWithinMethod() throws Exception {
31: // ExpressionContext ctxt = new ExpressionContext(PointcutType.EXECUTION, methodInfo, methodInfo);
32: //
33: // String expression = "execution(public void com.tc.bytecode.aspectwerkz.Target.testMethod(..))";
34: // assertTrue(checkMatch(expression, ctxt));
35: // }
36:
37: public void testWithinClass() throws Exception {
38: ExpressionHelper eh = new ExpressionHelper();
39: ExpressionContext ctxt = eh
40: .createWithinExpressionContext(this .classInfo);
41:
42: String expression = ExpressionHelper
43: .expressionPattern2WithinExpression("com.tc.object.bytecode.aspectwerkz.*");
44: assertTrue(checkMatch(expression, ctxt));
45:
46: expression = ExpressionHelper
47: .expressionPattern2WithinExpression("com.tc.object.bytecode.*");
48: assertFalse(checkMatch(expression, ctxt));
49:
50: expression = ExpressionHelper
51: .expressionPattern2WithinExpression("com.tc.object.bytecode..*");
52: assertTrue(checkMatch(expression, ctxt));
53:
54: expression = ExpressionHelper
55: .expressionPattern2WithinExpression("java.lang..*");
56: assertFalse(checkMatch(expression, ctxt));
57:
58: expression = ExpressionHelper
59: .expressionPattern2WithinExpression("*.tc..*");
60: assertTrue(checkMatch(expression, ctxt));
61:
62: expression = ExpressionHelper
63: .expressionPattern2WithinExpression("*.object.bytecode.aspectwerkz.*");
64: assertFalse(checkMatch(expression, ctxt));
65:
66: expression = ExpressionHelper
67: .expressionPattern2WithinExpression("*..object.bytecode.aspectwerkz.*");
68: assertTrue(checkMatch(expression, ctxt));
69:
70: expression = ExpressionHelper
71: .expressionPattern2WithinExpression("*.*.object.bytecode..*");
72: assertTrue(checkMatch(expression, ctxt));
73: }
74:
75: private boolean checkMatch(String expression, ExpressionContext ctxt) {
76: ExpressionVisitor visitor = new ExpressionHelper()
77: .createExpressionVisitor(expression);
78: return visitor.match(ctxt);
79: }
80: }
|