From b7252332e854af6c13d5c31c8638ca31c732139b Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Thu, 23 May 2013 12:19:12 +0200 Subject: [PATCH] SONAR-4329 Close no more existing confirmed issues --- .../core/issue/workflow/IssueWorkflow.java | 6 ++ .../issue/workflow/IssueWorkflowTest.java | 55 +++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/sonar-core/src/main/java/org/sonar/core/issue/workflow/IssueWorkflow.java b/sonar-core/src/main/java/org/sonar/core/issue/workflow/IssueWorkflow.java index 8d1b1ea539b..ff308798a0c 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/workflow/IssueWorkflow.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/workflow/IssueWorkflow.java @@ -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") diff --git a/sonar-core/src/test/java/org/sonar/core/issue/workflow/IssueWorkflowTest.java b/sonar-core/src/test/java/org/sonar/core/issue/workflow/IssueWorkflowTest.java index 7919a92219c..8d5e3bbeb22 100644 --- a/sonar-core/src/test/java/org/sonar/core/issue/workflow/IssueWorkflowTest.java +++ b/sonar-core/src/test/java/org/sonar/core/issue/workflow/IssueWorkflowTest.java @@ -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(); -- 2.39.5