use of org.springframework.aop.testfixture.interceptor.NopInterceptor in project spring-framework by spring-projects.
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 org.springframework.aop.testfixture.interceptor.NopInterceptor in project spring-framework by spring-projects.
the class UnsupportedInterceptor method testExceptionHandling.
@Test
public void testExceptionHandling() {
ExceptionThrower bean = new ExceptionThrower();
mockTargetSource.setTarget(bean);
AdvisedSupport as = new AdvisedSupport();
as.setTargetSource(mockTargetSource);
as.addAdvice(new NopInterceptor());
AopProxy aop = new CglibAopProxy(as);
ExceptionThrower proxy = (ExceptionThrower) aop.getProxy();
try {
proxy.doTest();
} catch (Exception ex) {
assertThat(ex instanceof ApplicationContextException).as("Invalid exception class").isTrue();
}
assertThat(proxy.isCatchInvoked()).as("Catch was not invoked").isTrue();
assertThat(proxy.isFinallyInvoked()).as("Finally was not invoked").isTrue();
}
use of org.springframework.aop.testfixture.interceptor.NopInterceptor in project spring-framework by spring-projects.
the class UnsupportedInterceptor method testProxyAProxy.
@Test
public void testProxyAProxy() {
ITestBean target = new TestBean();
mockTargetSource.setTarget(target);
AdvisedSupport as = new AdvisedSupport();
as.setTargetSource(mockTargetSource);
as.addAdvice(new NopInterceptor());
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);
assertThat(cglib.getProxy()).isInstanceOf(ITestBean.class);
}
use of org.springframework.aop.testfixture.interceptor.NopInterceptor in project spring-framework by spring-projects.
the class MBeanExporterTests method testExportJdkProxy.
@Test
void testExportJdkProxy() throws Exception {
JmxTestBean bean = new JmxTestBean();
bean.setName("Rob Harrop");
ProxyFactory factory = new ProxyFactory();
factory.setTarget(bean);
factory.addAdvice(new NopInterceptor());
factory.setInterfaces(IJmxTestBean.class);
IJmxTestBean proxy = (IJmxTestBean) factory.getProxy();
String name = "bean:mmm=whatever";
Map<String, Object> beans = new HashMap<>();
beans.put(name, proxy);
MBeanExporter exporter = new MBeanExporter();
exporter.setServer(server);
exporter.setBeans(beans);
exporter.registerBeans();
ObjectName oname = ObjectName.getInstance(name);
Object nameValue = server.getAttribute(oname, "Name");
assertThat(nameValue).isEqualTo("Rob Harrop");
}
use of org.springframework.aop.testfixture.interceptor.NopInterceptor in project spring-framework by spring-projects.
the class ProxyFactoryTests method testSealedInterfaceExclusion.
@Test
public void testSealedInterfaceExclusion() {
// String implements ConstantDesc on JDK 12+, sealed as of JDK 17
ProxyFactory factory = new ProxyFactory(new String());
NopInterceptor di = new NopInterceptor();
factory.addAdvice(0, di);
Object proxy = factory.getProxy();
assertThat(proxy).isInstanceOf(CharSequence.class);
}
Aggregations