aboutsummaryrefslogtreecommitdiffstats
path: root/compatibility-server/src/test/java/com/vaadin/tests/server/SerializationTest.java
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2016-08-18 22:10:47 +0300
committerArtur Signell <artur@vaadin.com>2016-08-20 00:12:18 +0300
commitfe3dca081a64af892a7f4c0416ecc643aec3ec5a (patch)
tree1901fb377336d3c5a772335322d9c434a4a75e24 /compatibility-server/src/test/java/com/vaadin/tests/server/SerializationTest.java
parent65370e12a0605926cb80e205c2b0e74fefe83e5b (diff)
downloadvaadin-framework-fe3dca081a64af892a7f4c0416ecc643aec3ec5a.tar.gz
vaadin-framework-fe3dca081a64af892a7f4c0416ecc643aec3ec5a.zip
Move remaining selects and container implementations to compatibility package
Because of dependencies also moves Calendar, ColorPicker, SQLContainer, container filters Change-Id: I0594cb24f20486ebbca4be578827fea7cdf92108
Diffstat (limited to 'compatibility-server/src/test/java/com/vaadin/tests/server/SerializationTest.java')
-rw-r--r--compatibility-server/src/test/java/com/vaadin/tests/server/SerializationTest.java135
1 files changed, 135 insertions, 0 deletions
diff --git a/compatibility-server/src/test/java/com/vaadin/tests/server/SerializationTest.java b/compatibility-server/src/test/java/com/vaadin/tests/server/SerializationTest.java
new file mode 100644
index 0000000000..30b0729ace
--- /dev/null
+++ b/compatibility-server/src/test/java/com/vaadin/tests/server/SerializationTest.java
@@ -0,0 +1,135 @@
+package com.vaadin.tests.server;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+
+import org.junit.Test;
+
+import com.vaadin.data.Item;
+import com.vaadin.data.Property;
+import com.vaadin.data.util.IndexedContainer;
+import com.vaadin.data.util.MethodProperty;
+import com.vaadin.server.VaadinSession;
+import com.vaadin.v7.data.validator.LegacyRegexpValidator;
+
+public class SerializationTest {
+
+ @Test
+ public void testValidators() throws Exception {
+ LegacyRegexpValidator validator = new LegacyRegexpValidator(".*",
+ "Error");
+ validator.validate("aaa");
+ LegacyRegexpValidator validator2 = serializeAndDeserialize(validator);
+ validator2.validate("aaa");
+ }
+
+ @Test
+ public void testIndedexContainerItemIds() throws Exception {
+ IndexedContainer ic = new IndexedContainer();
+ ic.addContainerProperty("prop1", String.class, null);
+ Object id = ic.addItem();
+ ic.getItem(id).getItemProperty("prop1").setValue("1");
+
+ Item item2 = ic.addItem("item2");
+ item2.getItemProperty("prop1").setValue("2");
+
+ serializeAndDeserialize(ic);
+ }
+
+ @Test
+ public void testMethodPropertyGetter() throws Exception {
+ MethodProperty<?> mp = new MethodProperty<Object>(new Data(),
+ "dummyGetter");
+ serializeAndDeserialize(mp);
+ }
+
+ @Test
+ public void testMethodPropertyGetterAndSetter() throws Exception {
+ MethodProperty<?> mp = new MethodProperty<Object>(new Data(),
+ "dummyGetterAndSetter");
+ serializeAndDeserialize(mp);
+ }
+
+ @Test
+ public void testMethodPropertyInt() throws Exception {
+ MethodProperty<?> mp = new MethodProperty<Object>(new Data(),
+ "dummyInt");
+ serializeAndDeserialize(mp);
+ }
+
+ @Test
+ public void testVaadinSession() throws Exception {
+ VaadinSession session = new VaadinSession(null);
+
+ session = serializeAndDeserialize(session);
+
+ assertNotNull(
+ "Pending access queue was not recreated after deserialization",
+ session.getPendingAccessQueue());
+ }
+
+ private static <S extends Serializable> S serializeAndDeserialize(S s)
+ throws IOException, ClassNotFoundException {
+ // Serialize and deserialize
+
+ ByteArrayOutputStream bs = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream(bs);
+ out.writeObject(s);
+ byte[] data = bs.toByteArray();
+ ObjectInputStream in = new ObjectInputStream(
+ new ByteArrayInputStream(data));
+ @SuppressWarnings("unchecked")
+ S s2 = (S) in.readObject();
+
+ // using special toString(Object) method to avoid calling
+ // Property.toString(), which will be temporarily disabled
+ // TODO This is hilariously broken (#12723)
+ if (s.equals(s2)) {
+ System.out.println(toString(s) + " equals " + toString(s2));
+ } else {
+ System.out.println(toString(s) + " does NOT equal " + toString(s2));
+ }
+
+ return s2;
+ }
+
+ private static String toString(Object o) {
+ if (o instanceof Property) {
+ return String.valueOf(((Property<?>) o).getValue());
+ } else {
+ return String.valueOf(o);
+ }
+ }
+
+ public static class Data implements Serializable {
+ private String dummyGetter;
+ private String dummyGetterAndSetter;
+ private int dummyInt;
+
+ public String getDummyGetterAndSetter() {
+ return dummyGetterAndSetter;
+ }
+
+ public void setDummyGetterAndSetter(String dummyGetterAndSetter) {
+ this.dummyGetterAndSetter = dummyGetterAndSetter;
+ }
+
+ public int getDummyInt() {
+ return dummyInt;
+ }
+
+ public void setDummyInt(int dummyInt) {
+ this.dummyInt = dummyInt;
+ }
+
+ public String getDummyGetter() {
+ return dummyGetter;
+ }
+ }
+}