]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3755 remove the resolution OPEN
authorSimon Brandhof <simon.brandhof@gmail.com>
Fri, 3 May 2013 21:41:09 +0000 (23:41 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Fri, 3 May 2013 21:41:09 +0000 (23:41 +0200)
14 files changed:
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/IssueTrackingTest.java
sonar-core/src/main/java/org/sonar/core/issue/DefaultIssue.java
sonar-core/src/main/java/org/sonar/core/issue/DefaultIssueBuilder.java
sonar-core/src/main/java/org/sonar/core/issue/db/IssueDto.java
sonar-core/src/main/java/org/sonar/core/issue/workflow/Function.java
sonar-core/src/main/java/org/sonar/core/issue/workflow/IssueWorkflow.java
sonar-core/src/main/java/org/sonar/core/issue/workflow/SetResolution.java
sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueBuilderTest.java
sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueTest.java
sonar-core/src/test/java/org/sonar/core/issue/workflow/SetResolutionTest.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/issue/Issue.java
sonar-server/src/main/webapp/WEB-INF/app/controllers/api/issues_controller.rb
sonar-ws-client/src/main/java/org/sonar/wsclient/issue/Issue.java
sonar-ws-client/src/test/java/org/sonar/wsclient/issue/NewIssueTest.java

index ba334f117697c7de46a1d456089b0c3e2db52576..bd3045632ee0fb5f1b32753822bfc319dd8781fe 100644 (file)
@@ -380,7 +380,7 @@ public class IssueTrackingTest {
   }
 
   private DefaultIssue newDefaultIssue(String message, Integer line, RuleKey ruleKey, String checksum) {
-    return new DefaultIssue().setDescription(message).setLine(line).setRuleKey(ruleKey).setChecksum(checksum).setResolution(Issue.RESOLUTION_OPEN).setStatus(Issue.STATUS_OPEN);
+    return new DefaultIssue().setDescription(message).setLine(line).setRuleKey(ruleKey).setChecksum(checksum).setStatus(Issue.STATUS_OPEN);
   }
 
   private IssueDto newReferenceIssue(String message, Integer lineId, int ruleId, String lineChecksum) {
@@ -392,7 +392,7 @@ public class IssueTrackingTest {
     referenceIssue.setDescription(message);
     referenceIssue.setRuleId(ruleId);
     referenceIssue.setChecksum(lineChecksum);
-    referenceIssue.setResolution(Issue.RESOLUTION_OPEN);
+    referenceIssue.setResolution(null);
     referenceIssue.setStatus(Issue.STATUS_OPEN);
     return referenceIssue;
   }
index 2e25531216e87bfcbf99b1bd5be7bf61331216b8..e97286276283b835da7c8e266cbb359003693242 100644 (file)
@@ -160,12 +160,12 @@ public class DefaultIssue implements Issue {
     return this;
   }
 
+  @CheckForNull
   public String resolution() {
     return resolution;
   }
 
-  public DefaultIssue setResolution(String s) {
-    Preconditions.checkArgument(!Strings.isNullOrEmpty(s), "Resolution must be set");
+  public DefaultIssue setResolution(@Nullable String s) {
     this.resolution = s;
     return this;
   }
index 497e1f860af2d6829f68b1d1bb0d9ffc1a3298cb..e4184397938fe6e89cd073e7762e520633edd350 100644 (file)
@@ -131,7 +131,7 @@ public class DefaultIssueBuilder implements Issuable.IssueBuilder {
     issue.setAttributes(attributes);
     issue.setNew(true);
     issue.setAlive(true);
-    issue.setResolution(Issue.RESOLUTION_OPEN);
+    issue.setResolution(null);
     issue.setStatus(Issue.STATUS_OPEN);
     return issue;
   }
index 6625f8e821b69be28524e6d6ef05bd5aa959510c..51fb8598ebeb92369bf8553fa4a0d04164d525bb 100644 (file)
@@ -27,6 +27,7 @@ import org.sonar.api.rule.RuleKey;
 import org.sonar.api.utils.KeyValueFormat;
 import org.sonar.core.issue.DefaultIssue;
 
+import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
 import java.util.Date;
 
@@ -103,6 +104,7 @@ public final class IssueDto {
     return this;
   }
 
+  @CheckForNull
   public String getSeverity() {
     return severity;
   }
@@ -130,6 +132,7 @@ public final class IssueDto {
     return this;
   }
 
+  @CheckForNull
   public String getDescription() {
     return description;
   }
@@ -139,6 +142,7 @@ public final class IssueDto {
     return this;
   }
 
+  @CheckForNull
   public Integer getLine() {
     return line;
   }
@@ -148,6 +152,7 @@ public final class IssueDto {
     return this;
   }
 
+  @CheckForNull
   public Double getEffortToFix() {
     return effortToFix;
   }
@@ -166,6 +171,7 @@ public final class IssueDto {
     return this;
   }
 
+  @CheckForNull
   public String getResolution() {
     return resolution;
   }
@@ -175,15 +181,17 @@ public final class IssueDto {
     return this;
   }
 
+  @CheckForNull
   public String getChecksum() {
     return checksum;
   }
 
-  public IssueDto setChecksum(String checksum) {
+  public IssueDto setChecksum(@Nullable String checksum) {
     this.checksum = checksum;
     return this;
   }
 
+  @CheckForNull
   public String getUserLogin() {
     return userLogin;
   }
index 400dbabaa6d2933f9747d2789de313bd66d6556d..578a3df0b247d0dec09eff71748c68e48584a0a3 100644 (file)
@@ -21,10 +21,12 @@ package org.sonar.core.issue.workflow;
 
 import org.sonar.api.issue.Issue;
 
+import javax.annotation.Nullable;
+
 interface Function {
   interface Context {
     Issue issue();
-    Context setResolution(String s);
+    Context setResolution(@Nullable String s);
     Context setCloseDate(boolean b);
   }
 
index 862402e723885b800666f529472888df5185a5ab..e5cd259df00a0d55baf892fd55d2ed24f65f66db 100644 (file)
@@ -52,11 +52,11 @@ public class IssueWorkflow implements BatchComponent, ServerComponent, Startable
         .build())
       .transition(Transition.builder(DefaultTransitions.REOPEN)
         .from(Issue.STATUS_RESOLVED).to(Issue.STATUS_REOPENED)
-        .functions(new SetResolution(Issue.RESOLUTION_OPEN))
+        .functions(new SetResolution(null))
         .build())
       .transition(Transition.builder(DefaultTransitions.REOPEN)
         .from(Issue.STATUS_CLOSED).to(Issue.STATUS_REOPENED)
-        .functions(new SetResolution(Issue.RESOLUTION_OPEN), new SetCloseDate(false))
+        .functions(new SetResolution(null), new SetCloseDate(false))
         .build())
       .transition(Transition.builder(DefaultTransitions.FALSE_POSITIVE)
         .from(Issue.STATUS_OPEN).to(Issue.STATUS_RESOLVED)
@@ -95,7 +95,7 @@ public class IssueWorkflow implements BatchComponent, ServerComponent, Startable
       .transition(Transition.builder("automaticreopen")
         .from(Issue.STATUS_RESOLVED).to(Issue.STATUS_REOPENED)
         .conditions(new IsAlive(true), new HasResolution(Issue.RESOLUTION_FIXED))
-        .functions(new SetResolution(Issue.RESOLUTION_OPEN))
+        .functions(new SetResolution(null))
         .automatic()
         .build())
       .build();
index e5147d4bf9986a680f58018dc16adb19ecbff32f..b2dab4c98b11031f2209681da8967e7ee03f7749 100644 (file)
  */
 package org.sonar.core.issue.workflow;
 
-import com.google.common.base.Preconditions;
-import com.google.common.base.Strings;
+import javax.annotation.Nullable;
 
 public class SetResolution implements Function {
   private final String resolution;
 
-  public SetResolution(String resolution) {
-    Preconditions.checkArgument(!Strings.isNullOrEmpty(resolution), "Resolution must be set");
+  public SetResolution(@Nullable String resolution) {
     this.resolution = resolution;
   }
 
index 6ce9186311084c1915c2450f5722f85bf6069c2c..e3bced3d3614e234dae791c16fc415a5d94d360c 100644 (file)
@@ -55,7 +55,7 @@ public class DefaultIssueBuilderTest {
     assertThat(issue.technicalUpdateDate()).isNotNull();
     assertThat(issue.assignee()).isNull();
     assertThat(issue.isNew()).isTrue();
-    assertThat(issue.resolution()).isEqualTo(Issue.RESOLUTION_OPEN);
+    assertThat(issue.resolution()).isNull();
     assertThat(issue.status()).isEqualTo(Issue.STATUS_OPEN);
     assertThat(issue.attribute("JIRA")).isEqualTo("FOO-123");
     assertThat(issue.attribute("YOUTRACK")).isEqualTo("YT-123");
index 1ac246e0db369c0bd06221840e6ec61120003196..23bf9b5a6a8c8bc94009d964a6529f6db00d5b71 100644 (file)
@@ -66,16 +66,6 @@ public class DefaultIssueTest {
     }
   }
 
-  @Test
-  public void should_fail_on_empty_resolution() {
-    try {
-      issue.setResolution("");
-      fail();
-    } catch (IllegalArgumentException e) {
-      assertThat(e).hasMessage("Resolution must be set");
-    }
-  }
-
   @Test
   public void should_fail_on_bad_severity() {
     try {
diff --git a/sonar-core/src/test/java/org/sonar/core/issue/workflow/SetResolutionTest.java b/sonar-core/src/test/java/org/sonar/core/issue/workflow/SetResolutionTest.java
new file mode 100644 (file)
index 0000000..f89b19e
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * 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.core.issue.workflow;
+
+import org.junit.Test;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+public class SetResolutionTest {
+  @Test
+  public void execute() throws Exception {
+    SetResolution function = new SetResolution("FIXED");
+    Function.Context context = mock(Function.Context.class);
+    function.execute(context);
+    verify(context, times(1)).setResolution("FIXED");
+  }
+}
index 5f30ec93678455718c5619241ea6169df60788c1..c1c5ea4c95d51ea7bece0545e6d8dcd605d22170 100644 (file)
@@ -39,7 +39,6 @@ public interface Issue extends Serializable {
   String STATUS_RESOLVED = "RESOLVED";
   String STATUS_CLOSED = "CLOSED";
 
-  String RESOLUTION_OPEN = "OPEN";
   String RESOLUTION_FIXED = "FIXED";
   String RESOLUTION_FALSE_POSITIVE = "FALSE-POSITIVE";
 
@@ -74,6 +73,10 @@ public interface Issue extends Serializable {
 
   String status();
 
+  /**
+   * The type of resolution. Return null if the issue is not resolved.
+   */
+  @CheckForNull
   String resolution();
 
   @CheckForNull
index 76bfc42e2c5088768492329555fef1db98027654..5c6690ec503d212a3f286ba6d1424e63397aa466 100644 (file)
@@ -181,9 +181,9 @@ class Api::IssuesController < Api::ApiController
         :key => issue.key,
         :component => issue.componentKey,
         :rule => issue.ruleKey.toString(),
-        :resolution => issue.resolution,
         :status => issue.status
     }
+    json[:resolution] = issue.resolution if issue.resolution
     json[:severity] = issue.severity if issue.severity
     json[:desc] = issue.description if issue.description
     json[:line] = issue.line.to_i if issue.line
index 62929609cd92e8fc5ba8cc584c3b8e9181a486b0..d22ed22afbbfc5da768eb9a6362d52ba17870f79 100644 (file)
@@ -21,6 +21,7 @@ package org.sonar.wsclient.issue;
 
 import org.sonar.wsclient.unmarshallers.JsonUtils;
 
+import javax.annotation.CheckForNull;
 import java.util.Collections;
 import java.util.Date;
 import java.util.Map;
@@ -55,10 +56,12 @@ public class Issue {
     return JsonUtils.getString(json, "severity");
   }
 
+  @CheckForNull
   public String description() {
     return JsonUtils.getString(json, "desc");
   }
 
+  @CheckForNull
   public Integer line() {
     return JsonUtils.getInteger(json, "line");
   }
@@ -68,6 +71,7 @@ public class Issue {
     return JsonUtils.getDouble(json, "effortToFix");
   }
 
+  @CheckForNull
   public Double effortToFix() {
     return JsonUtils.getDouble(json, "effortToFix");
   }
@@ -76,14 +80,26 @@ public class Issue {
     return JsonUtils.getString(json, "status");
   }
 
+  /**
+   * The resolution type. Null if the issue is not resolved.
+   */
+  @CheckForNull
   public String resolution() {
     return JsonUtils.getString(json, "resolution");
   }
 
+  /**
+   * Login of the user who created the manual issue, else null.
+   */
+  @CheckForNull
   public String userLogin() {
     return JsonUtils.getString(json, "userLogin");
   }
 
+  /**
+   * Login of assignee. Null if issue is not assigned.
+   */
+  @CheckForNull
   public String assignee() {
     return JsonUtils.getString(json, "assignee");
   }
@@ -96,10 +112,12 @@ public class Issue {
     return JsonUtils.getDateTime(json, "updateDate");
   }
 
+  @CheckForNull
   public Date closeDate() {
     return JsonUtils.getDateTime(json, "closeDate");
   }
 
+  @CheckForNull
   public String attribute(String key) {
     return attributes().get(key);
   }
index f544c9ed0c9bd0e8d70b613aa5351b0c4353feda..a6e2e9d7d406992c551e1bc1ea5201a5af60a190 100644 (file)
@@ -43,7 +43,7 @@ public class NewIssueTest {
 
     assertThat(newIssue.urlParams()).hasSize(7).includes(
       entry("component", "Action.java"),
-      entry("cost", 4.2),
+      entry("effortToFix", 4.2),
       entry("desc", "the desc"),
       entry("line", 123),
       entry("rule", "squid:AvoidCycle"),