KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > object > bytecode > aspectwerkz > ExpressionInfoTest


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.object.bytecode.aspectwerkz;
5
6 import com.tc.aspectwerkz.expression.ExpressionContext;
7 import com.tc.aspectwerkz.expression.ExpressionVisitor;
8 import com.tc.aspectwerkz.reflect.ClassInfo;
9
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 JavaDoc {
22     ClassInfoFactory classInfoFactory = new ClassInfoFactory();
23     classInfo = classInfoFactory.getClassInfo(com.tc.object.bytecode.aspectwerkz.Target.class.getName());
24   }
25
26   // TODO: Figure out how to create a MethodInfo class out of an ASM ClassVisitor context.
27
//
28
// public void testWithinMethod() throws Exception {
29
// ExpressionContext ctxt = new ExpressionContext(PointcutType.EXECUTION, methodInfo, methodInfo);
30
//
31
// String expression = "execution(public void com.tc.bytecode.aspectwerkz.Target.testMethod(..))";
32
// assertTrue(checkMatch(expression, ctxt));
33
// }
34

35   public void testWithinClass() throws Exception JavaDoc {
36     ExpressionHelper eh = new ExpressionHelper();
37     ExpressionContext ctxt = eh.createWithinExpressionContext(this.classInfo);
38
39     String JavaDoc expression = ExpressionHelper.expressionPattern2WithinExpression("com.tc.object.bytecode.aspectwerkz.*");
40     assertTrue(checkMatch(expression, ctxt));
41
42     expression = ExpressionHelper.expressionPattern2WithinExpression("com.tc.object.bytecode.*");
43     assertFalse(checkMatch(expression, ctxt));
44
45     expression = ExpressionHelper.expressionPattern2WithinExpression("com.tc.object.bytecode..*");
46     assertTrue(checkMatch(expression, ctxt));
47
48     expression = ExpressionHelper.expressionPattern2WithinExpression("java.lang..*");
49     assertFalse(checkMatch(expression, ctxt));
50
51     expression = ExpressionHelper.expressionPattern2WithinExpression("*.tc..*");
52     assertTrue(checkMatch(expression, ctxt));
53
54     expression = ExpressionHelper.expressionPattern2WithinExpression("*.object.bytecode.aspectwerkz.*");
55     assertFalse(checkMatch(expression, ctxt));
56
57     expression = ExpressionHelper.expressionPattern2WithinExpression("*..object.bytecode.aspectwerkz.*");
58     assertTrue(checkMatch(expression, ctxt));
59
60     expression = ExpressionHelper.expressionPattern2WithinExpression("*.*.object.bytecode..*");
61     assertTrue(checkMatch(expression, ctxt));
62   }
63
64   private boolean checkMatch(String JavaDoc expression, ExpressionContext ctxt) {
65     ExpressionVisitor visitor = new ExpressionHelper().createExpressionVisitor(expression);
66     return visitor.match(ctxt);
67   }
68 }
Popular Tags