summaryrefslogtreecommitdiffstats
path: root/sonar-ws-client
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2014-03-06 12:15:15 +0100
committerJulien Lancelot <julien.lancelot@sonarsource.com>2014-03-06 12:15:22 +0100
commit94ed63a7c64ddebf9056604535e4439a82ceecae (patch)
treeb8a2bb09bc2fe2653e80f8dda358da0795e8a176 /sonar-ws-client
parent975dacb594135e449c621d254081f6e179ec51c3 (diff)
downloadsonarqube-94ed63a7c64ddebf9056604535e4439a82ceecae.tar.gz
sonarqube-94ed63a7c64ddebf9056604535e4439a82ceecae.zip
SONAR-5056 Create new Durations API to format Duration and convert String to Duration
Diffstat (limited to 'sonar-ws-client')
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/issue/Issue.java2
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/issue/WorkDayDuration.java33
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/issue/internal/DefaultIssue.java11
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/issue/internal/DefaultIssueChangeDiff.java14
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/issue/internal/DefaultWorkDayDuration.java50
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/issue/internal/IssueJsonParserTest.java30
-rw-r--r--sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/internal/IssueJsonParserTest/changelog-with-only-new-technical-debt.json6
-rw-r--r--sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/internal/IssueJsonParserTest/changelog-with-technical-debt.json12
-rw-r--r--sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/internal/IssueJsonParserTest/issue-with-technical-debt.json6
9 files changed, 16 insertions, 148 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 5f0c825ca50..fe396834f22 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
@@ -55,7 +55,7 @@ public interface Issue {
Double effortToFix();
@CheckForNull
- WorkDayDuration technicalDebt();
+ String debt();
String status();
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/WorkDayDuration.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/WorkDayDuration.java
deleted file mode 100644
index 1db322bf5e3..00000000000
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/WorkDayDuration.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * 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 WorkDayDuration {
-
- Integer days();
-
- Integer minutes();
-
- Integer 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 75c1d776925..cbe7005e074 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,7 +21,6 @@ package org.sonar.wsclient.issue.internal;
import org.sonar.wsclient.issue.Issue;
import org.sonar.wsclient.issue.IssueComment;
-import org.sonar.wsclient.issue.WorkDayDuration;
import org.sonar.wsclient.unmarshallers.JsonUtils;
import javax.annotation.CheckForNull;
@@ -82,12 +81,8 @@ public class DefaultIssue implements Issue {
}
@CheckForNull
- public WorkDayDuration technicalDebt() {
- Map technicalDebt = (Map) json.get("technicalDebt");
- if (technicalDebt != null) {
- return new DefaultWorkDayDuration(technicalDebt);
- }
- return null;
+ public String debt() {
+ return JsonUtils.getString(json, "debt");
}
public String status() {
@@ -147,7 +142,7 @@ public class DefaultIssue implements Issue {
}
public Map<String, String> attributes() {
- Map<String, String> attr = (Map<String,String>) json.get("attr");
+ Map<String, String> attr = (Map<String, String>) json.get("attr");
if (attr == null) {
return Collections.emptyMap();
}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/internal/DefaultIssueChangeDiff.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/internal/DefaultIssueChangeDiff.java
index 289d3dd62e4..e357076fa1b 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/internal/DefaultIssueChangeDiff.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/internal/DefaultIssueChangeDiff.java
@@ -53,19 +53,7 @@ public class DefaultIssueChangeDiff implements IssueChangeDiff {
}
private Object parseValue(String attribute) {
- if ("technicalDebt".equals(key())) {
- return parseDefaultTechnicalDebt(attribute);
- } else {
- return JsonUtils.getString(json, attribute);
- }
- }
-
- private DefaultWorkDayDuration parseDefaultTechnicalDebt(String attribute){
- Map technicalDebt = (Map) json.get(attribute);
- if (technicalDebt != null) {
- return new DefaultWorkDayDuration(technicalDebt);
- }
- return null;
+ return JsonUtils.getString(json, attribute);
}
}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/internal/DefaultWorkDayDuration.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/internal/DefaultWorkDayDuration.java
deleted file mode 100644
index 7e2ecc79091..00000000000
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/internal/DefaultWorkDayDuration.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * 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.WorkDayDuration;
-import org.sonar.wsclient.unmarshallers.JsonUtils;
-
-import java.util.Map;
-
-/**
- * @since 4.0
- */
-public class DefaultWorkDayDuration implements WorkDayDuration {
-
- private final Map json;
-
- DefaultWorkDayDuration(Map json) {
- this.json = json;
- }
-
- public Integer days() {
- return JsonUtils.getInteger(json, "days");
- }
-
- public Integer hours() {
- return JsonUtils.getInteger(json, "hours");
- }
-
- public Integer minutes() {
- return JsonUtils.getInteger(json, "minutes");
- }
-
-}
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 5440852389b..b0f5de37056 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
@@ -52,7 +52,7 @@ public class IssueJsonParserTest {
assertThat(first.assignee()).isEqualTo("karadoc");
assertThat(first.message()).isEqualTo("the message");
assertThat(first.effortToFix()).isEqualTo(4.2);
- assertThat(first.technicalDebt()).isNull();
+ assertThat(first.debt()).isNull();
assertThat(first.reporter()).isEqualTo("perceval");
assertThat(first.author()).isEqualTo("pirlouis");
assertThat(first.actionPlan()).isEqualTo("9450b10c-e725-48b8-bf01-acdec751c491");
@@ -68,7 +68,7 @@ public class IssueJsonParserTest {
assertThat(second.key()).isEqualTo("FGHIJ");
assertThat(second.line()).isNull();
assertThat(second.effortToFix()).isNull();
- assertThat(second.technicalDebt()).isNull();
+ assertThat(second.debt()).isNull();
assertThat(second.reporter()).isNull();
assertThat(second.author()).isNull();
assertThat(second.attribute("JIRA")).isNull();
@@ -207,9 +207,7 @@ public class IssueJsonParserTest {
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);
+ assertThat(issue.debt()).isEqualTo("3d10min");
}
@@ -255,16 +253,8 @@ public class IssueJsonParserTest {
assertThat(change.diffs()).hasSize(1);
IssueChangeDiff changeDiff = change.diffs().get(0);
assertThat(changeDiff.key()).isEqualTo("technicalDebt");
-
- WorkDayDuration newTechnicalDebt = (WorkDayDuration) changeDiff.newValue();
- assertThat(newTechnicalDebt.days()).isEqualTo(2);
- assertThat(newTechnicalDebt.hours()).isEqualTo(1);
- assertThat(newTechnicalDebt.minutes()).isEqualTo(0);
-
- WorkDayDuration oldTechnicalDebt = (WorkDayDuration) changeDiff.oldValue();
- assertThat(oldTechnicalDebt.days()).isEqualTo(3);
- assertThat(oldTechnicalDebt.hours()).isEqualTo(0);
- assertThat(oldTechnicalDebt.minutes()).isEqualTo(10);
+ assertThat(changeDiff.newValue()).isEqualTo("2d1h");
+ assertThat(changeDiff.oldValue()).isEqualTo("3d10min");
}
@Test
@@ -280,14 +270,8 @@ public class IssueJsonParserTest {
assertThat(change.diffs()).hasSize(1);
IssueChangeDiff changeDiff = change.diffs().get(0);
assertThat(changeDiff.key()).isEqualTo("technicalDebt");
-
- WorkDayDuration newTechnicalDebt = (WorkDayDuration) changeDiff.newValue();
- assertThat(newTechnicalDebt.days()).isEqualTo(2);
- assertThat(newTechnicalDebt.hours()).isEqualTo(1);
- assertThat(newTechnicalDebt.minutes()).isEqualTo(0);
-
- WorkDayDuration oldTechnicalDebt = (WorkDayDuration) changeDiff.oldValue();
- assertThat(oldTechnicalDebt).isNull();
+ assertThat(changeDiff.newValue()).isEqualTo("2d1h");
+ assertThat(changeDiff.oldValue()).isNull();
}
@Test
diff --git a/sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/internal/IssueJsonParserTest/changelog-with-only-new-technical-debt.json b/sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/internal/IssueJsonParserTest/changelog-with-only-new-technical-debt.json
index 8600644db31..645c9eb2dac 100644
--- a/sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/internal/IssueJsonParserTest/changelog-with-only-new-technical-debt.json
+++ b/sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/internal/IssueJsonParserTest/changelog-with-only-new-technical-debt.json
@@ -6,11 +6,7 @@
"diffs": [
{
"key": "technicalDebt",
- "newValue": {
- "days": 2,
- "hours": 1,
- "minutes": 0
- }
+ "newValue": "2d1h"
}
]
}
diff --git a/sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/internal/IssueJsonParserTest/changelog-with-technical-debt.json b/sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/internal/IssueJsonParserTest/changelog-with-technical-debt.json
index 980a523216c..3989c989ad6 100644
--- a/sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/internal/IssueJsonParserTest/changelog-with-technical-debt.json
+++ b/sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/internal/IssueJsonParserTest/changelog-with-technical-debt.json
@@ -6,16 +6,8 @@
"diffs": [
{
"key": "technicalDebt",
- "oldValue": {
- "days": 3,
- "hours": 0,
- "minutes": 10
- },
- "newValue": {
- "days": 2,
- "hours": 1,
- "minutes": 0
- }
+ "oldValue": "3d10min",
+ "newValue": "2d1h"
}
]
}
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
index cda81fc2262..1da214fac67 100644
--- 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
@@ -7,11 +7,7 @@
"rule": "squid:CycleBetweenPackages",
"severity": "CRITICAL",
"status": "OPEN",
- "technicalDebt": {
- "days": 3,
- "hours": 0,
- "minutes": 10
- }
+ "debt": "3d10min"
}
],
"rules": [