1 16 17 package org.springframework.aop.target; 18 19 import org.springframework.aop.TargetSource; 20 import org.springframework.beans.MutablePropertyValues; 21 import org.springframework.beans.SerializablePerson; 22 import org.springframework.beans.TestBean; 23 import org.springframework.beans.factory.support.DefaultListableBeanFactory; 24 import org.springframework.beans.factory.support.RootBeanDefinition; 25 import org.springframework.util.SerializationTestUtils; 26 27 import junit.framework.TestCase; 28 29 36 public class PrototypeBasedTargetSourceTests extends TestCase { 37 38 public void testSerializability() throws Exception { 39 MutablePropertyValues tsPvs = new MutablePropertyValues(); 40 tsPvs.addPropertyValue("targetBeanName", "person"); 41 RootBeanDefinition tsBd = new RootBeanDefinition( 42 TestTargetSource.class, tsPvs); 43 44 MutablePropertyValues beanPvs = new MutablePropertyValues(); 45 RootBeanDefinition beanBd = new RootBeanDefinition( 46 SerializablePerson.class, beanPvs, false); 47 48 DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); 49 bf.registerBeanDefinition("ts", tsBd); 50 bf.registerBeanDefinition("person", beanBd); 51 52 TestTargetSource cpts = (TestTargetSource) bf 53 .getBean("ts"); 54 TargetSource serialized = (TargetSource) SerializationTestUtils 55 .serializeAndDeserialize(cpts); 56 assertTrue("Changed to SingletonTargetSource on deserialization", 57 serialized instanceof SingletonTargetSource); 58 SingletonTargetSource sts = (SingletonTargetSource) serialized; 59 assertNotNull(sts.getTarget()); 60 } 61 62 63 private static class TestTargetSource extends AbstractPrototypeBasedTargetSource { 64 65 69 private TestBean thisFieldIsNotSerializable = new TestBean(); 70 71 74 public Object getTarget() throws Exception { 75 return newPrototypeInstance(); 76 } 77 78 81 public void releaseTarget(Object target) throws Exception { 82 } 84 } 85 86 } | Popular Tags |