org.springframework.util.SerializationTestUtils Java Examples

The following examples show how to use org.springframework.util.SerializationTestUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AnnotationTransactionAttributeSourceTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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);
}
 
Example #2
Source File: PersistenceInjectionTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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));
}
 
Example #3
Source File: LocalContainerEntityManagerFactoryBeanTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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));
}
 
Example #4
Source File: DelegatingIntroductionInterceptorTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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());
}
 
Example #5
Source File: PersistenceInjectionTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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));
}
 
Example #6
Source File: AnnotationTransactionAttributeSourceTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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);
}
 
Example #7
Source File: ConcurrencyThrottleInterceptorTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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();
}
 
Example #8
Source File: AspectProxyFactoryTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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());
}
 
Example #9
Source File: TransactionInterceptorTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * 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());
}
 
Example #10
Source File: ComponentScanAnnotationIntegrationTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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"));
}
 
Example #11
Source File: AspectProxyFactoryTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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());
}
 
Example #12
Source File: ConcurrencyThrottleInterceptorTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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();
}
 
Example #13
Source File: DelegatingIntroductionInterceptorTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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());
}
 
Example #14
Source File: ProxyFactoryBeanTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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));
}
 
Example #15
Source File: ProxyFactoryBeanTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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));
}
 
Example #16
Source File: ComponentScanParserScopedProxyTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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();
}
 
Example #17
Source File: LocalContainerEntityManagerFactoryBeanTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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));
}
 
Example #18
Source File: PersistenceInjectionTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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));
}
 
Example #19
Source File: ComponentScanParserScopedProxyTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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();
}
 
Example #20
Source File: ComponentScanParserScopedProxyTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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();
}
 
Example #21
Source File: ComponentScanParserScopedProxyTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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();
}
 
Example #22
Source File: PersistenceInjectionTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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));
}
 
Example #23
Source File: NameMatchMethodPointcutTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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());
}
 
Example #24
Source File: InjectAnnotationBeanPostProcessorTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testObjectFactoryWithTypedListField() throws Exception {
	bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(ObjectFactoryListFieldInjectionBean.class));
	bf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class));
	bf.setSerializationId("test");

	ObjectFactoryListFieldInjectionBean bean = (ObjectFactoryListFieldInjectionBean) bf.getBean("annotatedBean");
	assertSame(bf.getBean("testBean"), bean.getTestBean());
	bean = (ObjectFactoryListFieldInjectionBean) SerializationTestUtils.serializeAndDeserialize(bean);
	assertSame(bf.getBean("testBean"), bean.getTestBean());
}
 
Example #25
Source File: AopUtilsTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * 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));
}
 
Example #26
Source File: MessageHeadersTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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"));
}
 
Example #27
Source File: AspectProxyFactoryTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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));
}
 
Example #28
Source File: MessageHeadersTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void serializeWithNonSerializableHeader() throws Exception {
	Object address = new Object();
	Map<String, Object> map = new HashMap<>();
	map.put("name", "joe");
	map.put("address", address);
	MessageHeaders input = new MessageHeaders(map);
	MessageHeaders output = (MessageHeaders) SerializationTestUtils.serializeAndDeserialize(input);
	assertEquals("joe", output.get("name"));
	assertNull(output.get("address"));
	assertEquals("joe", input.get("name"));
	assertSame(address, input.get("address"));
}
 
Example #29
Source File: MessageHeaderAccessorTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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));
}
 
Example #30
Source File: InjectAnnotationBeanPostProcessorTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testObjectFactoryWithBeanMethod() throws Exception {
	bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(ObjectFactoryMethodInjectionBean.class));
	bf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class));
	bf.setSerializationId("test");

	ObjectFactoryMethodInjectionBean bean = (ObjectFactoryMethodInjectionBean) bf.getBean("annotatedBean");
	assertSame(bf.getBean("testBean"), bean.getTestBean());
	bean = (ObjectFactoryMethodInjectionBean) SerializationTestUtils.serializeAndDeserialize(bean);
	assertSame(bf.getBean("testBean"), bean.getTestBean());
}