diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2013-11-04 19:07:58 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2013-11-04 19:07:58 +0100 |
commit | a14a9a7c40f58f57bb00bed6b70f9b721abac58a (patch) | |
tree | 23167a346a2589b90b05d14c86469c8fb5094320 /sonar-ws-client | |
parent | bd7dd6a9e820ea805ab285cf94101c2ff46deeba (diff) | |
download | sonarqube-a14a9a7c40f58f57bb00bed6b70f9b721abac58a.tar.gz sonarqube-a14a9a7c40f58f57bb00bed6b70f9b721abac58a.zip |
SONAR-4834 Add technical debt changelog WS
Diffstat (limited to 'sonar-ws-client')
6 files changed, 83 insertions, 13 deletions
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/IssueChangeDiff.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/IssueChangeDiff.java index 364b9fb9fce..7ab2fdce49f 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/IssueChangeDiff.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/IssueChangeDiff.java @@ -29,9 +29,9 @@ public interface IssueChangeDiff { String key(); @CheckForNull - String newValue(); + Object newValue(); @CheckForNull - String oldValue(); + Object oldValue(); } 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 50c74c34a08..652decf37f2 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 @@ -79,7 +79,7 @@ public class DefaultIssue implements Issue { @CheckForNull public TechnicalDebt technicalDebt() { - Map technicalDebt = (Map) json.get("technicalDebt"); + Map technicalDebt = (Map) json.get(DefaultTechnicalDebt.KEY); if (technicalDebt != null) { return new DefaultTechnicalDebt(technicalDebt); } 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 0454267e920..2f57f46653d 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 @@ -42,13 +42,30 @@ public class DefaultIssueChangeDiff implements IssueChangeDiff { } @CheckForNull - public String newValue() { - return JsonUtils.getString(json, "newValue"); + public Object newValue() { + return parseValue("newValue"); + } @CheckForNull - public String oldValue() { - return JsonUtils.getString(json, "oldValue"); + public Object oldValue() { + return parseValue("oldValue"); + } + + private Object parseValue(String attribute) { + if (DefaultTechnicalDebt.KEY.equals(key())) { + return parseDefaultTechnicalDebt(attribute); + } else { + return JsonUtils.getString(json, attribute); + } + } + + private DefaultTechnicalDebt parseDefaultTechnicalDebt(String attribute){ + Map technicalDebt = (Map) json.get(attribute); + if (technicalDebt != null) { + return new DefaultTechnicalDebt(technicalDebt); + } + return null; } } 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 index 5bd45d915a9..9bdab493bf7 100644 --- 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 @@ -28,6 +28,9 @@ import java.util.Map; * @since 4.0 */ public class DefaultTechnicalDebt implements TechnicalDebt { + + public static final String KEY = "technicalDebt"; + private final Map json; DefaultTechnicalDebt(Map json) { 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 87f86d26c4e..4acc0bf370e 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 @@ -20,7 +20,6 @@ package org.sonar.wsclient.issue.internal; import org.apache.commons.io.IOUtils; -import org.junit.Ignore; import org.junit.Test; import org.sonar.wsclient.base.Paging; import org.sonar.wsclient.component.Component; @@ -242,7 +241,6 @@ public class IssueJsonParserTest { } @Test - @Ignore public void should_parse_changelog_with_technical_debt() throws Exception { String json = IOUtils.toString(getClass().getResourceAsStream("/org/sonar/wsclient/issue/internal/IssueJsonParserTest/changelog-with-technical-debt.json")); List<IssueChange> changes = new IssueJsonParser().parseChangelog(json); @@ -254,10 +252,42 @@ public class IssueJsonParserTest { assertThat(change.updatedAt().getTime()).isEqualTo(1383202235000l); assertThat(change.diffs()).hasSize(1); - IssueChangeDiff diffChange1 = change.diffs().get(0); - assertThat(diffChange1.key()).isEqualTo("technicalDebt"); - assertThat(diffChange1.newValue()).isEqualTo("1.0"); - assertThat(diffChange1.oldValue()).isNull(); + IssueChangeDiff changeDiff = change.diffs().get(0); + assertThat(changeDiff.key()).isEqualTo("technicalDebt"); + + TechnicalDebt newTechnicalDebt = (TechnicalDebt) changeDiff.newValue(); + assertThat(newTechnicalDebt.days()).isEqualTo(2); + assertThat(newTechnicalDebt.hours()).isEqualTo(1); + assertThat(newTechnicalDebt.minutes()).isEqualTo(0); + + TechnicalDebt oldTechnicalDebt = (TechnicalDebt) changeDiff.oldValue(); + assertThat(oldTechnicalDebt.days()).isEqualTo(3); + assertThat(oldTechnicalDebt.hours()).isEqualTo(0); + assertThat(oldTechnicalDebt.minutes()).isEqualTo(10); + } + + @Test + public void should_parse_changelog_with_only_new_technical_debt() throws Exception { + String json = IOUtils.toString(getClass().getResourceAsStream("/org/sonar/wsclient/issue/internal/IssueJsonParserTest/changelog-with-only-new-technical-debt.json")); + List<IssueChange> changes = new IssueJsonParser().parseChangelog(json); + + assertThat(changes).hasSize(1); + IssueChange change = changes.get(0); + assertThat(change.user()).isEqualTo("julien"); + assertThat(change.createdAt().getTime()).isEqualTo(1383202235000l); + assertThat(change.updatedAt().getTime()).isEqualTo(1383202235000l); + + assertThat(change.diffs()).hasSize(1); + IssueChangeDiff changeDiff = change.diffs().get(0); + assertThat(changeDiff.key()).isEqualTo("technicalDebt"); + + TechnicalDebt newTechnicalDebt = (TechnicalDebt) changeDiff.newValue(); + assertThat(newTechnicalDebt.days()).isEqualTo(2); + assertThat(newTechnicalDebt.hours()).isEqualTo(1); + assertThat(newTechnicalDebt.minutes()).isEqualTo(0); + + TechnicalDebt oldTechnicalDebt = (TechnicalDebt) changeDiff.oldValue(); + assertThat(oldTechnicalDebt).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 new file mode 100644 index 00000000000..174513f5a5d --- /dev/null +++ b/sonar-ws-client/src/test/resources/org/sonar/wsclient/issue/internal/IssueJsonParserTest/changelog-with-only-new-technical-debt.json @@ -0,0 +1,20 @@ +{ + "changelog": [ + { + "user": "julien", + "createdAt": "2013-10-31T07:50:35+0100", + "updatedAt": "2013-10-31T07:50:35+0100", + "diffs": [ + { + "key": "technicalDebt", + "newValue": { + "days": 2, + "hours": 1, + "minutes": 0 + } + } + ] + } + ] +} + |