summaryrefslogtreecommitdiffstats
path: root/uitest
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2015-04-29 00:18:27 +0300
committerArtur Signell <artur@vaadin.com>2015-07-13 17:35:49 +0300
commite76a31f9a64bf2498f77cda85475da7db287c130 (patch)
treea1040afe7a41238c669632816063f6bc61c1d0e4 /uitest
parent6fe79a8f65f96c08946c36607428c8c5790c1f33 (diff)
downloadvaadin-framework-e76a31f9a64bf2498f77cda85475da7db287c130.tar.gz
vaadin-framework-e76a31f9a64bf2498f77cda85475da7db287c130.zip
Make response code test UI specific instead of global
Change-Id: Ia44ee5f18404253d5ad986a6a6007aeb466b63fc
Diffstat (limited to 'uitest')
-rw-r--r--uitest/src/com/vaadin/tests/application/CommErrorEmulatorServlet.java143
-rw-r--r--uitest/src/com/vaadin/tests/application/CommErrorEmulatorUI.java7
2 files changed, 98 insertions, 52 deletions
diff --git a/uitest/src/com/vaadin/tests/application/CommErrorEmulatorServlet.java b/uitest/src/com/vaadin/tests/application/CommErrorEmulatorServlet.java
index 06df6f9b55..116ef1c1f2 100644
--- a/uitest/src/com/vaadin/tests/application/CommErrorEmulatorServlet.java
+++ b/uitest/src/com/vaadin/tests/application/CommErrorEmulatorServlet.java
@@ -16,32 +16,101 @@
package com.vaadin.tests.application;
import java.io.IOException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import com.vaadin.server.ServletPortletHelper;
+import com.vaadin.server.DeploymentConfiguration;
+import com.vaadin.server.RequestHandler;
+import com.vaadin.server.ServiceException;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.server.VaadinResponse;
import com.vaadin.server.VaadinServlet;
-import com.vaadin.server.VaadinServletRequest;
+import com.vaadin.server.VaadinServletService;
+import com.vaadin.server.VaadinSession;
+import com.vaadin.server.communication.HeartbeatHandler;
+import com.vaadin.server.communication.UidlRequestHandler;
+import com.vaadin.ui.UI;
-/**
- *
- * @since
- * @author Vaadin Ltd
- */
public class CommErrorEmulatorServlet extends VaadinServlet {
- private volatile Integer uidlResponseCode;
- private volatile Integer heartbeatResponseCode;
+ private Map<UI, Integer> uidlResponseCode = Collections
+ .synchronizedMap(new HashMap<UI, Integer>());
+ private Map<UI, Integer> heartbeatResponseCode = Collections
+ .synchronizedMap(new HashMap<UI, Integer>());
- public void setUIDLResponseCode(int responseCode, final int delay) {
- uidlResponseCode = responseCode;
- System.out.println("Responding with " + uidlResponseCode
- + " to UIDL requests for " + delay + "s");
+ private final CommErrorUIDLRequestHandler uidlHandler = new CommErrorUIDLRequestHandler();
+ private final CommErrorHeartbeatHandler heartbeatHandler = new CommErrorHeartbeatHandler();
- new Thread(new Runnable() {
+ public class CommErrorUIDLRequestHandler extends UidlRequestHandler {
+ @Override
+ public boolean synchronizedHandleRequest(VaadinSession session,
+ VaadinRequest request, VaadinResponse response)
+ throws IOException {
+ UI ui = session.getService().findUI(request);
+ if (ui != null && uidlResponseCode.containsKey(ui)) {
+ response.sendError(uidlResponseCode.get(ui), "Error set in UI");
+ return true;
+ }
+
+ return super.synchronizedHandleRequest(session, request, response);
+ }
+ }
+
+ public class CommErrorHeartbeatHandler extends HeartbeatHandler {
+ @Override
+ public boolean synchronizedHandleRequest(VaadinSession session,
+ VaadinRequest request, VaadinResponse response)
+ throws IOException {
+ UI ui = session.getService().findUI(request);
+ if (ui != null && heartbeatResponseCode.containsKey(ui)) {
+ response.sendError(heartbeatResponseCode.get(ui),
+ "Error set in UI");
+ return true;
+ }
+
+ return super.synchronizedHandleRequest(session, request, response);
+ }
+
+ }
+
+ public class CommErrorEmulatorService extends VaadinServletService {
+
+ public CommErrorEmulatorService(VaadinServlet servlet,
+ DeploymentConfiguration deploymentConfiguration)
+ throws ServiceException {
+ super(servlet, deploymentConfiguration);
+ }
+ @Override
+ protected List<RequestHandler> createRequestHandlers()
+ throws ServiceException {
+ List<RequestHandler> handlers = super.createRequestHandlers();
+ handlers.add(uidlHandler);
+ handlers.add(heartbeatHandler);
+ return handlers;
+ }
+ }
+
+ @Override
+ protected VaadinServletService createServletService(
+ DeploymentConfiguration deploymentConfiguration)
+ throws ServiceException {
+ CommErrorEmulatorService s = new CommErrorEmulatorService(this,
+ deploymentConfiguration);
+ s.init();
+ return s;
+ }
+
+ public void setUIDLResponseCode(final UI ui, int responseCode,
+ final int delay) {
+ uidlResponseCode.put(ui, responseCode);
+ System.out.println("Responding with " + responseCode
+ + " to UIDL requests for " + ui + " for the next " + delay
+ + "s");
+
+ new Thread(new Runnable() {
@Override
public void run() {
try {
@@ -51,16 +120,18 @@ public class CommErrorEmulatorServlet extends VaadinServlet {
}
System.out.println("Handing UIDL requests normally again");
- uidlResponseCode = null;
+ uidlResponseCode.remove(ui);
}
}).start();
}
- public void setHeartbeatResponseCode(int responseCode, final int delay) {
- heartbeatResponseCode = responseCode;
+ public void setHeartbeatResponseCode(final UI ui, int responseCode,
+ final int delay) {
+ heartbeatResponseCode.put(ui, responseCode);
System.out.println("Responding with " + responseCode
- + " to heartbeat requests for " + delay + "s");
+ + " to heartbeat requests for " + ui + " for the next " + delay
+ + "s");
new Thread(new Runnable() {
@@ -72,35 +143,9 @@ public class CommErrorEmulatorServlet extends VaadinServlet {
e.printStackTrace();
}
System.out.println("Handing heartbeat requests normally again");
- heartbeatResponseCode = null;
+ heartbeatResponseCode.remove(ui);
}
}).start();
}
- /*
- * (non-Javadoc)
- *
- * @see
- * com.vaadin.server.VaadinServlet#service(javax.servlet.http.HttpServletRequest
- * , javax.servlet.http.HttpServletResponse)
- */
- @Override
- protected void service(HttpServletRequest request,
- HttpServletResponse response) throws ServletException, IOException {
- VaadinServletRequest vaadinRequest = createVaadinRequest(request);
- if (ServletPortletHelper.isUIDLRequest(vaadinRequest)) {
- if (uidlResponseCode != null) {
- response.sendError(uidlResponseCode, "Error set in UI");
- return;
- }
- }
- if (ServletPortletHelper.isHeartbeatRequest(vaadinRequest)) {
- if (heartbeatResponseCode != null) {
- response.sendError(heartbeatResponseCode, "Error set in UI");
- return;
- }
- }
- super.service(request, response);
- }
-
}
diff --git a/uitest/src/com/vaadin/tests/application/CommErrorEmulatorUI.java b/uitest/src/com/vaadin/tests/application/CommErrorEmulatorUI.java
index 9649b346b6..6e879d2a9b 100644
--- a/uitest/src/com/vaadin/tests/application/CommErrorEmulatorUI.java
+++ b/uitest/src/com/vaadin/tests/application/CommErrorEmulatorUI.java
@@ -108,8 +108,8 @@ public class CommErrorEmulatorUI extends AbstractTestUIWithLog {
@Override
public void buttonClick(ClickEvent event) {
if (uidlResponse.code != null && uidlResponse.code != 200) {
- getServlet().setUIDLResponseCode(uidlResponse.code,
- uidlResponse.time);
+ getServlet().setUIDLResponseCode(CommErrorEmulatorUI.this,
+ uidlResponse.code, uidlResponse.time);
log("Responding with " + uidlResponse.code
+ " to UIDL requests for " + uidlResponse.time
+ "s");
@@ -117,7 +117,8 @@ public class CommErrorEmulatorUI extends AbstractTestUIWithLog {
if (heartbeatResponse.code != null
&& heartbeatResponse.code != 200) {
getServlet().setHeartbeatResponseCode(
- heartbeatResponse.code, heartbeatResponse.time);
+ CommErrorEmulatorUI.this, heartbeatResponse.code,
+ heartbeatResponse.time);
log("Responding with " + heartbeatResponse.code
+ " to heartbeat requests for "
+ heartbeatResponse.time + "s");