]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4716 persist remediation cost
authorJulien Lancelot <julien.lancelot@gmail.com>
Wed, 2 Oct 2013 12:17:27 +0000 (14:17 +0200)
committerJulien Lancelot <julien.lancelot@gmail.com>
Wed, 2 Oct 2013 12:17:51 +0000 (14:17 +0200)
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/IssueTrackingDecorator.java
plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/IssueTrackingDecoratorTest.java
sonar-core/src/main/java/org/sonar/core/issue/IssueUpdater.java
sonar-core/src/main/java/org/sonar/core/issue/db/IssueDto.java
sonar-core/src/test/java/org/sonar/core/issue/IssueUpdaterTest.java
sonar-core/src/test/java/org/sonar/core/issue/db/IssueStorageTest.java
sonar-core/src/test/resources/org/sonar/core/issue/db/IssueStorageTest/should_insert_new_issues-result.xml
sonar-core/src/test/resources/org/sonar/core/issue/db/IssueStorageTest/should_update_issues-result.xml

index a8fe508840355d5eddfd98b0c15982b8733e5516..b42bff38ae4d9020b1dea4f81e2a5831eb3f2f72 100644 (file)
@@ -25,12 +25,7 @@ import com.google.common.collect.Lists;
 import org.apache.commons.lang.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.sonar.api.batch.Decorator;
-import org.sonar.api.batch.DecoratorBarriers;
-import org.sonar.api.batch.DecoratorContext;
-import org.sonar.api.batch.DependedUpon;
-import org.sonar.api.batch.DependsUpon;
-import org.sonar.api.batch.SonarIndex;
+import org.sonar.api.batch.*;
 import org.sonar.api.component.ResourcePerspectives;
 import org.sonar.api.issue.Issuable;
 import org.sonar.api.issue.Issue;
@@ -171,6 +166,7 @@ public class IssueTrackingDecorator implements Decorator {
       updater.setPastLine(issue, ref.getLine());
       updater.setPastMessage(issue, ref.getMessage(), changeContext);
       updater.setPastEffortToFix(issue, ref.getEffortToFix(), changeContext);
+      updater.setPastRemediationCost(issue, ref.getRemediationCost(), changeContext);
     }
   }
 
index f60e2eda89b5c0b94fc1c8fe81ee576edc029b50..5f12e68eee08db62115f059b980da29ad8009805 100644 (file)
@@ -114,6 +114,7 @@ resolution=Resolution
 result=Result
 results=Results
 x_results={0} results
+remediationCost=Remediation Cost
 review=Review
 reviews=Reviews
 review_verb=Review
index c81eb042b52c6729e53722b41f7c498b398dccdf..5b1d0b0bbc4c0388beecb7b7e26103745b676d60 100644 (file)
@@ -19,8 +19,6 @@
  */
 package org.sonar.plugins.core.issue;
 
-import org.mockito.Matchers;
-
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.ArgumentCaptor;
@@ -57,12 +55,7 @@ import static org.mockito.Matchers.anyCollection;
 import static org.mockito.Matchers.argThat;
 import static org.mockito.Matchers.eq;
 import static org.mockito.Matchers.isA;
-import static org.mockito.Mockito.RETURNS_MOCKS;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyZeroInteractions;
-import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.*;
 
 public class IssueTrackingDecoratorTest extends AbstractDaoTestCase {
 
index c5330050a9bbc4a23ece9b885169ba3977b6ea2c..ad834ed8ff225dce29044ab66c6813baf3952bf3 100644 (file)
@@ -31,6 +31,7 @@ import org.sonar.api.issue.internal.IssueChangeContext;
 import org.sonar.api.user.User;
 
 import javax.annotation.Nullable;
+
 import java.util.Calendar;
 import java.util.Date;
 
@@ -46,6 +47,7 @@ public class IssueUpdater implements BatchComponent, ServerComponent {
   public static final String STATUS = "status";
   public static final String AUTHOR = "author";
   public static final String ACTION_PLAN = "actionPlan";
+  public static final String REMEDIATION_COST = "remediationCost";
 
   public boolean setSeverity(DefaultIssue issue, String severity, IssueChangeContext context) {
     if (issue.manualSeverity()) {
@@ -197,6 +199,25 @@ public class IssueUpdater implements BatchComponent, ServerComponent {
     return setEffortToFix(issue, currentEffort, context);
   }
 
+  public boolean setRemediationCost(DefaultIssue issue, @Nullable Long value, IssueChangeContext context) {
+    Long oldValue = issue.remediationCost();
+    if (!Objects.equal(value, oldValue)) {
+      issue.setRemediationCost(value);
+      issue.setUpdateDate(context.date());
+      issue.setChanged(true);
+      issue.setFieldChange(context, REMEDIATION_COST, oldValue, value);
+      return true;
+    }
+    return false;
+  }
+
+  public boolean setPastRemediationCost(DefaultIssue issue, @Nullable Long previousRemediationCost, IssueChangeContext context) {
+    Long currentRemediationCost = issue.remediationCost();
+    issue.setRemediationCost(previousRemediationCost);
+    return setRemediationCost(issue, currentRemediationCost, context);
+
+  }
+
   public boolean setAttribute(DefaultIssue issue, String key, @Nullable String value, IssueChangeContext context) {
     String oldValue = issue.attribute(key);
     if (!Objects.equal(oldValue, value)) {
index e251095ede54d20069185ee5bf41759e35d204de..fabdee98933f6b4e35302addaace0ea5c7da6896 100644 (file)
@@ -29,6 +29,7 @@ import org.sonar.api.utils.KeyValueFormat;
 
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
+
 import java.io.Serializable;
 import java.util.Date;
 
@@ -366,6 +367,7 @@ public final class IssueDto implements Serializable {
       .setLine(issue.line())
       .setMessage(issue.message())
       .setEffortToFix(issue.effortToFix())
+      .setRemediationCost(issue.remediationCost())
       .setResolution(issue.resolution())
       .setStatus(issue.status())
       .setSeverity(issue.severity())
@@ -394,6 +396,7 @@ public final class IssueDto implements Serializable {
       .setLine(issue.line())
       .setMessage(issue.message())
       .setEffortToFix(issue.effortToFix())
+      .setRemediationCost(issue.remediationCost())
       .setResolution(issue.resolution())
       .setStatus(issue.status())
       .setSeverity(issue.severity())
index 1d68e98cc39de5a4d4d91aeb2662f3a31e7d5a0c..07e0e8f39775de1bfeb5862ba14ed360ffb8c6a0 100644 (file)
@@ -39,7 +39,7 @@ public class IssueUpdaterTest {
   IssueChangeContext context = IssueChangeContext.createUser(new Date(), "emmerik");
 
   @Test
-  public void should_assign() throws Exception {
+  public void assign() throws Exception {
     User user = new DefaultUser().setLogin("emmerik").setName("Emmerik");
 
     boolean updated = updater.assign(issue, user, context);
@@ -52,7 +52,7 @@ public class IssueUpdaterTest {
   }
 
   @Test
-  public void should_unassign() throws Exception {
+  public void unassign() throws Exception {
     issue.setAssignee("morgan");
     boolean updated = updater.assign(issue, null, context);
     assertThat(updated).isTrue();
@@ -64,7 +64,7 @@ public class IssueUpdaterTest {
   }
 
   @Test
-  public void should_change_assignee() throws Exception {
+  public void change_assignee() throws Exception {
     User user = new DefaultUser().setLogin("emmerik").setName("Emmerik");
 
     issue.setAssignee("morgan");
@@ -78,7 +78,7 @@ public class IssueUpdaterTest {
   }
 
   @Test
-  public void should_not_change_assignee() throws Exception {
+  public void not_change_assignee() throws Exception {
     User user = new DefaultUser().setLogin("morgan").setName("Morgan");
 
     issue.setAssignee("morgan");
@@ -89,7 +89,7 @@ public class IssueUpdaterTest {
   }
 
   @Test
-  public void should_set_severity() throws Exception {
+  public void set_severity() throws Exception {
     boolean updated = updater.setSeverity(issue, "BLOCKER", context);
     assertThat(updated).isTrue();
     assertThat(issue.severity()).isEqualTo("BLOCKER");
@@ -102,7 +102,7 @@ public class IssueUpdaterTest {
   }
 
   @Test
-  public void should_set_past_severity() throws Exception {
+  public void set_past_severity() throws Exception {
     issue.setSeverity("BLOCKER");
     boolean updated = updater.setPastSeverity(issue, "INFO", context);
     assertThat(updated).isTrue();
@@ -115,7 +115,7 @@ public class IssueUpdaterTest {
   }
 
   @Test
-  public void should_update_severity() throws Exception {
+  public void update_severity() throws Exception {
     issue.setSeverity("BLOCKER");
     boolean updated = updater.setSeverity(issue, "MINOR", context);
 
@@ -128,7 +128,7 @@ public class IssueUpdaterTest {
   }
 
   @Test
-  public void should_not_change_severity() throws Exception {
+  public void not_change_severity() throws Exception {
     issue.setSeverity("MINOR");
     boolean updated = updater.setSeverity(issue, "MINOR", context);
     assertThat(updated).isFalse();
@@ -137,7 +137,7 @@ public class IssueUpdaterTest {
   }
 
   @Test
-  public void should_not_revert_manual_severity() throws Exception {
+  public void not_revert_manual_severity() throws Exception {
     issue.setSeverity("MINOR").setManualSeverity(true);
     try {
       updater.setSeverity(issue, "MAJOR", context);
@@ -147,7 +147,7 @@ public class IssueUpdaterTest {
   }
 
   @Test
-  public void should_set_manual_severity() throws Exception {
+  public void set_manual_severity() throws Exception {
     issue.setSeverity("BLOCKER");
     boolean updated = updater.setManualSeverity(issue, "MINOR", context);
 
@@ -161,7 +161,7 @@ public class IssueUpdaterTest {
   }
 
   @Test
-  public void should_not_change_manual_severity() throws Exception {
+  public void not_change_manual_severity() throws Exception {
     issue.setSeverity("MINOR").setManualSeverity(true);
     boolean updated = updater.setManualSeverity(issue, "MINOR", context);
     assertThat(updated).isFalse();
@@ -170,7 +170,7 @@ public class IssueUpdaterTest {
   }
 
   @Test
-  public void should_set_line() throws Exception {
+  public void set_line() throws Exception {
     boolean updated = updater.setLine(issue, 123);
     assertThat(updated).isTrue();
     assertThat(issue.line()).isEqualTo(123);
@@ -180,7 +180,7 @@ public class IssueUpdaterTest {
   }
 
   @Test
-  public void should_set_past_line() throws Exception {
+  public void set_past_line() throws Exception {
     issue.setLine(42);
     boolean updated = updater.setPastLine(issue, 123);
     assertThat(updated).isTrue();
@@ -192,7 +192,7 @@ public class IssueUpdaterTest {
   }
 
   @Test
-  public void should_not_change_line() throws Exception {
+  public void not_change_line() throws Exception {
     issue.setLine(123);
     boolean updated = updater.setLine(issue, 123);
     assertThat(updated).isFalse();
@@ -202,7 +202,7 @@ public class IssueUpdaterTest {
   }
 
   @Test
-  public void should_set_resolution() throws Exception {
+  public void set_resolution() throws Exception {
     boolean updated = updater.setResolution(issue, "OPEN", context);
     assertThat(updated).isTrue();
     assertThat(issue.resolution()).isEqualTo("OPEN");
@@ -214,7 +214,7 @@ public class IssueUpdaterTest {
   }
 
   @Test
-  public void should_not_change_resolution() throws Exception {
+  public void not_change_resolution() throws Exception {
     issue.setResolution("FIXED");
     boolean updated = updater.setResolution(issue, "FIXED", context);
     assertThat(updated).isFalse();
@@ -224,7 +224,7 @@ public class IssueUpdaterTest {
   }
 
   @Test
-  public void should_set_status() throws Exception {
+  public void set_status() throws Exception {
     boolean updated = updater.setStatus(issue, "OPEN", context);
     assertThat(updated).isTrue();
     assertThat(issue.status()).isEqualTo("OPEN");
@@ -236,7 +236,7 @@ public class IssueUpdaterTest {
   }
 
   @Test
-  public void should_not_change_status() throws Exception {
+  public void not_change_status() throws Exception {
     issue.setStatus("CLOSED");
     boolean updated = updater.setStatus(issue, "CLOSED", context);
     assertThat(updated).isFalse();
@@ -246,7 +246,7 @@ public class IssueUpdaterTest {
   }
 
   @Test
-  public void should_set_new_attribute_value() throws Exception {
+  public void set_new_attribute_value() throws Exception {
     boolean updated = updater.setAttribute(issue, "JIRA", "FOO-123", context);
     assertThat(updated).isTrue();
     assertThat(issue.attribute("JIRA")).isEqualTo("FOO-123");
@@ -257,7 +257,7 @@ public class IssueUpdaterTest {
   }
 
   @Test
-  public void should_unset_attribute() throws Exception {
+  public void unset_attribute() throws Exception {
     issue.setAttribute("JIRA", "FOO-123");
     boolean updated = updater.setAttribute(issue, "JIRA", null, context);
     assertThat(updated).isTrue();
@@ -269,7 +269,7 @@ public class IssueUpdaterTest {
   }
 
   @Test
-  public void should_not_update_attribute() throws Exception {
+  public void not_update_attribute() throws Exception {
     issue.setAttribute("JIRA", "FOO-123");
     boolean updated = updater.setAttribute(issue, "JIRA", "FOO-123", context);
     assertThat(updated).isFalse();
@@ -277,7 +277,7 @@ public class IssueUpdaterTest {
   }
 
   @Test
-  public void should_plan_with_no_existing_plan() throws Exception {
+  public void plan_with_no_existing_plan() throws Exception {
     ActionPlan newActionPlan = DefaultActionPlan.create("newName");
 
     boolean updated = updater.plan(issue, newActionPlan, context);
@@ -291,7 +291,7 @@ public class IssueUpdaterTest {
   }
 
   @Test
-  public void should_plan_with_existing_plan() throws Exception {
+  public void plan_with_existing_plan() throws Exception {
     issue.setActionPlanKey("formerActionPlan");
 
     ActionPlan newActionPlan = DefaultActionPlan.create("newName").setKey("newKey");
@@ -307,7 +307,7 @@ public class IssueUpdaterTest {
   }
 
   @Test
-  public void should_unplan() throws Exception {
+  public void unplan() throws Exception {
     issue.setActionPlanKey("formerActionPlan");
 
     boolean updated = updater.plan(issue, null, context);
@@ -321,7 +321,7 @@ public class IssueUpdaterTest {
   }
 
   @Test
-  public void should_not_plan_again() throws Exception {
+  public void not_plan_again() throws Exception {
     issue.setActionPlanKey("existingActionPlan");
 
     ActionPlan newActionPlan = DefaultActionPlan.create("existingActionPlan").setKey("existingActionPlan");
@@ -333,7 +333,7 @@ public class IssueUpdaterTest {
   }
 
   @Test
-  public void should_set_effort_to_fix() throws Exception {
+  public void set_effort_to_fix() throws Exception {
     boolean updated = updater.setEffortToFix(issue, 3.14, context);
     assertThat(updated).isTrue();
     assertThat(issue.isChanged()).isTrue();
@@ -342,7 +342,7 @@ public class IssueUpdaterTest {
   }
 
   @Test
-  public void should_not_set_effort_to_fix_if_unchanged() throws Exception {
+  public void not_set_effort_to_fix_if_unchanged() throws Exception {
     issue.setEffortToFix(3.14);
     boolean updated = updater.setEffortToFix(issue, 3.14, context);
     assertThat(updated).isFalse();
@@ -352,7 +352,7 @@ public class IssueUpdaterTest {
   }
 
   @Test
-  public void should_set_past_effort() throws Exception {
+  public void set_past_effort() throws Exception {
     issue.setEffortToFix(3.14);
     boolean updated = updater.setPastEffortToFix(issue, 1.0, context);
     assertThat(updated).isTrue();
@@ -364,7 +364,20 @@ public class IssueUpdaterTest {
   }
 
   @Test
-  public void should_set_message() throws Exception {
+  public void set_past_remediation_cost() throws Exception {
+    issue.setRemediationCost(15l);
+    boolean updated = updater.setPastRemediationCost(issue, 10l, context);
+    assertThat(updated).isTrue();
+    assertThat(issue.remediationCost()).isEqualTo(15L);
+
+    FieldDiffs.Diff diff = issue.currentChange().get("remediationCost");
+    assertThat(diff.oldValue()).isEqualTo(10L);
+    assertThat(diff.newValue()).isEqualTo(15L);
+    assertThat(issue.mustSendNotifications()).isFalse();
+  }
+
+  @Test
+  public void set_message() throws Exception {
     boolean updated = updater.setMessage(issue, "the message", context);
     assertThat(updated).isTrue();
     assertThat(issue.isChanged()).isTrue();
@@ -373,7 +386,7 @@ public class IssueUpdaterTest {
   }
 
   @Test
-  public void should_set_past_message() throws Exception {
+  public void set_past_message() throws Exception {
     issue.setMessage("new message");
     boolean updated = updater.setPastMessage(issue, "past message", context);
     assertThat(updated).isTrue();
@@ -385,7 +398,7 @@ public class IssueUpdaterTest {
   }
 
   @Test
-  public void should_set_author() throws Exception {
+  public void set_author() throws Exception {
     boolean updated = updater.setAuthorLogin(issue, "eric", context);
     assertThat(updated).isTrue();
     assertThat(issue.authorLogin()).isEqualTo("eric");
@@ -395,4 +408,5 @@ public class IssueUpdaterTest {
     assertThat(diff.newValue()).isEqualTo("eric");
     assertThat(issue.mustSendNotifications()).isFalse();
   }
+
 }
index e1bfd076525c5950ae65290d8f1439ee17323140..b39bb5ba4134b74dbfae5f6d4168515484b05cd2 100644 (file)
@@ -53,6 +53,7 @@ public class IssueStorageTest extends AbstractDaoTestCase {
 
       .setRuleKey(RuleKey.of("squid", "AvoidCycle"))
       .setLine(5000)
+      .setRemediationCost(10L)
       .setReporter("emmerik")
       .setResolution("OPEN")
       .setStatus("OPEN")
@@ -86,6 +87,7 @@ public class IssueStorageTest extends AbstractDaoTestCase {
 
         // updated fields
       .setLine(5000)
+      .setRemediationCost(10L)
       .setChecksum("FFFFF")
       .setAuthorLogin("simon")
       .setAssignee("loic")
index af3b4371b4921d5e438734a57c1e5953f65184be..81c7d21c464e023c075f8fb1d9c2c14cb0b31972 100644 (file)
@@ -4,7 +4,7 @@
       author_login="[null]"
       checksum="[null]"
       effort_to_fix="[null]"
-      remediation_cost="[null]"
+      remediation_cost="10"
       message="[null]"
       line="5000"
       component_id="100"
@@ -22,4 +22,4 @@
 
   <issue_changes id="1" kee="FGHIJ" issue_key="ABCDE" change_type="comment" user_login="emmerik" change_data="the comment" created_at="[null]" updated_at="[null]" />
 
-</dataset>
\ No newline at end of file
+</dataset>
index 8d700c2f865e29282ef7ca37442d752df98f88b7..07fe401b3cab0b17a54e7c4da50519dbc54dba8e 100644 (file)
@@ -9,7 +9,7 @@
           author_login="simon"
           checksum="FFFFF"
           effort_to_fix="[null]"
-          remediation_cost="[null]"
+          remediation_cost="10"
           message="[null]"
           line="5000"
           component_id="100"
@@ -29,4 +29,4 @@
                  change_data="the comment" created_at="[null]" updated_at="[null]"/>
   <issue_changes id="2" kee="[null]" issue_key="ABCDE" change_type="diff" user_login="emmerik"
                  change_data="severity=INFO|BLOCKER" created_at="[null]" updated_at="[null]"/>
-</dataset>
\ No newline at end of file
+</dataset>