aboutsummaryrefslogtreecommitdiffstats
path: root/src/com/vaadin/tests/TestSerialization.java
diff options
context:
space:
mode:
authorArtur Signell <artur.signell@itmill.com>2009-06-08 19:06:26 +0000
committerArtur Signell <artur.signell@itmill.com>2009-06-08 19:06:26 +0000
commit202783a1981a328482642a13e36721e3d19af6f1 (patch)
treeb5b9e828721622066862704adf3b4042f78a09ef /src/com/vaadin/tests/TestSerialization.java
parent924219e468066f37e137af2e3c660880f6b841b1 (diff)
downloadvaadin-framework-202783a1981a328482642a13e36721e3d19af6f1.tar.gz
vaadin-framework-202783a1981a328482642a13e36721e3d19af6f1.zip
Test case for serialization issues #3051,#3015
svn changeset:8155/svn branch:6.0
Diffstat (limited to 'src/com/vaadin/tests/TestSerialization.java')
-rw-r--r--src/com/vaadin/tests/TestSerialization.java103
1 files changed, 103 insertions, 0 deletions
diff --git a/src/com/vaadin/tests/TestSerialization.java b/src/com/vaadin/tests/TestSerialization.java
new file mode 100644
index 0000000000..1b85ede47b
--- /dev/null
+++ b/src/com/vaadin/tests/TestSerialization.java
@@ -0,0 +1,103 @@
+package com.vaadin.tests;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+
+import junit.framework.TestCase;
+
+import com.sun.xml.internal.messaging.saaj.util.ByteOutputStream;
+import com.vaadin.data.Item;
+import com.vaadin.data.util.IndexedContainer;
+import com.vaadin.data.util.MethodProperty;
+import com.vaadin.ui.Form;
+
+public class TestSerialization extends TestCase {
+
+ public void testForm() throws Exception {
+ Form f = new Form();
+ String propertyId = "My property";
+ f.addItemProperty(propertyId, new MethodProperty(new Data(),
+ "dummyGetterAndSetter"));
+ f.replaceWithSelect(propertyId, new Object[] { "a", "b", null },
+ new String[] { "Item a", "ITem b", "Null item" });
+
+ serializeAndDeserialize(f);
+
+ }
+
+ 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);
+ }
+
+ public void testMethodPropertyGetter() throws Exception {
+ MethodProperty mp = new MethodProperty(new Data(), "dummyGetter");
+ serializeAndDeserialize(mp);
+ }
+
+ public void testMethodPropertyGetterAndSetter() throws Exception {
+ MethodProperty mp = new MethodProperty(new Data(),
+ "dummyGetterAndSetter");
+ serializeAndDeserialize(mp);
+ }
+
+ public void testMethodPropertyInt() throws Exception {
+ MethodProperty mp = new MethodProperty(new Data(), "dummyInt");
+ serializeAndDeserialize(mp);
+ }
+
+ private static void serializeAndDeserialize(Serializable s)
+ throws IOException, ClassNotFoundException {
+ // Serialize and deserialize
+
+ ByteOutputStream bs = new ByteOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream(bs);
+ out.writeObject(s);
+ byte[] data = bs.getBytes();
+ ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(
+ data));
+ Serializable s2 = (Serializable) in.readObject();
+
+ if (s.equals(s2)) {
+ System.out.println(s + " equals " + s2);
+ } else {
+ System.out.println(s + " does NOT equal " + s2);
+ }
+ }
+
+ 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;
+ }
+ }
+} \ No newline at end of file