use of cn.taketoday.beans.testfixture.beans.Person in project today-framework by TAKETODAY.
the class RegexpMethodPointcutAdvisorIntegrationTests method testSerialization.
@Test
public void testSerialization() throws Throwable {
StandardBeanFactory bf = new StandardBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(CONTEXT);
// This is a CGLIB proxy, so we can proxy it to the target class
Person p = (Person) bf.getBean("serializableSettersAdvised");
// Interceptor behind regexp advisor
NopInterceptor nop = (NopInterceptor) bf.getBean("nopInterceptor");
assertThat(nop.getCount()).isEqualTo(0);
int newAge = 12;
// Not advised
assertThat(p.getAge()).isEqualTo(0);
assertThat(nop.getCount()).isEqualTo(0);
// This is proxied
p.setAge(newAge);
assertThat(nop.getCount()).isEqualTo(1);
p.setAge(newAge);
assertThat(p.getAge()).isEqualTo(newAge);
// Only setter fired
assertThat(nop.getCount()).isEqualTo(2);
// Serialize and continue...
p = SerializationTestUtils.serializeAndDeserialize(p);
assertThat(p.getAge()).isEqualTo(newAge);
// Remembers count, but we need to get a new reference to nop...
nop = (SerializableNopInterceptor) ((Advised) p).getAdvisors()[0].getAdvice();
assertThat(nop.getCount()).isEqualTo(2);
assertThat(p.getName()).isEqualTo("serializableSettersAdvised");
p.setAge(newAge + 1);
assertThat(nop.getCount()).isEqualTo(3);
assertThat(p.getAge()).isEqualTo((newAge + 1));
}
use of cn.taketoday.beans.testfixture.beans.Person in project today-framework 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);
}
use of cn.taketoday.beans.testfixture.beans.Person in project today-framework by TAKETODAY.
the class ProxyFactoryBeanTests method testSerializableSingletonProxyFactoryBean.
@Test
public void testSerializableSingletonProxyFactoryBean() throws Exception {
StandardBeanFactory bf = new StandardBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(SERIALIZATION_CONTEXT, CLASS));
Person p = (Person) bf.getBean("serializableSingleton");
ProxyFactoryBean pfb = (ProxyFactoryBean) bf.getBean("&serializableSingleton");
ProxyFactoryBean pfb2 = SerializationTestUtils.serializeAndDeserialize(pfb);
Person p2 = (Person) pfb2.getObject();
assertThat(p2).isEqualTo(p);
assertThat(p2).isNotSameAs(p);
assertThat(p2.getName()).isEqualTo("serializableSingleton");
}
use of cn.taketoday.beans.testfixture.beans.Person in project today-framework by TAKETODAY.
the class ProxyFactoryBeanTests method testSerializablePrototypeProxy.
@Test
public void testSerializablePrototypeProxy() throws Exception {
StandardBeanFactory bf = new StandardBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(SERIALIZATION_CONTEXT, CLASS));
Person p = (Person) bf.getBean("serializablePrototype");
assertThat(bf.getBean("serializablePrototype")).as("Should not be a Singleton").isNotSameAs(p);
Person p2 = SerializationTestUtils.serializeAndDeserialize(p);
assertThat(p2).isEqualTo(p);
assertThat(p2).isNotSameAs(p);
assertThat(p2.getName()).isEqualTo("serializablePrototype");
}
use of cn.taketoday.beans.testfixture.beans.Person in project today-infrastructure by TAKETODAY.
the class ProxyFactoryBeanTests method testSerializableSingletonProxyFactoryBean.
@Test
public void testSerializableSingletonProxyFactoryBean() throws Exception {
StandardBeanFactory bf = new StandardBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(SERIALIZATION_CONTEXT, CLASS));
Person p = (Person) bf.getBean("serializableSingleton");
ProxyFactoryBean pfb = (ProxyFactoryBean) bf.getBean("&serializableSingleton");
ProxyFactoryBean pfb2 = SerializationTestUtils.serializeAndDeserialize(pfb);
Person p2 = (Person) pfb2.getObject();
assertThat(p2).isEqualTo(p);
assertThat(p2).isNotSameAs(p);
assertThat(p2.getName()).isEqualTo("serializableSingleton");
}
Aggregations