aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-ws-client/src/test
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2011-08-04 10:21:12 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2011-08-04 10:21:12 +0200
commitdd7b6e304adcd0365ed568833142590ebcaf7118 (patch)
tree201ab7e88e0d9c315bc0e2d6ef5ced3d1005292e /sonar-ws-client/src/test
parentb8ae0c40bc4d6dca25a745b01d1d93cbf8430264 (diff)
downloadsonarqube-dd7b6e304adcd0365ed568833142590ebcaf7118.tar.gz
sonarqube-dd7b6e304adcd0365ed568833142590ebcaf7118.zip
SONAR-2667 Keep context when Java Web Service raises exceptions
Diffstat (limited to 'sonar-ws-client/src/test')
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/BadRulesServlet.java38
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/SonarTest.java43
2 files changed, 65 insertions, 16 deletions
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/BadRulesServlet.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/BadRulesServlet.java
new file mode 100644
index 00000000000..3b01f0abe82
--- /dev/null
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/BadRulesServlet.java
@@ -0,0 +1,38 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2011 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.wsclient;
+
+import javax.servlet.GenericServlet;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import java.io.IOException;
+import java.io.PrintWriter;
+
+public class BadRulesServlet extends GenericServlet {
+
+ static final String JSON = "[{'foo': 'bar'}]";
+
+ @Override
+ public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {
+ PrintWriter out = response.getWriter();
+ out.println(JSON);
+ }
+}
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/SonarTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/SonarTest.java
index 716919076ea..13f5b8c0152 100644
--- a/sonar-ws-client/src/test/java/org/sonar/wsclient/SonarTest.java
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/SonarTest.java
@@ -19,14 +19,6 @@
*/
package org.sonar.wsclient;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.nullValue;
-import static org.hamcrest.number.OrderingComparisons.greaterThan;
-import static org.junit.Assert.assertThat;
-
-import java.util.Arrays;
-import java.util.Collection;
-
import org.junit.AfterClass;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -35,11 +27,18 @@ import org.mortbay.jetty.testing.ServletTester;
import org.sonar.wsclient.connectors.ConnectionException;
import org.sonar.wsclient.connectors.HttpClient3Connector;
import org.sonar.wsclient.connectors.HttpClient4Connector;
-import org.sonar.wsclient.services.Metric;
-import org.sonar.wsclient.services.MetricQuery;
-import org.sonar.wsclient.services.Query;
-import org.sonar.wsclient.services.Server;
-import org.sonar.wsclient.services.ServerQuery;
+import org.sonar.wsclient.services.*;
+import org.sonar.wsclient.unmarshallers.UnmarshalException;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.hamcrest.number.OrderingComparisons.greaterThan;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
+import static org.junit.internal.matchers.StringContains.containsString;
@RunWith(value = Parameterized.class)
public class SonarTest {
@@ -65,12 +64,13 @@ public class SonarTest {
tester.addServlet(ServerServlet.class, "/api/server/index");
tester.addServlet(MetricServlet.class, "/api/metrics");
tester.addServlet(EmptyServlet.class, "/api/empty");
+ tester.addServlet(BadRulesServlet.class, "/api/rules");
baseUrl = tester.createSocketConnector(true);
tester.start();
- return Arrays.asList(new Object[][] {
- { new Sonar(new HttpClient4Connector(new Host(baseUrl))) },
- { new Sonar(new HttpClient3Connector(new Host(baseUrl))) }
+ return Arrays.asList(new Object[][]{
+ {new Sonar(new HttpClient4Connector(new Host(baseUrl)))},
+ {new Sonar(new HttpClient3Connector(new Host(baseUrl)))}
});
}
@@ -111,6 +111,17 @@ public class SonarTest {
assertThat(server.getVersion(), is("2.0"));
}
+ @Test
+ public void shouldPropagateUnmarshalContext() {
+ try {
+ sonar.findAll(new RuleQuery("java"));
+ fail();
+ } catch (UnmarshalException ue) {
+ assertThat(ue.getMessage(), containsString("/api/rules")); // contains request url
+ assertThat(ue.getMessage(), containsString(BadRulesServlet.JSON)); // contains response
+ }
+ }
+
static class EmptyQuery extends Query<Metric> {
public String getUrl() {
return "/api/empty";