]> source.dussan.org Git - aspectj.git/commitdiff
205907 - world remembers registered handlers
authoraclement <aclement>
Fri, 14 Mar 2008 18:55:11 +0000 (18:55 +0000)
committeraclement <aclement>
Fri, 14 Mar 2008 18:55:11 +0000 (18:55 +0000)
weaver/testsrc/org/aspectj/weaver/tools/PointcutDesignatorHandlerTests.java

index 23acf58a57707aacae42601b4e961789dbeac67a..690f64d32af2191f1b5030fa01714142c5f6e220 100644 (file)
  * ******************************************************************/
 package org.aspectj.weaver.tools;
 
-import org.aspectj.util.LangUtil;
-
 import junit.framework.TestCase;
 
+import org.aspectj.util.LangUtil;
+
 /**
- * @author Adrian
- *
+ * @author Adrian Colyer
+ * 
  */
 public class PointcutDesignatorHandlerTests extends TestCase {
 
@@ -60,9 +60,64 @@ public class PointcutDesignatorHandlerTests extends TestCase {
                assertEquals("service.*",beanHandler.getExpressionLastAskedToParse());
        }
        
-       public void testParseWithHandlerAndMultipleSegments() { 
-               if (needToSkip) return;
-               PointcutParser parser = PointcutParser.getPointcutParserSupportingAllPrimitivesAndUsingContextClassloaderForResolution();
+    
+       /*
+     * Bug 205907 - the registered pointcut designator does not also get registered with the
+     * InternalUseOnlyPointcutParser inside the Java15ReflectionBasedReferenceTypeDelegate code. First test checks
+     * parsing is OK
+     */
+    public void testParsingBeanInReferencePointcut01() throws Exception {
+        if (needToSkip) return;
+        PointcutParser parser = PointcutParser.getPointcutParserSupportingAllPrimitivesAndUsingContextClassloaderForResolution();
+        BeanDesignatorHandler beanHandler = new BeanDesignatorHandler();
+        parser.registerPointcutDesignatorHandler(beanHandler);
+        // The pointcut in CounterAspect look as follows:
+        //
+        // @Pointcut("execution(* setAge(..)) && bean(testBean1)")
+        // public void testBean1SetAge() { }
+
+        // This should be found and resolved
+        PointcutExpression pc = parser.parsePointcutExpression("CounterAspect.testBean1SetAge()");
+
+    }
+
+    /*
+     * Bug 205907 - the registered pointcut designator does not also get registered with the
+     * InternalUseOnlyPointcutParser inside the Java15ReflectionBasedReferenceTypeDelegate code. This test checks the
+     * actual matching.
+     */
+    public void testParsingBeanInReferencePointcut02() throws Exception {
+        if (needToSkip) return;
+        PointcutParser parser = PointcutParser.getPointcutParserSupportingAllPrimitivesAndUsingContextClassloaderForResolution();
+        BeanDesignatorHandler beanHandler = new BeanDesignatorHandler();
+        parser.registerPointcutDesignatorHandler(beanHandler);
+        // The pointcut in CounterAspect look as follows:
+        //
+        // @Pointcut("execution(* toString(..)) && bean(testBean1)")
+        // public void testBean1toString() { }
+        
+        // This should be found and resolved
+        PointcutExpression pc = parser.parsePointcutExpression("CounterAspect.testBean1toString()");
+
+        DefaultMatchingContext context = new DefaultMatchingContext();
+        context.addContextBinding("beanName", "testBean1");
+        pc.setMatchingContext(context);
+        ShadowMatch sm = pc.matchesMethodExecution(Object.class.getMethod("toString", new Class[0]));
+        assertTrue(sm.alwaysMatches());
+        
+        sm = pc.matchesMethodExecution(Object.class.getMethod("hashCode", new Class[0]));
+        assertTrue(sm.neverMatches());
+        
+        context = new DefaultMatchingContext();
+        context.addContextBinding("beanName", "testBean2");
+        pc.setMatchingContext(context);
+        sm = pc.matchesMethodExecution(Object.class.getMethod("toString", new Class[0]));
+        assertTrue(sm.neverMatches());
+    }
+
+    public void testParseWithHandlerAndMultipleSegments() {
+        if (needToSkip) return;
+        PointcutParser parser = PointcutParser.getPointcutParserSupportingAllPrimitivesAndUsingContextClassloaderForResolution();
                BeanDesignatorHandler beanHandler = new BeanDesignatorHandler();
                parser.registerPointcutDesignatorHandler(beanHandler);
                parser.parsePointcutExpression("bean(org.xyz.someapp..*)");
@@ -192,4 +247,4 @@ public class PointcutDesignatorHandlerTests extends TestCase {
                        return this.beanNamePattern.equals(matchContext.getBinding("beanName"));
                }
        }               
-}
\ No newline at end of file
+}