org.springframework.tests.sample.beans.Person Java Examples

The following examples show how to use org.springframework.tests.sample.beans.Person. 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: 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 #2
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 #3
Source File: ProxyFactoryBeanTests.java    From spring4-understanding with Apache License 2.0 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 #4
Source File: DelegatingIntroductionInterceptorTests.java    From spring4-understanding with Apache License 2.0 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: 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 #6
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 #7
Source File: ProxyFactoryBeanTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testProxyNotSerializableBecauseOfAdvice() throws Exception {
	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
	new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(SERIALIZATION_CONTEXT, CLASS));
	Person p = (Person) bf.getBean("interceptorNotSerializableSingleton");
	assertFalse("Not serializable because an interceptor isn't serializable", SerializationTestUtils.isSerializable(p));
}
 
Example #8
Source File: NameMatchMethodPointcutTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Create an empty pointcut, populating instance variables.
 */
@Before
public void setup() {
	ProxyFactory pf = new ProxyFactory(new SerializablePerson());
	nop = new SerializableNopInterceptor();
	pc = new NameMatchMethodPointcut();
	pf.addAdvisor(new DefaultPointcutAdvisor(pc, nop));
	proxied = (Person) pf.getProxy();
}
 
Example #9
Source File: ProxyFactoryBeanTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testSerializableSingletonProxyFactoryBean() throws Exception {
	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
	new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(SERIALIZATION_CONTEXT, CLASS));
	Person p = (Person) bf.getBean("serializableSingleton");
	ProxyFactoryBean pfb = (ProxyFactoryBean) bf.getBean("&serializableSingleton");
	ProxyFactoryBean pfb2 = (ProxyFactoryBean) SerializationTestUtils.serializeAndDeserialize(pfb);
	Person p2 = (Person) pfb2.getObject();
	assertEquals(p, p2);
	assertNotSame(p, p2);
	assertEquals("serializableSingleton", p2.getName());
}
 
Example #10
Source File: ProxyFactoryBeanTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testSerializablePrototypeProxy() throws Exception {
	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
	new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(SERIALIZATION_CONTEXT, CLASS));
	Person p = (Person) bf.getBean("serializablePrototype");
	assertNotSame("Should not be a Singleton", p, bf.getBean("serializablePrototype"));
	Person p2 = (Person) SerializationTestUtils.serializeAndDeserialize(p);
	assertEquals(p, p2);
	assertNotSame(p, p2);
	assertEquals("serializablePrototype", p2.getName());
}
 
Example #11
Source File: NameMatchMethodPointcutTests.java    From spring4-understanding with Apache License 2.0 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 #12
Source File: NameMatchMethodPointcutTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Create an empty pointcut, populating instance variables.
 */
@Before
public void setUp() {
	ProxyFactory pf = new ProxyFactory(new SerializablePerson());
	nop = new SerializableNopInterceptor();
	pc = new NameMatchMethodPointcut();
	pf.addAdvisor(new DefaultPointcutAdvisor(pc, nop));
	proxied = (Person) pf.getProxy();
}
 
Example #13
Source File: ProxyFactoryBeanTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testProxyNotSerializableBecauseOfAdvice() throws Exception {
	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
	new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(SERIALIZATION_CONTEXT, CLASS));
	Person p = (Person) bf.getBean("interceptorNotSerializableSingleton");
	assertFalse("Not serializable because an interceptor isn't serializable", SerializationTestUtils.isSerializable(p));
}
 
Example #14
Source File: ProxyFactoryBeanTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testSerializableSingletonProxyFactoryBean() throws Exception {
	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
	new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(SERIALIZATION_CONTEXT, CLASS));
	Person p = (Person) bf.getBean("serializableSingleton");
	ProxyFactoryBean pfb = (ProxyFactoryBean) bf.getBean("&serializableSingleton");
	ProxyFactoryBean pfb2 = (ProxyFactoryBean) SerializationTestUtils.serializeAndDeserialize(pfb);
	Person p2 = (Person) pfb2.getObject();
	assertEquals(p, p2);
	assertNotSame(p, p2);
	assertEquals("serializableSingleton", p2.getName());
}
 
Example #15
Source File: ProxyFactoryBeanTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testSerializablePrototypeProxy() throws Exception {
	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
	new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(SERIALIZATION_CONTEXT, CLASS));
	Person p = (Person) bf.getBean("serializablePrototype");
	assertNotSame("Should not be a Singleton", p, bf.getBean("serializablePrototype"));
	Person p2 = (Person) SerializationTestUtils.serializeAndDeserialize(p);
	assertEquals(p, p2);
	assertNotSame(p, p2);
	assertEquals("serializablePrototype", p2.getName());
}
 
Example #16
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 #17
Source File: NameMatchMethodPointcutTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Create an empty pointcut, populating instance variables.
 */
@Before
public void setup() {
	ProxyFactory pf = new ProxyFactory(new SerializablePerson());
	nop = new SerializableNopInterceptor();
	pc = new NameMatchMethodPointcut();
	pf.addAdvisor(new DefaultPointcutAdvisor(pc, nop));
	proxied = (Person) pf.getProxy();
}
 
Example #18
Source File: ProxyFactoryBeanTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testProxyNotSerializableBecauseOfAdvice() throws Exception {
	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
	new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(SERIALIZATION_CONTEXT, CLASS));
	Person p = (Person) bf.getBean("interceptorNotSerializableSingleton");
	assertFalse("Not serializable because an interceptor isn't serializable", SerializationTestUtils.isSerializable(p));
}
 
Example #19
Source File: ProxyFactoryBeanTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testSerializableSingletonProxyFactoryBean() throws Exception {
	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
	new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(SERIALIZATION_CONTEXT, CLASS));
	Person p = (Person) bf.getBean("serializableSingleton");
	ProxyFactoryBean pfb = (ProxyFactoryBean) bf.getBean("&serializableSingleton");
	ProxyFactoryBean pfb2 = (ProxyFactoryBean) SerializationTestUtils.serializeAndDeserialize(pfb);
	Person p2 = (Person) pfb2.getObject();
	assertEquals(p, p2);
	assertNotSame(p, p2);
	assertEquals("serializableSingleton", p2.getName());
}
 
Example #20
Source File: ProxyFactoryBeanTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testSerializablePrototypeProxy() throws Exception {
	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
	new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(SERIALIZATION_CONTEXT, CLASS));
	Person p = (Person) bf.getBean("serializablePrototype");
	assertNotSame("Should not be a Singleton", p, bf.getBean("serializablePrototype"));
	Person p2 = (Person) SerializationTestUtils.serializeAndDeserialize(p);
	assertEquals(p, p2);
	assertNotSame(p, p2);
	assertEquals("serializablePrototype", p2.getName());
}
 
Example #21
Source File: NameMatchMethodPointcutTests.java    From spring-analysis-note 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());
}