use of cn.taketoday.aop.MethodBeforeAdvice in project today-infrastructure by TAKETODAY.
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) -> {
StaticPart aspectJVersionJp = Factory.makeEncSJP(method.getMethod());
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...
}
}
use of cn.taketoday.aop.MethodBeforeAdvice in project today-infrastructure by TAKETODAY.
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) -> {
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 cn.taketoday.aop.MethodBeforeAdvice in project today-infrastructure by TAKETODAY.
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((MethodBeforeAdvice) (method) -> {
SourceLocation sloc = AbstractAspectJAdvice.currentJoinPoint().getSourceLocation();
assertThat(AbstractAspectJAdvice.currentJoinPoint().getSourceLocation()).as("Same source location must be returned on subsequent requests").isEqualTo(sloc);
assertThat(sloc.getWithinType()).isEqualTo(TestBean.class);
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(sloc::getLine);
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(sloc::getFileName);
});
ITestBean itb = (ITestBean) pf.getProxy();
// Any call will do
itb.getAge();
}
use of cn.taketoday.aop.MethodBeforeAdvice in project today-framework by TAKETODAY.
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((MethodBeforeAdvice) (method) -> {
SourceLocation sloc = AbstractAspectJAdvice.currentJoinPoint().getSourceLocation();
assertThat(AbstractAspectJAdvice.currentJoinPoint().getSourceLocation()).as("Same source location must be returned on subsequent requests").isEqualTo(sloc);
assertThat(sloc.getWithinType()).isEqualTo(TestBean.class);
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(sloc::getLine);
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(sloc::getFileName);
});
ITestBean itb = (ITestBean) pf.getProxy();
// Any call will do
itb.getAge();
}
use of cn.taketoday.aop.MethodBeforeAdvice in project today-framework by TAKETODAY.
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) -> {
StaticPart aspectJVersionJp = Factory.makeEncSJP(method.getMethod());
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