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

The following examples show how to use org.springframework.tests.sample.beans.SerializablePerson. 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: 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 #3
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 #4
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 #5
Source File: DataBinderTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testBindExceptionSerializable() throws Exception {
	SerializablePerson tb = new SerializablePerson();
	tb.setName("myName");
	tb.setAge(99);

	BindException ex = new BindException(tb, "tb");
	ex.reject("invalid", "someMessage");
	ex.rejectValue("age", "invalidField", "someMessage");

	ByteArrayOutputStream baos = new ByteArrayOutputStream();
	ObjectOutputStream oos = new ObjectOutputStream(baos);
	oos.writeObject(ex);
	ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
	ObjectInputStream ois = new ObjectInputStream(bais);

	BindException ex2 = (BindException) ois.readObject();
	assertTrue(ex2.hasGlobalErrors());
	assertEquals("invalid", ex2.getGlobalError().getCode());
	assertTrue(ex2.hasFieldErrors("age"));
	assertEquals("invalidField", ex2.getFieldError("age").getCode());
	assertEquals(new Integer(99), ex2.getFieldValue("age"));

	ex2.rejectValue("name", "invalidField", "someMessage");
	assertTrue(ex2.hasFieldErrors("name"));
	assertEquals("invalidField", ex2.getFieldError("name").getCode());
	assertEquals("myName", ex2.getFieldValue("name"));
}
 
Example #6
Source File: AbstractAopProxyTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testSerializationAdviceNotSerializable() throws Exception {
	SerializablePerson sp = new SerializablePerson();
	assertTrue(SerializationTestUtils.isSerializable(sp));

	ProxyFactory pf = new ProxyFactory(sp);

	// This isn't serializable
	Advice i = new NopInterceptor();
	pf.addAdvice(i);
	assertFalse(SerializationTestUtils.isSerializable(i));
	Object proxy = createAopProxy(pf).getProxy();

	assertFalse(SerializationTestUtils.isSerializable(proxy));
}
 
Example #7
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 #8
Source File: DataBinderTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testBindExceptionSerializable() throws Exception {
	SerializablePerson tb = new SerializablePerson();
	tb.setName("myName");
	tb.setAge(99);

	BindException ex = new BindException(tb, "tb");
	ex.reject("invalid", "someMessage");
	ex.rejectValue("age", "invalidField", "someMessage");

	ByteArrayOutputStream baos = new ByteArrayOutputStream();
	ObjectOutputStream oos = new ObjectOutputStream(baos);
	oos.writeObject(ex);
	ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
	ObjectInputStream ois = new ObjectInputStream(bais);

	BindException ex2 = (BindException) ois.readObject();
	assertTrue(ex2.hasGlobalErrors());
	assertEquals("invalid", ex2.getGlobalError().getCode());
	assertTrue(ex2.hasFieldErrors("age"));
	assertEquals("invalidField", ex2.getFieldError("age").getCode());
	assertEquals(new Integer(99), ex2.getFieldValue("age"));

	ex2.rejectValue("name", "invalidField", "someMessage");
	assertTrue(ex2.hasFieldErrors("name"));
	assertEquals("invalidField", ex2.getFieldError("name").getCode());
	assertEquals("myName", ex2.getFieldValue("name"));
}
 
Example #9
Source File: AbstractAopProxyTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testSerializationAdviceNotSerializable() throws Exception {
	SerializablePerson sp = new SerializablePerson();
	assertTrue(SerializationTestUtils.isSerializable(sp));

	ProxyFactory pf = new ProxyFactory(sp);

	// This isn't serializable
	Advice i = new NopInterceptor();
	pf.addAdvice(i);
	assertFalse(SerializationTestUtils.isSerializable(i));
	Object proxy = createAopProxy(pf).getProxy();

	assertFalse(SerializationTestUtils.isSerializable(proxy));
}
 
Example #10
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 #11
Source File: DataBinderTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testBindExceptionSerializable() throws Exception {
	SerializablePerson tb = new SerializablePerson();
	tb.setName("myName");
	tb.setAge(99);

	BindException ex = new BindException(tb, "tb");
	ex.reject("invalid", "someMessage");
	ex.rejectValue("age", "invalidField", "someMessage");

	ByteArrayOutputStream baos = new ByteArrayOutputStream();
	ObjectOutputStream oos = new ObjectOutputStream(baos);
	oos.writeObject(ex);
	ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
	ObjectInputStream ois = new ObjectInputStream(bais);

	BindException ex2 = (BindException) ois.readObject();
	assertTrue(ex2.hasGlobalErrors());
	assertEquals("invalid", ex2.getGlobalError().getCode());
	assertTrue(ex2.hasFieldErrors("age"));
	assertEquals("invalidField", ex2.getFieldError("age").getCode());
	assertEquals(new Integer(99), ex2.getFieldValue("age"));

	ex2.rejectValue("name", "invalidField", "someMessage");
	assertTrue(ex2.hasFieldErrors("name"));
	assertEquals("invalidField", ex2.getFieldError("name").getCode());
	assertEquals("myName", ex2.getFieldValue("name"));
}
 
Example #12
Source File: AbstractAopProxyTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testSerializationAdviceNotSerializable() throws Exception {
	SerializablePerson sp = new SerializablePerson();
	assertTrue(SerializationTestUtils.isSerializable(sp));

	ProxyFactory pf = new ProxyFactory(sp);

	// This isn't serializable
	Advice i = new NopInterceptor();
	pf.addAdvice(i);
	assertFalse(SerializationTestUtils.isSerializable(i));
	Object proxy = createAopProxy(pf).getProxy();

	assertFalse(SerializationTestUtils.isSerializable(proxy));
}