<dependency>
<groupId>com.github.kevinsawicki</groupId>
<artifactId>http-request</artifactId>
- <version>5.1</version>
+ <version>5.2</version>
</dependency>
</dependencies>
</dependencyManagement>
import javax.annotation.Nullable;
-import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
-import java.util.LinkedHashMap;
import java.util.Map;
/**
}
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);
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) {
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");
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();
}
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();
}
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();
}
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");
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");