use of cn.taketoday.aop.framework.AdvisedSupport in project today-framework by TAKETODAY.
the class UnsupportedInterceptor method testWithNoArgConstructor.
@Test
public void testWithNoArgConstructor() {
NoArgCtorTestBean target = new NoArgCtorTestBean("b", 1);
target.reset();
mockTargetSource.setTarget(target);
AdvisedSupport pc = new AdvisedSupport();
pc.setTargetSource(mockTargetSource);
CglibAopProxy aop = new CglibAopProxy(pc);
aop.setConstructorArguments(new Object[] { "Rob Harrop", 22 }, new Class<?>[] { String.class, int.class });
NoArgCtorTestBean proxy = (NoArgCtorTestBean) aop.getProxy();
assertThat(proxy).isNotNull();
boolean called = proxy.called;
assertThat(called).isTrue();
}
use of cn.taketoday.aop.framework.AdvisedSupport in project today-framework by TAKETODAY.
the class UnsupportedInterceptor method testProxyCanBeClassNotInterface.
@Test
public void testProxyCanBeClassNotInterface() {
TestBean raw = new TestBean();
raw.setAge(32);
mockTargetSource.setTarget(raw);
AdvisedSupport pc = new AdvisedSupport();
pc.setTargetSource(mockTargetSource);
AopProxy aop = new CglibAopProxy(pc);
Object proxy = aop.getProxy();
assertThat(AopUtils.isCglibProxy(proxy)).isTrue();
assertThat(proxy instanceof ITestBean).isTrue();
assertThat(proxy instanceof TestBean).isTrue();
TestBean tb = (TestBean) proxy;
assertThat(tb.getAge()).isEqualTo(32);
}
use of cn.taketoday.aop.framework.AdvisedSupport in project today-framework by TAKETODAY.
the class JdkDynamicAopProxyTests method testInterceptorIsInvokedWithNoTarget.
@Test
public void testInterceptorIsInvokedWithNoTarget() {
// Test return value
final int age = 25;
MethodInterceptor mi = (invocation -> age);
AdvisedSupport pc = new AdvisedSupport(ITestBean.class);
pc.addAdvice(mi);
AopProxy aop = createAopProxy(pc);
ITestBean tb = (ITestBean) aop.getProxy();
assertThat(tb.getAge()).as("correct return value").isEqualTo(age);
}
use of cn.taketoday.aop.framework.AdvisedSupport in project today-framework by TAKETODAY.
the class JdkDynamicAopProxyTests method testProxyIsJustInterface.
@Test
public void testProxyIsJustInterface() {
TestBean raw = new TestBean();
raw.setAge(32);
AdvisedSupport pc = new AdvisedSupport(ITestBean.class);
pc.setTarget(raw);
JdkDynamicAopProxy aop = new JdkDynamicAopProxy(pc);
Object proxy = aop.getProxy();
boolean condition = proxy instanceof ITestBean;
assertThat(condition).isTrue();
boolean condition1 = proxy instanceof TestBean;
assertThat(condition1).isFalse();
}
use of cn.taketoday.aop.framework.AdvisedSupport in project today-framework by TAKETODAY.
the class AopProxyUtilsTests method testCompleteProxiedInterfacesAdvisedNotIncludedOpaque.
@Test
public void testCompleteProxiedInterfacesAdvisedNotIncludedOpaque() {
AdvisedSupport as = new AdvisedSupport();
as.setOpaque(true);
as.addInterface(ITestBean.class);
as.addInterface(Comparable.class);
Class<?>[] completedInterfaces = AopProxyUtils.completeProxiedInterfaces(as);
assertThat(completedInterfaces.length).isEqualTo(3);
// Can't assume ordering for others, so use a list
List<?> l = Arrays.asList(completedInterfaces);
assertThat(l.contains(Advised.class)).isFalse();
assertThat(l.contains(ITestBean.class)).isTrue();
assertThat(l.contains(Comparable.class)).isTrue();
}
Aggregations