KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > staticinitialization > StaticInitializationExpressionTest


1 /**************************************************************************************
2  * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved. *
3  * http://aspectwerkz.codehaus.org *
4  * ---------------------------------------------------------------------------------- *
5  * The software in this package is published under the terms of the LGPL license *
6  * a copy of which has been included with this distribution in the license.txt file. *
7  **************************************************************************************/

8 package test.staticinitialization;
9
10 import org.codehaus.aspectwerkz.expression.ExpressionContext;
11 import org.codehaus.aspectwerkz.expression.ExpressionInfo;
12 import org.codehaus.aspectwerkz.expression.ExpressionNamespace;
13 import org.codehaus.aspectwerkz.expression.PointcutType;
14 import org.codehaus.aspectwerkz.reflect.ClassInfo;
15 import org.codehaus.aspectwerkz.reflect.MethodInfo;
16 import org.codehaus.aspectwerkz.reflect.impl.java.JavaClassInfo;
17
18 import junit.framework.TestCase;
19 import test.CallerSideAdviceTest;
20
21
22 /**
23  * Expression parser test for staticinitialization.
24  *
25  * @author <a HREF="mailto:the_mindstorm@evolva.ro">Alex Popescu</a>
26  */

27 public class StaticInitializationExpressionTest extends TestCase {
28     private static final String JavaDoc NAMESPACE = "TESTING";
29     
30     static {
31         Object JavaDoc some = new Object JavaDoc();
32     }
33     
34     public void testStaticInitializerExpression() {
35         ClassInfo declaringType = JavaClassInfo.getClassInfo(StaticInitializationExpressionTest.class);
36         
37         assertTrue("should found <clinit>", declaringType.hasStaticInitializer());
38         
39         assertTrue(
40                 new ExpressionInfo(
41                         "staticinitialization(test.staticinitialization.StaticInitializationExpressionTest)",
42                         NAMESPACE).getExpression().match(
43                 new ExpressionContext(PointcutType.STATIC_INITIALIZATION, declaringType.staticInitializer(), null))
44         );
45
46
47         assertTrue(
48                 new ExpressionInfo(
49                         "staticinitialization(test.*.*) && within(test.staticinitialization.StaticInitializationExpressionTest)",
50                         NAMESPACE).getExpression().match(
51                 new ExpressionContext(PointcutType.STATIC_INITIALIZATION, declaringType.staticInitializer(), declaringType))
52         );
53                         
54         assertTrue(
55                 new ExpressionInfo(
56                         "staticinitialization(test.staticinitialization.StaticInitializationExpressionTest)",
57                         NAMESPACE).getAdvisedClassFilterExpression().match(
58                 new ExpressionContext(PointcutType.STATIC_INITIALIZATION, null, declaringType))
59         );
60
61         assertTrue(
62                 new ExpressionInfo(
63                         "staticinitialization(test.staticinitialization.StaticInitializationExpressionTest)",
64                         NAMESPACE).getAdvisedClassFilterExpression().match(
65                 new ExpressionContext(PointcutType.STATIC_INITIALIZATION, null, declaringType.staticInitializer()))
66         );
67     }
68     
69     public static void main(String JavaDoc[] args) {
70         junit.textui.TestRunner.run(suite());
71     }
72
73     public static junit.framework.Test suite() {
74         return new junit.framework.TestSuite(StaticInitializationExpressionTest.class);
75     }
76 }
77
Popular Tags