Search in sources :

Example 6 with TimestampIntroductionInterceptor

use of org.springframework.aop.testfixture.interceptor.TimestampIntroductionInterceptor in project spring-framework by spring-projects.

the class AbstractAopProxyTests method testUseAsHashKey.

@Test
public void testUseAsHashKey() {
    TestBean target1 = new TestBean();
    ProxyFactory pf1 = new ProxyFactory(target1);
    pf1.addAdvice(new NopInterceptor());
    ITestBean proxy1 = (ITestBean) createProxy(pf1);
    TestBean target2 = new TestBean();
    ProxyFactory pf2 = new ProxyFactory(target2);
    pf2.addAdvisor(new DefaultIntroductionAdvisor(new TimestampIntroductionInterceptor()));
    ITestBean proxy2 = (ITestBean) createProxy(pf2);
    HashMap<ITestBean, Object> h = new HashMap<>();
    Object value1 = "foo";
    Object value2 = "bar";
    assertThat(h.get(proxy1)).isNull();
    h.put(proxy1, value1);
    h.put(proxy2, value2);
    assertThat(value1).isEqualTo(h.get(proxy1));
    assertThat(value2).isEqualTo(h.get(proxy2));
}
Also used : ITestBean(org.springframework.beans.testfixture.beans.ITestBean) NopInterceptor(org.springframework.aop.testfixture.interceptor.NopInterceptor) SerializableNopInterceptor(org.springframework.aop.testfixture.interceptor.SerializableNopInterceptor) TimestampIntroductionInterceptor(org.springframework.aop.testfixture.interceptor.TimestampIntroductionInterceptor) TestBean(org.springframework.beans.testfixture.beans.TestBean) ITestBean(org.springframework.beans.testfixture.beans.ITestBean) HashMap(java.util.HashMap) DefaultIntroductionAdvisor(org.springframework.aop.support.DefaultIntroductionAdvisor) Test(org.junit.jupiter.api.Test)

Example 7 with TimestampIntroductionInterceptor

use of org.springframework.aop.testfixture.interceptor.TimestampIntroductionInterceptor in project spring-framework by spring-projects.

the class AbstractAopProxyTests method testValuesStick.

/**
 * Simple test that if we set values we can get them out again.
 */
@Test
public void testValuesStick() {
    int age1 = 33;
    int age2 = 37;
    String name = "tony";
    TestBean target1 = new TestBean();
    target1.setAge(age1);
    ProxyFactory pf1 = new ProxyFactory(target1);
    pf1.addAdvisor(new DefaultPointcutAdvisor(new NopInterceptor()));
    pf1.addAdvisor(new DefaultPointcutAdvisor(new TimestampIntroductionInterceptor()));
    ITestBean tb = (ITestBean) pf1.getProxy();
    assertThat(tb.getAge()).isEqualTo(age1);
    tb.setAge(age2);
    assertThat(tb.getAge()).isEqualTo(age2);
    assertThat(tb.getName()).isNull();
    tb.setName(name);
    assertThat(tb.getName()).isEqualTo(name);
}
Also used : ITestBean(org.springframework.beans.testfixture.beans.ITestBean) NopInterceptor(org.springframework.aop.testfixture.interceptor.NopInterceptor) SerializableNopInterceptor(org.springframework.aop.testfixture.interceptor.SerializableNopInterceptor) TimestampIntroductionInterceptor(org.springframework.aop.testfixture.interceptor.TimestampIntroductionInterceptor) TestBean(org.springframework.beans.testfixture.beans.TestBean) ITestBean(org.springframework.beans.testfixture.beans.ITestBean) DefaultPointcutAdvisor(org.springframework.aop.support.DefaultPointcutAdvisor) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)7 TimestampIntroductionInterceptor (org.springframework.aop.testfixture.interceptor.TimestampIntroductionInterceptor)7 ITestBean (org.springframework.beans.testfixture.beans.ITestBean)7 DefaultIntroductionAdvisor (org.springframework.aop.support.DefaultIntroductionAdvisor)6 TestBean (org.springframework.beans.testfixture.beans.TestBean)6 TimeStamped (org.springframework.core.testfixture.TimeStamped)3 DebugInterceptor (org.springframework.aop.interceptor.DebugInterceptor)2 NopInterceptor (org.springframework.aop.testfixture.interceptor.NopInterceptor)2 SerializableNopInterceptor (org.springframework.aop.testfixture.interceptor.SerializableNopInterceptor)2 HashMap (java.util.HashMap)1 DefaultPointcutAdvisor (org.springframework.aop.support.DefaultPointcutAdvisor)1 IOther (org.springframework.beans.testfixture.beans.IOther)1