use of org.aspectj.lang.JoinPoint.StaticPart in project spring-framework by spring-projects.
the class MethodInvocationProceedingJoinPointTests method testCanGetStaticPartFromJoinPoint.
@Test
public void testCanGetStaticPartFromJoinPoint() {
final Object raw = new TestBean();
ProxyFactory pf = new ProxyFactory(raw);
pf.addAdvisor(ExposeInvocationInterceptor.ADVISOR);
pf.addAdvice((MethodBeforeAdvice) (method, args, target) -> {
StaticPart staticPart = AbstractAspectJAdvice.currentJoinPoint().getStaticPart();
assertThat(AbstractAspectJAdvice.currentJoinPoint().getStaticPart()).as("Same static part must be returned on subsequent requests").isEqualTo(staticPart);
assertThat(staticPart.getKind()).isEqualTo(ProceedingJoinPoint.METHOD_EXECUTION);
assertThat(staticPart.getSignature()).isSameAs(AbstractAspectJAdvice.currentJoinPoint().getSignature());
assertThat(staticPart.getSourceLocation()).isEqualTo(AbstractAspectJAdvice.currentJoinPoint().getSourceLocation());
});
ITestBean itb = (ITestBean) pf.getProxy();
// Any call will do
itb.getAge();
}
use of org.aspectj.lang.JoinPoint.StaticPart in project spring-framework by spring-projects.
the class MethodInvocationProceedingJoinPointTests method toShortAndLongStringFormedCorrectly.
@Test
public void toShortAndLongStringFormedCorrectly() throws Exception {
final Object raw = new TestBean();
ProxyFactory pf = new ProxyFactory(raw);
pf.addAdvisor(ExposeInvocationInterceptor.ADVISOR);
pf.addAdvice((MethodBeforeAdvice) (method, args, target) -> {
// makeEncSJP, although meant for computing the enclosing join point,
// it serves our purpose here
StaticPart aspectJVersionJp = Factory.makeEncSJP(method);
JoinPoint jp = AbstractAspectJAdvice.currentJoinPoint();
assertThat(jp.getSignature().toLongString()).isEqualTo(aspectJVersionJp.getSignature().toLongString());
assertThat(jp.getSignature().toShortString()).isEqualTo(aspectJVersionJp.getSignature().toShortString());
assertThat(jp.getSignature().toString()).isEqualTo(aspectJVersionJp.getSignature().toString());
assertThat(jp.toLongString()).isEqualTo(aspectJVersionJp.toLongString());
assertThat(jp.toShortString()).isEqualTo(aspectJVersionJp.toShortString());
assertThat(jp.toString()).isEqualTo(aspectJVersionJp.toString());
});
ITestBean itb = (ITestBean) pf.getProxy();
itb.getAge();
itb.setName("foo");
itb.getDoctor();
itb.getStringArray();
itb.getSpouse();
itb.setSpouse(new TestBean());
try {
itb.unreliableFileOperation();
} catch (IOException ex) {
// we don't really care...
}
}
Aggregations