01: /**************************************************************************************
02: * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved. *
03: * http://aspectwerkz.codehaus.org *
04: * ---------------------------------------------------------------------------------- *
05: * The software in this package is published under the terms of the LGPL license *
06: * a copy of which has been included with this distribution in the license.txt file. *
07: **************************************************************************************/package test.staticinitialization;
08:
09: import org.codehaus.aspectwerkz.expression.ExpressionContext;
10: import org.codehaus.aspectwerkz.expression.ExpressionInfo;
11: import org.codehaus.aspectwerkz.expression.ExpressionNamespace;
12: import org.codehaus.aspectwerkz.expression.PointcutType;
13: import org.codehaus.aspectwerkz.reflect.ClassInfo;
14: import org.codehaus.aspectwerkz.reflect.MethodInfo;
15: import org.codehaus.aspectwerkz.reflect.impl.java.JavaClassInfo;
16:
17: import junit.framework.TestCase;
18: import test.CallerSideAdviceTest;
19:
20: /**
21: * Expression parser test for staticinitialization.
22: *
23: * @author <a href="mailto:the_mindstorm@evolva.ro">Alex Popescu</a>
24: */
25: public class StaticInitializationExpressionTest extends TestCase {
26: private static final String NAMESPACE = "TESTING";
27:
28: static {
29: Object some = new Object();
30: }
31:
32: public void testStaticInitializerExpression() {
33: ClassInfo declaringType = JavaClassInfo
34: .getClassInfo(StaticInitializationExpressionTest.class);
35:
36: assertTrue("should found <clinit>", declaringType
37: .hasStaticInitializer());
38:
39: assertTrue(new ExpressionInfo(
40: "staticinitialization(test.staticinitialization.StaticInitializationExpressionTest)",
41: NAMESPACE).getExpression().match(
42: new ExpressionContext(
43: PointcutType.STATIC_INITIALIZATION,
44: declaringType.staticInitializer(), null)));
45:
46: assertTrue(new ExpressionInfo(
47: "staticinitialization(test.*.*) && within(test.staticinitialization.StaticInitializationExpressionTest)",
48: NAMESPACE).getExpression().match(
49: new ExpressionContext(
50: PointcutType.STATIC_INITIALIZATION,
51: declaringType.staticInitializer(),
52: declaringType)));
53:
54: assertTrue(new ExpressionInfo(
55: "staticinitialization(test.staticinitialization.StaticInitializationExpressionTest)",
56: NAMESPACE).getAdvisedClassFilterExpression().match(
57: new ExpressionContext(
58: PointcutType.STATIC_INITIALIZATION, null,
59: declaringType)));
60:
61: assertTrue(new ExpressionInfo(
62: "staticinitialization(test.staticinitialization.StaticInitializationExpressionTest)",
63: NAMESPACE).getAdvisedClassFilterExpression().match(
64: new ExpressionContext(
65: PointcutType.STATIC_INITIALIZATION, null,
66: declaringType.staticInitializer())));
67: }
68:
69: public static void main(String[] args) {
70: junit.textui.TestRunner.run(suite());
71: }
72:
73: public static junit.framework.Test suite() {
74: return new junit.framework.TestSuite(
75: StaticInitializationExpressionTest.class);
76: }
77: }
|