use of cn.taketoday.aop.framework.AdvisedSupport in project today-framework by TAKETODAY.
the class AbstractAopProxyTests method testUndeclaredCheckedException.
/**
* An interceptor throws a checked exception not on the method signature.
* For efficiency, we don't bother unifying java.lang.reflect and
* cn.taketoday.cglib UndeclaredThrowableException
*/
@Test
public void testUndeclaredCheckedException() throws Throwable {
final Exception unexpectedException = new Exception();
// 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(UndeclaredThrowableException.class).isThrownBy(tb::getAge).satisfies(ex -> assertThat(ex.getUndeclaredThrowable()).isEqualTo(unexpectedException));
}
use of cn.taketoday.aop.framework.AdvisedSupport in project today-framework by TAKETODAY.
the class JdkDynamicAopProxyTests method testEqualsAndHashCodeDefined.
@Test
public void testEqualsAndHashCodeDefined() {
AdvisedSupport as = new AdvisedSupport(Named.class);
as.setTarget(new Person());
JdkDynamicAopProxy aopProxy = new JdkDynamicAopProxy(as);
Named proxy = (Named) aopProxy.getProxy();
Named named = new Person();
assertThat(proxy).isEqualTo(named);
assertThat(named.hashCode()).isEqualTo(proxy.hashCode());
}
use of cn.taketoday.aop.framework.AdvisedSupport in project today-framework by TAKETODAY.
the class UnsupportedInterceptor method testUnadvisedProxyCreationWithCallDuringConstructor.
@Test
public void testUnadvisedProxyCreationWithCallDuringConstructor() {
CglibTestBean target = new CglibTestBean();
target.setName("Rob Harrop");
AdvisedSupport pc = new AdvisedSupport();
pc.setFrozen(true);
pc.setTarget(target);
CglibAopProxy aop = new CglibAopProxy(pc);
CglibTestBean proxy = (CglibTestBean) aop.getProxy();
assertThat(proxy).as("Proxy should not be null").isNotNull();
assertThat(proxy.getName()).as("Constructor overrode the value of name").isEqualTo("Rob Harrop");
}
use of cn.taketoday.aop.framework.AdvisedSupport in project today-framework by TAKETODAY.
the class UnsupportedInterceptor method testToStringInvocation.
@Test
public void testToStringInvocation() {
PrivateCglibTestBean bean = new PrivateCglibTestBean();
bean.setName("Rob Harrop");
AdvisedSupport as = new AdvisedSupport();
as.setTarget(bean);
as.addAdvice(new NopInterceptor());
AopProxy aop = new CglibAopProxy(as);
PrivateCglibTestBean proxy = (PrivateCglibTestBean) aop.getProxy();
assertThat(proxy.toString()).as("The name property has been overwritten by the constructor").isEqualTo("Rob Harrop");
}
use of cn.taketoday.aop.framework.AdvisedSupport in project today-framework by TAKETODAY.
the class UnsupportedInterceptor method testProxyAProxyWithAdditionalInterface.
@Test
public void testProxyAProxyWithAdditionalInterface() {
ITestBean target = new TestBean();
mockTargetSource.setTarget(target);
AdvisedSupport as = new AdvisedSupport();
as.setTargetSource(mockTargetSource);
as.addAdvice(new NopInterceptor());
as.addInterface(Serializable.class);
CglibAopProxy cglib = new CglibAopProxy(as);
ITestBean proxy1 = (ITestBean) cglib.getProxy();
mockTargetSource.setTarget(proxy1);
as = new AdvisedSupport(new Class<?>[] {});
as.setTargetSource(mockTargetSource);
as.addAdvice(new NopInterceptor());
cglib = new CglibAopProxy(as);
ITestBean proxy2 = (ITestBean) cglib.getProxy();
assertThat(proxy2 instanceof Serializable).isTrue();
}
Aggregations