Fixed toString(), toShortString(), and toLongString() methods for signature and join point (SPR-5437)

This commit is contained in:
Ramnivas Laddad
2009-01-27 22:58:28 +00:00
parent 27460e323a
commit c8d6c15a05
2 changed files with 109 additions and 13 deletions

View File

@@ -18,6 +18,7 @@ package org.springframework.aop.aspectj;
import static org.junit.Assert.*;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Arrays;
@@ -26,6 +27,7 @@ import org.aspectj.lang.JoinPoint.StaticPart;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.reflect.MethodSignature;
import org.aspectj.lang.reflect.SourceLocation;
import org.aspectj.runtime.reflect.Factory;
import org.junit.Test;
import org.springframework.aop.MethodBeforeAdvice;
@@ -40,6 +42,7 @@ import test.beans.TestBean;
/**
* @author Rod Johnson
* @author Chris Beams
* @author Ramnivas Laddad
* @since 2.0
*/
public final class MethodInvocationProceedingJoinPointTests {
@@ -186,4 +189,38 @@ public final class MethodInvocationProceedingJoinPointTests {
itb.getAge();
}
@Test
public void toShortAndLongStringFormedCorrectly() throws Exception {
final Object raw = new TestBean();
ProxyFactory pf = new ProxyFactory(raw);
pf.addAdvisor(ExposeInvocationInterceptor.ADVISOR);
pf.addAdvice(new MethodBeforeAdvice() {
public void before(Method method, Object[] args, Object target) throws Throwable {
// makeEncSJP, although meant for computing the enclosing join point,
// it serves our purpose here
JoinPoint.StaticPart aspectJVersionJp = Factory.makeEncSJP(method);
JoinPoint jp = AbstractAspectJAdvice.currentJoinPoint();
assertEquals(aspectJVersionJp.getSignature().toLongString(), jp.getSignature().toLongString());
assertEquals(aspectJVersionJp.getSignature().toShortString(), jp.getSignature().toShortString());
assertEquals(aspectJVersionJp.getSignature().toString(), jp.getSignature().toString());
assertEquals(aspectJVersionJp.toLongString(), jp.toLongString());
assertEquals(aspectJVersionJp.toShortString(), jp.toShortString());
assertEquals(aspectJVersionJp.toString(), jp.toString());
}
});
ITestBean itb = (ITestBean) pf.getProxy();
itb.getAge();
itb.setName("foo");
itb.getDoctor();
itb.getStringArray();
itb.getSpouses();
itb.setSpouse(new TestBean());
try {
itb.unreliableFileOperation();
} catch (IOException ex) {
// we don't realy care...
}
}
}