]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3755 Set deadLine as Date instead of String in action plan Client
authorJulien Lancelot <julien.lancelot@gmail.com>
Wed, 5 Jun 2013 08:37:39 +0000 (10:37 +0200)
committerJulien Lancelot <julien.lancelot@gmail.com>
Wed, 5 Jun 2013 08:37:39 +0000 (10:37 +0200)
sonar-ws-client/src/main/java/org/sonar/wsclient/issue/NewActionPlan.java
sonar-ws-client/src/main/java/org/sonar/wsclient/issue/UpdateActionPlan.java
sonar-ws-client/src/test/java/org/sonar/wsclient/issue/DefaultActionPlanClientTest.java

index 4b9460f44bd06e42dec7c53ca9e3c6ac3b487eb3..74c92acbfe88e5142bfa99aa594499ea3952aa44 100644 (file)
@@ -19,6 +19,9 @@
  */
 package org.sonar.wsclient.issue;
 
+import org.sonar.wsclient.internal.EncodingUtils;
+
+import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -28,7 +31,6 @@ import java.util.Map;
 public class NewActionPlan {
 
   static final String BASE_URL = "/api/action_plans/create";
-
   private final Map<String, Object> params = new HashMap<String, Object>();
 
   private NewActionPlan() {
@@ -57,11 +59,8 @@ public class NewActionPlan {
     return this;
   }
 
-  /**
-   * Due date of the action plan. Format is 'day/month/year', for instance, '31/12/2013'.
-   */
-  public NewActionPlan deadLine(String s) {
-    params.put("deadLine", s);
+  public NewActionPlan deadLine(Date deadLine) {
+    params.put("deadLine", EncodingUtils.toQueryParam(deadLine, false));
     return this;
   }
 
index 8914e898fcef8d498685d5b176eae390fc117533..2ca316217b3589a3be8105c981ad5664ea1eb5f4 100644 (file)
@@ -19,6 +19,9 @@
  */
 package org.sonar.wsclient.issue;
 
+import org.sonar.wsclient.internal.EncodingUtils;
+
+import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -28,7 +31,6 @@ import java.util.Map;
 public class UpdateActionPlan {
 
   static final String BASE_URL = "/api/action_plans/update";
-
   private final Map<String, Object> params = new HashMap<String, Object>();
 
   private UpdateActionPlan() {
@@ -57,11 +59,8 @@ public class UpdateActionPlan {
     return this;
   }
 
-  /**
-   * Due date of the action plan. Format is 'day/month/year', for instance, '31/12/2013'.
-   */
-  public UpdateActionPlan deadLine(String s) {
-    params.put("deadLine", s);
+  public UpdateActionPlan deadLine(Date deadLine) {
+    params.put("deadLine", EncodingUtils.toQueryParam(deadLine, false));
     return this;
   }
 
index d6597c2e91817d265f4e418e16456f13019040ec..4498541a1dbe046e93a66ad2139936e6f4274b51 100644 (file)
@@ -25,6 +25,9 @@ import org.junit.Test;
 import org.sonar.wsclient.MockHttpServerInterceptor;
 import org.sonar.wsclient.internal.HttpRequestFactory;
 
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
 import java.util.List;
 
 import static org.fest.assertions.Assertions.assertThat;
@@ -68,14 +71,15 @@ public class DefaultActionPlanClientTest {
   }
 
   @Test
-  public void should_create_action_plan() {
+  public void should_create_action_plan() throws Exception {
     HttpRequestFactory requestFactory = new HttpRequestFactory(httpServer.url());
     httpServer.doReturnBody("{\"actionPlan\": {\"key\": \"382f6f2e-ad9d-424a-b973-9b065e04348a\"}}");
 
     ActionPlanClient client = new DefaultActionPlanClient(requestFactory);
-    ActionPlan result = client.create(NewActionPlan.create().name("Short term").project("org.sonar.Sample").description("Short term issues").deadLine("01/01/2014"));
+    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%20term%20issues&name=Short%20term&deadLine=01/01/2014");
+    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();
   }
 
@@ -85,9 +89,10 @@ public class DefaultActionPlanClientTest {
     httpServer.doReturnBody("{\"actionPlan\": {\"key\": \"382f6f2e-ad9d-424a-b973-9b065e04348a\"}}");
 
     ActionPlanClient client = new DefaultActionPlanClient(requestFactory);
-    ActionPlan result = client.update(UpdateActionPlan.create().key("382f6f2e-ad9d-424a-b973-9b065e04348a").name("Short term").description("Short term issues").deadLine("01/01/2014"));
+    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%20term%20issues&name=Short%20term&deadLine=01/01/2014&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();
   }
 
@@ -139,4 +144,13 @@ public class DefaultActionPlanClientTest {
     assertThat(result).isNotNull();
   }
 
+  private static Date stringToDate(String sDate) {
+    try {
+      SimpleDateFormat sdf = new SimpleDateFormat("yyyy-dd-MM");
+      return sdf.parse(sDate);
+    } catch (ParseException e) {
+      throw new RuntimeException(e);
+    }
+  }
+
 }