diff options
author | John Ahlroos <john@vaadin.com> | 2013-04-15 16:01:51 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2013-04-16 06:26:37 +0000 |
commit | 224cd8e24ac133e00685dc03c0cf30832589421a (patch) | |
tree | 1a4ad5c318f86088e05125887d6eda7cb0802378 /uitest/src/com/vaadin/tests/push/BasicPush.java | |
parent | f7ed5d10954ad6085f7b7ad97e651f92ee800a5f (diff) | |
download | vaadin-framework-224cd8e24ac133e00685dc03c0cf30832589421a.tar.gz vaadin-framework-224cd8e24ac133e00685dc03c0cf30832589421a.zip |
Simple test for testing push capabilities #11494
Change-Id: I7dc3b861c2fa19bd1cffad93911c525fc5a2d24c
Diffstat (limited to 'uitest/src/com/vaadin/tests/push/BasicPush.java')
-rw-r--r-- | uitest/src/com/vaadin/tests/push/BasicPush.java | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/uitest/src/com/vaadin/tests/push/BasicPush.java b/uitest/src/com/vaadin/tests/push/BasicPush.java new file mode 100644 index 0000000000..17d107bb8c --- /dev/null +++ b/uitest/src/com/vaadin/tests/push/BasicPush.java @@ -0,0 +1,102 @@ +package com.vaadin.tests.push; + +import java.util.Date; +import java.util.Timer; +import java.util.TimerTask; + +import com.vaadin.data.util.ObjectProperty; +import com.vaadin.server.VaadinRequest; +import com.vaadin.shared.ui.label.ContentMode; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Label; + +public class BasicPush extends AbstractTestUI { + + private ObjectProperty<Integer> counter = new ObjectProperty<Integer>(0); + + private ObjectProperty<Integer> counter2 = new ObjectProperty<Integer>(0); + + private final Timer timer = new Timer(true); + + private final TimerTask task = new TimerTask() { + + @Override + public void run() { + runSafely(new Runnable() { + @Override + public void run() { + counter2.setValue(counter2.getValue() + 1); + } + }); + } + }; + + @Override + protected void setup(VaadinRequest request) { + + spacer(); + + /* + * Client initiated push. + */ + Label lbl = new Label(counter); + lbl.setCaption("Client counter (click 'increment' to update):"); + addComponent(lbl); + + addComponent(new Button("Increment", new Button.ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + counter.setValue(counter.getValue() + 1); + } + })); + + spacer(); + + /* + * Server initiated push. + */ + lbl = new Label(counter2); + lbl.setCaption("Server counter (updates each 3s by server thread) :"); + addComponent(lbl); + + addComponent(new Button("Reset", new Button.ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + counter2.setValue(0); + } + })); + } + + @Override + protected String getTestDescription() { + return "This test tests the very basic operations of push. " + + "It tests that client initiated changes are " + + "recieved back to the client as well as server " + + "initiated changes are correctly updated to the client."; + } + + @Override + protected Integer getTicketNumber() { + return 11494; + } + + private void spacer() { + addComponent(new Label("<hr/>", ContentMode.HTML)); + } + + @Override + public void attach() { + super.attach(); + timer.scheduleAtFixedRate(task, new Date(), 3000); + } + + @Override + public void detach() { + super.detach(); + timer.cancel(); + } +} |