use of org.springframework.aop.testfixture.interceptor.NopInterceptor in project spring-framework by spring-projects.
the class UnsupportedInterceptor method testNoTarget.
@Test
public void testNoTarget() {
AdvisedSupport pc = new AdvisedSupport(ITestBean.class);
pc.addAdvice(new NopInterceptor());
AopProxy aop = createAopProxy(pc);
assertThatExceptionOfType(AopConfigException.class).isThrownBy(aop::getProxy);
}
use of org.springframework.aop.testfixture.interceptor.NopInterceptor in project spring-framework by spring-projects.
the class UnsupportedInterceptor method getAdvisedProxy.
private ITestBean getAdvisedProxy(TestBean target) {
ProxyFactory pf = new ProxyFactory(new Class<?>[] { ITestBean.class });
pf.setProxyTargetClass(true);
MethodInterceptor advice = new NopInterceptor();
Pointcut pointcut = new Pointcut() {
@Override
public ClassFilter getClassFilter() {
return ClassFilter.TRUE;
}
@Override
public MethodMatcher getMethodMatcher() {
return MethodMatcher.TRUE;
}
@Override
public boolean equals(Object obj) {
return true;
}
@Override
public int hashCode() {
return 0;
}
};
pf.addAdvisor(new DefaultPointcutAdvisor(pointcut, advice));
pf.setTarget(target);
pf.setFrozen(true);
pf.setExposeProxy(false);
return (ITestBean) pf.getProxy();
}
use of org.springframework.aop.testfixture.interceptor.NopInterceptor in project spring-framework by spring-projects.
the class UnsupportedInterceptor method testProtectedMethodInvocation.
@Test
public void testProtectedMethodInvocation() {
ProtectedMethodTestBean bean = new ProtectedMethodTestBean();
bean.value = "foo";
mockTargetSource.setTarget(bean);
AdvisedSupport as = new AdvisedSupport();
as.setTargetSource(mockTargetSource);
as.addAdvice(new NopInterceptor());
AopProxy aop = new CglibAopProxy(as);
ProtectedMethodTestBean proxy = (ProtectedMethodTestBean) aop.getProxy();
assertThat(AopUtils.isCglibProxy(proxy)).isTrue();
assertThat(bean.getClass().getClassLoader()).isEqualTo(proxy.getClass().getClassLoader());
assertThat(proxy.getString()).isEqualTo("foo");
}
use of org.springframework.aop.testfixture.interceptor.NopInterceptor in project spring-framework by spring-projects.
the class UnsupportedInterceptor method testMethodInvocationDuringConstructor.
@Test
public void testMethodInvocationDuringConstructor() {
CglibTestBean bean = new CglibTestBean();
bean.setName("Rob Harrop");
AdvisedSupport as = new AdvisedSupport();
as.setTarget(bean);
as.addAdvice(new NopInterceptor());
AopProxy aop = new CglibAopProxy(as);
CglibTestBean proxy = (CglibTestBean) aop.getProxy();
assertThat(proxy.getName()).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 NameMatchMethodPointcutTests method testSerializable.
@Test
public void testSerializable() throws Throwable {
testSets();
// Count is now 2
Person p2 = SerializationTestUtils.serializeAndDeserialize(proxied);
NopInterceptor nop2 = (NopInterceptor) ((Advised) p2).getAdvisors()[0].getAdvice();
p2.getName();
assertThat(nop2.getCount()).isEqualTo(2);
p2.echo(null);
assertThat(nop2.getCount()).isEqualTo(3);
}
Aggregations