下面列出了怎么用org.springframework.util.SerializationTestUtils的API类实例代码及写法,或者点击链接到github查看源代码。
@Test
@SuppressWarnings("unchecked")
public void testWithInstance() throws Exception {
MultiplyReturnValue aspect = new MultiplyReturnValue();
int multiple = 3;
aspect.setMultiple(multiple);
TestBean target = new TestBean();
target.setAge(24);
AspectJProxyFactory proxyFactory = new AspectJProxyFactory(target);
proxyFactory.addAspect(aspect);
ITestBean proxy = proxyFactory.getProxy();
assertEquals(target.getAge() * multiple, proxy.getAge());
ITestBean serializedProxy = (ITestBean) SerializationTestUtils.serializeAndDeserialize(proxy);
assertEquals(target.getAge() * multiple, serializedProxy.getAge());
}
@Test
public void testSerializable() throws Exception {
DerivedTestBean tb = new DerivedTestBean();
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setInterfaces(ITestBean.class);
ConcurrencyThrottleInterceptor cti = new ConcurrencyThrottleInterceptor();
proxyFactory.addAdvice(cti);
proxyFactory.setTarget(tb);
ITestBean proxy = (ITestBean) proxyFactory.getProxy();
proxy.getAge();
ITestBean serializedProxy = (ITestBean) SerializationTestUtils.serializeAndDeserialize(proxy);
Advised advised = (Advised) serializedProxy;
ConcurrencyThrottleInterceptor serializedCti =
(ConcurrencyThrottleInterceptor) advised.getAdvisors()[0].getAdvice();
assertEquals(cti.getConcurrencyLimit(), serializedCti.getConcurrencyLimit());
serializedProxy.getAge();
}
@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();
assertEquals(name, p.getName());
assertEquals(time, ((TimeStamped) p).getTimeStamp());
Person p1 = (Person) SerializationTestUtils.serializeAndDeserialize(p);
assertEquals(name, p1.getName());
assertEquals(time, ((TimeStamped) p1).getTimeStamp());
}
@Test
public void withScopedProxy() throws IOException, ClassNotFoundException {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(ComponentScanWithScopedProxy.class);
ctx.getBeanFactory().registerScope("myScope", new SimpleMapScope());
ctx.refresh();
// should cast to the interface
FooService bean = (FooService) ctx.getBean("scopedProxyTestBean");
// should be dynamic proxy
assertThat(AopUtils.isJdkDynamicProxy(bean), is(true));
// test serializability
assertThat(bean.foo(1), equalTo("bar"));
FooService deserialized = (FooService) SerializationTestUtils.serializeAndDeserialize(bean);
assertThat(deserialized, notNullValue());
assertThat(deserialized.foo(1), equalTo("bar"));
}
@Test
public void testInterfacesScopedProxy() throws Exception {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"org/springframework/context/annotation/scopedProxyInterfacesTests.xml");
context.getBeanFactory().registerScope("myScope", new SimpleMapScope());
// should cast to the interface
FooService bean = (FooService) context.getBean("scopedProxyTestBean");
// should be dynamic proxy
assertTrue(AopUtils.isJdkDynamicProxy(bean));
// test serializability
assertEquals("bar", bean.foo(1));
FooService deserialized = (FooService) SerializationTestUtils.serializeAndDeserialize(bean);
assertNotNull(deserialized);
assertEquals("bar", deserialized.foo(1));
context.close();
}
@Test
public void testTargetClassScopedProxy() throws Exception {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"org/springframework/context/annotation/scopedProxyTargetClassTests.xml");
context.getBeanFactory().registerScope("myScope", new SimpleMapScope());
ScopedProxyTestBean bean = (ScopedProxyTestBean) context.getBean("scopedProxyTestBean");
// should be a class-based proxy
assertTrue(AopUtils.isCglibProxy(bean));
// test serializability
assertEquals("bar", bean.foo(1));
ScopedProxyTestBean deserialized = (ScopedProxyTestBean) SerializationTestUtils.serializeAndDeserialize(bean);
assertNotNull(deserialized);
assertEquals("bar", deserialized.foo(1));
context.close();
}
@Test
public void testSerializableSingletonProxy() throws Exception {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(SERIALIZATION_CONTEXT, CLASS));
Person p = (Person) bf.getBean("serializableSingleton");
assertSame("Should be a Singleton", p, bf.getBean("serializableSingleton"));
Person p2 = (Person) SerializationTestUtils.serializeAndDeserialize(p);
assertEquals(p, p2);
assertNotSame(p, p2);
assertEquals("serializableSingleton", p2.getName());
// Add unserializable advice
Advice nop = new NopInterceptor();
((Advised) p).addAdvice(nop);
// Check it still works
assertEquals(p2.getName(), p2.getName());
assertFalse("Not serializable because an interceptor isn't serializable", SerializationTestUtils.isSerializable(p));
// Remove offending interceptor...
assertTrue(((Advised) p).removeAdvice(nop));
assertTrue("Serializable again because offending interceptor was removed", SerializationTestUtils.isSerializable(p));
}
@Test
public void testEntityManagerFactoryIsProxied() throws Exception {
LocalContainerEntityManagerFactoryBean cefb = parseValidPersistenceUnit();
EntityManagerFactory emf = cefb.getObject();
assertSame("EntityManagerFactory reference must be cached after init", emf, cefb.getObject());
assertNotSame("EMF must be proxied", mockEmf, emf);
assertTrue(emf.equals(emf));
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.setSerializationId("emf-bf");
bf.registerSingleton("emf", cefb);
cefb.setBeanFactory(bf);
cefb.setBeanName("emf");
assertNotNull(SerializationTestUtils.serializeAndDeserialize(emf));
}
@Test
public void testPrivatePersistenceContextField() throws Exception {
mockEmf = mock(EntityManagerFactory.class, withSettings().serializable());
GenericApplicationContext gac = new GenericApplicationContext();
gac.getDefaultListableBeanFactory().registerSingleton("entityManagerFactory", mockEmf);
gac.registerBeanDefinition("annotationProcessor",
new RootBeanDefinition(PersistenceAnnotationBeanPostProcessor.class));
gac.registerBeanDefinition(DefaultPrivatePersistenceContextField.class.getName(),
new RootBeanDefinition(DefaultPrivatePersistenceContextField.class));
gac.registerBeanDefinition(FactoryBeanWithPersistenceContextField.class.getName(),
new RootBeanDefinition(FactoryBeanWithPersistenceContextField.class));
gac.refresh();
DefaultPrivatePersistenceContextField bean = (DefaultPrivatePersistenceContextField) gac.getBean(
DefaultPrivatePersistenceContextField.class.getName());
FactoryBeanWithPersistenceContextField bean2 = (FactoryBeanWithPersistenceContextField) gac.getBean(
"&" + FactoryBeanWithPersistenceContextField.class.getName());
assertNotNull(bean.em);
assertNotNull(bean2.em);
assertNotNull(SerializationTestUtils.serializeAndDeserialize(bean.em));
assertNotNull(SerializationTestUtils.serializeAndDeserialize(bean2.em));
}
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testPublicExtendedPersistenceContextSetterWithEntityManagerInfoAndSerialization() throws Exception {
EntityManager mockEm = mock(EntityManager.class, withSettings().serializable());
given(mockEm.isOpen()).willReturn(true);
EntityManagerFactoryWithInfo mockEmf = mock(EntityManagerFactoryWithInfo.class);
given(mockEmf.getNativeEntityManagerFactory()).willReturn(mockEmf);
given(mockEmf.getJpaDialect()).willReturn(new DefaultJpaDialect());
given(mockEmf.getEntityManagerInterface()).willReturn((Class)EntityManager.class);
given(mockEmf.getBeanClassLoader()).willReturn(getClass().getClassLoader());
given(mockEmf.createEntityManager()).willReturn(mockEm);
GenericApplicationContext gac = new GenericApplicationContext();
gac.getDefaultListableBeanFactory().registerSingleton("entityManagerFactory", mockEmf);
gac.registerBeanDefinition("annotationProcessor",
new RootBeanDefinition(PersistenceAnnotationBeanPostProcessor.class));
gac.registerBeanDefinition(DefaultPublicPersistenceContextSetter.class.getName(),
new RootBeanDefinition(DefaultPublicPersistenceContextSetter.class));
gac.refresh();
DefaultPublicPersistenceContextSetter bean = (DefaultPublicPersistenceContextSetter) gac.getBean(
DefaultPublicPersistenceContextSetter.class.getName());
assertNotNull(bean.em);
assertNotNull(SerializationTestUtils.serializeAndDeserialize(bean.em));
}
@Test
public void serializable() throws Exception {
TestBean1 tb = new TestBean1();
CallCountingTransactionManager ptm = new CallCountingTransactionManager();
AnnotationTransactionAttributeSource tas = new AnnotationTransactionAttributeSource();
TransactionInterceptor ti = new TransactionInterceptor(ptm, tas);
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setInterfaces(ITestBean1.class);
proxyFactory.addAdvice(ti);
proxyFactory.setTarget(tb);
ITestBean1 proxy = (ITestBean1) proxyFactory.getProxy();
proxy.getAge();
assertEquals(1, ptm.commits);
ITestBean1 serializedProxy = (ITestBean1) SerializationTestUtils.serializeAndDeserialize(proxy);
serializedProxy.getAge();
Advised advised = (Advised) serializedProxy;
TransactionInterceptor serializedTi = (TransactionInterceptor) advised.getAdvisors()[0].getAdvice();
CallCountingTransactionManager serializedPtm =
(CallCountingTransactionManager) serializedTi.getTransactionManager();
assertEquals(2, serializedPtm.commits);
}
@Test
@SuppressWarnings("unchecked")
public void testWithInstance() throws Exception {
MultiplyReturnValue aspect = new MultiplyReturnValue();
int multiple = 3;
aspect.setMultiple(multiple);
TestBean target = new TestBean();
target.setAge(24);
AspectJProxyFactory proxyFactory = new AspectJProxyFactory(target);
proxyFactory.addAspect(aspect);
ITestBean proxy = proxyFactory.getProxy();
assertEquals(target.getAge() * multiple, proxy.getAge());
ITestBean serializedProxy = (ITestBean) SerializationTestUtils.serializeAndDeserialize(proxy);
assertEquals(target.getAge() * multiple, serializedProxy.getAge());
}
@Test
public void testSerializable() throws Exception {
DerivedTestBean tb = new DerivedTestBean();
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setInterfaces(ITestBean.class);
ConcurrencyThrottleInterceptor cti = new ConcurrencyThrottleInterceptor();
proxyFactory.addAdvice(cti);
proxyFactory.setTarget(tb);
ITestBean proxy = (ITestBean) proxyFactory.getProxy();
proxy.getAge();
ITestBean serializedProxy = (ITestBean) SerializationTestUtils.serializeAndDeserialize(proxy);
Advised advised = (Advised) serializedProxy;
ConcurrencyThrottleInterceptor serializedCti =
(ConcurrencyThrottleInterceptor) advised.getAdvisors()[0].getAdvice();
assertEquals(cti.getConcurrencyLimit(), serializedCti.getConcurrencyLimit());
serializedProxy.getAge();
}
@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();
assertEquals(name, p.getName());
assertEquals(time, ((TimeStamped) p).getTimeStamp());
Person p1 = (Person) SerializationTestUtils.serializeAndDeserialize(p);
assertEquals(name, p1.getName());
assertEquals(time, ((TimeStamped) p1).getTimeStamp());
}
@Test
public void testInterfacesScopedProxy() throws Exception {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"org/springframework/context/annotation/scopedProxyInterfacesTests.xml");
context.getBeanFactory().registerScope("myScope", new SimpleMapScope());
// should cast to the interface
FooService bean = (FooService) context.getBean("scopedProxyTestBean");
// should be dynamic proxy
assertTrue(AopUtils.isJdkDynamicProxy(bean));
// test serializability
assertEquals("bar", bean.foo(1));
FooService deserialized = (FooService) SerializationTestUtils.serializeAndDeserialize(bean);
assertNotNull(deserialized);
assertEquals("bar", deserialized.foo(1));
context.close();
}
@Test
public void testTargetClassScopedProxy() throws Exception {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"org/springframework/context/annotation/scopedProxyTargetClassTests.xml");
context.getBeanFactory().registerScope("myScope", new SimpleMapScope());
ScopedProxyTestBean bean = (ScopedProxyTestBean) context.getBean("scopedProxyTestBean");
// should be a class-based proxy
assertTrue(AopUtils.isCglibProxy(bean));
// test serializability
assertEquals("bar", bean.foo(1));
ScopedProxyTestBean deserialized = (ScopedProxyTestBean) SerializationTestUtils.serializeAndDeserialize(bean);
assertNotNull(deserialized);
assertEquals("bar", deserialized.foo(1));
context.close();
}
@Test
public void testSerializableSingletonProxy() throws Exception {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(SERIALIZATION_CONTEXT, CLASS));
Person p = (Person) bf.getBean("serializableSingleton");
assertSame("Should be a Singleton", p, bf.getBean("serializableSingleton"));
Person p2 = (Person) SerializationTestUtils.serializeAndDeserialize(p);
assertEquals(p, p2);
assertNotSame(p, p2);
assertEquals("serializableSingleton", p2.getName());
// Add unserializable advice
Advice nop = new NopInterceptor();
((Advised) p).addAdvice(nop);
// Check it still works
assertEquals(p2.getName(), p2.getName());
assertFalse("Not serializable because an interceptor isn't serializable", SerializationTestUtils.isSerializable(p));
// Remove offending interceptor...
assertTrue(((Advised) p).removeAdvice(nop));
assertTrue("Serializable again because offending interceptor was removed", SerializationTestUtils.isSerializable(p));
}
@Test
public void testEntityManagerFactoryIsProxied() throws Exception {
LocalContainerEntityManagerFactoryBean cefb = parseValidPersistenceUnit();
EntityManagerFactory emf = cefb.getObject();
assertSame("EntityManagerFactory reference must be cached after init", emf, cefb.getObject());
assertNotSame("EMF must be proxied", mockEmf, emf);
assertTrue(emf.equals(emf));
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.setSerializationId("emf-bf");
bf.registerSingleton("emf", cefb);
cefb.setBeanFactory(bf);
cefb.setBeanName("emf");
assertNotNull(SerializationTestUtils.serializeAndDeserialize(emf));
}
@Test
public void testPrivatePersistenceContextField() throws Exception {
mockEmf = mock(EntityManagerFactory.class, withSettings().serializable());
GenericApplicationContext gac = new GenericApplicationContext();
gac.getDefaultListableBeanFactory().registerSingleton("entityManagerFactory", mockEmf);
gac.registerBeanDefinition("annotationProcessor",
new RootBeanDefinition(PersistenceAnnotationBeanPostProcessor.class));
gac.registerBeanDefinition(DefaultPrivatePersistenceContextField.class.getName(),
new RootBeanDefinition(DefaultPrivatePersistenceContextField.class));
gac.registerBeanDefinition(FactoryBeanWithPersistenceContextField.class.getName(),
new RootBeanDefinition(FactoryBeanWithPersistenceContextField.class));
gac.refresh();
DefaultPrivatePersistenceContextField bean = (DefaultPrivatePersistenceContextField) gac.getBean(
DefaultPrivatePersistenceContextField.class.getName());
FactoryBeanWithPersistenceContextField bean2 = (FactoryBeanWithPersistenceContextField) gac.getBean(
"&" + FactoryBeanWithPersistenceContextField.class.getName());
assertNotNull(bean.em);
assertNotNull(bean2.em);
assertNotNull(SerializationTestUtils.serializeAndDeserialize(bean.em));
assertNotNull(SerializationTestUtils.serializeAndDeserialize(bean2.em));
}
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testPublicExtendedPersistenceContextSetterWithEntityManagerInfoAndSerialization() throws Exception {
EntityManager mockEm = mock(EntityManager.class, withSettings().serializable());
given(mockEm.isOpen()).willReturn(true);
EntityManagerFactoryWithInfo mockEmf = mock(EntityManagerFactoryWithInfo.class);
given(mockEmf.getNativeEntityManagerFactory()).willReturn(mockEmf);
given(mockEmf.getJpaDialect()).willReturn(new DefaultJpaDialect());
given(mockEmf.getEntityManagerInterface()).willReturn((Class)EntityManager.class);
given(mockEmf.getBeanClassLoader()).willReturn(getClass().getClassLoader());
given(mockEmf.createEntityManager()).willReturn(mockEm);
GenericApplicationContext gac = new GenericApplicationContext();
gac.getDefaultListableBeanFactory().registerSingleton("entityManagerFactory", mockEmf);
gac.registerBeanDefinition("annotationProcessor",
new RootBeanDefinition(PersistenceAnnotationBeanPostProcessor.class));
gac.registerBeanDefinition(DefaultPublicPersistenceContextSetter.class.getName(),
new RootBeanDefinition(DefaultPublicPersistenceContextSetter.class));
gac.refresh();
DefaultPublicPersistenceContextSetter bean = (DefaultPublicPersistenceContextSetter) gac.getBean(
DefaultPublicPersistenceContextSetter.class.getName());
assertNotNull(bean.em);
assertNotNull(SerializationTestUtils.serializeAndDeserialize(bean.em));
}
@Test
public void serializable() throws Exception {
TestBean1 tb = new TestBean1();
CallCountingTransactionManager ptm = new CallCountingTransactionManager();
AnnotationTransactionAttributeSource tas = new AnnotationTransactionAttributeSource();
TransactionInterceptor ti = new TransactionInterceptor(ptm, tas);
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setInterfaces(ITestBean1.class);
proxyFactory.addAdvice(ti);
proxyFactory.setTarget(tb);
ITestBean1 proxy = (ITestBean1) proxyFactory.getProxy();
proxy.getAge();
assertEquals(1, ptm.commits);
ITestBean1 serializedProxy = (ITestBean1) SerializationTestUtils.serializeAndDeserialize(proxy);
serializedProxy.getAge();
Advised advised = (Advised) serializedProxy;
TransactionInterceptor serializedTi = (TransactionInterceptor) advised.getAdvisors()[0].getAdvice();
CallCountingTransactionManager serializedPtm =
(CallCountingTransactionManager) serializedTi.getTransactionManager();
assertEquals(2, serializedPtm.commits);
}
/**
* A TransactionInterceptor should be serializable if its
* PlatformTransactionManager is.
*/
@Test
public void serializableWithAttributeProperties() throws Exception {
TransactionInterceptor ti = new TransactionInterceptor();
Properties props = new Properties();
props.setProperty("methodName", "PROPAGATION_REQUIRED");
ti.setTransactionAttributes(props);
PlatformTransactionManager ptm = new SerializableTransactionManager();
ti.setTransactionManager(ptm);
ti = (TransactionInterceptor) SerializationTestUtils.serializeAndDeserialize(ti);
// Check that logger survived deserialization
assertNotNull(ti.logger);
assertTrue(ti.getTransactionManager() instanceof SerializableTransactionManager);
assertNotNull(ti.getTransactionAttributeSource());
}
@Test
public void serializeWithAllSerializableHeaders() throws Exception {
Map<String, Object> map = new HashMap<>();
map.put("name", "joe");
map.put("age", 42);
MessageHeaders input = new MessageHeaders(map);
MessageHeaders output = (MessageHeaders) SerializationTestUtils.serializeAndDeserialize(input);
assertEquals("joe", output.get("name"));
assertEquals(42, output.get("age"));
assertEquals("joe", input.get("name"));
assertEquals(42, input.get("age"));
}
@Test
public void testObjectFactoryWithTypedListMethod() throws Exception {
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(ObjectFactoryListMethodInjectionBean.class));
bf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class));
bf.setSerializationId("test");
ObjectFactoryListMethodInjectionBean bean = (ObjectFactoryListMethodInjectionBean) bf.getBean("annotatedBean");
assertSame(bf.getBean("testBean"), bean.getTestBean());
bean = (ObjectFactoryListMethodInjectionBean) SerializationTestUtils.serializeAndDeserialize(bean);
assertSame(bf.getBean("testBean"), bean.getTestBean());
}
@Test
public void serializeMutableHeaders() throws Exception {
Map<String, Object> headers = new HashMap<>();
headers.put("foo", "bar");
Message<String> message = new GenericMessage<>("test", headers);
MessageHeaderAccessor mutableAccessor = MessageHeaderAccessor.getMutableAccessor(message);
mutableAccessor.setContentType(MimeTypeUtils.TEXT_PLAIN);
message = new GenericMessage<>(message.getPayload(), mutableAccessor.getMessageHeaders());
Message<?> output = (Message<?>) SerializationTestUtils.serializeAndDeserialize(message);
assertEquals("test", output.getPayload());
assertEquals("bar", output.getHeaders().get("foo"));
assertNotNull(output.getHeaders().get(MessageHeaders.CONTENT_TYPE));
}
@Test
@SuppressWarnings("unchecked")
public void testSerializable() throws Exception {
AspectJProxyFactory proxyFactory = new AspectJProxyFactory(new TestBean());
proxyFactory.addAspect(LoggingAspectOnVarargs.class);
ITestBean proxy = proxyFactory.getProxy();
assertTrue(proxy.doWithVarargs(MyEnum.A, MyOtherEnum.C));
ITestBean tb = (ITestBean) SerializationTestUtils.serializeAndDeserialize(proxy);
assertTrue(tb.doWithVarargs(MyEnum.A, MyOtherEnum.C));
}
@Test
public void testSerializable() throws Throwable {
testSets();
// Count is now 2
Person p2 = (Person) SerializationTestUtils.serializeAndDeserialize(proxied);
NopInterceptor nop2 = (NopInterceptor) ((Advised) p2).getAdvisors()[0].getAdvice();
p2.getName();
assertEquals(2, nop2.getCount());
p2.echo(null);
assertEquals(3, nop2.getCount());
}
@Test
public void testExactMatch() throws Exception {
rpc.setPattern("java.lang.Object.hashCode");
exactMatchTests(rpc);
rpc = (AbstractRegexpMethodPointcut) SerializationTestUtils.serializeAndDeserialize(rpc);
exactMatchTests(rpc);
}
/**
* Test that when we serialize and deserialize various canonical instances
* of AOP classes, they return the same instance, not a new instance
* that's subverted the singleton construction limitation.
*/
@Test
public void testCanonicalFrameworkClassesStillCanonicalOnDeserialization() throws Exception {
assertSame(MethodMatcher.TRUE, SerializationTestUtils.serializeAndDeserialize(MethodMatcher.TRUE));
assertSame(ClassFilter.TRUE, SerializationTestUtils.serializeAndDeserialize(ClassFilter.TRUE));
assertSame(Pointcut.TRUE, SerializationTestUtils.serializeAndDeserialize(Pointcut.TRUE));
assertSame(EmptyTargetSource.INSTANCE, SerializationTestUtils.serializeAndDeserialize(EmptyTargetSource.INSTANCE));
assertSame(Pointcuts.SETTERS, SerializationTestUtils.serializeAndDeserialize(Pointcuts.SETTERS));
assertSame(Pointcuts.GETTERS, SerializationTestUtils.serializeAndDeserialize(Pointcuts.GETTERS));
assertSame(ExposeInvocationInterceptor.INSTANCE,
SerializationTestUtils.serializeAndDeserialize(ExposeInvocationInterceptor.INSTANCE));
}
@Test
public void testSerialization() throws Exception {
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
CommonAnnotationBeanPostProcessor bpp2 = (CommonAnnotationBeanPostProcessor)
SerializationTestUtils.serializeAndDeserialize(bpp);
AnnotatedInitDestroyBean bean = new AnnotatedInitDestroyBean();
bpp2.postProcessBeforeDestruction(bean, "annotatedBean");
assertTrue(bean.destroyCalled);
}