summaryrefslogtreecommitdiffstats
path: root/sonar-ws
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2016-02-04 17:58:07 +0100
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2016-02-05 11:25:44 +0100
commite10c6ffc024ab79b1c188378726bb5da60ee2fec (patch)
treee3b89aa261e732bf3be5be23de2ffd6be38a59da /sonar-ws
parent9257a9559ecbe38f15a1901b9d8aed1b104d1ae3 (diff)
downloadsonarqube-e10c6ffc024ab79b1c188378726bb5da60ee2fec.tar.gz
sonarqube-e10c6ffc024ab79b1c188378726bb5da60ee2fec.zip
SONAR-7040 Add context when failing to write a web service response
Diffstat (limited to 'sonar-ws')
-rw-r--r--sonar-ws/src/main/java/org/sonarqube/ws/MessageFormatter.java34
-rw-r--r--sonar-ws/src/test/java/org/sonarqube/ws/MessageFormatterTest.java43
2 files changed, 77 insertions, 0 deletions
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/MessageFormatter.java b/sonar-ws/src/main/java/org/sonarqube/ws/MessageFormatter.java
new file mode 100644
index 00000000000..aafc7777115
--- /dev/null
+++ b/sonar-ws/src/main/java/org/sonarqube/ws/MessageFormatter.java
@@ -0,0 +1,34 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonarqube.ws;
+
+import com.google.protobuf.MessageOrBuilder;
+import com.google.protobuf.TextFormat;
+
+public class MessageFormatter {
+ private MessageFormatter() {
+ // prevent instantiation
+ }
+
+ public static String print(MessageOrBuilder message) {
+ return String.format("%s[%s]", message.getClass().getCanonicalName(), TextFormat.shortDebugString(message));
+ }
+}
diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/MessageFormatterTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/MessageFormatterTest.java
new file mode 100644
index 00000000000..bad2eaeba4a
--- /dev/null
+++ b/sonar-ws/src/test/java/org/sonarqube/ws/MessageFormatterTest.java
@@ -0,0 +1,43 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonarqube.ws;
+
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class MessageFormatterTest {
+
+ @Test
+ public void print() {
+ WsPermissions.Permission.Builder message = WsPermissions.Permission.newBuilder()
+ .setName("permission-name")
+ .setKey("permission-key")
+ .setDescription("permission-description")
+ .setUsersCount(1984)
+ .setGroupsCount(42);
+
+ String result = MessageFormatter.print(message);
+
+ assertThat(result).isEqualTo("org.sonarqube.ws.WsPermissions.Permission.Builder" +
+ "[key: \"permission-key\" name: \"permission-name\" description: \"permission-description\" usersCount: 1984 groupsCount: 42]");
+ }
+}