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;
08:
09: import junit.framework.TestCase;
10: import org.codehaus.aspectwerkz.cflow.CflowCompiler;
11: import org.codehaus.aspectwerkz.cflow.AbstractCflowSystemAspect;
12: import org.codehaus.aspectwerkz.transform.inlining.AsmHelper;
13: import org.codehaus.aspectwerkz.reflect.ClassInfo;
14: import org.codehaus.aspectwerkz.reflect.MethodInfo;
15: import org.codehaus.aspectwerkz.reflect.impl.asm.AsmClassInfo;
16: import org.codehaus.aspectwerkz.exception.DefinitionException;
17:
18: import java.lang.reflect.Method;
19:
20: /**
21: * @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
22: */
23: public class CflowCompilerTest extends TestCase {
24:
25: public void testCompiler() {
26: try {
27: Class cflowAspect = CflowCompiler
28: .compileCflowAspectAndAttachToClassLoader(
29: CflowCompilerTest.class.getClassLoader(), 4);
30:
31: assertEquals(cflowAspect.getName().replace('/', '.'),
32: "org.codehaus.aspectwerkz.cflow.Cflow_4");
33: assertTrue(cflowAspect.getSuperclass().equals(
34: AbstractCflowSystemAspect.class));
35: Method enter = cflowAspect.getDeclaredMethod("isInCflow",
36: new Class[0]);
37: } catch (Throwable t) {
38: fail(t.toString());
39: }
40: }
41:
42: public void testCflow() throws Throwable {
43: Class cflowAspect = CflowCompiler
44: .compileCflowAspectAndAttachToClassLoader(
45: CflowCompilerTest.class.getClassLoader(), 4);
46:
47: // check NPE
48: Method staticMethod = cflowAspect.getDeclaredMethod(
49: "isInCflow", new Class[0]);
50: Boolean b = (Boolean) staticMethod.invoke(null, new Object[0]);
51: assertFalse(b.booleanValue());
52:
53: final AbstractCflowSystemAspect cflow = (AbstractCflowSystemAspect) cflowAspect
54: .getDeclaredMethod("aspectOf", new Class[0]).invoke(
55: null, new Object[0]);
56:
57: assertFalse(cflow.inCflow());
58: Thread t = new Thread() {
59: public void run() {
60: System.out.println(Thread.currentThread());
61: cflow.enter();
62: assertTrue(cflow.inCflow());
63: cflow.enter();
64: assertTrue(cflow.inCflow());
65: cflow.exit();
66: // leave the cflow in "inCflow" state is in this thread
67: }
68: };
69: t.start();
70: System.out.println(Thread.currentThread());
71:
72: assertFalse(cflow.inCflow());
73: }
74:
75: public static void main(String[] args) {
76: junit.textui.TestRunner.run(suite());
77: }
78:
79: public static junit.framework.Test suite() {
80: return new junit.framework.TestSuite(CflowCompilerTest.class);
81: }
82:
83: }
|