summaryrefslogtreecommitdiffstats
path: root/uitest/src/com/vaadin
diff options
context:
space:
mode:
Diffstat (limited to 'uitest/src/com/vaadin')
-rw-r--r--uitest/src/com/vaadin/tests/appengine/GAESyncTest.java4
-rw-r--r--uitest/src/com/vaadin/tests/application/TerminalErrorNotification.java2
-rw-r--r--uitest/src/com/vaadin/tests/components/AbstractComponentTest.java2
-rw-r--r--uitest/src/com/vaadin/tests/components/abstractfield/TextFieldConversions.java9
-rw-r--r--uitest/src/com/vaadin/tests/components/button/ShortCutListenerModification.java4
-rw-r--r--uitest/src/com/vaadin/tests/errorhandler/ErrorHandlers.java134
6 files changed, 144 insertions, 11 deletions
diff --git a/uitest/src/com/vaadin/tests/appengine/GAESyncTest.java b/uitest/src/com/vaadin/tests/appengine/GAESyncTest.java
index f5d90bae79..146e85f5f3 100644
--- a/uitest/src/com/vaadin/tests/appengine/GAESyncTest.java
+++ b/uitest/src/com/vaadin/tests/appengine/GAESyncTest.java
@@ -29,7 +29,7 @@ public class GAESyncTest extends LegacyApplication {
}
@Override
- public void terminalError(com.vaadin.server.ErrorEvent event) {
+ public void error(com.vaadin.server.ErrorEvent event) {
Throwable t = event.getThrowable();
// Was this caused by a GAE timeout?
while (t != null) {
@@ -41,7 +41,7 @@ public class GAESyncTest extends LegacyApplication {
t = t.getCause();
}
- super.terminalError(event);
+ super.error(event);
}
diff --git a/uitest/src/com/vaadin/tests/application/TerminalErrorNotification.java b/uitest/src/com/vaadin/tests/application/TerminalErrorNotification.java
index 9dee2fe0b6..2c8d7e01af 100644
--- a/uitest/src/com/vaadin/tests/application/TerminalErrorNotification.java
+++ b/uitest/src/com/vaadin/tests/application/TerminalErrorNotification.java
@@ -38,7 +38,7 @@ public class TerminalErrorNotification extends TestBase {
}
@Override
- public void terminalError(com.vaadin.server.ErrorEvent event) {
+ public void error(com.vaadin.server.ErrorEvent event) {
event.getThrowable().printStackTrace();
UI mainWindow = getMainWindow();
diff --git a/uitest/src/com/vaadin/tests/components/AbstractComponentTest.java b/uitest/src/com/vaadin/tests/components/AbstractComponentTest.java
index f36437326a..c086e03ae0 100644
--- a/uitest/src/com/vaadin/tests/components/AbstractComponentTest.java
+++ b/uitest/src/com/vaadin/tests/components/AbstractComponentTest.java
@@ -715,7 +715,7 @@ public abstract class AbstractComponentTest<T extends AbstractComponent>
}
@Override
- public void terminalError(com.vaadin.server.ErrorEvent event) {
+ public void error(com.vaadin.server.ErrorEvent event) {
String logMsg = "Exception occured, "
+ event.getThrowable().getClass().getName();
diff --git a/uitest/src/com/vaadin/tests/components/abstractfield/TextFieldConversions.java b/uitest/src/com/vaadin/tests/components/abstractfield/TextFieldConversions.java
index 3a8275bd51..888922b69d 100644
--- a/uitest/src/com/vaadin/tests/components/abstractfield/TextFieldConversions.java
+++ b/uitest/src/com/vaadin/tests/components/abstractfield/TextFieldConversions.java
@@ -5,9 +5,9 @@ import java.util.Date;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.Property.ValueChangeListener;
import com.vaadin.data.util.ObjectProperty;
+import com.vaadin.server.ErrorEvent;
+import com.vaadin.server.ErrorHandler;
import com.vaadin.server.UserError;
-import com.vaadin.ui.AbstractComponent.ComponentErrorEvent;
-import com.vaadin.ui.AbstractComponent.ComponentErrorHandler;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.TextField;
@@ -41,12 +41,11 @@ public class TextFieldConversions extends AbstractComponentDataBindingTest {
tf = new TextField("TextField");
addComponent(tf);
- tf.setErrorHandler(new ComponentErrorHandler() {
+ tf.setErrorHandler(new ErrorHandler() {
@Override
- public boolean handleComponentError(ComponentErrorEvent event) {
+ public void error(ErrorEvent event) {
tf.setComponentError(new UserError("Invalid value"));
- return true;
}
});
}
diff --git a/uitest/src/com/vaadin/tests/components/button/ShortCutListenerModification.java b/uitest/src/com/vaadin/tests/components/button/ShortCutListenerModification.java
index 51ca47b4b7..9cdd803fe0 100644
--- a/uitest/src/com/vaadin/tests/components/button/ShortCutListenerModification.java
+++ b/uitest/src/com/vaadin/tests/components/button/ShortCutListenerModification.java
@@ -57,8 +57,8 @@ public class ShortCutListenerModification extends TestBase implements
}
@Override
- public void terminalError(com.vaadin.server.ErrorEvent event) {
- super.terminalError(event);
+ public void error(com.vaadin.server.ErrorEvent event) {
+ super.error(event);
getMainWindow().showNotification("Failed!",
Notification.TYPE_ERROR_MESSAGE);
diff --git a/uitest/src/com/vaadin/tests/errorhandler/ErrorHandlers.java b/uitest/src/com/vaadin/tests/errorhandler/ErrorHandlers.java
new file mode 100644
index 0000000000..c5ff1be1ed
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/errorhandler/ErrorHandlers.java
@@ -0,0 +1,134 @@
+package com.vaadin.tests.errorhandler;
+
+import java.lang.reflect.InvocationTargetException;
+
+import com.vaadin.event.ListenerMethod.MethodException;
+import com.vaadin.server.DefaultErrorHandler;
+import com.vaadin.server.ErrorHandler;
+import com.vaadin.server.RpcManager.RpcInvocationException;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Button.ClickListener;
+import com.vaadin.ui.Component;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.Notification;
+import com.vaadin.ui.Notification.Type;
+import com.vaadin.ui.VerticalLayout;
+
+public class ErrorHandlers extends AbstractTestUI {
+
+ public static class NotificationErrorHandler implements ErrorHandler {
+
+ @Override
+ public void error(com.vaadin.server.ErrorEvent event) {
+ Notification.show(getErrorMessage(event), Type.ERROR_MESSAGE);
+ }
+
+ }
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ addComponent(runtimeExceptionOnClick(new Button("Standard button")));
+ addComponent(npeOnClick(new Button("Standard button with NPE")));
+ Button customErrorButton = notificationErrorHandler(new Button(
+ "Button with notification error handler"));
+ addComponent(runtimeExceptionOnClick(customErrorButton));
+
+ final VerticalLayout layoutWithErrorHandler = new VerticalLayout(
+ runtimeExceptionOnClick(new Button("Error handler on parent")));
+ ErrorHandler e = new ErrorHandler() {
+
+ @Override
+ public void error(com.vaadin.server.ErrorEvent event) {
+ layoutWithErrorHandler.addComponent(new Label("Layout error: "
+ + getErrorMessage(event)));
+ }
+
+ };
+ layoutWithErrorHandler.setErrorHandler(e);
+ layoutWithErrorHandler
+ .addComponent(notificationErrorHandler(npeOnClick(new Button(
+ "Error handler on button and parent"))));
+ addComponent(layoutWithErrorHandler);
+ }
+
+ private Button notificationErrorHandler(Button button) {
+ button.setErrorHandler(new NotificationErrorHandler());
+ return button;
+ }
+
+ protected static String getErrorMessage(com.vaadin.server.ErrorEvent event) {
+ Component c = DefaultErrorHandler.findAbstractComponent(event);
+ String errorMsg = "Error: '" + getMessage(event) + "' in ";
+ errorMsg += c.getClass().getSimpleName() + " with caption '"
+ + c.getCaption() + "'";
+ return errorMsg;
+ }
+
+ private static String getMessage(com.vaadin.server.ErrorEvent event) {
+ Throwable e = getUserCodeException(event);
+ if (e.getMessage() != null) {
+ return e.getMessage();
+ } else {
+ return e.getClass().getSimpleName();
+ }
+ }
+
+ private static Throwable getUserCodeException(
+ com.vaadin.server.ErrorEvent event) {
+ Throwable t = event.getThrowable();
+ if (t instanceof RpcInvocationException) {
+ t = t.getCause();
+ }
+ if (t instanceof InvocationTargetException) {
+ t = t.getCause();
+ }
+ if (t instanceof MethodException) {
+ t = t.getCause();
+ }
+
+ return t;
+
+ }
+
+ private Button runtimeExceptionOnClick(Button customErrorButton) {
+ customErrorButton.setCaption("RE: " + customErrorButton.getCaption());
+
+ customErrorButton.addClickListener(new ClickListener() {
+
+ @Override
+ public void buttonClick(ClickEvent event) {
+ throw new RuntimeException("Fail in click event");
+ }
+ });
+ return customErrorButton;
+ }
+
+ private Button npeOnClick(Button customErrorButton) {
+ customErrorButton.setCaption("NPE: " + customErrorButton.getCaption());
+ customErrorButton.addClickListener(new ClickListener() {
+
+ @Override
+ public void buttonClick(ClickEvent event) {
+ Integer i = null;
+ i += 2;
+ }
+ });
+ return customErrorButton;
+ }
+
+ @Override
+ protected String getTestDescription() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}