summaryrefslogtreecommitdiffstats
path: root/uitest
diff options
context:
space:
mode:
Diffstat (limited to 'uitest')
-rw-r--r--uitest/src/com/vaadin/tests/applicationservlet/SystemMessages.java7
-rw-r--r--uitest/src/com/vaadin/tests/components/abstractcomponent/ResponseWritingErrorHandling.java61
-rw-r--r--uitest/src/com/vaadin/tests/components/abstractcomponent/ResponseWritingErrorHandlingTest.java35
3 files changed, 101 insertions, 2 deletions
diff --git a/uitest/src/com/vaadin/tests/applicationservlet/SystemMessages.java b/uitest/src/com/vaadin/tests/applicationservlet/SystemMessages.java
index 00547aa2d2..9912e660ef 100644
--- a/uitest/src/com/vaadin/tests/applicationservlet/SystemMessages.java
+++ b/uitest/src/com/vaadin/tests/applicationservlet/SystemMessages.java
@@ -14,13 +14,15 @@ import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.NativeSelect;
+import elemental.json.JsonObject;
+
public class SystemMessages extends AbstractTestUI {
public class MyButton extends Button {
private boolean fail = false;
@Override
- public void beforeClientResponse(boolean initial) {
+ public JsonObject encodeState() {
// Set the error message to contain the current locale.
VaadinService.getCurrentRequest().setAttribute(
ApplicationRunnerServlet.CUSTOM_SYSTEM_MESSAGES_PROPERTY,
@@ -30,9 +32,10 @@ public class SystemMessages extends AbstractTestUI {
return "MessagesInfo locale: " + getLocale();
}
});
- super.beforeClientResponse(initial);
if (fail) {
throw new RuntimeException("Failed on purpose");
+ } else {
+ return super.encodeState();
}
}
}
diff --git a/uitest/src/com/vaadin/tests/components/abstractcomponent/ResponseWritingErrorHandling.java b/uitest/src/com/vaadin/tests/components/abstractcomponent/ResponseWritingErrorHandling.java
new file mode 100644
index 0000000000..23be0f62b4
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/abstractcomponent/ResponseWritingErrorHandling.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2000-2014 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.components.abstractcomponent;
+
+import com.vaadin.server.ErrorHandler;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUIWithLog;
+import com.vaadin.ui.Button;
+
+public class ResponseWritingErrorHandling extends AbstractTestUIWithLog {
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ ErrorHandler errorHandler = new ErrorHandler() {
+ @Override
+ public void error(com.vaadin.server.ErrorEvent event) {
+ String message = event.getThrowable().getMessage();
+ log(message);
+ }
+ };
+
+ Button button = new Button("Throw in beforeClientResponse") {
+ private boolean throwInBeforeClientResponse = false;
+ {
+ addClickListener(new ClickListener() {
+ @Override
+ public void buttonClick(ClickEvent event) {
+ throwInBeforeClientResponse = true;
+ // Make sure beforeClientResponse is called
+ markAsDirty();
+ }
+ });
+ }
+
+ @Override
+ public void beforeClientResponse(boolean initial) {
+ if (throwInBeforeClientResponse) {
+ throwInBeforeClientResponse = false;
+ throw new RuntimeException("Button.beforeClientResponse");
+ }
+ }
+ };
+ button.setErrorHandler(errorHandler);
+
+ addComponent(button);
+ }
+
+}
diff --git a/uitest/src/com/vaadin/tests/components/abstractcomponent/ResponseWritingErrorHandlingTest.java b/uitest/src/com/vaadin/tests/components/abstractcomponent/ResponseWritingErrorHandlingTest.java
new file mode 100644
index 0000000000..7b939a5627
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/abstractcomponent/ResponseWritingErrorHandlingTest.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2000-2014 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.components.abstractcomponent;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.vaadin.testbench.elements.ButtonElement;
+import com.vaadin.tests.tb3.SingleBrowserTest;
+
+public class ResponseWritingErrorHandlingTest extends SingleBrowserTest {
+
+ @Test
+ public void testExceptionInBeforeClientResponse() {
+ openTestURL();
+
+ $(ButtonElement.class).first().click();
+
+ Assert.assertEquals("Message should be logged by error handler",
+ "1. Button.beforeClientResponse", getLogRow(0));
+ }
+}