Search in sources :

Example 36 with NopInterceptor

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);
}
Also used : NopInterceptor(org.springframework.aop.testfixture.interceptor.NopInterceptor) Test(org.junit.jupiter.api.Test)

Example 37 with NopInterceptor

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();
}
Also used : Pointcut(org.springframework.aop.Pointcut) ITestBean(org.springframework.beans.testfixture.beans.ITestBean) NopInterceptor(org.springframework.aop.testfixture.interceptor.NopInterceptor) MethodInterceptor(org.aopalliance.intercept.MethodInterceptor) DefaultPointcutAdvisor(org.springframework.aop.support.DefaultPointcutAdvisor)

Example 38 with NopInterceptor

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");
}
Also used : NopInterceptor(org.springframework.aop.testfixture.interceptor.NopInterceptor) Test(org.junit.jupiter.api.Test)

Example 39 with NopInterceptor

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");
}
Also used : NopInterceptor(org.springframework.aop.testfixture.interceptor.NopInterceptor) Test(org.junit.jupiter.api.Test)

Example 40 with NopInterceptor

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);
}
Also used : NopInterceptor(org.springframework.aop.testfixture.interceptor.NopInterceptor) SerializableNopInterceptor(org.springframework.aop.testfixture.interceptor.SerializableNopInterceptor) Person(org.springframework.beans.testfixture.beans.Person) SerializablePerson(org.springframework.beans.testfixture.beans.SerializablePerson) Test(org.junit.jupiter.api.Test)

Aggregations

NopInterceptor (org.springframework.aop.testfixture.interceptor.NopInterceptor)60 Test (org.junit.jupiter.api.Test)57 ITestBean (org.springframework.beans.testfixture.beans.ITestBean)39 SerializableNopInterceptor (org.springframework.aop.testfixture.interceptor.SerializableNopInterceptor)33 TestBean (org.springframework.beans.testfixture.beans.TestBean)32 DefaultPointcutAdvisor (org.springframework.aop.support.DefaultPointcutAdvisor)14 CountingBeforeAdvice (org.springframework.aop.testfixture.advice.CountingBeforeAdvice)13 DefaultIntroductionAdvisor (org.springframework.aop.support.DefaultIntroductionAdvisor)11 Advisor (org.springframework.aop.Advisor)10 StaticMethodMatcherPointcutAdvisor (org.springframework.aop.support.StaticMethodMatcherPointcutAdvisor)7 Method (java.lang.reflect.Method)6 LockMixinAdvisor (test.mixin.LockMixinAdvisor)6 IOException (java.io.IOException)4 Assertions.assertThatIllegalArgumentException (org.assertj.core.api.Assertions.assertThatIllegalArgumentException)4 ProxyFactory (org.springframework.aop.framework.ProxyFactory)4 CountingAfterReturningAdvice (org.springframework.aop.testfixture.advice.CountingAfterReturningAdvice)4 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)4 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)4 Person (org.springframework.beans.testfixture.beans.Person)4 Nullable (org.springframework.lang.Nullable)4