summaryrefslogtreecommitdiffstats
path: root/compatibility-server
diff options
context:
space:
mode:
authorArtur <artur@vaadin.com>2017-07-26 13:17:44 +0300
committerHenri Sara <henri.sara@gmail.com>2017-07-26 13:17:44 +0300
commitf38da154c1e6f5706c95e7bbc1468d47a0a65104 (patch)
tree054b5e3ea9491e5540a7233e49f334098c45aede /compatibility-server
parenteee5d3a25891579a1b2013a101ca7d185bc174ac (diff)
downloadvaadin-framework-f38da154c1e6f5706c95e7bbc1468d47a0a65104.tar.gz
vaadin-framework-f38da154c1e6f5706c95e7bbc1468d47a0a65104.zip
Make JavaScriptExtension serializable (#9721)
Fixes #9705
Diffstat (limited to 'compatibility-server')
-rw-r--r--compatibility-server/src/test/java/com/vaadin/tests/server/SerializationTest.java62
1 files changed, 62 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..eb852974fc
--- /dev/null
+++ b/compatibility-server/src/test/java/com/vaadin/tests/server/SerializationTest.java
@@ -0,0 +1,62 @@
+package com.vaadin.tests.server;
+
+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.server.AbstractJavaScriptExtension;
+import com.vaadin.ui.JavaScriptFunction;
+
+import elemental.json.JsonArray;
+
+public class SerializationTest {
+
+ public static class JSE extends AbstractJavaScriptExtension {
+ {
+ addFunction("foo", new JavaScriptFunction() {
+ @Override
+ public void call(JsonArray arguments) {
+ System.out.println("Foo called");
+ }
+ });
+ }
+
+ }
+
+ @Test
+ public void testJSExtension() throws Exception {
+ serializeAndDeserialize(new JSE());
+ }
+
+ 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();
+
+ if (s.equals(s2)) {
+ System.out.println(s + " equals " + s2);
+ } else {
+ System.out.println(s + " does NOT equal " + s2);
+ }
+
+ return s2;
+ }
+
+ private static String toString(Object o) {
+ return String.valueOf(o);
+ }
+
+}