mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-12-01 15:37:14 +00:00
#939 - Make ModifyAwareSet serializable ... (for serializable entity beans with @DbJson etc)
This commit is contained in:
1 parent
8467934021
commit
335cef870f
10 files changed
+245
-130
No files matched your search
@@ -0,0 +1,33 @@
|
||||
package io.ebeaninternal.server.type;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class ModifyAwareFlagTest {
|
||||
|
||||
@Test
|
||||
public void serialise() throws IOException, ClassNotFoundException {
|
||||
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oos = new ObjectOutputStream(os);
|
||||
|
||||
ModifyAwareFlag flag = new ModifyAwareFlag();
|
||||
flag.markAsModified();
|
||||
oos.writeObject(flag);
|
||||
oos.flush();
|
||||
oos.close();
|
||||
|
||||
ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
|
||||
ObjectInputStream ois = new ObjectInputStream(is);
|
||||
|
||||
ModifyAwareFlag read = (ModifyAwareFlag)ois.readObject();
|
||||
assertThat(read.isMarkedDirty()).isTrue();
|
||||
}
|
||||
}
|
||||
@@ -2,13 +2,21 @@ package io.ebeaninternal.server.type;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
|
||||
public class ModifyAwareListTest {
|
||||
@@ -242,4 +250,22 @@ public class ModifyAwareListTest {
|
||||
|
||||
assertTrue(set.isMarkedDirty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serialise() throws IOException, ClassNotFoundException {
|
||||
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oos = new ObjectOutputStream(os);
|
||||
|
||||
ModifyAwareList<String> orig = createList();
|
||||
oos.writeObject(orig);
|
||||
oos.flush();
|
||||
oos.close();
|
||||
|
||||
ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
|
||||
ObjectInputStream ois = new ObjectInputStream(is);
|
||||
|
||||
ModifyAwareList<String> read = (ModifyAwareList<String>)ois.readObject();
|
||||
assertThat(read).contains("A", "B", "C", "D", "E");
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,19 @@ package io.ebeaninternal.server.type;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class ModifyAwareMapTest {
|
||||
@@ -181,4 +188,22 @@ public class ModifyAwareMapTest {
|
||||
assertEquals(map.size(), entries.size());
|
||||
assertFalse(map.isMarkedDirty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serialise() throws IOException, ClassNotFoundException {
|
||||
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oos = new ObjectOutputStream(os);
|
||||
|
||||
ModifyAwareMap<String, String> orig = createMap();
|
||||
oos.writeObject(orig);
|
||||
oos.flush();
|
||||
oos.close();
|
||||
|
||||
ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
|
||||
ObjectInputStream ois = new ObjectInputStream(is);
|
||||
|
||||
ModifyAwareMap<String, String> read = (ModifyAwareMap<String, String>)ois.readObject();
|
||||
assertThat(read).hasSize(orig.size());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package io.ebeaninternal.server.type;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class ModifyAwareSetTest {
|
||||
|
||||
private ModifyAwareSet<String> createSet() {
|
||||
HashSet<String> set = new HashSet<>();
|
||||
set.addAll(Arrays.asList("A", "B", "C", "D", "E"));
|
||||
return new ModifyAwareSet<>(set);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serialise() throws IOException, ClassNotFoundException {
|
||||
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oos = new ObjectOutputStream(os);
|
||||
|
||||
oos.writeObject(createSet());
|
||||
oos.flush();
|
||||
oos.close();
|
||||
|
||||
ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
|
||||
ObjectInputStream ois = new ObjectInputStream(is);
|
||||
|
||||
ModifyAwareSet<String> read = (ModifyAwareSet<String>)ois.readObject();
|
||||
assertThat(read).contains("A", "B", "C", "D", "E");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user