]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3714 Add transition action
authorJulien Lancelot <julien.lancelot@gmail.com>
Wed, 26 Jun 2013 08:21:25 +0000 (10:21 +0200)
committerJulien Lancelot <julien.lancelot@gmail.com>
Wed, 26 Jun 2013 08:21:35 +0000 (10:21 +0200)
sonar-server/src/main/java/org/sonar/server/issue/TransitionAction.java [new file with mode: 0644]
sonar-server/src/main/java/org/sonar/server/platform/Platform.java
sonar-server/src/main/webapp/WEB-INF/app/views/issue/_issue.html.erb
sonar-server/src/test/java/org/sonar/server/issue/TransitionActionTest.java [new file with mode: 0644]

diff --git a/sonar-server/src/main/java/org/sonar/server/issue/TransitionAction.java b/sonar-server/src/main/java/org/sonar/server/issue/TransitionAction.java
new file mode 100644 (file)
index 0000000..e954440
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * 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.server.issue;
+
+import org.sonar.api.ServerComponent;
+import org.sonar.api.issue.Issue;
+import org.sonar.api.issue.internal.DefaultIssue;
+import org.sonar.core.issue.workflow.IssueWorkflow;
+import org.sonar.server.user.UserSession;
+
+import java.util.List;
+import java.util.Map;
+
+public class TransitionAction extends Action implements ServerComponent {
+
+  public static final String PLAN_ACTION_KEY = "transition";
+
+  private final IssueWorkflow workflow;
+
+  public TransitionAction(IssueWorkflow workflow) {
+    super(PLAN_ACTION_KEY);
+    this.workflow = workflow;
+  }
+
+  @Override
+  public boolean verify(Map<String, Object> properties, List<Issue> issues, UserSession userSession) {
+    return true;
+  }
+
+  @Override
+  public boolean execute(Map<String, Object> properties, Context context) {
+    return workflow.doTransition((DefaultIssue) context.issue(), transition(properties), context.issueChangeContext());
+  }
+
+  private String transition(Map<String, Object> properties) {
+    return (String) properties.get("transition");
+  }
+
+}
\ No newline at end of file
index 9bdc3e50d99c6e1dec43b4ccf3b4153fead52838..3d8aa0fe71d2f5eb9cdb173b059830fb3d2d8afb 100644 (file)
@@ -282,6 +282,7 @@ public final class Platform {
     servicesContainer.addSingleton(PlanAction.class);
     servicesContainer.addSingleton(SetSeverityAction.class);
     servicesContainer.addSingleton(CommentAction.class);
+    servicesContainer.addSingleton(TransitionAction.class);
 
     // rules
     servicesContainer.addSingleton(RubyRuleService.class);
index b3b568af4b36941a232b043466274442b1f752f4..ffdf06a369364fce4bda25a527f13ab45b4ed192 100644 (file)
           <a href='#' onclick="return issueForm('assign', this)" class="link-action"><%= message('assigned_to') -%></a> <%= h @issue_results.user(issue.assignee).name -%>
         <% else %>
           <a href='#' onclick="return issueForm('assign', this)" class="link-action"><%= message('issue.assign.formlink') -%></a>
-            <% if issue.assignee!=current_user.login %>
+            <% if issue.assignee != current_user.login %>
             [<a href="#" onclick="return assignIssueToMe(this)" class="link-action"><%= message('issue.assign.to_me') -%></a>]
             <% end %>
         <% end %>
         </span>
-      <% end %>
-
-      <% unless issue.resolution %>
         <img src="<%= ApplicationController.root_context -%>/images/sep12.png"/>
         &nbsp;
         <span class="spacer-right">
diff --git a/sonar-server/src/test/java/org/sonar/server/issue/TransitionActionTest.java b/sonar-server/src/test/java/org/sonar/server/issue/TransitionActionTest.java
new file mode 100644 (file)
index 0000000..ffda6ea
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * 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.server.issue;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.api.issue.Issue;
+import org.sonar.api.issue.internal.DefaultIssue;
+import org.sonar.api.issue.internal.IssueChangeContext;
+import org.sonar.core.issue.workflow.IssueWorkflow;
+
+import java.util.Map;
+
+import static com.google.common.collect.Maps.newHashMap;
+import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.*;
+
+public class TransitionActionTest {
+
+  private TransitionAction action;
+
+  private IssueWorkflow workflow = mock(IssueWorkflow.class);
+
+  @Before
+  public void before() {
+    action = new TransitionAction(workflow);
+  }
+
+  @Test
+  public void should_execute() {
+    String transition = "reopen";
+    Map<String, Object> properties = newHashMap();
+    properties.put("transition", transition);
+    DefaultIssue issue = mock(DefaultIssue.class);
+
+    Action.Context context = mock(Action.Context.class);
+    when(context.issue()).thenReturn(issue);
+
+    action.execute(properties, context);
+    verify(workflow).doTransition(eq(issue), eq(transition), any(IssueChangeContext.class));
+  }
+
+  @Test
+  public void should_support_all_issues() {
+    assertThat(action.supports(new DefaultIssue().setResolution(null))).isTrue();
+    assertThat(action.supports(new DefaultIssue().setResolution(Issue.RESOLUTION_FIXED))).isTrue();
+  }
+
+}