Package org.codehaus.aspectwerkz.expression

Examples of org.codehaus.aspectwerkz.expression.ExpressionInfo


    // ============ hasXXX =============
    public void tesHasMethod() throws Exception {
        ClassInfo klass = JavaClassInfo.getClassInfo(Target.class);
        ClassInfo string = JavaClassInfo.getClassInfo(String.class);
        assertTrue(new ExpressionInfo(
            "hasmethod(void modifiers1())",
            NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.EXECUTION, klass, klass)));
        assertFalse(new ExpressionInfo(
            "hasmethod(void modifiers1())",
            NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, klass, string)));
        // will match at the AdvisedClassFilterExpression level
        assertTrue(new ExpressionInfo(
            "hasmethod(* getClass())",
            NAMESPACE).getAdvisedClassFilterExpression().match(new ExpressionContext(PointcutType.EXECUTION, klass, klass)));
        // but not at the Expression level
        assertFalse(new ExpressionInfo(
            "hasmethod(* getClass())",
            NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.EXECUTION, klass, klass)));
        // unless method is in class hierarchy
        assertFalse(new ExpressionInfo(
            "hasmethod(* java.lang.Object+.getClass())",
            NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.EXECUTION, klass, klass)));
        // even a fake method will match, since we extend java.lang.Object, for the AdvisedClassFilterExpression level
        assertTrue(new ExpressionInfo(
            "hasmethod(* java.lang.Object+.DOESNOTEXIST())",
            NAMESPACE).getAdvisedClassFilterExpression().match(new ExpressionContext(PointcutType.EXECUTION, klass, klass)));
        // but not at Expression level
        assertFalse(new ExpressionInfo(
            "hasmethod(* java.lang.Object+.DOESNOTEXIST())",
            NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.EXECUTION, klass, klass)));
    }
View Full Code Here


    }

    public void tesHasField() throws Exception {
        ClassInfo klass = JavaClassInfo.getClassInfo(Target.class);
        ClassInfo string = JavaClassInfo.getClassInfo(String.class);
        assertTrue(new ExpressionInfo(
            "hasfield(int modifier1)",
            NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.EXECUTION, klass, klass)));
        assertFalse(new ExpressionInfo(
            "hasfield(* modifier1)",
            NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, klass, string)));
        // will match at the AdvisedClassFilterExpression level
        assertTrue(new ExpressionInfo(
            "hasfield(* value)",
            NAMESPACE).getAdvisedClassFilterExpression().match(new ExpressionContext(PointcutType.EXECUTION, klass, klass)));
        // but not at the Expression level
        assertFalse(new ExpressionInfo(
            "hasfield(* value)",
            NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.EXECUTION, klass, klass)));
        //value field exists in String.class
        assertTrue(new ExpressionInfo(
            "hasfield(* value)",
            NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, klass, string)));
    }
View Full Code Here

    // ============ within type tests =============
    public void testWithinType1() throws Exception {
        ClassInfo klass = JavaClassInfo.getClassInfo(Target.class);
        MethodInfo method = JavaMethodInfo.getMethodInfo(Target.class.getDeclaredMethod("modifiers1", new Class[] {}));
        assertTrue(new ExpressionInfo(
            "execution(void test.expression.Target.modifiers1()) AND within(test.expression.Target)",
            NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.EXECUTION, method, s_declaringType)));
        assertTrue(new ExpressionInfo(
            "call(void test.expression.Target.modifiers1()) AND within(test.expression.Target)",
            NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, method, s_declaringType)));
        assertFalse(new ExpressionInfo(
            "call(void test.expression.Target.modifiers1()) AND NOT within(test.expression.Target)",
            NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, method, s_declaringType)));
    }
View Full Code Here

    }

    public void testWithinType2() throws Exception {
        ClassInfo klass = JavaClassInfo.getClassInfo(Target.class);
        MethodInfo method = JavaMethodInfo.getMethodInfo(Target.class.getDeclaredMethod("modifiers1", new Class[] {}));
        assertTrue(new ExpressionInfo("execution(void *..*.modifiers1()) AND within(test.expression.Target)", NAMESPACE)
                .getAdvisedClassFilterExpression().match(
                    new ExpressionContext(PointcutType.EXECUTION, method, s_declaringType)));
        assertTrue(new ExpressionInfo("execution(void *..*.modifiers1()) AND within(@Serializable *..*)", NAMESPACE)
                .getAdvisedClassFilterExpression().match(
                    new ExpressionContext(PointcutType.EXECUTION, method, s_declaringType)));
        assertFalse(new ExpressionInfo(
            "execution(void *..*.modifiers1()) AND NOT within(@Serializable *..*)",
            NAMESPACE).getAdvisedClassFilterExpression().match(
            new ExpressionContext(PointcutType.EXECUTION, method, s_declaringType)));
    }
View Full Code Here

            new ExpressionContext(PointcutType.EXECUTION, method, s_declaringType)));
    }

    public void testWithinCodeType() throws Exception {
        MethodInfo method = JavaMethodInfo.getMethodInfo(Target.class.getDeclaredMethod("modifiers1", new Class[] {}));
        assertTrue(new ExpressionInfo(
            "execution(void test.expression.Target.modifiers1()) AND withincode(void test.expression.Target.modifiers1())",
            NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.EXECUTION, method, method)));
        assertTrue(new ExpressionInfo(
            "call(void test.expression.Target.modifiers1()) AND withincode(void test.expression.Target.modifiers1())",
            NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, method, method)));
        assertFalse(new ExpressionInfo(
            "call(void test.expression.Target.modifiers1()) AND NOT withincode(void test.expression.Target.modifiers1())",
            NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, method, method)));
    }
View Full Code Here

            NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, method, method)));
    }

    // ============ pointcut ref tests =============
    public void testPointcutReference() throws Exception {
        s_namespace.addExpressionInfo("pc1", new ExpressionInfo(
            "execution(void test.expression.Target.modifiers2())",
            NAMESPACE));
        s_namespace.addExpressionInfo("pc2", new ExpressionInfo(
            "execution(void test.expression.Target.modifiers3())",
            NAMESPACE));
        assertTrue(new ExpressionInfo("execution(void test.expression.Target.modifiers1()) || pc1", NAMESPACE)
                .getExpression().match(new ExpressionContext(PointcutType.EXECUTION, modifiers1, null)));
        assertTrue(new ExpressionInfo("execution(void test.expression.Target.modifiers1()) || pc1", NAMESPACE)
                .getExpression().match(new ExpressionContext(PointcutType.EXECUTION, modifiers2, null)));
        assertTrue(new ExpressionInfo("execution(void test.expression.Target.modifiers1()) || pc2", NAMESPACE)
                .getExpression().match(new ExpressionContext(PointcutType.EXECUTION, modifiers3, null)));
        assertTrue(new ExpressionInfo("execution(void test.expression.Target.modifiers1()) || pc1 || pc2", NAMESPACE)
                .getExpression().match(new ExpressionContext(PointcutType.EXECUTION, modifiers1, null)));
        assertTrue(new ExpressionInfo("execution(void test.expression.Target.modifiers1()) || pc1 || pc2", NAMESPACE)
                .getExpression().match(new ExpressionContext(PointcutType.EXECUTION, modifiers2, null)));
        assertTrue(new ExpressionInfo("execution(void test.expression.Target.modifiers1()) || pc1 || pc2 ", NAMESPACE)
                .getExpression().match(new ExpressionContext(PointcutType.EXECUTION, modifiers3, null)));
        assertTrue(new ExpressionInfo("execution(void test.expression.Target.modifiers1()) || pc2 || pc1", NAMESPACE)
                .getExpression().match(new ExpressionContext(PointcutType.EXECUTION, modifiers1, null)));
        assertTrue(new ExpressionInfo("execution(void test.expression.Target.modifiers1()) || pc2 || pc1", NAMESPACE)
                .getExpression().match(new ExpressionContext(PointcutType.EXECUTION, modifiers2, null)));
        assertTrue(new ExpressionInfo("execution(void test.expression.Target.modifiers1()) || pc2 || pc1 ", NAMESPACE)
                .getExpression().match(new ExpressionContext(PointcutType.EXECUTION, modifiers3, null)));
        assertTrue(new ExpressionInfo("pc1 || pc2 || execution(void test.expression.Target.modifiers1())", NAMESPACE)
                .getExpression().match(new ExpressionContext(PointcutType.EXECUTION, modifiers1, null)));
        assertTrue(new ExpressionInfo("pc1 || pc2 || execution(void test.expression.Target.modifiers1())", NAMESPACE)
                .getExpression().match(new ExpressionContext(PointcutType.EXECUTION, modifiers2, null)));
        assertTrue(new ExpressionInfo("pc1 || pc2 || execution(void test.expression.Target.modifiers1())", NAMESPACE)
                .getExpression().match(new ExpressionContext(PointcutType.EXECUTION, modifiers3, null)));
        assertTrue(new ExpressionInfo(
            "(execution(void test.expression.Target.modifiers1()) || pc1 || pc2) AND within(test.expression.Target)",
            NAMESPACE).getExpression()
                .match(new ExpressionContext(PointcutType.EXECUTION, modifiers1, s_declaringType)));
        assertTrue(new ExpressionInfo(
            "(execution(void test.expression.Target.modifiers1()) || pc1 || pc2) AND within(test.expression.Target)",
            NAMESPACE).getExpression()
                .match(new ExpressionContext(PointcutType.EXECUTION, modifiers2, s_declaringType)));
        assertTrue(new ExpressionInfo(
            "(execution(void test.expression.Target.modifiers1()) || pc1 || pc2) AND within(test.expression.Target)",
            NAMESPACE).getExpression()
                .match(new ExpressionContext(PointcutType.EXECUTION, modifiers3, s_declaringType)));
        assertTrue(new ExpressionInfo(
            "within(test.expression.Target) && (pc1 || pc2 || execution(void test.expression.Target.modifiers1()))",
            NAMESPACE).getExpression()
                .match(new ExpressionContext(PointcutType.EXECUTION, modifiers1, s_declaringType)));
        assertTrue(new ExpressionInfo(
            "within(test.expression.Target) && (pc2 || pc1 || execution(void test.expression.Target.modifiers1()))",
            NAMESPACE).getExpression()
                .match(new ExpressionContext(PointcutType.EXECUTION, modifiers2, s_declaringType)));
        assertTrue(new ExpressionInfo(
            "within(test.expression.Target) && (pc1 || execution(void test.expression.Target.modifiers1()) || pc2)",
            NAMESPACE).getExpression()
                .match(new ExpressionContext(PointcutType.EXECUTION, modifiers3, s_declaringType)));
    }
View Full Code Here

    public void testPointcutReferenceOutsideScope() throws Exception {
        String namespace1 = "Lib";
        String namespace2 = "org.moneymaker.Util";
        ExpressionNamespace.getNamespace(namespace1).addExpressionInfo(
            "pc1",
            new ExpressionInfo("execution(void test.expression.Target.modifiers1())", namespace1));
        ExpressionNamespace.getNamespace(namespace2).addExpressionInfo(
            "pc2",
            new ExpressionInfo("execution(void test.expression.Target.modifiers2())", namespace2));
        assertTrue(new ExpressionInfo("execution(* foo.bar.*()) || Lib.pc1", NAMESPACE).getExpression().match(
            new ExpressionContext(PointcutType.EXECUTION, modifiers1, null)));
        assertTrue(new ExpressionInfo("Lib.pc1 || execution(* foo.bar.*())", NAMESPACE).getExpression().match(
            new ExpressionContext(PointcutType.EXECUTION, modifiers1, null)));
        assertTrue(new ExpressionInfo("org.moneymaker.Util.pc2 || Lib.pc1", NAMESPACE).getExpression().match(
            new ExpressionContext(PointcutType.EXECUTION, modifiers2, null)));
        assertTrue(new ExpressionInfo("Lib.pc1 || org.moneymaker.Util.pc2", NAMESPACE).getExpression().match(
            new ExpressionContext(PointcutType.EXECUTION, modifiers2, null)));
        assertFalse(new ExpressionInfo("execution(void test.expression.Target.modifiers1()) || Lib.pc1", NAMESPACE)
                .getExpression().match(new ExpressionContext(PointcutType.EXECUTION, modifiers2, null)));
    }
View Full Code Here

                .getExpression().match(new ExpressionContext(PointcutType.EXECUTION, modifiers2, null)));
    }

    // ============ and tests =============
    public void testAnd() throws Exception {
        assertTrue(new ExpressionInfo(
            "execution(void test.expression.Target.modifiers1()) AND within(test.expression.Target)",
            NAMESPACE).getExpression()
                .match(new ExpressionContext(PointcutType.EXECUTION, modifiers1, s_declaringType)));
        assertFalse(new ExpressionInfo(
            "execution(void test.expression.Target.modifiers1()) AND call(void test.expression.Target.modifiers1())",
            NAMESPACE).getExpression()
                .match(new ExpressionContext(PointcutType.EXECUTION, modifiers1, s_declaringType)));
        assertFalse(new ExpressionInfo(
            "call(void test.expression.Target.modifiers1()) AND set(int test.expression.Target.modifier1)",
            NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, modifier1, null)));
        assertTrue(new ExpressionInfo(
            "execution(void test.expression.Target.modifiers1()) && within(test.expression.Target)",
            NAMESPACE).getExpression()
                .match(new ExpressionContext(PointcutType.EXECUTION, modifiers1, s_declaringType)));
        assertFalse(new ExpressionInfo(
            "execution(void test.expression.Target.modifiers1()) && call(void test.expression.Target.modifiers1())",
            NAMESPACE).getExpression()
                .match(new ExpressionContext(PointcutType.EXECUTION, modifiers1, s_declaringType)));
        assertFalse(new ExpressionInfo(
            "call(void test.expression.Target.modifiers1()) && set(int test.expression.Target.modifier1)",
            NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, modifier1, null)));
    }
View Full Code Here

            NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, modifier1, null)));
    }

    // ============ or tests =============
    public void testOr() throws Exception {
        assertTrue(new ExpressionInfo(
            "execution(void test.expression.Target.modifiers1()) OR call(void test.expression.Target.modifiers1())",
            NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.EXECUTION, modifiers1, null)));
        assertTrue(new ExpressionInfo(
            "execution(void test.expression.Target.modifiers1()) OR call(void test.expression.Target.modifiers1())",
            NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, modifiers1, null)));
        assertTrue(new ExpressionInfo(
            "call(void test.expression.Target.modifiers1()) OR set(int test.expression.Target.modifiers)",
            NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, modifiers1, null)));
        assertTrue(new ExpressionInfo(
            "set(int test.expression.Target.modifier1) OR call(void test.expression.Target.modifiers1())",
            NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.SET, modifier1, null)));
        assertTrue(new ExpressionInfo(
            "call(void test.expression.Target.modifiers1()) OR set(int test.expression.Target.modifier1)",
            NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.SET, modifier1, null)));
        assertTrue(new ExpressionInfo(
            "execution(void test.expression.Target.modifiers1()) || call(void test.expression.Target.modifiers1())",
            NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.EXECUTION, modifiers1, null)));
        assertTrue(new ExpressionInfo(
            "execution(void test.expression.Target.modifiers1()) || call(void test.expression.Target.modifiers1())",
            NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, modifiers1, null)));
        assertTrue(new ExpressionInfo(
            "call(void test.expression.Target.modifiers1()) || set(int test.expression.Target.modifier1)",
            NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, modifiers1, null)));
        assertTrue(new ExpressionInfo(
            "call(void test.expression.Target.modifiers1()) || set(int test.expression.Target.modifier1)",
            NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.SET, modifier1, null)));
    }
View Full Code Here

            NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.SET, modifier1, null)));
    }

    // ============ not tests =============
    public void testNot() throws Exception {
        assertFalse(new ExpressionInfo(
            "execution(void test.expression.Target.modifiers1()) AND NOT within(test.expression.Target)",
            NAMESPACE).getExpression()
                .match(new ExpressionContext(PointcutType.EXECUTION, modifiers1, s_declaringType)));
        assertTrue(new ExpressionInfo(
            "execution(void test.expression.Target.modifiers1()) AND NOT call(void test.expression.Target.modifiers1())",
            NAMESPACE).getExpression()
                .match(new ExpressionContext(PointcutType.EXECUTION, modifiers1, s_declaringType)));
        assertFalse(new ExpressionInfo(
            "call(void test.expression.Target.modifiers1()) AND NOT set(int test.expression.Target.modifier1)",
            NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, modifier1, null)));
        assertFalse(new ExpressionInfo(
            "execution(void test.expression.Target.modifiers1()) && !within(test.expression.Target)",
            NAMESPACE).getExpression()
                .match(new ExpressionContext(PointcutType.EXECUTION, modifiers1, s_declaringType)));
        assertTrue(new ExpressionInfo(
            "execution(void test.expression.Target.modifiers1()) && !call(void test.expression.Target.modifiers1())",
            NAMESPACE).getExpression()
                .match(new ExpressionContext(PointcutType.EXECUTION, modifiers1, s_declaringType)));
        ExpressionVisitor expression = new ExpressionInfo(
            "execution(void test.expression.Target.modifiers1()) && !call(void test.expression.Target.modifiers3()) && !(call(void test.expression.Target.modifiers1()) || call(void test.expression.Target.modifiers2()))",
            NAMESPACE).getExpression();
        assertTrue(expression.match(new ExpressionContext(PointcutType.EXECUTION, modifiers1, s_declaringType)));
        assertFalse(expression.match(new ExpressionContext(PointcutType.CALL, modifiers1, s_declaringType)));
        assertFalse(expression.match(new ExpressionContext(PointcutType.SET, modifier1, s_declaringType)));
        assertFalse(new ExpressionInfo(
            "call(void test.expression.Target.modifiers1()) && !set(int test.expression.Target.modifier1)",
            NAMESPACE).getExpression().match(new ExpressionContext(PointcutType.CALL, modifier1, null)));
    }
View Full Code Here

TOP

Related Classes of org.codehaus.aspectwerkz.expression.ExpressionInfo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.