Skip to content

Commit

Permalink
Pass critical notification details to the client (#18342)
Browse files Browse the repository at this point in the history
Change-Id: I3c4eace624453eb854a32fef5fe44d253b164f62
  • Loading branch information
Artur- committed Jun 25, 2015
1 parent 7552e9c commit 10e7a46
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 41 deletions.
4 changes: 3 additions & 1 deletion client/src/com/vaadin/client/ApplicationConnection.java
Expand Up @@ -63,6 +63,7 @@
import com.google.gwt.user.client.ui.HasWidgets;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.ApplicationConfiguration.ErrorMessage;
import com.vaadin.client.ApplicationConnection.ApplicationStoppedEvent;
import com.vaadin.client.ResourceLoader.ResourceLoadEvent;
import com.vaadin.client.ResourceLoader.ResourceLoadListener;
import com.vaadin.client.communication.HasJavaScriptConnectorHelper;
Expand Down Expand Up @@ -1768,7 +1769,8 @@ public void run() {
if (meta.containsKey("appError")) {
ValueMap error = meta.getValueMap("appError");

showError(null, error.getString("caption"),
showError(error.getString("details"),
error.getString("caption"),
error.getString("message"),
error.getString("url"));

Expand Down
15 changes: 2 additions & 13 deletions server/src/com/vaadin/server/VaadinService.java
Expand Up @@ -1574,8 +1574,8 @@ public static String createCriticalNotificationJSON(String caption,
JsonObject appError = Json.createObject();
putValueOrJsonNull(appError, "caption", caption);
putValueOrJsonNull(appError, "url", url);
putValueOrJsonNull(appError, "message",
createCriticalNotificationMessage(message, details));
putValueOrJsonNull(appError, "message", message);
putValueOrJsonNull(appError, "details", details);

JsonObject meta = Json.createObject();
meta.put("appError", appError);
Expand All @@ -1595,17 +1595,6 @@ public static String createCriticalNotificationJSON(String caption,
return "for(;;);[" + returnString + "]";
}

private static String createCriticalNotificationMessage(String message,
String details) {
if (message == null) {
return details;
} else if (details != null) {
return message + "<br/><br/>" + details;
}

return message;
}

private static void putValueOrJsonNull(JsonObject json, String key,
String value) {
if (value == null) {
Expand Down
45 changes: 23 additions & 22 deletions server/tests/src/com/vaadin/server/VaadinServiceTest.java
Expand Up @@ -42,9 +42,10 @@ public void sessionDestroy(SessionDestroyEvent event) {
}
}

private String createCriticalNotification(String caption, String message, String details, String url) {
return VaadinService
.createCriticalNotificationJSON(caption, message, details, url);
private String createCriticalNotification(String caption, String message,
String details, String url) {
return VaadinService.createCriticalNotificationJSON(caption, message,
details, url);
}

@Test
Expand Down Expand Up @@ -77,64 +78,64 @@ public void testFireSessionDestroy() throws ServletException {

@Test
public void captionIsSetToACriticalNotification() {
String notification =
createCriticalNotification("foobar", "message", "details", "url");
String notification = createCriticalNotification("foobar", "message",
"details", "url");

assertThat(notification, containsString("\"caption\":\"foobar\""));
}

@Test
public void nullCaptionIsSetToACriticalNotification() {
String notification =
createCriticalNotification(null, "message", "details", "url");
String notification = createCriticalNotification(null, "message",
"details", "url");

assertThat(notification, containsString("\"caption\":null"));
}

@Test
public void messageWithDetailsIsSetToACriticalNotification() {
String notification =
createCriticalNotification("caption", "foo", "bar", "url");
String notification = createCriticalNotification("caption", "foo",
"bar", "url");

assertThat(notification, containsString("\"message\":\"foo<br/><br/>bar\""));
assertThat(notification, containsString("\"details\":\"bar\""));
}

@Test
public void nullMessageIsReplacedByDetailsInACriticalNotification() {
String notification =
createCriticalNotification("caption", null, "foobar", "url");
public void nullMessageSentAsNullInACriticalNotification() {
String notification = createCriticalNotification("caption", null,
"foobar", "url");

assertThat(notification, containsString("\"message\":\"foobar\""));
assertThat(notification, containsString("\"message\":null"));
}

@Test
public void nullMessageIsSetToACriticalNotification() {
String notification =
createCriticalNotification("caption", null, null, "url");
String notification = createCriticalNotification("caption", null, null,
"url");

assertThat(notification, containsString("\"message\":null"));
}

@Test
public void messageSetToACriticalNotification() {
String notification =
createCriticalNotification("caption", "foobar", null, "url");
String notification = createCriticalNotification("caption", "foobar",
null, "url");

assertThat(notification, containsString("\"message\":\"foobar\""));
}

@Test
public void urlIsSetToACriticalNotification() {
String notification =
createCriticalNotification("caption", "message", "details", "foobar");
String notification = createCriticalNotification("caption", "message",
"details", "foobar");

assertThat(notification, containsString("\"url\":\"foobar\""));
}

@Test
public void nullUrlIsSetToACriticalNotification() {
String notification =
createCriticalNotification("caption", "message", "details", null);
String notification = createCriticalNotification("caption", "message",
"details", null);

assertThat(notification, containsString("\"url\":null"));
}
Expand Down
28 changes: 23 additions & 5 deletions uitest/src/com/vaadin/tests/application/CriticalNotifications.java
Expand Up @@ -26,24 +26,30 @@
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.CheckBox;

public class CriticalNotifications extends AbstractTestUI {

private SystemMessages systemMessages;
private CheckBox includeDetails;

@Override
protected void setup(VaadinRequest request) {
systemMessages = VaadinService.getCurrent().getSystemMessages(
getLocale(), request);

includeDetails = new CheckBox("Include details");
addComponent(includeDetails);

Button sessionExpired = new Button("Session expired");
addComponent(sessionExpired);
sessionExpired.addClickListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
showCriticalNotification(
systemMessages.getSessionExpiredCaption(),
systemMessages.getSessionExpiredMessage(), null,
systemMessages.getSessionExpiredMessage(),
getDetailsMessage(),
systemMessages.getSessionExpiredURL());

}
Expand All @@ -56,7 +62,8 @@ public void buttonClick(ClickEvent event) {
public void buttonClick(ClickEvent event) {
showCriticalNotification(
systemMessages.getAuthenticationErrorCaption(),
systemMessages.getAuthenticationErrorMessage(), null,
systemMessages.getAuthenticationErrorMessage(),
getDetailsMessage(),
systemMessages.getAuthenticationErrorURL());

}
Expand All @@ -69,7 +76,8 @@ public void buttonClick(ClickEvent event) {
public void buttonClick(ClickEvent event) {
showCriticalNotification(
systemMessages.getCommunicationErrorCaption(),
systemMessages.getCommunicationErrorMessage(), null,
systemMessages.getCommunicationErrorMessage(),
getDetailsMessage(),
systemMessages.getCommunicationErrorURL());

}
Expand All @@ -82,7 +90,8 @@ public void buttonClick(ClickEvent event) {
public void buttonClick(ClickEvent event) {
showCriticalNotification(
systemMessages.getInternalErrorCaption(),
systemMessages.getInternalErrorMessage(), null,
systemMessages.getInternalErrorMessage(),
getDetailsMessage(),
systemMessages.getInternalErrorURL());

}
Expand All @@ -95,7 +104,8 @@ public void buttonClick(ClickEvent event) {
public void buttonClick(ClickEvent event) {
showCriticalNotification(
systemMessages.getCookiesDisabledCaption(),
systemMessages.getCookiesDisabledMessage(), null,
systemMessages.getCookiesDisabledMessage(),
getDetailsMessage(),
systemMessages.getCookiesDisabledURL());

}
Expand All @@ -112,6 +122,14 @@ public void buttonClick(ClickEvent event) {
});
}

protected String getDetailsMessage() {
if (includeDetails.getValue()) {
return "Some details for the error";
} else {
return null;
}
}

protected void showCriticalNotification(String caption, String message,
String details, String url) {
VaadinService service = VaadinService.getCurrent();
Expand Down

0 comments on commit 10e7a46

Please sign in to comment.