Search in sources :

Example 1 with AnEntity

use of org.hibernate.serialization.entity.AnEntity in project hibernate-orm by hibernate.

the class GetterSetterSerializationTest method testProtectedMethodSetter.

@Test
@TestForIssue(jiraKey = "HHH-11202")
public void testProtectedMethodSetter() throws Exception {
    final AnEntity entity = new AnEntity(new PK(1L));
    final Getter getter = new GetterMethodImpl(AnEntity.class, "pk", ReflectHelper.findGetterMethod(AnEntity.class, "pk"));
    final Setter setter = new SetterMethodImpl(AnEntity.class, "pk", ReflectHelper.findSetterMethod(AnEntity.class, "pk", PK.class));
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(setter);
    final ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
    final Setter setterClone = (Setter) ois.readObject();
    final PK pkNew = new PK(2L);
    setterClone.set(entity, pkNew, null);
    assertSame(pkNew, getter.get(entity));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Getter(org.hibernate.property.access.spi.Getter) Setter(org.hibernate.property.access.spi.Setter) GetterMethodImpl(org.hibernate.property.access.spi.GetterMethodImpl) PK(org.hibernate.serialization.entity.PK) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AnEntity(org.hibernate.serialization.entity.AnEntity) ObjectOutputStream(java.io.ObjectOutputStream) SetterMethodImpl(org.hibernate.property.access.spi.SetterMethodImpl) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 2 with AnEntity

use of org.hibernate.serialization.entity.AnEntity in project hibernate-orm by hibernate.

the class GetterSetterSerializationTest method testProtectedMethodGetter.

@Test
@TestForIssue(jiraKey = "HHH-11202")
public void testProtectedMethodGetter() throws Exception {
    final AnEntity entity = new AnEntity(new PK(1L));
    final Getter getter = new GetterMethodImpl(AnEntity.class, "pk", ReflectHelper.findGetterMethod(AnEntity.class, "pk"));
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(getter);
    final ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
    final Getter getterClone = (Getter) ois.readObject();
    assertSame(getter.get(entity), getterClone.get(entity));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Getter(org.hibernate.property.access.spi.Getter) GetterMethodImpl(org.hibernate.property.access.spi.GetterMethodImpl) PK(org.hibernate.serialization.entity.PK) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AnEntity(org.hibernate.serialization.entity.AnEntity) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 3 with AnEntity

use of org.hibernate.serialization.entity.AnEntity in project hibernate-orm by hibernate.

the class GetterSetterSerializationTest method testPrivateFieldSetter.

@Test
@TestForIssue(jiraKey = "HHH-11202")
public void testPrivateFieldSetter() throws Exception {
    AnEntity entity = new AnEntity(new PK(1L));
    final Getter getter = new GetterFieldImpl(AnEntity.class, "pk", ReflectHelper.findField(AnEntity.class, "pk"));
    final Setter setter = new SetterFieldImpl(AnEntity.class, "pk", ReflectHelper.findField(AnEntity.class, "pk"));
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(setter);
    final ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
    final Setter setterClone = (Setter) ois.readObject();
    final PK pkNew = new PK(2L);
    setterClone.set(entity, pkNew, null);
    assertSame(pkNew, getter.get(entity));
}
Also used : GetterFieldImpl(org.hibernate.property.access.spi.GetterFieldImpl) ByteArrayInputStream(java.io.ByteArrayInputStream) Getter(org.hibernate.property.access.spi.Getter) Setter(org.hibernate.property.access.spi.Setter) PK(org.hibernate.serialization.entity.PK) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AnEntity(org.hibernate.serialization.entity.AnEntity) SetterFieldImpl(org.hibernate.property.access.spi.SetterFieldImpl) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 4 with AnEntity

use of org.hibernate.serialization.entity.AnEntity in project hibernate-orm by hibernate.

the class GetterSetterSerializationTest method testPrivateFieldGetter.

@Test
@TestForIssue(jiraKey = "HHH-11202")
public void testPrivateFieldGetter() throws Exception {
    final AnEntity entity = new AnEntity(new PK(1L));
    final Getter getter = new GetterFieldImpl(AnEntity.class, "pk", ReflectHelper.findField(AnEntity.class, "pk"));
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(getter);
    final ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
    final Getter getterClone = (Getter) ois.readObject();
    assertSame(getter.get(entity), getterClone.get(entity));
}
Also used : GetterFieldImpl(org.hibernate.property.access.spi.GetterFieldImpl) ByteArrayInputStream(java.io.ByteArrayInputStream) Getter(org.hibernate.property.access.spi.Getter) PK(org.hibernate.serialization.entity.PK) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AnEntity(org.hibernate.serialization.entity.AnEntity) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 ObjectInputStream (java.io.ObjectInputStream)4 ObjectOutputStream (java.io.ObjectOutputStream)4 Getter (org.hibernate.property.access.spi.Getter)4 AnEntity (org.hibernate.serialization.entity.AnEntity)4 PK (org.hibernate.serialization.entity.PK)4 TestForIssue (org.hibernate.testing.TestForIssue)4 Test (org.junit.Test)4 GetterFieldImpl (org.hibernate.property.access.spi.GetterFieldImpl)2 GetterMethodImpl (org.hibernate.property.access.spi.GetterMethodImpl)2 Setter (org.hibernate.property.access.spi.Setter)2 SetterFieldImpl (org.hibernate.property.access.spi.SetterFieldImpl)1 SetterMethodImpl (org.hibernate.property.access.spi.SetterMethodImpl)1