Search in sources :

Example 31 with TimeStamped

use of cn.taketoday.core.testfixture.TimeStamped in project today-infrastructure by TAKETODAY.

the class DelegatingIntroductionInterceptorTests method testSerializableDelegatingIntroductionInterceptorSerializable.

@Test
public void testSerializableDelegatingIntroductionInterceptorSerializable() throws Exception {
    SerializablePerson serializableTarget = new SerializablePerson();
    String name = "Tony";
    serializableTarget.setName("Tony");
    ProxyFactory factory = new ProxyFactory(serializableTarget);
    factory.addInterface(Person.class);
    long time = 1000;
    TimeStamped ts = new SerializableTimeStamped(time);
    factory.addAdvisor(new DefaultIntroductionAdvisor(new DelegatingIntroductionInterceptor(ts)));
    factory.addAdvice(new SerializableNopInterceptor());
    Person p = (Person) factory.getProxy();
    assertThat(p.getName()).isEqualTo(name);
    assertThat(((TimeStamped) p).getTimeStamp()).isEqualTo(time);
    Person p1 = SerializationTestUtils.serializeAndDeserialize(p);
    assertThat(p1.getName()).isEqualTo(name);
    assertThat(((TimeStamped) p1).getTimeStamp()).isEqualTo(time);
}
Also used : TimeStamped(cn.taketoday.core.testfixture.TimeStamped) SerializableNopInterceptor(cn.taketoday.aop.testfixture.interceptor.SerializableNopInterceptor) SerializablePerson(cn.taketoday.beans.testfixture.beans.SerializablePerson) ProxyFactory(cn.taketoday.aop.framework.ProxyFactory) Person(cn.taketoday.beans.testfixture.beans.Person) SerializablePerson(cn.taketoday.beans.testfixture.beans.SerializablePerson) Test(org.junit.jupiter.api.Test)

Example 32 with TimeStamped

use of cn.taketoday.core.testfixture.TimeStamped in project today-infrastructure by TAKETODAY.

the class DelegatingIntroductionInterceptorTests method testIntroductionInterceptorWithDelegation.

@Test
public void testIntroductionInterceptorWithDelegation() throws Exception {
    TestBean raw = new TestBean();
    assertThat(!(raw instanceof TimeStamped)).isTrue();
    ProxyFactory factory = new ProxyFactory(raw);
    TimeStamped ts = mock(TimeStamped.class);
    long timestamp = 111L;
    given(ts.getTimeStamp()).willReturn(timestamp);
    factory.addAdvisor(0, new DefaultIntroductionAdvisor(new DelegatingIntroductionInterceptor(ts)));
    TimeStamped tsp = (TimeStamped) factory.getProxy();
    assertThat(tsp.getTimeStamp() == timestamp).isTrue();
}
Also used : TimeStamped(cn.taketoday.core.testfixture.TimeStamped) NestedTestBean(cn.taketoday.beans.testfixture.beans.NestedTestBean) TestBean(cn.taketoday.beans.testfixture.beans.TestBean) ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) INestedTestBean(cn.taketoday.beans.testfixture.beans.INestedTestBean) ProxyFactory(cn.taketoday.aop.framework.ProxyFactory) Test(org.junit.jupiter.api.Test)

Aggregations

TimeStamped (cn.taketoday.core.testfixture.TimeStamped)32 Test (org.junit.jupiter.api.Test)32 ITestBean (cn.taketoday.beans.testfixture.beans.ITestBean)28 TestBean (cn.taketoday.beans.testfixture.beans.TestBean)22 ProxyFactory (cn.taketoday.aop.framework.ProxyFactory)16 INestedTestBean (cn.taketoday.beans.testfixture.beans.INestedTestBean)14 NestedTestBean (cn.taketoday.beans.testfixture.beans.NestedTestBean)14 DefaultIntroductionAdvisor (cn.taketoday.aop.support.DefaultIntroductionAdvisor)8 NopInterceptor (cn.taketoday.aop.testfixture.interceptor.NopInterceptor)6 TimestampIntroductionInterceptor (cn.taketoday.aop.testfixture.interceptor.TimestampIntroductionInterceptor)6 DebugInterceptor (cn.taketoday.aop.interceptor.DebugInterceptor)4 DelegatingIntroductionInterceptor (cn.taketoday.aop.support.DelegatingIntroductionInterceptor)4 SerializableNopInterceptor (cn.taketoday.aop.testfixture.interceptor.SerializableNopInterceptor)4 Lockable (test.aop.Lockable)4 IntroductionAdvisor (cn.taketoday.aop.IntroductionAdvisor)2 IntroductionInterceptor (cn.taketoday.aop.IntroductionInterceptor)2 Pointcuts (cn.taketoday.aop.support.Pointcuts)2 IOther (cn.taketoday.beans.testfixture.beans.IOther)2 Person (cn.taketoday.beans.testfixture.beans.Person)2 SerializablePerson (cn.taketoday.beans.testfixture.beans.SerializablePerson)2