001: /**************************************************************************************
002: * Copyright (c) Jonas Bonér, Alexandre Vasseur. All rights reserved. *
003: * http://aspectwerkz.codehaus.org *
004: * ---------------------------------------------------------------------------------- *
005: * The software in this package is published under the terms of the LGPL license *
006: * a copy of which has been included with this distribution in the license.txt file. *
007: **************************************************************************************/package test;
008:
009: import junit.framework.TestCase;
010: import org.codehaus.aspectwerkz.annotation.Before;
011: import org.codehaus.aspectwerkz.annotation.Expression;
012:
013: /**
014: * @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
015: */
016: public class CflowBelowTest extends TestCase {
017:
018: static int s_inAspectCount = 0;
019:
020: public void testCflow() {
021: s_inAspectCount = 0;
022: recursiveCflow(3);
023: assertEquals(3, s_inAspectCount);
024: }
025:
026: public void testCflowBelow() {
027: s_inAspectCount = 0;
028: recursiveCflowBelow(3);
029: assertEquals(2, s_inAspectCount);// one less
030: }
031:
032: /**
033: * Recursive i times.
034: *
035: * @param i
036: */
037: void recursiveCflow(int i) {
038: if (i <= 1) {
039: return;
040: } else {
041: recursiveCflow(i - 1);
042: }
043: }
044:
045: /**
046: * Recursive i times.
047: *
048: * @param i
049: */
050: void recursiveCflowBelow(int i) {
051: if (i <= 1) {
052: return;
053: } else {
054: recursiveCflowBelow(i - 1);
055: }
056: }
057:
058: public void testWithincodeAndCflowRuntimeTestOnEnclosingJP() {
059: s_inAspectCount = 0;
060: startCflowWithinCode();
061: assertEquals(1, s_inAspectCount);
062:
063: s_inAspectCount = 0;
064: startCflowNotWithinCode();
065: assertEquals(0, s_inAspectCount);
066: }
067:
068: public void startCflowWithinCode() {
069: withinCode();
070: }
071:
072: public void startCflowNotWithinCode() {
073: notWithinCode();
074: }
075:
076: public void withinCode() {
077: targetCall();// call of this method advised by withincode && cflow
078: }
079:
080: public void notWithinCode() {
081: targetCall();// call of this method advised by withincode && cflow but don't match
082: }
083:
084: public void targetCall() {
085: ;
086: }
087:
088: //--- JUnit
089:
090: public static void main(String[] args) {
091: junit.textui.TestRunner.run(suite());
092: }
093:
094: public static junit.framework.Test suite() {
095: return new junit.framework.TestSuite(CflowBelowTest.class);
096: }
097:
098: /**
099: * @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
100: */
101: public static class Aspect {
102:
103: @Expression("execution(* test.CflowBelowTest.recursiveCflow(..))")
104: void pcCflow() {
105: };
106:
107: @Expression("execution(* test.CflowBelowTest.recursiveCflowBelow(..))")
108: void pcCflowBelow() {
109: };
110:
111: @Before("pcCflow() && cflow(pcCflow())")
112: public void beforeCflow() {
113: s_inAspectCount++;
114: }
115:
116: @Before("pcCflowBelow() && cflowbelow(pcCflowBelow())")
117: public void beforeCflowBelow() {
118: s_inAspectCount++;
119: }
120:
121: @Before("call(* test.CflowBelowTest.targetCall())" + " && withincode(* test.CflowBelowTest.withinCode())" + " && cflow(execution(* test.CflowBelowTest.startCflowWithinCode()))")
122: public void withinCodeAndCflow() {
123: s_inAspectCount++;
124: }
125:
126: @Before("call(* test.CflowBelowTest.targetCall())" + " && withincode(* test.CflowBelowTest.withinCode())" + " && cflow(execution(* test.CflowBelowTest.startCflowNotWithinCode()))")
127: public void notWithinCodeAndCflow() {
128: s_inAspectCount++;
129: }
130:
131: }
132: }
|