]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4329 Close no more existing confirmed issues
authorJulien Lancelot <julien.lancelot@gmail.com>
Thu, 23 May 2013 10:19:12 +0000 (12:19 +0200)
committerJulien Lancelot <julien.lancelot@gmail.com>
Thu, 23 May 2013 10:19:12 +0000 (12:19 +0200)
sonar-core/src/main/java/org/sonar/core/issue/workflow/IssueWorkflow.java
sonar-core/src/test/java/org/sonar/core/issue/workflow/IssueWorkflowTest.java

index 8d1b1ea539b5d3c5f28ddcc1bf8c203e35d0c1bc..ff308798a0c1eb0427bf0e452ff2c8196735d326 100644 (file)
@@ -111,6 +111,12 @@ public class IssueWorkflow implements BatchComponent, ServerComponent, Startable
         .functions(new SetResolution(Issue.RESOLUTION_FIXED), new SetCloseDate(true))
         .automatic()
         .build())
+      .transition(Transition.builder("automaticclose")
+        .from(Issue.STATUS_CONFIRMED).to(Issue.STATUS_CLOSED)
+        .conditions(new IsAlive(false))
+        .functions(new SetResolution(Issue.RESOLUTION_FIXED), new SetCloseDate(true))
+        .automatic()
+        .build())
         // Close the issues marked as resolved and that do not exist anymore.
         // Note that false-positives are kept resolved and are not closed.
       .transition(Transition.builder("automaticclose")
index 7919a92219c4f8759c0013be09982ee83e85efd8..8d5e3bbeb22bc343b7a8a9552e3ad9f58737477d 100644 (file)
@@ -120,6 +120,61 @@ public class IssueWorkflowTest {
     assertThat(issue.updateDate()).isEqualTo(now);
   }
 
+  @Test
+  public void should_close_open_dead_issue() throws Exception {
+    workflow.start();
+
+    DefaultIssue issue = new DefaultIssue()
+      .setKey("ABCDE")
+      .setResolution(null)
+      .setStatus(Issue.STATUS_OPEN)
+      .setNew(false)
+      .setAlive(false);
+    Date now = new Date();
+    workflow.doAutomaticTransition(issue, IssueChangeContext.createScan(now));
+    assertThat(issue.resolution()).isEqualTo(Issue.RESOLUTION_FIXED);
+    assertThat(issue.status()).isEqualTo(Issue.STATUS_CLOSED);
+    assertThat(issue.closeDate()).isNotNull();
+    assertThat(issue.updateDate()).isEqualTo(now);
+  }
+
+  @Test
+  public void should_close_reopened_dead_issue() throws Exception {
+    workflow.start();
+
+    DefaultIssue issue = new DefaultIssue()
+      .setKey("ABCDE")
+      .setResolution(null)
+      .setStatus(Issue.STATUS_REOPENED)
+      .setNew(false)
+      .setAlive(false);
+    Date now = new Date();
+    workflow.doAutomaticTransition(issue, IssueChangeContext.createScan(now));
+    assertThat(issue.resolution()).isEqualTo(Issue.RESOLUTION_FIXED);
+    assertThat(issue.status()).isEqualTo(Issue.STATUS_CLOSED);
+    assertThat(issue.closeDate()).isNotNull();
+    assertThat(issue.updateDate()).isEqualTo(now);
+  }
+
+  @Test
+  public void should_close_confirmed_dead_issue() throws Exception {
+    workflow.start();
+
+    DefaultIssue issue = new DefaultIssue()
+      .setKey("ABCDE")
+      .setResolution(null)
+      .setStatus(Issue.STATUS_CONFIRMED)
+      .setNew(false)
+      .setAlive(false);
+    Date now = new Date();
+    workflow.doAutomaticTransition(issue, IssueChangeContext.createScan(now));
+    assertThat(issue.resolution()).isEqualTo(Issue.RESOLUTION_FIXED);
+    assertThat(issue.status()).isEqualTo(Issue.STATUS_CLOSED);
+    assertThat(issue.closeDate()).isNotNull();
+    assertThat(issue.updateDate()).isEqualTo(now);
+  }
+
+
   @Test
   public void should_fail_if_unknown_status() throws Exception {
     workflow.start();