aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-ws-client
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@gmail.com>2013-10-07 13:35:09 +0200
committerJulien Lancelot <julien.lancelot@gmail.com>2013-10-07 13:35:09 +0200
commiteb61eba8a4e2dead826feca34b22ca8fc5fa0ffb (patch)
tree63fb2bccde71e2134d0a99a6e1b3f2f1692f3f75 /sonar-ws-client
parenta559fa67ec15486009e7dccdb79d6f488699dbc2 (diff)
downloadsonarqube-eb61eba8a4e2dead826feca34b22ca8fc5fa0ffb.tar.gz
sonarqube-eb61eba8a4e2dead826feca34b22ca8fc5fa0ffb.zip
SONAR-4716 Replace remediation cost by technical debt in issue
Diffstat (limited to 'sonar-ws-client')
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/issue/Issue.java3
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/issue/TechnicalDebt.java31
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/issue/internal/DefaultIssue.java10
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/issue/internal/DefaultTechnicalDebt.java49
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/issue/internal/DefaultIssueClientTest.java1
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/issue/internal/IssueJsonParserTest.java16
-rw-r--r--sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/internal/IssueJsonParserTest/issue-with-technical-debt.json33
-rw-r--r--sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/internal/IssueJsonParserTest/search.json3
8 files changed, 139 insertions, 7 deletions
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/Issue.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/Issue.java
index c88a9a228e0..8f81332bb86 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/Issue.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/Issue.java
@@ -20,6 +20,7 @@
package org.sonar.wsclient.issue;
import javax.annotation.CheckForNull;
+
import java.util.Date;
import java.util.List;
import java.util.Map;
@@ -52,7 +53,7 @@ public interface Issue {
Double effortToFix();
@CheckForNull
- Long remediationCost();
+ TechnicalDebt technicalDebt();
String status();
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/TechnicalDebt.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/TechnicalDebt.java
new file mode 100644
index 00000000000..c2014b0dfe5
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/TechnicalDebt.java
@@ -0,0 +1,31 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.sonar.wsclient.issue;
+
+/**
+ * @since 4.0
+ */
+public interface TechnicalDebt {
+
+ int days();
+ int minutes();
+ int hours();
+
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/internal/DefaultIssue.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/internal/DefaultIssue.java
index 2f83632ab17..50c74c34a08 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/internal/DefaultIssue.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/internal/DefaultIssue.java
@@ -21,9 +21,11 @@ package org.sonar.wsclient.issue.internal;
import org.sonar.wsclient.issue.Issue;
import org.sonar.wsclient.issue.IssueComment;
+import org.sonar.wsclient.issue.TechnicalDebt;
import org.sonar.wsclient.unmarshallers.JsonUtils;
import javax.annotation.CheckForNull;
+
import java.util.*;
/**
@@ -76,8 +78,12 @@ public class DefaultIssue implements Issue {
}
@CheckForNull
- public Long remediationCost() {
- return JsonUtils.getLong(json, "remediationCost");
+ public TechnicalDebt technicalDebt() {
+ Map technicalDebt = (Map) json.get("technicalDebt");
+ if (technicalDebt != null) {
+ return new DefaultTechnicalDebt(technicalDebt);
+ }
+ return null;
}
public String status() {
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/internal/DefaultTechnicalDebt.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/internal/DefaultTechnicalDebt.java
new file mode 100644
index 00000000000..c82ceb13a41
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/internal/DefaultTechnicalDebt.java
@@ -0,0 +1,49 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.sonar.wsclient.issue.internal;
+
+import org.sonar.wsclient.issue.TechnicalDebt;
+import org.sonar.wsclient.unmarshallers.JsonUtils;
+
+import java.util.Map;
+
+/**
+ * @since 4.0
+ */
+public class DefaultTechnicalDebt implements TechnicalDebt {
+ private final Map json;
+
+ DefaultTechnicalDebt(Map json) {
+ this.json = json;
+ }
+
+ public int days() {
+ return JsonUtils.getInteger(json, "days");
+ }
+
+ public int hours() {
+ return JsonUtils.getInteger(json, "hours");
+ }
+
+ public int minutes() {
+ return JsonUtils.getInteger(json, "minutes");
+ }
+
+}
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/issue/internal/DefaultIssueClientTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/issue/internal/DefaultIssueClientTest.java
index 96140bd593a..b01badc4bdc 100644
--- a/sonar-ws-client/src/test/java/org/sonar/wsclient/issue/internal/DefaultIssueClientTest.java
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/issue/internal/DefaultIssueClientTest.java
@@ -34,6 +34,7 @@ import static org.fest.assertions.Fail.fail;
import static org.fest.assertions.MapAssert.entry;
public class DefaultIssueClientTest {
+
@Rule
public MockHttpServerInterceptor httpServer = new MockHttpServerInterceptor();
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/issue/internal/IssueJsonParserTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/issue/internal/IssueJsonParserTest.java
index 4e95e9dcbe0..42e517cd069 100644
--- a/sonar-ws-client/src/test/java/org/sonar/wsclient/issue/internal/IssueJsonParserTest.java
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/issue/internal/IssueJsonParserTest.java
@@ -51,7 +51,7 @@ public class IssueJsonParserTest {
assertThat(first.assignee()).isEqualTo("karadoc");
assertThat(first.message()).isEqualTo("the message");
assertThat(first.effortToFix()).isEqualTo(4.2);
- assertThat(first.remediationCost()).isEqualTo(10L);
+ assertThat(first.technicalDebt()).isNull();
assertThat(first.reporter()).isEqualTo("perceval");
assertThat(first.author()).isEqualTo("pirlouis");
assertThat(first.actionPlan()).isEqualTo("9450b10c-e725-48b8-bf01-acdec751c491");
@@ -67,7 +67,7 @@ public class IssueJsonParserTest {
assertThat(second.key()).isEqualTo("FGHIJ");
assertThat(second.line()).isNull();
assertThat(second.effortToFix()).isNull();
- assertThat(second.remediationCost()).isNull();
+ assertThat(second.technicalDebt()).isNull();
assertThat(second.reporter()).isNull();
assertThat(second.author()).isNull();
assertThat(second.attribute("JIRA")).isNull();
@@ -197,6 +197,18 @@ public class IssueJsonParserTest {
}
@Test
+ public void should_parse_technical_debt() throws Exception {
+ String json = IOUtils.toString(getClass().getResourceAsStream("/org/sonar/wsclient/issue/internal/IssueJsonParserTest/issue-with-technical-debt.json"));
+ Issues issues = new IssueJsonParser().parseIssues(json);
+ assertThat(issues.size()).isEqualTo(1);
+
+ Issue issue = issues.list().get(0);
+ assertThat(issue.technicalDebt().days()).isEqualTo(3);
+ assertThat(issue.technicalDebt().hours()).isEqualTo(0);
+ assertThat(issue.technicalDebt().minutes()).isEqualTo(10);
+ }
+
+ @Test
public void should_parse_bulk_change() throws Exception {
String json = IOUtils.toString(getClass().getResourceAsStream("/org/sonar/wsclient/issue/internal/IssueJsonParserTest/bulk-change.json"));
BulkChange bulkChange = new IssueJsonParser().parseBulkChange(json);
diff --git a/sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/internal/IssueJsonParserTest/issue-with-technical-debt.json b/sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/internal/IssueJsonParserTest/issue-with-technical-debt.json
new file mode 100644
index 00000000000..cda81fc2262
--- /dev/null
+++ b/sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/internal/IssueJsonParserTest/issue-with-technical-debt.json
@@ -0,0 +1,33 @@
+{
+ "issues": [
+ {
+ "key": "ABCDE",
+ "component": "Action.java",
+ "project": "struts",
+ "rule": "squid:CycleBetweenPackages",
+ "severity": "CRITICAL",
+ "status": "OPEN",
+ "technicalDebt": {
+ "days": 3,
+ "hours": 0,
+ "minutes": 10
+ }
+ }
+ ],
+ "rules": [
+ {
+
+ "key": "squid:CycleBetweenPackages",
+ "name": "Avoid cycle between java packages",
+ "desc": "<p>\nWhen several packages are involved in a cycle (package A > package B > package C > package A where \">\" means \"depends upon\"),\nthat means that those packages are highly coupled and that there is no way to reuse/extract one of those packages without importing all the other packages.\nSuch cycle could quickly increase the effort required to maintain an application and to embrace business change.\nSonar not only detect cycles between packages but also determines what is the minimum effort to break those cycles.\nThis rule log a violation on each source file having an outgoing dependency to be but in order to break a cycle.\n</p>\n"
+
+ }
+ ],
+ "paging": {
+ "pageIndex": 1,
+ "pageSize": 100,
+ "total": 2,
+ "pages": 1
+ },
+ "maxResultsReached": false
+}
diff --git a/sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/internal/IssueJsonParserTest/search.json b/sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/internal/IssueJsonParserTest/search.json
index e1f131c2f96..8a944880826 100644
--- a/sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/internal/IssueJsonParserTest/search.json
+++ b/sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/internal/IssueJsonParserTest/search.json
@@ -11,7 +11,6 @@
"status": "OPEN",
"assignee": "karadoc",
"effortToFix": 4.2,
- "remediationCost": 10,
"message": "the message",
"title": "the title",
"reporter": "perceval",
@@ -55,4 +54,4 @@
"pages": 1
},
"maxResultsReached": true
-} \ No newline at end of file
+}