0001: /**************************************************************************************
0002: * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved. *
0003: * http://aspectwerkz.codehaus.org *
0004: * ---------------------------------------------------------------------------------- *
0005: * The software in this package is published under the terms of the LGPL license *
0006: * a copy of which has been included with this distribution in the license.txt file. *
0007: **************************************************************************************/package test.expression;
0008:
0009: import junit.framework.TestCase;
0010: import org.codehaus.aspectwerkz.expression.ExpressionContext;
0011: import org.codehaus.aspectwerkz.expression.ExpressionInfo;
0012: import org.codehaus.aspectwerkz.expression.ExpressionNamespace;
0013: import org.codehaus.aspectwerkz.expression.ExpressionVisitor;
0014: import org.codehaus.aspectwerkz.expression.PointcutType;
0015: import org.codehaus.aspectwerkz.reflect.ClassInfo;
0016: import org.codehaus.aspectwerkz.reflect.ConstructorInfo;
0017: import org.codehaus.aspectwerkz.reflect.FieldInfo;
0018: import org.codehaus.aspectwerkz.reflect.MethodInfo;
0019: import org.codehaus.aspectwerkz.reflect.impl.java.JavaClassInfo;
0020: import org.codehaus.aspectwerkz.reflect.impl.java.JavaFieldInfo;
0021: import org.codehaus.aspectwerkz.reflect.impl.java.JavaMethodInfo;
0022: import org.codehaus.aspectwerkz.exception.DefinitionException;
0023: import org.codehaus.aspectwerkz.cflow.CflowBinding;
0024:
0025: /**
0026: * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
0027: * @author <a href="mailto:alex@gnilux.com">Alexandre Vasseur </a>
0028: */
0029: public class ExpressionTest extends TestCase {
0030: private static final String NAMESPACE = "TESTING";
0031:
0032: private static ExpressionNamespace s_namespace = ExpressionNamespace
0033: .getNamespace(NAMESPACE);
0034:
0035: private static ClassInfo s_declaringType = JavaClassInfo
0036: .getClassInfo(Target.class);
0037:
0038: private static MethodInfo modifiers1;
0039:
0040: private static MethodInfo modifiers2;
0041:
0042: private static MethodInfo modifiers3;
0043:
0044: private static MethodInfo modifiers4;
0045:
0046: private static MethodInfo parameters1;
0047:
0048: private static MethodInfo parameters2;
0049:
0050: private static MethodInfo parameters2bis;
0051:
0052: private static MethodInfo parameters3;
0053:
0054: private static MethodInfo parameters4;
0055:
0056: private static MethodInfo parameters5;
0057:
0058: private static MethodInfo returnType1;
0059:
0060: private static MethodInfo returnType2;
0061:
0062: private static MethodInfo returnType3;
0063:
0064: private static MethodInfo returnType4;
0065:
0066: private static MethodInfo returnType5;
0067:
0068: private static MethodInfo _method$Name1;
0069:
0070: private static MethodInfo attributes1;
0071:
0072: private static ConstructorInfo constructorNoArgPublic;
0073:
0074: private static ConstructorInfo constructorIntArgPrivate;
0075:
0076: private static FieldInfo modifier1;
0077:
0078: private static FieldInfo modifier2;
0079:
0080: private static FieldInfo modifier3;
0081:
0082: private static FieldInfo type1;
0083:
0084: private static FieldInfo type2;
0085:
0086: private static FieldInfo type3;
0087:
0088: private static FieldInfo type4;
0089:
0090: private static FieldInfo _field$Name1;
0091:
0092: private static FieldInfo attribute1;
0093:
0094: // ============ setup =============
0095: static {
0096: ConstructorInfo[] constructors = s_declaringType
0097: .getConstructors();
0098: for (int i = 0; i < constructors.length; i++) {
0099: ConstructorInfo constructor = constructors[i];
0100: if (constructor.getParameterTypes().length == 0) {
0101: constructorNoArgPublic = constructor;
0102: } else {
0103: constructorIntArgPrivate = constructor;
0104: }
0105: }
0106:
0107: MethodInfo[] methods = s_declaringType.getMethods();
0108: for (int i = 0; i < methods.length; i++) {
0109: MethodInfo method = methods[i];
0110: if (method.getName().equals("modifiers1")) {
0111: modifiers1 = method;
0112: }
0113: if (method.getName().equals("modifiers2")) {
0114: modifiers2 = method;
0115: }
0116: if (method.getName().equals("modifiers3")) {
0117: modifiers3 = method;
0118: }
0119: if (method.getName().equals("modifiers4")) {
0120: modifiers4 = method;
0121: }
0122: if (method.getName().equals("parameters1")) {
0123: parameters1 = method;
0124: }
0125: if (method.getName().equals("parameters2")) {
0126: parameters2 = method;
0127: }
0128: if (method.getName().equals("parameters2bis")) {
0129: parameters2bis = method;
0130: }
0131: if (method.getName().equals("parameters3")) {
0132: parameters3 = method;
0133: }
0134: if (method.getName().equals("parameters4")) {
0135: parameters4 = method;
0136: }
0137: if (method.getName().equals("parameters5")) {
0138: parameters5 = method;
0139: }
0140: if (method.getName().equals("returnType1")) {
0141: returnType1 = method;
0142: }
0143: if (method.getName().equals("returnType1")) {
0144: returnType1 = method;
0145: }
0146: if (method.getName().equals("returnType2")) {
0147: returnType2 = method;
0148: }
0149: if (method.getName().equals("returnType3")) {
0150: returnType3 = method;
0151: }
0152: if (method.getName().equals("returnType4")) {
0153: returnType4 = method;
0154: }
0155: if (method.getName().equals("returnType5")) {
0156: returnType5 = method;
0157: }
0158: if (method.getName().equals("__method$Name1")) {
0159: _method$Name1 = method;
0160: }
0161: if (method.getName().equals("attributes1")) {
0162: attributes1 = method;
0163: }
0164: }
0165: FieldInfo[] fields = s_declaringType.getFields();
0166: for (int f = 0; f < fields.length; f++) {
0167: FieldInfo field = fields[f];
0168: if (field.getName().equals("modifier1")) {
0169: modifier1 = field;
0170: }
0171: if (field.getName().equals("modifier2")) {
0172: modifier2 = field;
0173: }
0174: if (field.getName().equals("modifier3")) {
0175: modifier3 = field;
0176: }
0177: if (field.getName().equals("type1")) {
0178: type1 = field;
0179: }
0180: if (field.getName().equals("type2")) {
0181: type2 = field;
0182: }
0183: if (field.getName().equals("type3")) {
0184: type3 = field;
0185: }
0186: if (field.getName().equals("type4")) {
0187: type4 = field;
0188: }
0189: if (field.getName().equals("__field$Name1")) {
0190: _field$Name1 = field;
0191: }
0192: if (field.getName().equals("attribute1")) {
0193: attribute1 = field;
0194: }
0195: }
0196: }
0197:
0198: public ExpressionTest(String name) {
0199: super (name);
0200: }
0201:
0202: // ============ constructor signature test =============
0203: public void testConstructor() throws Exception {
0204: assertTrue(new ExpressionInfo(
0205: "call(test.expression.Target.new())", NAMESPACE)
0206: .getExpression().match(
0207: new ExpressionContext(PointcutType.CALL,
0208: constructorNoArgPublic, null)));
0209: assertFalse(new ExpressionInfo(
0210: "call(test.expression.Target.new(String))", NAMESPACE)
0211: .getExpression().match(
0212: new ExpressionContext(PointcutType.CALL,
0213: constructorNoArgPublic, null)));
0214: assertTrue(new ExpressionInfo(
0215: "call(test.expression.Target.new())", NAMESPACE)
0216: .getExpression().match(
0217: new ExpressionContext(PointcutType.CALL,
0218: constructorNoArgPublic, null)));
0219: assertFalse(new ExpressionInfo(
0220: "call(test.expression.Target.new(String))", NAMESPACE)
0221: .getExpression().match(
0222: new ExpressionContext(PointcutType.CALL,
0223: constructorNoArgPublic, null)));
0224: //AW-112 below
0225: assertTrue(new ExpressionInfo(
0226: "within(test.expression.Target) && execution(new())",
0227: NAMESPACE).getExpression().match(
0228: new ExpressionContext(PointcutType.EXECUTION,
0229: constructorNoArgPublic, null)));
0230: assertTrue(new ExpressionInfo(
0231: "within(test..*) && execution(*.expression.Target.new())",
0232: NAMESPACE).getExpression().match(
0233: new ExpressionContext(PointcutType.EXECUTION,
0234: constructorNoArgPublic, constructorNoArgPublic
0235: .getDeclaringType())));
0236: assertTrue(new ExpressionInfo(
0237: "within(test..*.*) && execution(*.expression.Target.new())",
0238: NAMESPACE).getExpression().match(
0239: new ExpressionContext(PointcutType.EXECUTION,
0240: constructorNoArgPublic, constructorNoArgPublic
0241: .getDeclaringType())));
0242: }
0243:
0244: // ============ constructor modifiers test =============
0245: public void testConstructorModifiers1() throws Exception {
0246: assertTrue(new ExpressionInfo(
0247: "call(public test.expression.Target.new())", NAMESPACE)
0248: .getExpression().match(
0249: new ExpressionContext(PointcutType.CALL,
0250: constructorNoArgPublic, null)));
0251: assertFalse(new ExpressionInfo(
0252: "call(private test.expression.Target.new())", NAMESPACE)
0253: .getExpression().match(
0254: new ExpressionContext(PointcutType.CALL,
0255: constructorNoArgPublic, null)));
0256: }
0257:
0258: // ============ constructor annotations test =============
0259: public void testConstructorAnnotations1() throws Exception {
0260: assertTrue(new ExpressionInfo(
0261: "call(@Requires test.expression.Target.new())",
0262: NAMESPACE).getExpression().match(
0263: new ExpressionContext(PointcutType.CALL,
0264: constructorNoArgPublic, null)));
0265: assertFalse(new ExpressionInfo(
0266: "call(@RequiresNew test.expression.Target.new())",
0267: NAMESPACE).getExpression().match(
0268: new ExpressionContext(PointcutType.CALL,
0269: constructorNoArgPublic, null)));
0270: assertTrue(new ExpressionInfo(
0271: "execution(@Requires test.expression.Target.new())",
0272: NAMESPACE).getExpression().match(
0273: new ExpressionContext(PointcutType.EXECUTION,
0274: constructorNoArgPublic, null)));
0275: assertFalse(new ExpressionInfo(
0276: "execution(@RequiresNew test.expression.Target.new())",
0277: NAMESPACE).getExpression().match(
0278: new ExpressionContext(PointcutType.EXECUTION,
0279: constructorNoArgPublic, null)));
0280: }
0281:
0282: public void testConstructorAnnotations2() throws Exception {
0283: assertTrue(new ExpressionInfo(
0284: "execution(@Requires *..*.new(..))", NAMESPACE)
0285: .getExpression().match(
0286: new ExpressionContext(PointcutType.EXECUTION,
0287: constructorNoArgPublic, null)));
0288: try {
0289: // should fail - we are specifying a return type for ctor
0290: assertTrue(new ExpressionInfo(
0291: "execution(@Requires * new(..))", NAMESPACE)
0292: .getExpression().match(
0293: new ExpressionContext(
0294: PointcutType.EXECUTION,
0295: constructorNoArgPublic, null)));
0296: fail("Should fail - specified return type for ctor");
0297: } catch (DefinitionException e) {
0298: ;//test ok
0299: }
0300:
0301: assertFalse(new ExpressionInfo(
0302: "execution(@RequiresNew *..*.new(..))", NAMESPACE)
0303: .getExpression().match(
0304: new ExpressionContext(PointcutType.EXECUTION,
0305: constructorNoArgPublic, null)));
0306: assertTrue(new ExpressionInfo("call(@Requires *..*.new(..))",
0307: NAMESPACE).getExpression().match(
0308: new ExpressionContext(PointcutType.CALL,
0309: constructorNoArgPublic, null)));
0310: assertFalse(new ExpressionInfo(
0311: "call(@RequiresNew *..*.new(..))", NAMESPACE)
0312: .getExpression().match(
0313: new ExpressionContext(PointcutType.CALL,
0314: constructorNoArgPublic, null)));
0315: }
0316:
0317: // ============ method modifiers test =============
0318: public void testMethodModifiers1() throws Exception {
0319: assertFalse(new ExpressionInfo(
0320: "call(public void test.expression.Target.modifiers1())",
0321: NAMESPACE).getExpression().match(
0322: new ExpressionContext(PointcutType.CALL, modifiers1,
0323: null)));
0324: assertTrue(new ExpressionInfo(
0325: "call(void test.expression.Target.modifiers1())",
0326: NAMESPACE).getExpression().match(
0327: new ExpressionContext(PointcutType.CALL, modifiers1,
0328: null)));
0329: assertFalse(new ExpressionInfo(
0330: "call(static final void test.expression.Target.modifiers1())",
0331: NAMESPACE).getExpression().match(
0332: new ExpressionContext(PointcutType.CALL, modifiers1,
0333: null)));
0334: }
0335:
0336: public void testMethodModifiers2() throws Exception {
0337: assertTrue(new ExpressionInfo(
0338: "call(public void test.expression.Target.modifiers2())",
0339: NAMESPACE).getExpression().match(
0340: new ExpressionContext(PointcutType.CALL, modifiers2,
0341: null)));
0342: assertTrue(new ExpressionInfo(
0343: "call(void test.expression.Target.modifiers2())",
0344: NAMESPACE).getExpression().match(
0345: new ExpressionContext(PointcutType.CALL, modifiers2,
0346: null)));
0347: assertFalse(new ExpressionInfo(
0348: "call(static final void test.expression.Target.modifiers2())",
0349: NAMESPACE).getExpression().match(
0350: new ExpressionContext(PointcutType.CALL, modifiers2,
0351: null)));
0352: assertFalse(new ExpressionInfo(
0353: "call(public static final void test.expression.Target.modifiers2())",
0354: NAMESPACE).getExpression().match(
0355: new ExpressionContext(PointcutType.CALL, modifiers2,
0356: null)));
0357: assertTrue(new ExpressionInfo(
0358: "call(public static void test.expression.Target.modifiers2())",
0359: NAMESPACE).getExpression().match(
0360: new ExpressionContext(PointcutType.CALL, modifiers2,
0361: null)));
0362: }
0363:
0364: public void testMethodModifiers3() throws Exception {
0365: assertFalse(new ExpressionInfo(
0366: "call(public void test.expression.Target.modifiers3())",
0367: NAMESPACE).getExpression().match(
0368: new ExpressionContext(PointcutType.CALL, modifiers3,
0369: null)));
0370: assertTrue(new ExpressionInfo(
0371: "call(void test.expression.Target.modifiers3())",
0372: NAMESPACE).getExpression().match(
0373: new ExpressionContext(PointcutType.CALL, modifiers3,
0374: null)));
0375: assertTrue(new ExpressionInfo(
0376: "call(static final void test.expression.Target.modifiers3())",
0377: NAMESPACE).getExpression().match(
0378: new ExpressionContext(PointcutType.CALL, modifiers3,
0379: null)));
0380: assertFalse(new ExpressionInfo(
0381: "call(public static native void test.expression.Target.modifiers3())",
0382: NAMESPACE).getExpression().match(
0383: new ExpressionContext(PointcutType.CALL, modifiers3,
0384: null)));
0385: assertFalse(new ExpressionInfo(
0386: "call(public static void test.expression.Target.modifiers3())",
0387: NAMESPACE).getExpression().match(
0388: new ExpressionContext(PointcutType.CALL, modifiers3,
0389: null)));
0390: assertTrue(new ExpressionInfo(
0391: "call(synchronized void test.expression.Target.modifiers3())",
0392: NAMESPACE).getExpression().match(
0393: new ExpressionContext(PointcutType.CALL, modifiers3,
0394: null)));
0395: assertTrue(new ExpressionInfo(
0396: "call(protected native synchronized void test.expression.Target.modifiers3())",
0397: NAMESPACE).getExpression().match(
0398: new ExpressionContext(PointcutType.CALL, modifiers3,
0399: null)));
0400: assertTrue(new ExpressionInfo(
0401: "call(native protected void test.expression.Target.modifiers3())",
0402: NAMESPACE).getExpression().match(
0403: new ExpressionContext(PointcutType.CALL, modifiers3,
0404: null)));
0405: }
0406:
0407: public void testMethodModifiers4() throws Exception {
0408: ClassInfo otherType = JavaClassInfo.getClassInfo(String.class);
0409: assertFalse(new ExpressionInfo(
0410: "call(public * test.expression.*.*(..)) && within(test.expression.*)",
0411: NAMESPACE).getExpression().match(
0412: new ExpressionContext(PointcutType.CALL, modifiers4,
0413: s_declaringType)));
0414: assertTrue(new ExpressionInfo(
0415: "call(private * test.expression.*.*(..)) && within(test.expression.*)",
0416: NAMESPACE).getExpression().match(
0417: new ExpressionContext(PointcutType.CALL, modifiers4,
0418: s_declaringType)));
0419: assertFalse(new ExpressionInfo(
0420: "call(protected * test.expression.*.*(..)) && within(test.expression.*)",
0421: NAMESPACE).getExpression().match(
0422: new ExpressionContext(PointcutType.CALL, modifiers4,
0423: s_declaringType)));
0424: assertFalse(new ExpressionInfo(
0425: "call(protected * test.expression.*.*(..)) && within(test.expression.*)",
0426: NAMESPACE).getExpression().match(
0427: new ExpressionContext(PointcutType.CALL, modifiers4,
0428: otherType)));
0429: assertTrue(new ExpressionInfo(
0430: "call(private * test.expression.*.*(..)) && within(java.lang.String)",
0431: NAMESPACE).getExpression().match(
0432: new ExpressionContext(PointcutType.CALL, modifiers4,
0433: otherType)));
0434: }
0435:
0436: public void testMethodModifiers5() throws Exception {
0437: assertFalse(new ExpressionInfo(
0438: "call(!public void test.expression.Target.modifiers2())",
0439: NAMESPACE).getExpression().match(
0440: new ExpressionContext(PointcutType.CALL, modifiers2,
0441: null)));
0442: assertFalse(new ExpressionInfo(
0443: "call(!public void test.expression.Target.modifiers2())",
0444: NAMESPACE).getExpression().match(
0445: new ExpressionContext(PointcutType.CALL, modifiers2,
0446: null)));
0447: assertTrue(new ExpressionInfo(
0448: "call(!private void test.expression.Target.modifiers2())",
0449: NAMESPACE).getExpression().match(
0450: new ExpressionContext(PointcutType.CALL, modifiers2,
0451: null)));
0452: assertTrue(new ExpressionInfo(
0453: "call(!private static void test.expression.Target.modifiers2())",
0454: NAMESPACE).getExpression().match(
0455: new ExpressionContext(PointcutType.CALL, modifiers2,
0456: null)));
0457: assertFalse(new ExpressionInfo(
0458: "call(public !static void test.expression.Target.modifiers2())",
0459: NAMESPACE).getExpression().match(
0460: new ExpressionContext(PointcutType.CALL, modifiers2,
0461: null)));
0462: assertFalse(new ExpressionInfo(
0463: "call(public !static void test.expression.Target.modifiers2())",
0464: NAMESPACE).getExpression().match(
0465: new ExpressionContext(PointcutType.CALL, modifiers2,
0466: null)));
0467: }
0468:
0469: // ============ method parameters test =============
0470: public void testMethodParameters1() throws Exception {
0471: assertTrue(new ExpressionInfo(
0472: "call(void test.expression.Target.parameters1())",
0473: NAMESPACE).getExpression().match(
0474: new ExpressionContext(PointcutType.CALL, parameters1,
0475: null)));
0476: assertTrue(new ExpressionInfo(
0477: "call(void test.expression.Target.parameters1(..))",
0478: NAMESPACE).getExpression().match(
0479: new ExpressionContext(PointcutType.CALL, parameters1,
0480: null)));
0481: assertFalse(new ExpressionInfo(
0482: "call(void test.expression.Target.parameters1(*))",
0483: NAMESPACE).getExpression().match(
0484: new ExpressionContext(PointcutType.CALL, parameters1,
0485: null)));
0486: assertFalse(new ExpressionInfo(
0487: "call(void test.expression.Target.parameters1(int))",
0488: NAMESPACE).getExpression().match(
0489: new ExpressionContext(PointcutType.CALL, parameters1,
0490: null)));
0491: }
0492:
0493: public void testMethodParameters2() throws Exception {
0494: assertFalse(new ExpressionInfo(
0495: "call(void test.expression.Target.parameters2())",
0496: NAMESPACE).getExpression().match(
0497: new ExpressionContext(PointcutType.CALL, parameters2,
0498: null)));
0499: assertTrue(new ExpressionInfo(
0500: "call(void test.expression.Target.parameters2(..))",
0501: NAMESPACE).getExpression().match(
0502: new ExpressionContext(PointcutType.CALL, parameters2,
0503: null)));
0504: assertTrue(new ExpressionInfo(
0505: "call(void test.expression.Target.parameters2(int, ..))",
0506: NAMESPACE).getExpression().match(
0507: new ExpressionContext(PointcutType.CALL, parameters2,
0508: null)));
0509: //AW-263
0510: assertTrue(new ExpressionInfo(
0511: "call(void test.expression.Target.parameters2(int, float, byte, ..))",
0512: NAMESPACE).getExpression().match(
0513: new ExpressionContext(PointcutType.CALL, parameters2,
0514: null)));
0515: assertTrue(new ExpressionInfo(
0516: "call(void test.expression.Target.parameters2(.., int, float, byte, ..))",
0517: NAMESPACE).getExpression().match(
0518: new ExpressionContext(PointcutType.CALL, parameters2,
0519: null)));
0520: assertTrue(new ExpressionInfo(
0521: "call(void test.expression.Target.parameters2(.., int, float, byte))",
0522: NAMESPACE).getExpression().match(
0523: new ExpressionContext(PointcutType.CALL, parameters2,
0524: null)));
0525: assertTrue(new ExpressionInfo(
0526: "call(void test.expression.Target.parameters2(.., int, float, ..))",
0527: NAMESPACE).getExpression().match(
0528: new ExpressionContext(PointcutType.CALL, parameters2,
0529: null)));
0530: assertTrue(new ExpressionInfo(
0531: "call(void test.expression.Target.parameters2bis(.., int, float, byte, ..))",
0532: NAMESPACE).getExpression().match(
0533: new ExpressionContext(PointcutType.CALL,
0534: parameters2bis, null)));
0535:
0536: assertTrue(new ExpressionInfo(
0537: "call(void test.expression.Target.parameters2(int, float, byte))",
0538: NAMESPACE).getExpression().match(
0539: new ExpressionContext(PointcutType.CALL, parameters2,
0540: null)));
0541: assertTrue(new ExpressionInfo(
0542: "call(void test.expression.Target.parameters2(int, *, *))",
0543: NAMESPACE).getExpression().match(
0544: new ExpressionContext(PointcutType.CALL, parameters2,
0545: null)));
0546: assertFalse(new ExpressionInfo(
0547: "call(void test.expression.Target.parameters2(int, int, byte))",
0548: NAMESPACE).getExpression().match(
0549: new ExpressionContext(PointcutType.CALL, parameters2,
0550: null)));
0551: assertTrue(new ExpressionInfo(
0552: "call(void test.expression.Target.parameters2(*, *, byte))",
0553: NAMESPACE).getExpression().match(
0554: new ExpressionContext(PointcutType.CALL, parameters2,
0555: null)));
0556: }
0557:
0558: public void testMethodParameters3() throws Exception {
0559: assertFalse(new ExpressionInfo(
0560: "call(void test.expression.Target.parameters3())",
0561: NAMESPACE).getExpression().match(
0562: new ExpressionContext(PointcutType.CALL, parameters3,
0563: null)));
0564: assertTrue(new ExpressionInfo(
0565: "call(void test.expression.Target.parameters3(..))",
0566: NAMESPACE).getExpression().match(
0567: new ExpressionContext(PointcutType.CALL, parameters3,
0568: null)));
0569: assertFalse(new ExpressionInfo(
0570: "call(void test.expression.Target.parameters3(int, ..))",
0571: NAMESPACE).getExpression().match(
0572: new ExpressionContext(PointcutType.CALL, parameters3,
0573: null)));
0574: assertTrue(new ExpressionInfo(
0575: "call(void test.expression.Target.parameters3(String, ..))",
0576: NAMESPACE).getExpression().match(
0577: new ExpressionContext(PointcutType.CALL, parameters3,
0578: null)));
0579: assertFalse(new ExpressionInfo(
0580: "call(void test.expression.Target.parameters3(String, String, String))",
0581: NAMESPACE).getExpression().match(
0582: new ExpressionContext(PointcutType.CALL, parameters3,
0583: null)));
0584: assertTrue(new ExpressionInfo(
0585: "call(void test.expression.Target.parameters3(String, StringBuffer, String))",
0586: NAMESPACE).getExpression().match(
0587: new ExpressionContext(PointcutType.CALL, parameters3,
0588: null)));
0589: assertFalse(new ExpressionInfo(
0590: "call(void test.expression.Target.parameters3(String, StringBuffer, String, *))",
0591: NAMESPACE).getExpression().match(
0592: new ExpressionContext(PointcutType.CALL, parameters3,
0593: null)));
0594: }
0595:
0596: public void testMethodParameters4() throws Exception {
0597: assertFalse(new ExpressionInfo(
0598: "call(void test.expression.Target.parameters4())",
0599: NAMESPACE).getExpression().match(
0600: new ExpressionContext(PointcutType.CALL, parameters4,
0601: null)));
0602: assertTrue(new ExpressionInfo(
0603: "call(void test.expression.Target.parameters4(..))",
0604: NAMESPACE).getExpression().match(
0605: new ExpressionContext(PointcutType.CALL, parameters4,
0606: null)));
0607: assertFalse(new ExpressionInfo(
0608: "call(void test.expression.Target.parameters4(Object))",
0609: NAMESPACE).getExpression().match(
0610: new ExpressionContext(PointcutType.CALL, parameters4,
0611: null)));
0612: assertTrue(new ExpressionInfo(
0613: "call(void test.expression.Target.parameters4(Object[]))",
0614: NAMESPACE).getExpression().match(
0615: new ExpressionContext(PointcutType.CALL, parameters4,
0616: null)));
0617: assertFalse(new ExpressionInfo(
0618: "call(void test.expression.Target.parameters4(Object[][]))",
0619: NAMESPACE).getExpression().match(
0620: new ExpressionContext(PointcutType.CALL, parameters4,
0621: null)));
0622: }
0623:
0624: public void testMethodParameters5() throws Exception {
0625: assertFalse(new ExpressionInfo(
0626: "call(void test.expression.Target.parameters5())",
0627: NAMESPACE).getExpression().match(
0628: new ExpressionContext(PointcutType.CALL, parameters5,
0629: null)));
0630: assertTrue(new ExpressionInfo(
0631: "call(void test.expression.Target.parameters5(..))",
0632: NAMESPACE).getExpression().match(
0633: new ExpressionContext(PointcutType.CALL, parameters5,
0634: null)));
0635: assertFalse(new ExpressionInfo(
0636: "call(void test.expression.Target.parameters5(int))",
0637: NAMESPACE).getExpression().match(
0638: new ExpressionContext(PointcutType.CALL, parameters5,
0639: null)));
0640: assertFalse(new ExpressionInfo(
0641: "call(void test.expression.Target.parameters5(int[]))",
0642: NAMESPACE).getExpression().match(
0643: new ExpressionContext(PointcutType.CALL, parameters5,
0644: null)));
0645: assertTrue(new ExpressionInfo(
0646: "call(void test.expression.Target.parameters5(int[][]))",
0647: NAMESPACE).getExpression().match(
0648: new ExpressionContext(PointcutType.CALL, parameters5,
0649: null)));
0650: assertFalse(new ExpressionInfo(
0651: "call(void test.expression.Target.parameters5(int[][][]))",
0652: NAMESPACE).getExpression().match(
0653: new ExpressionContext(PointcutType.CALL, parameters5,
0654: null)));
0655: }
0656:
0657: // ============ method return type test =============
0658: public void testMethodReturnType1() throws Exception {
0659: assertTrue(new ExpressionInfo(
0660: "call(void test.expression.Target.returnType1())",
0661: NAMESPACE).getExpression().match(
0662: new ExpressionContext(PointcutType.CALL, returnType1,
0663: null)));
0664: assertFalse(new ExpressionInfo(
0665: "call(String test.expression.Target.returnType1())",
0666: NAMESPACE).getExpression().match(
0667: new ExpressionContext(PointcutType.CALL, returnType1,
0668: null)));
0669: assertTrue(new ExpressionInfo(
0670: "call(* test.expression.Target.returnType1())",
0671: NAMESPACE).getExpression().match(
0672: new ExpressionContext(PointcutType.CALL, returnType1,
0673: null)));
0674: }
0675:
0676: public void testMethodReturnType2() throws Exception {
0677: assertFalse(new ExpressionInfo(
0678: "call(void test.expression.Target.returnType2())",
0679: NAMESPACE).getExpression().match(
0680: new ExpressionContext(PointcutType.CALL, returnType2,
0681: null)));
0682: assertFalse(new ExpressionInfo(
0683: "call(String test.expression.Target.returnType2())",
0684: NAMESPACE).getExpression().match(
0685: new ExpressionContext(PointcutType.CALL, returnType2,
0686: null)));
0687: assertTrue(new ExpressionInfo(
0688: "call(* test.expression.Target.returnType2())",
0689: NAMESPACE).getExpression().match(
0690: new ExpressionContext(PointcutType.CALL, returnType2,
0691: null)));
0692: assertTrue(new ExpressionInfo(
0693: "call(int test.expression.Target.returnType2())",
0694: NAMESPACE).getExpression().match(
0695: new ExpressionContext(PointcutType.CALL, returnType2,
0696: null)));
0697: assertFalse(new ExpressionInfo(
0698: "call(int[] test.expression.Target.returnType2())",
0699: NAMESPACE).getExpression().match(
0700: new ExpressionContext(PointcutType.CALL, returnType2,
0701: null)));
0702: }
0703:
0704: public void testMethodReturnType3() throws Exception {
0705: assertFalse(new ExpressionInfo(
0706: "call(void test.expression.Target.returnType3())",
0707: NAMESPACE).getExpression().match(
0708: new ExpressionContext(PointcutType.CALL, returnType3,
0709: null)));
0710: assertTrue(new ExpressionInfo(
0711: "call(String test.expression.Target.returnType3())",
0712: NAMESPACE).getExpression().match(
0713: new ExpressionContext(PointcutType.CALL, returnType3,
0714: null)));
0715: assertTrue(new ExpressionInfo(
0716: "call(* test.expression.Target.returnType3())",
0717: NAMESPACE).getExpression().match(
0718: new ExpressionContext(PointcutType.CALL, returnType3,
0719: null)));
0720: assertTrue(new ExpressionInfo(
0721: "call(java.lang.String* test.expression.Target.returnType3())",
0722: NAMESPACE).getExpression().match(
0723: new ExpressionContext(PointcutType.CALL, returnType3,
0724: null)));
0725: assertFalse(new ExpressionInfo(
0726: "call(java.lang.StringBuffer test.expression.Target.returnType3())",
0727: NAMESPACE).getExpression().match(
0728: new ExpressionContext(PointcutType.CALL, returnType3,
0729: null)));
0730: }
0731:
0732: public void testMethodReturnType4() throws Exception {
0733: assertFalse(new ExpressionInfo(
0734: "call(void test.expression.Target.returnType4())",
0735: NAMESPACE).getExpression().match(
0736: new ExpressionContext(PointcutType.CALL, returnType4,
0737: null)));
0738: assertTrue(new ExpressionInfo(
0739: "call(Process test.expression.Target.returnType4())",
0740: NAMESPACE).getExpression().match(
0741: new ExpressionContext(PointcutType.CALL, returnType4,
0742: null)));
0743: assertTrue(new ExpressionInfo(
0744: "call(* test.expression.Target.returnType4())",
0745: NAMESPACE).getExpression().match(
0746: new ExpressionContext(PointcutType.CALL, returnType4,
0747: null)));
0748: assertTrue(new ExpressionInfo(
0749: "call(java.lang.Process test.expression.Target.returnType4())",
0750: NAMESPACE).getExpression().match(
0751: new ExpressionContext(PointcutType.CALL, returnType4,
0752: null)));
0753: assertTrue(new ExpressionInfo(
0754: "call(java.lang.* test.expression.Target.returnType4())",
0755: NAMESPACE).getExpression().match(
0756: new ExpressionContext(PointcutType.CALL, returnType4,
0757: null)));
0758: assertTrue(new ExpressionInfo(
0759: "call(java..* test.expression.Target.returnType4())",
0760: NAMESPACE).getExpression().match(
0761: new ExpressionContext(PointcutType.CALL, returnType4,
0762: null)));
0763: assertTrue(new ExpressionInfo(
0764: "call(java.*.Process test.expression.Target.returnType4())",
0765: NAMESPACE).getExpression().match(
0766: new ExpressionContext(PointcutType.CALL, returnType4,
0767: null)));
0768: }
0769:
0770: public void testMethodReturnType5() throws Exception {
0771: assertFalse(new ExpressionInfo(
0772: "call(void test.expression.Target.returnType5())",
0773: NAMESPACE).getExpression().match(
0774: new ExpressionContext(PointcutType.CALL, returnType5,
0775: null)));
0776: assertFalse(new ExpressionInfo(
0777: "call(float test.expression.Target.returnType5())",
0778: NAMESPACE).getExpression().match(
0779: new ExpressionContext(PointcutType.CALL, returnType5,
0780: null)));
0781: assertFalse(new ExpressionInfo(
0782: "call(float[] test.expression.Target.returnType5())",
0783: NAMESPACE).getExpression().match(
0784: new ExpressionContext(PointcutType.CALL, returnType5,
0785: null)));
0786: assertTrue(new ExpressionInfo(
0787: "call(float[][] test.expression.Target.returnType5())",
0788: NAMESPACE).getExpression().match(
0789: new ExpressionContext(PointcutType.CALL, returnType5,
0790: null)));
0791: assertTrue(new ExpressionInfo(
0792: "call(* test.expression.Target.returnType5())",
0793: NAMESPACE).getExpression().match(
0794: new ExpressionContext(PointcutType.CALL, returnType5,
0795: null)));
0796: }
0797:
0798: // ============ method name test =============
0799: public void testMethodName() throws Exception {
0800: assertTrue(new ExpressionInfo(
0801: "call(void test.expression.Target.__method$Name1())",
0802: NAMESPACE).getExpression().match(
0803: new ExpressionContext(PointcutType.CALL, _method$Name1,
0804: null)));
0805: assertTrue(new ExpressionInfo(
0806: "call(void test.expression.Target.__method$*())",
0807: NAMESPACE).getExpression().match(
0808: new ExpressionContext(PointcutType.CALL, _method$Name1,
0809: null)));
0810: assertTrue(new ExpressionInfo(
0811: "call(void test.expression.Target.*Name1())", NAMESPACE)
0812: .getExpression().match(
0813: new ExpressionContext(PointcutType.CALL,
0814: _method$Name1, null)));
0815: assertTrue(new ExpressionInfo(
0816: "call(void test.expression.Target.*$*())", NAMESPACE)
0817: .getExpression().match(
0818: new ExpressionContext(PointcutType.CALL,
0819: _method$Name1, null)));
0820: assertTrue(new ExpressionInfo(
0821: "call(void test.expression.*.__method$Name1())",
0822: NAMESPACE).getExpression().match(
0823: new ExpressionContext(PointcutType.CALL, _method$Name1,
0824: null)));
0825: assertTrue(new ExpressionInfo(
0826: "call(void test..*.__method$Name1())", NAMESPACE)
0827: .getExpression().match(
0828: new ExpressionContext(PointcutType.CALL,
0829: _method$Name1, null)));
0830: assertTrue(new ExpressionInfo("call(void test..*.*())",
0831: NAMESPACE).getExpression().match(
0832: new ExpressionContext(PointcutType.CALL, _method$Name1,
0833: null)));
0834: assertFalse(new ExpressionInfo(
0835: "call(void test.expression.Target.__Method$Name1())",
0836: NAMESPACE).getExpression().match(
0837: new ExpressionContext(PointcutType.CALL, _method$Name1,
0838: null)));
0839: assertFalse(new ExpressionInfo(
0840: "call(void test.expression.Target.__method$Name())",
0841: NAMESPACE).getExpression().match(
0842: new ExpressionContext(PointcutType.CALL, _method$Name1,
0843: null)));
0844: assertFalse(new ExpressionInfo(
0845: "call(void test.expression.Target._methodName1())",
0846: NAMESPACE).getExpression().match(
0847: new ExpressionContext(PointcutType.CALL, _method$Name1,
0848: null)));
0849: assertTrue(new ExpressionInfo("execution(* __method$Name1())",
0850: NAMESPACE).getExpression().match(
0851: new ExpressionContext(PointcutType.EXECUTION,
0852: _method$Name1, null)));
0853: assertTrue(new ExpressionInfo(
0854: "within(test.expression.Target) && execution(* __method$Name1())",
0855: NAMESPACE).getExpression()
0856: .match(
0857: new ExpressionContext(PointcutType.EXECUTION,
0858: _method$Name1, _method$Name1
0859: .getDeclaringType())));
0860: //AW-112 below
0861: assertTrue(new ExpressionInfo(
0862: "within(test.expression.Target) && execution(* __method$Name1())",
0863: NAMESPACE).getExpression()
0864: .match(
0865: new ExpressionContext(PointcutType.EXECUTION,
0866: _method$Name1, _method$Name1
0867: .getDeclaringType())));
0868: assertTrue(new ExpressionInfo(
0869: "execution(* test.expression..*(..)) && execution(* *..Target.__method$Name1())",
0870: NAMESPACE).getExpression()
0871: .match(
0872: new ExpressionContext(PointcutType.EXECUTION,
0873: _method$Name1, _method$Name1
0874: .getDeclaringType())));
0875: assertTrue(new ExpressionInfo(
0876: "execution(* test.expression..*.*(..)) && execution(* *..Target.__method$Name1())",
0877: NAMESPACE).getExpression()
0878: .match(
0879: new ExpressionContext(PointcutType.EXECUTION,
0880: _method$Name1, _method$Name1
0881: .getDeclaringType())));
0882: assertTrue(new ExpressionInfo(
0883: "execution(* test..*(..)) && execution(* *.expression.Target.__method$Name1())",
0884: NAMESPACE).getExpression()
0885: .match(
0886: new ExpressionContext(PointcutType.EXECUTION,
0887: _method$Name1, _method$Name1
0888: .getDeclaringType())));
0889: assertTrue(new ExpressionInfo(
0890: "execution(* test..*.*(..)) && execution(* *.expression.Target.__method$Name1())",
0891: NAMESPACE).getExpression()
0892: .match(
0893: new ExpressionContext(PointcutType.EXECUTION,
0894: _method$Name1, _method$Name1
0895: .getDeclaringType())));
0896:
0897: assertTrue(new ExpressionInfo(
0898: "execution(* test.expression.Target+.*(..)) && !execution(* returnType*(..))",
0899: NAMESPACE).getExpression()
0900: .match(
0901: new ExpressionContext(PointcutType.EXECUTION,
0902: _method$Name1, _method$Name1
0903: .getDeclaringType())));
0904: assertTrue(new ExpressionInfo(
0905: "execution(* test.expression.Target+.*(..)) && !execution(* returnType*(..))",
0906: NAMESPACE).getAdvisedClassFilterExpression()
0907: .match(
0908: new ExpressionContext(PointcutType.EXECUTION,
0909: _method$Name1, _method$Name1
0910: .getDeclaringType())));
0911: assertFalse(new ExpressionInfo(
0912: "execution(* test.expression.Target+.*(..)) && !execution(* returnType*(..))",
0913: NAMESPACE).getExpression().match(
0914: new ExpressionContext(PointcutType.EXECUTION,
0915: returnType1, returnType1.getDeclaringType())));
0916: }
0917:
0918: // ============ method attribute test =============
0919: public void testMethodAttributes1() throws Exception {
0920: assertTrue(new ExpressionInfo(
0921: "call(void test.expression.Target.attributes1())",
0922: NAMESPACE).getExpression().match(
0923: new ExpressionContext(PointcutType.CALL, attributes1,
0924: null)));
0925: assertTrue(new ExpressionInfo(
0926: "call(@Requires void test.expression.Target.attributes1())",
0927: NAMESPACE).getExpression().match(
0928: new ExpressionContext(PointcutType.CALL, attributes1,
0929: null)));
0930: assertFalse(new ExpressionInfo(
0931: "call(@RequiresNew void test.expression.Target.attributes1())",
0932: NAMESPACE).getExpression().match(
0933: new ExpressionContext(PointcutType.CALL, attributes1,
0934: null)));
0935: assertFalse(new ExpressionInfo(
0936: "call(@Requires @RequiresNew void test.expression.Target.attributes1())",
0937: NAMESPACE).getExpression().match(
0938: new ExpressionContext(PointcutType.CALL, attributes1,
0939: null)));
0940: }
0941:
0942: // ============ field modifier test =============
0943: public void testFieldModifiers1() throws Exception {
0944: assertTrue(new ExpressionInfo(
0945: "set(int test.expression.Target.modifier1)", NAMESPACE)
0946: .getExpression().match(
0947: new ExpressionContext(PointcutType.SET,
0948: modifier1, null)));
0949: assertFalse(new ExpressionInfo(
0950: "set(public int test.expression.Target.modifier1)",
0951: NAMESPACE).getExpression()
0952: .match(
0953: new ExpressionContext(PointcutType.SET,
0954: modifier1, null)));
0955: assertFalse(new ExpressionInfo(
0956: "set(public int test.expression.Target.modifier1)",
0957: NAMESPACE).getExpression()
0958: .match(
0959: new ExpressionContext(PointcutType.SET,
0960: modifier1, null)));
0961: }
0962:
0963: public void testFieldModifiers2() throws Exception {
0964: assertTrue(new ExpressionInfo(
0965: "set(int test.expression.Target.modifier2)", NAMESPACE)
0966: .getExpression().match(
0967: new ExpressionContext(PointcutType.SET,
0968: modifier2, null)));
0969: assertTrue(new ExpressionInfo(
0970: "set(public int test.expression.Target.modifier2)",
0971: NAMESPACE).getExpression()
0972: .match(
0973: new ExpressionContext(PointcutType.SET,
0974: modifier2, null)));
0975: assertTrue(new ExpressionInfo(
0976: "set(static public int test.expression.Target.modifier2)",
0977: NAMESPACE).getExpression()
0978: .match(
0979: new ExpressionContext(PointcutType.SET,
0980: modifier2, null)));
0981: assertTrue(new ExpressionInfo(
0982: "set(static int test.expression.Target.modifier2)",
0983: NAMESPACE).getExpression()
0984: .match(
0985: new ExpressionContext(PointcutType.SET,
0986: modifier2, null)));
0987: assertFalse(new ExpressionInfo(
0988: "set(protected int test.expression.Target.modifier2)",
0989: NAMESPACE).getExpression()
0990: .match(
0991: new ExpressionContext(PointcutType.SET,
0992: modifier2, null)));
0993: }
0994:
0995: public void testFieldModifiers3() throws Exception {
0996: assertTrue(new ExpressionInfo(
0997: "set(int test.expression.Target.modifier3)", NAMESPACE)
0998: .getExpression().match(
0999: new ExpressionContext(PointcutType.SET,
1000: modifier3, null)));
1001: assertTrue(new ExpressionInfo(
1002: "set(protected int test.expression.Target.modifier3)",
1003: NAMESPACE).getExpression()
1004: .match(
1005: new ExpressionContext(PointcutType.SET,
1006: modifier3, null)));
1007: assertTrue(new ExpressionInfo(
1008: "set(static protected int test.expression.Target.modifier3)",
1009: NAMESPACE).getExpression()
1010: .match(
1011: new ExpressionContext(PointcutType.SET,
1012: modifier3, null)));
1013: assertTrue(new ExpressionInfo(
1014: "set(static int test.expression.Target.modifier3)",
1015: NAMESPACE).getExpression()
1016: .match(
1017: new ExpressionContext(PointcutType.SET,
1018: modifier3, null)));
1019: assertTrue(new ExpressionInfo(
1020: "set(transient int test.expression.Target.modifier3)",
1021: NAMESPACE).getExpression()
1022: .match(
1023: new ExpressionContext(PointcutType.SET,
1024: modifier3, null)));
1025: assertTrue(new ExpressionInfo(
1026: "set(static transient protected final int test.expression.Target.modifier3)",
1027: NAMESPACE).getExpression()
1028: .match(
1029: new ExpressionContext(PointcutType.SET,
1030: modifier3, null)));
1031: assertFalse(new ExpressionInfo(
1032: "set(public int test.expression.Target.modifier3)",
1033: NAMESPACE).getExpression()
1034: .match(
1035: new ExpressionContext(PointcutType.SET,
1036: modifier3, null)));
1037: }
1038:
1039: // public void testFieldModifiers4() throws Exception {
1040: // assertTrue(new ExpressionInfo("set(!private int test.expression.Target.modifier2)",
1041: // NAMESPACE).getExpression().parse(new ExpressionContext(PointcutType.SET,
1042: // modifier2,
1043: // null)));
1044: // assertFalse(new ExpressionInfo("set(!public int test.expression.Target.modifier2)",
1045: // NAMESPACE).getExpression()
1046: // .parse(new ExpressionContext(PointcutType.SET,
1047: // modifier2,
1048: // null)));
1049: // assertFalse(new ExpressionInfo("set(public !static int test.expression.Target.modifier2)",
1050: // NAMESPACE).getExpression()
1051: // .parse(new ExpressionContext(PointcutType.SET,
1052: // modifier2,
1053: // null)));
1054: // }
1055: // ============ field type test =============
1056: public void testFieldType1() throws Exception {
1057: assertTrue(new ExpressionInfo(
1058: "set(int test.expression.Target.type1)", NAMESPACE)
1059: .getExpression().match(
1060: new ExpressionContext(PointcutType.SET, type1,
1061: null)));
1062: assertTrue(new ExpressionInfo(
1063: "set(* test.expression.Target.type1)", NAMESPACE)
1064: .getExpression().match(
1065: new ExpressionContext(PointcutType.SET, type1,
1066: null)));
1067: assertFalse(new ExpressionInfo(
1068: "set(Integer test.expression.Target.type1)", NAMESPACE)
1069: .getExpression().match(
1070: new ExpressionContext(PointcutType.SET, type1,
1071: null)));
1072: assertFalse(new ExpressionInfo(
1073: "set(int[] test.expression.Target.type1)", NAMESPACE)
1074: .getExpression().match(
1075: new ExpressionContext(PointcutType.SET, type1,
1076: null)));
1077: }
1078:
1079: public void testFieldType2() throws Exception {
1080: assertFalse(new ExpressionInfo(
1081: "set(int test.expression.Target.type2)", NAMESPACE)
1082: .getExpression().match(
1083: new ExpressionContext(PointcutType.SET, type2,
1084: null)));
1085: assertTrue(new ExpressionInfo(
1086: "set(* test.expression.Target.type2)", NAMESPACE)
1087: .getExpression().match(
1088: new ExpressionContext(PointcutType.SET, type2,
1089: null)));
1090: assertFalse(new ExpressionInfo(
1091: "set(Integer test.expression.Target.type2)", NAMESPACE)
1092: .getExpression().match(
1093: new ExpressionContext(PointcutType.SET, type2,
1094: null)));
1095: assertFalse(new ExpressionInfo(
1096: "set(int[] test.expression.Target.type2)", NAMESPACE)
1097: .getExpression().match(
1098: new ExpressionContext(PointcutType.SET, type2,
1099: null)));
1100: assertTrue(new ExpressionInfo(
1101: "set(int[][] test.expression.Target.type2)", NAMESPACE)
1102: .getExpression().match(
1103: new ExpressionContext(PointcutType.SET, type2,
1104: null)));
1105: }
1106:
1107: public void testFieldType3() throws Exception {
1108: assertTrue(new ExpressionInfo(
1109: "set(String test.expression.Target.type3)", NAMESPACE)
1110: .getExpression().match(
1111: new ExpressionContext(PointcutType.SET, type3,
1112: null)));
1113: assertTrue(new ExpressionInfo(
1114: "set(java.lang.String test.expression.Target.type3)",
1115: NAMESPACE).getExpression().match(
1116: new ExpressionContext(PointcutType.SET, type3, null)));
1117: assertFalse(new ExpressionInfo(
1118: "set(java.lang.string test.expression.Target.type3)",
1119: NAMESPACE).getExpression().match(
1120: new ExpressionContext(PointcutType.SET, type3, null)));
1121: assertTrue(new ExpressionInfo(
1122: "set(java..* test.expression.Target.type3)", NAMESPACE)
1123: .getExpression().match(
1124: new ExpressionContext(PointcutType.SET, type3,
1125: null)));
1126: assertTrue(new ExpressionInfo(
1127: "set(java.*.String test.expression.Target.type3)",
1128: NAMESPACE).getExpression().match(
1129: new ExpressionContext(PointcutType.SET, type3, null)));
1130: assertTrue(new ExpressionInfo(
1131: "set(java.lang.String* test.expression.Target.type3)",
1132: NAMESPACE).getExpression().match(
1133: new ExpressionContext(PointcutType.SET, type3, null)));
1134: assertTrue(new ExpressionInfo(
1135: "set(* test.expression.Target.type3)", NAMESPACE)
1136: .getExpression().match(
1137: new ExpressionContext(PointcutType.SET, type3,
1138: null)));
1139: assertFalse(new ExpressionInfo(
1140: "set(StringBuffer test.expression.Target.type3)",
1141: NAMESPACE).getExpression().match(
1142: new ExpressionContext(PointcutType.SET, type3, null)));
1143: assertFalse(new ExpressionInfo(
1144: "set(java.lang.StringBuffer test.expression.Target.type3)",
1145: NAMESPACE).getExpression().match(
1146: new ExpressionContext(PointcutType.SET, type3, null)));
1147: assertFalse(new ExpressionInfo(
1148: "set(String[] test.expression.Target.type3)", NAMESPACE)
1149: .getExpression().match(
1150: new ExpressionContext(PointcutType.SET, type3,
1151: null)));
1152: assertFalse(new ExpressionInfo(
1153: "set(java.lang.String[] test.expression.Target.type3)",
1154: NAMESPACE).getExpression().match(
1155: new ExpressionContext(PointcutType.SET, type3, null)));
1156: }
1157:
1158: public void testFieldType4() throws Exception {
1159: assertFalse(new ExpressionInfo(
1160: "set(String test.expression.Target.type4)", NAMESPACE)
1161: .getExpression().match(
1162: new ExpressionContext(PointcutType.SET, type4,
1163: null)));
1164: assertFalse(new ExpressionInfo(
1165: "set(java.lang.String test.expression.Target.type4)",
1166: NAMESPACE).getExpression().match(
1167: new ExpressionContext(PointcutType.SET, type4, null)));
1168: assertTrue(new ExpressionInfo(
1169: "set(String[] test.expression.Target.type4)", NAMESPACE)
1170: .getExpression().match(
1171: new ExpressionContext(PointcutType.SET, type4,
1172: null)));
1173: assertTrue(new ExpressionInfo(
1174: "set(java.lang.String[] test.expression.Target.type4)",
1175: NAMESPACE).getExpression().match(
1176: new ExpressionContext(PointcutType.SET, type4, null)));
1177: assertTrue(new ExpressionInfo(
1178: "set(* test.expression.Target.type4)", NAMESPACE)
1179: .getExpression().match(
1180: new ExpressionContext(PointcutType.SET, type4,
1181: null)));
1182: assertFalse(new ExpressionInfo(
1183: "set(String[][] test.expression.Target.type4)",
1184: NAMESPACE).getExpression().match(
1185: new ExpressionContext(PointcutType.SET, type4, null)));
1186: assertFalse(new ExpressionInfo(
1187: "set(int[] test.expression.Target.type4)", NAMESPACE)
1188: .getExpression().match(
1189: new ExpressionContext(PointcutType.SET, type4,
1190: null)));
1191: }
1192:
1193: // ============ field name test =============
1194: public void testFieldName() throws Exception {
1195: assertTrue(new ExpressionInfo(
1196: "set(int test.expression.Target.__field$Name1)",
1197: NAMESPACE).getExpression().match(
1198: new ExpressionContext(PointcutType.SET, _field$Name1,
1199: null)));
1200: assertFalse(new ExpressionInfo(
1201: "set(int test.expression.Target.field$Name1)",
1202: NAMESPACE).getExpression().match(
1203: new ExpressionContext(PointcutType.SET, _field$Name1,
1204: null)));
1205: assertTrue(new ExpressionInfo(
1206: "set(int test.expression.Target.__*$Name*)", NAMESPACE)
1207: .getExpression().match(
1208: new ExpressionContext(PointcutType.SET,
1209: _field$Name1, null)));
1210: assertTrue(new ExpressionInfo(
1211: "set(int test.expression.Target.__field*)", NAMESPACE)
1212: .getExpression().match(
1213: new ExpressionContext(PointcutType.SET,
1214: _field$Name1, null)));
1215: assertTrue(new ExpressionInfo(
1216: "set(int test.expression.*.__field$Name1)", NAMESPACE)
1217: .getExpression().match(
1218: new ExpressionContext(PointcutType.SET,
1219: _field$Name1, null)));
1220: assertTrue(new ExpressionInfo(
1221: "set(int test..Target.__field$Name1)", NAMESPACE)
1222: .getExpression().match(
1223: new ExpressionContext(PointcutType.SET,
1224: _field$Name1, null)));
1225: assertTrue(new ExpressionInfo("set(int test..*.__field$Name1)",
1226: NAMESPACE).getExpression().match(
1227: new ExpressionContext(PointcutType.SET, _field$Name1,
1228: null)));
1229: assertFalse(new ExpressionInfo("set(int test..*.__fieldName1)",
1230: NAMESPACE).getExpression().match(
1231: new ExpressionContext(PointcutType.SET, _field$Name1,
1232: null)));
1233: // AW-112 below
1234: assertTrue(new ExpressionInfo(
1235: "within(test.expression.Target) && set(int __field$Name1)",
1236: NAMESPACE).getExpression().match(
1237: new ExpressionContext(PointcutType.SET, _field$Name1,
1238: null)));
1239: assertTrue(new ExpressionInfo(
1240: "within(*.expression.Target) && set(int test..__field$Name1)",
1241: NAMESPACE).getExpression().match(
1242: new ExpressionContext(PointcutType.SET, _field$Name1,
1243: null)));
1244:
1245: }
1246:
1247: // ============ field attribute test =============
1248: public void testFieldAttributes1() throws Exception {
1249: assertTrue(new ExpressionInfo(
1250: "set(int test.expression.Target.attribute1)", NAMESPACE)
1251: .getExpression().match(
1252: new ExpressionContext(PointcutType.SET,
1253: attribute1, null)));
1254: assertTrue(new ExpressionInfo(
1255: "set(@ReadOnly int test.expression.Target.attribute1)",
1256: NAMESPACE).getExpression().match(
1257: new ExpressionContext(PointcutType.SET, attribute1,
1258: null)));
1259: assertFalse(new ExpressionInfo(
1260: "set(@Read int test.expression.Target.attribute1)",
1261: NAMESPACE).getExpression().match(
1262: new ExpressionContext(PointcutType.SET, attribute1,
1263: null)));
1264: assertFalse(new ExpressionInfo(
1265: "set(@ReadOnly @ReadWrite int test.expression.Target.attribute1)",
1266: NAMESPACE).getExpression().match(
1267: new ExpressionContext(PointcutType.SET, attribute1,
1268: null)));
1269: }
1270:
1271: // ============ class modifier test =============
1272: public void testClassModifier() throws Exception {
1273: assertTrue(new ExpressionInfo("within(test.expression.Target)",
1274: NAMESPACE).getExpression().match(
1275: new ExpressionContext(PointcutType.HANDLER,
1276: s_declaringType, s_declaringType)));
1277: assertTrue(new ExpressionInfo(
1278: "within(public test.expression.Target)", NAMESPACE)
1279: .getExpression().match(
1280: new ExpressionContext(PointcutType.HANDLER,
1281: s_declaringType, s_declaringType)));
1282: assertFalse(new ExpressionInfo(
1283: "within(protected test.expression.Target)", NAMESPACE)
1284: .getExpression().match(
1285: new ExpressionContext(PointcutType.HANDLER,
1286: s_declaringType, s_declaringType)));
1287: assertTrue(new ExpressionInfo(
1288: "within(final public test.expression.Target)",
1289: NAMESPACE).getExpression().match(
1290: new ExpressionContext(PointcutType.HANDLER,
1291: s_declaringType, s_declaringType)));
1292:
1293: // assertFalse(
1294: // new ExpressionInfo( "within(abstract test.expression.Target)", NAMESPACE).
1295: // getExpression().parse(new ExpressionContext( PointcutType.HANDLER, klass, klass))
1296: //
1297: // );
1298: }
1299:
1300: // ============ class type test =============
1301: public void testClassType() throws Exception {
1302: assertTrue(new ExpressionInfo("within(test.expression.Target)",
1303: NAMESPACE).getExpression().match(
1304: new ExpressionContext(PointcutType.WITHIN,
1305: s_declaringType, s_declaringType)));
1306: assertTrue(new ExpressionInfo("within(*)", NAMESPACE)
1307: .getExpression().match(
1308: new ExpressionContext(PointcutType.HANDLER,
1309: s_declaringType, s_declaringType)));
1310: assertTrue(new ExpressionInfo("within(..)", NAMESPACE)
1311: .getExpression().match(
1312: new ExpressionContext(PointcutType.HANDLER,
1313: s_declaringType, s_declaringType)));
1314: assertTrue(new ExpressionInfo("within(public *)", NAMESPACE)
1315: .getExpression().match(
1316: new ExpressionContext(PointcutType.HANDLER,
1317: s_declaringType, s_declaringType)));
1318: assertTrue(new ExpressionInfo("within(test.*.Target)",
1319: NAMESPACE).getExpression().match(
1320: new ExpressionContext(PointcutType.HANDLER,
1321: s_declaringType, s_declaringType)));
1322: assertTrue(new ExpressionInfo("within(test.expression.*)",
1323: NAMESPACE).getExpression().match(
1324: new ExpressionContext(PointcutType.HANDLER,
1325: s_declaringType, s_declaringType)));
1326: assertTrue(new ExpressionInfo("within(test.expression.Tar*)",
1327: NAMESPACE).getExpression().match(
1328: new ExpressionContext(PointcutType.HANDLER,
1329: s_declaringType, s_declaringType)));
1330: assertTrue(new ExpressionInfo("within(test.expression.T*et)",
1331: NAMESPACE).getExpression().match(
1332: new ExpressionContext(PointcutType.HANDLER,
1333: s_declaringType, s_declaringType)));
1334: assertTrue(new ExpressionInfo("within(test..*)", NAMESPACE)
1335: .getExpression().match(
1336: new ExpressionContext(PointcutType.HANDLER,
1337: s_declaringType, s_declaringType)));
1338: assertTrue(new ExpressionInfo("within(*.expression.*)",
1339: NAMESPACE).getExpression().match(
1340: new ExpressionContext(PointcutType.HANDLER,
1341: s_declaringType, s_declaringType)));
1342: assertFalse(new ExpressionInfo(
1343: "within(test.expression.target)", NAMESPACE)
1344: .getExpression().match(
1345: new ExpressionContext(PointcutType.HANDLER,
1346: s_declaringType, s_declaringType)));
1347: assertFalse(new ExpressionInfo(
1348: "within(test.expression.Targett)", NAMESPACE)
1349: .getExpression().match(
1350: new ExpressionContext(PointcutType.HANDLER,
1351: s_declaringType, s_declaringType)));
1352: assertFalse(new ExpressionInfo("within(test.*.*.Target)",
1353: NAMESPACE).getExpression().match(
1354: new ExpressionContext(PointcutType.HANDLER,
1355: s_declaringType, s_declaringType)));
1356: }
1357:
1358: public void testClassTypeEarlyFiltering() throws Exception {
1359: ExpressionNamespace.getNamespace(NAMESPACE).addExpressionInfo(
1360: "pcWithinForCall",
1361: new ExpressionInfo("within(test.expression.Target)",
1362: NAMESPACE));
1363: ExpressionInfo referenceToWithin = new ExpressionInfo(
1364: "pcWithinForCall AND execution(* modifiers1(..))",
1365: NAMESPACE);
1366: assertTrue(referenceToWithin.getAdvisedClassFilterExpression()
1367: .match(
1368: new ExpressionContext(PointcutType.EXECUTION,
1369: modifiers1, s_declaringType)));
1370: ExpressionNamespace.getNamespace(NAMESPACE).addExpressionInfo(
1371: "pcWithinForCall2",
1372: new ExpressionInfo(
1373: "within(test.expression.TargetNOMATCH)",
1374: NAMESPACE));
1375: ExpressionInfo referenceToWithin2 = new ExpressionInfo(
1376: "pcWithinForCall2 AND execution(* modifiers1(..))",
1377: NAMESPACE);
1378: assertFalse(referenceToWithin2
1379: .getAdvisedClassFilterExpression().match(
1380: new ExpressionContext(PointcutType.EXECUTION,
1381: modifiers1, s_declaringType)));
1382: }
1383:
1384: // ============ class attribute test =============
1385: public void testClassAttribute1() throws Exception {
1386: assertTrue(new ExpressionInfo("within(test.expression.Target)",
1387: NAMESPACE).getExpression().match(
1388: new ExpressionContext(PointcutType.HANDLER,
1389: s_declaringType, s_declaringType)));
1390: assertTrue(new ExpressionInfo(
1391: "within(@Serializable test.expression.Target)",
1392: NAMESPACE).getExpression().match(
1393: new ExpressionContext(PointcutType.HANDLER,
1394: s_declaringType, s_declaringType)));
1395: assertFalse(new ExpressionInfo(
1396: "within(!@Serializable test.expression.Target)",
1397: NAMESPACE).getExpression().match(
1398: new ExpressionContext(PointcutType.HANDLER,
1399: s_declaringType, s_declaringType)));
1400: assertTrue(new ExpressionInfo(
1401: "within(!@NotHereSerializable test.expression.Target)",
1402: NAMESPACE).getExpression().match(
1403: new ExpressionContext(PointcutType.HANDLER,
1404: s_declaringType, s_declaringType)));
1405: assertTrue(new ExpressionInfo(
1406: "within(@Serializable public final test.expression.Target)",
1407: NAMESPACE).getExpression().match(
1408: new ExpressionContext(PointcutType.HANDLER,
1409: s_declaringType, s_declaringType)));
1410: assertFalse(new ExpressionInfo(
1411: "within(@Serializable @Dummy test.expression.Target)",
1412: NAMESPACE).getExpression().match(
1413: new ExpressionContext(PointcutType.HANDLER,
1414: s_declaringType, s_declaringType)));
1415: }
1416:
1417: // Tests: http://jira.codehaus.org/browse/AW-223
1418: public void testClassAttribute2() throws Exception {
1419: MethodInfo method = JavaMethodInfo.getMethodInfo(Target.class
1420: .getDeclaredMethod("modifiers1", new Class[] {}));
1421: assertTrue(new ExpressionInfo(
1422: "execution(void test.expression.*.*(..)) AND within(@Serializable *..*)",
1423: NAMESPACE).getExpression().match(
1424: new ExpressionContext(PointcutType.EXECUTION, method,
1425: s_declaringType)));
1426: assertFalse(new ExpressionInfo(
1427: "execution(void test.expression.*.*(..)) AND within(@FakeAnnotation *..*)",
1428: NAMESPACE).getExpression().match(
1429: new ExpressionContext(PointcutType.EXECUTION, method,
1430: s_declaringType)));
1431: }
1432:
1433: // ============ pointcut type tests =============
1434: public void testPointcutTypes() throws Exception {
1435: MethodInfo method = JavaMethodInfo.getMethodInfo(Target.class
1436: .getDeclaredMethod("modifiers1", new Class[] {}));
1437: FieldInfo field = JavaFieldInfo.getFieldInfo(Target.class
1438: .getDeclaredField("modifier1"));
1439: assertTrue(new ExpressionInfo(
1440: "execution(void test.expression.Target.modifiers1())",
1441: NAMESPACE).getExpression().match(
1442: new ExpressionContext(PointcutType.EXECUTION, method,
1443: null)));
1444: assertFalse(new ExpressionInfo(
1445: "execution(void test.expression.Target.modifiers1())",
1446: NAMESPACE).getExpression().match(
1447: new ExpressionContext(PointcutType.CALL, method, null)));
1448: assertTrue(new ExpressionInfo(
1449: "set(int test.expression.Target.modifier1)", NAMESPACE)
1450: .getExpression().match(
1451: new ExpressionContext(PointcutType.SET, field,
1452: null)));
1453: assertFalse(new ExpressionInfo(
1454: "get(int test.expression.Target.modifier1)", NAMESPACE)
1455: .getExpression().match(
1456: new ExpressionContext(PointcutType.SET, field,
1457: null)));
1458: try {
1459: assertFalse(new ExpressionInfo(
1460: "set(int test.expression.Target.modifier1())",
1461: NAMESPACE).getExpression().match(
1462: new ExpressionContext(PointcutType.SET, method,
1463: null)));
1464: } catch (Throwable e) {
1465: return;
1466: }
1467: fail("expected exception");
1468: }
1469:
1470: // ============ advised class tests =============
1471: public void testAdvisedClassExpression() throws Exception {
1472: ClassInfo otherType = JavaClassInfo.getClassInfo(String.class);
1473: assertFalse(new ExpressionInfo(
1474: "execution(void test.expression.Target.modifiers1())",
1475: NAMESPACE).getAdvisedClassFilterExpression().match(
1476: new ExpressionContext(PointcutType.WITHIN, otherType,
1477: null)));
1478: assertTrue(new ExpressionInfo(
1479: "execution(void test.expression.Target.modifiers1())",
1480: NAMESPACE).getAdvisedClassFilterExpression().match(
1481: new ExpressionContext(PointcutType.WITHIN,
1482: s_declaringType, null)));
1483: assertTrue(new ExpressionInfo(
1484: "call(void test.expression.Target.modifiers1())",
1485: NAMESPACE).getAdvisedClassFilterExpression().match(
1486: new ExpressionContext(PointcutType.WITHIN,
1487: s_declaringType, null)));
1488: assertTrue(new ExpressionInfo(
1489: "set(int test.expression.Target.modifier1)", NAMESPACE)
1490: .getAdvisedClassFilterExpression().match(
1491: new ExpressionContext(PointcutType.WITHIN,
1492: s_declaringType, null)));
1493: assertTrue(new ExpressionInfo(
1494: "get(int test.expression.Target.modifier1)", NAMESPACE)
1495: .getAdvisedClassFilterExpression().match(
1496: new ExpressionContext(PointcutType.WITHIN,
1497: s_declaringType, null)));
1498:
1499: //DIGME all hanlder stuff there
1500: assertTrue(new ExpressionInfo(
1501: "handler(java.lang.Exception) && within(test.expression.Target)",
1502: NAMESPACE).getAdvisedClassFilterExpression().match(
1503: new ExpressionContext(PointcutType.WITHIN,
1504: s_declaringType, null)));
1505: assertTrue(new ExpressionInfo(
1506: "handler(java.lang.Exception) && within(test.expression.Target)",
1507: NAMESPACE).getAdvisedClassFilterExpression().match(
1508: new ExpressionContext(PointcutType.WITHIN,
1509: s_declaringType, s_declaringType)));
1510: assertTrue(new ExpressionInfo(
1511: "handler(java.lang.Exception) && withincode(void test.expression.Target.modifiers1())",
1512: NAMESPACE).getAdvisedClassFilterExpression().match(
1513: new ExpressionContext(PointcutType.WITHIN,
1514: s_declaringType, null)));
1515: assertTrue(new ExpressionInfo(
1516: "handler(java.lang.Exception) && !withincode(void test.expression.Target.modifiers1())",
1517: NAMESPACE).getAdvisedClassFilterExpression().match(
1518: new ExpressionContext(PointcutType.WITHIN, otherType,
1519: null)));
1520: assertFalse(new ExpressionInfo(
1521: "call(void test.expression.Dummy.modifiers1()) && within(test.expression.Target)",
1522: NAMESPACE).getAdvisedClassFilterExpression().match(
1523: new ExpressionContext(PointcutType.WITHIN,
1524: s_declaringType, null)));
1525: assertFalse(new ExpressionInfo(
1526: "call(void test.expression.Dummy.modifiers1()) && withincode(void test.expression.Target.modifiers1())",
1527: NAMESPACE).getAdvisedClassFilterExpression().match(
1528: new ExpressionContext(PointcutType.WITHIN,
1529: s_declaringType, null)));//fails on CALL
1530: assertFalse(new ExpressionInfo(
1531: "call(void test.expression.Target.modifiers1()) && withincode(void test.expression.TargetNOMATCH.modifiers1())",
1532: NAMESPACE).getAdvisedClassFilterExpression().match(
1533: new ExpressionContext(PointcutType.WITHIN,
1534: s_declaringType, s_declaringType)));//fails on WITHIN but withincode needs more info??
1535: assertTrue(new ExpressionInfo(
1536: "execution(void test.expression.Target.modifiers1()) OR execution(* java.lang.String.*(..))",
1537: NAMESPACE).getAdvisedClassFilterExpression().match(
1538: new ExpressionContext(PointcutType.WITHIN, otherType,
1539: null)));
1540:
1541: assertTrue(new ExpressionInfo(
1542: "execution(void test.expression.Target.modifiers1()) OR execution(* java.lang.String.*(..))",
1543: NAMESPACE).getAdvisedClassFilterExpression().match(
1544: new ExpressionContext(PointcutType.WITHIN,
1545: s_declaringType, null)));
1546: assertTrue(new ExpressionInfo(
1547: "execution(void test.expression.Target.modifiers1()) AND !execution(* java.lang.String.*(..))",
1548: NAMESPACE).getAdvisedClassFilterExpression().match(
1549: new ExpressionContext(PointcutType.WITHIN,
1550: s_declaringType, null)));
1551:
1552: // check that we ignore cflow
1553: assertTrue(new ExpressionInfo(
1554: "execution(void test.expression.Target.modifiers1()) AND cflow(execution(* *..*(..)))",
1555: NAMESPACE).getAdvisedClassFilterExpression().match(
1556: new ExpressionContext(PointcutType.WITHIN,
1557: s_declaringType, null)));
1558: assertTrue(new ExpressionInfo(
1559: "execution(void test.expression.Target.modifiers1()) AND !cflow(execution(* *..*(..)))",
1560: NAMESPACE).getAdvisedClassFilterExpression().match(
1561: new ExpressionContext(PointcutType.WITHIN,
1562: s_declaringType, null)));
1563: assertFalse(new ExpressionInfo(
1564: "execution(void test.expression.TargetNOMATCH.modifiers1()) AND cflow(execution(* *..*(..)))",
1565: NAMESPACE).getAdvisedClassFilterExpression().match(
1566: new ExpressionContext(PointcutType.WITHIN,
1567: s_declaringType, null)));
1568: assertFalse(new ExpressionInfo(
1569: "execution(void test.expression.TargetNOMATCH.modifiers1()) AND !cflow(execution(* *..*(..)))",
1570: NAMESPACE).getAdvisedClassFilterExpression().match(
1571: new ExpressionContext(PointcutType.WITHIN,
1572: s_declaringType, null)));
1573:
1574: // the following should return FALSE with a good early filtering
1575: // returning TRUE is not a problem for the early filtering but false will save time
1576: assertFalse(new ExpressionInfo(
1577: "execution(void test.expression.Target.modifiers1()) OR !execution(* java.lang.String.*(..))",
1578: NAMESPACE).getAdvisedClassFilterExpression().match(
1579: new ExpressionContext(PointcutType.WITHIN, otherType,
1580: null)));
1581: assertFalse(new ExpressionInfo(
1582: "execution(void test.expression.Target.modifiers1()) AND execution(* java.lang.String.*(..))",
1583: NAMESPACE).getAdvisedClassFilterExpression().match(
1584: new ExpressionContext(PointcutType.WITHIN,
1585: s_declaringType, null)));
1586: assertFalse(new ExpressionInfo(
1587: "execution(void test.expression.Target.modifiers1()) AND execution(* java.lang.String.*(..))",
1588: NAMESPACE).getAdvisedClassFilterExpression().match(
1589: new ExpressionContext(PointcutType.WITHIN,
1590: s_declaringType, null)));
1591:
1592: assertTrue(new ExpressionInfo(
1593: "!(execution(void test.expression.Target.modifiers1()) OR !execution(* java.lang.String.*(..)))",
1594: NAMESPACE).getAdvisedClassFilterExpression().match(
1595: new ExpressionContext(PointcutType.WITHIN, otherType,
1596: null)));
1597:
1598: }
1599:
1600: public void testAdvisedCflowClassExpression() throws Exception {
1601: ClassInfo otherType = JavaClassInfo.getClassInfo(String.class);
1602: s_namespace.addExpressionInfo("string", new ExpressionInfo(
1603: "execution(void java.lang.String.*(..))", NAMESPACE));
1604: s_namespace
1605: .addExpressionInfo("target", new ExpressionInfo(
1606: "execution(* test.expression.Target.*(..))",
1607: NAMESPACE));
1608: s_namespace
1609: .addExpressionInfo(
1610: "cflowString",
1611: new ExpressionInfo(
1612: "cflow(execution(void java.lang.String.*(..)))",
1613: NAMESPACE));
1614: s_namespace
1615: .addExpressionInfo(
1616: "cflowTarget",
1617: new ExpressionInfo(
1618: "cflow(call(void test.expression.Target.modifiers3()) && withincode(void test.expression.Target.*(..)))",
1619: NAMESPACE));
1620: assertFalse(singleCflowOf(
1621: new ExpressionInfo("string && cflowString", NAMESPACE))
1622: .getAdvisedClassFilterExpression().match(
1623: new ExpressionContext(PointcutType.WITHIN,
1624: s_declaringType, null)));
1625: assertTrue(singleCflowOf(
1626: new ExpressionInfo("string && cflowString", NAMESPACE))
1627: .getAdvisedClassFilterExpression().match(
1628: new ExpressionContext(PointcutType.WITHIN,
1629: otherType, null)));
1630: assertFalse(singleCflowOf(
1631: new ExpressionInfo("target && cflowString", NAMESPACE))
1632: .getAdvisedClassFilterExpression().match(
1633: new ExpressionContext(PointcutType.WITHIN,
1634: s_declaringType, null)));
1635: assertTrue(singleCflowOf(
1636: new ExpressionInfo("target && cflowString", NAMESPACE))
1637: .getAdvisedClassFilterExpression().match(
1638: new ExpressionContext(PointcutType.WITHIN,
1639: otherType, null)));
1640: assertTrue(singleCflowOf(
1641: new ExpressionInfo("! target && cflowString", NAMESPACE))
1642: .getAdvisedClassFilterExpression().match(
1643: new ExpressionContext(PointcutType.WITHIN,
1644: otherType, null)));
1645: // will match since NOT is ignored so that cflow aspect can be plugged
1646: assertTrue(singleCflowOf(
1647: new ExpressionInfo("target && ! cflowString", NAMESPACE))
1648: .getAdvisedClassFilterExpression().match(
1649: new ExpressionContext(PointcutType.WITHIN,
1650: otherType, null)));
1651: assertFalse(singleCflowOf(
1652: new ExpressionInfo("string && cflowTarget", NAMESPACE))
1653: .getAdvisedClassFilterExpression().match(
1654: new ExpressionContext(PointcutType.WITHIN,
1655: otherType, null)));
1656: assertTrue(singleCflowOf(
1657: new ExpressionInfo("string && cflowTarget", NAMESPACE))
1658: .getAdvisedClassFilterExpression().match(
1659: new ExpressionContext(PointcutType.WITHIN,
1660: s_declaringType, null)));
1661: assertFalse(singleCflowOf(
1662: new ExpressionInfo("target && cflowTarget", NAMESPACE))
1663: .getAdvisedClassFilterExpression().match(
1664: new ExpressionContext(PointcutType.WITHIN,
1665: otherType, null)));
1666: assertTrue(singleCflowOf(
1667: new ExpressionInfo("target && cflowTarget", NAMESPACE))
1668: .getAdvisedClassFilterExpression().match(
1669: new ExpressionContext(PointcutType.WITHIN,
1670: s_declaringType, null)));
1671: assertTrue(singleCflowOf(
1672: new ExpressionInfo(
1673: "execution(void test.expression.Dummy.modifiers1()) && cflow(execution(void test.expression.Target.modifiers1()))",
1674: NAMESPACE)).getAdvisedClassFilterExpression()
1675: .match(
1676: new ExpressionContext(PointcutType.WITHIN,
1677: s_declaringType, null)));
1678: assertFalse(singleCflowOf(
1679: new ExpressionInfo(
1680: "execution(void test.expression.Dummy.modifiers1()) && cflow(execution(void test.expression.Target.modifiers1()))",
1681: NAMESPACE)).getAdvisedClassFilterExpression()
1682: .match(
1683: new ExpressionContext(PointcutType.WITHIN,
1684: otherType, null)));
1685: assertFalse(singleCflowOf(
1686: new ExpressionInfo(
1687: "cflow(execution(void test.expression.Target.modifiers1()))",
1688: NAMESPACE)).getAdvisedClassFilterExpression()
1689: .match(
1690: new ExpressionContext(PointcutType.WITHIN,
1691: otherType, null)));
1692: assertTrue(singleCflowOf(
1693: new ExpressionInfo(
1694: "cflow(call(void test.expression.Target.modifiers1()))",
1695: NAMESPACE)).getAdvisedClassFilterExpression()
1696: .match(
1697: new ExpressionContext(PointcutType.WITHIN,
1698: s_declaringType, null)));
1699: assertTrue(singleCflowOf(
1700: new ExpressionInfo(
1701: "cflow(execution(void test.expression.Target.modifiers1())) && within(test.expression.Target)",
1702: NAMESPACE)).getAdvisedClassFilterExpression()
1703: .match(
1704: new ExpressionContext(PointcutType.WITHIN,
1705: s_declaringType, null)));
1706: assertTrue(singleCflowOf(
1707: new ExpressionInfo(
1708: "within(test.expression.Target) && cflow(call(void test.expression.Target.modifiers1()))",
1709: NAMESPACE)).getAdvisedClassFilterExpression()
1710: .match(
1711: new ExpressionContext(PointcutType.WITHIN,
1712: s_declaringType, null)));
1713: assertFalse(singleCflowOf(
1714: new ExpressionInfo(
1715: "cflow(within(test.expression.T) && call(void test.expression.T.modifiers1()))",
1716: NAMESPACE)).getAdvisedClassFilterExpression()
1717: .match(
1718: new ExpressionContext(PointcutType.WITHIN,
1719: s_declaringType, null)));
1720: assertTrue(singleCflowOf(
1721: new ExpressionInfo(
1722: "cflow(!within(test.expression.T) && call(void test.expression.Target.modifiers1()))",
1723: NAMESPACE)).getAdvisedClassFilterExpression()
1724: .match(
1725: new ExpressionContext(PointcutType.WITHIN,
1726: s_declaringType, null)));
1727: assertFalse(singleCflowOf(
1728: new ExpressionInfo(
1729: "cflow(call(void test.expression.Target.modifiers1()) && !withincode(void test.expression.Target.modifiers1()))",
1730: NAMESPACE)).getAdvisedClassFilterExpression()
1731: .match(
1732: new ExpressionContext(PointcutType.WITHIN,
1733: otherType, null)));
1734:
1735: assertTrue(singleCflowOf(
1736: new ExpressionInfo(
1737: "!execution(void test.expression.Target.modifiers1()) && cflow(call(void test.expression.Target.modifiers1()))",
1738: NAMESPACE)).getAdvisedClassFilterExpression()
1739: .match(
1740: new ExpressionContext(PointcutType.WITHIN,
1741: s_declaringType, null)));
1742:
1743: }
1744:
1745: // ============ cflow type tests =============
1746: public void testFindCflowPointcut() throws Exception {
1747: MethodInfo method1 = JavaMethodInfo.getMethodInfo(Target.class
1748: .getDeclaredMethod("modifiers1", new Class[] {}));
1749: MethodInfo method2 = JavaMethodInfo.getMethodInfo(Target.class
1750: .getDeclaredMethod("modifiers2", new Class[] {}));
1751: MethodInfo method3 = JavaMethodInfo.getMethodInfo(Target.class
1752: .getDeclaredMethod("modifiers3", new Class[] {}));
1753: s_namespace.addExpressionInfo("pc1", new ExpressionInfo(
1754: "execution(void test.expression.Target.modifiers2())",
1755: NAMESPACE));
1756: s_namespace.addExpressionInfo("pc2", new ExpressionInfo(
1757: "execution(void test.expression.Target.modifiers3())",
1758: NAMESPACE));
1759: s_namespace
1760: .addExpressionInfo(
1761: "cflowPC",
1762: new ExpressionInfo(
1763: "cflow(call(void test.expression.Target.modifiers3()) AND within(test.expression.*))",
1764: NAMESPACE));
1765: assertTrue(singleCflowOf(
1766: new ExpressionInfo(
1767: "cflow(execution(void test.expression.Target.modifiers1()))",
1768: NAMESPACE)).getExpression().match(
1769: new ExpressionContext(PointcutType.EXECUTION, method1,
1770: null)));
1771:
1772: ExpressionInfo expression = null;
1773:
1774: expression = new ExpressionInfo(
1775: "execution(void test.expression.Target.modifiers2()) && cflow(execution(void test.expression.Target.modifiers1()))",
1776: NAMESPACE);
1777: assertTrue(CflowBinding.getCflowBindingsForCflowOf(expression)
1778: .size() == 1);
1779:
1780: expression = new ExpressionInfo(
1781: "execution(void test.expression.Target.modifiers2()) && cflow(execution(void test.expression.Target.modifiers1()))",
1782: NAMESPACE);
1783: assertTrue(CflowBinding.getCflowBindingsForCflowOf(expression)
1784: .size() == 1);
1785:
1786: expression = new ExpressionInfo(
1787: "cflow(execution(void test.expression.Target.modifiers1())) && execution(void test.expression.Target.modifiers2())",
1788: NAMESPACE);
1789: assertTrue(CflowBinding.getCflowBindingsForCflowOf(expression)
1790: .size() == 1);
1791:
1792: expression = new ExpressionInfo("cflowPC && pc1", NAMESPACE);
1793: assertTrue(CflowBinding.getCflowBindingsForCflowOf(expression)
1794: .size() == 1);
1795: expression = new ExpressionInfo("pc1 && cflowPC", NAMESPACE);
1796: assertTrue(CflowBinding.getCflowBindingsForCflowOf(expression)
1797: .size() == 1);
1798: expression = new ExpressionInfo("cflow(pc2) && pc1", NAMESPACE);
1799: assertTrue(CflowBinding.getCflowBindingsForCflowOf(expression)
1800: .size() == 1);
1801: expression = new ExpressionInfo("pc1 && cflow(pc2)", NAMESPACE);
1802: assertTrue(CflowBinding.getCflowBindingsForCflowOf(expression)
1803: .size() == 1);
1804:
1805: expression = new ExpressionInfo(
1806: "pc2 && cflow(pc1 || pc2 || call(void test.expression.Target.modifiers1()))",
1807: NAMESPACE);
1808: assertTrue(CflowBinding.getCflowBindingsForCflowOf(expression)
1809: .size() == 1);
1810:
1811: expression = new ExpressionInfo(
1812: "cflow(pc1 || pc2 || call(void test.expression.Target.modifiers1())) AND pc1",
1813: NAMESPACE);
1814: assertTrue(CflowBinding.getCflowBindingsForCflowOf(expression)
1815: .size() == 1);
1816:
1817: expression = new ExpressionInfo(
1818: "cflow(pc1 || call(void test.expression.Target.modifiers1())) && (execution(void test.expression.Target.modifiers3()) || pc1)",
1819: NAMESPACE);
1820: assertTrue(CflowBinding.getCflowBindingsForCflowOf(expression)
1821: .size() == 1);
1822:
1823: expression = new ExpressionInfo(
1824: "cflow(execution(void test.expression.Target.modifiers1())) && execution(void test.expression.Target.modifiers2())",
1825: NAMESPACE);
1826: assertTrue(CflowBinding.getCflowBindingsForCflowOf(expression)
1827: .size() == 1);
1828:
1829: expression = new ExpressionInfo(
1830: "cflow(pc1) && execution(void test.expression.Target.modifiers3())",
1831: NAMESPACE);
1832: assertTrue(CflowBinding.getCflowBindingsForCflowOf(expression)
1833: .size() == 1);
1834:
1835: expression = new ExpressionInfo(
1836: "cflow(call(void test.expression.Target.modifiers1())) && execution(void test.expression.Target.modifiers1())",
1837: NAMESPACE);
1838: assertTrue(CflowBinding.getCflowBindingsForCflowOf(expression)
1839: .size() == 1);
1840:
1841: expression = new ExpressionInfo(
1842: "cflow(call(void test.expression.Target.modifiers1())) || execution(void test.expression.Target.modifiers1())",
1843: NAMESPACE);
1844: assertTrue(CflowBinding.getCflowBindingsForCflowOf(expression)
1845: .size() == 1);
1846:
1847: expression = new ExpressionInfo(
1848: "cflow(call(void test.expression.Target.modifiers1())) && cflow(call(void test.expression.Target.modifiers2())) || execution(void test.expression.Target.modifiers1())",
1849: NAMESPACE);
1850: assertTrue(CflowBinding.getCflowBindingsForCflowOf(expression)
1851: .size() == 2);
1852:
1853: expression = new ExpressionInfo(
1854: "call(void test.expression.Target.modifiers1()) || execution(void test.expression.Target.modifiers1())",
1855: NAMESPACE);
1856: assertTrue(CflowBinding.getCflowBindingsForCflowOf(expression)
1857: .size() == 0);
1858:
1859: expression = new ExpressionInfo(
1860: "call(void test.expression.Target.modifiers1()) && execution(void test.expression.Target.modifiers1())",
1861: NAMESPACE);
1862: assertTrue(CflowBinding.getCflowBindingsForCflowOf(expression)
1863: .size() == 0);
1864: }
1865:
1866: public void testCflowTypes() throws Exception {
1867: MethodInfo method1 = JavaMethodInfo.getMethodInfo(Target.class
1868: .getDeclaredMethod("modifiers1", new Class[] {}));
1869: MethodInfo method2 = JavaMethodInfo.getMethodInfo(Target.class
1870: .getDeclaredMethod("modifiers2", new Class[] {}));
1871: MethodInfo method3 = JavaMethodInfo.getMethodInfo(Target.class
1872: .getDeclaredMethod("modifiers3", new Class[] {}));
1873: s_namespace.addExpressionInfo("pc1", new ExpressionInfo(
1874: "execution(void test.expression.Target.modifiers2())",
1875: NAMESPACE));
1876: s_namespace.addExpressionInfo("pc2", new ExpressionInfo(
1877: "execution(void test.expression.Target.modifiers3())",
1878: NAMESPACE));
1879: s_namespace
1880: .addExpressionInfo(
1881: "cflowPC",
1882: new ExpressionInfo(
1883: "cflow(call(void test.expression.Target.modifiers3()) AND within(test.expression.*))",
1884: NAMESPACE));
1885: assertTrue(singleCflowOf(
1886: new ExpressionInfo(
1887: "cflow(execution(void test.expression.Target.modifiers1()))",
1888: NAMESPACE)).getExpression().match(
1889: new ExpressionContext(PointcutType.EXECUTION, method1,
1890: null)));
1891: assertTrue(singleCflowOf(
1892: new ExpressionInfo(
1893: "execution(void test.expression.Target.modifiers2()) && cflow(execution(void test.expression.Target.modifiers1()))",
1894: NAMESPACE)).getExpression().match(
1895: new ExpressionContext(PointcutType.EXECUTION, method1,
1896: null)));
1897: assertTrue(singleCflowOf(
1898: new ExpressionInfo(
1899: "execution(void test.expression.Target.modifiers2()) && cflow(execution(void test.expression.Target.modifiers1()))",
1900: NAMESPACE)).getExpression().match(
1901: new ExpressionContext(PointcutType.EXECUTION, method1,
1902: null)));
1903: assertTrue(singleCflowOf(
1904: new ExpressionInfo(
1905: "cflow(execution(void test.expression.Target.modifiers1())) && execution(void test.expression.Target.modifiers2())",
1906: NAMESPACE)).getExpression().match(
1907: new ExpressionContext(PointcutType.EXECUTION, method1,
1908: null)));
1909: assertTrue(singleCflowOf(
1910: new ExpressionInfo("cflowPC && pc1", NAMESPACE))
1911: .getExpression().match(
1912: new ExpressionContext(PointcutType.CALL,
1913: method3, s_declaringType)));
1914: assertTrue(singleCflowOf(
1915: new ExpressionInfo("pc1 && cflowPC", NAMESPACE))
1916: .getExpression().match(
1917: new ExpressionContext(PointcutType.CALL,
1918: method3, s_declaringType)));
1919: assertTrue(singleCflowOf(
1920: new ExpressionInfo("cflow(pc2) && pc1", NAMESPACE))
1921: .getExpression().match(
1922: new ExpressionContext(PointcutType.EXECUTION,
1923: method3, s_declaringType)));
1924: assertFalse(singleCflowOf(
1925: new ExpressionInfo("pc1 && cflow(pc2)", NAMESPACE))
1926: .getExpression().match(
1927: new ExpressionContext(PointcutType.EXECUTION,
1928: method2, s_declaringType)));
1929: assertTrue(singleCflowOf(
1930: new ExpressionInfo(
1931: "pc2 && cflow(pc1 || pc2 || call(void test.expression.Target.modifiers1()))",
1932: NAMESPACE)).getExpression()
1933: .match(
1934: new ExpressionContext(PointcutType.CALL,
1935: method1, null)));
1936: assertTrue(singleCflowOf(
1937: new ExpressionInfo(
1938: "cflow(pc1 || pc2 || call(void test.expression.Target.modifiers1())) AND pc1",
1939: NAMESPACE)).getExpression().match(
1940: new ExpressionContext(PointcutType.EXECUTION, method3,
1941: null)));
1942: assertTrue(singleCflowOf(
1943: new ExpressionInfo(
1944: "cflow(pc1 || call(void test.expression.Target.modifiers1())) && (execution(void test.expression.Target.modifiers3()) || pc1)",
1945: NAMESPACE)).getExpression().match(
1946: new ExpressionContext(PointcutType.EXECUTION, method2,
1947: null)));
1948: assertFalse(singleCflowOf(
1949: new ExpressionInfo(
1950: "cflow(execution(void test.expression.Target.modifiers1())) && execution(void test.expression.Target.modifiers2())",
1951: NAMESPACE)).getExpression().match(
1952: new ExpressionContext(PointcutType.EXECUTION, method2,
1953: null)));
1954: assertTrue(new ExpressionInfo(
1955: "cflow(pc1) && execution(void test.expression.Target.modifiers3())",
1956: NAMESPACE).getExpression().match(
1957: new ExpressionContext(PointcutType.EXECUTION, method3,
1958: null)));
1959: assertFalse(singleCflowOf(
1960: new ExpressionInfo(
1961: "cflow(call(void test.expression.Target.modifiers1())) && execution(void test.expression.Target.modifiers1())",
1962: NAMESPACE)).getExpression().match(
1963: new ExpressionContext(PointcutType.EXECUTION, method1,
1964: null)));
1965: assertFalse(singleCflowOf(
1966: new ExpressionInfo(
1967: "cflow(call(void test.expression.Target.modifiers1())) || execution(void test.expression.Target.modifiers1())",
1968: NAMESPACE)).getExpression().match(
1969: new ExpressionContext(PointcutType.EXECUTION, method1,
1970: null)));
1971: assertTrue(new ExpressionInfo(
1972: "execution(void test.expression.Target.modifiers2()) AND !cflow(call(void test.expression.Target.modifiers1()))",
1973: NAMESPACE).getExpression().match(
1974: new ExpressionContext(PointcutType.EXECUTION, method2,
1975: null)));
1976: assertTrue(singleCflowOf(
1977: new ExpressionInfo(
1978: "execution(void test.expression.Target.modifiers2()) AND !cflow(call(void test.expression.Target.modifiers1()))",
1979: NAMESPACE)).getExpression()
1980: .match(
1981: new ExpressionContext(PointcutType.CALL,
1982: method1, null)));
1983: }
1984:
1985: public void testCflowBelowTypes() throws Exception {
1986: MethodInfo method1 = JavaMethodInfo.getMethodInfo(Target.class
1987: .getDeclaredMethod("modifiers1", new Class[] {}));
1988: MethodInfo method2 = JavaMethodInfo.getMethodInfo(Target.class
1989: .getDeclaredMethod("modifiers2", new Class[] {}));
1990: MethodInfo method3 = JavaMethodInfo.getMethodInfo(Target.class
1991: .getDeclaredMethod("modifiers3", new Class[] {}));
1992: s_namespace.addExpressionInfo("pc1", new ExpressionInfo(
1993: "execution(void test.expression.Target.modifiers2())",
1994: NAMESPACE));
1995: s_namespace.addExpressionInfo("pc2", new ExpressionInfo(
1996: "execution(void test.expression.Target.modifiers3())",
1997: NAMESPACE));
1998: assertTrue(singleCflowOf(
1999: new ExpressionInfo(
2000: "cflowbelow(execution(void test.expression.Target.modifiers1()))",
2001: NAMESPACE)).getExpression().match(
2002: new ExpressionContext(PointcutType.EXECUTION, method1,
2003: null)));
2004: assertTrue(singleCflowOf(
2005: new ExpressionInfo(
2006: "cflowbelow(pc1 || pc2 || call(void test.expression.Target.modifiers1()))",
2007: NAMESPACE)).getExpression()
2008: .match(
2009: new ExpressionContext(PointcutType.CALL,
2010: method1, null)));
2011: assertTrue(singleCflowOf(
2012: new ExpressionInfo(
2013: "cflowbelow(pc1 || pc2 || call(void test.expression.Target.modifiers1()))",
2014: NAMESPACE)).getExpression().match(
2015: new ExpressionContext(PointcutType.EXECUTION, method2,
2016: null)));
2017: assertTrue(singleCflowOf(
2018: new ExpressionInfo(
2019: "cflowbelow(pc1 || pc2 || call(void test.expression.Target.modifiers1()))",
2020: NAMESPACE)).getExpression().match(
2021: new ExpressionContext(PointcutType.EXECUTION, method3,
2022: null)));
2023: }
2024:
2025: // ============ hasmethod/hasfield =============
2026: public void testHasMethod() throws Exception {
2027: ClassInfo klass = JavaClassInfo.getClassInfo(Target.class);
2028: ClassInfo string = JavaClassInfo.getClassInfo(String.class);
2029: assertTrue(new ExpressionInfo("hasmethod(void modifiers1())",
2030: NAMESPACE).getExpression().match(
2031: new ExpressionContext(PointcutType.EXECUTION, klass,
2032: klass)));
2033: assertFalse(new ExpressionInfo("hasmethod(void modifiers1())",
2034: NAMESPACE).getExpression()
2035: .match(
2036: new ExpressionContext(PointcutType.CALL, klass,
2037: string)));
2038: // will match at the AdvisedClassFilterExpression level
2039: assertTrue(new ExpressionInfo("hasmethod(* getClass())",//since has not declaring type there !
2040: NAMESPACE).getAdvisedClassFilterExpression().match(
2041: new ExpressionContext(PointcutType.EXECUTION, klass,
2042: klass)));
2043: // but not at the Expression level
2044: assertFalse(new ExpressionInfo("hasmethod(* getClass())",
2045: NAMESPACE).getExpression().match(
2046: new ExpressionContext(PointcutType.EXECUTION, klass,
2047: klass)));
2048: // unless method is in class hierarchy
2049: assertFalse(new ExpressionInfo(
2050: "hasmethod(* java.lang.Object+.getClass())", NAMESPACE)
2051: .getExpression().match(
2052: new ExpressionContext(PointcutType.EXECUTION,
2053: klass, klass)));
2054: // even a fake method will match
2055: assertTrue(new ExpressionInfo(
2056: "hasmethod(* java.lang.Object+.DOESNOTEXIST())",
2057: NAMESPACE).getAdvisedClassFilterExpression().match(
2058: new ExpressionContext(PointcutType.EXECUTION, klass,
2059: klass)));
2060: // but not at Expression level
2061: assertFalse(new ExpressionInfo(
2062: "hasmethod(* java.lang.Object+.DOESNOTEXIST())",
2063: NAMESPACE).getExpression().match(
2064: new ExpressionContext(PointcutType.EXECUTION, klass,
2065: klass)));
2066: }
2067:
2068: public void testHasField() throws Exception {
2069: ClassInfo klass = JavaClassInfo.getClassInfo(Target.class);
2070: ClassInfo string = JavaClassInfo.getClassInfo(String.class);
2071: assertTrue(new ExpressionInfo("hasfield(int modifier1)",
2072: NAMESPACE).getExpression().match(
2073: new ExpressionContext(PointcutType.EXECUTION, klass,
2074: klass)));
2075: assertFalse(new ExpressionInfo("hasfield(* modifier1)",
2076: NAMESPACE).getExpression()
2077: .match(
2078: new ExpressionContext(PointcutType.CALL, klass,
2079: string)));
2080: // will match here
2081: assertTrue(new ExpressionInfo("hasfield(* value)",//since no declaring class here !
2082: NAMESPACE).getAdvisedClassFilterExpression().match(
2083: new ExpressionContext(PointcutType.EXECUTION, klass,
2084: klass)));
2085: // and not at the Expression level
2086: assertFalse(new ExpressionInfo("hasfield(* value)", NAMESPACE)
2087: .getExpression().match(
2088: new ExpressionContext(PointcutType.EXECUTION,
2089: klass, klass)));
2090: //value field exists in String.class
2091: assertTrue(new ExpressionInfo("hasfield(* value)", NAMESPACE)
2092: .getExpression().match(
2093: new ExpressionContext(PointcutType.CALL, klass,
2094: string)));
2095: }
2096:
2097: // ============ within type tests =============
2098: public void testWithinType1() throws Exception {
2099: ClassInfo otherType = JavaClassInfo.getClassInfo(String.class);
2100: MethodInfo method = JavaMethodInfo.getMethodInfo(Target.class
2101: .getDeclaredMethod("modifiers1", new Class[] {}));
2102: assertTrue(new ExpressionInfo(
2103: "execution(void test.expression.Target.modifiers1()) AND within(test.expression.Target)",
2104: NAMESPACE).getExpression().match(
2105: new ExpressionContext(PointcutType.EXECUTION, method,
2106: s_declaringType)));
2107: assertTrue(new ExpressionInfo(
2108: "call(void test.expression.Target.modifiers1()) AND within(test.expression.Target)",
2109: NAMESPACE).getExpression().match(
2110: new ExpressionContext(PointcutType.CALL, method,
2111: s_declaringType)));
2112: assertFalse(new ExpressionInfo(
2113: "call(void test.expression.Target.modifiers1()) AND !within(test.expression.Target)",
2114: NAMESPACE).getExpression().match(
2115: new ExpressionContext(PointcutType.CALL, method,
2116: s_declaringType)));
2117: assertTrue(new ExpressionInfo(
2118: "call(void test.expression.Target.modifiers1()) AND within(java.lang.String)",
2119: NAMESPACE).getExpression().match(
2120: new ExpressionContext(PointcutType.CALL, method,
2121: otherType)));
2122: assertFalse(new ExpressionInfo(
2123: "call(void test.expression.Target.modifiers1()) AND within(java.lang.String)",
2124: NAMESPACE).getExpression().match(
2125: new ExpressionContext(PointcutType.CALL, method,
2126: s_declaringType)));
2127: assertTrue(new ExpressionInfo(
2128: "call(void test.expression.Target.modifiers1()) AND !within(java.lang.String)",
2129: NAMESPACE).getExpression().match(
2130: new ExpressionContext(PointcutType.CALL, method,
2131: s_declaringType)));
2132: //-- test early evaluation
2133: assertTrue(new ExpressionInfo(
2134: "call(void test.expression.Target.NOMATCH()) AND within(java.lang.String)",
2135: NAMESPACE).getAdvisedClassFilterExpression().match(
2136: new ExpressionContext(PointcutType.CALL, method,
2137: otherType)));
2138: assertFalse(new ExpressionInfo(
2139: "call(void test.expression.Target.NOMATCH()) AND within(java.lang.String)",
2140: NAMESPACE).getAdvisedClassFilterExpression().match(
2141: new ExpressionContext(PointcutType.CALL, method,
2142: s_declaringType)));
2143: assertTrue(new ExpressionInfo(
2144: "call(void test.expression.Target.NOMATCH()) AND !within(java.lang.String)",
2145: NAMESPACE).getAdvisedClassFilterExpression().match(
2146: new ExpressionContext(PointcutType.CALL, method,
2147: s_declaringType)));
2148: assertFalse(new ExpressionInfo(
2149: "call(void test.expression.NOMATCHTarget.NOMATCH()) AND within(java.lang.String)",
2150: NAMESPACE).getAdvisedClassFilterExpression().match(
2151: new ExpressionContext(PointcutType.CALL, method,
2152: otherType)));
2153: }
2154:
2155: public void testWithinType2() throws Exception {
2156: ClassInfo klass = JavaClassInfo.getClassInfo(Target.class);
2157: MethodInfo method = JavaMethodInfo.getMethodInfo(Target.class
2158: .getDeclaredMethod("modifiers1", new Class[] {}));
2159: assertTrue(new ExpressionInfo(
2160: "execution(void *..*.modifiers1()) AND within(test.expression.Target)",
2161: NAMESPACE).getAdvisedClassFilterExpression().match(
2162: new ExpressionContext(PointcutType.EXECUTION, method,
2163: s_declaringType)));
2164: assertTrue(new ExpressionInfo(
2165: "execution(void *..*.modifiers1()) AND within(@Serializable *..*)",
2166: NAMESPACE).getAdvisedClassFilterExpression().match(
2167: new ExpressionContext(PointcutType.EXECUTION, method,
2168: s_declaringType)));
2169: assertFalse(new ExpressionInfo(
2170: "execution(void *..*.modifiers1()) AND !within(@Serializable *..*)",
2171: NAMESPACE).getAdvisedClassFilterExpression().match(
2172: new ExpressionContext(PointcutType.EXECUTION, method,
2173: s_declaringType)));
2174: }
2175:
2176: public void testWithinCodeType() throws Exception {
2177: MethodInfo stringtoStringMethod = JavaMethodInfo
2178: .getMethodInfo(String.class.getDeclaredMethod(
2179: "toString", new Class[] {}));
2180: MethodInfo method = JavaMethodInfo.getMethodInfo(Target.class
2181: .getDeclaredMethod("modifiers1", new Class[] {}));
2182: assertTrue(new ExpressionInfo(
2183: "execution(void test.expression.Target.modifiers1()) AND withincode(void test.expression.Target.modifiers1())",
2184: NAMESPACE).getExpression().match(
2185: new ExpressionContext(PointcutType.EXECUTION, method,
2186: method)));
2187: assertTrue(new ExpressionInfo(
2188: "call(void test.expression.Target.modifiers1()) AND withincode(void test.expression.Target.modifiers1())",
2189: NAMESPACE).getExpression()
2190: .match(
2191: new ExpressionContext(PointcutType.CALL,
2192: method, method)));
2193: assertFalse(new ExpressionInfo(
2194: "call(void test.expression.Target.modifiers1()) AND !withincode(void test.expression.Target.modifiers1())",
2195: NAMESPACE).getExpression()
2196: .match(
2197: new ExpressionContext(PointcutType.CALL,
2198: method, method)));
2199: assertTrue(new ExpressionInfo(
2200: "execution(void test.expression.Target.modifiers1()) AND withincode(* java.lang.String.toString())",
2201: NAMESPACE).getExpression().match(
2202: new ExpressionContext(PointcutType.EXECUTION, method,
2203: stringtoStringMethod)));
2204: assertFalse(new ExpressionInfo(
2205: "execution(void test.expression.Target.modifiers1()) AND withincode(* java.lang.String.toString())",
2206: NAMESPACE).getExpression().match(
2207: new ExpressionContext(PointcutType.EXECUTION, method,
2208: method)));
2209: //-- test early evaluation
2210: assertTrue(new ExpressionInfo(
2211: "call(void test.expression.Target.modifiers1()) AND withincode(* java.lang.String.NOMATCHtoString())",
2212: NAMESPACE).getAdvisedClassFilterExpression().match(
2213: new ExpressionContext(PointcutType.CALL, method,
2214: stringtoStringMethod)));
2215: assertFalse(new ExpressionInfo(
2216: "call(void test.expression.Target.modifiers1()) AND withincode(* java.lang.String.NOMATCHtoString())",
2217: NAMESPACE).getAdvisedClassFilterExpression()
2218: .match(
2219: new ExpressionContext(PointcutType.CALL,
2220: method, method)));
2221: assertFalse(new ExpressionInfo(
2222: "call(void test.expression.Target.modifiers1()) AND withincode(* java.lang.StringNOMATCH.*())",
2223: NAMESPACE).getAdvisedClassFilterExpression()
2224: .match(
2225: new ExpressionContext(PointcutType.CALL,
2226: method, method)));
2227:
2228: }
2229:
2230: // ============ pointcut ref tests =============
2231: public void testPointcutReference() throws Exception {
2232: s_namespace.addExpressionInfo("pc1", new ExpressionInfo(
2233: "execution(void test.expression.Target.modifiers2())",
2234: NAMESPACE));
2235: s_namespace.addExpressionInfo("pc2", new ExpressionInfo(
2236: "execution(void test.expression.Target.modifiers3())",
2237: NAMESPACE));
2238: assertTrue(new ExpressionInfo(
2239: "execution(void test.expression.Target.modifiers1()) || pc1",
2240: NAMESPACE).getExpression().match(
2241: new ExpressionContext(PointcutType.EXECUTION,
2242: modifiers1, null)));
2243: assertTrue(new ExpressionInfo(
2244: "execution(void test.expression.Target.modifiers1()) || pc1",
2245: NAMESPACE).getExpression().match(
2246: new ExpressionContext(PointcutType.EXECUTION,
2247: modifiers2, null)));
2248: assertTrue(new ExpressionInfo(
2249: "execution(void test.expression.Target.modifiers1()) || pc2",
2250: NAMESPACE).getExpression().match(
2251: new ExpressionContext(PointcutType.EXECUTION,
2252: modifiers3, null)));
2253: assertTrue(new ExpressionInfo(
2254: "execution(void test.expression.Target.modifiers1()) || pc1 || pc2",
2255: NAMESPACE).getExpression().match(
2256: new ExpressionContext(PointcutType.EXECUTION,
2257: modifiers1, null)));
2258: assertTrue(new ExpressionInfo(
2259: "execution(void test.expression.Target.modifiers1()) || pc1 || pc2",
2260: NAMESPACE).getExpression().match(
2261: new ExpressionContext(PointcutType.EXECUTION,
2262: modifiers2, null)));
2263: assertTrue(new ExpressionInfo(
2264: "execution(void test.expression.Target.modifiers1()) || pc1 || pc2 ",
2265: NAMESPACE).getExpression().match(
2266: new ExpressionContext(PointcutType.EXECUTION,
2267: modifiers3, null)));
2268: assertTrue(new ExpressionInfo(
2269: "execution(void test.expression.Target.modifiers1()) || pc2 || pc1",
2270: NAMESPACE).getExpression().match(
2271: new ExpressionContext(PointcutType.EXECUTION,
2272: modifiers1, null)));
2273: assertTrue(new ExpressionInfo(
2274: "execution(void test.expression.Target.modifiers1()) || pc2 || pc1",
2275: NAMESPACE).getExpression().match(
2276: new ExpressionContext(PointcutType.EXECUTION,
2277: modifiers2, null)));
2278: assertTrue(new ExpressionInfo(
2279: "execution(void test.expression.Target.modifiers1()) || pc2 || pc1 ",
2280: NAMESPACE).getExpression().match(
2281: new ExpressionContext(PointcutType.EXECUTION,
2282: modifiers3, null)));
2283: assertTrue(new ExpressionInfo(
2284: "pc1 || pc2 || execution(void test.expression.Target.modifiers1())",
2285: NAMESPACE).getExpression().match(
2286: new ExpressionContext(PointcutType.EXECUTION,
2287: modifiers1, null)));
2288: assertTrue(new ExpressionInfo(
2289: "pc1 || pc2 || execution(void test.expression.Target.modifiers1())",
2290: NAMESPACE).getExpression().match(
2291: new ExpressionContext(PointcutType.EXECUTION,
2292: modifiers2, null)));
2293: assertTrue(new ExpressionInfo(
2294: "pc1 || pc2 || execution(void test.expression.Target.modifiers1())",
2295: NAMESPACE).getExpression().match(
2296: new ExpressionContext(PointcutType.EXECUTION,
2297: modifiers3, null)));
2298: assertTrue(new ExpressionInfo(
2299: "(execution(void test.expression.Target.modifiers1()) || pc1 || pc2) AND within(test.expression.Target)",
2300: NAMESPACE).getExpression().match(
2301: new ExpressionContext(PointcutType.EXECUTION,
2302: modifiers1, s_declaringType)));
2303: assertTrue(new ExpressionInfo(
2304: "(execution(void test.expression.Target.modifiers1()) || pc1 || pc2) AND within(test.expression.Target)",
2305: NAMESPACE).getExpression().match(
2306: new ExpressionContext(PointcutType.EXECUTION,
2307: modifiers2, s_declaringType)));
2308: assertTrue(new ExpressionInfo(
2309: "(execution(void test.expression.Target.modifiers1()) || pc1 || pc2) AND within(test.expression.Target)",
2310: NAMESPACE).getExpression().match(
2311: new ExpressionContext(PointcutType.EXECUTION,
2312: modifiers3, s_declaringType)));
2313: assertTrue(new ExpressionInfo(
2314: "within(test.expression.Target) && (pc1 || pc2 || execution(void test.expression.Target.modifiers1()))",
2315: NAMESPACE).getExpression().match(
2316: new ExpressionContext(PointcutType.EXECUTION,
2317: modifiers1, s_declaringType)));
2318: assertTrue(new ExpressionInfo(
2319: "within(test.expression.Target) && (pc2 || pc1 || execution(void test.expression.Target.modifiers1()))",
2320: NAMESPACE).getExpression().match(
2321: new ExpressionContext(PointcutType.EXECUTION,
2322: modifiers2, s_declaringType)));
2323: assertTrue(new ExpressionInfo(
2324: "within(test.expression.Target) && (pc1 || execution(void test.expression.Target.modifiers1()) || pc2)",
2325: NAMESPACE).getExpression().match(
2326: new ExpressionContext(PointcutType.EXECUTION,
2327: modifiers3, s_declaringType)));
2328: }
2329:
2330: // ============ pointcut ref tests =============
2331: public void testPointcutReferenceOutsideScope() throws Exception {
2332: String namespace1 = "Lib";
2333: String namespace2 = "org.moneymaker.Util";
2334: ExpressionNamespace
2335: .getNamespace(namespace1)
2336: .addExpressionInfo(
2337: "pc1",
2338: new ExpressionInfo(
2339: "execution(void test.expression.Target.modifiers1())",
2340: namespace1));
2341: ExpressionNamespace
2342: .getNamespace(namespace2)
2343: .addExpressionInfo(
2344: "pc2",
2345: new ExpressionInfo(
2346: "execution(void test.expression.Target.modifiers2())",
2347: namespace2));
2348: assertTrue(new ExpressionInfo(
2349: "execution(* foo.bar.*()) || Lib.pc1", NAMESPACE)
2350: .getExpression().match(
2351: new ExpressionContext(PointcutType.EXECUTION,
2352: modifiers1, null)));
2353: assertTrue(new ExpressionInfo(
2354: "Lib.pc1 || execution(* foo.bar.*())", NAMESPACE)
2355: .getExpression().match(
2356: new ExpressionContext(PointcutType.EXECUTION,
2357: modifiers1, null)));
2358: assertTrue(new ExpressionInfo(
2359: "org.moneymaker.Util.pc2 || Lib.pc1", NAMESPACE)
2360: .getExpression().match(
2361: new ExpressionContext(PointcutType.EXECUTION,
2362: modifiers2, null)));
2363: assertTrue(new ExpressionInfo(
2364: "Lib.pc1 || org.moneymaker.Util.pc2", NAMESPACE)
2365: .getExpression().match(
2366: new ExpressionContext(PointcutType.EXECUTION,
2367: modifiers2, null)));
2368: assertFalse(new ExpressionInfo(
2369: "execution(void test.expression.Target.modifiers1()) || Lib.pc1",
2370: NAMESPACE).getExpression().match(
2371: new ExpressionContext(PointcutType.EXECUTION,
2372: modifiers2, null)));
2373: }
2374:
2375: // ============ and tests =============
2376: public void testAnd() throws Exception {
2377: assertTrue(new ExpressionInfo(
2378: "execution(void test.expression.Target.modifiers1()) AND within(test.expression.Target)",
2379: NAMESPACE).getExpression().match(
2380: new ExpressionContext(PointcutType.EXECUTION,
2381: modifiers1, s_declaringType)));
2382: assertFalse(new ExpressionInfo(
2383: "execution(void test.expression.Target.modifiers1()) AND call(void test.expression.Target.modifiers1())",
2384: NAMESPACE).getExpression().match(
2385: new ExpressionContext(PointcutType.EXECUTION,
2386: modifiers1, s_declaringType)));
2387: assertFalse(new ExpressionInfo(
2388: "call(void test.expression.Target.modifiers1()) AND set(int test.expression.Target.modifier1)",
2389: NAMESPACE).getExpression().match(
2390: new ExpressionContext(PointcutType.CALL, modifier1,
2391: null)));
2392: assertTrue(new ExpressionInfo(
2393: "execution(void test.expression.Target.modifiers1()) && within(test.expression.Target)",
2394: NAMESPACE).getExpression().match(
2395: new ExpressionContext(PointcutType.EXECUTION,
2396: modifiers1, s_declaringType)));
2397: assertFalse(new ExpressionInfo(
2398: "execution(void test.expression.Target.modifiers1()) && call(void test.expression.Target.modifiers1())",
2399: NAMESPACE).getExpression().match(
2400: new ExpressionContext(PointcutType.EXECUTION,
2401: modifiers1, s_declaringType)));
2402: assertFalse(new ExpressionInfo(
2403: "call(void test.expression.Target.modifiers1()) && set(int test.expression.Target.modifier1)",
2404: NAMESPACE).getExpression().match(
2405: new ExpressionContext(PointcutType.CALL, modifier1,
2406: null)));
2407: }
2408:
2409: // ============ or tests =============
2410: public void testOr() throws Exception {
2411: assertTrue(new ExpressionInfo(
2412: "execution(void test.expression.Target.modifiers1()) OR call(void test.expression.Target.modifiers1())",
2413: NAMESPACE).getExpression().match(
2414: new ExpressionContext(PointcutType.EXECUTION,
2415: modifiers1, null)));
2416: assertTrue(new ExpressionInfo(
2417: "execution(void test.expression.Target.modifiers1()) OR call(void test.expression.Target.modifiers1())",
2418: NAMESPACE).getExpression().match(
2419: new ExpressionContext(PointcutType.CALL, modifiers1,
2420: null)));
2421: assertTrue(new ExpressionInfo(
2422: "call(void test.expression.Target.modifiers1()) OR set(int test.expression.Target.modifiers)",
2423: NAMESPACE).getExpression().match(
2424: new ExpressionContext(PointcutType.CALL, modifiers1,
2425: null)));
2426: assertTrue(new ExpressionInfo(
2427: "set(int test.expression.Target.modifier1) OR call(void test.expression.Target.modifiers1())",
2428: NAMESPACE).getExpression()
2429: .match(
2430: new ExpressionContext(PointcutType.SET,
2431: modifier1, null)));
2432: assertTrue(new ExpressionInfo(
2433: "call(void test.expression.Target.modifiers1()) OR set(int test.expression.Target.modifier1)",
2434: NAMESPACE).getExpression()
2435: .match(
2436: new ExpressionContext(PointcutType.SET,
2437: modifier1, null)));
2438: assertTrue(new ExpressionInfo(
2439: "execution(void test.expression.Target.modifiers1()) || call(void test.expression.Target.modifiers1())",
2440: NAMESPACE).getExpression().match(
2441: new ExpressionContext(PointcutType.EXECUTION,
2442: modifiers1, null)));
2443: assertTrue(new ExpressionInfo(
2444: "execution(void test.expression.Target.modifiers1()) || call(void test.expression.Target.modifiers1())",
2445: NAMESPACE).getExpression().match(
2446: new ExpressionContext(PointcutType.CALL, modifiers1,
2447: null)));
2448: assertTrue(new ExpressionInfo(
2449: "call(void test.expression.Target.modifiers1()) || set(int test.expression.Target.modifier1)",
2450: NAMESPACE).getExpression().match(
2451: new ExpressionContext(PointcutType.CALL, modifiers1,
2452: null)));
2453: assertTrue(new ExpressionInfo(
2454: "call(void test.expression.Target.modifiers1()) || set(int test.expression.Target.modifier1)",
2455: NAMESPACE).getExpression()
2456: .match(
2457: new ExpressionContext(PointcutType.SET,
2458: modifier1, null)));
2459: }
2460:
2461: // ============ not tests =============
2462: public void testNot() throws Exception {
2463: assertFalse(new ExpressionInfo(
2464: "execution(void test.expression.Target.modifiers1()) AND !within(test.expression.Target)",
2465: NAMESPACE).getExpression().match(
2466: new ExpressionContext(PointcutType.EXECUTION,
2467: modifiers1, s_declaringType)));
2468: assertTrue(new ExpressionInfo(
2469: "execution(void test.expression.Target.modifiers1()) AND !call(void test.expression.Target.modifiers1())",
2470: NAMESPACE).getExpression().match(
2471: new ExpressionContext(PointcutType.EXECUTION,
2472: modifiers1, s_declaringType)));
2473: assertFalse(new ExpressionInfo(
2474: "call(void test.expression.Target.modifiers1()) AND !set(int test.expression.Target.modifier1)",
2475: NAMESPACE).getExpression().match(
2476: new ExpressionContext(PointcutType.CALL, modifier1,
2477: null)));
2478: assertFalse(new ExpressionInfo(
2479: "execution(void test.expression.Target.modifiers1()) && !within(test.expression.Target)",
2480: NAMESPACE).getExpression().match(
2481: new ExpressionContext(PointcutType.EXECUTION,
2482: modifiers1, s_declaringType)));
2483: assertTrue(new ExpressionInfo(
2484: "execution(void test.expression.Target.modifiers1()) && !call(void test.expression.Target.modifiers1())",
2485: NAMESPACE).getExpression().match(
2486: new ExpressionContext(PointcutType.EXECUTION,
2487: modifiers1, s_declaringType)));
2488: ExpressionVisitor expression = new ExpressionInfo(
2489: "execution(void test.expression.Target.modifiers1()) && !call(void test.expression.Target.modifiers3()) && !(call(void test.expression.Target.modifiers1()) || call(void test.expression.Target.modifiers2()))",
2490: NAMESPACE).getExpression();
2491: assertTrue(expression.match(new ExpressionContext(
2492: PointcutType.EXECUTION, modifiers1, s_declaringType)));
2493: assertFalse(expression.match(new ExpressionContext(
2494: PointcutType.CALL, modifiers1, s_declaringType)));
2495: assertFalse(expression.match(new ExpressionContext(
2496: PointcutType.SET, modifier1, s_declaringType)));
2497: assertFalse(new ExpressionInfo(
2498: "call(void test.expression.Target.modifiers1()) && !set(int test.expression.Target.modifier1)",
2499: NAMESPACE).getExpression().match(
2500: new ExpressionContext(PointcutType.CALL, modifier1,
2501: null)));
2502: }
2503:
2504: public void testGrammar() throws Throwable {
2505: // test parsing
2506: new ExpressionInfo("args(..)", NAMESPACE);
2507: new ExpressionInfo("args(foo, java, String[], foo, ..)",
2508: NAMESPACE);
2509: new ExpressionInfo("args(foo, String+)", NAMESPACE);
2510: new ExpressionInfo("args(.., String+)", NAMESPACE);
2511: new ExpressionInfo("args(java.lang.String, ..)", NAMESPACE);
2512: new ExpressionInfo("args(.., String+, ..)", NAMESPACE); // TODO this syntax is a bit dangerous
2513: }
2514:
2515: // ============ args() test =============
2516: public void testMethodArgs1() throws Exception {
2517: assertTrue(new ExpressionInfo(
2518: "call(void test.expression.Target.parameters1(..)) && args(..)",
2519: NAMESPACE).getExpression().match(
2520: new ExpressionContext(PointcutType.CALL, parameters1,
2521: null)));
2522: assertTrue(new ExpressionInfo(
2523: "call(void test.expression.Target.parameters1(..)) && args()",
2524: NAMESPACE).getExpression().match(
2525: new ExpressionContext(PointcutType.CALL, parameters1,
2526: null)));
2527: assertFalse(new ExpressionInfo(
2528: "call(void test.expression.Target.parameters1(..)) && args(int)",
2529: NAMESPACE).getExpression().match(
2530: new ExpressionContext(PointcutType.CALL, parameters1,
2531: null)));
2532: assertFalse(new ExpressionInfo(
2533: "execution(void test.expression.Target.parameters1(..)) && args(.., int)",
2534: NAMESPACE).getExpression().match(
2535: new ExpressionContext(PointcutType.CALL, parameters1,
2536: null)));
2537: assertFalse(new ExpressionInfo(
2538: "execution(void test.expression.Target.parameters1(..)) && args(.., int)",
2539: NAMESPACE).getExpression().match(
2540: new ExpressionContext(PointcutType.CALL, parameters1,
2541: null)));
2542: }
2543:
2544: public void testMethodArgs2() throws Exception {
2545: assertTrue(new ExpressionInfo(
2546: "call(void test.expression.Target.parameters2(..)) && args(..)",
2547: NAMESPACE).getExpression().match(
2548: new ExpressionContext(PointcutType.CALL, parameters2,
2549: null)));
2550: assertFalse(new ExpressionInfo(
2551: "call(void test.expression.Target.parameters2(..)) && args()",
2552: NAMESPACE).getExpression().match(
2553: new ExpressionContext(PointcutType.CALL, parameters2,
2554: null)));
2555: assertFalse(new ExpressionInfo(
2556: "call(void test.expression.Target.parameters2(..)) && args(int)",
2557: NAMESPACE).getExpression().match(
2558: new ExpressionContext(PointcutType.CALL, parameters2,
2559: null)));
2560: assertTrue(new ExpressionInfo(
2561: "call(void test.expression.Target.parameters2(..)) && args(int, float, byte)",
2562: NAMESPACE).getExpression().match(
2563: new ExpressionContext(PointcutType.CALL, parameters2,
2564: null)));
2565: assertTrue(new ExpressionInfo(
2566: "call(void test.expression.Target.parameters2(..)) && args(.., float, byte)",
2567: NAMESPACE).getExpression().match(
2568: new ExpressionContext(PointcutType.CALL, parameters2,
2569: null)));
2570: assertTrue(new ExpressionInfo(
2571: "call(void test.expression.Target.parameters2(..)) && args(.., byte)",
2572: NAMESPACE).getExpression().match(
2573: new ExpressionContext(PointcutType.CALL, parameters2,
2574: null)));
2575: assertTrue(new ExpressionInfo(
2576: "call(void test.expression.Target.parameters2(..)) && args(int, float, ..)",
2577: NAMESPACE).getExpression().match(
2578: new ExpressionContext(PointcutType.CALL, parameters2,
2579: null)));
2580: assertTrue(new ExpressionInfo(
2581: "call(void test.expression.Target.parameters2(..)) && args(int, ..)",
2582: NAMESPACE).getExpression().match(
2583: new ExpressionContext(PointcutType.CALL, parameters2,
2584: null)));
2585:
2586: // AW-263
2587: assertTrue(new ExpressionInfo(
2588: "call(void test.expression.Target.parameters2(..)) && args(int, float, byte, ..)",
2589: NAMESPACE).getExpression().match(
2590: new ExpressionContext(PointcutType.CALL, parameters2,
2591: null)));
2592: assertTrue(new ExpressionInfo(
2593: "call(void test.expression.Target.parameters2(..)) && args(.., int, float, byte, ..)",
2594: NAMESPACE).getExpression().match(
2595: new ExpressionContext(PointcutType.CALL, parameters2,
2596: null)));
2597: assertTrue(new ExpressionInfo(
2598: "call(void test.expression.Target.parameters2(..)) && args(.., int, float, byte)",
2599: NAMESPACE).getExpression().match(
2600: new ExpressionContext(PointcutType.CALL, parameters2,
2601: null)));
2602:
2603: // target method is parameters2bis(int i, short s, byte b, int ibis, float fbis, byte bbis)
2604: assertFalse(new ExpressionInfo(
2605: "call(void test.expression.Target.parameters2bis(..)) && args(int, float, byte, ..)",
2606: NAMESPACE).getExpression().match(
2607: new ExpressionContext(PointcutType.CALL,
2608: parameters2bis, null)));
2609: assertTrue(new ExpressionInfo(
2610: "call(void test.expression.Target.parameters2bis(..)) && args(.., int, float, byte, ..)",
2611: NAMESPACE).getExpression().match(
2612: new ExpressionContext(PointcutType.CALL,
2613: parameters2bis, null)));
2614: assertTrue(new ExpressionInfo(
2615: "call(void test.expression.Target.parameters2bis(..)) && args(.., int, float, byte)",
2616: NAMESPACE).getExpression().match(
2617: new ExpressionContext(PointcutType.CALL,
2618: parameters2bis, null)));
2619: assertTrue(new ExpressionInfo(
2620: "call(void test.expression.Target.parameters2bis(..)) && args(.., int, float, ..)",
2621: NAMESPACE).getExpression().match(
2622: new ExpressionContext(PointcutType.CALL,
2623: parameters2bis, null)));
2624: assertFalse(new ExpressionInfo(
2625: "call(void test.expression.Target.parameters2bis(..)) && args(.., int, float, a, b, c, d, e, f, g, h, i,..)",
2626: NAMESPACE).getExpression().match(
2627: new ExpressionContext(PointcutType.CALL,
2628: parameters2bis, null)));
2629:
2630: assertFalse(new ExpressionInfo(
2631: "call(void test.expression.Target.parameters2(..)) && args(WRONG, ..)",
2632: NAMESPACE).getExpression().match(
2633: new ExpressionContext(PointcutType.CALL, parameters2,
2634: null)));
2635: assertFalse(new ExpressionInfo(
2636: "call(void test.expression.Target.parameters2(..)) && args(.., WRONG)",
2637: NAMESPACE).getExpression().match(
2638: new ExpressionContext(PointcutType.CALL, parameters2,
2639: null)));
2640: assertFalse(new ExpressionInfo(
2641: "call(void test.expression.Target.parameters2(..)) && args(int, float, WRONG)",
2642: NAMESPACE).getExpression().match(
2643: new ExpressionContext(PointcutType.CALL, parameters2,
2644: null)));
2645: assertFalse(new ExpressionInfo(
2646: "call(void test.expression.Target.parameters2(..)) && args(int, float, byte, WRONG)",
2647: NAMESPACE).getExpression().match(
2648: new ExpressionContext(PointcutType.CALL, parameters2,
2649: null)));
2650: }
2651:
2652: public void testMethodArgs3() throws Exception {
2653: assertFalse(new ExpressionInfo(
2654: "call(void test.expression.Target.parameters3())",
2655: NAMESPACE).getExpression().match(
2656: new ExpressionContext(PointcutType.CALL, parameters3,
2657: null)));
2658: assertTrue(new ExpressionInfo(
2659: "call(void test.expression.Target.parameters3(..))",
2660: NAMESPACE).getExpression().match(
2661: new ExpressionContext(PointcutType.CALL, parameters3,
2662: null)));
2663: assertFalse(new ExpressionInfo(
2664: "call(void test.expression.Target.parameters3(int, ..))",
2665: NAMESPACE).getExpression().match(
2666: new ExpressionContext(PointcutType.CALL, parameters3,
2667: null)));
2668: assertTrue(new ExpressionInfo(
2669: "call(void test.expression.Target.parameters3(String, ..))",
2670: NAMESPACE).getExpression().match(
2671: new ExpressionContext(PointcutType.CALL, parameters3,
2672: null)));
2673: assertFalse(new ExpressionInfo(
2674: "call(void test.expression.Target.parameters3(String, String, String))",
2675: NAMESPACE).getExpression().match(
2676: new ExpressionContext(PointcutType.CALL, parameters3,
2677: null)));
2678: assertTrue(new ExpressionInfo(
2679: "call(void test.expression.Target.parameters3(String, StringBuffer, String))",
2680: NAMESPACE).getExpression().match(
2681: new ExpressionContext(PointcutType.CALL, parameters3,
2682: null)));
2683: assertTrue(new ExpressionInfo(
2684: "call(void test.expression.Target.parameters3(String, java.io.Serializable+, String))",
2685: NAMESPACE).getExpression().match(
2686: new ExpressionContext(PointcutType.CALL, parameters3,
2687: null)));
2688: assertFalse(new ExpressionInfo(
2689: "call(void test.expression.Target.parameters3(String, StringBuffer, String, *))",
2690: NAMESPACE).getExpression().match(
2691: new ExpressionContext(PointcutType.CALL, parameters3,
2692: null)));
2693: }
2694:
2695: public void testMethodArgs4() throws Exception {
2696: assertTrue(new ExpressionInfo(
2697: "call(void test.expression.Target.parameters4(..)) && args(..)",
2698: NAMESPACE).getExpression().match(
2699: new ExpressionContext(PointcutType.CALL, parameters4,
2700: null)));
2701: assertTrue(new ExpressionInfo(
2702: "call(void test.expression.Target.parameters4(..)) && args(java.lang.Object[])",
2703: NAMESPACE).getExpression().match(
2704: new ExpressionContext(PointcutType.CALL, parameters4,
2705: null)));
2706: //use of abbreviation on java.lang.*, up to 2 dimension array, see regexp.Pattern
2707: assertTrue(new ExpressionInfo(
2708: "call(void test.expression.Target.parameters4(..)) && args(Object[])",
2709: NAMESPACE).getExpression().match(
2710: new ExpressionContext(PointcutType.CALL, parameters4,
2711: null)));
2712: assertFalse(new ExpressionInfo(
2713: "call(void test.expression.Target.parameters4(..)) && args(java.lang.Object[][])",
2714: NAMESPACE).getExpression().match(
2715: new ExpressionContext(PointcutType.CALL, parameters4,
2716: null)));
2717: }
2718:
2719: public void testMethodArgs5() throws Exception {
2720: assertTrue(new ExpressionInfo(
2721: "call(void test.expression.Target.parameters5(..)) && args(..)",
2722: NAMESPACE).getExpression().match(
2723: new ExpressionContext(PointcutType.CALL, parameters5,
2724: null)));
2725: assertTrue(new ExpressionInfo(
2726: "call(void test.expression.Target.parameters5(..)) && args(int[][])",
2727: NAMESPACE).getExpression().match(
2728: new ExpressionContext(PointcutType.CALL, parameters5,
2729: null)));
2730: assertFalse(new ExpressionInfo(
2731: "call(void test.expression.Target.parameters5(..)) && args(int[])",
2732: NAMESPACE).getExpression().match(
2733: new ExpressionContext(PointcutType.CALL, parameters5,
2734: null)));
2735: }
2736:
2737: public void testMethodArgsBinding() throws Exception {
2738: ExpressionInfo info = null;
2739:
2740: info = new ExpressionInfo(
2741: "call(void test.expression.Target.parameters2(..)) && args(i, f, b)",
2742: NAMESPACE);
2743: info.addArgument("i", "int", this .getClass().getClassLoader());
2744: info
2745: .addArgument("f", "float", this .getClass()
2746: .getClassLoader());
2747: info.addArgument("b", "byte", this .getClass().getClassLoader());
2748: assertTrue(info.getExpression().match(
2749: new ExpressionContext(PointcutType.CALL, parameters2,
2750: null)));
2751:
2752: info = new ExpressionInfo(
2753: "call(void test.expression.Target.parameters2(..)) && args(i, f, byte)",
2754: NAMESPACE);
2755: info.addArgument("i", "int", this .getClass().getClassLoader());
2756: info
2757: .addArgument("f", "float", this .getClass()
2758: .getClassLoader());
2759: assertTrue(info.getExpression().match(
2760: new ExpressionContext(PointcutType.CALL, parameters2,
2761: null)));
2762:
2763: // info = new ExpressionInfo("call(void test.expression.Target.parameters2(..)) && args(i, f, b)", NAMESPACE);
2764: // info.addArgument("i", "int", this.getClass().getClassLoader());
2765: // info.addArgument("f", "WRONG", this.getClass().getClassLoader());
2766: // // b will be considered as a type
2767: // assertFalse(info.getExpression().match(new ExpressionContext(PointcutType.CALL, parameters2, null)));
2768: }
2769:
2770: public void testAnnotationFQN() {
2771: //class @
2772: ExpressionInfo info = new ExpressionInfo(
2773: "within(@examples.annotation.AnnotationA *)", NAMESPACE);
2774: info = new ExpressionInfo(
2775: "within(@examples.annotation.Annotation$A *)",
2776: NAMESPACE);
2777: info = new ExpressionInfo(
2778: "within(@examples.annotation.Annotation$A @bar.Baz *)",
2779: NAMESPACE);
2780: info = new ExpressionInfo(
2781: "within(@examples.annotation.Annotation$A !@bar.Baz *)",
2782: NAMESPACE);
2783:
2784: // method @
2785: info = new ExpressionInfo(
2786: "execution(@examples.annotation.AnnotationA * examples.annotation.Target.*(..))",
2787: NAMESPACE);
2788: info = new ExpressionInfo(
2789: "execution(@examples.annotation.Annotation$A * examples.annotation.Target.*(..))",
2790: NAMESPACE);
2791: info = new ExpressionInfo(
2792: "execution(@examples.annotation.Annotation$A @bar.Baz * examples.annotation.Target.*(..))",
2793: NAMESPACE);
2794:
2795: // field @
2796: info = new ExpressionInfo(
2797: "set(@examples.annotation.AnnotationA * Class.field)",
2798: NAMESPACE);
2799: info = new ExpressionInfo(
2800: "set(@examples.annotation.AnnotationA @bar.Baz * Class.field)",
2801: NAMESPACE);
2802: }
2803:
2804: public void testWithinCtor() {
2805: ExpressionInfo info = null;
2806:
2807: info = new ExpressionInfo(
2808: "withincode(test.expression.Target.new())", NAMESPACE);
2809:
2810: info = new ExpressionInfo(
2811: "execution(* test.expression.Target.*(..)) && withincode(test.expression.Target.new())",
2812: NAMESPACE);
2813: assertTrue(info.getAdvisedClassFilterExpression().match(
2814: new ExpressionContext(PointcutType.EXECUTION,
2815: modifiers1, constructorNoArgPublic)));
2816: assertTrue(info.getExpression().match(
2817: new ExpressionContext(PointcutType.EXECUTION,
2818: modifiers1, constructorNoArgPublic)));
2819: // will match since we limit early match to declaring type:
2820: assertTrue(info.getAdvisedClassFilterExpression().match(
2821: new ExpressionContext(PointcutType.EXECUTION,
2822: modifiers1, constructorIntArgPrivate)));
2823: assertFalse(info.getExpression().match(
2824: new ExpressionContext(PointcutType.EXECUTION,
2825: modifiers1, constructorIntArgPrivate)));
2826:
2827: info = new ExpressionInfo(
2828: "execution(* test.expression.Target.*(..)) && withincode(test.expression.Target.new(int))",
2829: NAMESPACE);
2830: assertTrue(info.getAdvisedClassFilterExpression().match(
2831: new ExpressionContext(PointcutType.EXECUTION,
2832: modifiers1, constructorIntArgPrivate)));
2833: assertTrue(info.getExpression().match(
2834: new ExpressionContext(PointcutType.EXECUTION,
2835: modifiers1, constructorIntArgPrivate)));
2836: // will match since we limit early match to declaring type:
2837: assertTrue(info.getAdvisedClassFilterExpression().match(
2838: new ExpressionContext(PointcutType.EXECUTION,
2839: modifiers1, constructorNoArgPublic)));
2840: assertFalse(info.getExpression().match(
2841: new ExpressionContext(PointcutType.EXECUTION,
2842: modifiers1, constructorNoArgPublic)));
2843:
2844: info = new ExpressionInfo(
2845: "execution(* test.expression.Target.*(..)) && withincode(private test.expression.Target.new())",
2846: NAMESPACE);
2847: assertTrue(info.getAdvisedClassFilterExpression().match(
2848: new ExpressionContext(PointcutType.EXECUTION,
2849: modifiers1, constructorIntArgPrivate)));
2850: assertFalse(info.getExpression().match(
2851: new ExpressionContext(PointcutType.EXECUTION,
2852: modifiers1, constructorIntArgPrivate)));
2853: assertTrue(info.getAdvisedClassFilterExpression().match(
2854: new ExpressionContext(PointcutType.EXECUTION,
2855: modifiers1, constructorNoArgPublic)));
2856: assertFalse(info.getExpression().match(
2857: new ExpressionContext(PointcutType.EXECUTION,
2858: modifiers1, constructorNoArgPublic)));
2859:
2860: // test early filtering
2861: info = new ExpressionInfo(
2862: "execution(* test.expression.Target.*(..)) && withincode(test.expressionWRONG.Target.new())",
2863: NAMESPACE);
2864: assertFalse(info.getAdvisedClassFilterExpression().match(
2865: new ExpressionContext(PointcutType.EXECUTION,
2866: modifier1, constructorNoArgPublic)));
2867: }
2868:
2869: public void testThis() {
2870: ClassInfo otherType = JavaClassInfo.getClassInfo(String.class);
2871: ExpressionInfo info = null;
2872:
2873: info = new ExpressionInfo(
2874: "execution(* parameters1(..)) && this(test.expression.Target)",
2875: NAMESPACE);
2876: assertTrue(info.getAdvisedClassFilterExpression().match(
2877: new ExpressionContext(PointcutType.EXECUTION,
2878: s_declaringType, s_declaringType)));
2879: assertTrue(info.getAdvisedClassFilterExpression().match(
2880: new ExpressionContext(PointcutType.EXECUTION,
2881: parameters1, s_declaringType)));
2882: assertTrue(info.getAdvisedClassFilterExpression().match(
2883: new ExpressionContext(PointcutType.EXECUTION,
2884: parameters2, s_declaringType)));
2885: assertFalse(info.getAdvisedClassFilterExpression().match(
2886: new ExpressionContext(PointcutType.EXECUTION,
2887: parameters2, otherType)));
2888: assertFalse(info.getExpression().match(
2889: new ExpressionContext(PointcutType.EXECUTION,
2890: s_declaringType, s_declaringType)));
2891: assertTrue(info.getExpression().match(
2892: new ExpressionContext(PointcutType.EXECUTION,
2893: parameters1, s_declaringType)));
2894: assertFalse(info.getExpression().match(
2895: new ExpressionContext(PointcutType.EXECUTION,
2896: parameters2, s_declaringType)));
2897: assertFalse(info.getExpression().match(
2898: new ExpressionContext(PointcutType.EXECUTION,
2899: parameters2, otherType)));
2900:
2901: info = new ExpressionInfo(
2902: "call(* parameters1(..)) && this(test.expression.Target)",
2903: NAMESPACE);
2904: assertTrue(info.getAdvisedClassFilterExpression().match(
2905: new ExpressionContext(PointcutType.CALL,
2906: s_declaringType, s_declaringType)));
2907: assertTrue(info.getAdvisedClassFilterExpression().match(
2908: new ExpressionContext(PointcutType.CALL, parameters1,
2909: s_declaringType)));
2910: assertTrue(info.getAdvisedClassFilterExpression().match(
2911: new ExpressionContext(PointcutType.CALL, parameters2,
2912: s_declaringType)));
2913: assertFalse(info.getAdvisedClassFilterExpression().match(
2914: new ExpressionContext(PointcutType.CALL, parameters2,
2915: otherType)));
2916: assertFalse(info.getExpression().match(
2917: new ExpressionContext(PointcutType.CALL,
2918: s_declaringType, s_declaringType)));
2919: assertTrue(info.getExpression().match(
2920: new ExpressionContext(PointcutType.CALL, parameters1,
2921: s_declaringType)));
2922: assertFalse(info.getExpression().match(
2923: new ExpressionContext(PointcutType.CALL, parameters2,
2924: s_declaringType)));
2925: assertFalse(info.getExpression().match(
2926: new ExpressionContext(PointcutType.CALL, parameters2,
2927: otherType)));
2928:
2929: info = new ExpressionInfo(
2930: "call(* parameters1(..)) && this(java.lang.String)",
2931: NAMESPACE);
2932: assertTrue(info.getAdvisedClassFilterExpression().match(
2933: new ExpressionContext(PointcutType.CALL, parameters1,
2934: otherType)));
2935: assertTrue(info.getExpression().match(
2936: new ExpressionContext(PointcutType.CALL, parameters1,
2937: otherType)));
2938: assertTrue(info.getAdvisedClassFilterExpression().match(
2939: new ExpressionContext(PointcutType.CALL, parameters2,
2940: otherType)));
2941: assertFalse(info.getExpression().match(
2942: new ExpressionContext(PointcutType.CALL, parameters2,
2943: otherType)));
2944:
2945: //TODO test when withinInfo is a static method (should not match)
2946: //same with field get / set
2947: }
2948:
2949: public void testTarget() {
2950: ClassInfo otherType = JavaClassInfo.getClassInfo(String.class);
2951: ExpressionInfo info = null;
2952:
2953: info = new ExpressionInfo(
2954: "execution(* parameters1(..)) && target(test.expression.Target)",
2955: NAMESPACE);
2956: assertTrue(info.getAdvisedClassFilterExpression().match(
2957: new ExpressionContext(PointcutType.EXECUTION,
2958: s_declaringType, s_declaringType)));
2959: assertTrue(info.getAdvisedClassFilterExpression().match(
2960: new ExpressionContext(PointcutType.EXECUTION,
2961: parameters1, s_declaringType)));
2962: assertTrue(info.getAdvisedClassFilterExpression().match(
2963: new ExpressionContext(PointcutType.EXECUTION,
2964: parameters2, s_declaringType)));
2965: assertTrue(info.getAdvisedClassFilterExpression().match(
2966: new ExpressionContext(PointcutType.EXECUTION,
2967: parameters2, otherType)//otherType ignored
2968: ));
2969: assertFalse(info.getExpression().match(
2970: new ExpressionContext(PointcutType.EXECUTION,
2971: s_declaringType, s_declaringType)));
2972: assertTrue(info.getExpression().match(
2973: new ExpressionContext(PointcutType.EXECUTION,
2974: parameters1, s_declaringType)));
2975: assertFalse(info.getExpression().match(
2976: new ExpressionContext(PointcutType.EXECUTION,
2977: parameters2, s_declaringType)));
2978: assertFalse(info.getExpression().match(
2979: new ExpressionContext(PointcutType.EXECUTION,
2980: parameters2, otherType)));
2981:
2982: info = new ExpressionInfo(
2983: "call(* parameters1(..)) && target(test.expression.Target)",
2984: NAMESPACE);
2985: assertTrue(info.getAdvisedClassFilterExpression().match(
2986: new ExpressionContext(PointcutType.CALL,
2987: s_declaringType, s_declaringType)));
2988: assertTrue(info.getAdvisedClassFilterExpression().match(
2989: new ExpressionContext(PointcutType.CALL, parameters1,
2990: s_declaringType)));
2991: assertTrue(info.getAdvisedClassFilterExpression().match(
2992: new ExpressionContext(PointcutType.CALL, parameters2,
2993: s_declaringType)));
2994: assertTrue(info.getAdvisedClassFilterExpression().match(
2995: new ExpressionContext(PointcutType.CALL, parameters2,
2996: otherType)//otherType ignored
2997: ));
2998: assertFalse(info.getExpression().match(
2999: new ExpressionContext(PointcutType.CALL,
3000: s_declaringType, s_declaringType)));
3001: assertTrue(info.getExpression().match(
3002: new ExpressionContext(PointcutType.CALL, parameters1,
3003: s_declaringType)));
3004: assertFalse(info.getExpression().match(
3005: new ExpressionContext(PointcutType.CALL, parameters2,
3006: s_declaringType)));
3007: assertFalse(info.getExpression().match(
3008: new ExpressionContext(PointcutType.CALL, parameters2,
3009: otherType)));
3010:
3011: info = new ExpressionInfo(
3012: "call(* parameters1(..)) && target(java.lang.String)",
3013: NAMESPACE);
3014: assertTrue(info.getAdvisedClassFilterExpression().match(
3015: new ExpressionContext(PointcutType.CALL, parameters1,
3016: otherType)));
3017: assertFalse(info.getExpression().match(
3018: new ExpressionContext(PointcutType.CALL, parameters1,
3019: otherType)));
3020: assertTrue(info.getAdvisedClassFilterExpression().match(
3021: new ExpressionContext(PointcutType.CALL, parameters2,
3022: otherType)));
3023: assertFalse(info.getExpression().match(
3024: new ExpressionContext(PointcutType.CALL, parameters2,
3025: otherType)));
3026:
3027: //TODO test when withinInfo is a static method (should not match)
3028: //same with field get / set
3029: }
3030:
3031: public static void main(String[] args) {
3032: junit.textui.TestRunner.run(suite());
3033: }
3034:
3035: public static junit.framework.Test suite() {
3036: return new junit.framework.TestSuite(ExpressionTest.class);
3037: }
3038:
3039: private static ExpressionInfo singleCflowOf(
3040: ExpressionInfo singleCflowExpression) {
3041: CflowBinding cfb = (CflowBinding) CflowBinding
3042: .getCflowBindingsForCflowOf(singleCflowExpression).get(
3043: 0);
3044: return cfb.getExpression();
3045: }
3046:
3047: }
|