Search in sources :

Example 1 with SourceLocation

use of org.aspectj.lang.reflect.SourceLocation in project spring-framework by spring-projects.

the class MethodInvocationProceedingJoinPointTests method testCanGetSourceLocationFromJoinPoint.

@Test
public void testCanGetSourceLocationFromJoinPoint() {
    final Object raw = new TestBean();
    ProxyFactory pf = new ProxyFactory(raw);
    pf.addAdvisor(ExposeInvocationInterceptor.ADVISOR);
    pf.addAdvice(new MethodBeforeAdvice() {

        @Override
        public void before(Method method, Object[] args, Object target) throws Throwable {
            SourceLocation sloc = AbstractAspectJAdvice.currentJoinPoint().getSourceLocation();
            assertEquals("Same source location must be returned on subsequent requests", sloc, AbstractAspectJAdvice.currentJoinPoint().getSourceLocation());
            assertEquals(TestBean.class, sloc.getWithinType());
            try {
                sloc.getLine();
                fail("Can't get line number");
            } catch (UnsupportedOperationException ex) {
            // Expected
            }
            try {
                sloc.getFileName();
                fail("Can't get file name");
            } catch (UnsupportedOperationException ex) {
            // Expected
            }
        }
    });
    ITestBean itb = (ITestBean) pf.getProxy();
    // Any call will do
    itb.getAge();
}
Also used : SourceLocation(org.aspectj.lang.reflect.SourceLocation) ITestBean(org.springframework.tests.sample.beans.ITestBean) ITestBean(org.springframework.tests.sample.beans.ITestBean) TestBean(org.springframework.tests.sample.beans.TestBean) ProxyFactory(org.springframework.aop.framework.ProxyFactory) MethodBeforeAdvice(org.springframework.aop.MethodBeforeAdvice) Method(java.lang.reflect.Method) Test(org.junit.Test)

Aggregations

Method (java.lang.reflect.Method)1 SourceLocation (org.aspectj.lang.reflect.SourceLocation)1 Test (org.junit.Test)1 MethodBeforeAdvice (org.springframework.aop.MethodBeforeAdvice)1 ProxyFactory (org.springframework.aop.framework.ProxyFactory)1 ITestBean (org.springframework.tests.sample.beans.ITestBean)1 TestBean (org.springframework.tests.sample.beans.TestBean)1