/************************************************
 * Copyright (c) Shen Li. All rights reserved.  *
 * http://joyaop.sourceforge.net                *
 * -------------------------------------------- *
 * Distributable under LGPL license.            *
 * See terms of license at gnu.org.             *
 ************************************************/
package test.config;

import junit.framework.TestCase;
import net.sf.joyaop.config.PointcutExpressionParser;
import net.sf.joyaop.framework.Pointcut;
import net.sf.joyaop.impl.Pointcuts;

import java.io.Serializable;

/**
 * @author Shen Li
 */
public class PointcutExpressionTest extends TestCase {
    public void testExpression() {
        PointcutExpressionParser parser = new PointcutExpressionParser();
        parser.addPointcutDefinition("pointcut", "execution(aaa) AND (target(bbb) OR target(ccc))");
        String expr = "pointcut AND !(interface(java.io.Serializable) AND target(ddd))";
        Pointcut p1 = Pointcuts.byRegexp("bbb", null);
        p1 = Pointcuts.or(p1, Pointcuts.byRegexp("ccc", null));
        p1 = Pointcuts.and(p1, Pointcuts.byRegexp(null, "aaa"));
        Pointcut p2 = Pointcuts.byInterface(Serializable.class);
        p2 = Pointcuts.and(p2, Pointcuts.byRegexp("ddd", null));
        p2 = Pointcuts.not(p2);
        p1 = Pointcuts.and(p1, p2);
        assertTrue(p1.equals(parser.parse(expr)));
    }
}
