From edca4095d2e75d73f9d6a5acb2da9009129b4db2 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Wed, 5 Jun 2013 14:27:09 +0300 Subject: Allow customizing client-side push config on server side (#11867) Change-Id: I212067aa0bd04e3e73844ef57963b5622291986a --- .../com/vaadin/tests/push/PushConfiguration.html | 130 ++++++++++++++++++ .../vaadin/tests/push/PushConfigurationTest.java | 102 ++++++++++++++ .../com/vaadin/tests/push/PushConfigurator.java | 152 +++++++++++++++++++++ uitest/src/com/vaadin/tests/push/TogglePush.java | 13 +- .../widgetset/client/TestingPushConnection.java | 4 +- 5 files changed, 395 insertions(+), 6 deletions(-) create mode 100644 uitest/src/com/vaadin/tests/push/PushConfiguration.html create mode 100644 uitest/src/com/vaadin/tests/push/PushConfigurationTest.java create mode 100644 uitest/src/com/vaadin/tests/push/PushConfigurator.java (limited to 'uitest/src/com') diff --git a/uitest/src/com/vaadin/tests/push/PushConfiguration.html b/uitest/src/com/vaadin/tests/push/PushConfiguration.html new file mode 100644 index 0000000000..c3786b1cc1 --- /dev/null +++ b/uitest/src/com/vaadin/tests/push/PushConfiguration.html @@ -0,0 +1,130 @@ + + + + + + +New Test + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
New Test
open/run/com.vaadin.tests.push.PushConfigurationTest?debug&restartApplication
assertNotTextvaadin=runcomvaadintestspushPushConfigurationTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[5]/VLabel[0]4
selectvaadin=runcomvaadintestspushPushConfigurationTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[1]/VNativeSelect[0]/domChild[0]label=WEBSOCKET
assertNotTextvaadin=runcomvaadintestspushPushConfigurationTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[5]/VLabel[0]4
selectvaadin=runcomvaadintestspushPushConfigurationTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[0]/VNativeSelect[0]/domChild[0]label=AUTOMATIC
assertTextvaadin=runcomvaadintestspushPushConfigurationTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[5]/VLabel[0]/domChild[0]*fallbackTransport: streaming*transport: websocket*
assertNotTextvaadin=runcomvaadintestspushPushConfigurationTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[5]/VLabel[0]4
waitForTextvaadin=runcomvaadintestspushPushConfigurationTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[5]/VLabel[0]4
assertTextPresentPush connection established using websocket
assertTextNotPresentPush connection established using streamingPush connection established using streaming
selectvaadin=runcomvaadintestspushPushConfigurationTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[0]/VNativeSelect[0]/domChild[0]label=DISABLED
open/run/com.vaadin.tests.push.PushConfigurationTest?debug&restartApplication
assertNotTextvaadin=runcomvaadintestspushPushConfigurationTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[5]/VLabel[0]4
selectvaadin=runcomvaadintestspushPushConfigurationTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[1]/VNativeSelect[0]/domChild[0]label=STREAMING
assertNotTextvaadin=runcomvaadintestspushPushConfigurationTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[5]/VLabel[0]4
selectvaadin=runcomvaadintestspushPushConfigurationTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[0]/VNativeSelect[0]/domChild[0]label=AUTOMATIC
assertNotTextvaadin=runcomvaadintestspushPushConfigurationTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[5]/VLabel[0]4
assertTextvaadin=runcomvaadintestspushPushConfigurationTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[5]/VLabel[0]/domChild[0]*fallbackTransport: streaming*transport: streaming*
waitForTextvaadin=runcomvaadintestspushPushConfigurationTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[5]/VLabel[0]4
assertTextNotPresentPush connection established using websocket
assertTextPresentPush connection established using streaming
selectvaadin=runcomvaadintestspushPushConfigurationTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[0]/VNativeSelect[0]/domChild[0]label=DISABLED
+ + diff --git a/uitest/src/com/vaadin/tests/push/PushConfigurationTest.java b/uitest/src/com/vaadin/tests/push/PushConfigurationTest.java new file mode 100644 index 0000000000..b57e9732cc --- /dev/null +++ b/uitest/src/com/vaadin/tests/push/PushConfigurationTest.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 PushConfigurationTest extends AbstractTestUI { + + private ObjectProperty counter = new ObjectProperty(0); + + private ObjectProperty counter2 = new ObjectProperty(0); + + private final Timer timer = new Timer(true); + + private final TimerTask task = new TimerTask() { + + @Override + public void run() { + access(new Runnable() { + @Override + public void run() { + counter2.setValue(counter2.getValue() + 1); + } + }); + } + }; + + @Override + protected void setup(VaadinRequest request) { + addComponent(new PushConfigurator(this)); + 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 1s 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("
", ContentMode.HTML)); + } + + @Override + public void attach() { + super.attach(); + timer.scheduleAtFixedRate(task, new Date(), 1000); + } + + @Override + public void detach() { + super.detach(); + timer.cancel(); + } +} diff --git a/uitest/src/com/vaadin/tests/push/PushConfigurator.java b/uitest/src/com/vaadin/tests/push/PushConfigurator.java new file mode 100644 index 0000000000..6528366b59 --- /dev/null +++ b/uitest/src/com/vaadin/tests/push/PushConfigurator.java @@ -0,0 +1,152 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +/** + * + */ +package com.vaadin.tests.push; + +import java.util.ArrayList; +import java.util.Collections; + +import com.vaadin.data.Property.ValueChangeEvent; +import com.vaadin.data.Property.ValueChangeListener; +import com.vaadin.shared.communication.PushMode; +import com.vaadin.shared.ui.label.ContentMode; +import com.vaadin.shared.ui.ui.Transport; +import com.vaadin.ui.Alignment; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Button.ClickListener; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.Label; +import com.vaadin.ui.NativeSelect; +import com.vaadin.ui.PushConfiguration; +import com.vaadin.ui.TextField; +import com.vaadin.ui.UI; +import com.vaadin.ui.VerticalLayout; + +/** + * + * @since 7.1 + * @author Vaadin Ltd + */ +public class PushConfigurator extends VerticalLayout { + private NativeSelect pushMode = new NativeSelect("Push mode"); + private NativeSelect transport = new NativeSelect("Transport"); + private NativeSelect fallbackTransport = new NativeSelect("Fallback"); + private TextField parameter = new TextField("Parameter"); + private TextField value = new TextField("Value"); + private Button set = new Button("Set"); + private HorizontalLayout paramValue = new HorizontalLayout(); + private VerticalLayout vl = new VerticalLayout(); + private UI ui; + + private Label status = new Label("", ContentMode.PREFORMATTED); + + public PushConfigurator(UI ui) { + this.ui = ui; + construct(); + refreshStatus(); + } + + /** + * @since + */ + private void refreshStatus() { + PushConfiguration pc = ui.getPushConfiguration(); + String value = ""; + ArrayList names = new ArrayList(); + names.addAll(pc.getParameterNames()); + Collections.sort(names); + for (String param : names) { + value += param + ": " + pc.getParameter(param) + "\n"; + } + status.setValue(value); + } + + /** + * @since + */ + private void construct() { + pushMode.addItem(PushMode.DISABLED); + pushMode.addItem(PushMode.MANUAL); + pushMode.addItem(PushMode.AUTOMATIC); + + for (Transport t : Transport.values()) { + transport.addItem(t.toString()); + fallbackTransport.addItem(t.toString()); + } + transport.addItem(""); + fallbackTransport.addItem(""); + + pushMode.setImmediate(true); + transport.setImmediate(true); + fallbackTransport.setImmediate(true); + + listeners(); + + paramValue.setDefaultComponentAlignment(Alignment.BOTTOM_RIGHT); + paramValue.addComponents(parameter, value, set); + vl.addComponents(pushMode, transport, fallbackTransport, paramValue, + new Label("
", ContentMode.HTML), status); + addComponent(vl); + + } + + /** + * @since + */ + private void listeners() { + pushMode.addValueChangeListener(new ValueChangeListener() { + @Override + public void valueChange(ValueChangeEvent event) { + ui.getPushConfiguration().setPushMode( + (PushMode) pushMode.getValue()); + refreshStatus(); + } + }); + + transport.addValueChangeListener(new ValueChangeListener() { + @Override + public void valueChange(ValueChangeEvent event) { + Transport t = Transport.valueOf((String) transport.getValue()); + ui.getPushConfiguration().setTransport(t); + refreshStatus(); + } + }); + + fallbackTransport.addValueChangeListener(new ValueChangeListener() { + @Override + public void valueChange(ValueChangeEvent event) { + Transport t = Transport.valueOf((String) fallbackTransport + .getValue()); + ui.getPushConfiguration().setFallbackTransport(t); + refreshStatus(); + } + }); + + set.addClickListener(new ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + ui.getPushConfiguration().setParameter(parameter.getValue(), + value.getValue()); + refreshStatus(); + } + }); + + } +} diff --git a/uitest/src/com/vaadin/tests/push/TogglePush.java b/uitest/src/com/vaadin/tests/push/TogglePush.java index 37687260dd..c0bdc54ee0 100644 --- a/uitest/src/com/vaadin/tests/push/TogglePush.java +++ b/uitest/src/com/vaadin/tests/push/TogglePush.java @@ -22,19 +22,22 @@ public class TogglePush extends AbstractTestUI { updateCounter(); addComponent(counterLabel); - setPushMode("disabled".equals(request.getParameter("push")) ? PushMode.DISABLED - : PushMode.AUTOMATIC); + getPushConfiguration() + .setPushMode( + "disabled".equals(request.getParameter("push")) ? PushMode.DISABLED + : PushMode.AUTOMATIC); CheckBox pushSetting = new CheckBox("Push enabled"); - pushSetting.setValue(Boolean.valueOf(getPushMode().isEnabled())); + pushSetting.setValue(Boolean.valueOf(getPushConfiguration() + .getPushMode().isEnabled())); pushSetting.setImmediate(true); pushSetting.addValueChangeListener(new ValueChangeListener() { @Override public void valueChange(ValueChangeEvent event) { if (event.getProperty().getValue() == Boolean.TRUE) { - setPushMode(PushMode.AUTOMATIC); + getPushConfiguration().setPushMode(PushMode.AUTOMATIC); } else { - setPushMode(PushMode.DISABLED); + getPushConfiguration().setPushMode(PushMode.DISABLED); } } }); diff --git a/uitest/src/com/vaadin/tests/widgetset/client/TestingPushConnection.java b/uitest/src/com/vaadin/tests/widgetset/client/TestingPushConnection.java index e255a5f95a..4dae8892e7 100644 --- a/uitest/src/com/vaadin/tests/widgetset/client/TestingPushConnection.java +++ b/uitest/src/com/vaadin/tests/widgetset/client/TestingPushConnection.java @@ -4,6 +4,7 @@ import com.google.gwt.user.client.Window; import com.vaadin.client.ApplicationConnection; import com.vaadin.client.ApplicationConnection.CommunicationErrorHandler; import com.vaadin.client.communication.AtmospherePushConnection; +import com.vaadin.shared.ui.ui.UIState.PushConfigurationState; public class TestingPushConnection extends AtmospherePushConnection { @@ -11,8 +12,9 @@ public class TestingPushConnection extends AtmospherePushConnection { @Override public void init(ApplicationConnection connection, + PushConfigurationState pushConfiguration, CommunicationErrorHandler errorHandler) { - super.init(connection, errorHandler); + super.init(connection, pushConfiguration, errorHandler); transport = Window.Location.getParameter("transport"); } -- cgit v1.2.3