use of cn.taketoday.aop.framework.AdvisedSupport in project today-framework by TAKETODAY.
the class AopProxyUtilsTests method testCompleteProxiedInterfacesWorksWithNull.
@Test
public void testCompleteProxiedInterfacesWorksWithNull() {
AdvisedSupport as = new AdvisedSupport();
Class<?>[] completedInterfaces = AopProxyUtils.completeProxiedInterfaces(as);
assertThat(completedInterfaces.length).isEqualTo(2);
List<?> ifaces = Arrays.asList(completedInterfaces);
assertThat(ifaces.contains(Advised.class)).isTrue();
assertThat(ifaces.contains(StandardProxy.class)).isTrue();
}
use of cn.taketoday.aop.framework.AdvisedSupport in project today-framework by TAKETODAY.
the class AopProxyUtilsTests method testCompleteProxiedInterfacesAdvisedNotIncluded.
@Test
public void testCompleteProxiedInterfacesAdvisedNotIncluded() {
AdvisedSupport as = new AdvisedSupport();
as.addInterface(ITestBean.class);
as.addInterface(Comparable.class);
Class<?>[] completedInterfaces = AopProxyUtils.completeProxiedInterfaces(as);
assertThat(completedInterfaces.length).isEqualTo(4);
// Can't assume ordering for others, so use a list
List<?> l = Arrays.asList(completedInterfaces);
assertThat(l.contains(Advised.class)).isTrue();
assertThat(l.contains(ITestBean.class)).isTrue();
assertThat(l.contains(Comparable.class)).isTrue();
}
use of cn.taketoday.aop.framework.AdvisedSupport in project today-framework by TAKETODAY.
the class AbstractAopProxyTests method testNoInterceptorsAndNoTarget.
@Test
public void testNoInterceptorsAndNoTarget() {
assertThatExceptionOfType(AopConfigException.class).isThrownBy(() -> {
AdvisedSupport pc = new AdvisedSupport(ITestBean.class);
// Add no interceptors
AopProxy aop = createAopProxy(pc);
aop.getProxy();
});
}
use of cn.taketoday.aop.framework.AdvisedSupport in project today-framework by TAKETODAY.
the class AbstractAopProxyTests method testUndeclaredUncheckedException.
@Test
public void testUndeclaredUncheckedException() throws Throwable {
final RuntimeException unexpectedException = new RuntimeException();
// Test return value
MethodInterceptor mi = new MethodInterceptor() {
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
throw unexpectedException;
}
};
AdvisedSupport pc = new AdvisedSupport(ITestBean.class);
pc.addAdvice(ExposeInvocationInterceptor.INSTANCE);
pc.addAdvice(mi);
// We don't care about the object
pc.setTarget(new TestBean());
AopProxy aop = createAopProxy(pc);
ITestBean tb = (ITestBean) aop.getProxy();
assertThatExceptionOfType(RuntimeException.class).isThrownBy(tb::getAge).matches(unexpectedException::equals);
}
use of cn.taketoday.aop.framework.AdvisedSupport in project today-framework by TAKETODAY.
the class AbstractAopProxyTests method testContext.
/**
* @param context if true, want context
*/
private void testContext(final boolean context) throws Throwable {
final String s = "foo";
// Test return value
MethodInterceptor mi = new MethodInterceptor() {
@Override
public Object invoke(MethodInvocation invocation) {
if (!context) {
assertNoInvocationContext();
} else {
assertThat(ExposeInvocationInterceptor.currentInvocation()).as("have context").isNotNull();
}
return s;
}
};
AdvisedSupport pc = new AdvisedSupport(ITestBean.class);
if (context) {
pc.addAdvice(ExposeInvocationInterceptor.INSTANCE);
}
pc.addAdvice(mi);
// Keep CGLIB happy
if (requiresTarget()) {
pc.setTarget(new TestBean());
}
AopProxy aop = createAopProxy(pc);
assertNoInvocationContext();
ITestBean tb = (ITestBean) aop.getProxy();
assertNoInvocationContext();
assertThat(tb.getName()).as("correct return value").isSameAs(s);
}
Aggregations