use of org.springframework.beans.testfixture.beans.SerializablePerson in project spring-framework by spring-projects.
the class CommonsPool2TargetSourceTests method testProxySerializableWithoutConfigMixin.
@Test
void testProxySerializableWithoutConfigMixin() throws Exception {
Person pooled = (Person) beanFactory.getBean("pooledPerson");
boolean condition1 = ((Advised) pooled).getTargetSource() instanceof CommonsPool2TargetSource;
assertThat(condition1).isTrue();
// ((Advised) pooled).setTargetSource(new SingletonTargetSource(new SerializablePerson()));
Person serialized = SerializationTestUtils.serializeAndDeserialize(pooled);
boolean condition = ((Advised) serialized).getTargetSource() instanceof SingletonTargetSource;
assertThat(condition).isTrue();
serialized.setAge(25);
assertThat(serialized.getAge()).isEqualTo(25);
}
use of org.springframework.beans.testfixture.beans.SerializablePerson in project spring-framework by spring-projects.
the class DataBinderTests method testBindExceptionSerializable.
@Test
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();
assertThat(ex2.hasGlobalErrors()).isTrue();
assertThat(ex2.getGlobalError().getCode()).isEqualTo("invalid");
assertThat(ex2.hasFieldErrors("age")).isTrue();
assertThat(ex2.getFieldError("age").getCode()).isEqualTo("invalidField");
assertThat(ex2.getFieldValue("age")).isEqualTo(99);
ex2.rejectValue("name", "invalidField", "someMessage");
assertThat(ex2.hasFieldErrors("name")).isTrue();
assertThat(ex2.getFieldError("name").getCode()).isEqualTo("invalidField");
assertThat(ex2.getFieldValue("name")).isEqualTo("myName");
}
Aggregations