From eea33c63a820011ca95cd7fd844133941349c265 Mon Sep 17 00:00:00 2001 From: aclement Date: Fri, 14 Mar 2008 18:55:11 +0000 Subject: [PATCH] 205907 - world remembers registered handlers --- .../tools/PointcutDesignatorHandlerTests.java | 71 ++++++++++++++++--- 1 file changed, 63 insertions(+), 8 deletions(-) diff --git a/weaver/testsrc/org/aspectj/weaver/tools/PointcutDesignatorHandlerTests.java b/weaver/testsrc/org/aspectj/weaver/tools/PointcutDesignatorHandlerTests.java index 23acf58a5..690f64d32 100644 --- a/weaver/testsrc/org/aspectj/weaver/tools/PointcutDesignatorHandlerTests.java +++ b/weaver/testsrc/org/aspectj/weaver/tools/PointcutDesignatorHandlerTests.java @@ -11,13 +11,13 @@ * ******************************************************************/ 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 +} -- 2.39.5