]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3755 Update com.github.kevinsawicki:http-request version to 5.2 that fix issue...
authorJulien Lancelot <julien.lancelot@gmail.com>
Fri, 7 Jun 2013 07:48:30 +0000 (09:48 +0200)
committerJulien Lancelot <julien.lancelot@gmail.com>
Fri, 7 Jun 2013 07:48:30 +0000 (09:48 +0200)
pom.xml
sonar-ws-client/src/main/java/org/sonar/wsclient/internal/HttpRequestFactory.java
sonar-ws-client/src/test/java/org/sonar/wsclient/internal/HttpRequestFactoryTest.java
sonar-ws-client/src/test/java/org/sonar/wsclient/issue/DefaultActionPlanClientTest.java
sonar-ws-client/src/test/java/org/sonar/wsclient/issue/DefaultIssueClientTest.java
sonar-ws-client/src/test/java/org/sonar/wsclient/user/DefaultUserClientTest.java

diff --git a/pom.xml b/pom.xml
index 2165236824b780feff8d2fb7b44642d50c9923b0..7c70852c560e6641e5b9edbd3d9b2cecfc9c6933 100644 (file)
--- a/pom.xml
+++ b/pom.xml
       <dependency>
         <groupId>com.github.kevinsawicki</groupId>
         <artifactId>http-request</artifactId>
-        <version>5.1</version>
+        <version>5.2</version>
       </dependency>
     </dependencies>
   </dependencyManagement>
index d022f5960b7624b11087038b23ccce5ffced4b66..a601df34efc3cfeeb348874a280ef5c9a0c26c19 100644 (file)
@@ -23,9 +23,6 @@ import com.github.kevinsawicki.http.HttpRequest;
 
 import javax.annotation.Nullable;
 
-import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
-import java.util.LinkedHashMap;
 import java.util.Map;
 
 /**
@@ -120,36 +117,15 @@ public class HttpRequestFactory {
   }
 
   public HttpRequest get(String wsUrl, Map<String, Object> queryParams) {
-    HttpRequest request = HttpRequest.get(baseUrl + wsUrl, encode(queryParams), false);
+    HttpRequest request = HttpRequest.get(baseUrl + wsUrl, queryParams, true);
     return prepare(request);
   }
 
   public HttpRequest post(String wsUrl, Map<String, Object> queryParams) {
-    HttpRequest request = HttpRequest.post(baseUrl + wsUrl, encode(queryParams), false);
+    HttpRequest request = HttpRequest.post(baseUrl + wsUrl, queryParams, true);
     return prepare(request);
   }
 
-  private static Map<String, Object> encode(Map<String, Object> queryParams){
-    Map<String, Object> newQueryParams = new LinkedHashMap<String, Object>();
-    for (Map.Entry<String, Object> entry : queryParams.entrySet()) {
-      newQueryParams.put(entry.getKey(), encode(entry.getValue()));
-    }
-    return newQueryParams;
-  }
-
-  private static String encode(Object value){
-    try {
-      if (value != null) {
-        return URLEncoder.encode(value.toString(), "UTF-8");
-      }
-      else {
-        return "";
-      }
-    } catch (UnsupportedEncodingException e) {
-      throw new IllegalStateException("Fail to encore parameter", e);
-    }
-  }
-
   private HttpRequest prepare(HttpRequest request) {
     if (proxyHost != null) {
       request.useProxy(proxyHost, proxyPort);
index 0c3151017a41132b23c9eacdaacaef2fe79d0016..0006ad7295baf496d03b6a0eeeb63a26a0be4671 100644 (file)
@@ -99,13 +99,13 @@ public class HttpRequestFactoryTest {
 
     IssueClient client = new DefaultIssueClient(requestFactory);
     client.find(IssueQuery.create().issues("ABC DE"));
-    assertThat(httpServer.requestedPath()).isEqualTo("/api/issues/search?issues=ABC+DE");
+    assertThat(httpServer.requestedPath()).isEqualTo("/api/issues/search?issues=ABC%20DE");
 
     client.find(IssueQuery.create().issues("ABC+BDE"));
     assertThat(httpServer.requestedPath()).isEqualTo("/api/issues/search?issues=ABC%2BBDE");
 
     client.find(IssueQuery.create().createdAfter(toDate("2013-01-01")));
-    assertThat(httpServer.requestedPath()).isEqualTo("/api/issues/search?createdAfter=2013-01-01T00%3A00%3A00%2B0100");
+    assertThat(httpServer.requestedPath()).isEqualTo("/api/issues/search?createdAfter=2013-01-01T00:00:00%2B0100");
   }
 
   protected static Date toDate(String sDate) {
index 1bddcc0bc1acea37f1325f249db2b370566dd9f2..e56572fc2b10550ff1ede996844a3e3748ec687d 100644 (file)
@@ -42,20 +42,20 @@ public class DefaultActionPlanClientTest {
   public void should_find_action_plans() {
     HttpRequestFactory requestFactory = new HttpRequestFactory(httpServer.url());
     httpServer.doReturnBody("{\"actionPlans\": [{\"key\": \"382f6f2e-ad9d-424a-b973-9b065e04348a\",\n" +
-                              "\"name\": \"Long term\",\n" +
-                              "\"status\": \"CLOSED\",\n" +
-                              "\"project\": \"com.sonarsource.it.samples:simple-sample\",\n" +
-                              "\"userLogin\": \"admin\",\n" +
-                              "\"deadLine\": \"2013-05-30T00:00:00+0200\",\n" +
-                              "\"totalIssues\": 3,\n" +
-                              "\"unresolvedIssues\": 2,\n" +
-                              "\"createdAt\": \"2013-05-13T12:50:29+0200\",\n" +
-                              "\"updatedAt\": \"2013-05-13T12:50:44+0200\"}]}");
+      "\"name\": \"Long term\",\n" +
+      "\"status\": \"CLOSED\",\n" +
+      "\"project\": \"com.sonarsource.it.samples:simple-sample\",\n" +
+      "\"userLogin\": \"admin\",\n" +
+      "\"deadLine\": \"2013-05-30T00:00:00+0200\",\n" +
+      "\"totalIssues\": 3,\n" +
+      "\"unresolvedIssues\": 2,\n" +
+      "\"createdAt\": \"2013-05-13T12:50:29+0200\",\n" +
+      "\"updatedAt\": \"2013-05-13T12:50:44+0200\"}]}");
 
     ActionPlanClient client = new DefaultActionPlanClient(requestFactory);
     List<ActionPlan> actionPlans = client.find("com.sonarsource.it.samples:simple-sample");
 
-    assertThat(httpServer.requestedPath()).isEqualTo("/api/action_plans/search?project=com.sonarsource.it.samples%3Asimple-sample");
+    assertThat(httpServer.requestedPath()).isEqualTo("/api/action_plans/search?project=com.sonarsource.it.samples:simple-sample");
     assertThat(actionPlans).hasSize(1);
     ActionPlan actionPlan = actionPlans.get(0);
     assertThat(actionPlan.key()).isEqualTo("382f6f2e-ad9d-424a-b973-9b065e04348a");
@@ -79,7 +79,7 @@ public class DefaultActionPlanClientTest {
     ActionPlan result = client.create(
       NewActionPlan.create().name("Short term").project("org.sonar.Sample").description("Short term issues").deadLine(stringToDate("2014-01-01")));
 
-    assertThat(httpServer.requestedPath()).isEqualTo("/api/action_plans/create?project=org.sonar.Sample&description=Short+term+issues&name=Short+term&deadLine=2014-01-01");
+    assertThat(httpServer.requestedPath()).isEqualTo("/api/action_plans/create?project=org.sonar.Sample&description=Short%20term%20issues&name=Short%20term&deadLine=2014-01-01");
     assertThat(result).isNotNull();
   }
 
@@ -92,7 +92,7 @@ public class DefaultActionPlanClientTest {
     ActionPlan result = client.update(
       UpdateActionPlan.create().key("382f6f2e-ad9d-424a-b973-9b065e04348a").name("Short term").description("Short term issues").deadLine(stringToDate("2014-01-01")));
 
-    assertThat(httpServer.requestedPath()).isEqualTo("/api/action_plans/update?description=Short+term+issues&name=Short+term&deadLine=2014-01-01&key=382f6f2e-ad9d-424a-b973-9b065e04348a");
+    assertThat(httpServer.requestedPath()).isEqualTo("/api/action_plans/update?description=Short%20term%20issues&name=Short%20term&deadLine=2014-01-01&key=382f6f2e-ad9d-424a-b973-9b065e04348a");
     assertThat(result).isNotNull();
   }
 
index 90d4229680e99a86660979cfe7049da30ddf5f93..7ad6f6df3c836f20153f960409500bd864619853 100644 (file)
@@ -130,7 +130,7 @@ public class DefaultIssueClientTest {
     IssueClient client = new DefaultIssueClient(requestFactory);
     Issue result = client.create(NewIssue.create().component("Action.java").rule("squid:AvoidCycle"));
 
-    assertThat(httpServer.requestedPath()).isEqualTo("/api/issues/create?component=Action.java&rule=squid%3AAvoidCycle");
+    assertThat(httpServer.requestedPath()).isEqualTo("/api/issues/create?component=Action.java&rule=squid:AvoidCycle");
     assertThat(result).isNotNull();
   }
 
@@ -172,7 +172,7 @@ public class DefaultIssueClientTest {
     IssueClient client = new DefaultIssueClient(requestFactory);
     IssueComment comment = client.addComment("ISSUE-1", "this is my comment");
 
-    assertThat(httpServer.requestedPath()).isEqualTo("/api/issues/add_comment?issue=ISSUE-1&text=this+is+my+comment");
+    assertThat(httpServer.requestedPath()).isEqualTo("/api/issues/add_comment?issue=ISSUE-1&text=this%20is%20my%20comment");
     assertThat(comment).isNotNull();
     assertThat(comment.key()).isEqualTo("COMMENT-123");
     assertThat(comment.htmlText()).isEqualTo("this is my comment");
index ca327f370ca0a442094d4cc9507ea07938d9c535..716802c6fde886c5eb7af2977b8952b9d7b68054 100644 (file)
@@ -41,7 +41,7 @@ public class DefaultUserClientTest {
     UserQuery query = UserQuery.create().logins("simon", "loic");
     List<User> users = client.find(query);
 
-    assertThat(httpServer.requestedPath()).isEqualTo("/api/users/search?logins=simon%2Cloic");
+    assertThat(httpServer.requestedPath()).isEqualTo("/api/users/search?logins=simon,loic");
     assertThat(users).hasSize(1);
     User simon = users.get(0);
     assertThat(simon.login()).isEqualTo("simon");